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

Task & TaskInfo datetime consistency #661

Merged
merged 7 commits into from
Jan 30, 2023

Conversation

Azanul
Copy link
Contributor

@Azanul Azanul commented Jan 23, 2023

Pull Request

Related issue

Fixes #615

What does this PR do?

  • Adds datetime type consistency across the SDK
  • Adapts corresponding tests

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?

Copy link
Collaborator

@sanders41 sanders41 left a comment

Choose a reason for hiding this comment

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

Importing datetime should fix the current test failures.

from datetime import datetime

There is a chance there will be mypy errors after making this change so I would suggest running both the test suite and mypy after making the change to see if anything comes up.

meilisearch/models/task.py Outdated Show resolved Hide resolved
@Azanul
Copy link
Contributor Author

Azanul commented Jan 23, 2023

@sanders41 So how do I decide whether a given argument is going to be Optional[datetime], datetime or Union[datetime, str] or even Optional[str] ?

@sanders41
Copy link
Collaborator

I used a combination of the docs and looking at the output to figure it all out. If helpful I have all this setup here.

@Azanul
Copy link
Contributor Author

Azanul commented Jan 23, 2023

@sanders41 Should I remove str from other argument type hints as well (which follow RFC3339) ?

@sanders41
Copy link
Collaborator

@sanders41 Should I remove str from other argument type hints as well (which follow RFC3339) ?

Unfortunately it's not a completely straight forward answer. The TLDR is any datetime referenced from Task or TaskInfo could drop the str. If there are other models or dictionaries that aren't converted to models that have fields for RFC3339 data they will be strings because they will not get converted to datetime.

@alallema I'll put the reason below to get your input.

datetime only works on the models that use CamelBase. CamelBase extends PydanticBase adding the conversion to/from camel case/snake case. So for example when enqueuedAt comes in in the json CamelBase converts it to enqueued_at.

The other thing CamelBase is doing is type coercion and validation based on the type hint supplied (this happens on all fields, not just the ones converted to camel case). This means during serialization the RFC3339 string gets validated and will be converted from a string a datetime if the type hint is datetime.

Currently CamelBase is only used on Task and TaskInfo so these are the only two places datetime will work.

@Azanul
Copy link
Contributor Author

Azanul commented Jan 24, 2023

Understood

@Azanul Azanul marked this pull request as ready for review January 24, 2023 04:41
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.

Thanks, @Azanul for this PR! And thanks, @sanders41, for your reviews, your explanations and for taking care of this repo 😊 ❤️
LGTM! 🎉

@alallema
Copy link
Contributor

bors merge

@bors
Copy link
Contributor

bors bot commented Jan 30, 2023

@bors bors bot merged commit ce9f60e into meilisearch:main Jan 30, 2023
@alallema alallema added the breaking-change The related changes are breaking for the users label Feb 6, 2023
bors bot added a commit that referenced this pull request Feb 6, 2023
678: Update version for the next release (v0.24.0) r=alallema a=alallema

This version makes this package compatible with Meilisearch v1.0.0 🎉
Check out the changelog of [Meilisearch v1.0.0](https://github.com/meilisearch/meilisearch/releases/tag/v1.0.0) for more information on the changes(#635).

## ⚠️ Breaking changes

* Make the usage of the module typing consistent (#625) `@pbrochar`
* Put all dates to `datetime` type for consistency. Class impacted: `Task` and `TasInfo` (#661) `@Azanul`
* Change `details` fields in `Task` class `Dict[str, Any]` -> `Union[Dict[str, Any], None]` (#664) `@Azanul`

## 🚀 Enhancements

* Added `update_documents_csv(str_documents: str, primary_key: Optional[str] = None) -> TaskInfo` (#654) `@sajdakabir`

## 🐛 Bug Fixes

* Include py.typed in package build (#637) `@sanders41`

Thanks again to `@Azanul,` `@alallema,` `@pbrochar,` `@sajdakabir,` `@sanders41!` 🎉



Co-authored-by: alallema <amelie@meilisearch.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change The related changes are breaking for the users
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consistency in datetime
3 participants