Tencent/APIJSON · critical · UnsupportedOperationException
写操作请求必须带条件!!!
Error message
写操作请求必须带条件!!!
What it means
getWhereString() builds the WHERE clause from the where map + @combine; if the result is empty AND the request method is not a query method (isQueryMethod covers GET/HEAD and similar), it throws UnsupportedOperationException. APIJSON deliberately forbids unconditional writes/updates/deletes — an UPDATE or DELETE with no WHERE would affect every row in the table.
Source
Thrown at APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java:3396
return getWhereString(hasPrefix, getMethod(), getWhere(), getCombineMap(), getJoinList(), ! isTest());
}
return getWhereString(hasPrefix, getMethod(), getWhere(), combineExpr, getJoinList(), ! isTest());
}
/**获取WHERE
* @param method
* @param where
* @return
* @throws Exception
*/
public String getWhereString(boolean hasPrefix, RequestMethod method, Map<String, Object> where
, String combine, List<Join<T, M, L>> joinList, boolean verifyName) throws Exception {
String whereString = parseCombineExpression(method, getQuote(), getTable(), getAlias()
, where, combine, verifyName, false, false);
whereString = concatJoinWhereString(whereString);
String result = StringUtil.isEmpty(whereString, true) ? "" : (hasPrefix ? " WHERE " : "") + whereString;
if (result.isEmpty() && RequestMethod.isQueryMethod(method) == false) {
throw new UnsupportedOperationException("写操作请求必须带条件!!!");
}
return result;
}
/**解析 @combine 条件 key 组合的与或非+括号的逻辑运算表达式为具体的完整条件组合
* @param method
* @param quote
* @param table
* @param alias
* @param conditionMap where 或 having 对应条件的 Map
* @param combine
* @param verifyName
* @param containRaw
* @param isHaving
* @return
* @throws Exception
*/View on GitHub (pinned to 5284052872)
Solutions
- Add an explicit condition key to the write request, almost always the primary key: {"User":{"id":1,"name":"x"}} for PUT or {"User":{"id":1}} for DELETE.
- If a genuinely global operation is required, do it with a raw/ADMIN-authorized endpoint or a stored procedure — do not try to bypass this guard in ORM code.
- When building requests programmatically, assert the condition map is non-empty before sending (see validation code).
- Check that your conditions are not silently dropped (e.g. misspelled keys filtered by request structure) leaving an empty WHERE.
Example fix
// before (DELETE everything)
{"User":{}}
// after (DELETE one row)
{"User":{"id":1}} Defensive patterns
Strategy: try-catch
Validate before calling
RequestMethod m = parser.getMethod();
if (!RequestMethod.isQueryMethod(m)) {
JSONObject table = request.getJSONObject("User");
boolean hasCondition = table.keySet().stream().anyMatch(k -> !k.startsWith("@"));
if (!hasCondition) throw new IllegalStateException("write request needs a where key (e.g. id)");
} Type guard
function hasWriteCondition(req: Record<string, any>): boolean {
return Object.keys(req).some(k => !k.startsWith('@')); // at least one condition key present
} Try / catch
try { parser.execute(...); } catch (UnsupportedOperationException e) { if (e.getMessage().contains("写操作请求必须带条件")) { /* surface 'missing WHERE' to user, never retry blindly */ } throw e; } Prevention
- Always include the primary key in PUT/DELETE request objects.
- Assert non-empty condition map before sending any non-query request.
- Treat this exception as a hard stop — it prevented a full-table write.
When it happens
Trigger: A PUT/DELETE request (per APIJSON method mapping) whose table object contains no condition keys at all, e.g. {"User":{"name":"a"}} on DELETE where the keys are all consumed as SET columns, or conditions that all resolve to empty (e.g. @combine referencing no effective keys). RequestMethod.isQueryMethod(method) == false is what activates the check at line 3395.
Common situations: Forgetting the id in an update/delete request; building the request dynamically so the condition object ends up empty; migrating a GET-style request to PUT without adding a where key; test scripts that mass-update by intent and hit the safety guard.
Related errors
- {}: { @key(): value } 对应存储过程 value 中字符 {} 不合法!schema.functio
- @raw:value 的 value 中 {} 不合法!对应的 {}: value 在当前对象 {} 不存在或 valu
- key[]:{} 只支持 GET, GETS 方法!其它方法不允许传 {}:{} 等这种 key[]:{} 格式!
- ${key}:{} 里的 @combine:value 不合法!开放请求 GET、HEAD 才允许传 @combine:
- 不支持在 ${method} 中 ${_method} !
AI-assisted analysis of Tencent/APIJSON@5284052872 (2026-08-14).
Data as JSON: /api/errors/4e78e016bb3530d4.
Report an issue: GitHub.