canonical / canonical/data-platform-charmlibs

Uncaught `UnsupportedFieldAttributeWarning` with newer pydantic versions

Open
#21 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
Python
Stars
2
Forks
1
Avg merge
4d 1h
Merged PRs (30d)
1

Description

These warnings bubble up to juju debug logs on imports from `dpcharmlibs.interfaces`

## Steps to reproduce

```bash
python3 -m venv venv
source venv/bin/activate

(venv) $ pip install dpcharmlibs-interfaces "pydantic>=2.11"

(venv) $ python3 -c "from dpcharmlibs.interfaces import *"
/home/iman/monorepo/venv/lib/python3.14/site-packages/pydantic/_internal/_generate_schema.py:2274: UnsupportedFieldAttributeWarning: The 'default' attribute with value None was provided to the `Field()` function, which has no effect in the context it was used. 'default' is field-specific metadata, and can only be attached to a model field using `Annotated` metadata or by assignment. This may have happened because an `Annotated` type alias using the `type` statement was used, or if the `Field()` function was attached to a single member of a union type.
warnings.warn(
/home/iman/monorepo/venv/lib/python3.14/site-packages/pydantic/_internal/_generate_schema.py:2274: UnsupportedFieldAttributeWarning: The 'exclude' attribute with value True was provided to the `Field()` function, which has no effect in the context it was used. 'exclude' is field-specific metadata, and can only be attached to a model field using `Annotated` metadata or by assignment. This may have happened because an `Annotated` type alias using the `type` statement was used, or if the `Field()` function was attached to a single member of a union type.
warnings.warn(
```

## Details

