Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
dryobates opened this issue Jan 28, 2019 · 0 comments
Closed

Comments

@dryobates
Copy link

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]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant