Duplicate join table rows created when modifying contents of InstrumentedList in many-to-many relationship.

Issue #2647 resolved
Former user created an issue

(original reporter: anthonyt) Like the title says, this is a test case for a bug that affects setting the contents of an InstrumentedList property.

Essentially it boils down to: If there is an object X in a Many-To-Many relationship with a join table, and you remove it, then add it again, then flush, SQLAlchemy tries to insert a duplicate row into the join table.

e.g. given the following... tables: users, groups, users_groups classes: User, Group and instances: u, g

The following operations will succeed:

    u.groups = [g](g)
    session.commit()
    u.groups.remove(g)
    session.commit()
    u.groups.append(g)
    session.commit()

But the following operations (missing the intermediate flush/commit) will fail:

    u.groups = [g](g)
    session.commit()
    u.groups.remove(g)
    u.groups.append(g)
    session.commit()

Runnable test case at https://gist.github.com/4449077 though you'll have to edit the config dictionary to add your own user and database name.

Comments (6)

  1. Former user Account Deleted

    (original author: anthonyt) Looks like it's probably the same problem, but I haven't had a chance to actually test it out. The change is implemented in an unreleased branch of 0.8.0, right? What's the best way to get a hold of that?

  2. Log in to comment