Repository navigation
Description
Describe the bug
Updating an existing channel through the REST API with override=false (the default) returns false and doesn't save, even when nobody else has touched the channel. It happens every time for channels that have never been saved from the Administrator, for example channels created or imported through the API, or by tools such as mirthsync. The only way to save them is override=true, which also turns off the concurrent-edit check.
From the code on main (and the same in 4.5.2), DefaultChannelController.updateChannel decides this at:
if ((currentRevision > 0) && !override && (dateStartEdit.before(lastModifiedDate))) {
return false;
}ChannelServlet.updateChannelsetsdateStartEditto the time of the request when the caller doesn't sendstartEdit.lastModifiedDatecomes fromChannelMetadata.getLastModified(), which returnsCalendar.getInstance()when nolastModifiedhas been recorded:
public Calendar getLastModified() {
if (lastModified == null) {
lastModified = Calendar.getInstance();
}
return lastModified;
}So for a channel with no recorded modification time, lastModified is always a few milliseconds after startEdit, and the update is always refused.
Two related points:
- The API docs for
overridesay "If true, the channel will be updated even if a different revision exists on the server", but the check never compares revisions. After a channel does have alastModified, an unforced PUT with a stale<revision>succeeds and overwrites the newer version. - The
startEditexample in the docs is1985-10-26T09:00:00.000-0700, but the servlet parses withyyyy-MM-dd'T'HH:mm:ssZ. As far as I can tell, the documented format, with milliseconds, fails to parse, gets logged as "Error parsing start edit date", and falls back to "now".
To Reproduce
Stock OIE 4.5.2 (official Docker image, Derby):
- Create a channel through the API:
POST /api/channels. GET /api/channels/{id}, change only the description, thenPUT /api/channels/{id}?override=falsewith that XML.- The response is
false, and the change isn't saved. - The same PUT with
override=truesaves, and so does the same PUT withstartEditset to a future time.
Expected behavior
An update to a channel that nobody else has changed since the caller read it is saved without override=true. A caller holding an older revision is refused, as the docs describe.
Actual behavior
Every unforced update of a channel without a recorded lastModified is refused. For channels that do have one, the decision is made on timestamps only, so a stale revision is not caught.
Environment
- OS: Linux (Docker)
- Java: the official image's bundled JRE
- Version: OIE 4.5.2. The code is unchanged on
main.
Workaround(s)
Send override=true (mirthsync's -f), or save the channel once from the Administrator so it gets a lastModified.
Additional context
Possible fixes, smallest first:
- In
updateChannel, treat a missinglastModifiedas "no conflict" instead of "modified now", for example by reading the stored field without the lazy default. - Compare
channel.getRevision()against the stored revision whenoverrideis false, which is what the docs describe and what the channel group update already does (group.getRevision().equals(matchingGroup.getRevision())).
I'm happy to open a PR for either, or both, if one direction is preferred. Found while testing mirthsync, where every unforced push of an API-created channel fails with "Unable to save the channel".
Activity