diff --git a/src/core/schemas.py b/src/core/schemas.py index ede18e8c2..24d8fc7c5 100644 --- a/src/core/schemas.py +++ b/src/core/schemas.py @@ -2492,9 +2492,11 @@ def model_dump(self, **kwargs): # Ensure required AdCP fields are present for responses # (These should be set during package creation/processing) - if data.get("package_id") is None: + # Check the actual object attributes, not the serialized dict, + # because exclude_none=True (default) may exclude None values from the dict + if self.package_id is None: raise ValueError("Package missing required package_id for AdCP response") - if data.get("status") is None: + if self.status is None: raise ValueError("Package missing required status for AdCP response") return data diff --git a/src/core/tools/media_buy_create.py b/src/core/tools/media_buy_create.py index cdcdf36bd..613e06992 100644 --- a/src/core/tools/media_buy_create.py +++ b/src/core/tools/media_buy_create.py @@ -70,7 +70,6 @@ def validate_agent_url(url: str | None) -> bool: Principal, Product, Targeting, - TaskStatus, ) from src.core.testing_hooks import TestingContext, apply_testing_hooks, get_testing_context from src.core.tool_context import ToolContext @@ -1867,8 +1866,8 @@ async def _create_media_buy_impl( { "package_id": package_id, "buyer_ref": pkg.buyer_ref, # Include buyer_ref from request package - # Package status should be null until the package is actually created in the ad server - # After approval + adapter creation, it will be set to "draft" or "active" by the adapter + "status": "draft", # Set initial status (required by AdCP spec) + # Status will be updated to "active" after approval + adapter creation } ) pending_packages.append(Package(**pkg_data)) @@ -2236,7 +2235,7 @@ async def _create_media_buy_impl( "package_id": package_id, "name": f"{pkg.product_id} - Package {idx}", "buyer_ref": pkg.buyer_ref, # Include buyer_ref from request - "status": TaskStatus.INPUT_REQUIRED, # Consistent with TaskStatus enum (requires approval) + "status": "draft", # Package is pending approval (AdCP-compliant status) } ) diff --git a/tests/e2e/test_schema_validation_standalone.py b/tests/e2e/test_schema_validation_standalone.py index 2c895ddbf..4b6e33daf 100644 --- a/tests/e2e/test_schema_validation_standalone.py +++ b/tests/e2e/test_schema_validation_standalone.py @@ -38,7 +38,11 @@ async def test_valid_get_products_response(): "name": "Test Display Product", "description": "Test description", "publisher_properties": [ - {"publisher_domain": "example.com", "property_tags": ["premium_content"]} + { + "publisher_domain": "example.com", + "selection_type": "by_tag", + "property_tags": ["premium_content"], + } ], # Required: publisher properties covered by this product "format_ids": [ {