Fix: Exclude null values from list_authorized_properties response #647
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
AdCP client schema validation was rejecting the
list_authorized_propertiesresponse because optional fields were being set tonullinstead of being completely omitted from the JSON.Error messages:
primary_channels: Expected array, received nullprimary_countries: Expected array, received nullportfolio_description: Expected string, received nulladvertising_policies: Expected string, received nulllast_updated: Expected string, received nullerrors: Expected array, received nullThe AdCP JSON schema expects optional fields to be either:
It does NOT accept
nullvalues for these fields.Root Cause
When FastMCP serializes Pydantic models, it may use Python's built-in
dict()function which calls__iter__instead of the model'smodel_dump()method. This resulted in all fields (including those withNonevalues) being included in the response.Solution
__iter__()inListAuthorizedPropertiesResponseto only yield non-None fieldsdict()method to usemodel_dump()withexclude_none=TrueThese changes ensure optional fields are completely omitted from the JSON response rather than being present with
nullvalues, matching AdCP spec requirements.Testing
Nonevalues are excludeddict(response)andresponse.model_dump()now exclude None fieldsFiles Changed
src/core/schema_adapters.py: Added__iter__anddictmethod overridessrc/core/tools/properties.py: Only pass non-None values to response constructor