Skip to content
This repository was archived by the owner on Jan 12, 2022. It is now read-only.

Commit 4248d7d

Browse files
author
Bryan Mau
committed
Updating Exported SDK to 0.66
1 parent 371e08a commit 4248d7d

15 files changed

Lines changed: 847 additions & 46 deletions

File tree

appengine-compat/exported_appengine_sdk/google/appengine/api/dispatchinfo.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
DISPATCH = 'dispatch'
7070
URL = 'url'
7171
MODULE = 'module'
72+
SERVICE = 'service'
7273

7374

7475
class Error(Exception):
@@ -168,7 +169,8 @@ class DispatchEntry(validation.Validated):
168169
"""A Dispatch entry describes a mapping from a URL pattern to a module."""
169170
ATTRIBUTES = {
170171
URL: DispatchEntryURLValidator(),
171-
MODULE: validation.Regex(appinfo.MODULE_ID_RE_STRING),
172+
MODULE: validation.Optional(appinfo.MODULE_ID_RE_STRING),
173+
SERVICE: validation.Optional(appinfo.MODULE_ID_RE_STRING)
172174
}
173175

174176

@@ -195,7 +197,7 @@ def LoadSingleDispatch(dispatch_info, open_fn=None):
195197
196198
Raises:
197199
MalformedDispatchConfigurationError: The yaml file contains multiple
198-
dispatch sections.
200+
dispatch sections or is missing a required value.
199201
yaml_errors.EventError: An error occured while parsing the yaml file.
200202
"""
201203
builder = yaml_object.ObjectBuilder(DispatchInfoExternal)
@@ -209,4 +211,19 @@ def LoadSingleDispatch(dispatch_info, open_fn=None):
209211
if len(parsed_yaml) > 1:
210212
raise MalformedDispatchConfigurationError('Multiple dispatch: sections '
211213
'in configuration.')
212-
return parsed_yaml[0]
214+
215+
216+
217+
dispatch_info_external = parsed_yaml[0]
218+
for dispatch in getattr(dispatch_info_external, DISPATCH) or []:
219+
if dispatch.module and dispatch.service:
220+
raise MalformedDispatchConfigurationError(
221+
'Both module: and service: in dispatch entry. Please use only one.')
222+
if not (dispatch.module or dispatch.service):
223+
raise MalformedDispatchConfigurationError(
224+
"Missing required value 'service'.")
225+
226+
227+
dispatch.module = dispatch.module or dispatch.service
228+
dispatch.service = None
229+
return dispatch_info_external

appengine-compat/exported_appengine_sdk/google/appengine/datastore/cloud_datastore_validator.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,7 @@ def validate_query(self, query, is_strong_read_consistency):
825825
ValidationError: if the query is invalid
826826
"""
827827
_assert_condition((not is_strong_read_consistency
828-
or self._has_ancestor(query.filter)),
828+
or self._has_ancestor_or_parent(query.filter)),
829829
'Global queries do not support strong consistency.')
830830
if query.HasField('filter'):
831831
self.validate_filter(query.filter)
@@ -911,7 +911,7 @@ def __validate_property_order(self, property_order):
911911
"""
912912
self.__validate_property_reference(property_order.property)
913913

914-
def _has_ancestor(self, filt):
914+
def _has_ancestor_or_parent(self, filt):
915915
"""Determines if a filter includes an ancestor filter.
916916
917917
Args:
@@ -923,13 +923,16 @@ def _has_ancestor(self, filt):
923923
if filt.HasField('property_filter'):
924924
op = filt.property_filter.op
925925
name = filt.property_filter.property.name
926-
return (op == googledatastore.PropertyFilter.HAS_ANCESTOR
926+
value = filt.property_filter.value
927+
return ((op == googledatastore.PropertyFilter.HAS_ANCESTOR or
928+
op == googledatastore.PropertyFilter.HAS_PARENT)
929+
and value.HasField('key_value')
927930
and name == datastore_pbs.PROPERTY_NAME_KEY)
928931
if filt.HasField('composite_filter'):
929932
if (filt.composite_filter.op
930933
== googledatastore.CompositeFilter.AND):
931934
for sub_filter in filt.composite_filter.filters:
932-
if self._has_ancestor(sub_filter):
935+
if self._has_ancestor_or_parent(sub_filter):
933936
return True
934937
return False
935938

appengine-compat/exported_appengine_sdk/google/appengine/datastore/datastore_pbs.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1652,12 +1652,17 @@ def _v3_query_to_v1_ancestor_filter(self, v3_query, v1_property_filter):
16521652
"""
16531653
v1_property_filter.Clear()
16541654
v1_property_filter.set_operator(
1655+
v3_query.shallow() and
1656+
googledatastore.PropertyFilter.HAS_PARENT or
16551657
googledatastore.PropertyFilter.HAS_ANCESTOR)
16561658
prop = v1_property_filter.property
16571659
prop.set_name(PROPERTY_NAME_KEY)
1658-
self._entity_converter.v3_to_v1_key(
1659-
v3_query.ancestor(),
1660-
v1_property_filter.value.mutable_key_value)
1660+
if v3_query.has_ancestor():
1661+
self._entity_converter.v3_to_v1_key(
1662+
v3_query.ancestor(),
1663+
v1_property_filter.value.mutable_key_value)
1664+
else:
1665+
v1_property_filter.value.null_value = googledatastore.NULL_VALUE
16611666

16621667
def v3_order_to_v1_order(self, v3_order, v1_order):
16631668
"""Converts a v3 Query order to a v1 PropertyOrder.

appengine-compat/exported_appengine_sdk/google/appengine/datastore/datastore_stub_util.py

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,6 +1281,17 @@ def __init__(self, query, dsquery, orders, index_list, results):
12811281
new_results.append(result)
12821282
results = new_results
12831283

1284+
if query.shallow():
1285+
key_path_length = 1
1286+
if query.has_ancestor():
1287+
key_path_length += query.ancestor().path().element_size()
1288+
1289+
new_results = []
1290+
for result in results:
1291+
if result.entity.key().path().element_size() == key_path_length:
1292+
new_results.append(result)
1293+
results = new_results
1294+
12841295
if (query.has_compiled_cursor()
12851296
and query.compiled_cursor().has_postfix_position()):
12861297
start_cursor = self._DecodeCompiledCursor(query.compiled_cursor())
@@ -3820,7 +3831,7 @@ def v3_to_v1_query(self, v3_query, v1_query):
38203831

38213832

38223833
num_v1_filters = len(v3_query.filter_list())
3823-
if v3_query.has_ancestor():
3834+
if v3_query.has_ancestor() or v3_query.shallow():
38243835
num_v1_filters += 1
38253836

38263837
if num_v1_filters == 1:
@@ -3830,7 +3841,7 @@ def v3_to_v1_query(self, v3_query, v1_query):
38303841
googledatastore.CompositeFilter.AND)
38313842
get_property_filter = self.__add_property_filter_from_V1
38323843

