cant set association proxy collection to None

Issue #597 resolved
Mike Bayer repo owner created an issue

Starting with r2598, I'm seeing some failures with how I'm using the association proxy. I've modified the examples/association/proxied_association.py file which duplicates the problem.

It is possible that I'm not suppose to remove associations like I am. But it did work before (in 0.3.7 and 0.3.6).

It looks like if I read in part of the association into the current session and then delete it, things don't go so well.

Index: examples/association/proxied_association.py
===================================================================
--- examples/association/proxied_association.py (revision 2723)
+++ examples/association/proxied_association.py (working copy)
@@ -106,8 +106,18 @@

+# new additions to proxied_association.py

+#engine.echo = True

+new_item = Item('new item', 100)
+session.clear()
+order = session.query(Order).get_by(customer_name='john smith')
+bogus = order.items[0](0).item_id  # comment out and it works on 0.3.8
+order.itemassociations = None
+session.flush()
+order.items.append(new_item)
+session.flush()

It fails with:

sqlalchemy.exceptions.SQLError: (IntegrityError) orderitems.order_id
may not be NULL u'INSERT INTO orderitems (item_id, price) VALUES (?,
?)' [100](5,)

Comments (1)

  1. jek

    Fixed in changeset:2730.

    Also, a heads up that assigning None to a collection attribute will raise an exception in 0.4.

    # no
    order.itemassociations = None
    # yes
    order.itemassociations = [or any other operation appropriate to the collection type
    del order.itemassociations[:](]
    #)
    
  2. Log in to comment