Kate
10/02/2025, 9:14 AME 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
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?Marvin
10/02/2025, 9:14 AMMarvin
10/02/2025, 9:16 AMpyproject_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
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):
# 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):
# 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.Kate
10/02/2025, 9:23 AMprefect 3.4.4
pydantic-settings 2.10.1
pydantic 2.11.7Marvin
10/02/2025, 9:23 AMMarvin
10/02/2025, 9:24 AMpyproject_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:
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:
# 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):
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.Kate
10/02/2025, 10:05 AME 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.Marvin
10/02/2025, 10:05 AMMarvin
10/02/2025, 10:06 AM[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):
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:
[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.Kate
10/08/2025, 12:37 PMField() 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.Marvin
10/08/2025, 12:37 PMMarvin
10/08/2025, 12:38 PMdefault=... 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):
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:
Timezone = Annotated[str, Field(description="time zone")]
class Config(BaseModel):
tz: Timezone = "UTC"
Fix 2: apply Annotated at the field site:
class Config(BaseModel):
tz: Annotated[str, Field(default="UTC", description="time zone")]
Union case:
Bad (default on just one union member is ignored):
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:
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.Kate
10/08/2025, 12:41 PM/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+?Marvin
10/08/2025, 12:42 PMMarvin
10/08/2025, 12:50 PMimport warnings
from pydantic.warnings import UnsupportedFieldAttributeWarning
warnings.filterwarnings("ignore", category=UnsupportedFieldAttributeWarning)
- Via pytest (pytest.ini)
[pytest]
filterwarnings =
ignore:The 'default' attribute.*has no effect.*:pydantic.warnings.UnsupportedFieldAttributeWarning
- Via env
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.