3833-
if v3_query.has_ancestor():
3844+
if v3_query.has_ancestor() or v3_query.shallow():
38343845
self._v3_query_to_v1_ancestor_filter(v3_query,
38353846
get_property_filter(v1_query))
38363847
for v3_filter in v3_query.filter_list():
@@ -3861,19 +3872,30 @@ def __populate_v3_filters_from_v1(self, v1_filter, v3_query):
38613872
if filter_type == 'property_filter':
38623873
v1_property_filter = v1_filter.property_filter
38633874
v1_property_name = v1_property_filter.property.name
3864-
if (v1_property_filter.op
3865-
== googledatastore.PropertyFilter.HAS_ANCESTOR):
3866-
datastore_pbs.check_conversion(
3867-
v1_property_filter.value.HasField('key_value'),
3868-
'HAS_ANCESTOR requires a reference value')
3875+
if (v1_property_filter.op == googledatastore.PropertyFilter.HAS_PARENT or
3876+
v1_property_filter.op == googledatastore.PropertyFilter.HAS_ANCESTOR):
3877+
if v1_property_filter.op == googledatastore.PropertyFilter.HAS_PARENT:
3878+
datastore_pbs.check_conversion(
3879+
v1_property_filter.value.HasField('key_value') or
3880+
v1_property_filter.value.HasField('null_value'),
3881+
'HAS_PARENT requires a key value or null')
3882+
else:
3883+
datastore_pbs.check_conversion(
3884+
v1_property_filter.value.HasField('key_value'),
3885+
'HAS_ANCESTOR requires a key value')
38693886
datastore_pbs.check_conversion((v1_property_name
38703887
== datastore_pbs.PROPERTY_NAME_KEY),
38713888
'unsupported property')
3872-
datastore_pbs.check_conversion(not v3_query.has_ancestor(),
3873-
'duplicate ancestor constraint')
3874-
self._entity_converter.v1_to_v3_reference(
3875-
v1_property_filter.value.key_value,
3876-
v3_query.mutable_ancestor())
3889+
datastore_pbs.check_conversion(not v3_query.has_ancestor() and
3890+
not v3_query.shallow(),
3891+
'duplicate ancestor or parent '
3892+
'constraint')
3893+
if v1_property_filter.value.HasField('key_value'):
3894+
self._entity_converter.v1_to_v3_reference(
3895+
v1_property_filter.value.key_value,
3896+
v3_query.mutable_ancestor())
3897+
if v1_property_filter.op == googledatastore.PropertyFilter.HAS_PARENT:
3898+
v3_query.set_shallow(True)
38773899
else:
38783900
v3_filter = v3_query.add_filter()
38793901
property_name = v1_property_name

0 commit comments

Comments
 (0)