Skip to content

v0.24.0: safer writes, stricter filters, enums by value

Choose a tag to compare

@jaravan jaravan released this 07 Nov 10:36
· 29 commits to main since this release

What's new

PUT [] no longer wipes a row

A PUT whose body was an array was read as an entity with no properties, so every property was reset, and the client got a 204. Inside a $batch, the array was turned into an object first, so a PATCH [] was a silent 204 and a POST [] complained about a missing key.

PUT /odata/v4/MySrv/Items(1)
[]

Now it's a 400 with Request body must be a JSON object, directly and in a $batch, in V4 and V2, on drafts too. The row stays as it was.

Renaming a draft child no longer deletes it

A PUT on a draft child with only {"title": "Renamed"} reset its link to the parent, so the child left the draft. Activating then deleted the active child, although the client had only renamed it.

The columns that hold a child in its draft are now the server's: they keep their value through a PUT, a PATCH, or a link. HasDraftEntity is also right at every step: an active child says false as soon as its draft is deleted, and after a discard.

Links follow the draft rules

A $ref, a $links or a bind could change an active entity directly, which a PATCH can't. Now it's a 400, change its draft, not the active entity. A link held elsewhere leaves the entity as it is, so a row outside the draft can still point at an active entity, by its own foreign key or through a many-to-many link.

A bind that disagrees with a foreign key in the same update is a 400 too, including a bind that removes the link while the body sets the key.

Enums compare by value

Enums were compared by the way they were spelled, so R,W, W,R and 3 were different values. Now an enum is its number, in $filter, $orderby and groupby:

  • Pm eq F.Perm'R,W' finds rows saved as W,R or 3
  • members with no Value are numbered from 0, each after the one before
  • IsFlags types work up to the full 64 bits
  • two members of one value are one group in groupby

A flags value is held one way, so with a member RW=3, a client that writes R,W reads back RW.

A member Value that isn't a whole number stops the start, rather than failing later on a $orderby:

metadata.xml: F.Color.Red: Value "abc" is not a whole number

Filters into complex values

Addr/City eq 'Athens' was a 400, Cannot filter on path Addr/City. $filter and $orderby now follow paths through single complex values, at any depth, through navigations and in lambdas:

$filter=Addr/City eq 'Athens'
$filter=Place/Stops/any(p:p/Addr/City eq 'Rome')
$orderby=Customer/Addr/City desc

A null Addr gives null, so Addr/City eq null matches its row.

A filter that can't mean anything is a 400

These used to return rows, or no rows, with no sign that anything was wrong. Each is now a 400, whatever rows there are, and the message doesn't quote row data:

Request Why
$filter=Qty, not Qty, Qty and true A filter has to be a condition, at every level
Kids/any(k:k/ID) So does a lambda's body
Tags eq 'a', Tags has 'a', Addr eq 'x' A collection or a complex value only compares with null
Qty eq F.Color'Red', Col eq Sh Another type's enum isn't a value of this one
Qty has 1 has needs an enum
Qty eq 'abc' Text compared with a number has to be one
$orderby=Tags, $orderby=Addr Neither has a value to sort by

Options that were ignored are refused

PATCH ?$select=Nope was a 204, and the write applied. Options on a write are now checked before anything changes, and options that don't apply to a request are a 400: $count=true on an entity or a property, $select or $expand on a property, read options on a POST, $select on a DELETE, $skiptoken on one entity. $select that names real properties still works on a write.

$format is checked everywhere: one a resource isn't given in is a 501, as $metadata?$format=json is, since $metadata is XML.

Requests can't hang the server

Some small requests kept the server busy for seconds or longer. A very long number in Pm has 1111… took 20 seconds on 2,000 rows, and it's now refused at once. Long literals, sorts, groups, searches and multiplied rows all count against the work limit now, so they end in a 400, and a long literal is read once, not again for each row. A very large $batch is refused instead of crashing the process, and a hierarchy chain of any depth is answered in linear time.

Values come back as they went in

  • Decimals, times and long integers keep every digit in comparisons, keys and groups: 0.3 and 0.30, or PT1H and PT60M, are one value
  • every key type round-trips through its URL
  • a number past a double's range is a 400: 1e400 isn't INF, which is written "INF"
  • length, indexof and substring count characters as MaxLength does: an emoji is one, and substring doesn't cut it in half
  • a DefaultValue applies to a create or a PUT that leaves the property out. One that isn't a value of its property is ignored, with a line in the startup log
  • a V2 PUT leaves alone the collections V2 can't see
  • a required spatial property isn't required, as the server holds none
  • $count on a collection property counts everything, whatever $top says

Smaller fixes

  • A next link no longer encodes a key twice, and keeps a custom option given twice
  • A $ in a URL may be written %24, as in %24metadata, and any method but POST on $batch is a 405
  • A config or JSON data file saved with a byte order mark, as Notepad does, loads
  • metadata.xml can use names such as constructor for a namespace or an operation

Data file columns the metadata doesn't have

metadata.xml says what an entity has. A data file's other columns are ignored, and the startup log names them.

Tested with the Fiori sample apps on UI5 1.152.0, on V2 and V4, with V4 drafts on PostgreSQL 18.6, on Docker Compose and on Kubernetes with two replicas.

Upgrading

  • A filter, $orderby or query option from the table above is now a 400 instead of an empty or partial answer
  • An update that sends Kids: [] or Group: null is a 400 when the row has kids or a group: remove links with DELETE on $ref. Group: [] is always a 400
  • A link that changes an active draft-enabled entity is a 400: change its draft
  • $count=true on a collection property is refused, not ignored
  • $metadata?$format=json and V2's $format=atom are a 501
  • An enum Value that isn't a whole number stops the server at startup
  • A combined flags value reads back in one spelling, which may differ from what was written

Install

npx odata-prova@0.24.0 ./MySrv
docker run -p 3000:3000 -v "$PWD/MySrv:/models/MySrv:ro" ghcr.io/jaravan/odata-prova:0.24.0

Details