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] Beanie persists root field #668

Closed
WingCode opened this issue Aug 21, 2023 · 3 comments
Closed

[BUG] Beanie persists root field #668

WingCode opened this issue Aug 21, 2023 · 3 comments

Comments

@WingCode
Copy link

Describe the bug
Beanie persists root field in the database when using Pydantic RootModel. The root field must not be persisted in the database.

To Reproduce

from typing import List
from motor.motor_asyncio import AsyncIOMotorClient
from pydantic import RootModel
from beanie import Document, init_beanie

Pets = RootModel[List[str]]

class PetDocument(Document):
    content: Pets

async def example():
    client = AsyncIOMotorClient("mongodb://user:pass@host:27017")

    await init_beanie(database=client.db_name, document_models=[PetDocument])

    my_pets = PetDocument(content=["dog", "cat", "fish"])

    await my_pets.insert()

import asyncio
asyncio.run(example())

Expected behavior
In MongoDB it is expected to have record like

{"content": ["dog", "cat", "fish"]

but instead it stores it as

{"content": {"root":["dog", "cat", "fish"]}}
@roman-right
Copy link
Member

Hi! Let me check this Pydantic feature and the doc.

@roman-right roman-right added the bug Something isn't working label Aug 21, 2023
@roman-right
Copy link
Member

Fixed in #669 . Please, try

@roman-right roman-right removed the bug Something isn't working label Sep 10, 2023
@WingCode
Copy link
Author

This has been fixed in #669 . Thank you for looking into it!

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

2 participants