-
-
Notifications
You must be signed in to change notification settings - Fork 505
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
Fix failing tests #2452
Fix failing tests #2452
Conversation
82e0447
to
c11de01
Compare
Re
Feel free to remove the test. It'd have value without types in the ctor 👍 |
180c123
to
e7b5287
Compare
I have no idea to be honest, I couldn't find an example like the format we had in the documentation:
maybe @alexandre-abrioux can help here? |
Hey! Nice find for the |
cc @jmikola we might need your awesome detective skills :) |
@@ -197,7 +197,7 @@ the ``odm:schema:create`` or ``odm:schema:update`` command. | |||
}, | |||
"$or": [ | |||
{ "phone": { "$type": "string" } }, | |||
{ "email": { "$regex": { "$regularExpression" : { "pattern": "@mongodb\\.com$", "options": "" } } } }, | |||
{ "email": { "$regex": "@mongodb\\.com$" } }, |
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.
I wasn't aware of these examples, but I see no reason we should have ever nested $regularExpression
within a $regex
. $regularExpression
is the extended JSON syntax for a BSON regex type. $regex
in extended JSON was legacy syntax that predated that spec, and it wasn't kept because of the conflict with the $regex
query operator. The only example I found of nesting $regularExpression
within $regex
is within a note in the Extended JSON spec about parsing legacy syntax.
To clarify, were you seeing a "Unexpected nested object value for..." error on the latest version of the PHP driver (with libmongoc 1.22)? I think the code path we're seeing here relates to this bit of the libmongoc PR @franmomu dug up. I'm not familiar with the PR but it looks like some of the legacy parsing might have been removed. That might have been unintended, so I'll raise a comment in CDRIVER-3380 to confirm.
Assuming these code examples were depending on the legacy syntax parser, I think the direct change would be to drop $regex
and just use the $regularExpression
object as the value of email
. That would continue to match an email
field against a BSON regex type.
That said, matching email
with the query operator works just as well. IMO, there isn't much reason to use a BSON regex type when writing queries. It's more useful when you actually need to store a regex type for some reason.
Outside of extended JSON parsing, I don't know offhand if a $regex
query operator would accept a BSON regex type; however, that wouldn't apply here since the entire $jsonSchema
string is likely being run through the driver's extended JSON parser. I suppose this is more an academic question were you to write something like a find
query that used $regex
and an instance of MongoDB\BSON\Regex
. Not worth thinking about further, but I wan't to mention it :)
Thank you, @jmikola, for all the details! I think I used { "email": { "$regularExpression" : { "pattern": "@mongodb\\.com$", "options": "" } } }, |
This tests started to fail with the 1.14 version of the driver
We were testing the annotation instantiation which is done by doctrine/annotations package.
@alexandre-abrioux: Just to clarify, I think modifiers would still have been possible by using $regex vs. /pattern/ Syntax is basically explaining the subtle differences between the two and why you might need to use the |
@jmikola Great! Thanks for clarifying! |
I'm gonna merge this with failing SA/CS jobs so the history of this PR (especially conversation) is easily accessed through |
Summary
These tests started to fail using the 1.14 version of the driver: https://github.com/doctrine/mongodb-odm/runs/7379626257?check_suite_focus=true.
Digging into these fails I've ended up in mongodb/mongo-c-driver#988 which seems to be the origin.
IIUC #2238 (comment), the data in the tests is from https://www.mongodb.com/docs/manual/core/schema-validation/#other-query-expressions, so I've updated it to simplify it.
Should we add another field and validation using
$regularExpression
?The remaining fail is because of doctrine/annotations#438, maybe we should remove that tests since it's up to the reader to throw errors or bump
doctrine/annotations
to the latest version (1.13.3).