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

[FIX] Optimistically compute position only for objectMetadataItem that has the field #10510

Merged
merged 10 commits into from
Feb 26, 2025

Conversation

prastoin
Copy link
Contributor

@prastoin prastoin commented Feb 26, 2025

Introduction

In this PR #10493 introduced a regression on optimistic cache for record creation, by expecting a position fieldMetadataItem on every ObjectMetadataItem which is a wrong assertion
Some Tasks and ApiKeys do not have one

Fix

Dynamically compute optimistic record input position depending on current ObjectMetadataItem

Refactor

Refactored a failing test following jest each pattern to avoid error prone duplicated env tests. Created a "standard' and applied it to an other test also using it.each.

@prastoin prastoin changed the title [FIX] Optimistically compute positio only for objectMetadataItem that has the field [FIX] Optimistically compute position only for objectMetadataItem that has the field Feb 26, 2025
@prastoin prastoin marked this pull request as ready for review February 26, 2025 14:11
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

This PR fixes a regression in optimistic cache handling for record creation by correctly identifying objects that have position fields.

  • Added new utility hasObjectMetadataItemPositionField in /packages/twenty-front/src/modules/object-metadata/utils/hasObjectMetadataItemPositionField.ts to check if an object actually has a position field
  • Removed incorrect hasPositionField.ts which assumed all non-remote objects had position fields
  • Created new utility computeOptimisticCreateRecordBaseRecordInput to conditionally add position and createdBy fields only when they exist
  • Updated multiple components to use the new utilities, ensuring position fields are only computed for objects that actually have them
  • Renamed checkObjectMetadataItemHasFieldCreatedBy to hasObjectMetadataItemFieldCreatedBy for naming consistency

8 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings | Greptile

Copy link
Contributor Author

@prastoin prastoin left a comment

Choose a reason for hiding this comment

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

As discussed with @lucasbordeau refactored failing test using jest each pattern and created a standard regarding it and applied to an other test also using it.each

}

if (hasObjectMetadataItemPositionField(objectMetadataItem)) {
baseRecordInput.position = Number.NEGATIVE_INFINITY;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we really use this NEGATIVE_INFINITY ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed this might seems a bit radical but calculating the next index would quite complex for a very small plus value regarding this solution here

Copy link
Contributor Author

@prastoin prastoin Feb 26, 2025

Choose a reason for hiding this comment

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

Note that this isn't sent to the api and will override on api response

@prastoin prastoin merged commit ea0d3c6 into main Feb 26, 2025
47 checks passed
@prastoin prastoin deleted the prastoin-fix-tasks-has-no-positions branch February 26, 2025 16:04
charlesBochet pushed a commit that referenced this pull request Feb 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants