fix: support non-default Firestore database ID in datasource configuration#41546
fix: support non-default Firestore database ID in datasource configuration#41546RaikaSurendra wants to merge 2 commits intoappsmithorg:releasefrom
Conversation
…ation - Added optional 'Database ID' field to Firestore datasource form.json - Added getDatabaseId() helper to extract database ID from properties - Changed FirestoreClient.getFirestore(app, databaseId) to pass database ID - Defaults to '(default)' when no database ID is provided - Added tests for default, custom, and empty database ID scenarios Fixes appsmithorg#38121
WalkthroughReads a "databaseId" property from datasource configuration (defaulting to "(default)"), passes it into FirestoreClient initialization during datasource creation, and adds form inputs and tests to exercise this new databaseId flow. Changes
Sequence Diagram(s)sequenceDiagram
participant UI as "Admin UI"
participant DS as "DatasourceConfiguration"
participant Plugin as "FirestorePlugin / Executor"
participant Client as "FirestoreClient"
participant Firebase as "FirebaseApp / Firestore"
UI->>DS: user provides service account + Database ID
DS->>Plugin: datasourceCreate / testConnection with config
Plugin->>Plugin: getDatabaseId(datasourceConfiguration)
Plugin->>Client: getFirestore(app, databaseId)
Client->>Firebase: initialize or getInstance(projectId, options, databaseId)
Firebase-->>Client: Firestore instance bound to databaseId
Client-->>Plugin: initialized Firestore
Plugin-->>DS: return success / connection result
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉 Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In
`@app/server/appsmith-plugins/firestorePlugin/src/main/java/com/external/plugins/FirestorePlugin.java`:
- Around line 948-959: getDatabaseId currently casts property.getValue() to
String directly and can throw ClassCastException; change the check in the loop
inside getDatabaseId to first verify the value is a String (e.g.,
property.getValue() instanceof String) before casting and passing to
StringUtils.isEmpty, or defensively convert with
Objects.toString(property.getValue(), null) and then check emptiness; update the
logic around Property, DatasourceConfiguration, CollectionUtils and StringUtils
usage so non-String values are ignored (or handled safely) and only valid String
databaseId values are returned.
In
`@app/server/appsmith-plugins/firestorePlugin/src/test/java/com/external/plugins/FirestorePluginTest.java`:
- Around line 1801-1859: The tests call validateDatasource() but that method
never inspects the databaseId, so add unit tests that directly exercise
getDatabaseId() (or make it package-private) and assert it returns "(default)"
when properties are null/empty, returns the custom value when set, and falls
back to "(default)" when the property exists but is empty; additionally add a
Mockito-based test for datasourceCreate() to verify
FirestoreClient.getFirestore(app, expectedDatabaseId) is invoked with the
expected databaseId for default, custom, and empty cases (referencing
getDatabaseId(), validateDatasource(), datasourceCreate(), and
FirestoreClient.getFirestore(app, databaseId) to locate the code under test).
🧹 Nitpick comments (1)
app/server/appsmith-plugins/firestorePlugin/src/main/resources/form.json (1)
29-36: Consider adding a tooltip/subtitle explaining the field.The "Database ID" field defaults to
(default)but users unfamiliar with Firestore multi-database support may not know what to put here. A shortsubtitleortooltip(e.g., "Leave as (default) unless using a named Firestore database") would improve UX.
...ver/appsmith-plugins/firestorePlugin/src/main/java/com/external/plugins/FirestorePlugin.java
Outdated
Show resolved
Hide resolved
...appsmith-plugins/firestorePlugin/src/test/java/com/external/plugins/FirestorePluginTest.java
Show resolved
Hide resolved
- Add instanceof String guard in getDatabaseId() to prevent ClassCastException - Change getDatabaseId() from private to package-private for testability - Rewrite tests to directly test getDatabaseId() with 5 scenarios: no properties, null properties, custom value, empty value, non-String value - Remove unused Set import
Description
Fixes #38121 — Firestore connection always connects to the default database, ignoring non-default database configuration.
Changes
(default))FirestoreClient::getFirestore→FirestoreClient.getFirestore(app, databaseId)Root Cause
FirestoreClient::getFirestore(no-arg) always returns the default database.The fix uses
FirestoreClient.getFirestore(app, databaseId)from Firebase Admin SDK 9.2.0.Testing
Summary by CodeRabbit
New Features
Tests