diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2008-11-25 04:43:04 +0000 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2008-11-25 04:43:04 +0000 |
| commit | 332f5ee2662835ed1ca008043d40c37d7cddc270 (patch) | |
| tree | a173fd7bb9f624490a9456ded43ba3b19849caf4 /lib/sqlalchemy | |
| parent | e3502f7f9d9b68d718a517a3d17f5bdd2aaa86c7 (diff) | |
| download | sqlalchemy-332f5ee2662835ed1ca008043d40c37d7cddc270.tar.gz | |
- Duplicate items in a list-based collection will
be maintained when issuing INSERTs to
a "secondary" table in a many-to-many relation.
Assuming the m2m table has a unique or primary key
constraint on it, this will raise the expected
constraint violation instead of silently
dropping the duplicate entries. Note that the
old behavior remains for a one-to-many relation
since collection entries in that case
don't result in INSERT statements and SQLA doesn't
manually police collections. [ticket:1232]
Diffstat (limited to 'lib/sqlalchemy')
| -rw-r--r-- | lib/sqlalchemy/orm/attributes.py | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/lib/sqlalchemy/orm/attributes.py b/lib/sqlalchemy/orm/attributes.py index 662ea05d3..79be76c3a 100644 --- a/lib/sqlalchemy/orm/attributes.py +++ b/lib/sqlalchemy/orm/attributes.py @@ -1427,11 +1427,15 @@ class History(tuple): elif original is NEVER_SET: return cls((), list(current), ()) else: - collection = util.OrderedIdentitySet(current) - s = util.OrderedIdentitySet(original) - return cls(list(collection.difference(s)), - list(collection.intersection(s)), - list(s.difference(collection))) + current_set = util.IdentitySet(current) + original_set = util.IdentitySet(original) + + # ensure duplicates are maintained + return cls( + [x for x in current if x not in original_set], + [x for x in current if x in original_set], + [x for x in original if x not in current_set] + ) else: if current is NO_VALUE: if original not in [None, NEVER_SET, NO_VALUE]: |
