fix: refuse a str-subclass key in a database TEST dict instead of raising

Aperta Adatta ai principianti
#177 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
62/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
django, python
Ambito
backend

Direzione di ricerca

La riproduzione chiama databases_problems da neolith/_databases.py, e il difetto si trova in _entry_problems, che cerca le chiavi MIRROR, DEPENDENCIES e NAME nel dict TEST. Leggi quella funzione e la regola K2 che cita, poi esegui lo snippet della issue. È completato quando una chiave TEST che è una sottoclasse di str viene rifiutata con un errore che ne indica il tipo, eq non viene mai eseguito e le chiavi str esatte si comportano come prima.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Reproduction

On release/0.1.0a4 (07b71c6):

from neolith._databases import databases_problems

class Trap(str):
    def __eq__(self, other):
        raise RuntimeError("eq ran")
    __hash__ = str.__hash__

pg = "django.db.backends.postgresql"
databases_problems({"billing": {"ENGINE": pg, "NAME": "n", "TEST": {Trap("MIRROR"): "x"}}}, ["billing"])

raises RuntimeError: eq ran; the same with Trap("NAME") or Trap("DEPENDENCIES"). _entry_problems looks "MIRROR", "DEPENDENCIES" and "NAME" up in the TEST dict, which runs the __eq__ of a str-subclass key with the same hash (rule K2).

Expected

A refusal naming the key's type, as for the entry's own keys: check that every TEST key is an exact str before any lookup.

Lingua principale
Python
Stelle
1
Fork
0
Merge medio
6h 34m
PR unite (30g)
108

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di stack314/django-neolith

Tutte le issue di stack314/django-neolith

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.