Require the codec `context` kwarg: remove connection context from the `key` dict

Ouverte
#1,557 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 6 jours

Personne n'a encore pris cette issue.

Évaluation

Difficulté
4/5
Temps estimé
3-5 jours
Accessibilité débutants
54/100
Type d'issue
Refactorisation
Clarté
Clairement spécifiée
Activité
Active
Stack technique
python
Domaine
databases

Piste de recherche

Start in table.py, decode_attribute, _extract_context, Codec._codec_config, _build_path, and _get_backend; trace where codec_context and config are passed before removing the legacy underscore-key path. Check the four named ecosystem codecs for migration readiness before removing compatibility. Done means supported codecs require context, config is explicit in the path/backend helpers, and the legacy fallback and capability check are gone.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

stale

The breaking half of #1550, deliberately deferred out of #1556 so that 2.3.4 stayed additive.

What 2.3.4 shipped

encode/decode gained an explicit context argument carrying schema, table, field and config. Nothing broke, by three deliberate choices:

  • DataJoint passes context only to codecs whose signature declares it, so a codec with the old signature is never offered the argument.
  • The underscore keys — _schema, _table, _field, _config — stay in key and are still populated.
  • _extract_context(key) still accepts one argument, warning only when it actually falls back to those keys.

The documentation already teaches the new signature as the signature, in both repos, so codecs written from 2.3.4 onward are ready for this.

What this issue removes

  • Stop populating the underscore keys. table.py builds them alongside codec_context; decode_attribute builds {"_config": ...} alongside {"config": ...}. Both halves collapse to the context one, and key reverts to meaning the primary key, as it does everywhere else in DataJoint.
  • Drop the fallback in _extract_context and Codec._codec_config, along with the DeprecationWarning.
  • Drop the capability check. With every supported codec declaring context, _accepts_kwarg(fn, "context") can go and the argument is passed unconditionally. The store_name check stays — that one is genuinely optional.

Worth doing at the same time

Make config a required parameter of _build_path and _get_backend rather than defaulting to None with a global-config fallback. That fallback is what made the original defect silent: omitting config resolved a different store rather than raising, which is how dj-figpack-codecs#6 and dj-canvasxpress-codecs#3 both shipped broken. A required parameter turns that into a TypeError at the call site.

This is the part with real value, and it is why the deprecation window exists.

Migration

For a codec author it is two lines:

# before
def encode(self, value, *, key=None, store_name=None):
    schema, table, field, pk = self._extract_context(key)
    config = (key or {}).get("_config")

# after
def encode(self, value, *, key=None, context=None, store_name=None):
    schema, table, field, pk = self._extract_context(key, context)
    config = self._codec_config(key, context)

Before closing

Check the four codecs in the ecosystem — dj-figpack-codecs, dj-canvasxpress-codecs, dj-zarr-codecs, dj-photon-codecs. All four were on the old signature when 2.3.4 was cut; each needs the two-line change above before the legacy path is removed, and a release that requires DataJoint >= 2.4.

Langage dominant
Python
Étoiles
198
Forks
103
Merge moyen
6 j 1 h
PR mergées (30 j)
10

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de datajoint/datajoint-python

Toutes les issues de datajoint/datajoint-python

Issues similaires

Plus d'issues Python

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.