Fix rest metadata version missing#16536
Merged
charlesBochet merged 1 commit intomainfrom Dec 12, 2025
Merged
Conversation
Contributor
There was a problem hiding this comment.
Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.
Contributor
|
🚀 Preview Environment Ready! Your preview environment is available at: http://bore.pub:37040 This environment will automatically shut down when the PR is closed or after 5 hours. |
ijreilly
approved these changes
Dec 12, 2025
charlesBochet
approved these changes
Dec 12, 2025
prastoin
pushed a commit
that referenced
this pull request
Dec 12, 2025
## Context The REST pipeline re-fetches/sets the metadata version later in RestApiBaseHandler#getObjectMetadata by reading from DB and seeding the cache if it’s missing. That’s the place that actually needs it and already handles the “undefined” case. This also mirror the graphql path that was updated 3 weeks ago
FelixMalfait
added a commit
that referenced
this pull request
Dec 27, 2025
## Context
After flushing the Redis cache (e.g., via `cache:flush` command), users
get stuck in an infinite loop showing "Your workspace has been updated
with a new data model. Please refresh the page." - refreshing the page
doesn't help.
## Root Cause
When the cache is flushed, `getMetadataVersion()` returns `undefined`.
The version comparison in the error handler then becomes:
```typescript
requestMetadataVersion !== `${currentMetadataVersion}`
// Evaluates to: "5" !== "undefined" → always true
```
This triggers the schema mismatch error on every request, even after
page refresh.
## History
| Date | Commit | What Happened |
|------|--------|---------------|
| Aug 2024 | #6691 (`17a1760afd`) | Introduced the
`${currentMetadataVersion}` template literal that converts `undefined`
to the string `"undefined"` |
| Dec 2025 | #16536 (`0035fc1145`) | Removed the safety check that would
throw an early error when cache is empty, allowing `undefined` to
propagate |
## Fix
Add `isDefined(currentMetadataVersion)` check before comparing versions.
If the server doesn't have a cached version, we shouldn't treat it as a
mismatch - the schema factory already handles populating the cache when
it actually needs the version.
```typescript
if (
requestMetadataVersion &&
isDefined(currentMetadataVersion) && // ← Added this check
requestMetadataVersion !== `${currentMetadataVersion}`
) {
```
## Testing
1. Flush the cache: `npx nx run twenty-server:command cache:flush`
2. Refresh the page
3. Verify no infinite loop occurs and app loads normally
BOHEUS
pushed a commit
to BOHEUS/twenty
that referenced
this pull request
Jan 6, 2026
…tyhq#16816) ## Context After flushing the Redis cache (e.g., via `cache:flush` command), users get stuck in an infinite loop showing "Your workspace has been updated with a new data model. Please refresh the page." - refreshing the page doesn't help. ## Root Cause When the cache is flushed, `getMetadataVersion()` returns `undefined`. The version comparison in the error handler then becomes: ```typescript requestMetadataVersion !== `${currentMetadataVersion}` // Evaluates to: "5" !== "undefined" → always true ``` This triggers the schema mismatch error on every request, even after page refresh. ## History | Date | Commit | What Happened | |------|--------|---------------| | Aug 2024 | twentyhq#6691 (`17a1760afd`) | Introduced the `${currentMetadataVersion}` template literal that converts `undefined` to the string `"undefined"` | | Dec 2025 | twentyhq#16536 (`0035fc1145`) | Removed the safety check that would throw an early error when cache is empty, allowing `undefined` to propagate | ## Fix Add `isDefined(currentMetadataVersion)` check before comparing versions. If the server doesn't have a cached version, we shouldn't treat it as a mismatch - the schema factory already handles populating the cache when it actually needs the version. ```typescript if ( requestMetadataVersion && isDefined(currentMetadataVersion) && // ← Added this check requestMetadataVersion !== `${currentMetadataVersion}` ) { ``` ## Testing 1. Flush the cache: `npx nx run twenty-server:command cache:flush` 2. Refresh the page 3. Verify no infinite loop occurs and app loads normally
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
The REST pipeline re-fetches/sets the metadata version later in RestApiBaseHandler#getObjectMetadata by reading from DB and seeding the cache if it’s missing. That’s the place that actually needs it and already handles the “undefined” case.
This also mirror the graphql path that was updated 3 weeks ago