Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
Making tests for the Entity Share module which uses the JSON:API, I found that filtering on a datetime field has unexpected results.
https://www.drupal.org/project/entity_share/issues/3082518#comment-13271362 (failing tests commented out)
Proposed resolution
Unknown
Remaining tasks
- Provide a failing test: DONE
- Found a solution
API changes
Unknown
Release notes snippet
Unknown
Comment | File | Size | Author |
---|---|---|---|
#20 | interdiff_3083561_14-20.txt | 3.42 KB | ankithashetty |
#20 | 3083561-20.patch | 5.96 KB | ankithashetty |
#14 | interdiff_12-14.txt | 669 bytes | raman.b |
#14 | 3083561-14.patch | 5.75 KB | raman.b |
#12 | interdiff_6-12.txt | 2.2 KB | raman.b |
Issue fork drupal-3083561
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
GrimreaperComment #5
mglamanIsn't this working as expected? You are querying by a timestamp and DateTimeItemInterface::DATETIME_STORAGE_FORMAT is
Y-m-d\TH:i:s
. Are you expecting the timestamp to be converted to a string format on query?Looking at: https://www.drupal.org/docs/8/modules/jsonapi/filtering, it is conflicting.
Filtering on Date (Date only, no time)
Filtering on Date (with Date AND Time)
It shows that date and time should require a timestamp. But these docs are using
=
Comment #6
mglamanLooks like the JSON API documentation needs to be updated. You cannot pass a timestamp anymore. You must pass a time string.
Comment #7
GrimreaperThanks @mglaman for the feedbacks.
If it is working with DateTimeItemInterface::DATETIME_STORAGE_FORMAT no problem for me.
As you said, the documentation needs to be updated in this case.
Comment #8
mglamanI updated the documentation node. I figure we can close this, then.
Comment #9
GrimreaperThanks.
Confirming it is working in tests in #3082518-9: Tests: filter, group and sort on channel.
Maybe keeping it opened to have more tests in JSON:API?
Comment #10
Wim LeersI agree this would be a good addition to JSON:API's test coverage.
These still need to be implemented.
core/modules/datetime
?Comment #12
raman.b CreditAttribution: raman.b at OpenSense Labs commented1. Took some inspiration from
core/modules/jsonapi/tests/src/Functional/JsonApiFunctionalTest.php
and added assertions for checking the nodes.2.
Not certain about this one as the issue is still under
jsonapi.module
but would love to do the required changes if neededComment #14
raman.b CreditAttribution: raman.b at OpenSense Labs commentedResolving deprecation notices
Comment #17
bbralaGreat work, this seems like a good addition. I would need a reroll to 9.3.x i think. Could you do that? I'll review it again after.
Comment #18
bbralaNo it doesn't need a reroll. Well done.
Comment #19
quietone CreditAttribution: quietone as a volunteer commentedJust some suggestions for improvements to the comments.
The comment should reflect that this is a test of the date field not a 'General' test.
The naming here is a bit confusing. $timestamp_node_2 is used for node 1 and node 2 and node 3. I think it would be easier to follow to remove the '_node_' part of the name.
These are rather cryptic. It would be easier to understand if this was in plain English.
Comment #20
ankithashettyAddressed changes specified in #19 Not 100% sure about #19.3, gave it a try though. Thanks!
Comment #21
bbralaThanks for the changes (and for the feedback @quietone). Looking good.
Comment #22
Wim LeersNice work here!
I was gonna say "isn't it 'datetime'?" — but no:
🙈
Übernit: 🤔 Why assign it to a variable if you're not going to use it?
Übernit: s/Test/Tests/
So this is the key thing that this is implicitly documenting through tests: you apparently have to use the storage-level datetime representation to get this to work.
That makes sense from a Field API POV.
It's not ideal from a JSON:API POV. But … we can still work to improve this in the future obviously :)
Wonderful to have this explicitly documented & tested!
Keeping at RTBC.
Comment #24
bbralaUnrelated test failure.
Comment #26
GrimreaperHello,
I have created a MR for easier rebase and review.
And taking points 22.2 and 22.3 into account.
22.4: exactly!
Thanks for the review and the updates on the issue :)
Comment #27
alexpottCommitted and pushed 623cc951b5 to 9.3.x and 7fb32c14ed to 9.2.x. Thanks!
Backported to 9.2.x as this is a test only change.