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

Add support for Pydantic v2 #790

Merged
merged 3 commits into from
Jul 3, 2023
Merged

Add support for Pydantic v2 #790

merged 3 commits into from
Jul 3, 2023

Conversation

sanders41
Copy link
Collaborator

Pull Request

Pydantic v2 was released with several breaking changes. This PR allows users to use Pydantic 2 or Pydantic 1. I went this direction because Pydantic 2 is so new not all packages can use it yet. Because of this I don't think we can drop support for v1 since it would prevent people that still need v1 from using this package.

Related issue

Fixes #789

What does this PR do?

  • Adds support for Pydantic v2

PR checklist

Please check if your PR fulfills the following requirements:

  • Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)?
  • Have you read the contributing guidelines?
  • Have you made sure that the title is accurate and descriptive of the changes?

Thank you so much for contributing to Meilisearch!

Copy link
Contributor

@alallema alallema left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much, @sanders41 for this PR ❤️
I just have a few questions

meilisearch/task.py Outdated Show resolved Hide resolved
Pipfile Show resolved Hide resolved

class Task(CamelBase):
uid: str
uid: int
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this not breaking?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is where my stray print came from with testing this out. It was erroring so I wanted to see the values. uid gets returned from Meilisearch like: {"uid": 123} and not {"uid": "123"}. Pydantic used to convert the int into a string, but now considers this an error since it isn't the correct type.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed the uid is an int. I was surprised we let it as str in the code. but I wonder if it will break something

Copy link
Collaborator Author

@sanders41 sanders41 Jul 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, you mean with people using it, I didn't consider that. Yes, I suppose it could. I was surprised to see it was a str initially also.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's exactly what I meant, anyway the task_uid is well-defined as an int so I think it's better to change it.

Copy link
Contributor

@alallema alallema left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 🎉

@alallema
Copy link
Contributor

alallema commented Jul 3, 2023

bors merge

@meili-bors
Copy link
Contributor

meili-bors bot commented Jul 3, 2023

@sanders41 sanders41 merged commit 4966620 into main Jul 3, 2023
9 checks passed
@sanders41 sanders41 deleted the pydantic2 branch July 3, 2023 13:51
@meili-bot
Copy link
Contributor

This message is sent automatically

Thank you very much for submitting your PR! Did you know that throughout the month of June we’re holding a rafle?
If you share the link to your merged PR in our #giveaway Discord channel, you’ll automatically join a lottery for a chance at winning some Meiliswag. 🙂
Don’t hesitate to join us: https://discord.com/channels/1006923006964154428/1111273670657200198

@alallema alallema added the bug Something isn't working label Jul 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Datetime serialization issue with latest meilisearch and client
3 participants