-
Notifications
You must be signed in to change notification settings - Fork 10
IA-4652: Fix looking up instances using JSONLogic with suffixed questions #2628
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
base: develop
Are you sure you want to change the base?
IA-4652: Fix looking up instances using JSONLogic with suffixed questions #2628
Conversation
Due to the mobile application's need to assign a type to some calculated questions, the JSONField `Instance.json` might contain keys with a suffix like this: `__int__`. This collides with DRF's way to declare accessing sub-objects properties or even casting. The cleanest solution is to annotate the queryset to give those keys a name not containing `__`. After the query has been annotated, we can refer to that name and avoid any collisions. IA-4652
|
Original PR is here |
|
Staphan comment: apparently there's some black magic at play... it's working but don't know why ;)
OK I think I found out running the produced sql show warning but execute properly but in fact the UI is just using the json field not that new column |
That is a very good point, although, the code replace a character by another one. I.e.: I thought of naming with indexed aliases like Although, now that I think about it, I wonder if PostGreSQL would complain if we have 2 times the same annotation, like if we said: { "and": [
{"<": [{"var": "age__int__"}, 6] },
{">": [{"var": "age__int__"}, 2] },
]}We might have to use an indexed alias to avoid this situation. |
bramj
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Auwch, this is an annoying one, seems like there's no way around it than the annotate everything like you're doing here.
I didn't properly test, but from the looks of it this looks like it's working.
The iaso/utils/jsonlogic.py has become very complex, almost feels like it should be extracted as a package.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't try it, but for this method, it didn't work to do the annotation right after this line? https://github.com/BLSQ/iaso/blob/fix/IA-4652_suffixed_questions_not_working_in_json_logic_filters/iaso/api/entity.py#L227
`some` and `all` operators would fail when used with `in` operator since, in this case, the `var` is in first position. `some` and `all` operators using double underscore fields would fail due to no aliasing the fields name. Using twice the same field with double underscore would fail due to aliasing with twice the same name. Also, fix enketo not working locally when accessing Iaso using `127.0.0.1` IA-4652
|
TOKEN=$(curl -s -X POST 'http://localhost:8081/api/token/' FILTER='{"==": [{"var": "age__int__"}, 25]}' FILTER='{"and": [{"==": [{"var": "gender"}, "female"]}, {">": [{"var": "age__int__"}, 30]}]}' I have tested those endpoints and got the correct response |

Due to the mobile application's need to assign a type to some calculated questions, the JSONField
Instance.jsonmight contain keys with a suffix like this:__int__. This collides with DRF's way to declare accessing sub-objects properties or even casting.The cleanest solution is to annotate the queryset to give those keys a name not containing
__. After the query has been annotated, we can refer to that name and avoid any collisions.IA-4652
What problem is this PR solving? Explain here in one sentence.
Related JIRA tickets : IA-4652
Self proofreading checklist
Doc
Tell us where the doc can be found (docs folder, wiki, in the code...).
Changes
Explain the changes that were made.
The idea is not to list exhaustively all the changes made (GitHub already provides a full diff), but to help the reviewers better understand:
How to test
Explain how to test your PR.
If a specific config is required explain it here: dataset, account, profile, etc.
Print screen / video
Upload here print screens or videos showing the changes.
Notes
Things that the reviewers should know:
Follow the Conventional Commits specification
The merge message of a pull request must follow the Conventional Commits specification.
This convention helps to automatically generate release notes.
Use lowercase for consistency.
Example:
Note that the Jira reference is preceded by a line break.
Both the line break and the Jira reference are entered in the Add an optional extended description… field.