dropbox / sqlalchemy-stubs

Mypy plugin and stubs for SQLAlchemy
Apache License 2.0
573 stars 101 forks source link

Multiple classes found for path "Model" in the registry of this declarative base. Please use a fully module-qualified path. #159

Closed DanCardin closed 2 years ago

DanCardin commented 4 years ago

In instances where you have more than one model with the same name, sqlalchemy directs you to supply the fully qualified module name. This breaks sqlalchemy-stubs.

if my relationship were defined as:

foo = relationship('package.models.foo.Foo')

it doesn't seem like any combination of TYPE_CHECKING guarded imports, allows it to correctly work.

I assume the issue is here: https://github.com/dropbox/sqlalchemy-stubs/blob/ea93332454f3d5646b87395f82b4d7badbd64de1/sqlmypy.py#L376, where it's just looking for the given arg name in the context.

I would make a PR to just take something like arg.value.split('.')[-1], but I have to imagine mypy has got a better way make actual use of the fact that the fully qualified name is specified (which seems like it would obviate the need for the import if so).

NotarySigningAgent commented 4 years ago

thank you

On Wed, Jun 24, 2020 at 9:10 AM DanCardin notifications@github.com wrote:

In instances where you have more than one model with the same name, sqlalchemy directs you to supply the fully qualified module name. This breaks sqlalchemy-stubs.

if my relationship were defined as:

foo = relationship('package.models.foo.Foo')

it doesn't seem like any combination of TYPE_CHECKING guarded imports, allows it to correctly work.

I assume the issue is here: https://github.com/dropbox/sqlalchemy-stubs/blob/ea93332454f3d5646b87395f82b4d7badbd64de1/sqlmypy.py#L376, where it's just looking for the given arg name in the context.

I would make a PR to just take something like arg.value.split('.')[-1], but I have to imagine mypy has got a better way make actual use of the fact that the fully qualified name is specified (which seems like it would obviate the need for the import if so).

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/dropbox/sqlalchemy-stubs/issues/159, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEHEGGG4MGACFMTOJP3LMZTRYIJOBANCNFSM4OGYKJBA .