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

data attribute filter accepts date-time #473

Open
flinden68 opened this issue Nov 13, 2024 · 10 comments
Open

data attribute filter accepts date-time #473

flinden68 opened this issue Nov 13, 2024 · 10 comments

Comments

@flinden68
Copy link

Thema / Theme

Objecten API

Omschrijving / Description

Momenteel kunnen we voor bijvoorbeeld LTE alleen maar een date of numeric waarde gebruiken.
Maar in ons object hebben we te maken met date-time en dan faalt het LTE filter als je de huidige datum gebruikt om alle objecten op wilt halen voor vandaag en ouder.

Toegevoegde waarde / Added value

Hierdoor kan je beter filteren op basis van een date-time

Aanvullende opmerkingen / Additional context

No response

@flinden68 flinden68 added enhancement New feature or request triage labels Nov 13, 2024
@alextreme
Copy link
Member

JSON doesn't have a native datetime format so this will be quite complicated, we would recommend to store the date separately if it is necessary to filter on it

@sdegroot
Copy link

@alextreme what do you mean there is no native date time format? If you mean that dates are serialised either as numeric timestamps or string values (RFC 3339 / ISO 8601) then yes.

However, JSON Schema very much allows to enforce those standards upon a property using the "format" attribute.
See https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-validation-00#rfc.section.7.3

Unfortunately, the validator used in objects-api/objecttypes-api does not adhere to the standards and simply ignores the format field. I discussed this several months ago with @joeribekker but haven't heard back about this.

@flinden68 is this what you meant?

@flinden68
Copy link
Author

@sdegroot yes, because we pass on the date also a date format as string, should be that hard also accept a date-time formatted string

@alextreme
Copy link
Member

@sdegroot https://json-schema.org/understanding-json-schema/reference/string#format

The format keyword allows for basic semantic identification of certain kinds of string values that are commonly used. For example, because JSON doesn't have a "DateTime" type, dates need to be encoded as strings. format allows the schema author to indicate that the string value should be interpreted as a date. By default, format is just an annotation and does not effect validation.

Optionally, validator implementations can provide a configuration option to enable format to function as an assertion rather than just an annotation. That means that validation will fail if, for example, a value with a date format isn't in a form that can be parsed as a date. This can allow values to be constrained beyond what the other tools in JSON Schema, including Regular Expressions can do.

@sdegroot
Copy link

Ah, so it is optional. I would highly suggest enabling this as it will increase data quality -a lot- :)

@JanBrek
Copy link

JanBrek commented Jan 8, 2025

@alextreme I agree with @sdegroot. It would help a lot for connecting applications as they would get errors while unmarshalling the json objects.
We currently have an issue where an object has a wrong date '000' even though the json schema has the date-time format. This causes the search function for that object type to break (One item in the list is invalid, thus the whole list is unable to unmarshall resulting in a broken query/call.
If the objecten API would honor the dateTime format this error would be caught while trying to store the object.
Must we make a separate (taiga?) issue to request this?

@alextreme
Copy link
Member

@JanBrek please indeed create a Taiga issue with the details of the object and json schema involved, combined with the API request which failed. I'll then pick this up with Team Bron to triage further

@alextreme
Copy link
Member

Discussed with Team Bron and Dimpact
Two changes are necessary:

  • An ability to enable datetime format validation for the data in an object. This could be added overall to the Objects API (so all datetime-strings are validated when creating/modifying an objects) or we could add the ability to specify this per objecttype in the ObjectType API. We assume the first (with an envvar/setting by default this would be off to avoid a breaking change) would be sufficient
  • Then we need to investigate using data_attr comparison filters together with datetimes, as per the example of @flinden68.

Estimated at a week of development time, for @PeterVanBragt to approve

@alextreme alextreme moved this from Triage to Waiting for approval in Data en API fundament Jan 14, 2025
@PeterVanBragt
Copy link

For now no budget for this feature at GDH (also no internal sponsor).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Waiting for approval
Development

No branches or pull requests

5 participants