Skip to content

APIv2: duplicate UUID check is flawed after writes were added #7704

@legoktm

Description

@legoktm

Description

        # Process events in snowflake order.
        for event in sorted(events, key=lambda e: int(e.id)):
            result = handler.process(event)
            for uuid, source in result.sources.items():
                response.sources[uuid] = source.to_api_v2() if source is not None else None
            for uuid, item in result.items.items():
                response.items[uuid] = item.to_api_v2() if item is not None else None
            response.events[result.event_id] = result.status
...

    if requested.items:
        submission_query: EagerQuery = eager_query("Submission")
        for item in submission_query.filter(
            Submission.uuid.in_(str(uuid) for uuid in requested.items)
        ):
            response.items[item.uuid] = item.to_api_v2()

        reply_query: EagerQuery = eager_query("Reply")
        for item in reply_query.filter(Reply.uuid.in_(str(uuid) for uuid in requested.items)):
            if item.uuid in response.items:
                # Fail if we get unlucky and hit a UUID collision between the
                # `Submission` and `Reply` tables.  This is vanishingly unlikely,
                # but SQLite can't enforce uniqueness between them.
                raise MultipleResultsFound(f"found {item.uuid} in both submissions and replies")
            response.items[item.uuid] = item.to_api_v2()

if an item is modified as the result of a write event, and then it is also a requested item, and a reply, then it will already be in response.items and trigger our duplicate UUID detection.

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions