Bug #9010
open
[paddles] `rollback()` is used incorrectly
Added by Alfredo Deza over 9 years ago.
Updated over 8 years ago.
Description
In places like `paddles/controllers/runs.py` there are try/except blocks that catch non-altering database actions
that call `rollback()` which is meant to "roll back a transaction". It is usually there so that when a transaction that
is going to do a delete, update, or create action that requires a commit and that action creates an error it can be "rolled back".
This is an example of wrong usage of rollback:
def latest_runs(fields=None, count=conf.default_latest_runs_count, page=1):
query = Run.query.order_by(Run.posted.desc())
query = offset_query(query, page_size=count, page=page)
runs = query.all()
if fields:
try:
return [run.slice(fields) for run in runs]
except AttributeError:
rollback()
error('/errors/invalid/',
'an invalid field was specified')
return [run for run in runs]
- Project changed from devops to teuthology
- Status changed from New to Need More Info
- Assignee deleted (
Zack Cerza)
I still don't agree that I'm necessarily using it incorrectly; there is at least one instance where I had to add it because pecan was explicitly throwing an error telling me to do so.
Would you mind showing what you say Pecan was suggesting? The Paddles app uses a hook that should handle these
when there is an HTTP verb that should affect data (e.g. POST, DELETE, PUT), the hook may not operate if for example
there is a GET operation and data is getting modified.
The pasted example in the description is just one place, this is done in a few others as well.
- Status changed from Need More Info to Closed
- Regression set to No
If this is still an issue, reopen.
- Status changed from Closed to 12
Unfortunately this is still an issue:
~/python/paddles/paddles$ grep -A 1 -B 1 -Hrn 'rollback()' *
...
controllers/jobs.py-99- except AttributeError:
controllers/jobs.py:100: rollback()
controllers/jobs.py-101- error('/errors/invalid/',
--
--
controllers/jobs.py-114- except ValueError:
controllers/jobs.py:115: rollback()
controllers/jobs.py-116- error('/errors/invalid/', 'could not decode JSON body')
--
--
controllers/nodes.py-50- except ValueError:
controllers/nodes.py:51: rollback()
controllers/nodes.py-52- error('/errors/invalid/', 'could not decode JSON body')
--
--
controllers/runs.py-24- except AttributeError:
controllers/runs.py:25: rollback()
controllers/runs.py-26- error('/errors/invalid/',
--
--
controllers/runs.py-48- except ValueError:
controllers/runs.py:49: rollback()
controllers/runs.py-50- error('/errors/invalid/', 'date format must match %s' %
--
--
controllers/runs.py-286- except ValueError:
controllers/runs.py:287: rollback()
controllers/runs.py-288- error('/errors/invalid/', 'could not decode JSON body')
- Status changed from 12 to New
- Assignee set to Zack Cerza
Also available in: Atom
PDF