Versioning extension for SQLAlchemy.
I've a many to many relationship in my current application, which looks pretty much like the example I posted at the end of this issue. It all works great and SQLAlchemy Continuum nicely tracks all changes, except for gathering the changeset accross these relationships. It does keep track of the changes nicely in the database, however: if I change a tag on a bank-transaction, the version table of the junction table `bank_transaction_tags_version` gets an extra record with the same transaction_id as the transaction_id of the version table of `bank_transaction_version`. And this is always the case, if I only change a tag, the `bank_transaction_version` still gets another record with the same `transaction_id ` as the record in `bank_transaction_tag_version`, but obviously only the relationship has changed and nothing to the record in `bank_transaction` So, my issue is that, when printing the changeset of the BankTransaction class it does show the changeset of that specific table but it ignores all relationships. Example: ```python bank_transaction = db.query(BankTransaction).first() # this prints a list with two tag objects print(bank_transaction.tags) # Output: # [<models.tag.Tag object at 0x7f85cf609350>, <models.tag.Tag object at 0x7f85cf609450>] for version in bank_transaction.versions: # This only prints the changeset of the main object print(version.changeset) # This is always empty print(version.tags) ``` So `version.changeset` is also returning an empty object, when there was only a change with respect to the tags, ie. I only added or removed a tag to the object. This is how the classes look like: ```python class BankTransaction(Base): """Model which contains all bank transactions from all bank accounts""" __versioned__ = {} __tablename__ = "bank_transactions" __table_args__ = (UniqueConstraint("hash", name="unique_bank_transaction_hash"),) id = Column(Integer, primary_key=True) user_id = Column(Integer, ForeignKey("users.id")) date = Column(Date()) # Account where transaction goes to or comes from offset_iban = Column(String(30)) offset_name = Column(String(256)) # Where money goes to, or initiating party final_party = Column(String(256)) # Credit or debit amount amount = Column(Float()) currency = Column(String(10)) description = Column(Text()) # Dates records created/updated created_on = Column(DateTime, server_default=func.now()) updated_on = Column( DateTime, server_default=func.now(), onupdate=func.current_timestamp() ) # Hash we create to keep track of unique records hash = Column(String(256)) # Many-to-Many relationships tags = relationship( "Tag", secondary=bank_transaction_tag_mapping, back_populates="bank_transactions" ) class Tag(Base): __versioned__ = {} __tablename__ = "tags" # fields here id = Column(Integer, primary_key=True) name = Column(String(256)) alias = Column(String(256)) color = Column(String(256)) description = Column(String(256)) # Many-to-Many relationships bank_transactions = relationship( "BankTransaction", secondary=bank_transaction_tag_mapping, back_populates="tags" ) # Many to many relationship for tags and bank_transactions bank_transaction_tag_mapping = Table( "bank_transaction_tags", Base.metadata, Column("bank_transaction_id", ForeignKey("bank_transactions.id"), primary_key=True), Column("tag_id", ForeignKey("tags.id"), primary_key=True), ) ``` Is there a way to get this working?
This issue appears to be discussing a feature request or bug report related to the repository. Based on the content, it seems to be still under discussion. The issue was opened by ErikvdVen and has received 2 comments.