Feature: Option to handle empty filter results #22
Merged
outscale-mgo merged 2 commits intooutscale:mainfrom Mar 24, 2026
Merged
Feature: Option to handle empty filter results #22outscale-mgo merged 2 commits intooutscale:mainfrom
outscale-mgo merged 2 commits intooutscale:mainfrom
Conversation
ae71351 to f277530 Compare f277530 to c8b9d21 Compare cosmo-ray reviewed Mar 24, 2026
csonpath_python.c Outdated
| } | ||
| | ||
| if (csonpath_init(ret, s) < 0) { | ||
| PyErr_NoMemory(); |
There was a problem hiding this comment.
pretty sure, this should be return, so py_ret = PyErr_NoMemory();
| PyCsonPathObject *self = (PyCsonPathObject *)subtype->tp_alloc(subtype, 0); | ||
| const char *s; | ||
| int return_empty_list = 0; | ||
| struct csonpath *ret = NULL; |
csonpath_python.c Outdated
| free(ret); | ||
| error: | ||
| Py_DECREF(self); | ||
| return NULL; |
csonpath_python.c Outdated
| | ||
| PyObject *ret = csonpath_find_all(self->cp, json); | ||
| | ||
| if (ret == Py_None && self->return_empty_list) { |
There was a problem hiding this comment.
this should be already done when cjp->return_empty_array = 1
csonpath_python.c Outdated
| | ||
| PyObject *ret = csonpath_find_first(self->cp, json); | ||
| | ||
| if (ret == Py_None && self->return_empty_list) { |
There was a problem hiding this comment.
keep this one, because find_first in C should not do the list creation.
or keep python consistant with C and maybe doing this for find_first was a bad idea
csonpath_do.h Outdated
| CSONPATH_DO_POST_OPERATION; | ||
| | ||
| return ret; | ||
| #ifdef CSONPATH_DO_RETURNS_JSON_PTR |
There was a problem hiding this comment.
this, should be done in CSONPATH_DO_FIND_ALL_OUT , so I think the define just add code duplication
c8b9d21 to 75842c1 Compare Added the return_empty_array parameter
75842c1 to 37d1aa8 Compare outscale-mgo approved these changes Mar 24, 2026
Contributor
outscale-mgo left a comment
There was a problem hiding this comment.
but the indentation could be better
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📦 Pull Request Template
Description
At @outscale-mgo request, and to comply with the jsonpath-ng convention, an option has been added to return an empty array instead of
Nonevalues for thefind_firstandfind_allfunctions.This feature is supported in both Python and C. The unit tests have been updated to test this feature (C and Python).
No breaking changes. The default behavior and the previous behavior (returns
Noneif the filters return no results) remain unchanged. Please see the filestests/json-c/filter.candtests/python/test_filter.pyFixes: # (if applicable)
Type of Change
Please check the relevant option(s):
How Has This Been Tested?
Please describe the test strategy:
Commands used (if applicable):
Checklist
Additional Context
Add any additional context or screenshots if necessary.