Repository navigation
Firestore: from_api_repr and parse_field_path methods - #5109
chemelnucfin wants to merge 3 commits into
Conversation
|
@chemelnucfin Although PRs may introduce bugs, we don't want to classify them as bugs. If this PR is fixing an existing bug (or even working toward it), please link that issue in the description. |
|
@jba could you take a look at this one first? Thanks. |
|
|
||
| This method always splits on dots. If the unicode string representation | ||
| includes dots or other invalid characters `~*/[]`, this method will fail | ||
| and the constructor must be used to determine nesting. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| A tuple with the first field name and the api_repr | ||
| of the rest. | ||
| """ | ||
| if api_repr[0] == '.': |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| if api_repr[index-1] == '`': # skips escaped backticks | ||
| value = ( | ||
| api_repr[:index+1], | ||
| '.'.join(api_repr[index+1:].split('.'))) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| api_repr = api_repr[1:] | ||
| if api_repr[0] != '`': # first field name is simple | ||
| field_names = api_repr.split('.') | ||
| return field_names[0], '.'.join(field_names[1:]) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| return field_names[0], '.'.join(field_names[1:]) | ||
| else: | ||
| index = 1 | ||
| while index < len(api_repr): |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| return cls(*string) | ||
|
|
||
| @classmethod | ||
| def _parse_field_name(cls, api_repr): |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| @@ -133,64 +133,90 @@ def test_unicode(self): | |||
| self.assertEqual(field_path.parts, ('一', '二', '三')) | |||
|
|
|||
| def test_to_api_repr_a(self): | |||
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
af7b563 to
caf8a50
Compare
caf8a50 to
5c2d4a4
Compare
| The constructor must be used if the unicode string representation | ||
| consists of invalid characters `~*/[]`. This method always splits | ||
| on the character `.` for nesting. If any field names in this field | ||
| path includes the character `.`, the constructor must also be used |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| return cls(*string) | ||
|
|
||
| @classmethod | ||
| def _parse_field_name(cls, api_repr): |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
@jba I think I found the scenario where I needed this From this test The only reason I know that that is actually Maybe I missed something? How do you handle this in golang? |
|
The JSON in the tests should correspond exactly to a Python dict that is the argument to the update method. So that JSON should map to the Python Thus, update( { ‘foo.bar’ : 42 } ) becomes an object with the nested hierarchy of { foo { bar : 42 }}. |
|
Just to be clear: nothing in the tests requires you to parse the API format for field paths. You only need to generate that format, not parse it. |
|
Ahh, I think this makes more sense now. Note that the server rejects documents that contain single field names with dots that prefix match other field names. Hence, a document cannot contain both ‘a’ and ‘`a.b`’. The Server SDKs can rely on the backend to perform this validation. |
|
Closing this for now. |
No description provided.