MongoEngine / MongoEngine/mongoengine

Documents to json show all fields when using only() or exclude()

Open
#2,030 6 comments 4 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

When converting a QuerySet with an only() or exclude() field to json, the required fields returned in each object are the required ones from the query.

output = Example.objects.only('field_1').to_json()
# Required feilds are returned
# [{'field_1': ...}, ...]

When converting a single document from a query with only paramaters the document containes the fields with default values.

output = Example.objects.only('field_1').first().to_json()
# All fields are returned with default values
# [{'field_1': ..., 'field_2': None, 'field_3': None, ...}, ...]

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

No files or tests are named. First reproduce the two examples using QuerySet.only() and exclude(), comparing queryset JSON output with a single document's to_json() output. Done means the selected-field behavior is consistent and the resulting JSON matches the fields requested by the query without unexpected default-valued fields.

Written by the indexing model from the issue text.

Assessment

Tech stack
mongodb, python
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.