#8669 closed (fixed)
All remaining create() methods also force an insert (continuation of r8670)
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Keywords: | ||
Cc: | richard.davies@… | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
#8419 / [8670] forced an SQL insert in the main create() and get_or_create() methods, preventing data loss from overwriting existing data - thanks Malcolm!
All other get_or_create() methods end up calling back to the main get_or_create().
However, there are a few extra create() methods which don't call back to the main create() - this patch ensures that those also force an insert, so cannot overwrite existing data.
Extra methods found via "find django -name '*.py' | xargs grep -F 'def create('" and "find django -name '*.py' | xargs grep -F 'def get_or_create('"
Attachments (6)
Change History (16)
by , 16 years ago
Attachment: | create-always-inserts.diff added |
---|
comment:1 by , 16 years ago
Triage Stage: | Unreviewed → Design decision needed |
---|
It's not clear that add()
should do this. At some point, if you're playing with custom set primary keys, you have to act responsibly and by calling that method you are saying that you want to 'add' that object, which is what happens.
The generic relations one is probably in line with the other changes, but I'm going to think about the first two thirds of the patch a bit.
by , 16 years ago
Attachment: | create-always-inserts.v2.diff added |
---|
comment:2 by , 16 years ago
Here's a different (better?) approach - which avoids changing add() and points everyone back to the main create() implementation, rather than maintaining multiple copies.
comment:3 by , 16 years ago
Triage Stage: | Design decision needed → Ready for checkin |
---|
The second patch is the way to go. It's a little annoying that overriding add()
many-to-many now won't get called in the create case, but that's an acceptable trade-off.
I haven't checked that the full test suite passes with this patch yet, but, on the surface, it looks good to go.
comment:4 by , 16 years ago
Patch needs improvement: | set |
---|---|
Triage Stage: | Ready for checkin → Accepted |
This patch (the second one, which is the one we're considering) causes a lot of failures in the test suite, even with SQLite. They need to be fixed. I'd also like some confirmation that the revised version runs against the full test suite on a database that supports transacations (one of the PostgreSQL backends or Oracle).
Finally, given the scope of the change and the fact that it's already caused some problems, some tests to verify the new functionality would be a good idea.
by , 16 years ago
Attachment: | create-always-inserts.v3.diff added |
---|
Fix test suite failures (was a silly one line error in last patch)
by , 16 years ago
Attachment: | tests.diff added |
---|
Extra tests (actually test changeset 8670, but that's the base of this ticket too)
comment:5 by , 16 years ago
Note: tests.diff includes creating an empty file "tests/modeltests/create/_init_.py", which doesn't show up in the web view of the diff
by , 16 years ago
Attachment: | authors.diff added |
---|
Have I done enough across various tickets to be in the authors list?
comment:6 by , 16 years ago
The full test suite succeeds on SQLite with all of the above 3 patches (create-always-inserts.v3.diff, tests.diff, authors.diff).
In my (somewhat unusual) PostgreSQL set up, the test suite fails in several ways on unmodified trunk, even without these patches. I'll continue working on this tomorrow, both to post bugs to make it work initially, and also then to verify my actual patches.
comment:7 by , 16 years ago
#8739 is a separate bug report against save(force_insert=True) failing on PostgreSQL. Since create() is built on that function, save(force_insert=True) will have to be fixed to get create() working on postgreSQL - all the work in this ticket makes that situation no better and no worse.
by , 16 years ago
Attachment: | 8669_tests.v2.diff added |
---|
comment:8 by , 16 years ago
Patch needs improvement: | unset |
---|
OK, I've validated this against the full test suite on both sqlite3 and postgresql_psycopg2. It is ready to check in.
The patches:
- create-always-inserts.v3.diff is the actual fix to the ticket
- authors.diff adds me to the authors list
comment:9 by , 16 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Fixes for 3 different create() methods