Skip to content

Call in prefect._internal.concurrency.calls raises AttributeError on equality #18080

@willhcr

Description

@willhcr

Bug summary

Call objects stored in contextvars raise AttributeError when compared using != after internal attributes (args, kwargs) have been deleted. This code del self.args, self.kwargs is run in a few places in Call. The error occurs because the class uses an auto-generated __eq__ from @dataclass, which accesses these now-missing fields during comparison.

This led to an error when using async code with prefect and Django in asgiref. Fixing this would allow Prefect tasks and Django async ORM methods to interoperate.

@task
async def get_account(account_uuid: UUID):
    return await Account.objects.select_related('domain').aget(uuid=account_uuid)

Exception from asgiref:

def _restore_context(context: contextvars.Context) -> None:
    # Check for changes in contextvars, and set them to the current
    # context for downstream consumers
    for cvar in context:
        cvalue = context.get(cvar)
        try:
            if cvar.get() != cvalue:
                cvar.set(cvalue)
        except LookupError:
            cvar.set(cvalue)
  if cvar.get() != cvalue:
AttributeError: 'Call' object has no attribute 'args'

Version info

Version:             3.3.7
API version:         0.8.4
Python version:      3.12.10
Git commit:          8f86aaee
Built:               Mon, Apr 28, 2025 03:04 PM
OS/Arch:             linux/x86_64
Profile:             ephemeral
Server type:         ephemeral
Pydantic version:    2.10.6
Server:
  Database:          sqlite
  SQLite version:    3.47.1
Integrations:
  prefect-azure:     0.4.4
  prefect-docker:    0.6.4

Additional context

Implementing object equality resolved this issue. But is attribute level comparison used elsewhere with Call?

class Call(Generic[T]):
...
    def __eq__(self, other):
        return self is other

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions