Skip to content

Commit

Permalink
Fix dataset cache invalidation.
Browse files Browse the repository at this point in the history
  • Loading branch information
coleifer committed Mar 23, 2019
1 parent f1f2cfe commit 8b42987
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions playhouse/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def update_cache(self, table=None):
dependencies.extend(self.get_table_dependencies(table))
else:
dependencies = None # Update all tables.
self._models = {}
updated = self._introspector.generate_models(
skip_invalid=True,
table_names=dependencies,
Expand Down
9 changes: 9 additions & 0 deletions tests/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,15 @@ def test_update_cache(self):
self.assertEqual(sorted(Foo.columns), ['data', 'id'])
self.assertTrue('foo' in self.dataset._models)

self.dataset._models['foo'].drop_table()
self.dataset.update_cache()
self.assertTrue('foo' not in self.database.get_tables())

# This will create the table again.
Foo = self.dataset['foo']
self.assertTrue('foo' in self.database.get_tables())
self.assertEqual(Foo.columns, ['id'])

def assertQuery(self, query, expected, sort_key='id'):
key = operator.itemgetter(sort_key)
self.assertEqual(
Expand Down

0 comments on commit 8b42987

Please sign in to comment.