Fix reflection error for SQL Server sysname type by registering it in the dialect#471
Conversation
|
I'm not sure this is the right place for this fix. Shouldn't this be done against the actual dialect rather than patching downstream, here? |
|
Good point, thanks for pointing that out. My understanding was that sysname is a built-in SQL Server alias (NVARCHAR(128)), but it isn't always present in ischema_names depending on the SQLAlchemy / dialect version. When sqlacodegen reflects a schema containing it, the reflection fails because the type cannot be resolved. I added the registration here mainly as a defensive workaround so that reflection succeeds even when the underlying dialect does not include it. That said, I agree the proper place to fix this would be in the MSSQL dialect itself. Would you prefer that this PR be dropped in favor of opening an issue/PR against SQLAlchemy instead? Alternatively, I could keep this as a small compatibility workaround here if supporting older dialect versions is desirable. |
It is preferable. Things would gradually get out of hand if we started accepting workarounds for all kinds of upstream bugs. |
|
Got it, that makes sense. I'll close this PR and look into proposing the fix upstream in SQLAlchemy so it can be handled in the dialect itself. Thanks for the review! |
Changes
Fixes SQL Server reflection issues when a database contains columns using the
sysnametype.sysnameis a built-in SQL Server type (an alias forNVARCHAR(128)), but itis not registered in SQLAlchemy's
ischema_namesfor some dialect versions.When sqlacodegen reflects a schema containing this type, the reflection process
fails because the type cannot be resolved.
This change registers
sysnameasNVARCHARin the MSSQL dialect beforereflection:
This allows sqlacodegen to correctly reflect databases that contain columns
defined with the
sysnametype.Checklist
tests/) which would fail without your patchCHANGES.rst).