<@ULVA73B9P> I've started to get this error ```E ...
# ask-marvin
k
@Marvin I've started to get this error
Copy code
E   UserWarning: Config key `pyproject_toml_table_header` is set in model_config but will be ignored because no PyprojectTomlConfigSettingsSource source is configured. To use this config key, add a PyprojectTomlConfigSettingsSource source to the settings sources via the settings_customise_sources hook.
in my tests
Copy code
tests/conftest.py:11: in <module>
    from prefect.testing.utilities import prefect_test_harness
after updating Prefect to
3.4.20
Can you explain me the error and what to do with it?
m
thought for 135.0 seconds
Thanks for the details — this is a warning, not a runtime error, but it can fail tests if your test suite treats warnings as errors. What’s happening - pydantic-settings 2.11 introduced a new warning that fires when a settings model sets config keys for TOML-based sources (like
pyproject_toml_table_header
) but has not actually enabled the corresponding source (PyprojectTomlConfigSettingsSource). - Prefect’s settings model historically set those keys even when TOML sources weren’t enabled, which triggers the warning in pydantic-settings 2.11+. - This shows up during imports like
from prefect.testing.utilities import prefect_test_harness
. Status in Prefect - A fix to address pydantic-settings 2.11+ compatibility warnings landed in Prefect 3.4.20. See the release notes: 3.4.20 release notes (item: “Fix pydantic-settings 2.11+ compatibility warnings”, PR #19029). - There’s also related context in this issue where the same warning appears with pydantic-settings 2.11: Prefect logging setup failure with pydantic-settings==2.11. What you can do 1) Verify versions in your environment
Copy code
python -c "import prefect, pydantic_settings, pydantic; print('prefect', prefect.__version__); print('pydantic-settings', pydantic_settings.__version__); print('pydantic', pydantic.__version__)"
- If Prefect is 3.4.20 and pydantic-settings is 2.11+, you should generally not see this warning anymore. If you still do, it’s harmless, but see options below to silence it. 2) Short-term workarounds if the warning is failing tests - Pin pydantic-settings below 2.11 (this avoids the new warning):
Copy code
# pip
pip install 'pydantic-settings<2.11'

# poetry
poetry add 'pydantic-settings<2.11'
- Or, silence just this warning in pytest (keeps warnings-as-errors for everything else):
Copy code
# pytest.ini
[pytest]
filterwarnings =
    ignore:Config key `pyproject_toml_table_header`.*:UserWarning
3) If the warning persists on 3.4.20 - Let me know your exact versions (Prefect, pydantic-settings, Python). There may be an import path in your test harness that triggers the warning before Prefect’s customization takes effect; we can dig into that once we see your env details. Bottom line: It’s a benign warning introduced by pydantic-settings 2.11. Prefect 3.4.20 includes a fix, but if you still see it in tests, pinning pydantic-settings < 2.11 or adding a targeted pytest warning filter will unblock you.
k
@Marvin but I already have pydantic-settings <2.11
Copy code
prefect 3.4.4
pydantic-settings 2.10.1
pydantic 2.11.7
m
thought for 84.4 seconds
Thanks — that explains it. You’re actually running Prefect 3.4.4, not 3.4.20: - prefect 3.4.4 - pydantic-settings 2.10.1 - pydantic 2.11.7 The fix for these pydantic-settings compatibility warnings landed in Prefect 3.4.20, so 3.4.4 will still emit them. Details: - Release notes: 3.4.20 release notes (item: “Fix pydantic-settings 2.11+ compatibility warnings”, PR #19029) - Related issue for context: Prefect logging setup failure with pydantic-settings==2.11 Why you see it even with pydantic-settings 2.10.1 - The warning is triggered when a model sets config keys for TOML sources (like
pyproject_toml_table_header
) but does not enable the corresponding source. Prefect <3.4.20 set those keys without wiring up the source, so the warning can appear with 2.10.x as well. What to do 1) If possible, upgrade Prefect to 3.4.20+ in the environment where tests run. This removes the warning at the source. - If you expected 3.4.20 already, verify which copy of Prefect your tests import:
Copy code
python -c "import prefect, sys; print('prefect', prefect.__version__, 'at', prefect.__file__); print('python', sys.executable)"
2) If you can’t upgrade yet, silence just this warning so your tests don’t fail: - Pytest config:
Copy code
# pytest.ini
   [pytest]
   filterwarnings =
       ignore:Config key `pyproject_toml_table_header`.*:UserWarning
       ignore:Config key `toml_file`.*:UserWarning
- Or very early in tests/conftest.py (before importing Prefect):
Copy code
import warnings
   warnings.filterwarnings(
       "ignore",
       message=r"Config key `pyproject_toml_table_header`.*",
       category=UserWarning,
   )
   warnings.filterwarnings(
       "ignore",
       message=r"Config key `toml_file`.*",
       category=UserWarning,
   )
