association_table = Table(\"association_table\",
Base.metadata,
Column(\"show_id\", Integer(), ForeignKey(\"show_
Session.bulk_save_objects() is too low level API for your use case, which is persisting multiple model objects and their relationships. The documentation is clear on this:
Warning
The bulk save feature allows for a lower-latency INSERT/UPDATE of rows at the expense of most other unit-of-work features. Features such as object management, relationship handling, and SQL clause support are silently omitted in favor of raw INSERT/UPDATES of records.
Please read the list of caveats at Bulk Operations before using this method, and fully test and confirm the functionality of all code developed using these systems.
You should use Session.add_all() to add a collection of instances to the session. It will handle the instances one at a time, but that is the price you have to pay for advanced features such as relationship handling.
So, instead of
session.bulk_save_objects(showtime_lists)
session.commit()
do
session.add_all(showtime_lists)
session.commit()