Fix: Prevent areFieldsCompatible from crashing when DB or field type mappings are missing #742
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.
This PR adds safeguards to the areFieldsCompatible utility to prevent runtime crashes when database or field type mappings are missing from dbToTypes. The fix improves stability when importing schemas with custom types or partially supported DB engines.
Issue
The previous implementation assumed that every DB and field type exists:
When any of these were missing:
DrawDB threw a runtime error:
TypeError: Cannot read properties of undefined (reading 'compatibleWith')This caused schema imports to fail for:
Fix
The function now safely checks for missing mappings using optional chaining:
✅ No behavior change for valid field types
✅ Gracefully handles unknown types by falling back to equality check
✅ Matches DrawDB’s existing behavior of “best effort” compatibility
Impact
Prevents app crashes during schema import and diagram loading
Improves stability for custom DBs and user-defined field types
Changes are small, isolated, and low-risk
No new dependencies or breaking changes
Testing
Manual verification performed:
[x] Schema imports that previously crashed now load correctly
[x] Normal schemas behave exactly as before
[x] No regressions observed