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

fix:defaults in the url query string will create deprecatedID for new submissions #321

Merged

Conversation

punkch
Copy link
Contributor

@punkch punkch commented Oct 5, 2021

This seems to fix enketo/enketo#1052 though I don't think it addresses the root cause.

@eyelidlessness
Copy link
Contributor

Thanks for submitting this PR @punkch! I'll take a look.

Copy link
Contributor

@eyelidlessness eyelidlessness left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took some time to track the current behavior, which I'll describe here for posterity/future recall:

  1. When defaults are present, enketo-webform.js passes an instanceStr with a representation of the form's model, with those defaults populated.
  2. Before line 63, data.submitted is undefined.
  3. The check prior to this change only assigns data.submitted = false when there is a draft record being filled.
  4. When initializing a form, enketo-core's FormModel assigns data.submitted = true when it's undefined.
  5. When submitting a record, FormModel then checks for both instanceStr and submitted; if both are truthy, it creates a deprecatedID.

I have validated that this does fix the issue, by ensuring data.submitted = false regardless of whether defaults are present. Thanks @punkch!

@eyelidlessness eyelidlessness merged commit f2aaecb into enketo:master Oct 18, 2021
@eyelidlessness eyelidlessness mentioned this pull request Oct 20, 2021
@lognaturel
Copy link
Contributor

lognaturel commented Oct 21, 2021

This breaks edits. I think everyone assumed that somebody else had tried edits and verified they still worked. I made the mistake of saying this felt safe to me based on secondhand analysis rather than looking at it myself.

I think it makes sense to spend a little bit to see whether there's actually a low-hanging fix but pretty quickly we should just revert and do another point release.

@lognaturel
Copy link
Contributor

Looking at it again, it really is surprising that record is set for offline draft edits but not for edits from an edit url. No wonder we all thought this was safe.

I’ve reviewed the modes/URLs from https://apidocs.enketo.org/v2 carefully and feel confident that a deprecatedId should should only be generated when an instance was provided for edit. Maybe approaching from that angle is more promising.

eyelidlessness added a commit to eyelidlessness/enketo-express that referenced this pull request Oct 21, 2021
This was a regression in enketo#321. `record` here is populated by `_checkAutoSavedRecord`, which is only available in offline mode. Since that will always be falsey (undefined) in edit mode, `submitted` would be set to false. Since we should only set `deprecatedID` when editing submissions, it made more sense to assign it directly based on the `isEditing` property introduced in enketo#269 (which should also have been added to the JSDoc type at that time).
@lognaturel
Copy link
Contributor

lognaturel commented Oct 21, 2021

The line being modified here was introduced to make sure that a deprecatedId was not generated for a draft edit. It previously checked for the existence of a record and the record being a draft. Was the draft check necessary? Is there ever a case in which a record is populated and it’s not a draft? I’m asking in the context of thinking about risks around #345

yanokwa pushed a commit that referenced this pull request Oct 21, 2021
This was a regression in #321. `record` here is populated by `_checkAutoSavedRecord`, which is only available in offline mode. Since that will always be falsey (undefined) in edit mode, `submitted` would be set to false. Since we should only set `deprecatedID` when editing submissions, it made more sense to assign it directly based on the `isEditing` property introduced in #269 (which should also have been added to the JSDoc type at that time).
@eyelidlessness
Copy link
Contributor

Was the draft check necessary?

Looking back at the history, it was introduced in 853fb44 to fix enketo/enketo#1137, and as mentioned in my review here/notes in #345, when data.submitted is not assigned at all it defaults to true, so it was necessary to assign it to false for cases where a deprecatedID should not be generated even if an instanceStr is present. Both of these previous checks just happened to be incorrect.

Is there ever a case in which a record is populated and it’s not a draft?

When submitting a record in offline mode, without first saving a draft. Technically it is submitted from the auto-saved record, but that should be considered an implementation detail.

@lognaturel
Copy link
Contributor

Technically it is submitted from the auto-saved record

Oh! Surprising to me. Makes #345 even more appealing so we don’t have to reason around when exactly record is set.

@punkch punkch deleted the fix-new-submissions-with-defaults branch October 22, 2021 08:05
punkch pushed a commit to UNOPS/enketo-express that referenced this pull request Nov 5, 2021
This was a regression in enketo#321. `record` here is populated by `_checkAutoSavedRecord`, which is only available in offline mode. Since that will always be falsey (undefined) in edit mode, `submitted` would be set to false. Since we should only set `deprecatedID` when editing submissions, it made more sense to assign it directly based on the `isEditing` property introduced in enketo#269 (which should also have been added to the JSDoc type at that time).
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
3 participants