{"record":{"id":"105ed8bfb26ac592","repo":"mvanhorn/last30days-skill","slug":"polymarket-item-carries-no-event-id-slug-equality","errorCode":null,"errorMessage":"Polymarket item carries no event id; slug equality alone cannot verify event identity","messagePattern":"Polymarket item carries no event id; slug equality alone cannot verify event identity","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"skills/last30days/scripts/lib/polymarket.py","lineNumber":949,"sourceCode":"    # On the slug fallback, a slug can be re-used by a re-created event. When\n    # the cached item still carries the original Gamma event id (numeric; the\n    # synthetic PM<N> parse fallback carries no identity), the response id\n    # must match it too, or the verdict would come from another market.\n    expected_id = (\n        cached_item_id\n        if not event_id and re.fullmatch(r\"\\d+\", cached_item_id)\n        else \"\"\n    )\n    if event_id:\n        payload = http.request(\n            \"GET\", f\"{GAMMA_EVENTS_URL}/{quote(event_id)}\", timeout=10, retries=2,\n        )\n    elif slug_match:\n        if not expected_id:\n            # No event id anywhere: slug equality alone cannot verify event\n            # identity, so fail closed (unsupported) instead of re-deriving a\n            # verdict from whatever event currently owns the slug.\n            raise ValueError(\n                \"Polymarket item carries no event id; slug equality alone \"\n                \"cannot verify event identity\"\n            )\n        requested_slug = slug_match.group(1)\n        payload = http.request(\n            \"GET\", GAMMA_EVENTS_URL, params={\"slug\": requested_slug},\n            timeout=10, retries=2,\n        )\n    else:\n        raise ValueError(\"Polymarket item has no event id or slug\")\n\n    requested_slug = slug_match.group(1) if slug_match else None\n\n    def _matches_identity(entry: dict) -> bool:\n        if str(entry.get(\"slug\") or \"\").strip() != requested_slug:\n            return False\n        if expected_id and str(entry.get(\"id\") or \"\").strip() != expected_id:\n            return False","sourceCodeStart":931,"sourceCodeEnd":967,"githubUrl":"https://github.com/mvanhorn/last30days-skill/blob/c7460f6114449ddfe6ea3fc2f23c3d910c0e740c/skills/last30days/scripts/lib/polymarket.py#L931-L967","documentation":"Raised during Polymarket datum re-verification when the item's URL matches a slug pattern but the item carries no event id anywhere. Because a slug can be reused by a different event over time, slug equality alone cannot prove the refreshed event is the same one originally cited, so the library fails closed with ValueError instead of returning a possibly-wrong verdict.","triggerScenarios":"refetch_datum is called on a Polymarket item whose URL is a slug-style link (e.g. polymarket.com/event/some-slug) but whose cached item id is not purely numeric (so no event id can be derived) and no expected id is available from metadata. The slug_match branch is taken with expected_id falsy, hitting the explicit raise.","commonSituations":"Items persisted from an older schema that did not store the Gamma event id; hand-constructed items with only a URL; upstream Gamma data where the id field was stripped; migrating stored items between versions of the ingest pipeline.","solutions":["Ensure items persisted for Polymarket carry the Gamma numeric event id (item.metadata/event id) at ingest time","If the event id is genuinely unavailable, refresh via the original search flow instead of refetch_datum so identity is re-established","Catch ValueError here and mark the datum 'unverified' rather than retrying - retrying cannot fix missing identity data"],"exampleFix":"# before\nurl = f\"https://polymarket.com/event/{slug}\"  # id never stored\n\n# after\nmetadata = {\"event_id\": event[\"id\"], \"slug\": slug}  # persist id at ingest\nurl = f\"https://polymarket.com/event/{slug}\"","handlingStrategy":"validation","validationCode":"def can_verify_polymarket_event(item) -> bool:\n    has_id = bool(getattr(item, \"id\", \"\") and re.fullmatch(r\"\\d+\", str(item.id)))\n    has_slug = bool(re.search(r\"polymarket\\.com/event/([\\w-]+)\", getattr(item, \"url\", \"\") or \"\"))\n    return has_id or (has_slug and bool(item.metadata.get(\"event_id\")))","typeGuard":null,"tryCatchPattern":"try:\n    datum = refetch_datum(item, key)\nexcept ValueError as e:\n    if \"slug equality alone\" in str(e):\n        mark_unverifiable(item)  # identity data missing; do not retry\n    raise","preventionTips":["Persist the Gamma numeric event id in item.metadata at ingest time","Treat slug-only items as unverifiable by design - never 'fix' by trusting slug equality","Keep the fail-closed semantics: unverified is a valid state, not a bug"],"tags":["polymarket","data-integrity","fail-closed","valueerror"],"backgroundTag":null,"analyzedSha":"c7460f6114449ddfe6ea3fc2f23c3d910c0e740c","analyzedAt":"2026-08-15T03:34:49.540Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}