dmitry b
unread,Nov 7, 2011, 4:49:47 PM11/7/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to django-sentry
Granted, this is somewhat of a edge case. Unfortunately for me, this
is the case I have run into.
Consider the following call:
@transaction.commit_on_success
def process_data():
try:
do_some_db_task()
except SomeDatabaseException:
log.error("Database exception")
what I get is the following:
Exception: current transaction is aborted, commands ignored until end
of transaction block
/usr/lib/python2.6/site-packages/sentry/filters/__init__.py in process
/usr/lib/python2.6/site-packages/django/contrib/sites/models.py in
get_current
/usr/lib/python2.6/site-packages/django/db/models/manager.py in get
/usr/lib/python2.6/site-packages/django/db/models/query.py in get
/usr/lib/python2.6/site-packages/django/db/models/query.py in __len__
/usr/lib/python2.6/site-packages/django/db/models/query.py in iterator
/usr/lib/python2.6/site-packages/django/db/models/sql/compiler.py in
results_iter
/usr/lib/python2.6/site-packages/django/db/models/sql/compiler.py in
execute_sql
/usr/lib/python2.6/site-packages/django/db/backends/
postgresql_psycopg2/base.py in execute
This is not the original exception that triggered that catch clause in
the code above. This is a new exception triggered by log.error().
What happens is this: do_some_db_task() throws a database exception
leaving the transaction is an aborted state. Then during processing
of the logging statement, sentry tries to make a query against the
database within the context of the same transaction (since it's the
same database as the one used by do_some_db_task(). Since the
previous query in the transaction failed, a new exception is
generated.
I can definitely restructure my code to reduce the scope of the
transaction and to make sure that logging happens outside that scope.
This, to me, feels a bit unclean as it would require writing "Sentry
aware" code. Another solution is to define a new django connection
for the sole use by Sentry. This way Sentry's database interactions
will happen outside of business transactions.
Are there any other ways of dealing with this?
Thanks
Dmitry