-
Notifications
You must be signed in to change notification settings - Fork 257
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
AssertionError: TypeDecorator implementations require a class-level variable 'impl' #315
Comments
No luck with the latest rc5. This is where the sqlacodegen/src/sqlacodegen/generators.py Lines 675 to 679 in 2a60532
|
It appears to work fine if I change it to Is Happy to put in a PR... |
Before suppressing any exceptions, I'd like to understand the root cause of this. Could you find out for me? |
Yep, I'm digging into it now... |
This is with If I patch my implementation as: try:
new_coltype = coltype.adapt(supercls)
except TypeError:
# If the adaptation fails, don't try again
break
except Exception:
print('#'*80)
print(coltype)
print(coltype.__class__)
print(coltype.__class__.mro())
print(supercls)
print('#'*80)
raise ...I get:
|
Yeah, |
Agreed - it's highlighting a actual problem with their implementation of the I'll close this and open an issue on their repo... |
Thanks for taking the time to triage this issue! |
It's curious because the impl = sqlalchemy.types.DateTime |
...and seems to be following the recommended recipe to augment existing types: |
It seems that if not hasattr(self.__class__, "impl"):
raise AssertionError(
"TypeDecorator implementations "
"require a class-level variable "
"'impl' which refers to the class of "
"type being decorated"
) |
...so I think perhaps the issue lies with a too-strict exception clause here. In the specific instance that the except (TypeError, AssertionError): to also handle this specific case. Thoughts? |
If you wanted to be a bit more defensive you could instead do: try:
new_coltype = coltype.adapt(supercls)
except TypeError:
# If the adaptation fails, don't try again
break
except AssertionError:
if supercls is TypeDecorator:
# trying to instantiate a TypeDecorator class
# will fail with an AssertionError
break
else:
raise |
I think I would like to check if the coltype is a type decorator, thus avoiding |
Things to check first
I have searched the existing issues and didn't find my bug already reported there
I have checked that my bug is still present in the latest release
Sqlacodegen version
3.0.0rc3
SQLAlchemy version
2.0.25
RDBMS vendor
Other
What happened?
I'm seeing the below error when trying to generate code for a
databricks
"database"Just posting to remind me to investigate further and in case others are also seeing this...
Database schema for reproducing the bug
No response
The text was updated successfully, but these errors were encountered: