Skip to content
This repository has been archived by the owner on Feb 7, 2019. It is now read-only.

Commit

Permalink
Merge pull request #103 from swisscom/bugfix/nonversionedintegration
Browse files Browse the repository at this point in the history
Bugfix/nonversionedintegration
  • Loading branch information
maennel committed Jul 15, 2015
2 parents 0c0212b + 5d15da7 commit b34414a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 4 additions & 2 deletions versions/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,10 @@ def as_sql(self, qn=None, connection=None):
sql = ""
params = []

# Fail fast for inacceptable cases
if self._as_of_time_set and not self._joined_alias:
raise ValueError("joined_alias is not set, but as_of is; this is a conflict!")

# Set the SQL string in dependency of whether as_of_time was set or not
if self._as_of_time_set:
if self.as_of_time:
Expand All @@ -382,8 +386,6 @@ def as_sql(self, qn=None, connection=None):
# By here, the sql string is defined if an as_of_time was provided
if self._joined_alias:
sql = sql.format(alias=self._joined_alias)
else:
raise ValueError("joined_alias not set")

# Set the final sqls
# self.sqls needs to be set before the call to parent
Expand Down
10 changes: 10 additions & 0 deletions versions_tests/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2231,6 +2231,15 @@ def test_accessibility_of_versions_and_non_versionables_via_versioned_fk(self):
should_be_jacques_t1 = should_be_jacques.__class__.objects.as_of(self.t1).get(identity=should_be_jacques.identity)
self.assertEqual(jacques_t1, should_be_jacques_t1)

def test_filter_on_fk_versioned_and_nonversioned_join(self):
# Get non-versioned objects, filtering on a FK-related versioned object
jacques_hats = WineDrinkerHat.objects.filter(wearer__name='Jacques').distinct()
self.assertEqual(set(jacques_hats), set([self.green_vagabond_hat, self.red_sailor_hat]))

# Get all versions of a Versionable by filtering on a FK-related non-versioned object
person_versions = WineDrinker.objects.filter(hats__shape='Vagabond')
self.assertIn(self.jacques, person_versions)


class FilterOnForeignKeyRelationTest(TestCase):
def test_filter_on_fk_relation(self):
Expand All @@ -2243,6 +2252,7 @@ def test_filter_on_fk_relation(self):
l2 = len(Player.objects.as_of(t1).filter(team__name='team'))
self.assertEqual(l1, l2)


class SpecifiedUUIDTest(TestCase):

@staticmethod
Expand Down

0 comments on commit b34414a

Please sign in to comment.