Skip to content
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

Support $NOW in conditional fields #14759

Open
u12206050 opened this issue Jul 30, 2022 · 12 comments
Open

Support $NOW in conditional fields #14759

u12206050 opened this issue Jul 30, 2022 · 12 comments

Comments

@u12206050
Copy link
Contributor

Describe the Bug

After setting a condition on a field that includes checking a date field, I get an error after trying to insert a new item.

Not sure if it is due to the depth of the relationship or the $NOW have also tried $NOW()

To Reproduce

I have the following collections.

Check-ins->Registrations<-Event

On check-ins the registration field has the following condition:

{ "registration": { "event": { "open_date": { "_lt": "$NOW" } } } }

Errors Shown

{"errors":[{"message":"date must have a valid date format or reference","extensions":{"code":"INTERNAL_SERVER_ERROR"}}]}

What version of Directus are you using?

9.14.5

What version of Node.js are you using?

16.4.0

What database are you using?

mysql 8

What browser are you using?

chromium

How are you deploying Directus?

Locally & GCP

@u12206050
Copy link
Contributor Author

Further update. Condition works when using static set date. eg. 2022-07-30T22:47:00+02:00
So might be an issue with $NOW

@u12206050
Copy link
Contributor Author

Ah further update. When I said the previous comment that the condition works using a static value, I was mistaken. It doens't throw the Date must have a valid date format or reference error but actually states the correct validation message, but unfortunately it never works even when the condition should pass. So doesn't seem the it is able to test on relationships. Still a bug with the $NOW though.

@rijkvanzanten
Copy link
Member

It sounds like the dynamic variables aren't parsed (correctly) before the rule check is performed in conditions, that'd explain why you'd get a valid date reference problem 🤔

@u12206050
Copy link
Contributor Author

u12206050 commented Aug 1, 2022 via email

@u12206050
Copy link
Contributor Author

However in addition to that, I checked the payload/context being validated as well, and it is not loading the relationship data before checking either. So the validation still fails. Any changes to validatePayload recently?

@mediaxtend
Copy link

We are also experiencing the same bug using a same kind of validation filter:
"validation": { "_and": [ { "begin_date": { "_gte": "$NOW" } } ] },
The same error (HTTP code 500) is returned by the PATCH request on an item.

What version of Directus are you using?
9.23.1

What version of Node.js are you using?
18.14.2 (from directus/directus Docker image)

What database are you using?
PostgreSQL 13.10

What browser are you using?
Firefox

How are you deploying Directus?
Docker compose

@u12206050
Copy link
Contributor Author

Actually had a PR that fixed this, but closed it due to the new $CURRENT_ITEM PR which seems to also have stagnated.

@falmanna
Copy link

what is the status of this issue?
if $CURRENT_ITEM isn't coming soon, why not fix this $NOW var issue in validation?

@rijkvanzanten
Copy link
Member

rijkvanzanten commented Jul 21, 2023

if $CURRENT_ITEM isn't coming soon

We're re-architecting how Directus fetches data in the first place, which is where we're adding proper support for using current / other items in filters etc. It's the same reason the json query support in the current setup was paused, as we'd rather focus that effort on putting it in the new system in a foundational level 🙂

why not fix this $NOW var issue in validation?

It's marked as a medium priority bug right now, which means that we gotta prioritize some higher prio stuff first. You're more than welcome to open a PR for the $NOW fix though!

@falmanna
Copy link

It's marked as a medium priority bug right now, which means that we gotta prioritize some higher prio stuff first. You're more than welcome to open a PR for the $NOW fix though!

I think #14788 was supposed to fix it, but was closed in favor of #14887
Maybe it can be reused to fix this until the new architecture is in place?

@arladmin
Copy link

arladmin commented Sep 6, 2023

This issue still seems to be prevalent.

Unable to do validation using the $NOW variable.

@Pachat
Copy link

Pachat commented Jan 24, 2024

Surprisingly, as of v10.2.3, if it does not work as a Fields' Collection validation, it does work at the Collection validation in the Roles.
So you can

  • set a message in the Fields' Collection validation but with no validation condition
  • and set the validation condition in the Collection's Role

@rijkvanzanten rijkvanzanten changed the title Date must have a valid date format or reference Support $NOW in conditional fields Mar 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 📋 Backlog
Development

Successfully merging a pull request may close this issue.

6 participants