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

Mongo ObjectId fields issue #102

Open
ngdbao opened this issue May 16, 2024 · 0 comments
Open

Mongo ObjectId fields issue #102

ngdbao opened this issue May 16, 2024 · 0 comments

Comments

@ngdbao
Copy link

ngdbao commented May 16, 2024

While _id is not only ObjectId field in most collection, any other objectId may cause below error:

│                                                                              │
│ /usr/local/lib/python3.12/json/encoder.py:180 in default                     │
│                                                                              │
│   177 │   │   │   │   return JSONEncoder.default(self, o)                    │
│   178 │   │                                                                  │
│   179 │   │   """                                                            │
│ ❱ 180 │   │   raise TypeError(f'Object of type {o.__class__.__name__} '      │
│   181 │   │   │   │   │   │   f'is not JSON serializable')                   │
│   182 │                                                                      │
│   183 │   def encode(self, o):                                               │
│                                                                              │
│ ╭────────────────────────── locals ──────────────────────────╮               │
│ │    o = ObjectId('637e1e913e9e101f8f9150b5')                │               │
│ │ self = <json.encoder.JSONEncoder object at 0x7ab18389f770> │               │
│ ╰────────────────────────────────────────────────────────────╯               │
╰──────────────────────────────────────────────────────────────────────────────╯
TypeError: Object of type ObjectId is not JSON serializable

So, It would be better if we can define stringify some fields right in config.yml, example like this:

  - table: picture
    index: beauty-pictures
    full: true
    fields:
      id: str(id)
      uid: str(id)
      description: description
      category: category
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

1 participant