Skip to content

LSP panic (exit code 101) on startup with Django custom User model — answers_solver.rs:233 unwrap() on None #2479

@dongju93

Description

@dongju93

Environment

Item Version
OS macOS 26.3 (arm64)
Python 3.14.2
Pyrefly 0.53.0
VS Code 1.109.5
VS Code Extension meta.pyrefly-0.53.0-darwin-arm64
Django 6.0.2
django-stubs 5.2.9

Reproducible file

src/core/models.py — Django custom User model with email-based auth:

"""Custom User model using email as the login identifier instead of username."""

from typing import Any, ClassVar

from django.contrib.auth.base_user import (
    AbstractBaseUser,
    BaseUserManager,
)
from django.contrib.auth.models import PermissionsMixin
from django.db.models import BooleanField, CharField, EmailField


class UserManagement(BaseUserManager["User"]):
    def create_user(
        self, email: str, password: str | None = None, **extra_fields: Any
    ) -> "User":
        if not email:
            raise ValueError("Users must have an email address")
        user: User = self.model(email=self.normalize_email(email), **extra_fields)
        user.set_password(password)
        user.save(using=self._db)
        return user

    def create_superuser(self, email: str, password: str) -> "User":
        user: User = self.create_user(email=email, password=password)
        user.is_staff = True
        user.is_superuser = True
        user.save(using=self._db)
        return user


class User(AbstractBaseUser, PermissionsMixin):
    email = EmailField(max_length=255, unique=True)
    name = CharField(max_length=255)
    is_active = BooleanField(default=True)  # type: ignore[bad-override]
    is_staff = BooleanField(default=False)

    objects: ClassVar[UserManagement] = UserManagement()

    USERNAME_FIELD = "email"

What happens

Opening this file in VS Code causes the Pyrefly LSP to panic immediately during the initial indexing phase (DidOpenTextDocument). The server crashes 5 times and stops restarting.

Crash log

starting generic LSP server
 INFO Reading messages
 INFO File src/core/models.py opened, prepare to validate open files.
 INFO Ran task on sourcedb_queue heavy task queue. Queue time: 0.00, task time: 0.00
 INFO Published 0 diagnostics for file:///…/src/core/models.py
 INFO Validated open files and committed transaction.
 INFO Cleared 1 dropped configs from config cache
 INFO Language server processed event `DidOpenTextDocument` in 1.21s (0.00s waiting)
 WARN /var/folders/…/pyrefly_bundled_typeshed_e52a9c11f401/pyrefly.toml: Cannot use both `permissive-ignores` and `enabled-ignores`: `permissive-ignores` will be ignored.
 INFO Unhandled notification: Notification { method: "$/setTrace", params: Object {"value": String("off")}, activity_key: None }
[Error] Client Pyrefly language server: connection to server is erroring.
write EPIPE
ERROR Thread panicked, shutting down: panicked at pyrefly/lib/alt/answers_solver.rs:233:66:
called `Option::unwrap()` on a `None` value
Backtrace:
   0: <std::backtrace::Backtrace>::create
   1: <std::sync::once::Once>::call_once::<pyrefly_util::panic::print_panic::{closure#0}>::{closure#0}
   2: <std::sys::sync::once::queue::Once>::call
   3: pyrefly_util::panic::print_panic
   4: pyrefly_util::panic::exit_on_panic::{closure#0}
   5: std::panicking::panic_with_hook
   6: std::panicking::panic_handler::{closure#0}
   7: std::sys::backtrace::__rust_end_short_backtrace::<std::panicking::panic_handler::{closure#0}, !>
   8: __rustc::rust_begin_unwind
   9: core::panicking::panic_fmt
  10: core::panicking::panic
  11: core::option::unwrap_failed
  12: <pyrefly::alt::answers_solver::AnswersSolver<pyrefly::state::state::TransactionHandle>>::get_idx::<pyrefly::binding::binding::KeyClassField>
  13: <pyrefly::alt::answers_solver::AnswersSolver<pyrefly::state::state::TransactionHandle>>::get_from_module::<pyrefly::binding::binding::KeyClassField>
  14: <pyrefly::alt::answers_solver::AnswersSolver<pyrefly::state::state::TransactionHandle>>::get_non_synthesized_field_from_current_class_only
  15: <pyrefly::alt::answers_solver::AnswersSolver<pyrefly::state::state::TransactionHandle>>::get_class_member_with_defining_class
  16: <pyrefly::state::steps::Step>::step_solutions::<pyrefly::state::state::TransactionHandle>
  17: <pyrefly::state::steps::Step>::compute::<pyrefly::state::state::TransactionHandle>
  18: <pyrefly::state::state::Transaction>::demand
  19: <pyrefly::state::state::Transaction>::run_step::{closure#1}
  20: <rayon_core::job::HeapJob<…> as rayon_core::job::Job>::execute
  21: <rayon_core::registry::WorkerThread>::wait_until_cold
  22: std::sys::backtrace::__rust_end_short_backtrace::<…>
  23: <std::thread::lifecycle::spawn_unchecked<…>>::call_once::{shim:vtable#0}
  24: <std::sys::thread::unix::Thread>::new::thread_start
  25: __pthread_cond_wait

PANIC Sorry, Pyrefly crashed, this is always a bug in Pyrefly itself.
PANIC Please report the bug at https://github.com/facebook/pyrefly/issues/new
[Error] Server process exited with code 101.
[Error] The Pyrefly language server server crashed 5 times in the last 3 minutes. The server will not be restarted.

Additional notes

  • The panic happens during DidOpenTextDocument processing, before any interactive LSP requests (no codeAction, documentSymbol etc.)
  • The write EPIPE on the Node.js side is a consequence of the Rust thread panic closing the pipe, not a separate cause
  • The bundled pyrefly.toml warning (Cannot use both permissive-ignores and enabled-ignores) appears on every startup — possible related config issue in the bundled typeshed
  • Pyrefly CLI (pyrefly check) works fine on the same file — crash is LSP-only
  • Related closed issue: Language Server Panic (Exit Code 101) on startup (Django 5.0.14 project) #2238 (same Django + exit 101 symptoms, closed for lack of repro)
  • Crash location (answers_solver.rs:233) is different from the previously fixed Django panic in Panic in pyrefly/lib/alt/answers_solver.rs #1527 (answers_solver.rs:650)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions