-
Notifications
You must be signed in to change notification settings - Fork 227
Allow SQLAlchemy class mapping errors to propagate #281
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,12 @@ def get_query(model, context): | |
def is_mapped_class(cls): | ||
try: | ||
class_mapper(cls) | ||
except (ArgumentError, UnmappedClassError): | ||
except ArgumentError as error: | ||
# Only handle ArgumentErrors for non-class objects | ||
if "Class object expected" in str(error): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To me, this is a bit of a code-smell. Is it possible to instead create a new exception class and catch that instead? I'm not sure what the import tree looks like, so I'm unsure where it should go, but perhaps:
Then there's no need for checking the string of the error message here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree but I think that would need to be handled in SQLAlchemy itself |
||
return False | ||
raise error | ||
except UnmappedClassError: | ||
return False | ||
else: | ||
return True | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert
is only evaluated when the interpreter is running in "debug" mode and is ignored when optimizations are enabled with the-O
command line switch. I personally think it's proper to have this check every time and what you have written is an improvement, but to match the previous behavior it might be best to wrap this in anif __debug__:
check.https://docs.python.org/3/reference/simple_stmts.html#grammar-token-assert-stmt
Perhaps