Skip to content

Wildcard dictionary omits keys with null values #409

Open

Description

@dpeschman

The marshalled output of a model with wildcard field omits any member of the input dictionary whose value is None or whose key "comes before" a key whose value is None.

Repro Steps

  1. Run this:
from flask_restx import marshal
from flask_restx.fields import Wildcard, String
wild = Wildcard(String)
model = {'*': wild}
data = {'a': 1, 'b': '2', 'c': None, 'd': 20, 'e': 'e'}
print('data:', data)
marshalled = marshal(data, model)
print('marshalled:', marshalled)
assert len(data) == len(marshalled)

Expected Behavior

Marshalled response should include all fields from data.

./test.py
data: {'a': 1, 'b': '2', 'c': None, 'd': 20, 'e': 'e'}
marshalled: {'e': 'e', 'd': '20', 'c': None, 'b': '2', 'a': '1'}

Actual Behavior

The field with null value and keys that come before it are missing.

./test.py
data: {'a': 1, 'b': '2', 'c': None, 'd': 20, 'e': 'e'}
marshalled: {'e': 'e', 'd': '20'}
Traceback (most recent call last):
  File "./test.py", line 10, in <module>
    assert len(data) == len(marshalled)
AssertionError

Environment

Python 3.8.5
Flask 0.12.5
flask-restx 0.5.1
Flask-SQLAlchemy 2.5.1

Additional Context

I have a "fix" for this, might be incorrect, will submit PR tomorrow. Similar to #283, but not sure fix will be the same.

Activity

  1. added
    bug
    on Feb 2, 2022
  2. changed the title [-]Wildcard dictionary omits keys will null values[/-] [+]Wildcard dictionary omits keys with null values[/+] on Feb 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions