Skip to content

Commit

Permalink
Merge pull request #169 from fuhrysteve/dont_include_excluded_relatio…
Browse files Browse the repository at this point in the history
…nships

don't include excluded properties
  • Loading branch information
kvesteri committed Mar 7, 2018
2 parents f036ffa + a9ac2fb commit 5e00c0d
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Expand Up @@ -34,3 +34,9 @@ nosetests.xml
.mr.developer.cfg
.project
.pydevproject

# mypy
.mypy_cache/

# Unit test / coverage reports
.cache
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -15,9 +15,9 @@ before_script:
language: python
python:
- 2.7
- 3.3
- 3.4
- 3.5
- 3.6
install:
- pip install -e ".[test]"
script:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -77,9 +77,9 @@ def get_version():
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
'Topic :: Software Development :: Libraries :: Python Modules'
]
Expand Down
5 changes: 4 additions & 1 deletion sqlalchemy_continuum/relationship_builder.py
Expand Up @@ -346,7 +346,10 @@ def __call__(self):
except ClassNotVersioned:
self.remote_cls = self.property.mapper.class_

if self.property.secondary is not None and not self.property.viewonly:
if (self.property.secondary is not None and
not self.property.viewonly and
not self.manager.is_excluded_property(
self.model, self.property.key)):
self.build_association_version_tables()

# store remote cls to association table column pairs
Expand Down
49 changes: 49 additions & 0 deletions tests/test_column_inclusion_and_exclusion.py
Expand Up @@ -53,3 +53,52 @@ class TextItem(self.Model):
content = sa.Column('_content', sa.UnicodeText)

self.TextItem = TextItem


class TestColumnExclusionWithRelationship(TestCase):
def create_models(self):

class Word(self.Model):
__tablename__ = 'word'
id = sa.Column(sa.Integer, autoincrement=True, primary_key=True)
word = sa.Column(sa.Unicode(255))

class TextItemWord(self.Model):
__tablename__ = 'text_item_word'
id = sa.Column(sa.Integer, autoincrement=True, primary_key=True)
text_item_id = sa.Column(sa.Integer, sa.ForeignKey('text_item.id'), nullable=False)
word_id = sa.Column(sa.Integer, sa.ForeignKey('word.id'), nullable=False)

class TextItem(self.Model):
__tablename__ = 'text_item'
__versioned__ = {
'exclude': ['content']
}

id = sa.Column(sa.Integer, autoincrement=True, primary_key=True)
name = sa.Column(sa.Unicode(255))
content = sa.orm.relationship(Word, secondary='text_item_word')

self.TextItem = TextItem
self.Word = Word

def test_excluded_columns_not_included_in_version_class(self):
cls = version_class(self.TextItem)
manager = cls._sa_class_manager
assert 'content' not in manager.keys()

def test_versioning_with_column_exclusion(self):
item = self.TextItem(name=u'Some textitem',
content=[self.Word(word=u'bird')])
self.session.add(item)
self.session.commit()

assert item.versions[0].name == u'Some textitem'

def test_does_not_create_record_if_only_excluded_column_updated(self):
item = self.TextItem(name=u'Some textitem')
self.session.add(item)
self.session.commit()
item.content.append(self.Word(word=u'Some content'))
self.session.commit()
assert item.versions.count() == 1

0 comments on commit 5e00c0d

Please sign in to comment.