-
Notifications
You must be signed in to change notification settings - Fork 81
Fixes error message when lat and lng are unparseable #763
Fixes error message when lat and lng are unparseable #763
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @ahlner , thank you for the PR :)
After a bit more testing, I realised the bug lies somewhere else than in the validate_geo_from_json
function.
On line 98-102, we have the following bit of code, giving us the internal id (u16) of the _geo
field:
// If the settings specifies that a _geo field must be used therefore we must check the
// validity of it in all the documents of this batch and this is when we return `Some`.
let geo_field_id = match documents_batch_index.id("_geo") {
Some(geo_field_id) if index.sortable_fields(rtxn)?.contains("_geo") => Some(geo_field_id),
_otherwise => None,
};
But if _geo
is only a filterableAttribute
(i.e. not a sortableAttribute
), then geo_field_id
will be equal to None
and the validate_geo_from_json
function will not be called. This will cause indexing to progress further, until the extract_geo_points
function is called (in milli/src/update/index_documents/extract/extract_geo_points.rs
) where a second (redundant) verification is performed. This second verification is the one that returns the wrong error message. However, I don't think it's necessary to change anything in extract_geo_points
, since it is not supposed to catch any more errors anyway.
The easiest/best fix is probably to replace the condition if index.sortable_fields(rtxn)?.contains("_geo")
with one that checks whether the index contains _geo
either in sortable_fields
or in filterable_fields
.
Let me know if you want to amend your PR or if you'd prefer us to make the fix :)
Hi @loiclec, thank you for the answer. I would prefer to write a test like this benchmark: benches/indexing.rs and amend this PR with tests and a fix. Is there already a (integration) test for this functionality? |
That sounds great! An integration test would be very appreciated 😄 #[test]
fn bug_3007() { // or a more descriptive name
let index = TempIndex::new();
index
.update_settings(|settings| {
// set the index's settings
}).unwrap();
// add some documents. Here you wouldn't unwrap, but check the content of the error instead.
index.add_documents(documents!({ "a" : "id"})).unwrap();
} We like to use inline snapshot tests with |
Adds a test for #3007: Wrong error message when lat and lng are unparseable
023f926
to
0e1ae75
Compare
Hi @loiclec, I've reworked the fix, please review again ;) |
The test "update::index_documents::tests::index_all_flavour_of_geo" is failing now. The format of the longitude ( |
Another test fails now:
The first one comes from (the wrong check) extract_geo_points where the document_id is a Value::Number() Now it comes from validate_geo_from_json where the document_id is a Value::String() from the debug-impl of DocumentId. I've found a more convenient way to refactor debug_id to deserialize the id in the same way as if it's loaded (and not auto-generated). |
5ff0178
to
1dcd538
Compare
Oh, that's interesting! As far as I can tell, it's a bug that: { "id": 0, "_geo": { "lat": 31, "lng": [42] } } is still sometimes accepted (doc link). But I'll ping @gmourier to make sure, and also @irevoire to judge the impact of it on the dump feature. IMO, it's the perfect opportunity to fix it since we are going to release meilisearch v1.0 very soon :-) Then, after you delete the whole |
1dcd538
to
a647b4d
Compare
Ok, perfekt. There was an formatting issue, I've (hopefully) fixed that. |
a647b4d
to
a2cd721
Compare
bors try |
tryBuild succeeded: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for the PR! :)
bors merge
Let me know if I'm wrong @loiclec, but Is not fixed in this PR, right? |
@irevoire no, it is fixed :) |
Pull Request
Related issue
Fixes partially #3007
What does this PR do?
PR checklist
Please check if your PR fulfills the following requirements:
Thank you so much for contributing to Meilisearch!