dcramer/sentry — Issue #343: Sentry commits managed transactions unexpectedly (integrated)
Author: lettertwo
Created: 2012-02-07 16:10:47+00:00
State: open

I'm not convinced this is necessarily something that needs to change, but...

When running an integrated Sentry server in a Django project, I came upon the following scenario (simplified for clarity (I hope)):

```python
class Command(BaseCommand):

@transaction.commit_on_success
def handle(self, *args, **options):
"""
Create three new users. When the last user fails,
rollback all three and log the error.

"""
for username in ('test', 'fake', None):
logger.warning('adding user %s' % username)
user = User(username=username)
try:
user.save()
except IntegrityError as e:
transaction.rollback()
logger.exception(e)
raise CommandError('bad username: %s' % username)

```

With the root logger configured to log everything from WARNING up to Sentry, the first two saves() end up in the database, though the code expects the whole batch to be rolled back.

Logging config:

```python
LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'root': {
'level': 'WARNING',
'handlers': ['sentry'],
},
'formatters': {
'verbose': {
'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
},
},
'handlers': {
'sentry': {
'level': 'WARNING',
'class': 'raven.contrib.django.handlers.SentryHandler',
},
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'verbose'
}
},
'loggers': {
'django.db.backends': {
'level': 'ERROR',
'handlers': ['console'],
'propagate': False,
},
'raven': {
'level': 'DEBUG',
'handlers': ['console'],
'propagate': False,
},
'sentry.errors': {
'level': 'DEBUG',
'handlers': ['console'],
'propagate': False,
},
},
}

```

This seems to be because of [this change](https://github.com/dcramer/sentry/commit/9b00dd61ec2095333be58cee7b7d9fb7895d7c2e#L1R208).

As I said, I don't know if this is necessarily a candidate for a bugfix, as there are various ways to work around it. Any thoughts, comments?