Git Product home page Git Product logo

Comments (11)

Wolfhound905 avatar Wolfhound905 commented on June 1, 2024

Just to clarify, this is only happening after upgrading to the Pydantic v2 release.

from beanie.

Wolfhound905 avatar Wolfhound905 commented on June 1, 2024

I have narrowed it down to the parse_model function in beanie/odm/utils/pydantic.py line 42

def parse_model(model_type: Type[BaseModel], data: Any):
    if IS_PYDANTIC_V2:
        return model_type.model_validate(data)
    else:
        return model_type.parse_obj(data)

The data that goes in there looks good. But then comes out wrong. (referring to the int64s)

from beanie.

Wolfhound905 avatar Wolfhound905 commented on June 1, 2024

With some even more digging, it seems that I was able to make the output match what is expected with the following bson_encoders

class TestCollection(Document):
    test: int

    class Settings:
        bson_encoders = {int: lambda x: str(x)}

from beanie.

roman-right avatar roman-right commented on June 1, 2024

Thank you for the cath!

from beanie.

Wolfhound905 avatar Wolfhound905 commented on June 1, 2024

No problem, I love this library so I wanted to help as much as I could.

from beanie.

roman-right avatar roman-right commented on June 1, 2024

Woah. It looks like it happens somewhere inside Pydantic. But at the same time I can not reproduce it with pure Pydantic. What a black magic! :)

from beanie.

roman-right avatar roman-right commented on June 1, 2024

Ah, no. I can.

from bson import Int64
from pydantic import BaseModel


class A(BaseModel):
    i: int


a = A.model_validate({"i": Int64(1136885225876639845)})

print(a.i)

from beanie.

roman-right avatar roman-right commented on June 1, 2024

I've opened an issue: pydantic/pydantic#7201

from beanie.

roman-right avatar roman-right commented on June 1, 2024

I believe it got fixed on the Pydantic side

from beanie.

Wolfhound905 avatar Wolfhound905 commented on June 1, 2024

This issue can be closed if or when Beanies dependencies are up to date.

from beanie.

github-actions avatar github-actions commented on June 1, 2024

This issue is stale because it has been open 30 days with no activity.

from beanie.

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.