Skip to content

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

Open
wants to merge 1 commit into
base: next
Choose a base branch
from

Conversation

YounesAmalou
Copy link

@YounesAmalou YounesAmalou commented May 23, 2025

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

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.
@cabljac cabljac requested review from cabljac and Copilot and removed request for cabljac May 27, 2025 08:22
@cabljac
Copy link
Contributor

cabljac commented May 27, 2025

Hi, thanks for opening this! Really appreciate contributions. I'll review ASAP

@cabljac cabljac moved this to Review Requested [PR] in [Cloud] Extensions + Functions May 27, 2025
Copy link

@Copilot Copilot AI left a 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 for endAt
  • 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 malformed referenceValue inputs are handled correctly.
if (serializableQuery.startAt?.values?.[0]?.referenceValue) {

Comment on lines +54 to +60
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];
Copy link
Preview

Copilot AI May 27, 2025

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.

Comment on lines 49 to +60
// 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];
Copy link
Preview

Copilot AI May 27, 2025

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.

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