Deprecate `safemode`: confirm destructive operations explicitly, with `prompt=False` at the call

Offen
#1,685 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 6 Tagen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Anfängerfreundlichkeit
35/100
Issue-Typ
Feature
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
mysql, python
Bereich
databases

Rechercherichtung

Start by reading the implementations of Table.delete(), Table.drop(), Schema.drop(), and the configuration paths named in the issue, then locate their existing tests and delete/drop documentation. Map how safemode supplies the current prompt default before estimating the changes. Done means the acceptance criteria pass across each configuration path, per-call-site warning, non-TTY behavior, docs, and 2.4 release notes.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

enhancement

Problem

dj.config["safemode"] (default True) sets the default prompt for Table.delete(), Table.drop() and Schema.drop(). Setting it to False turns off confirmation for every destructive call in the process, at once and out of sight:

  • It's usually switched off for convenience, in a helper, a datajoint.json, or a DJ_SAFEMODE environment variable, and then it applies to code that never asked for it.
  • A reader of (Session & key).delete() can't tell whether it will prompt without knowing the process's configuration.
  • The setting's name says nothing about what it controls.

Getting it wrong costs more than the setting saves: a silent cascade delete or schema drop in the wrong session can't be undone. Skipping confirmation is a decision about one call, so it belongs at that call.

Proposal (2.4)

  1. prompt defaults to True in Table.delete(), Table.drop() and Schema.drop(). Passing prompt=False is the supported way to skip confirmation. The deprecated setting is honored, with a warning, until 3.0 (item 3).
  2. Deprecate safemode. Setting it through dj.config, datajoint.json, DJ_SAFEMODE, config.override() or an instance's config emits a DeprecationWarning naming the replacement: pass prompt=False at the call.
  3. Warn where code relied on it. While the deprecated setting is False, a destructive call made without an explicit prompt warns once per call site, says to pass prompt=False, and behaves as it does today, so existing scripts keep working through 2.x.
  4. No silent hangs. When prompt=True and there's no interactive terminal (stdin isn't a TTY: batch jobs, CI, schedulers), raise DataJointError saying to pass prompt=False, instead of blocking on input().
  5. Remove safemode in 3.0.

Documentation

  • The delete and drop docs and the configuration reference: replace safemode with explicit prompt=False, and show the pattern for scripts: preview first (for example dj.Diagram.cascade(T & cond).counts()), then (T & cond).delete(prompt=False).
  • Say plainly that with prompt=True, the confirmation is answered while the delete's transaction is open, so the affected rows and tables stay locked until it's answered. In shared databases, preview first and delete with prompt=False.
  • What's new in 2.4: the deprecation and the migration (search for safemode, and pass prompt=False where the call should not ask).

Acceptance criteria

  • With default configuration, delete(), drop() and Schema.drop() prompt unless called with prompt=False.
  • Setting safemode in any of its forms emits a DeprecationWarning; behavior is otherwise unchanged in 2.x.
  • prompt=True without a TTY raises with a message naming prompt=False; no call blocks on input in a non-interactive process.
  • Tests cover each configuration path, the per-call-site warning, and the no-TTY error.
  • The docs and release notes describe the migration.
Vorherrschende Sprache
Python
Sterne
198
Forks
103
Ø Merge
6 T. 1 Std.
Gemergte PRs (30 T.)
10

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus datajoint/datajoint-python

Alle Issues in datajoint/datajoint-python

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.