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

Fideslang Pydantic V2 Upgrade #11

Merged
merged 49 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from 48 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
197b889
Pin pydantic to 2.7.1
pattisdr Jun 14, 2024
a644507
Replace "class Config" with "model_config" which is a ConfigDict. "o…
pattisdr Jun 14, 2024
5cf361f
root_validator has been deprecated in favor of model_validator
pattisdr Jun 14, 2024
6c1be96
@validator has been deprecated in favor of field_validator
pattisdr Jun 14, 2024
51332a3
Add missing field_validator, model_validator, and ConfigDict imports.
pattisdr Jun 14, 2024
d7323eb
Update some @validator -> @field_validator changes that bump-pydantic…
pattisdr Jun 14, 2024
0c06a15
Adjust DefaultModel.validate_version_added and validate_version_depre…
pattisdr Jun 14, 2024
4bbd059
Convert DatasetField.validate_object_fields from a field_validator to…
pattisdr Jun 14, 2024
20081c1
Transform System.privacy_declarations_reference_data_flows from a fie…
pattisdr Jun 14, 2024
912b9a9
Fields that were marked Optional used to not be required. Now this j…
pattisdr Jun 14, 2024
af4aef3
First attempt at replacing deprecated FidesVersion.__get_validators__…
pattisdr Jun 14, 2024
9b1ce39
Add required field mode="after" to model_validator.
pattisdr Jun 14, 2024
9531c9a
Remove skip_on_failure=True from model_validator, which is an unexpec…
pattisdr Jun 14, 2024
c49f7af
Redefine FidesKey using Annotated[Str, StringConstraints(pattern=...)
pattisdr Jun 14, 2024
48e3bbf
Organization tests failed because name_field and description_field do…
pattisdr Jun 14, 2024
07def94
Update all instances of model_validator(mode="after") to mode=before …
pattisdr Jun 14, 2024
c1f407e
Continued changes to get pytest tests/fideslang/test_models.py running.
pattisdr Jun 14, 2024
171307c
Revert some of the defaults for Optional[bool] fields, making them No…
pattisdr Jun 14, 2024
69bc988
Very shaky changes. FidesVersion is not always the type I expect it t…
pattisdr Jun 15, 2024
d194ba6
Update deprecated methods that won't be removed until v3
pattisdr Jun 15, 2024
7f03b22
Update how FidesKey is to defined to use Annotated and a BeforeValida…
pattisdr Jun 16, 2024
a0bc3ec
Likewise, update definition of FidesCollectionKey be a custom type us…
pattisdr Jun 16, 2024
21eb4b2
Get rid of FidesVersion entirely - it's not being used as a pydantic …
pattisdr Jun 16, 2024
3fa9cb7
update requirements file, remove python 3.8 and add 3.12 to supported…
ThomasLaPiana Nov 14, 2023
abc66ec
Add 2.7.1 to pydantic matrix -
pattisdr Jun 16, 2024
51af7dd
Remove python 3.12 support
pattisdr Jun 16, 2024
b35343f
Use Python 3.9 in the base dockerfile
pattisdr Jun 16, 2024
3fb3d43
Uninstall bump-pydantic - no longer necessary after using it to start…
pattisdr Jun 16, 2024
7a01971
Fix: Name field is not nullable in every location.
pattisdr Jun 16, 2024
221db2b
Linting
pattisdr Jun 16, 2024
747a460
Formatting
pattisdr Jun 16, 2024
4f4a302
Fix pyyaml typo.
pattisdr Jun 16, 2024
922417a
Fix validator order discovered when testing that new-style validators…
pattisdr Jun 17, 2024
3656a14
Update existing tests to make sure they're still testing what we inte…
pattisdr Jun 17, 2024
5557236
Update types.
pattisdr Jun 17, 2024
eb37c7d
Certain versions have a space in this error message, some don't. Shor…
pattisdr Jun 17, 2024
761fd61
Bump to Pydantic 2.3.0 as lowest version supported
pattisdr Jun 17, 2024
b2cc053
Switch FidesKey to use an AfterValidator so strings are validated bef…
pattisdr Jun 23, 2024
b37aa75
Convert remaining model validators in "before" mode to use after mode…
pattisdr Jun 24, 2024
27a5e15
For backwards compat, coerce SystemMetadata endpoint ports from integ…
pattisdr Jun 26, 2024
63b3816
Add AnyUrlString to Fideslang which returns a string instead of a Url…
pattisdr Jul 5, 2024
c692bcf
Wrap usages of AnyUrlString with SerializeAsAny to suppress Pydantic…
pattisdr Jul 11, 2024
797662a
Adjust mkdocks Dockerfile to use 3.9 instead of 3.8.
pattisdr Jul 15, 2024
2184527
Update behavior so AnyUrlSting removes trailing slash by default, as …
pattisdr Jul 15, 2024
891ef24
Get clear on when trailing slash is actually added - revert behavior …
pattisdr Jul 16, 2024
412424a
Further add test coverage.
pattisdr Jul 16, 2024
b27bf03
Fix pylint.
pattisdr Jul 16, 2024
4c2b6e5
Upgrade mypy
pattisdr Jul 19, 2024
97bd9e1
Update changelog.
pattisdr Aug 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/pr_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ jobs:
Pytest-Matrix:
strategy:
matrix:
python_version: ["3.8", "3.9", "3.10", "3.11"]
pydantic_version: ["1.8.2", "1.9.2", "1.10.9"]
pyyaml_version: ["5.4.1", "6.0"]
python_version: ["3.9", "3.10", "3.11"]
pydantic_version: ["2.3.0", "2.4.2", "2.5.3", "2.6.4", "2.7.1"]
pyyaml_version: ["5.4.1", "6.0.1"]
pattisdr marked this conversation as resolved.
Show resolved Hide resolved
runs-on: ubuntu-latest
continue-on-error: true
steps:
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.8-slim-bullseye as base
FROM python:3.9-slim-bullseye as base

# Update pip in the base image since we'll use it everywhere
RUN pip install -U pip
Expand Down
6 changes: 3 additions & 3 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
black==23.3.0
mypy==1.4.0
mypy==1.10.0
nox>=2023
packaging>=22.0
pre-commit==2.9.3
pre-commit==3.7.1
pylint==2.10.0
pytest==7.3.1
pytest-cov==2.11.1
requests-mock==1.8.0
setuptools>=64.0.2
types-PyYAML
xenon==0.7.3
xenon==0.9.1
pattisdr marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion mkdocs/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.8-slim-bullseye
FROM python:3.9-slim-bullseye

# Install auxiliary software
RUN apt-get update
Expand Down
7 changes: 4 additions & 3 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
nox.options.sessions = []
nox.options.reuse_existing_virtualenvs = True

TESTED_PYTHON_VERSIONS = ["3.8", "3.9", "3.10", "3.11"]
TESTED_PYDANTIC_VERSIONS = ["1.8.2", "1.9.2", "1.10.9"]
TESTED_PYYAML_VERSIONS = ["5.4.1", "6.0"]
# These should match what is in the `pr_checks.yml` file for CI runs
TESTED_PYTHON_VERSIONS = ["3.9", "3.10", "3.11"]
TESTED_PYDANTIC_VERSIONS = ["2.3.0", "2.4.2", "2.5.3", "2.6.4", "2.7.1"]
TESTED_PYYAML_VERSIONS = ["5.4.1", "6.0.1"]


def install_requirements(session: nox.Session) -> None:
Expand Down
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ name = "fideslang"
description = "Fides Taxonomy Language"
dynamic = ["dependencies", "version"]
readme = "README.md"
requires-python = ">=3.8, <4"
requires-python = ">=3.9, <4"
authors = [{ name = "Ethyca, Inc.", email = "fidesteam@ethyca.com" }]
license = { text = "Apache License 2.0" }
classifiers = [
"License :: OSI Approved :: Apache Software License",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pydantic>=1.8.1,<1.11.0
pydantic>=2.3.0,<=2.7.1
pyyaml>=5,<7
pattisdr marked this conversation as resolved.
Show resolved Hide resolved
packaging>=20.0
2 changes: 1 addition & 1 deletion src/fideslang/default_taxonomy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ def default_factory(taxonomy_class: CustomType, **kwargs: Dict) -> CustomType:
# This is the version where we started tracking from, so
# we use it as the default starting point.
kwargs["version_added"] = "2.0.0" # type: ignore[assignment]
item = taxonomy_class.parse_obj(kwargs)
item = taxonomy_class.model_validate(kwargs)
pattisdr marked this conversation as resolved.
Show resolved Hide resolved
return item
16 changes: 8 additions & 8 deletions src/fideslang/gvl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,16 @@ def _load_data() -> None:
) as mapping_file:
data = load(mapping_file)
for raw_purpose in data["purposes"].values():
purpose = Purpose.parse_obj(raw_purpose)
mapped_purpose = MappedPurpose.parse_obj(raw_purpose)
purpose = Purpose.model_validate(raw_purpose)
mapped_purpose = MappedPurpose.model_validate(raw_purpose)
GVL_PURPOSES[purpose.id] = purpose
MAPPED_PURPOSES[mapped_purpose.id] = mapped_purpose
for data_use in mapped_purpose.data_uses:
MAPPED_PURPOSES_BY_DATA_USE[data_use] = mapped_purpose

for raw_special_purpose in data["specialPurposes"].values():
special_purpose = Purpose.parse_obj(raw_special_purpose)
mapped_special_purpose = MappedPurpose.parse_obj(raw_special_purpose)
special_purpose = Purpose.model_validate(raw_special_purpose)
mapped_special_purpose = MappedPurpose.model_validate(raw_special_purpose)
GVL_SPECIAL_PURPOSES[special_purpose.id] = special_purpose
MAPPED_SPECIAL_PURPOSES[mapped_special_purpose.id] = mapped_special_purpose
for data_use in mapped_special_purpose.data_uses:
Expand All @@ -71,12 +71,12 @@ def _load_data() -> None:
feature_data = load(feature_mapping_file)

for raw_feature in feature_data["features"].values():
feature = Feature.parse_obj(raw_feature)
feature = Feature.model_validate(raw_feature)
GVL_FEATURES[feature.id] = feature
FEATURES_BY_NAME[feature.name] = feature

for raw_special_feature in feature_data["specialFeatures"].values():
special_feature = Feature.parse_obj(raw_special_feature)
special_feature = Feature.model_validate(raw_special_feature)
GVL_SPECIAL_FEATURES[special_feature.id] = special_feature
FEATURES_BY_NAME[special_feature.name] = special_feature

Expand All @@ -86,8 +86,8 @@ def _load_data() -> None:
data_category_data = load(data_category_mapping_file)

for raw_data_category in data_category_data.values():
data_category = GVLDataCategory.parse_obj(raw_data_category)
mapped_data_category = MappedDataCategory.parse_obj(raw_data_category)
data_category = GVLDataCategory.model_validate(raw_data_category)
mapped_data_category = MappedDataCategory.model_validate(raw_data_category)
GVL_DATA_CATEGORIES[data_category.id] = data_category
MAPPED_GVL_DATA_CATEGORIES[mapped_data_category.id] = mapped_data_category

Expand Down
3 changes: 2 additions & 1 deletion src/fideslang/gvl/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ class MappedPurpose(Purpose):


class Feature(BaseModel):
"Pydantic model for GVL feature records"
"""Pydantic model for GVL feature records"""

id: int = Field(description="Official GVL feature ID or special feature ID")
name: str = Field(description="Name of the GVL feature or special feature.")
description: str = Field(
Expand Down
Loading
Loading