Repository navigation
Description
Search before asking
- I had searched in the issues and found no similar issues.
What happened
K8sNamespaceMapper#queryByNamespaceCode annotates its only parameter with @Param("clusterCode"):
// dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/K8sNamespaceMapper.java#L75
K8sNamespace queryByNamespaceCode(@Param("clusterCode") Long namespaceCode);but the mapped statement in K8sNamespaceMapper.xml reads #{namespaceCode}:
<!-- dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/K8sNamespaceMapper.xml#L73-L78 -->
<select id="queryByNamespaceCode" resultType="org.apache.dolphinscheduler.dao.entity.K8sNamespace">
select
<include refid="baseSql"/>
from t_ds_k8s_namespace
where code = #{namespaceCode}
</select>Because of @Param("clusterCode"), MyBatis only exposes clusterCode and param1 to the statement, so calling queryByNamespaceCode will fail with:
org.apache.ibatis.binding.BindingException: Parameter 'namespaceCode' not found. Available parameters are [clusterCode, param1]
Nothing on dev calls K8sNamespaceMapper#queryByNamespaceCode or K8sNamespaceDao#queryByNamespaceCode today, which is probably why this has not been noticed. Since #18257 the method is part of the K8sNamespaceDao API, so the first caller will hit this exception.
What you expected to happen
queryByNamespaceCode(code) returns the K8sNamespace whose code equals the argument, or null if there is none.
How to reproduce
Add this test to K8sNamespaceMapperTest and run it on dev:
@Test
public void testQueryByNamespaceCode() {
K8sNamespace entity = insertOne();
Assertions.assertNotNull(k8sNamespaceMapper.queryByNamespaceCode(entity.getCode()));
}./mvnw verify -pl dolphinscheduler-dao -DskipUT=false -Dtest=K8sNamespaceMapperTestBased on MyBatis' parameter binding this fails with the BindingException above unless @Param("clusterCode") is changed to @Param("namespaceCode").
Anything else
- The mismatch was introduced together with the method in [Feature-10629][Improvement] Support multi cluster environments - namespace use cluster #10650 (it uses the same
@Param("clusterCode")name asexistNamespaceright above it). It is present on the 3.1.x–3.4.x release branches and ondev. - I noticed it with a small static check that compares
@Paramnames with the#{...}/${...}references in mapper XML files. On currentdevit reports no other mismatch of this kind. - Two possible fixes:
(a) change the annotation to@Param("namespaceCode")and add a unit test. This is a one-line change and does not touch the XML file, which [DSIP-104][ApiServer][UI] Introduce project-scoped authorization #18718 also modifies;
(b) remove the unused method fromK8sNamespaceMapper, its XML,K8sNamespaceDaoandK8sNamespaceDaoImpl.
I will open a PR for (a), and I am happy to switch to (b) if you prefer.
Version
dev
Are you willing to submit PR?
- Yes I am willing to submit a PR!
Code of Conduct
- I agree to follow this project's Code of Conduct
Activity