Skip to content

Bug: Django crashes on startup due to Strawberry GraphQL import mismatch (strawberry.django.auto) #73

Description

@incidunt

Description

Django fails during system checks when loading the GraphQL schema due to an incompatible import in strawberry-graphql-django.

This causes a full startup crash before the server can boot.

Error

ImportError: cannot import name 'auto' from 'strawberry.django'
(/opt/venv/lib/python3.14/site-packages/strawberry/django/__init__.py)

Trace originates from:

  • config/urls.py
  • apps/api/urls.py
  • apps/api/graphql_urls.py
  • apps/api/schema.py

Root Cause

The codebase uses an outdated import:

from strawberry.django import auto

In newer versions of strawberry-graphql-django (>= 0.86):

  • auto is exported from strawberry, not strawberry.django
  • Django integration now uses strawberry_django.type and strawberry_django.field

Full Schema File (Current Implementation)

The failing schema is:

"""GraphQL schema."""
from typing import Optional

import strawberry
import strawberry_django
from strawberry import auto

from apps.users.models import User


@strawberry_django.type(User)
class UserType:
    id: auto
    email: auto
    first_name: auto
    last_name: auto
    is_active: auto


@strawberry.type
class Query:
    users: list[UserType] = strawberry_django.field()

    @strawberry_django.field
    def user(self, id: int) -> Optional[UserType]:
        return User.objects.filter(pk=id).first()


@strawberry.type
class Mutation:
    @strawberry.mutation
    def update_user_name(self, id: int, first_name: str, last_name: str) -> UserType:
        user = User.objects.get(pk=id)
        user.first_name = first_name
        user.last_name = last_name
        user.save()
        return user


schema = strawberry.Schema(query=Query, mutation=Mutation)

Steps to Reproduce

docker compose up

or:

python manage.py runserver

Django crashes during URL resolution.

Expected Behavior

GraphQL schema loads successfully and endpoint is available at:

/api/graphql/

Actual Behavior

Application crashes during startup with import error.

Suggested Fix

1. Fix import

Replace:

from strawberry.django import auto

With:

from strawberry import auto
import strawberry_django

2. Keep schema structure but align with modern API

Ensure:

  • strawberry_django.type
  • strawberry_django.field

Impact

  • Blocks all Django startup
  • Breaks GraphQL endpoint entirely
  • Prevents docker-compose stack from booting

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions