Skip to content

fix: make PromptVersion.published_at optional#2

Open
anxkhn wants to merge 1 commit into
px0-ai:masterfrom
anxkhn:fix/prompt-version-published-at-nullable
Open

fix: make PromptVersion.published_at optional#2
anxkhn wants to merge 1 commit into
px0-ai:masterfrom
anxkhn:fix/prompt-version-published-at-nullable

Conversation

@anxkhn

@anxkhn anxkhn commented Jul 1, 2026

Copy link
Copy Markdown

px0-python is generated from the OpenAPI spec in px0-ai/px0, so this is ultimately a spec issue: the durable fix belongs in that spec, and this patch corrects the currently published SDK to match. Happy to redo it as a spec-side change if you prefer.

published_at is populated only once a version is set to live. For draft, stable and archived versions the API returns published_at: null, but the field was generated as a required, non-nullable datetime, so from_dict raised ValidationError and the SDK could not read the response.

The underlying fix belongs in the OpenAPI document: mark published_at nullable: true and remove it from required on the PromptVersion schema. This applies the equivalent change to the generated model so it matches what the generator would produce, mirroring APIKey.last_used_at, which already handles the same "Null if ..." case:

-    published_at: datetime = Field(description="Timestamp when status was set to live. Null if draft.")
+    published_at: Optional[datetime] = Field(default=None, description="Timestamp when status was set to live. Null if draft.")

from_dict already reads the value with obj.get("published_at"), and to_dict uses exclude_none=True, so a null or omitted value round-trips cleanly and is dropped on serialization. docs/PromptVersion.md is updated to mark the field optional.

Why it matters

Without this, create_version, promote_version, duplicate_version, get_version, archive_version and list_versions all fail whenever the version they touch is not live (a single non-live element also breaks the whole list_versions array).

Testing

Added tests/test_prompt_version_published_at.py covering a draft version with published_at: null, published_at omitted entirely, a live version keeping its timestamp, to_dict dropping the null field, and a list_versions payload containing a draft element. pytest test tests passes.

Closes #1

@anxkhn
anxkhn force-pushed the fix/prompt-version-published-at-nullable branch from 2b0422e to 18ed180 Compare July 1, 2026 14:21
@anxkhn anxkhn changed the title fix: make PromptVersion.published_at optional Make PromptVersion.published_at nullable in the generated model Jul 1, 2026
published_at is only populated once a version is set to live; the API
returns null for draft, stable and archived versions (as the field
description itself states). It was generated as a required, non-nullable
datetime, so PromptVersion.from_dict raised pydantic ValidationError for
any non-live version. This broke create_version (returns a draft),
promote_version (draft -> stable, never-live), duplicate_version,
get_version and, because one element poisons the whole array,
list_versions.

Make the field Optional[datetime] with a None default, mirroring the
already-correct APIKey.last_used_at which shares the same 'Null if ...'
semantics. Add regression tests covering null, omitted and populated
published_at plus a list_versions payload containing a draft.
@anxkhn
anxkhn force-pushed the fix/prompt-version-published-at-nullable branch from 18ed180 to 46dfaf5 Compare July 1, 2026 14:29
@anxkhn anxkhn changed the title Make PromptVersion.published_at nullable in the generated model fix: make PromptVersion.published_at optional Jul 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PromptVersion.published_at is required, so draft and other non-live versions fail to deserialize

1 participant