-
Notifications
You must be signed in to change notification settings - Fork 1.4k
PHPORM-60 Fix Query on whereDate, whereDay, whereMonth, whereYear #2572
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
Conversation
Codecov ReportPatch coverage:
❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more. Additional details and impacted files@@ Coverage Diff @@
## master #2572 +/- ##
============================================
+ Coverage 90.57% 90.83% +0.26%
- Complexity 748 752 +4
============================================
Files 34 34
Lines 1783 1834 +51
============================================
+ Hits 1615 1666 +51
Misses 168 168
☔ View full report in Codecov by Sentry. |
CHANGELOG.md
Outdated
@@ -16,6 +16,7 @@ All notable changes to this project will be documented in this file. | |||
- Remove `Query\Builder::whereAll($column, $values)`. Use `Query\Builder::where($column, 'all', $values)` instead. [#16](https://github.com/GromNaN/laravel-mongodb-private/pull/16) by [@GromNaN](https://github.com/GromNaN). | |||
- Fix validation of unique values when the validated value is found as part of an existing value. [#21](https://github.com/GromNaN/laravel-mongodb-private/pull/21) by [@GromNaN](https://github.com/GromNaN). | |||
- Support `%` and `_` in `like` expression [#17](https://github.com/GromNaN/laravel-mongodb-private/pull/17) by [@GromNaN](https://github.com/GromNaN). | |||
- Fix Query on `whereDate`, `whereDay`, `whereMonth`, `whereYear`, `whereTime` to use MongoDB operators [#2376](https://github.com/jenssegers/laravel-mongodb/pull/2376) by [@Davpyu](https://github.com/Davpyu) |
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 noticed some of the earlier changelog entries refer to your old URL. For instance, https://github.com/GromNaN/laravel-mongodb-private/pull/16
redirects to GromNaN/laravel-mongodb#16. I assume your archived fork will remain public for the forseeable future but would it make more sense to replace most of these links with references to PHPORM tickets, which might be more permanent?
This is outside the scope of this PR, so I'm happy to defer this until we're closer to tagging a release with this changelog.
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.
src/Query/Builder.php
Outdated
], | ||
], | ||
'ne' => [ | ||
'$or' => [ |
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.
Can we continue to conversation about segfaults from GromNaN/laravel-mongodb#28 (comment)?
You wrote:
I tested this alternative, but got segfaults.
'ne' => ['$not' => [ $column => [ '$gte' => $startOfDay, '$lte' => $endOfDay, ], ]],
My response:
Segfaults in mongod (executing the query) or PHP (executing this match construct)?
I'm trying to think about how this would trigger a segfault in PHP. The only thing I can think of is that $column is referenced at multiple levels of the same return value. If so, that seems like something you might be able to isolate in a PHPT test. I'd be happy to dive into it further if so.
If this is actually a mongod segfault, I assume it'd be reproducible in the shell and would warrant a new SERVER ticket.
Over video, you mentioned that the segfault was in PHP after receiving an error message from the server. So if you can extract this to a reproducible failing PHPUnit test that'd be a good starting point for me to look into.
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.
Updated to use the $not
format proposed (and fixed).
The segfault occurs when the query in invalid and the server return an error message.
Checkout this branch : https://github.com/gromnan/laravel-mongodb-fork/tree/PHPORM-60-segfault
./vendor/bin/phpunit tests/QueryTest.php --filter testWhereDate
PHPUnit 9.6.11 by Sebastian Bergmann and contributors.
segmentation fault ./vendor/bin/phpunit tests/QueryTest.php --filter testWhereDate
The error event was:
unknown top level operator: $not. If you are trying to negate an entire expression, use $nor.
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.
@GromNaN: What version of PHP, ext-mongodb
, and MongoDB were you running when you observed a segfault? I'm not seeing it with PHP 8.2.3, ext-mongodb
1.16.2, and MongoDB 6.0.5:
$ ./vendor/bin/phpunit tests/QueryTest.php --filter testWhereDate
PHPUnit 9.6.11 by Sebastian Bergmann and contributors.
E 1 / 1 (100%)
Time: 00:00.228, Memory: 24.00 MB
There was 1 error:
1) Jenssegers\Mongodb\Tests\QueryTest::testWhereDate
MongoDB\Driver\Exception\CommandException: unknown top level operator: $not. If you are trying to negate an entire expression, use $nor.
/home/jmikola/workspace/mongodb/laravel-mongodb-fork/vendor/mongodb/mongodb/src/Operation/Find.php:314
/home/jmikola/workspace/mongodb/laravel-mongodb-fork/vendor/mongodb/mongodb/src/Collection.php:644
/home/jmikola/workspace/mongodb/laravel-mongodb-fork/src/Collection.php:48
/home/jmikola/workspace/mongodb/laravel-mongodb-fork/src/Query/Builder.php:420
/home/jmikola/workspace/mongodb/laravel-mongodb-fork/src/Query/Builder.php:211
/home/jmikola/workspace/mongodb/laravel-mongodb-fork/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:735
/home/jmikola/workspace/mongodb/laravel-mongodb-fork/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:719
/home/jmikola/workspace/mongodb/laravel-mongodb-fork/tests/QueryTest.php:204
/home/jmikola/workspace/mongodb/laravel-mongodb-fork/vendor/orchestra/testbench-core/src/PHPUnit/TestCase.php:42
ERRORS!
Tests: 1, Assertions: 0, Errors: 1.
[ | ||
'$dateToString' => ['date' => '$'.$where['column'], 'format' => '%H:%M:%S'], | ||
], | ||
$where['value'], |
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.
We talked about validating user input. Should we enforce a string in the format HH:MM:SS
and permit trailing components to be omitted (e.g. allow HH:MM
or even just HH
)?
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.
Fixed with support for various time formats.
4f1e8b2
to
317ba9f
Compare
…ective query rather than using basic comparison
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.
Code changes LGTM.
We can take the segfault discussion over to Slack if you like, since it seems unrelated to this PR.
|
||
$where['operator'] = $operator; | ||
$where['value'] = $value; | ||
$format = match (count($matches)) { |
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.
Clever use of count($matches)
.
Fix PHPORM-60
Created from #2376
whereDate
uses$lt
&$gt
comparison withUTCDateTime
objectswhereDay
uses$dayOfWeek
whereMonth
uses$month
whereYear
uses$year
whereTime
uses$dateToString
to format intoHH:MM:SS
,HH:MM
orHH
(not performance optimized)