#21166 closed Bug (fixed)
Reset the errors_occurred flag
| Reported by: | Aymeric Augustin | Owned by: | Aymeric Augustin |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | 1.6-beta-1 |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Accepted | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
Currently it's reset only in close_if_unusable_or_obsolete, after making a test query.
I think it should be reset in atomic.__exit__ after a successful rollback too.
Reported by Anssi.
Change History (5)
comment:1 by , 12 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
comment:2 by , 12 years ago
comment:3 by , 12 years ago
| Has patch: | set |
|---|
comment:4 by , 12 years ago
| Resolution: | → fixed |
|---|---|
| Status: | assigned → closed |
Note:
See TracTickets
for help on using tickets.
In fact, I'm hesitating about this. It's a very small change: https://github.com/django/django/pull/2537.
errors_occurredis set after exceptions other thanDataErrorandIntegrityError. Given the definition of these two exceptions, they're unlikely to be thrown in situations that make the connection unusable. I can't say much about the other exceptions. That's why I implemented a safety net inclose_if_unusable_or_obsolete(). When another exception occurs, that method tests if the connection still works, and if it doesn't, drops it.The vast majority of expected and recoverable exceptions are
IntegrityErrors. These don't set the flag and don't incur the cost of the extra query to check the state of the connection. So there isn't a lot at stake.But a small gain is still a gain. I believe that a successful
ROLLBACKvalidates the state of the connection just as well as aSELECT 1. While we're there, a successfulCOMMITalso means that the connection works.The argument against this change is to keep the safety net simple. Preserving a broken connection is very bad; making an extra query on a working connection is almost negligible.
Considering that the patch is dead simple, if I had to make the choice, I'd say +0.