bugfix(datastore) Fix get_user for various DBs #73
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
DB drivers vary in how strict they are. For example
postgres+pyscopg2 throws errors if you attempt to lower(integer) or
compare a string field with an integer field.
Furthermore, when pyscopg2 throws an internal error like that, it
aborts the transaction - so you can't just try another query.
To solve this - in get_user we check for compatibility of types using
metadata that the ORM provides. This isn't trying to be completely
general - just looking at numeric and non-numeric types - on the
presumption that we would have unique user attributes on things like
dates, boolean, etc!.
To enable testing, added an option to pytest to specify a real DB
url to replace the default sqlite. This required a bit of refactoring
and realized that we really shouldn't be passing in fixtures to
the datastore() fixture since that meant all 5 datastores would be
instantiated EVERY time - which for a real DB was a performance issue.
With this addition - tested Sqlalchemy, peewee, pony with sqlite,
postgres, mysql.