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

firestore: add a FieldPath class #4378

Closed
jba opened this issue Nov 9, 2017 · 12 comments
Closed

firestore: add a FieldPath class #4378

jba opened this issue Nov 9, 2017 · 12 comments
Assignees
Labels
api: firestore Issues related to the Firestore API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@jba
Copy link
Contributor

jba commented Nov 9, 2017

The firestore client conflates dot-separated strings with field paths in the update methods. There should be two cases for top-level dict keys passed to update:

  • If the key is a string, it is split on dots and cannot contain any of the special characters ~*/[]. There also can't be any empty parts. One reasonable approach is:
    # validate that there are no special characters in s
    fp = FieldPath(s.split('.'))
    
  • If the key is a FieldPath, it is treated as-is.

Where FieldPath is something like:

class FieldPath(object):
    def __init__(self, *parts):
        # Verify that each part is a string, and that no part is the empty string.

    def _to_api_repr(self):
        # Apply Firestore escaping rules, using backticks and backslashes for parts
        # that do not match ^[A-Za-z_][A-Za-z_0-9]*$.
        # E.g. FieldPath("a", "~", "`").to_api_repr() => "a.`~`.`\``"

    def __eq__(self): # and __ne__ and whatever else is needed to be a dict key.

Since it is now possible to pass a dict where the same effective path occurs twice, that needs to be checked explicitly.
E.g.

{"a": 1, FieldPath("a"): 2}

should be an error.

@schmidt-sebastian Confirm this is accurate.

@dhermes dhermes added the api: firestore Issues related to the Firestore API. label Nov 9, 2017
@schmidt-sebastian
Copy link

Yes, this is accurate.

@tseaver tseaver added the type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. label Nov 10, 2017
@chemelnucfin chemelnucfin self-assigned this Nov 13, 2017
@chemelnucfin
Copy link
Contributor

chemelnucfin commented Nov 13, 2017

@jba I would like some clarifications on the FieldPath (FP).

  1. It seems like I should be able to take either a string, or an iterable and FP will figure out what to do. So either FP("a.b.c"), FP("a", "b", "c") and FP(["a", "b", "c"]) should all work and return the same thing, but I assume FP(["a"], "b", "c") will raise ValueError. Is this correct?

  2. You mentioned above that ~ is an invalid character, but you allowed FieldPath to have "~" in the constructor. I would like to confirm that that "~" is only invalid inside a string such as FP("a.~.c"), but valid in FP("a", "~", "b")

  3. How do backslashes get handled in api_repr()? Would "\\" (single slash) return "\\" or "`\\`"? I assume that "\\\\" (double slash) doesn't happen in paths, so how do you want that to be handled? An error, or "`\\``\\`", or something else?

  4. Do unicode characters fit into your regex requirements?

  5. Not exactly sure where to check for the same effective path, but I haven't looked at that part of the code yet.

Thanks in advance.

chemelnucfin added a commit to chemelnucfin/google-cloud-python that referenced this issue Nov 14, 2017
chemelnucfin added a commit to chemelnucfin/google-cloud-python that referenced this issue Nov 15, 2017
chemelnucfin added a commit to chemelnucfin/google-cloud-python that referenced this issue Nov 15, 2017
chemelnucfin added a commit to chemelnucfin/google-cloud-python that referenced this issue Nov 15, 2017
chemelnucfin added a commit to chemelnucfin/google-cloud-python that referenced this issue Nov 15, 2017
chemelnucfin added a commit to chemelnucfin/google-cloud-python that referenced this issue Nov 19, 2017
chemelnucfin added a commit to chemelnucfin/google-cloud-python that referenced this issue Nov 20, 2017
chemelnucfin added a commit to chemelnucfin/google-cloud-python that referenced this issue Nov 20, 2017
chemelnucfin added a commit to chemelnucfin/google-cloud-python that referenced this issue Nov 20, 2017
@jba
Copy link
Contributor Author

jba commented Nov 20, 2017

Sorry, just saw this. I think we figured out all the answers on the PR.

chemelnucfin added a commit to chemelnucfin/google-cloud-python that referenced this issue Nov 27, 2017
chemelnucfin added a commit to chemelnucfin/google-cloud-python that referenced this issue Nov 28, 2017
@schmidt-sebastian
Copy link

schmidt-sebastian commented Dec 1, 2017

@dhermes / @chemelnucfin: Can you give us an estimate for the completion of this change?

@schmidt-sebastian
Copy link

schmidt-sebastian commented Dec 1, 2017

I might be late to this, but let me answer:

1 - FieldPath("a.b.c") is not the same as FieldPath("a", "b', "c"). In fact, it is a.b.c. String("a.b.c") is the same as FieldPath("a", "b', "c"). FieldPath(string) should not split on dots.
2. The set of invalid characters only applies to String field paths.
3.-5.: Please look at how it is done in Node: https://github.com/googleapis/nodejs-firestore/blob/master/src/path.js#L518

@schmidt-sebastian
Copy link

@chemelnucfin Can you provide an estimate for this issue?

@chemelnucfin
Copy link
Contributor

@schmidt-sebastian #4392 has been approved by jba, but dhermes would like to review it first before I merge it.

@chemelnucfin
Copy link
Contributor

@schmidt-sebastian Danny has been helping me quite a bit on spanner reviews and getting pull requests in for pubsub and a lot of others. I can understand that he's quite busy with other tasks.

@schmidt-sebastian
Copy link

@schmidt-sebastian Danny has been helping me quite a bit on spanner reviews and getting pull requests in for pubsub and a lot of others. I can understand that he's quite busy with other tasks.

That's fine, just wanted to make sure that this doesn't get dropped.

chemelnucfin added a commit to chemelnucfin/google-cloud-python that referenced this issue Dec 21, 2017
chemelnucfin added a commit to chemelnucfin/google-cloud-python that referenced this issue Mar 6, 2018
chemelnucfin added a commit that referenced this issue Mar 6, 2018
* #4378 - Field Path

* review changes

* 2nd review changes

* 3rd review changes
@schmidt-sebastian
Copy link

@chemelnucfin Is there any work remaining on this, now that #4392 is closed?

@chemelnucfin
Copy link
Contributor

@schmidt-sebastian Could you please review #4466?
This can be closed after that is merged. Thanks.

@chemelnucfin
Copy link
Contributor

Closed in #4392 and #4466.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: firestore Issues related to the Firestore API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

No branches or pull requests

5 participants