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

Enforce that entity field is always structure type #1053

Merged
merged 10 commits into from
Dec 7, 2023
Merged

Conversation

ktuite
Copy link
Member

@ktuite ktuite commented Nov 29, 2023

In response to getodk/central#551, getodk/central#552, and getodk/central#552

It was the case that the whether or not the <entity> block had a child like <label> would change the type of field that entity was from structure (if it had children) to unknown. This lead to each of the errors above.

Example 1: This is possible for an update form that doesn't update an entity's label, but wasn't really possible before because a label was needed to create an entity.

<entity dataset="people" id="" update="" baseVersion="" />

Example 2: This was the only kind of form we saw before, where entity was always structural.

<entity dataset="people" id="" create="">
	<label/>
</entity>

The main change in this PR is forcing the entity field, which so far is always at /meta/entity to be structural, even if it is empty.

What has been done to verify that this works as intended?

Tests.

Why is this the best possible solution? Were any other approaches considered?

This is the simplest approach. The code change is small, if solves a bunch of issues at once.
The other option we considered was not changing the field type and adding workarounds for when entity was unknown. But these were getting cumbersome and likely hard/annoying to maintain or work around in the future.

How does this change affect users? Describe intentional changes to behavior and behavior that could have accidentally been affected by code changes. In other words, what are the regression risks?

Risk 1: The fact that entity can be an empty structural node might cause some problems somewhere. There are places in the code that use the structure type of the field to recurse over children. That could lead to a problem that we haven't realized yet. The entity field is the only one that gets this treatment, though, so the problem would be contained to those fields and those label-less update forms.

We want to check exports and OData because that is where, if there were a problem, it would probably come up.

Risk 2: It's unlikely that people got forms into the system that had <entity> blocks without labels/children that got saved as type unknown... but maybe? We could add a migration to make sure all meta/entity fields are structural. Or we could not, because it's probably not common. It would have to be a super old form that someone is oddly committed to upgrading rather than replacing to run into this problem at all.

Does this change require updates to the API documentation? If so, please update docs/api.md as part of this PR.

Luckily no.

Before submitting this PR, please make sure you have:

  • run make test-full and confirmed all checks still pass OR confirm CircleCI build passes
  • verified that any code from external sources are properly credited in comments or that everything is internally sourced

@ktuite ktuite marked this pull request as ready for review December 1, 2023 21:45
@ktuite ktuite requested a review from matthew-white December 1, 2023 21:46
@ktuite ktuite changed the title Better handling of entity tag with no children Enforce that entity field is always structure type Dec 1, 2023
Copy link
Member Author

@ktuite ktuite left a comment

Choose a reason for hiding this comment

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

Interactive review with @matthew-white

test/unit/data/submission.js Show resolved Hide resolved
test/integration/api/datasets.js Outdated Show resolved Hide resolved
test/integration/api/datasets.js Outdated Show resolved Hide resolved
test/integration/api/datasets.js Show resolved Hide resolved
test/integration/other/empty-entity-structure.js Outdated Show resolved Hide resolved
@ktuite ktuite merged commit c258056 into master Dec 7, 2023
5 checks passed
@ktuite ktuite deleted the ktuite/entity-bug branch December 7, 2023 00:10
@ktuite ktuite mentioned this pull request Dec 12, 2023
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants