Skip to content
This repository was archived by the owner on Jan 23, 2024. It is now read-only.

Commit 8c47fbd

Browse files
committed
allow_nan and catch list field
1 parent ea5c9c6 commit 8c47fbd

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

flask_mongorest/resources.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ def serialize_list_field(self, field_instance, field_name, field_value, **kwargs
472472
return [val for val in [
473473
self.get_field_value(elem, field_name, field_instance=field_instance.field, **kwargs)
474474
for elem in field_value
475-
] if val is not None]
475+
] if val is not None] if field_value else []
476476

477477
def serialize_document_field(self, field_name, field_value, **kwargs):
478478
"""If this field is a reference or an embedded document, either return

flask_mongorest/views.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
register_mime('gz', ('application/gzip',))
2929

3030
def render_json(**payload):
31-
return json.dumps(payload, allow_nan=False, cls=MongoEncoder)
31+
return json.dumps(payload, allow_nan=True, cls=MongoEncoder)
3232

3333
def render_html(**payload):
3434
d = json.dumps(payload, cls=MongoEncoder, sort_keys=True, indent=4)
@@ -41,7 +41,7 @@ def render_gz(**payload):
4141
fmt = request.args.get('format')
4242
content_type = 'text/csv' if fmt == 'csv' else 'application/json'
4343
if fmt == 'json':
44-
contents = json.dumps(payload['data'], allow_nan=False, cls=MongoEncoder)
44+
contents = json.dumps(payload['data'], allow_nan=True, cls=MongoEncoder)
4545
elif fmt == 'csv':
4646
from pandas import DataFrame
4747
from cherrypicker import CherryPicker

0 commit comments

Comments
 (0)