Skip to content

Wrong filter response when I reduce path by using the property map because of the wrong type of joint. #175

@jfb-NRB

Description

@jfb-NRB

Hello,

We are using the feature that simplifies the path by adding a property mapping.
This mapping is interpreted by generating a "cross join" instead of a "left join" without the mapping. Thus, the results are incorrect.
We are using version 5.x, but the problem is the same in version 6.

Here's a test that reproduces the issue in the version 5.x

@Test
public final void testQuery() {
	//Add a user without UserRole, Can be added in import_user.sql
	userRepository.saveAndFlush(new User(0, "test", null, null, null, new Date(), Status.STARTED, null));

	RSQLJPASupport.addMapping(User.class, new HashMap<String, String>() {{put("roles", "userRoles.role");}});
	final Map<String, JoinType> joinHints = new HashMap<String, JoinType>() {{put("UserRole.role", JoinType.LEFT);}};

	final String rsql = "name==test,userRoles.role.code==admin";
	final List<User> users = userRepository.findAll(toSpecification(rsql, true, null, joinHints));
	log.info("rsql: {} -> count: {}", rsql, users.size());

	final String rsqlWithMapping = "name==test,roles.code==admin";
	final List<User> usersWithMapping = userRepository.findAll(toSpecification(rsqlWithMapping, true, null, joinHints));
	log.info("rsql: {} -> count: {}", rsqlWithMapping, usersWithMapping.size());

	assertThat(rsqlWithMapping, usersWithMapping.size(), is(users.size()));
}

The problem may be with the RSQLJPAPredicateConverter class in the findPropertyPath function.
The function uses a loop to iterate through the properties, but if a property has a mapping, the function uses recursion on the mapping without adding the rest of the properties. This leads to a bad check when calling "properties[i + 1]" which is null while there are still properties.
It seems to me that we should remove the loop on the properties and use only recursion, either on the mapping with the rest of the properties to be processed, or on the rest of the properties to be processed alone.

Could you also fix version 5.x because our project is still in SpringBoot 2.
Thanks for your follow-up

Regards

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions