Skip to content

refactor(api): enforce type annotations on whitelisted methods - #306

Closed
github-actions[bot] wants to merge 1 commit into
mainfrom
backport-303-to-main
Closed

refactor(api): enforce type annotations on whitelisted methods#306
github-actions[bot] wants to merge 1 commit into
mainfrom
backport-303-to-main

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Automated backport of #303 to main.

* refactor(api): enforce type annotations on whitelisted methods
Turn on require_type_annotated_api_methods so Frappe rejects any whitelisted
method whose arguments are not annotated. No annotations had to be added:
typing_validations.py skips the first parameter when it is self/cls, and every
whitelisted controller method in the app takes only self.
This is runtime cover for what CI already blocks statically. The Linters
workflow runs frappe/semgrep-rules, whose missing-argument-type-hint rule
(rules/security/whitelisted.yml) fails the build on an unannotated whitelisted
argument. The hook catches what a syntactic rule cannot see, and unlike semgrep
it cannot be silenced with a nosemgrep comment.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
* refactor: drop a stray whitelist and use frappe.parse_json
BuzzEvent.after_insert was whitelisted, which made a lifecycle hook remotely
re-runnable through run_doc_method. Re-running it duplicates the default
sponsorship tiers and ticket types and then calls save(ignore_permissions=True).
Nothing calls it remotely.
Replace the last two json.loads calls with frappe.parse_json. It already returns
a frappe._dict for dict payloads, so payments.py collapses to a single call and
its function-local import goes with it. In event_booking.py the except clause
widens to (ValueError, TypeError): orjson.JSONDecodeError subclasses
json.JSONDecodeError so the old clause still caught it, but naming json there
was the last reason to keep the module imported.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
(cherry picked from commit a4f52b2)
@github-actionsgithub-actionsBot added the backport This PR / Issue is a backport for a branch other than develop label Jul 29, 2026
@harshtandiya
harshtandiya deleted the backport-303-to-main branch July 29, 2026 18:41
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backportThis PR / Issue is a backport for a branch other than develop

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@harshtandiya