Skip to content

Backwards incompatibilities on @Query [DATAMONGO-2545] #3401

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
spring-projects-issues opened this issue May 12, 2020 · 2 comments
Closed

Backwards incompatibilities on @Query [DATAMONGO-2545] #3401

spring-projects-issues opened this issue May 12, 2020 · 2 comments
Assignees
Labels
in: repository Repositories abstraction type: bug A general bug

Comments

@spring-projects-issues
Copy link

Steve Jerman opened DATAMONGO-2545 and commented

I posted this to /. but I think its actually a bug:

https://stackoverflow.com/questions/61740106/moving-query-to-2-2-6
 
I am moving our code to Spring Data MongoDB 2.2.6 from 2.1.X and am having some issues with some repository queries (that have worked in the past).

One example:

 {{ @Query(
 " ?#{ hasRole('ROLE_ADMIN') ? {'_class': { '$eq' : 
 'region }} : { '$and' : { {'_class': { '$eq' : 'region' }}, {'$or': {{'users._id': 
 { '$oid' :principal.id}},{'usersFromHierarchy._id':{ '$oid' :principal.id}}} } } } } ")
 List<Region> findRegions();}}

Doesn't get evaluated since the evaluation seems to expect a valid BSON document at the start of the query string. It only evaluates parameters.

Another:

 `@Query("{ 'name' : ?#{ hasRole('ROLE_ADMIN') ? '?0' : '?1' `")
 Optional<TestObject> findByAuthName(String name, String name2);}}

Doesn't work ... it always selects the first parameter.

Looking at the code, seems like org.springframework.data.mongodb.util.json.ParameterBindingJsonReader is interpreting the ?#{..} as a parameter binding (line 369) and munging down to the first call param...

Is there any guidance on this? What are the restrictions?

 


Affects: 2.2.7 (Moore SR7)

Referenced from: pull request #864

Backported to: 3.0.1 (Neumann SR1), 2.2.8 (Moore SR8)

@spring-projects-issues
Copy link
Author

Christoph Strobl commented

Good catch - thanks for reporting!

@spring-projects-issues
Copy link
Author

Steve Jerman commented

Thanks for having a look. Happy to help if needed...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: repository Repositories abstraction type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants