[Sqlalchemy-tickets] Issue #4056: Merge doesn't create all nested objects (zzzeek/sqlalchemy)
Brought to you by:
zzzeek
From: Haim R. <iss...@bi...> - 2017-08-30 14:39:10
|
New issue 4056: Merge doesn't create all nested objects https://bitbucket.org/zzzeek/sqlalchemy/issues/4056/merge-doesnt-create-all-nested-objects Haim Raitsev: When trying to update an object with nested objects, some of nested objects are already exists in the db and some are new. merge will handle correctly the existing nested objects (will update them) but will only insert the last one of the nested newly created objects. This is the code we ran with the following input: modal: ``` #!python class Order(Base): __tablename__ = 'orders' id = Column(Integer, primary_key=True) status = Column(Enum(OrderStatus), nullable=False) suppression_files = relationship('File', lazy='joined', cascade="all, delete-orphan") class File(Base): __tablename__ = 'files' id = Column(Integer, primary_key=True) order_id = Column(Integer, ForeignKey('orders.id'), nullable=False) file_name = Column(String, nullable=False) file_url = Column(String, nullable=False) ``` The object we are trying to merge: ``` #!python id = {int} 59 status = {OrderStatus} OrderStatus.draft suppression_files = {InstrumentedList} [ {File} file_name = {str} 'test' file_url = {str} 'https://docs.sqlalchemy.org/en/rel_1_1/contents.html' id = {NoneType} None order_id = {NoneType} None, {File} file_name = {str} 'test1' file_url = {str} 'https://docs.sqlalchemy.org/en/rel_1_1/contents.html' id = {NoneType} None order_id = {NoneType} None] ``` Expected: All 2 new files in the array('suppression_files') should be created Actual: Only the last file (named 'test1') will be inserted to the db, the first file is ignored. Database: PostgresSQL 9.6 SQLAlchemy:1.1.13 |