Skip to content

Deprecation warning (PydanticDeprecatedSince20) from class Config in sas.py/SASBase. #68

@imanshafiei540

Description

@imanshafiei540

Hello Team,

While using planetary_computer, I saw the following deprecation warning during import:

/usr/local/lib/python3.11/site-packages/pydantic/_internal/_config.py:291: PydanticDeprecatedSince20: Support for class-based `config` is deprecated, use ConfigDict instead. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.8/migration/
    warnings.warn(DEPRECATION_MESSAGE, DeprecationWarning)

This originates from planetary_computer/sas.py, where a Pydantic model defines a class Config:

class SASBase(BaseModel):
    """Base model for responses."""

    expiry: datetime = Field(alias="msft:expiry")
    """RFC339 datetime format of the time this token will expire"""

    class Config:
        if _PYDANTIC_2_0:
            populate_by_name = True
        else:
            allow_population_by_field_name = True
            json_encoders = {datetime: datetime_to_str}

As a fix, if you want to support both v1 and v2, we can consider using something like:

if pydantic.VERSION.startswith("1."):
    class SASBase(BaseModel):
        expiry: datetime = Field(alias="msft:expiry")

        class Config:
            allow_population_by_field_name = True
            json_encoders = {datetime: datetime_to_str}
else:
    from pydantic import ConfigDict

    class SASBase(BaseModel):
        expiry: datetime = Field(alias="msft:expiry")
        model_config = ConfigDict(
            populate_by_name=True,
            json_encoders={datetime: datetime_to_str}
        )

Please, let me know, and I'm also happy to open a PR if possible.

Environment:

  • Python==3.11.12
  • planetary-computer==1.0.0

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions