spring-data-commons icon indicating copy to clipboard operation
spring-data-commons copied to clipboard

Defect in QueryDSLBindings class while updating local field pathSpecs for ListPath [DATACMNS-1302]

Open spring-projects-issues opened this issue 7 years ago • 2 comments

GT opened DATACMNS-1302 and commented

The method in question is below in QuerydslBindings class -

{{^private static String fromRootPath(Path<?> path) {

	Path<?> rootPath = path.getMetadata().getRootPath();

	if (rootPath == null) {
		throw new IllegalStateException(String.format("Couldn't find root path on path %s!", path));
	}

	return path.toString().substring(rootPath.getMetadata().getName().length() + 1);
}^}}

Let's say I have customized bindings for 3 paths for root object QUser with root name in generated metadata as "user":

  • user.userName
  • user.profile.internalSystemID
  • user.emails.any().value which gets internally translated as any(user.emails).value

When bindings are updated locally in pathSpecs, the logic in above method simply tries to strip the root object path name and following DOT, so in this case it ends up storing following 3 entries:

  • userName
  • profile.internalSystemID
  • ser.emails).value <--- this is a wrong key

During a subsequent phase when bindings are invoked, since invocation logic isn't able to find the binding using key "emails.value" (which is how the HTTP request parameter is expected to be named) in pathSpec, it uses the default binding which is obviously different from what we wanted.

Unfortunately it's a private static method, so we can override anything on our end. Also, we could have worked around it by trying to also register an alias with this binding but none of the binder methods exposed take alias an argument and hence when they internally construct AliasingPathBinder, the alias is always null.


No further details from DATACMNS-1302

spring-projects-issues avatar Apr 19 '18 06:04 spring-projects-issues

GT commented

I figured a way around it by closely looking at source, by aliasing the original binder returned and then adding the binding. It worked ok! Issue can be closed though it would have been nice for core bind(...path..) method to handle the spec update itself. Or perhaps a note in document for custom binding on ListPath, users are required to alias it.

bindings.bind(root.emails.any().value) .as("emails" + ".value") .all( (path, values) -> new CollectionComparison(path, values) .predicate() );

spring-projects-issues avatar Apr 19 '18 07:04 spring-projects-issues

as of this posting it appears this issue is still present. a simpler work around for this may be : bindings.bind(root.emails.any().value).as("email.value") .all((path, x) -> Optional.empty()); `

       please note that the alias name must be different that the original path name. 

mconklin-sqsp avatar Sep 15 '22 21:09 mconklin-sqsp