Skip to content

PRESIDECMS-3215: Fix webflow step sync site-tenancy caching bug and add migration for orphaned steps#1726

Open
jamesallenuk wants to merge 5 commits intostablefrom
feature-PRESIDECMS-3215_Fix-site-tenancy-caching-bug-in-webflow-configuration-sync
Open

PRESIDECMS-3215: Fix webflow step sync site-tenancy caching bug and add migration for orphaned steps#1726
jamesallenuk wants to merge 5 commits intostablefrom
feature-PRESIDECMS-3215_Fix-site-tenancy-caching-bug-in-webflow-configuration-sync

Conversation

@jamesallenuk
Copy link
Contributor

@jamesallenuk jamesallenuk commented Jan 5, 2026

  • Fix _getExistingSingletonFlowForStartupCheck() to use site-aware caching
    Prevents subsequent sites from using first site's cached webflow config data
  • Add WebflowStepOrphanedRecordsFix migration to fix orphaned step foreign keys
    Updates steps pointing to wrong site's config and removes duplicates

Note

Fixes site-tenanted caching for singleton webflow configs and adds a DB migration to repair step FK issues.

  • Adjusts _getExistingSingletonFlowForStartupCheck() to cache per-site when site tenancy is enabled; introduces _populateSingletonFlowCache() helper to populate cache
  • New migration WebflowStepOrphanedRecordsFix.cfc:
    • Deletes duplicate webflow_configuration_step rows when both orphaned and correct-site steps exist
    • Updates orphaned steps to reference the correct singleton webflow_configuration for their site

Written by Cursor Bugbot for commit 61cd141. This will update automatically on new commits. Configure here.

…dd migration for orphaned steps

- Fix _getExistingSingletonFlowForStartupCheck() to use site-aware caching
  Prevents subsequent sites from using first site's cached webflow config data
- Add WebflowStepOrphanedRecordsFix migration to fix orphaned step foreign keys
  Updates steps pointing to wrong site's config and removes duplicates
@github-actions
Copy link

github-actions bot commented Jan 5, 2026

Test Results

    1 files  ±0    117 suites  ±0   2m 44s ⏱️ +7s
1 829 tests ±0  1 826 ✅ ±0  3 💤 ±0  0 ❌ ±0 
1 832 runs  ±0  1 829 ✅ ±0  3 💤 ±0  0 ❌ ±0 

Results for commit 61cd141. ± Comparison against base commit 5fc8f5c.

♻️ This comment has been updated with latest results.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

This PR is being reviewed by Cursor Bugbot

Details

Your team is on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle for each member of your team.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

var rawflows = $getPresideObject( "webflow_configuration" ).selectData( filter="instance_ref is null" );
for( var f in rawFlows ) {
request._webflowSingletonsStartupCache[ f.webflow_id ] = f;
request._webflowSingletonsStartupCache[ currentSiteId ][ f.webflow_id ] = f;
Copy link

Choose a reason for hiding this comment

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

Site-aware cache populates with all sites' data

The fix creates a site-specific cache bucket at request._webflowSingletonsStartupCache[ currentSiteId ], but the selectData query has no site filter - it fetches configurations from all sites. When multiple sites have configurations with the same webflow_id, the loop overwrites entries and the wrong site's configuration ends up cached. The query needs a site filter or the loop needs to check f.site == currentSiteId before storing.

Fix in Cursor Fix in Web

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The explicit site check isn't needed because Preside's site tenancy handles filtering automatically.
The webflow_configuration object is site-tenanted (@tenant site). When selectData() is called without bypassTenants, Preside filters by the current site context set by event.setSite() in the interceptor (line 126 of PresideCfFlowInterceptors.cfc).
So the query at line 791 only returns records for the current site, and all records in rawFlows are already for currentSiteId.
The fix is making the cache site-aware by using currentSiteId as a key in the cache structure (lines 788-796). This prevents cross-site data reuse—the original bug—without needing an explicit site filter in the loop.
If tenancy weren't working, we'd see broader issues across the system, not just this method.

}

private struct function _getExistingSingletonFlowForStartupCheck( required string webflowId ) {
var currentSiteId = $getRequestContext().getSiteId();
Copy link
Contributor

Choose a reason for hiding this comment

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

think we need to consider the case where the application isn't had the sites feature enabled

}

private struct function _getExistingSingletonFlowForStartupCheck( required string webflowId ) {
var sitesEnabled = $isFeatureEnabled( "sites" );
Copy link

Choose a reason for hiding this comment

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

Inconsistent site tenancy check may persist caching bug

High Severity

The function uses $isFeatureEnabled("sites") to determine whether to use site-aware caching, but the calling interceptor in PresideCfFlowInterceptors.cfc uses isSiteTenanted (checking the object's @tenant site attribute) to decide whether to loop through sites. These are different checks. When the webflow_configuration object is site-tenanted but the "sites" feature flag is disabled, the interceptor will loop through sites (setting site context), but this function will use flat caching. Since selectData() without bypassTenants will still filter by site tenancy, the first site's data gets cached and incorrectly returned for subsequent sites - the exact bug this PR aims to fix.

Fix in Cursor Fix in Web

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed by using tenancy check instead of sites feature check.

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.

2 participants