MCPcopy
hub / github.com/TaskingAI/TaskingAI / check_path_params

Function check_path_params

backend/app/routes/utils.py:85–115  ·  view source on GitHub ↗

Check if kwargs contains all the primary key fields except the id field.

(
    model_operator: ModelOperator,
    object_id_required: bool,
    path_params: Dict,
)

Source from the content-addressed store, hash-verified

83
84
85def check_path_params(
86 model_operator: ModelOperator,
87 object_id_required: bool,
88 path_params: Dict,
89):
90 """Check if kwargs contains all the primary key fields except the id field."""
91 entity_class = model_operator.entity_class
92 id_field_name = entity_class.id_field_name()
93 primary_key_fields = entity_class.primary_key_fields()
94
95 # Only the id field is required
96 required_fields = [field for field in primary_key_fields if "id" in field]
97
98 # If the id field is required, add it to the required fields
99 for k in required_fields:
100 if k not in path_params and (k != id_field_name or object_id_required):
101 raise_request_validation_error(f"Missing path parameter: {k}")
102
103 # check all oath params are alphanumeric
104 for k, v in path_params.items():
105 if not alphanumeric_pattern.match(v):
106 raise_request_validation_error(f"Invalid path parameter: {k}")
107
108 # Check each id field
109 try:
110 entity_class.validate_path_params(path_params)
111 except ValidationError as exc:
112 detail = exc.errors()[0]
113 raise_request_validation_error(f"{detail['loc'][0]}: {detail['msg']}")
114
115 return
116
117
118async def path_params_required(request: Request) -> Dict[str, str]:

Callers 15

api_ui_get_assistantFunction · 0.90
api_ui_list_assistantsFunction · 0.90
api_get_ui_collectionFunction · 0.90
api_list_ui_collectionsFunction · 0.90
api_getFunction · 0.85
api_listFunction · 0.85
api_createFunction · 0.85
api_updateFunction · 0.85
api_deleteFunction · 0.85
api_getFunction · 0.85
api_listFunction · 0.85
api_createFunction · 0.85

Calls 4

validate_path_paramsMethod · 0.80
id_field_nameMethod · 0.45
primary_key_fieldsMethod · 0.45

Tested by

no test coverage detected