-
Notifications
You must be signed in to change notification settings - Fork 408
fix(firestore-bigquery-export): fixed reference path #2437
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: next
Are you sure you want to change the base?
Conversation
Fixed the Firestore doc reference path by passing the part after the "/documents/" only, which is what is needed for the doc function to work properly.
Hi, thanks for opening this! Really appreciate contributions. I'll review ASAP |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes how Firestore document reference paths are handled by stripping the full resource name down to the relative path required by firebase.firestore().doc
.
- Adjusts
startAt
to use only the path after/documents/
- Adjusts
endBefore
similarly forendAt
- Retains existing offset logic untouched
Comments suppressed due to low confidence (1)
firestore-bigquery-export/scripts/import/src/worker.ts:51
- There are no tests covering the case where the reference value includes the full resource name. Add unit tests for
processDocuments
to ensure both valid and malformedreferenceValue
inputs are handled correctly.
if (serializableQuery.startAt?.values?.[0]?.referenceValue) {
const relativePath = resourceName.split("/documents/")[1]; | ||
query = query.startAt(firebase.firestore().doc(relativePath)); | ||
} | ||
if (serializableQuery.endAt?.values?.[0]?.referenceValue) { | ||
const endPath = serializableQuery.endAt.values[0].referenceValue; | ||
query = query.endBefore(firebase.firestore().doc(endPath)); | ||
// similarly strip to relative path | ||
const resourceName = serializableQuery.endAt.values[0].referenceValue; | ||
const relativePath = resourceName.split("/documents/")[1]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If resourceName
does not contain /documents/
, split("/documents/")[1]
will be undefined
, causing doc(undefined)
to fail. Consider validating the split result or using a more robust extraction (e.g., const idx = resourceName.indexOf('/documents/'); if (idx === -1) throw ...; const relativePath = resourceName.substring(idx + 11);
).
Copilot uses AI. Check for mistakes.
// Apply partition boundaries from the serialized query | ||
// These define the range of documents this worker should process | ||
if (serializableQuery.startAt?.values?.[0]?.referenceValue) { | ||
const startPath = serializableQuery.startAt.values[0].referenceValue; | ||
query = query.startAt(firebase.firestore().doc(startPath)); | ||
// strip off the full resource name, keep only the part after "/documents/" | ||
const resourceName = serializableQuery.startAt.values[0].referenceValue; | ||
const relativePath = resourceName.split("/documents/")[1]; | ||
query = query.startAt(firebase.firestore().doc(relativePath)); | ||
} | ||
if (serializableQuery.endAt?.values?.[0]?.referenceValue) { | ||
const endPath = serializableQuery.endAt.values[0].referenceValue; | ||
query = query.endBefore(firebase.firestore().doc(endPath)); | ||
// similarly strip to relative path | ||
const resourceName = serializableQuery.endAt.values[0].referenceValue; | ||
const relativePath = resourceName.split("/documents/")[1]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The logic to strip the /documents/
prefix is duplicated for startAt
and endAt
. Extract this into a helper function (e.g. getRelativePath(resourceName)
) to reduce repetition and improve clarity.
Copilot uses AI. Check for mistakes.
Fixed the Firestore doc reference path by passing the part after the "/documents/" only, which is what is needed for the doc function to work properly.
#2436