xai-org/x-algorithm · error · ValueError

Post metadata is required

Error message

Post metadata is required

What it means

PostMapper.from_strato_post_with_quote_metadata converts a Strato PostWithQuoteMetadata object into the library's Post model. It requires the inner `post` field to be present because all other data (quoted posts, ancestors) hangs off it. If `post_with_quote_metadata.post` is None or missing, the mapper cannot build a Post and raises ValueError immediately.

Source

Thrown at grox/core/data_loaders/post_mapper.py:52

    GrokShareCard,
    GrokShare,
    ArticleMetadata,
    ListMetadata,
    ChatGroupMetadata,
    SpaceMetadata,
    AffiliatedBusiness,
)

logger = logging.getLogger(__name__)


class PostMapper:
    @classmethod
    def from_strato_post_with_quote_metadata(
        cls, post_with_quote_metadata: PostWithQuoteMetadata
    ) -> Post:
        if not post_with_quote_metadata.post:
            raise ValueError("Post metadata is required")
        post = cls.from_post_metadata_strato(post_with_quote_metadata.post)
        if post_with_quote_metadata.quotedPost:
            post.quoted_post = cls.from_post_metadata_strato(
                post_with_quote_metadata.quotedPost
            )
        return post

    @classmethod
    def from_strato_content_understanding_metadata(
        cls, content_understanding_metadata: ContentUnderstandingMetadataV2
    ) -> Post:
        if not content_understanding_metadata.postMetadata:
            raise ValueError("Post metadata is required")
        post = cls.from_strato_post_with_quote_metadata(
            content_understanding_metadata.postMetadata
        )
        if content_understanding_metadata.replyThreadPostsMetadata:
            post.ancestors = [

View on GitHub (pinned to 24c60942c5)

Solutions

  1. Check that the source payload actually contains post metadata before mapping: `if not pwqm.post: skip/log`.
  2. Log or inspect the raw PostWithQuoteMetadata to confirm the Strato response isn't empty or filtered.
  3. If building fixtures/tests, populate the `.post` field with a valid PostMetadata instance.
  4. Validate at the boundary where Strato responses enter your system so empty posts are dropped early.

Example fix

// before
post = PostMapper.from_strato_post_with_quote_metadata(pwqm)  # pwqm.post is None

// after
if pwqm.post is None:
    raise ValueError("upstream Strato payload missing post metadata")
post = PostMapper.from_strato_post_with_quote_metadata(pwqm)
Defensive patterns

Strategy: validation

Validate before calling

def has_post(pwqm) -> bool:
    return getattr(pwqm, "post", None) is not None

Type guard

from grox.core.data_loaders.post_mapper import PostWithQuoteMetadata

def is_mappable_post(pwqm: PostWithQuoteMetadata) -> bool:
    return pwqm.post is not None

Try / catch

try:
    post = PostMapper.from_strato_post_with_quote_metadata(pwqm)
except ValueError as e:
    if "Post metadata is required" in str(e):
        log.warning("skipping post without metadata: %r", pwqm)
        continue
    raise

Prevention

When it happens

Trigger: Calling PostMapper.from_strato_post_with_quote_metadata (directly or via from_strato_content_understanding_metadata / load_post / hydrate) with a PostWithQuoteMetadata instance whose `.post` attribute is None, falsy, or was never populated by the upstream Strato payload.

Common situations: Deserializing a truncated or filtered Strato API response; passing a partially-constructed dataclass; upstream schema changes renaming post->postMetadata; test fixtures built without the post field.

Related errors


AI-assisted analysis of xai-org/x-algorithm@24c60942c5 (2026-08-28). Data as JSON: /api/errors/d0277d787d88907d. Report an issue: GitHub.