Skip to content

[Bug] [DAO] K8sNamespaceMapper#queryByNamespaceCode uses @Param("clusterCode") but its XML expects #{namespaceCode} #18776

Closed

Description

@andrehqh

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=K8sNamespaceMapperTest

Based 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 as existNamespace right above it). It is present on the 3.1.x–3.4.x release branches and on dev.
  • I noticed it with a small static check that compares @Param names with the #{...} / ${...} references in mapper XML files. On current dev it 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 from K8sNamespaceMapper, its XML, K8sNamespaceDao and K8sNamespaceDaoImpl.
    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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

backendbugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions