MongoEngine / MongoEngine/mongoengine

Raise exception on trying to access fields that weren't retrieved from db

Open
#2,145 5 comments 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

Hi. When using mongoengine in our project, we encountered a problem when we tried to access fields that were not received from db (fields in .exclude () or not in .only ()). Now it returns None or the default value, but we think raising an Exception would be safer, so it will tell us to get these fields to avoid unexpected behavior. As an example I added a check_fields_retrieved: True for Document's meta. So for this Document objects and embedded fields we pass .exclude or .only fields, by which we rise an Exception to avoid unexpected behavior. Do you have any developments in this direction?

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 by tracing how Document and embedded-field access behaves after fields are omitted with .exclude() or restricted with .only(). Review the proposed check_fields_retrieved meta option and define the exception behavior for omitted fields, defaults, and embedded fields. Done means configured documents raise an exception instead of returning None or a default value.

Written by the indexing model from the issue text.

Assessment

Tech stack
mongodb, python
Domain
databases
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.