Opened 12 years ago
Closed 12 years ago
#19861 closed Bug (fixed)
Improve connection._dirty flag handling
Reported by: | Anssi Kääriäinen | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
The connection._dirty flag currently represents a mix of things:
- It is sometimes used for tracking if transaction management is enabled (enabled when self._dirty is not None). This doesn't work correctly, as the _dirty flag is never reset to None. And, three valued flag isn't a good idea anyways.
- It is used to track if the connection needs commit, but only inside transaction management. When outside tx management it will not be set by Django.
Patch available here: https://github.com/akaariai/django/commit/cd31b74c01eca1744bc07f1b462ce73a78666fa6. I believe the commit resolves a bunch of subtle bugs, but it likely also causes a bunch of subtle backwards incompatibilities. One such change is that .commit() and .rollback() can now be called always, not only inside transaction management.
I tried the patch and it passes all tests on sqlite and postgresql (with autocommit off, autocommit on I had time to run just backends transactions transactions_regress and these pass).
With postgresql I also ran the tests with transaction state tracking enabled (the commented out code in psycopg2/base.py). There is one false positive (Django believes the transaction to be in transaction, in reality it isn't) caused by test_cursor_executemany_with_empty_params_list in backends tests. executemany with empty params does nothing, but the dirty flag handling doesn't spot this. This is likely a non issue (or, if this is a issue, it is a bug in current Django, too). There are no false negatives (Django doesn't believe the connection to be in tx, but it is).
The patch also contains a bunch of fixes to tests doing various weird things with transaction management.
Change History (3)
comment:1 by , 12 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 12 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
comment:3 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
A new version of the patch available from https://github.com/akaariai/django/commit/50328f0a618674b7143d86acaa7016c5293e9774
I think this one is ready for commit now.