Skip to content
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

Table type needs to be visible even if Databases not installed #21

Merged
merged 4 commits into from
Jan 11, 2021

Conversation

agallant
Copy link
Contributor

Great project! I'm happy to report I was able to drop it in along with https://github.com/tiangolo/pydantic-sqlalchemy and it plays nicely with the generated Pydantic models.

That said, I ran into an issue where I had to install Databases in my project to be able to import any code from your package, even though I don't care about the databases connector (just using SQLAlchemy).

fastapi_1  |   File "./main.py", line 6, in <module>
fastapi_1  |     from fastapi_crudrouter import SQLAlchemyCRUDRouter as CRUDRouter
fastapi_1  |   File "/usr/local/lib/python3.8/site-packages/fastapi_crudrouter/__init__.py", line 1, in <module>
fastapi_1  |     from .core import MemoryCRUDRouter, SQLAlchemyCRUDRouter, DatabasesCRUDRouter
fastapi_1  |   File "/usr/local/lib/python3.8/site-packages/fastapi_crudrouter/core/__init__.py", line 5, in <module>
fastapi_1  |     from .databases import DatabasesCRUDRouter
fastapi_1  |   File "/usr/local/lib/python3.8/site-packages/fastapi_crudrouter/core/databases.py", line 16, in <module>
fastapi_1  |     class DatabasesCRUDRouter(CRUDGenerator):
fastapi_1  |   File "/usr/local/lib/python3.8/site-packages/fastapi_crudrouter/core/databases.py", line 18, in DatabasesCRUDRouter
fastapi_1  |     def __init__(self, schema: BaseModel, table: Table, database: Database, *args, **kwargs):
fastapi_1  | NameError: name 'Table' is not defined

Importing SQLAlchemyCRUDRouter ends up looking at the overall package fastapi_crudrouter which ends up looking at that from .core import... etc. etc. until it hits DatabasesCRUDRouter.

Then, the try/except for importing Databases works as expected, but the import for the Table type is also in that block. It's missing, but the rest of the code is still executing, and so it fails as not defined.

This is the simplest/most direct fix, but you could also change the overall from .core import ... model if you want.

Thanks again!

@vercel
Copy link

vercel bot commented Jan 11, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/flortz/fastapi-crudrouter/b86eudb7c
✅ Preview: https://fastapi-crudrouter-git-fork-agallant-master.flortz.vercel.app

@awtkns
Copy link
Owner

awtkns commented Jan 11, 2021

I can see how that is an issue but I think the proposed solution might also cause problems if SQLAlchemy is not installed.

@awtkns awtkns linked an issue Jan 11, 2021 that may be closed by this pull request
Copy link
Owner

@awtkns awtkns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should fix the problems with SQLA and databases

fastapi_crudrouter/core/databases.py Outdated Show resolved Hide resolved
fastapi_crudrouter/core/databases.py Show resolved Hide resolved
agallant and others added 2 commits January 11, 2021 13:12
Co-authored-by: Adam Watkins <32209255+awtkns@users.noreply.github.com>
Co-authored-by: Adam Watkins <32209255+awtkns@users.noreply.github.com>
@agallant
Copy link
Contributor Author

Makes sense, thanks! Added the suggested changes.

@awtkns awtkns merged commit 0eb9f0a into awtkns:master Jan 11, 2021
awtkns added a commit that referenced this pull request Jan 11, 2021
awtkns added a commit that referenced this pull request Jan 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fast-apicrudrouter not working on Python 3.8
2 participants