getodk / central

ODK Central is a server that is easy to use, very fast, and stuffed with features that make data collection easier. Contribute and make the world a better place! ✨🗄✨
https://docs.getodk.org/central-intro/
Apache License 2.0
121 stars 145 forks source link

Unable to create a draft for one of existing forms in a project when "entity definition within the form is invalid.." #632

Closed dbemke closed 2 months ago

dbemke commented 2 months ago

Problem description

I'm unable to create a draft for one of existing forms in a project. When I click "Create a new draft" I can see info "The entity definition within the form is invalid. The form must specify at least one entity action, for example, create or update." and after that the draft doesn't allow to upload a form.

URL of the page

https://test.getodk.cloud/#/projects/385/forms/people_registration

Steps to reproduce the problem

  1. Go to the URL.
  2. Click "Create a new draft".

    Screenshot

    draftBlocked

Expected behavior

Central version shown in version.txt

https://test.getodk.cloud/ versions: 645a8061b8df3644584cefc036d751c6115fcbec (v2023.5.1-3-g645a806) +5c93766eb558c113a6389f7d035d3bde3fe2261f client (v2023.5.0-47-g5c93766e) +85a0e3cbcec39c000d29002a9e9bce3150115ac2 server (v2023.5.0-35-g85a0e3cb)

Browser

Chrome and Firefox

matthew-white commented 2 months ago

I think there's actually an issue with this form. In its XML, I see:

<entities:entity entities:dataset="people">
    <entities:create/>
    <entities:label/>
</entities:entity>

However, create shouldn't be its own element and instead should be an attribute of the <entities:entity> element:

<entities:entity entities:dataset="people" create="true">
    <entities:label/>
</entities:entity>

I think maybe at one time early on, create was an element instead of an attribute, so it might just be an old form. Here is a current example of XML to create entities where you can see the create attribute. A form that has an effect on entities should have a create attribute and/or an update attribute, but not neither attribute. Before v2023.5, Central would accept a form without a create or update attribute even though that's technically invalid. That changed as part of #518. Now if there's an existing form like that, it will continue working, but you won't be able to create a new version of it without adding a create or update attribute. Let me know if you have questions about any of this. :)

matthew-white commented 2 months ago

you won't be able to create a new version of it without adding a create or update attribute.

I guess part of the issue is that you can't even use the UI to create a new version. The new form draft would be a copy of the existing invalid form definition, so the backend refuses to create the draft. I vaguely remember discussing this case in Slack when I was working on #518. I think we decided that this case was acceptable because it's possible to use the API to work around this situation: an API user can create a form draft with corrected XML without copying the existing form definition. I think the hope is that old forms like this that are invalid should be rare.

matthew-white commented 2 months ago

I'm going to go ahead and close this issue. @dbemke, let me know if you have any other questions or if you think we should reopen the issue.