Skip to content

Activity plugin does not work with primary keys named other than "id" #210

Closed

Description

@dryobates

SQLAlchemy-Continuum: 1.3.7
SQLAlchemy: 1.2.17

If I name primary_key of my model other than "id", then it raises "AttributeError: type object 'Version' has no attribute 'id'".

Test that shows problem:

class TestActivityNotId(ActivityTestCase):

    def create_models(self):
        TestCase.create_models(self)

        class NotIdModel(self.Model):
            __tablename__ = 'not_id'
            __versioned__ = {
                'base_classes': (self.Model, )
            }

            pk = sa.Column(sa.Integer, autoincrement=True, primary_key=True)
            name = sa.Column(sa.Unicode(255), nullable=False)
        self.NotIdModel = NotIdModel

    def test_create_activity_with_pk(self):
        not_id_model = self.NotIdModel(name="abc")
        self.session.add(not_id_model)
        self.session.commit()
        self.create_activity(not_id_model)
        self.session.commit()
        activity = self.session.query(versioning_manager.activity_cls).first()
        assert activity
        assert activity.transaction_id
        assert activity.object == not_id_model
        assert activity.object_version == not_id_model.versions[-1]

Activity

  1. added a commit that references this issue on Jan 28, 2019
    a9d6657
  2. added a commit that references this issue on Apr 16, 2019
    a885bae
  3. added a commit that references this issue on Feb 10, 2022
    48d8179
  4. added a commit that references this issue on Aug 23, 2022
    76a60cd
  5. added a commit that references this issue on Sep 11, 2022
    eb0c8d1
  6. added a commit that references this issue on Oct 2, 2025
    46886b0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions