Git Product home page Git Product logo

Comments (7)

vsdudakov avatar vsdudakov commented on May 26, 2024

  File "C:\Users\Владислав\PycharmProjects\mitsu_api\virtualenv\Lib\site-packages\fastadmin\api\frameworks\fastapi\api.py", line 329, in configuration
    return await api_service.get_configuration(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Владислав\PycharmProjects\mitsu_api\virtualenv\Lib\site-packages\fastadmin\api\service.py", line 414, in get_configuration
    current_user_id = await get_user_id_from_session_id(session_id)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Владислав\PycharmProjects\mitsu_api\virtualenv\Lib\site-packages\fastadmin\api\service.py", line 62, in get_user_id_from_session_id
    if not user_id or not await admin_model.get_obj(user_id):
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Владислав\PycharmProjects\mitsu_api\virtualenv\Lib\site-packages\fastadmin\models\base.py", line 415, in get_obj
    obj = await self.orm_get_obj(id)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Владислав\PycharmProjects\mitsu_api\virtualenv\Lib\site-packages\fastadmin\models\orms\sqlalchemy.py", line 314, in orm_get_obj
    return await session.get(self.model_cls, id)

from fastadmin.

vsdudakov avatar vsdudakov commented on May 26, 2024

Investigation:

  • we get configuration after sign in to render UI
  • we get current_user_id from session (jwt token which we store in http only cookies)
    current_user_id = await get_user_id_from_session_id(session_id) (fastadmin\api\service.py, line 447)

In get_user_id_from_session_id:

    user_id = convert_id(user_id)
    if not user_id or not await admin_model.get_obj(user_id):
        return None

After a fix in 0.1.37 we have convert_id and get_obj should receive int | UUID not string

get_obj -> orm_get_obj (SQL Alchemy orm)

    async def orm_get_obj(self, id: UUID | int) -> Any | None:
        sessionmaker = self.get_sessionmaker()
        async with sessionmaker() as session:
            return await session.get(self.model_cls, id)

from fastadmin.

vsdudakov avatar vsdudakov commented on May 26, 2024

My suggestion is to change the code >>https://github.com/vsdudakov/fastadmin/blob/f618ac98f8f50f5cddf835139ca626fe6c2e7/fastadmin/api/service.py#L121:
"user_id": str(user_id),
To:
"user_id": user_id,

And add this code before return:

if isinstance(user_id, UUID) :
user_id = str(user_id)

I will try the solution. Thank you!

from fastadmin.

vsdudakov avatar vsdudakov commented on May 26, 2024

0.1.37...0.1.38
@kuyugama Provided your solution in 0.1.38. Hope it will help.

from fastadmin.

kuyugama avatar kuyugama commented on May 26, 2024

Investigation:

  • we get configuration after sign in to render UI
  • we get current_user_id from session (jwt token which we store in http only cookies)
    current_user_id = await get_user_id_from_session_id(session_id) (fastadmin\api\service.py, line 447)

In get_user_id_from_session_id:

    user_id = convert_id(user_id)
    if not user_id or not await admin_model.get_obj(user_id):
        return None

After a fix in 0.1.37 we have convert_id and get_obj should receive int | UUID not string

get_obj -> orm_get_obj (SQL Alchemy orm)

    async def orm_get_obj(self, id: UUID | int) -> Any | None:
        sessionmaker = self.get_sessionmaker()
        async with sessionmaker() as session:
            return await session.get(self.model_cls, id)

Converting id to a number after it has been converted to a string is a bad decision. Because you can store id already in the desired data type

from fastadmin.

vsdudakov avatar vsdudakov commented on May 26, 2024

Agreed but it doesn't work for UUID , could you please check 0.1.38?

from fastadmin.

vsdudakov avatar vsdudakov commented on May 26, 2024

In case it works I will clean up code and remove convert_id keep it only for UUID may be

from fastadmin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.