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

Bug: ID pk gives JSON serialization error when excluded from the list #564

Open
jhq223 opened this issue Jul 31, 2024 · 1 comment
Open
Labels
bug Something isn't working

Comments

@jhq223
Copy link

jhq223 commented Jul 31, 2024

Describe the bug
ID pk gives JSON serialization error when excluded from the list

  File "D:\Documents\Code\Python\starlette-admin\.venv\Lib\site-packages\starlette\responses.py", line 184, in __init__
    super().__init__(content, status_code, headers, media_type, background)
  File "D:\Documents\Code\Python\starlette-admin\.venv\Lib\site-packages\starlette\responses.py", line 41, in __init__
    self.body = self.render(content)
                ^^^^^^^^^^^^^^^^^^^^
  File "D:\Documents\Code\Python\starlette-admin\.venv\Lib\site-packages\starlette\responses.py", line 187, in render
    return json.dumps(
           ^^^^^^^^^^^
  File "D:\.ENV\Python\Lib\json\__init__.py", line 238, in dumps
    **kw).encode(obj)
          ^^^^^^^^^^^
  File "D:\.ENV\Python\Lib\json\encoder.py", line 200, in encode
    chunks = self.iterencode(o, _one_shot=True)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\.ENV\Python\Lib\json\encoder.py", line 258, in iterencode
    return _iterencode(o, 0)
           ^^^^^^^^^^^^^^^^^
  File "D:\.ENV\Python\Lib\json\encoder.py", line 180, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type ObjectId is not JSON serializable

To Reproduce
Add id to exclude_fields_from_list

# Add views
class UserView(ModelView):
    exclude_fields_from_list = ["id"]

run uvicorn examples.mongoengine.app:app
An exception will be thrown when the user data table has data.

Environment (please complete the following information):

  • starlette-admin>=0.14.1
  • uvicorn>=0.30.3
  • mongoengine>=0.28.2
  • ORM/ODMs: MongoEngine
  • python: 3.12.4

Additional context
This error is similar to that #552

@jhq223 jhq223 added the bug Something isn't working label Jul 31, 2024
@jowilf
Copy link
Owner

jowilf commented Aug 5, 2024

This error is similar to that #552

Yes, we need to implement get_serialized_pk_value for other backends as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants