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

Unsetting or clearing out DateTime field does not actually unset data in field #4965

Open
dfinton opened this issue Sep 4, 2019 · 0 comments

Comments

@dfinton
Copy link

dfinton commented Sep 4, 2019

Expected behavior

If someone wants to clear out the data for a DateTime field in the UI (i.e. set it to null), they should be able to delete the data in the inputs, click "save", and see that the DateTime is no longer set for that field within that document.

Actual/Current behavior

After clicking "Save" after clearing out the existing DateTime value, it appears that the field was cleared out as expected, but when you refresh the page in the UI, the original DateTime value is still set for that field. Also:

  • Data in the database for that field never gets cleared out or set to null as expected
  • I looked at the data in both pre-save and pre-validate schema hooks and it would appear that the UI is still sending the original DateTime data to mongoose to save rather than empty fields or null

Steps to reproduce the actual/current behavior

  1. Go to admin UI, edit existing document with a DateTime field set. Set that value to any date/time.
  2. Click "Save". Note that the DateTime field is correctly updated. Refreshing the page shows that the date and time are correctly set.
  3. Go to same record, and remove the date and time strings from both form inputs
  4. Click "Save" again.
  5. Field data should be set to "null" in the database and the fields should be empty in the UI even after a refresh
  6. Instead, the UI makes it look like the data was unset, but if you refresh the page, the original DateTime field returns. Also verified this by looking at the database directly and through console.log dumps in a pre-save and pre-validate hook; instead of empty data, the original timestamp is sent to the database to store.

Here's the config for that field in our model:

    {
      label: 'Expire At',
      type: Types.Datetime,
      utc: true,
      format: 'YYYY-MM-DD',
      default: null,
    };

It's worth noting that the default value (null) is honored. Also, according to the mongoose documentation, "null" (the value, not the string) is a valid value for a DateTime record. The moment an actual date/time is saved to that field, however, it can never be unset.

Right now our workaround for this issue is to set the value of our data to some date in the distant future, i.e. sometime in 2030.

Environment

Software Version
Keystone 4.2.1
Node.js 10.15.3 (reproducible irrespective of supported node version)
Browser Chrome/Firefox. Likely affects all browsers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant