Skip to content

fix: v2/v3 data access runtime switch with instanceof fixes#1831

Merged
ekremney merged 5 commits intomainfrom
fix/data-access-v2-v3-instanceof
Feb 19, 2026
Merged

fix: v2/v3 data access runtime switch with instanceof fixes#1831
ekremney merged 5 commits intomainfrom
fix/data-access-v2-v3-instanceof

Conversation

@ekremney
Copy link
Member

Summary

  • Re-applies the v2/v3 data access runtime switch (reverted in feat: add markOpportunitiesReviewed endpoint to LlmoController | LLMO-3058 #1828) with fixes for the cross-package instanceof failures that caused the production outage
  • Replaces instanceof ValidationError with error.name === 'ValidationError' checks in controllers (fixes, opportunities, suggestions)
  • Replaces instanceof Site/Organization/Project with entity.entityName checks in access-control-util
  • Updates all affected tests to use entityName mock pattern instead of Object.setPrototypeOf

Root Cause

When v3 is installed as the main package and v2 as an npm alias, instanceof checks against v3 classes fail for v2-created instances (different constructors from different packages). The fix uses duck-typing via entityName property and error.name string checks, both of which are stable across v2/v3.

Test plan

  • All 3547 unit tests passing
  • 100% code coverage maintained
  • ESLint passes
  • Deploy to stage and verify with non-admin user
  • Verify DATA_SERVICE_PROVIDER=postgres switches to v3

🤖 Generated with Claude Code

Re-apply the v2/v3 data access runtime switch (reverted in #1828) with
fixes for the cross-package instanceof failures that caused the
production outage.

Changes:
- Upgrade spacecat-shared-data-access to v3, keep v2 as npm alias
- Add runtime switch middleware (DATA_SERVICE_PROVIDER env var)
- Replace instanceof ValidationError with error.name check
- Replace instanceof Site/Organization/Project with entityName check
- Update all affected tests to use entityName mock pattern

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions
Copy link

This PR will trigger a patch release when merged.

@ekremney ekremney requested a review from solaris007 February 18, 2026 21:30
@codecov
Copy link

codecov bot commented Feb 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link
Member

@solaris007 solaris007 left a comment

Choose a reason for hiding this comment

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

@ekremney - the .name may be similarly affected as instanceof.

Consider these PRs:

@solaris007 solaris007 added the bug Something isn't working label Feb 19, 2026
ekremney and others added 2 commits February 19, 2026 13:20
…e checks

Replace instance property checks (entity.entityName === 'site') with static
constant checks (entity.constructor.ENTITY_NAME === 'Site') for more robust
cross-package entity type identification.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@ekremney ekremney merged commit 5181b92 into main Feb 19, 2026
16 checks passed
@ekremney ekremney deleted the fix/data-access-v2-v3-instanceof branch February 19, 2026 13:51
solaris007 pushed a commit that referenced this pull request Feb 19, 2026
## [1.320.4](v1.320.3...v1.320.4) (2026-02-19)

### Bug Fixes

* v2/v3 data access runtime switch with instanceof fixes ([#1831](#1831)) ([5181b92](5181b92)), closes [#1828](#1828)
@solaris007
Copy link
Member

🎉 This PR is included in version 1.320.4 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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

Labels

bug Something isn't working released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants