Skip to content

gc: drop jobs tables whose table no longer exists #1644

Open

Description

@dimitri-yatsenko

Summary

A jobs table, ~~<name>, can outlive the auto-populated table it belongs to: #1601 shows it for drop(), and its comments show it for a cascading drop and for a drop through a virtual module. It also happens with tables dropped by an earlier release, by another process, or by hand. A jobs table left behind keeps its records and its primary key, and a table declared later under the same name inherits them (#1601).

Fixing drop() stops new leftovers, but not the ones already in existing schemas. A garbage-collection step would remove those too, whatever path left them, the same way dj.gc already handles orphaned objects in storage.

Proposal

A function in dj.gc, separate from GarbageCollector because jobs tables live in the database and not in a store:

dj.gc.collect_jobs_tables(schema)                 # report only (dry_run=True by default)
dj.gc.collect_jobs_tables(schema, dry_run=False)  # drop the orphans
  • For each schema, list the ~~% tables and the Computed and Imported tables. A jobs table is orphaned when no Computed or Imported table has its name, after the tier prefix is stripped (__name or _name for ~~name).
  • dry_run=True is a read-only report; dry_run=False drops the orphaned jobs tables, and nothing else.
  • Return a report in the style of GarbageCollector.collect(): the number of jobs tables found, the orphaned ones by full name, the number dropped, and errors.

Out of scope

A jobs table whose table exists but whose primary key no longer matches it, after a table is re-declared under the same name. That is the check in AutoPopulate.jobs that #1601 proposes; a GC step cannot tell a stale jobs table from a current one by name alone.

Acceptance

Activity

  1. added this to the v2.4 milestone on Oct 21, 2026
  2. dimitri-yatsenko commented on Oct 21, 2026

    @dimitri-yatsenko
    MemberAuthor

    Planned for 2.4, with the other dj.gc work, and designed together with #1601 (#1615). That PR makes drop() drop each dropped table's jobs table by name, and makes AutoPopulate.jobs raise on a leftover jobs table whose primary key no longer matches. Deciding which of the three 2.4 needs, and in what form, is part of this issue.

    On PostgreSQL, dropping a jobs table safely depends on #1632 (#1630). Every jobs table's status column shares one enum type, and dropping that type with CASCADE removed status from every other jobs table in the schema.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementIndicates new improvements

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions