From b5feed66f9693a9555830eb169cad39538bbe9e2 Mon Sep 17 00:00:00 2001 From: Devon Fulcher <24593113+DevonFulcher@users.noreply.github.com> Date: Tue, 15 Oct 2024 11:52:11 -0500 Subject: [PATCH] Downgrade pydantic in dev env (#355) ### Description This PR makes type-checking more consistent for local development. I have had an annoying issue with the type-checker reporting errors that weren't appearing in CI. Initially, I thought this was a problem with mypy, but actually the problem was that I have been using Pydantic 2, but the types in the codebase are only compatible with Pydantic 1. Specifically, I was getting a lot of errors for properties like `extra_detail` that don't have a default value: ``` class ValidationIssue(ABC, BaseModel): """The abstract base ValidationIssue class that the specific ValidationIssue classes are built from.""" message: str context: Optional[ValidationContext] = None extra_detail: Optional[str] ``` ### Checklist - [x] I have read [the contributing guide](https://github.com/dbt-labs/dbt-semantic-interfaces/blob/main/CONTRIBUTING.md) and understand what's expected of me - [x] I have signed the [CLA](https://docs.getdbt.com/docs/contributor-license-agreements) - [x] This PR includes tests, or tests are not required/relevant for this PR - [x] I have run `changie new` to [create a changelog entry](https://github.com/dbt-labs/dbt-semantic-interfaces/blob/main/CONTRIBUTING.md#adding-a-changelog-entry) --------- Co-authored-by: Courtney Holcomb --- .../unreleased/Under the Hood-20241010-164927.yaml | 6 ++++++ dsi_pydantic_shim.py | 10 ++++++++++ pyproject.toml | 9 ++++----- 3 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 .changes/unreleased/Under the Hood-20241010-164927.yaml diff --git a/.changes/unreleased/Under the Hood-20241010-164927.yaml b/.changes/unreleased/Under the Hood-20241010-164927.yaml new file mode 100644 index 00000000..17b2a295 --- /dev/null +++ b/.changes/unreleased/Under the Hood-20241010-164927.yaml @@ -0,0 +1,6 @@ +kind: Under the Hood +body: Downgrade Pydantic in dev-env +time: 2024-10-10T16:49:27.844308-05:00 +custom: + Author: DevonFulcher + Issue: None diff --git a/dsi_pydantic_shim.py b/dsi_pydantic_shim.py index 3ea00720..9c333cbf 100644 --- a/dsi_pydantic_shim.py +++ b/dsi_pydantic_shim.py @@ -1,3 +1,13 @@ +"""Shim to allow support for both Pydantic 1 and Pydantic 2. + +DSI must support both major versions of Pydantic because dbt-core depends on DSI. dbt-core users might be using an +environment with either version, and we can't restrict them to one or the other. Here, we essentially import all +Pydantic objects from version 1. Throughout the repo, we import those objects from this file instead of from Pydantic +directly, meaning that we essentially only use Pydantic 1 in this repo, but without forcing that restriction on dbt +users. The development environment for this repo should be pinned to Pydantic 1 to ensure devs get appropriate type +hints. +""" + from importlib.metadata import version pydantic_version = version("pydantic") diff --git a/pyproject.toml b/pyproject.toml index 2fc2a9af..7710213b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,9 +6,7 @@ readme = "README.md" requires-python = ">=3.8" license = "Apache-2.0" keywords = [] -authors = [ - { name = "dbt Labs", email = "info@dbtlabs.com" }, -] +authors = [{ name = "dbt Labs", email = "info@dbtlabs.com" }] classifiers = [ "Development Status :: 4 - Beta", "License :: OSI Approved :: Apache Software License", @@ -66,7 +64,8 @@ dependencies = [ "isort>=5.12,<6", "black>=23.3,<24", "ruff==0.0.260", - "mypy>=1.3,<2", + "mypy==1.6.1", + "pydantic>=1.10,<2", # The types in this codebase with mypy checker are only compatible with pydantic 1 "pytest>=7.3,<8", "types-Jinja2>=2.11,<3", "types-jsonschema>=4.17,<5", @@ -86,7 +85,7 @@ ignore = [ # Missing docstring in public module -- often docs handled within classes "D100", # Missing docstring in public package -- often docs handled within files not __init__.py - "D104" + "D104", ] # Let ruff autofix these errors. # F401 - Unused imports.