```bash
python3 -W error -c "from dpcharmlibs.interfaces import *"
Traceback (most recent call last):
File "", line 1, in
from dpcharmlibs.interfaces import *
File "/home/iman/monorepo/venv/lib/python3.14/site-packages/dpcharmlibs/interfaces/__init__.py", line 252, in
from .diff import (
...<4 lines>...
)
File "/home/iman/monorepo/venv/lib/python3.14/site-packages/dpcharmlibs/interfaces/diff.py", line 23, in
from dpcharmlibs.interfaces.models import CROSS_MODEL_RELATION_CONSUMER_SECRETS
File "/home/iman/monorepo/venv/lib/python3.14/site-packages/dpcharmlibs/interfaces/models.py", line 376, in
class RequirerCommonModel(CommonModel):
...<26 lines>...
return self
File "/home/iman/monorepo/venv/lib/python3.14/site-packages/pydantic/_internal/_model_construction.py", line 256, in __new__
complete_model_class(
~~~~~~~~~~~~~~~~~~~~^
cls,
^^^^
...<3 lines>...
create_model_module=_create_model_module,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/home/iman/monorepo/venv/lib/python3.14/site-packages/pydantic/_internal/_model_construction.py", line 667, in complete_model_class
schema = gen_schema.generate_schema(cls)
File "/home/iman/monorepo/venv/lib/python3.14/site-packages/pydantic/_internal/_generate_schema.py", line 744, in generate_schema
schema = self._generate_schema_inner(obj)
File "/home/iman/monorepo/venv/lib/python3.14/site-packages/pydantic/_internal/_generate_schema.py", line 1038, in _generate_schema_inner
return self._model_schema(obj)
~~~~~~~~~~~~~~~~~~^^^^^
File "/home/iman/monorepo/venv/lib/python3.14/site-packages/pydantic/_internal/_generate_schema.py", line 868, in _model_schema
{k: self._generate_md_field_schema(k, v, decorators) for k, v in fields.items()},
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
File "/home/iman/monorepo/venv/lib/python3.14/site-packages/pydantic/_internal/_generate_schema.py", line 1245, in _generate_md_field_schema
schema, metadata = self._common_field_schema(name, field_info, decorators)
~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/iman/monorepo/venv/lib/python3.14/site-packages/pydantic/_internal/_generate_schema.py", line 1299, in _common_field_schema
schema = self._apply_annotations(
source_type,
annotations + validators_from_decorators,
)
File "/home/iman/monorepo/venv/lib/python3.14/site-packages/pydantic/_internal/_generate_schema.py", line 2252, in _apply_annotations
schema = get_inner_schema(source_type)
File "/home/iman/monorepo/venv/lib/python3.14/site-packages/pydantic/_internal/_schema_generation_shared.py", line 83, in __call__
schema = self._handler(source_type)
File "/home/iman/monorepo/venv/lib/python3.14/site-packages/pydantic/_internal/_generate_schema.py", line 2231, in inner_handler
schema = self._generate_schema_inner(obj)
File "/home/iman/monorepo/venv/lib/python3.14/site-packages/pydantic/_internal/_generate_schema.py", line 1043, in _generate_schema_inner
return self.match_type(obj)
~~~~~~~~~~~~~~~^^^^^
File "/home/iman/monorepo/venv/lib/python3.14/site-packages/pydantic/_internal/_generate_schema.py", line 1161, in match_type
return self._match_generic_type(obj, origin)
~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
File "/home/iman/monorepo/venv/lib/python3.14/site-packages/pydantic/_internal/_generate_schema.py", line 1184, in _match_generic_type
return self._union_schema(obj)
~~~~~~~~~~~~~~~~~~^^^^^
File "/home/iman/monorepo/venv/lib/python3.14/site-packages/pydantic/_internal/_generate_schema.py", line 1344, in _union_schema
choices.append(self.generate_schema(arg))
~~~~~~~~~~~~~~~~~~~~^^^^^
File "/home/iman/monorepo/venv/lib/python3.14/site-packages/pydantic/_internal/_generate_schema.py", line 744, in generate_schema
schema = self._generate_schema_inner(obj)
File "/home/iman/monorepo/venv/lib/python3.14/site-packages/pydantic/_internal/_generate_schema.py", line 1022, in _generate_schema_inner
return self._annotated_schema(obj)
~~~~~~~~~~~~~~~~~~~~~~^^^^^
File "/home/iman/monorepo/venv/lib/python3.14/site-packages/pydantic/_internal/_generate_schema.py", line 2202, in _annotated_schema
schema = self._apply_annotations(source_type, annotations)
File "/home/iman/monorepo/venv/lib/python3.14/site-packages/pydantic/_internal/_generate_schema.py", line 2252, in _apply_annotations
schema = get_inner_schema(source_type)
File "/home/iman/monorepo/venv/lib/python3.14/site-packages/pydantic/_internal/_schema_generation_shared.py", line 83, in __call__
schema = self._handler(source_type)
File "/home/iman/monorepo/venv/lib/python3.14/site-packages/pydantic/_internal/_generate_schema.py", line 2425, in new_handler
schema = get_inner_schema(source)
File "/home/iman/monorepo/venv/lib/python3.14/site-packages/pydantic/_internal/_schema_generation_shared.py", line 83, in __call__
schema = self._handler(source_type)
File "/home/iman/monorepo/venv/lib/python3.14/site-packages/pydantic/_internal/_generate_schema.py", line 2426, in new_handler
schema = self._apply_single_annotation(
schema,
annotation,
check_unsupported_field_info_attributes=check_unsupported_field_info_attributes,
)
File "/home/iman/monorepo/venv/lib/python3.14/site-packages/pydantic/_internal/_generate_schema.py", line 2274, in _apply_single_annotation
warnings.warn(
~~~~~~~~~~~~~^
f'The {attr!r} attribute with value {value!r} was provided to the `Field()` function, '
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...<4 lines>...
category=UnsupportedFieldAttributeWarning,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
pydantic.warnings.UnsupportedFieldAttributeWarning: The 'default' attribute with value None was provided to the `Field()` function, which has no effect in the context it was used. 'default' is field-specific metadata, and can only be attached to a model field using `Annotated` metadata or by assignment. This may have happened because an `Annotated` type alias using the `type` statement was used, or if the `Field()` function was attached to a single member of a union type.
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with dpcharmlibs/interfaces/models.py, especially RequirerCommonModel, using the reported import command with pydantic>=2.11. Trace the Field metadata involved in the warnings and verify that importing dpcharmlibs.interfaces produces neither warnings nor an exception with Python warnings treated as errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.