Fix API circuit type validation rejecting valid circuitTypes ids - #4643
Open
ammad-elev8ai wants to merge 1 commit into
Open
Fix API circuit type validation rejecting valid circuitTypes ids#4643ammad-elev8ai wants to merge 1 commit into
ammad-elev8ai wants to merge 1 commit into
Conversation
validate_circuit_type() treated circuits.type as a legacy MySQL enum column and parsed allowed values out of getFieldInfo()'s Type string. type is now an int FK into circuitTypes, so every POST/PATCH containing type failed with "Invalid circuit type", even for valid ids. Validate against real circuitTypes rows instead, matching the existing non-API pattern in edit-circuit-submit.php.
4 tasks
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.
Part of #4642 (context/overview for a set of 4 related API fixes).
Bug
POST/PATCHto/api/{app_id}/circuits/reject every request that includes atype,even a valid one:
{"code": 400, "success": false, "message": "Invalid circuit type", "time": 0.004}Same result on
PATCH:{"code": 400, "success": false, "message": "Invalid circuit type", "time": 0.003}typefails no matter what's supplied - a numeric id, a string id, or the type's name allproduce the same error. A
PATCHthat omitstypeentirely (e.g. onlycapacity) worksfine, which was the tell.
Root cause
validate_circuit_type()treatscircuits.typeas a legacy MySQLenum(...)column andtries to parse the allowed values out of
getFieldInfo("circuits", "type")->Type.typewas migrated to a plain
int(10) unsignedforeign key into thecircuitTypeslookup tablesome time ago, so
getFieldInfo()now returns"int(10) unsigned"as theTypestring -never anything resembling a real type id - and the
in_array()check fails unconditionally.Fix
Validate
typeagainst realcircuitTypesrows instead, mirroring the already-correctpattern already used by the non-API UI in
app/admin/circuits/edit-circuit-submit.php(fetch real rows via
Tools->fetch_all_objects("circuitTypes", "ctname"), check thesubmitted id against real ids). The "no type supplied on create" fallback now resolves to
the
circuitTypesrow namedDefault's actual numeric id, instead of assigning theliteral string
"Default"to a now-numeric column.Fixes #4038
Fixes #3148
Tested with
Verified: the exact failing POST/PATCH payloads above now succeed; a genuinely invalid
type(e.g.999) is still correctly rejected; an invalidprovideris still correctlyrejected; the previously-working capacity-only PATCH still works. Customers/Locations
regression-checked, unaffected.
Tested against PHP 8.2, 8.3, and 8.4 (the full range
develop's README lists assupported) - lint clean and all scenarios passing on each, no new entries in the PHP error
log.