Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the null terminator from flask_utils.py #709

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
- Replaced entity with getter (#652)
- Resolved TODO in Dockerfile (#680)
- Resolved TODO at src/reporter/tests/test_timescale_types.py (#667)
- Resolved TODO in src/wq/ql/flask_utils.py (#707)

### Bug fixes

Expand Down
5 changes: 1 addition & 4 deletions src/wq/ql/flaskutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ def json_array_streamer(xs: Iterable[BaseModel]) -> Iterable[str]:
for x in xs:
json_repr = x.json()
yield json_repr + ',\n'
yield 'null\n]'
# TODO how to get rid of the null terminator in an efficient and **simple**
# way? I could use the same put-back approach as in itersplit but I'd rather
# keep it simple.
yield '\n]'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NEC-Vishal nice try, but it won't work :-)
In fact, if the input iterable isn't empty the output JSON array will contain an extra comma before the array end symbol, e.g. [1, 2, 3] ~~~> "[\n1,\n2,\n3,\n]" which is not a valid JSON array!



def build_json_array_response_stream(xs: Iterable[BaseModel]) -> Response:
Expand Down