MongoEngine / MongoEngine/mongoengine

MapField with Normalized Keys

Open
#1,713 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
4.3k
Forks
1.2k
Avg merge
4h 41m
Merged PRs (30d)
11

Description

I need a MapField that automatically normalizes the keys I give it. For example, I need the following to work:

import mongoengine

class TestDoc(mongoengine.document):
    foo = mongoengine.MapField(mongoengine.IntField())

a = TestDoc()
a.foo['test'] = 1
assert a.foo['TEST'] == a.foo['test']

I've tried subclass the MapField object, but the __setitem__ and __getitem__ methods seem to be ignored. What functions do I override so that I can normalize the keys before setting or getting?

Contributor guide

Open the contributing guide

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.

Research direction

Start at the MapField entry point and trace how key access is handled; the report specifically notes that subclass setitem and getitem are ignored. Determine the supported extension point for key normalization, then verify that 'test' and 'TEST' resolve to the same value.

Written by the indexing model from the issue text.

Assessment

Tech stack
mongodb, python
Domain
databases
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.