Skip to content
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

fix: return null for 'parent' call on root collection #1099

Merged
merged 2 commits into from
May 31, 2020

Conversation

schmidt-sebastian
Copy link
Contributor

@schmidt-sebastian schmidt-sebastian commented May 30, 2020

We need to return "null" for the parent call in a root collection.

Also noticed that our Path.isEqual doesn't work correctly since it considers QualifiedResourcePaths and ResourcePaths as non-equal. Our typings already ensure that a FieldPath and a ResourcePath can never be compared for equality.

Fixes #1098

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label May 30, 2020
@codecov
Copy link

codecov bot commented May 30, 2020

Codecov Report

Merging #1099 into master will decrease coverage by 0.12%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1099      +/-   ##
==========================================
- Coverage   97.61%   97.48%   -0.13%     
==========================================
  Files          27       27              
  Lines       16970    16974       +4     
  Branches     1351     1270      -81     
==========================================
- Hits        16565    16547      -18     
- Misses        402      423      +21     
- Partials        3        4       +1     
Impacted Files Coverage Δ
dev/src/path.ts 98.55% <100.00%> (-0.01%) ⬇️
dev/src/reference.ts 99.80% <100.00%> (-0.08%) ⬇️
dev/src/order.ts 98.09% <0.00%> (-1.15%) ⬇️
dev/src/pool.ts 97.75% <0.00%> (-0.90%) ⬇️
dev/src/transaction.ts 96.47% <0.00%> (-0.51%) ⬇️
dev/src/watch.ts 98.77% <0.00%> (-0.37%) ⬇️
dev/src/bulk-writer.ts 98.49% <0.00%> (-0.31%) ⬇️
dev/src/document.ts 98.62% <0.00%> (-0.30%) ⬇️
dev/src/validate.ts 98.05% <0.00%> (-0.25%) ⬇️
dev/src/serializer.ts 98.81% <0.00%> (-0.24%) ⬇️
... and 3 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cd5e296...9002742. Read the comment docs.

Copy link

@thebrianchen thebrianchen left a comment

Choose a reason for hiding this comment

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

LGTM. Wouldn't this be considered a breaking change since users would have to check that their .parent call isn't null now?

get parent(): DocumentReference<DocumentData> {
return new DocumentReference(this.firestore, this._queryOptions.parentPath);
get parent(): DocumentReference<DocumentData> | null {
if (this._queryOptions.parentPath.isDocument) {

Choose a reason for hiding this comment

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

s/isDocument/isDocument()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

isDocument is a property (typed a get isDocument()). As such, no parenthesis are needed.

Copy link
Contributor Author

@schmidt-sebastian schmidt-sebastian left a comment

Choose a reason for hiding this comment

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

Thanks for the review. Fortunately, this is not a breaking change:

  • The method is already typed to return null (in the firestore.d.ts types). I will also update the JSDoc.
  • This caused an "NPE" in our code before, so this was already broken (that's the issue that was filed).

@schmidt-sebastian schmidt-sebastian merged commit c5c0b15 into master May 31, 2020
@schmidt-sebastian schmidt-sebastian deleted the mrschmidt/parent branch June 24, 2020 21:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'parent' of null
3 participants