Skip to content

chore: Update Annotation to Python 3.12 #1034

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

Open
wants to merge 32 commits into
base: main
Choose a base branch
from

Conversation

vukosavljevicNatalija
Copy link

@vukosavljevicNatalija vukosavljevicNatalija commented May 23, 2025

Task

  • Update Annotation to Python 3.12.

Action

  • Upgraded Python version in pyproject.toml, along with the upgrade of some dependencies as a result of this change.
  • Most changes in the code were caused by upgrading Pydantic to v2. The bump-pydantic tool was run to assist the conversion from v1 to v2. However, some changes needed to be performed manually due to issues like this one: pydantic/bump-pydantic#134. Afterward, the code that was using Pydantic schemas was adapted to Pydantic v2.
    Additionally, some issues occurred with numeric constraints when updating to the Pydantic version, and these issues were resolved by using Annotated pydantic-constraint.
  • Regarding FastAPI, versions starting from v0.109.0 have an issue with the root_path parameter. More information can be found in this closed PR. Additionally, there were issues with TestClient that can be solved by using the bump-testclient package.
  • Dev dependencies such as flake8, black, and isort were updated to match the project’s pyproject.toml. Also, moto was updated because the previous version had issues with SSL.
  • The Annotation Dockerfile, pre-commit hooks, and GitHub Actions file were updated to adapt to Python 3.12.
    Furthermore, isort command in Annotation .pre-commit hook was updated to use Annotation folder as a source.
  • Corrected the datetime format from the frontend side for the "Create Task" endpoint in the Jobs tab. The previous datetime format functioned due to less strict criteria in earlier versions of Pydantic. More information about the expected datetime.datetime field format can be found pydatic-datetime.
  • The SQLAlchemy bulk_insert_mappings method was replaced with the bulk ORM insert feature insert due to issues issue in earlier versions of SQLAlchemy 2.*. Additionally, this method is deprecated and will be removed in future versions.

@khyurri khyurri requested a review from Copilot May 30, 2025 11:06
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR upgrades the Annotation service to Python 3.12 and adapts the code to work with Pydantic v2 along with updating dependencies and tooling. Key changes include:

  • Replacing Pydantic v1 methods (.dict()) with their v2 equivalents (.model_dump()), and updating validators to use model_validator.
  • Updating SQLAlchemy bulk insert methods, dependency header examples, and various schema field definitions to use the new “examples” syntax.
  • Bumping dependency versions in the Dockerfile, pre-commit hooks, and GitHub Actions workflow.

Reviewed Changes

Copilot reviewed 36 out of 36 changed files in this pull request and generated 1 comment.

File Description
annotation/annotation/tasks/services.py Converted schema dumping methods and replaced bulk insert mappings with the ORM insert feature.
annotation/annotation/resources.py, schemas, categories, jobs, annotations Updated header and field example parameters and validators to the new Pydantic v2 syntax.
annotation/Dockerfile, .pre-commit-config.yaml, .github/workflows/annotation.yml Upgraded base images, dependency versions, and adjusted install commands for Python 3.12.

@vukosavljevicNatalija vukosavljevicNatalija marked this pull request as draft May 30, 2025 11:11
@vukosavljevicNatalija vukosavljevicNatalija marked this pull request as ready for review June 2, 2025 10:50
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

Successfully merging this pull request may close these issues.

2 participants