-
-
Notifications
You must be signed in to change notification settings - Fork 218
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
Check for custom callouts on app builds #35628
base: master
Are you sure you want to change the base?
Changes from 9 commits
a847070
dd8145e
9e400b1
16745fb
fb0ff78
2741b7e
265a39d
30598b0
f274054
8b8e04c
cd95688
452b577
6968738
58df9e1
751d406
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
from couchdbkit import ResourceNotFound | ||
from couchdbkit.exceptions import DocTypeError | ||
|
||
from memoized import memoized | ||
from dimagi.utils.couch import CriticalSection | ||
|
||
from corehq import toggles | ||
|
@@ -540,7 +541,13 @@ def _app_callout_templates(): | |
yield data | ||
|
||
|
||
@memoized | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Memoized is only an in-memory cache, so it isn't the thing to use here, you'll want to cache across requests. I was thinking you could quickcache, probably for a while, maybe a week or longer. Check out these docs if you haven't seen them. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Ah, I thought it was the other way around (but haven't read that docs to be honest). Probably the "quick" in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cool, thanks for updating |
||
def _app_callout_templates_ids(): | ||
return {t['id'] for t in next(_app_callout_templates())} | ||
|
||
|
||
app_callout_templates = _app_callout_templates() | ||
app_callout_templates_ids = _app_callout_templates_ids() | ||
|
||
|
||
def purge_report_from_mobile_ucr(report_config): | ||
|
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.
Potential
IndexError
when accessing previous build IDIn
check_build_dependencies
, lines 142-143 calculateprevious_build_id
usingapp_build_ids[app_build_ids.index(new_build.id) + 1]
. Ifnew_build.id
is the last element inapp_build_ids
, this will result in anIndexError
. Additionally, ifnew_build.id
is not inapp_build_ids
, aValueError
will be raised.Modify the code to handle these edge cases safely:
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.
Good point
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.
@Charl1996 Would you like me to help you implement the suggested fix to handle the edge cases safely? Let me know if you need any assistance.
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.
No, it's fine. I don't think this will be a concern because the docstring in the
get_build_ids
says the following:"Returns all the built apps for an application id, in descending order of time built."
I've verified that it's indeed so, meaning
new_build.id
will definitely exist in the listlen(app_build_ids)
will evaluate to false, meaning this block of code won't execute in the first place.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.
@Charl1996 I've found the implementation in
dbaccessors.py
and can confirm your explanation. The docstring indeed explicitly states that it "Returns all the built apps for an application id, in descending order of time built." This validates your assessment of the code's safety. Thank you for helping me understand the implementation better.🔗 Analysis chain
@Charl1996 Thank you for the detailed explanation. I understand now that the code is indeed safe due to the guarantees provided by
get_build_ids
. Your explanation makes perfect sense - since the builds are returned in descending order and the new build will always be present, we don't need additional error handling.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 1548
✏️ Learnings added
If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!
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.
Here's a carrot, Mr Rabbit!
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.
@Charl1996 🥕 Thank you for the carrot! happy rabbit noises 🐰
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 agree this shouldn't be an issue, but you could save readers from going through the same thought process you outlined, and make it obvious that isn't an issue, by doing something like:
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.