Closed filipmarkoski closed 2 years ago
I have tested in my environment with your same code with pg version 14 but different AsyncSession generator, and it can run normally and call the api successfully. Can I have your DATABASE_URL and AsyncSession generator code please?
please try to update the library version to 0.1.9.
I have provided the sql_type
argument in crud_router_builder in this version.
can you please try rerun the code with the code as follows?
from fastapi_quickcrud.misc.type import SqlType
QuoteCRUDRouter = crud_router_builder(db_model=Quote,
prefix='/quote', tags=['Quote'],
exclude_columns=['UUID','DateCreated','DateModified','IsActive'],
crud_methods=[CrudMethods.CREATE_ONE],
async_mode=True,
autocommit=False,
db_session=get_transaction_session,
sql_type=SqlType.postgresql
)
and I hope you can provide more detail of your environment to let me reproduce this issue, such as python version, pip list. Thanks so much
DATABASE_URL = 'postgresql+asyncpg://postgres:metamars@localhost:5432/postgres'
engine = create_async_engine(DATABASE_URL,
future=True, echo=True,
pool_use_lifo=True, pool_pre_ping=True, pool_recycle=7200
)
async_session_maker = sessionmaker(engine, class_=AsyncSession,
expire_on_commit=False)
Base: DeclarativeMeta = declarative_base()
async def get_transaction_session() -> AsyncSession:
async with async_session_maker() as session:
async with session.begin():
yield session
I will make a GitHub repository to share all of my code.
Here's a GitHub repository with all of the code. https://github.com/filipmarkoski/fastapi-learning
Also, is there a way to override a certain function, for example, let's say I want to create an instance of a certain model such as Quote, but I also want to perform some machine learning before I insert the record into the database. Is there any way to get the generated code verbatim, which I can edit how I choose afterwards? My question is inspired by the following package: https://pypi.org/project/sqlacodegen/
Your update seemed to work, I am able to post a quote from Swagger now. Thank you! I love the package by the way.
Originally I didn't plan to open sql_type because I wanted to automate it. But it seems like some errors will occur. I'll look into it. Thanks for the issue that made me aware of the bug <3
Also, is there a way to override a certain function, for example, let's say I want to create an instance of a certain model such as Quote, but I also want to perform some machine learning before I insert the record into the database. Is there any way to get the generated code verbatim, which I can edit how I choose afterwards? My question is inspired by the following package: https://pypi.org/project/sqlacodegen/
Sorry, it's not supported yet. But this is what I've always wanted to achieve, I think this feature is a high priority, I will implement it after I complete the #9 .
Root cause: Fastapi project in async mode with auto-reload and crud_router_builder with async mode, but I created an event loop to get the type of the sql connection. Which creates multiple event loops when reload.
SOLVED: Provide sql_type to be declared by the user
I am using a PostgreSQL 14.2-1 Windows x64 database using pgAdmin to which I am connecting to like so:
Using the following SQL script I have made the table
dbo.Quote
, like so:I have also developed an SQLAlchemy model for the
dbo.Quote
postgres table:and I am adding the crud router builder like so
Finally, when I run
I get the following error
Why am I getting this error?
Also, because SQLite does not have schemas, the
__table_args__
in the SQLAlchemy model cause a problem, so what is the issue with that as well?