Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

indexed nullable DATE_TIME field causes error on .insert() unless specified #273

Open
fezzzza opened this issue Mar 17, 2021 · 1 comment

Comments

@fezzzza
Copy link

fezzzza commented Mar 17, 2021

I have been using lovefield for a while, but now I am starting to use DATE_TIME columns. I discover that if they are .addIndex()-ed they must be specified explicitly on .insert() - even if made .addNullable(), as an uncaught error occurs. However if the column is not indexed, the error does not occur but they are incorrectly assigned the default value of null, instead of Date(0).

Repro: https://plnkr.co/edit/sZ7gGCDpXWrOTpKC

As you can see from test 2, treating a STRING in the same way results in more expected behaviour.

I have tested further without .addNullable() and my tests mostly result in error 202:

Constraint error: (202) Attempted to insert NULL value to non-nullable field deals.[FIELDNAME]

Further testing shows a 202 error is generated for whichever field is not specified, whether STRING, DATE_TIME, INTEGER, NUMBER or BOOLEAN.

However, according to documentation the default value for a DATE_TIME field is Date(0). I presume this to be new Date (0) and not a string representation of the current date/time, and this is borne out by inspecting lf.type .

However observed behaviour suggests that the default values for STRING, DATE_TIME, INTEGER, NUMBER and BOOLEAN are not implemented, because when added with .addNullable() they come out as undefined, and not null.

So I did another test:
https://plnkr.co/edit/4351TPYa7BlSVn7d?preview

...and it appears that the defaults specified in lf.type are not applied at all.

Perhaps that is the root of this issue?

@freshp86
Copy link
Contributor

Thanks for filing. Will take a look and respond on this thread with any updates.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants