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

DM-40002: Try to support pydantic v1 and v2 #866

Merged
merged 18 commits into from
Jul 19, 2023
Merged

DM-40002: Try to support pydantic v1 and v2 #866

merged 18 commits into from
Jul 19, 2023

Commits on Jul 14, 2023

  1. Fix some tests that require optional dependencies

    We always tend to install the optionals for testing but it
    turns out the import tests were not working properly.
    
    Consider removing S3 completely.
    timj committed Jul 14, 2023
    Configuration menu
    Copy the full SHA
    6eeb67c View commit details
    Browse the repository at this point in the history
  2. Fix types in test to match model

    Somehow pydantic v1 did not notice.
    timj committed Jul 14, 2023
    Configuration menu
    Copy the full SHA
    0bd4a79 View commit details
    Browse the repository at this point in the history

Commits on Jul 17, 2023

  1. Initial attempt to support pydantic v2

    Still some failures. Lots of deprecation warnings.
    timj committed Jul 17, 2023
    Configuration menu
    Copy the full SHA
    2e913d3 View commit details
    Browse the repository at this point in the history
  2. For storage class conversion test use usable storage classes

    AstropyArrow and Dataframe use classes that are not part of
    the core butler dependencies. This leads to the tests failing
    in a minimal environment. Replace with two storage classes
    that are available to the core environment.
    timj committed Jul 17, 2023
    Configuration menu
    Copy the full SHA
    afe26c4 View commit details
    Browse the repository at this point in the history
  3. Remove fastapi pin

    This enables pydantic v2
    timj committed Jul 17, 2023
    Configuration menu
    Copy the full SHA
    7e19163 View commit details
    Browse the repository at this point in the history

Commits on Jul 18, 2023

  1. Use model_construct for pydantic v2

    This is meant to be the rquivalent of using __setattr__
    and __field_set__ directly. The latter has been renamed in
    pydantic v2
    timj committed Jul 18, 2023
    Configuration menu
    Copy the full SHA
    56d2a1e View commit details
    Browse the repository at this point in the history
  2. Use mambaforge for build action

    timj committed Jul 18, 2023
    Configuration menu
    Copy the full SHA
    d3eee16 View commit details
    Browse the repository at this point in the history
  3. Use python 3.11 for doc build

    timj committed Jul 18, 2023
    Configuration menu
    Copy the full SHA
    37afb3f View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    2e129be View commit details
    Browse the repository at this point in the history
  5. Pydantic/fastAPI no longer handle generic Mapping for Config classes

    This all worked before but now we have to force the Config
    to a plain dict before it will be accepted.
    timj committed Jul 18, 2023
    Configuration menu
    Copy the full SHA
    e0894c6 View commit details
    Browse the repository at this point in the history
  6. Fix mypy with pydantic

    There is clearly some issue with the RootModel constructor
    that we will need to sort out.
    timj committed Jul 18, 2023
    Configuration menu
    Copy the full SHA
    e96015d View commit details
    Browse the repository at this point in the history
  7. Fix mypy for pydantic v1 and v2

    This required that we allow unused igores since the location
    of the ignores depends on the version of pydantic and mypy
    always picks up the first definition it sees even if that
    is a pydantic V2 code path and pydantic is v1.
    timj committed Jul 18, 2023
    Configuration menu
    Copy the full SHA
    92a5351 View commit details
    Browse the repository at this point in the history
  8. Configuration menu
    Copy the full SHA
    45d95e6 View commit details
    Browse the repository at this point in the history
  9. Configuration menu
    Copy the full SHA
    eba136b View commit details
    Browse the repository at this point in the history

Commits on Jul 19, 2023

  1. Configuration menu
    Copy the full SHA
    594b379 View commit details
    Browse the repository at this point in the history
  2. Use model_construct in direct methods

    If the BaseModel.construct() method is slow we can still
    reimplement it as was done in the individual direct() methods
    but with the direct() methods still being much simpler.
    timj committed Jul 19, 2023
    Configuration menu
    Copy the full SHA
    f6cfafa View commit details
    Browse the repository at this point in the history
  3. Add note about use of BaseModel.construct

    The previous version used by the direct() methods
    would be something like:
    
            def model_construct(cls, _fields_set: set[str] | None = None, **values: Any) -> Self:
                node = cls.__new__(cls)
                setter = object.__setattr__
                for k, v in values.items():
                    setter(node, k, v)
                if _fields_set is None:
                    _fields_set = set(values.keys())
                setter(node, "__fields_set__", _fields_set)
                return node
    
    Testing with 100MB graph indicates that construct() might be
    fractionally slower than implementing it ourselves as above
    but it is not conclusive. The direct() method only accounts
    for 14% of the graph load time.
    timj committed Jul 19, 2023
    Configuration menu
    Copy the full SHA
    50673f4 View commit details
    Browse the repository at this point in the history
  4. Add news fragment

    timj committed Jul 19, 2023
    Configuration menu
    Copy the full SHA
    1ce5be8 View commit details
    Browse the repository at this point in the history