If you upgrade to 3.4.20+ and still see the warning, please share the output of the version/location check above and I’ll dig in further.
k
@Marvin I ignored the warning as you suggested. But I got a new one:
Copy code
E   UserWarning: Config key `toml_file` is set in model_config but will be ignored because no TomlConfigSettingsSource source is configured. To use this config key, add a TomlConfigSettingsSource source to the settings sources via the settings_customise_sources hook.
m
thought for 25.9 seconds
Yep — that’s the sibling warning to the first one. You can silence it the same way. Add both filters (or a single combined one). In pytest.ini:
Copy code
[pytest]
filterwarnings =
    ignore:Config key `pyproject_toml_table_header`.*:UserWarning
    ignore:Config key `toml_file`.*:UserWarning
Or, at the very top of tests/conftest.py (before any Prefect imports):
Copy code
import warnings

warnings.filterwarnings(
    "ignore",
    message=r"Config key `pyproject_toml_table_header`.*",
    category=UserWarning,
)
warnings.filterwarnings(
    "ignore",
    message=r"Config key `toml_file`.*",
    category=UserWarning,
)
# now import Prefect test utilities
from prefect.testing.utilities import prefect_test_harness
If you prefer a single rule:
Copy code
[pytest]
filterwarnings =
    ignore:Config key `(pyproject_toml_table_header|toml_file)`.*:UserWarning
Longer-term, upgrading to Prefect 3.4.20+ removes these warnings at the source (see 3.4.20 release notes). If you upgrade and still see them, let me know the exact versions and I’ll dig in.
k
@Marvin what about this error? E pydantic.warnings.UnsupportedFieldAttributeWarning: The 'default' attribute with value 'UTC' 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.
m
thought for 37.0 seconds
That warning is from Pydantic v2 and means you passed
default=...
to
Field()
in a place where it can’t actually set a field’s default. Common causes: - Putting
Field(default=...)
inside an
Annotated
type alias and then using that alias as a field type - Attaching
Field(default=...)
to just one member of a
Union[...]
In v2, defaults must be attached to the actual model field (via assignment or
Field(default=...)
on the field), not buried in a type alias or a single union branch. Examples of what triggers the warning vs. fixes: Bad (default inside an alias is ignored):
Copy code
from typing import Annotated
from pydantic import BaseModel, Field

Timezone = Annotated[str, Field(default="UTC", description="time zone")]

class Config(BaseModel):
    tz: Timezone  # warning: default in alias is ignored
Fix 1: keep metadata in the alias, move default to the field assignment:
Copy code
Timezone = Annotated[str, Field(description="time zone")]

class Config(BaseModel):
    tz: Timezone = "UTC"
Fix 2: apply
Annotated
at the field site:
Copy code
class Config(BaseModel):
    tz: Annotated[str, Field(default="UTC", description="time zone")]
Union case: Bad (default on just one union member is ignored):
Copy code
class A(BaseModel): ...
class B(BaseModel): ...

class Config(BaseModel):
    x: Annotated[A, Field(default_factory=A)] | B  # warning
Fix: put the default on the whole field or assign a default value:
Copy code
class Config(BaseModel):
    x: A | B = Field(default_factory=A)
# or
class Config(BaseModel):
    x: A | B = A(...)
This warning is safe but indicates the default you expected won’t be applied. If this came from a Prefect block/model you wrote, can you share the relevant model field(s) and your Pydantic version? I can suggest the exact change. If it’s from a dependency, you can usually ignore it or filter the warning, but it’s better to correct the model code if you control it.
k
@Marvin It's coming from Prefect:
Copy code
/opt/hostedtoolcache/Python/3.11.13/x64/lib/python3.11/site-packages/prefect/server/schemas/schedules.py:475: in <module>
    class RRuleSchedule(PrefectBaseModel):
Is it fixed in prefect 3.4.20+?
m
thought for 527.4 seconds
Short answer: I don’t see a fix for that warning in 3.4.20–3.4.22. It’s still emitted by the server schema’s RRuleSchedule where the timezone default is attached via Field in a context Pydantic v2 ignores. - Source file: prefect/server/schemas/schedules.py - Latest release notes (3.4.22) don’t mention this warning: changelog diff The warning is harmless, but I know it’s noisy. If you want to silence it until we adjust the model: - Via Python
Copy code
import warnings
from pydantic.warnings import UnsupportedFieldAttributeWarning

warnings.filterwarnings("ignore", category=UnsupportedFieldAttributeWarning)
- Via pytest (pytest.ini)
Copy code
[pytest]
filterwarnings =
    ignore:The 'default' attribute.*has no effect.*:pydantic.warnings.UnsupportedFieldAttributeWarning
- Via env
Copy code
PYTHONWARNINGS=ignore::pydantic.warnings.UnsupportedFieldAttributeWarning
If you can share your Prefect and Pydantic versions, I can double-check against that exact combo. If you’d like, I can also open an issue upstream to track moving the default off the Annotated/Field usage in RRuleSchedule.