Closed lognaturel closed 5 months ago
What would option 1 look like in practice? That they must fill entity_id
column with coalesce(${existing_participant}, uuid())
? This feels okay to me. I like that it is less magical. Hopefully people that are trying to go this route with their form design can handle/would appreciate less magic.
Software and hardware versions
acbfc439528a45b59392f0278705fbc7adba6630
Problem description
When the entity create action is specified by an XLSForm, the generated XForm includes a
setvalue
to generate an entity UUID. When the update action is specified, the expression given in the XLSFormentity_id
field is used as the entity UUID.When a form can both update and create an entity, the
pyxform
behavior is the same as for the update-only case. That means that if theentity_id
field is set directly to a form field that represents an existing entity's UUID, submissions that attempt to create entities will be rejected. We do want UUIDs to always be generated client-side to support the offline case so the reject behavior is good.We need to decide how much responsibility
pyxform
should take for this case.Steps to reproduce the problem
Use a form that can both create and update entities such as https://docs.google.com/spreadsheets/d/1poe2lx_MUzbN0ySuZlRX8_fuKqM4LdsBMwKORQW1QRk/edit#gid=1068911091
Make sure the
entity_id
is just${existing_participant}
, see that the create case is rejected. Set theentity_id
tocoalesce(${existing_participant}, uuid())
instead and see that both creation and update work as expected.Expected behavior
The options I see:
coalesce
expressions elsewhere if there's the possibility of updating existing entity properties (seeid_number_to_save
) or displaying a property that could be new or existing (seedisplay_first_name
).entity_id
expression of${foo}
, have pyxform generatecoalesce(${foo}, uuid())
The reason I'm hesitating about having pyxform generate something in that case is that it does feel a bit magical and it could be more confusing than helpful. I think it's likely someone writing this kind of form would come up with something like
coalesce(${foo}, uuid())
and then we could end up withcoalesce(coalesce(${foo}, uuid()), uuid())
. That would work but certainly be a bit strange.I also do generally feel a bit uncomfortable with the fact that
uuid()
could be recomputed at any time. As I wrote in the last bullet point, I don't know that there is an alternative that doesn't include injecting a node. I generally prefer not to inject nodes because that has impact on users' data exports. If we go with the first option, a form creator who really cares about entity ids being stable throughout a form-filling session could add a form field with a dynamic default value ofuuid()
if they want.