Skip to content

Conversation

@sebastienhoorens
Copy link
Contributor

@sebastienhoorens sebastienhoorens commented Oct 29, 2025

One fix to rule them all.

There was a lot of code spread around the code base that attempted to fix this bug, but the issue remained. Adding a unique constraint on the database level should fix this once and for all.

Ideally we should do this for all ordering columns we have today.

This task will be ran before releasing:

rake fix_existing_tenants:custom_fields_orderings

This flow was tested thoroughly on a snapshot of the Benelux cluster.

Changelog

Fixed

  • [TAN-5720] Issues with loading some input forms (inconsistent ordering).

@notion-workspace
Copy link

@cl-dev-bot
Copy link
Collaborator

cl-dev-bot commented Oct 29, 2025

Messages
📖 Changelog provided 🎉
📖 Notion issue: TAN-5720
📖

Run the e2e tests

📖 Check translation progress

Generated by 🚫 dangerJS against 5cfe6e7

Comment on lines +12 to +15
add_index :custom_fields, :ordering,
unique: true,
where: 'resource_id IS NULL',
algorithm: :concurrently
Copy link
Contributor

Choose a reason for hiding this comment

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

Learn something every day. Did not know that you could have a conditional on an index

Copy link
Contributor

Choose a reason for hiding this comment

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

Is it needed though? Does the first index not create an index on [null, 1] for example?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jamesspeake Apparently uniqueness does not apply to null values. Duplicates like [null, 1] and [null, 1] will be allowed if we would make one index. That's why a separate index is needed to deal with the registration forms.

Copy link
Contributor

@jamesspeake jamesspeake left a comment

Choose a reason for hiding this comment

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

Generally looks fine, but have a question about the update_all endpoint. I just want to be sure. Happy to talk through if you want

update_statements! field, statements_params, errors, index if statements_params
relate_map_config_to_field(field, field_params, errors, index)
field.set_list_position(index)
field.move_to_bottom
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this work fine where new fields are added in the middle of the form? I have it in my mind that we changed update_all a while back so that it was not making updates to every field, every time. ie the next statements on line 152, 155

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jamesspeake I wasn't aware of this change. Will do more testing around these cases (new field in the middle and the other field) and will likely use a different method to insert at that position. But it would have to be a different method because set_list_position will temporarily have two fields with the same ordering.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants