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

Open Beginner friendly
#177 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
62/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
django, python
Domain
backend

Research direction

The reproduction calls databases_problems from neolith/_databases.py, and the fault sits in _entry_problems, which looks up the MIRROR, DEPENDENCIES and NAME keys in the TEST dict. Read that function and the rule K2 it cites, then run the snippet from the issue. Done means a str-subclass TEST key is refused with an error naming its type, the eq never runs, and exact-str keys behave as before.

Written by the indexing model from the issue text.

Description

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.

Dominant language
Python
Stars
1
Forks
0
Avg merge
6h 34m
Merged PRs (30d)
108

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from stack314/django-neolith

All issues in stack314/django-neolith

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.