-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(#25): handle attributes which are not accessible in ORM
doing a check for property key before enabling active_history to make sure it can be directly accessed by parent_cls
- Loading branch information
1 parent
3f0ae08
commit 7a2ebf9
Showing
2 changed files
with
50 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import datetime | ||
import sqlalchemy as sa | ||
from copy import copy | ||
from tests import TestCase | ||
|
||
|
||
class TestBug25(TestCase): | ||
# ref: https://github.com/corridor/sqlalchemy-history/issues/25 | ||
def create_models(self): | ||
class Writer(self.Model): | ||
__tablename__ = "writer" | ||
__versioned__ = {} | ||
|
||
id = sa.Column(sa.Integer, sa.Sequence(f"{__tablename__}_seq"), primary_key=True) | ||
name = sa.Column(sa.String(255)) | ||
type = sa.Column(sa.String(255)) | ||
|
||
__mapper_args__ = { | ||
"polymorphic_on": ( | ||
sa.case( | ||
[(type.in_(["poet", "lyricist"]), "bard")], | ||
else_=type, | ||
) | ||
), | ||
"polymorphic_identity": "writer", | ||
} | ||
|
||
class Author(self.Model): | ||
__tablename__ = "author" | ||
__versioned__ = {} | ||
id = sa.Column(sa.Integer, sa.Sequence(f"{__tablename__}_seq"), primary_key=True) | ||
name = sa.Column(sa.String(255)) | ||
|
||
__mapper_args__ = { | ||
"polymorphic_identity": "author", | ||
} | ||
|
||
self.Writer = Writer | ||
self.Author = Author | ||
|
||
def test_inserting_entries(self): | ||
writer = self.Writer(name="Writer 1") | ||
author = self.Author(name="Author 1") | ||
self.session.add(writer) | ||
self.session.add(author) | ||
self.session.commit() |