Skip to content

Commit

Permalink
Fix: #50, broken exception handling in _swap_database()
Browse files Browse the repository at this point in the history
  • Loading branch information
rudyryk committed Mar 5, 2017
1 parent 120b0c3 commit 7c93839
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions peewee_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,11 +351,12 @@ def _swap_database(self, query):
"""Swap database for query if swappable. Return **new query**
with swapped database.
Check manager database and model database match. If model
database is `auto`, manager's one will be used.
This is experimental feature which allows us to have multiple
managers configured against different databases for single model
definition.
If query database can't be swapped and differs from manager's
database, it's **WRONG AND DANGEROUS**, so assertion is raised.
The essential limitation though is that database backend have
to be **the same type** for model and manager!
"""
if query.database == self.database:
return query
Expand All @@ -376,8 +377,12 @@ def _swap_database(self, query):
query.database = self.database
return query
else:
assert False, ("Error, models's database and manager's "
"database are different: %s" % model)
assert False, (
"Error, query's database and manager's database are "
"different. Query: %s Manager: %s" % (
query.database, self.database
)
)

@staticmethod
def _subclassed(base, *classes):
Expand Down

0 comments on commit 7c93839

Please sign in to comment.