Comments (11)
Just to clarify, this is only happening after upgrading to the Pydantic v2 release.
from beanie.
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.
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.
Thank you for the cath!
from beanie.
No problem, I love this library so I wanted to help as much as I could.
from beanie.
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.
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.
I've opened an issue: pydantic/pydantic#7201
from beanie.
I believe it got fixed on the Pydantic side
from beanie.
This issue can be closed if or when Beanies dependencies are up to date.
from beanie.
This issue is stale because it has been open 30 days with no activity.
from beanie.
Related Issues (20)
- [BUG] Fetching Links in view raises AttributeError: _database_major_version HOT 2
- [BUG] Double return in sources code of class beanie.odm.fields.Link HOT 4
- [BUG] Beanie projection and Pydantic Schema do not play well together HOT 6
- [BUG] before_event not working with validate_on_save = True HOT 2
- [BUG] ModuleNotFoundError when importing models in a migration module HOT 1
- [BUG]before_event bug HOT 4
- [BUG] Missing documentation for `beanie.odm.BulkWriter` HOT 1
- [BUG] (some) type annotations for session wrong HOT 3
- [BUG] type annotation for init_beanie() should use Sequence
- [BUG] before_event of type Update HOT 4
- [BUG] mypy does not raise error when trying to access a non-existing attribute from a beanie Document. HOT 1
- [BUG] Indexed unique will not work after Field regex. HOT 1
- [BUG] Empty BackLink for `Optional[BackLink[ADoc]]` when document has no back-link HOT 2
- Concerns and Suggestions Regarding Beanie Library HOT 2
- [Doc] Document for soft delete feature
- [BUG] Order of elements in list[Link] is not preserved HOT 1
- [BUG] pydantic computed properties omitted during `insert_many` operation on Document
- [BUG] get_motor_collection() returning None under volume only HOT 1
- [BUG] search criteria not using pydantic Field alias to set the key.
- [BUG] `PydanticObjectId` isn't properly configured when deserializing from JSON
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from beanie.