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

Example doesn't work #49

Closed
aldoshkind opened this issue Dec 2, 2023 · 2 comments
Closed

Example doesn't work #49

aldoshkind opened this issue Dec 2, 2023 · 2 comments

Comments

@aldoshkind
Copy link

Hello!
I am getting familiar with pydantic-mongo and I faced problems with example:

pydantic.errors.PydanticUserError: A non-annotated attribute was detected: `apple = 'x'`. All model fields require a type annotation; if `apple` is not meant to be a field, you may be able to resolve this error by annotating it as a `ClassVar` or updating `model_config['ignored_types']`.

and

    more_edges = spam_repository.paginate({'foo.count': {'$gte': 1}}, limit=1, after=edges[-1].cursor)
TypeError: 'map' object is not subscriptable

Python and packages versions are:
Python 3.10.12
pydantic 2.4.1
pydantic_core 2.10.1
pydantic-mongo 2.0.3
pymongo 4.6.1

What am I doing wrong?
Thanks!

Artucuno added a commit to Artucuno/pydantic-mongo that referenced this issue Dec 3, 2023
@Artucuno
Copy link
Contributor

Artucuno commented Dec 3, 2023

Added a simpler method for pagination. (#45)

Here is an example of how to use it:

edges = spam_repository.paginate_simple({'foo.count': {'$gte': 1}}, limit=25, page=1)
print(edges)
print(len(edges))

Output:

>>> [Spam(id=ObjectId('656bef2c3da1ab2e5e160522'), foo=Foo(count=1, size=1.0), bars=[Bar(apple='x', banana='y')]), ...]
>>> 25

You can use pip install -U git+https://github.com/jefersondaniel/pydantic-mongo.git@refs/pull/45/head to test it out.

@jefersondaniel
Copy link
Owner

I'm closing this since the readme example was fixed in the latest version

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

3 participants