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

Extraneous local_kw added to mandatory arguments in swagger #20

Open
AntonyM71 opened this issue Aug 28, 2022 · 9 comments
Open

Extraneous local_kw added to mandatory arguments in swagger #20

AntonyM71 opened this issue Aug 28, 2022 · 9 comments

Comments

@AntonyM71
Copy link

Hi all, I've noticed that this seems to appear in the swagger documentation, I've not specified it

image

I've tried posting using thunder client, and without a 'local_kw" a 422 error is returned, however if it's specified we get Session.__init__() got an unexpected keyword argument 'local_kw'

@LuisLuii
Copy link
Owner

LuisLuii commented Aug 28, 2022

Hi could you share some infomation to let me reproduce your issue? such as the SQLalchemy schema, and the code

@AntonyM71
Copy link
Author

Hi Luis, I've been using the User Model from the first demo.

class User(Base):
    __tablename__ = 'test_users'
    id = Column(Integer, primary_key=True, autoincrement=True, unique=True)
    name = Column(String, nullable=False)
    email = Column(String, nullable=False)

crud_route_1 = crud_router_builder(db_model=User,
                                   prefix="/user",
                                   tags=["User"],
                                    db_session=session,
                                    sql_type=SqlType("postgresql"),
                                #    async_mode=True
                                   )


app = FastAPI()
app.include_router(crud_route_1)

Initially I thought it was due to an environment clash, as I was using Conda with pip dependencies, however the issue seems to persist when the versions are pinned to those in the Readme, and even with only fastapi-quickcrud in the environment.

I've tried recreating your "Simple Code" example in another file, and even with only fastapi-quickcrud in the environment the issue seems to be there. The only changes I made were to point at a postrgess database, with

    db_session=session,
    sql_type=SqlType("postgresql"),

@LuisLuii
Copy link
Owner

LuisLuii commented Aug 29, 2022

many thanks Antony, I still no idea about the local_kw , btw could you run that normally without set the session like the following example, which is using in-memory db
https://github.com/LuisLuii/FastAPIQuickCRUD/blob/main/tutorial/sample.py
or could you share your full code that includes the session part of code.

@AntonyM71
Copy link
Author

Hi Luis,

Running the example at https://github.com/LuisLuii/FastAPIQuickCRUD/blob/main/tutorial/sample.py works fine, so I'll use that for now :)

@AntonyM71
Copy link
Author

AntonyM71 commented Sep 10, 2022

Looking back to postures integration, it seems that the local_kw appears when we add the following lines to our model

     db_session=async_session,
     sql_type=SqlType("postgresql"),

e.g. from:

crud_route_child = generic_sql_crud_router_builder(
    db_model=Child,
    prefix="/child",
    tags=["child"],
)

to :

crud_route_child = generic_sql_crud_router_builder(
    db_model=Child,
    prefix="/child",
    tags=["child"],
    db_session=async_session,
    sql_type=SqlType("postgresql"),
)

for reference, the async session is:

engine = create_engine("postgresql://xxxx:[email protected]/xxxxx")
session = sessionmaker(engine)

async_session = sessionmaker(
    autocommit=False,
    autoflush=False,
    bind=engine,
)

@LuisLuii
Copy link
Owner

LuisLuii commented Sep 10, 2022

Thanks Antony! I have reproduced it based on your information. And It is due to my documentation is not clear enough.

I saw you has used the async_session to be db_session argument. The correct way is like the following

engine = create_engine("postgresql://xxxx:[email protected]/xxxxx")
session = sessionmaker(engine)

def get_transaction_session():
    try:
        db = session()
        yield db
    finally:
        db.close()

crud_route_child = generic_sql_crud_router_builder(
    db_model=Child,
    prefix="/child",
    tags=["child"],
    db_session= get_transaction_session,
    sql_type=SqlType("postgresql"),
)

@Avin-Techv
Copy link

I am facing almost the same issue, I am also seeing local_kw in one of my api endpoint, any specific solution ?

@AntonyM71
Copy link
Author

The changes Luis suggested in #20 (comment) worked fine for me. And I've been using the libraries without issues

@LuisLuii
Copy link
Owner

LuisLuii commented Jan 4, 2024

The changes Luis suggested in #20 (comment) worked fine for me. And I've been using the libraries without issues

Hi Avin, sorry for reply so late, so happy to see you are using it fine. I will suggest u to try my another crud code generator project. Which one is optimised on query and able to maintain by yourself. I have used it in few project already and working so far so good.

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

No branches or pull requests

3 participants