Skip to content

QueryMapper and UpdateMapper do not properly consider @DocumentReference to non-id properties #3853

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
mp911de opened this issue Oct 5, 2021 · 0 comments
Assignees
Labels
type: bug A general bug

Comments

@mp911de
Copy link
Member

mp911de commented Oct 5, 2021

Using document references with non-Id properties in the context of queries and updates render invalid query documents. Consider the two examples below.

@DocumentReference(lookup = "{ 'name' : ?#{#target} }")
Query: {"customer": {"target": "wu"}, "sample": {"$oid": "615c04ae3fc147443f2a3352"}}

@DocumentReference(lookup = "{ '_id' : ?#{#target} }")
Query: {"customer": {"$oid": "615c04e09b072503508c6321"}, "sample": {"$oid": "615c04e09b072503508c6322"}}

Reproducer:

@Test
void mapsDocumentReferences() {

	Customer customer = new Customer();
	customer.id = new ObjectId();
	customer.name = "wu";

	Sample sample = new Sample();
	sample.foo = new ObjectId().toString();

	org.bson.Document mappedQuery = mapper.getMappedObject(
			Criteria.where("customer").is(customer).and("sample").is(sample).getCriteriaObject(),
			context.getPersistentEntity(WithReference.class));
	// …
}

Object model

@Document
static class Customer {

	@Id
	private ObjectId id;
	private String name;
	private MyAddress address;
}

static class Sample {

	@Id private String foo;
}

@Document
static class WithReference {

	private ObjectId id;
	private String name;
	@DocumentReference(lookup = "{ 'name' : ?#{#target} }") // remove `lookup` for the other test case.
	private Customer customer;

	@DocumentReference
	private Sample sample;
}
@mp911de mp911de added the type: bug A general bug label Oct 5, 2021
@mp911de mp911de closed this as completed in 673a81a Oct 7, 2021
mp911de added a commit that referenced this issue Oct 7, 2021
Reformat code.

See #3853
Original pull request: #3856.
@mp911de mp911de added this to the 3.3 RC1 (2021.1.0) milestone Oct 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
2 participants