We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Entities loaded in gcloud.datastore don't have a dataset
``` python
>>> dataset = demo.get_dataset()
>>> query = dataset.query()
>>> entity = query.fetch()[0]
>>> entity.delete()
... 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "gcloud/datastore/entity.py", line 206, in delete
    self.dataset().connection().delete_entity(
AttributeError: 'NoneType' object has no attribute 'delete_entity'
```

This is because we're creating entities from the protobufs, with the proper `dataset_id` but not a true reference to the Dataset object (which has a pointer to the connection).


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `gcloud/datastore/query.py`
Content:
```
1 import copy
2 
3 from gcloud.datastore import datastore_v1_pb2 as datastore_pb
4 from gcloud.datastore import helpers
5 from gcloud.datastore.entity import Entity
6 
7 
8 # TODO: Figure out how to properly handle namespaces.
9 
10 class Query(object):
11   """A Query against the Cloud Datastore.
12 
13   This class serves as an abstraction for creating
14   a query over data stored in the Cloud Datastore.
15 
16   Each :class:`Query` object is immutable,
17   and a clone is returned whenever
18   any part of the query is modified::
19 
20     >>> query = Query('MyKind')
21     >>> limited_query = query.limit(10)
22     >>> query.limit() == 10
23     False
24     >>> limited_query.limit() == 10
25     True
26 
27   You typically won't construct a :class:`Query`
28   by initializing it like ``Query('MyKind', dataset=...)``
29   but instead use the helper
30   :func:`gcloud.datastore.dataset.Dataset.query` method
31   which generates a query that can be executed
32   without any additional work::
33 
34     >>> from gcloud import datastore
35     >>> dataset = datastore.get_dataset('dataset-id', email, key_path)
36     >>> query = dataset.query('MyKind')
37 
38   :type kind: string
39   :param kind: The kind to query.
40 
41   :type dataset: :class:`gcloud.datastore.dataset.Dataset`
42   :param dataset: The dataset to query.
43   """
44 
45   OPERATORS = {
46       '<': datastore_pb.PropertyFilter.LESS_THAN,
47       '<=': datastore_pb.PropertyFilter.LESS_THAN_OR_EQUAL,
48       '>': datastore_pb.PropertyFilter.GREATER_THAN,
49       '>=': datastore_pb.PropertyFilter.GREATER_THAN_OR_EQUAL,
50       '=': datastore_pb.PropertyFilter.EQUAL,
51       }
52   """Mapping of operator strings and their protobuf equivalents."""
53 
54   def __init__(self, kind=None, dataset=None):
55     self._dataset = dataset
56     self._pb = datastore_pb.Query()
57 
58     if kind:
59       self._pb.kind.add().name = kind
60 
61   def _clone(self):
62     # TODO(jjg): Double check that this makes sense...
63     clone = copy.deepcopy(self)
64     clone._dataset = self._dataset  # Shallow copy the dataset.
65     return clone
66 
67   def to_protobuf(self):
68     """Convert the :class:`Query` instance to a :class:`gcloud.datastore.datastore_v1_pb2.Query`.
69 
70     :rtype: :class:`gclouddatstore.datastore_v1_pb2.Query`
71     :returns: A Query protobuf that can be sent to the protobuf API.
72     """
73     return self._pb
74 
75   def filter(self, expression, value):
76     """Filter the query based on an expression and a value.
77 
78     This will return a clone of the current :class:`Query`
79     filtered by the expression and value provided.
80 
81     Expressions take the form of::
82 
83       .filter('<property> <operator>', <value>)
84 
85     where property is a property stored on the entity in the datastore
86     and operator is one of ``OPERATORS``
87     (ie, ``=``, ``<``, ``<=``, ``>``, ``>=``)::
88 
89       >>> query = Query('Person')
90       >>> filtered_query = query.filter('name =', 'James')
91       >>> filtered_query = query.filter('age >', 50)
92 
93     Because each call to ``.filter()`` returns a cloned ``Query`` object
94     we are able to string these together::
95 
96       >>> query = Query('Person').filter('name =', 'James').filter('age >', 50)
97 
98     :type expression: string
99     :param expression: An expression of a property and an operator (ie, ``=``).
100 
101     :type value: integer, string, boolean, float, None, datetime
102     :param value: The value to filter on.
103 
104     :rtype: :class:`Query`
105     :returns: A Query filtered by the expression and value provided.
106     """
107     clone = self._clone()
108 
109     # Take an expression like 'property >=', and parse it into useful pieces.
110     property_name, operator = None, None
111     expression = expression.strip()
112 
113     for operator_string in self.OPERATORS:
114       if expression.endswith(operator_string):
115         operator = self.OPERATORS[operator_string]
116         property_name = expression[0:-len(operator_string)].strip()
117 
118     if not operator or not property_name:
119       raise ValueError('Invalid expression: "%s"' % expression)
120 
121     # Build a composite filter AND'd together.
122     composite_filter = clone._pb.filter.composite_filter
123     composite_filter.operator = datastore_pb.CompositeFilter.AND
124 
125     # Add the specific filter
126     property_filter = composite_filter.filter.add().property_filter
127     property_filter.property.name = property_name
128     property_filter.operator = operator
129 
130     # Set the value to filter on based on the type.
131     attr_name, pb_value = helpers.get_protobuf_attribute_and_value(value)
132     setattr(property_filter.value, attr_name, pb_value)
133     return clone
134 
135   def kind(self, *kinds):
136     """Get or set the Kind of the Query.
137 
138     .. note::
139       This is an **additive** operation.
140       That is, if the Query is set for kinds A and B,
141       and you call ``.kind('C')``,
142       it will query for kinds A, B, *and*, C.
143 
144     :type kinds: string
145     :param kinds: The entity kinds for which to query.
146 
147     :rtype: string or :class:`Query`
148     :returns: If no arguments, returns the kind.
149               If a kind is provided, returns a clone of the :class:`Query`
150               with those kinds set.
151     """
152     # TODO: Do we want this to be additive?
153     #       If not, clear the _pb.kind attribute.
154     if kinds:
155       clone = self._clone()
156       for kind in kinds:
157         clone._pb.kind.add().name = kind
158       return clone
159     else:
160       return self._pb.kind
161 
162   def limit(self, limit=None):
163     """Get or set the limit of the Query.
164 
165     This is the maximum number of rows (Entities) to return for this Query.
166 
167     This is a hybrid getter / setter, used as::
168 
169       >>> query = Query('Person')
170       >>> query = query.limit(100)  # Set the limit to 100 rows.
171       >>> query.limit()  # Get the limit for this query.
172       100
173 
174     :rtype: integer, None, or :class:`Query`
175     :returns: If no arguments, returns the current limit.
176               If a limit is provided, returns a clone of the :class:`Query`
177               with that limit set.
178     """
179     if limit:
180       clone = self._clone()
181       clone._pb.limit = limit
182       return clone
183     else:
184       return self._pb.limit
185 
186   def dataset(self, dataset=None):
187     """Get or set the :class:`gcloud.datastore.dataset.Dataset` for this Query.
188 
189     This is the dataset against which the Query will be run.
190 
191     This is a hybrid getter / setter, used as::
192 
193       >>> query = Query('Person')
194       >>> query = query.dataset(my_dataset)  # Set the dataset.
195       >>> query.dataset()  # Get the current dataset.
196       <Dataset object>
197 
198     :rtype: :class:`gcloud.datastore.dataset.Dataset`, None, or :class:`Query`
199     :returns: If no arguments, returns the current dataset.
200               If a dataset is provided, returns a clone of the :class:`Query`
201               with that dataset set.
202     """
203     if dataset:
204       clone = self._clone()
205       clone._dataset = dataset
206       return clone
207     else:
208       return self._dataset
209 
210   def fetch(self, limit=None):
211     """Executes the Query and returns all matching entities.
212 
213     This makes an API call to the Cloud Datastore,
214     sends the Query as a protobuf,
215     parses the responses to Entity protobufs,
216     and then converts them to :class:`gcloud.datastore.entity.Entity` objects.
217 
218     For example::
219 
220       >>> from gcloud import datastore
221       >>> dataset = datastore.get_dataset('dataset-id', email, key_path)
222       >>> query = dataset.query('Person').filter('name =', 'Sally')
223       >>> query.fetch()
224       [<Entity object>, <Entity object>, ...]
225       >>> query.fetch(1)
226       [<Entity object>]
227       >>> query.limit()
228       None
229 
230     :type limit: integer
231     :param limit: An optional limit to apply temporarily to this query.
232                   That is, the Query itself won't be altered,
233                   but the limit will be applied to the query
234                   before it is executed.
235 
236     :rtype: list of :class:`gcloud.datastore.entity.Entity`'s
237     :returns: The list of entities matching this query's criteria.
238     """
239     clone = self
240 
241     if limit:
242       clone = self.limit(limit)
243 
244     entity_pbs = self.dataset().connection().run_query(
245         query_pb=clone.to_protobuf(), dataset_id=self.dataset().id())
246 
247     return [Entity.from_protobuf(entity) for entity in entity_pbs]
248
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/gcloud/datastore/query.py b/gcloud/datastore/query.py
--- a/gcloud/datastore/query.py
+++ b/gcloud/datastore/query.py
@@ -244,4 +244,5 @@
     entity_pbs = self.dataset().connection().run_query(
         query_pb=clone.to_protobuf(), dataset_id=self.dataset().id())
 
-    return [Entity.from_protobuf(entity) for entity in entity_pbs]
+    return [Entity.from_protobuf(entity, dataset=self.dataset())
+            for entity in entity_pbs]

{"golden_diff": "diff --git a/gcloud/datastore/query.py b/gcloud/datastore/query.py\n--- a/gcloud/datastore/query.py\n+++ b/gcloud/datastore/query.py\n@@ -244,4 +244,5 @@\n     entity_pbs = self.dataset().connection().run_query(\n         query_pb=clone.to_protobuf(), dataset_id=self.dataset().id())\n \n-    return [Entity.from_protobuf(entity) for entity in entity_pbs]\n+    return [Entity.from_protobuf(entity, dataset=self.dataset())\n+            for entity in entity_pbs]\n", "issue": "Entities loaded in gcloud.datastore don't have a dataset\n``` python\n>>> dataset = demo.get_dataset()\n>>> query = dataset.query()\n>>> entity = query.fetch()[0]\n>>> entity.delete()\n... \nTraceback (most recent call last):\n  File \"<stdin>\", line 1, in <module>\n  File \"gcloud/datastore/entity.py\", line 206, in delete\n    self.dataset().connection().delete_entity(\nAttributeError: 'NoneType' object has no attribute 'delete_entity'\n```\n\nThis is because we're creating entities from the protobufs, with the proper `dataset_id` but not a true reference to the Dataset object (which has a pointer to the connection).\n\n", "before_files": [{"content": "import copy\n\nfrom gcloud.datastore import datastore_v1_pb2 as datastore_pb\nfrom gcloud.datastore import helpers\nfrom gcloud.datastore.entity import Entity\n\n\n# TODO: Figure out how to properly handle namespaces.\n\nclass Query(object):\n  \"\"\"A Query against the Cloud Datastore.\n\n  This class serves as an abstraction for creating\n  a query over data stored in the Cloud Datastore.\n\n  Each :class:`Query` object is immutable,\n  and a clone is returned whenever\n  any part of the query is modified::\n\n    >>> query = Query('MyKind')\n    >>> limited_query = query.limit(10)\n    >>> query.limit() == 10\n    False\n    >>> limited_query.limit() == 10\n    True\n\n  You typically won't construct a :class:`Query`\n  by initializing it like ``Query('MyKind', dataset=...)``\n  but instead use the helper\n  :func:`gcloud.datastore.dataset.Dataset.query` method\n  which generates a query that can be executed\n  without any additional work::\n\n    >>> from gcloud import datastore\n    >>> dataset = datastore.get_dataset('dataset-id', email, key_path)\n    >>> query = dataset.query('MyKind')\n\n  :type kind: string\n  :param kind: The kind to query.\n\n  :type dataset: :class:`gcloud.datastore.dataset.Dataset`\n  :param dataset: The dataset to query.\n  \"\"\"\n\n  OPERATORS = {\n      '<': datastore_pb.PropertyFilter.LESS_THAN,\n      '<=': datastore_pb.PropertyFilter.LESS_THAN_OR_EQUAL,\n      '>': datastore_pb.PropertyFilter.GREATER_THAN,\n      '>=': datastore_pb.PropertyFilter.GREATER_THAN_OR_EQUAL,\n      '=': datastore_pb.PropertyFilter.EQUAL,\n      }\n  \"\"\"Mapping of operator strings and their protobuf equivalents.\"\"\"\n\n  def __init__(self, kind=None, dataset=None):\n    self._dataset = dataset\n    self._pb = datastore_pb.Query()\n\n    if kind:\n      self._pb.kind.add().name = kind\n\n  def _clone(self):\n    # TODO(jjg): Double check that this makes sense...\n    clone = copy.deepcopy(self)\n    clone._dataset = self._dataset  # Shallow copy the dataset.\n    return clone\n\n  def to_protobuf(self):\n    \"\"\"Convert the :class:`Query` instance to a :class:`gcloud.datastore.datastore_v1_pb2.Query`.\n\n    :rtype: :class:`gclouddatstore.datastore_v1_pb2.Query`\n    :returns: A Query protobuf that can be sent to the protobuf API.\n    \"\"\"\n    return self._pb\n\n  def filter(self, expression, value):\n    \"\"\"Filter the query based on an expression and a value.\n\n    This will return a clone of the current :class:`Query`\n    filtered by the expression and value provided.\n\n    Expressions take the form of::\n\n      .filter('<property> <operator>', <value>)\n\n    where property is a property stored on the entity in the datastore\n    and operator is one of ``OPERATORS``\n    (ie, ``=``, ``<``, ``<=``, ``>``, ``>=``)::\n\n      >>> query = Query('Person')\n      >>> filtered_query = query.filter('name =', 'James')\n      >>> filtered_query = query.filter('age >', 50)\n\n    Because each call to ``.filter()`` returns a cloned ``Query`` object\n    we are able to string these together::\n\n      >>> query = Query('Person').filter('name =', 'James').filter('age >', 50)\n\n    :type expression: string\n    :param expression: An expression of a property and an operator (ie, ``=``).\n\n    :type value: integer, string, boolean, float, None, datetime\n    :param value: The value to filter on.\n\n    :rtype: :class:`Query`\n    :returns: A Query filtered by the expression and value provided.\n    \"\"\"\n    clone = self._clone()\n\n    # Take an expression like 'property >=', and parse it into useful pieces.\n    property_name, operator = None, None\n    expression = expression.strip()\n\n    for operator_string in self.OPERATORS:\n      if expression.endswith(operator_string):\n        operator = self.OPERATORS[operator_string]\n        property_name = expression[0:-len(operator_string)].strip()\n\n    if not operator or not property_name:\n      raise ValueError('Invalid expression: \"%s\"' % expression)\n\n    # Build a composite filter AND'd together.\n    composite_filter = clone._pb.filter.composite_filter\n    composite_filter.operator = datastore_pb.CompositeFilter.AND\n\n    # Add the specific filter\n    property_filter = composite_filter.filter.add().property_filter\n    property_filter.property.name = property_name\n    property_filter.operator = operator\n\n    # Set the value to filter on based on the type.\n    attr_name, pb_value = helpers.get_protobuf_attribute_and_value(value)\n    setattr(property_filter.value, attr_name, pb_value)\n    return clone\n\n  def kind(self, *kinds):\n    \"\"\"Get or set the Kind of the Query.\n\n    .. note::\n      This is an **additive** operation.\n      That is, if the Query is set for kinds A and B,\n      and you call ``.kind('C')``,\n      it will query for kinds A, B, *and*, C.\n\n    :type kinds: string\n    :param kinds: The entity kinds for which to query.\n\n    :rtype: string or :class:`Query`\n    :returns: If no arguments, returns the kind.\n              If a kind is provided, returns a clone of the :class:`Query`\n              with those kinds set.\n    \"\"\"\n    # TODO: Do we want this to be additive?\n    #       If not, clear the _pb.kind attribute.\n    if kinds:\n      clone = self._clone()\n      for kind in kinds:\n        clone._pb.kind.add().name = kind\n      return clone\n    else:\n      return self._pb.kind\n\n  def limit(self, limit=None):\n    \"\"\"Get or set the limit of the Query.\n\n    This is the maximum number of rows (Entities) to return for this Query.\n\n    This is a hybrid getter / setter, used as::\n\n      >>> query = Query('Person')\n      >>> query = query.limit(100)  # Set the limit to 100 rows.\n      >>> query.limit()  # Get the limit for this query.\n      100\n\n    :rtype: integer, None, or :class:`Query`\n    :returns: If no arguments, returns the current limit.\n              If a limit is provided, returns a clone of the :class:`Query`\n              with that limit set.\n    \"\"\"\n    if limit:\n      clone = self._clone()\n      clone._pb.limit = limit\n      return clone\n    else:\n      return self._pb.limit\n\n  def dataset(self, dataset=None):\n    \"\"\"Get or set the :class:`gcloud.datastore.dataset.Dataset` for this Query.\n\n    This is the dataset against which the Query will be run.\n\n    This is a hybrid getter / setter, used as::\n\n      >>> query = Query('Person')\n      >>> query = query.dataset(my_dataset)  # Set the dataset.\n      >>> query.dataset()  # Get the current dataset.\n      <Dataset object>\n\n    :rtype: :class:`gcloud.datastore.dataset.Dataset`, None, or :class:`Query`\n    :returns: If no arguments, returns the current dataset.\n              If a dataset is provided, returns a clone of the :class:`Query`\n              with that dataset set.\n    \"\"\"\n    if dataset:\n      clone = self._clone()\n      clone._dataset = dataset\n      return clone\n    else:\n      return self._dataset\n\n  def fetch(self, limit=None):\n    \"\"\"Executes the Query and returns all matching entities.\n\n    This makes an API call to the Cloud Datastore,\n    sends the Query as a protobuf,\n    parses the responses to Entity protobufs,\n    and then converts them to :class:`gcloud.datastore.entity.Entity` objects.\n\n    For example::\n\n      >>> from gcloud import datastore\n      >>> dataset = datastore.get_dataset('dataset-id', email, key_path)\n      >>> query = dataset.query('Person').filter('name =', 'Sally')\n      >>> query.fetch()\n      [<Entity object>, <Entity object>, ...]\n      >>> query.fetch(1)\n      [<Entity object>]\n      >>> query.limit()\n      None\n\n    :type limit: integer\n    :param limit: An optional limit to apply temporarily to this query.\n                  That is, the Query itself won't be altered,\n                  but the limit will be applied to the query\n                  before it is executed.\n\n    :rtype: list of :class:`gcloud.datastore.entity.Entity`'s\n    :returns: The list of entities matching this query's criteria.\n    \"\"\"\n    clone = self\n\n    if limit:\n      clone = self.limit(limit)\n\n    entity_pbs = self.dataset().connection().run_query(\n        query_pb=clone.to_protobuf(), dataset_id=self.dataset().id())\n\n    return [Entity.from_protobuf(entity) for entity in entity_pbs]\n", "path": "gcloud/datastore/query.py"}], "after_files": [{"content": "import copy\n\nfrom gcloud.datastore import datastore_v1_pb2 as datastore_pb\nfrom gcloud.datastore import helpers\nfrom gcloud.datastore.entity import Entity\n\n\n# TODO: Figure out how to properly handle namespaces.\n\nclass Query(object):\n  \"\"\"A Query against the Cloud Datastore.\n\n  This class serves as an abstraction for creating\n  a query over data stored in the Cloud Datastore.\n\n  Each :class:`Query` object is immutable,\n  and a clone is returned whenever\n  any part of the query is modified::\n\n    >>> query = Query('MyKind')\n    >>> limited_query = query.limit(10)\n    >>> query.limit() == 10\n    False\n    >>> limited_query.limit() == 10\n    True\n\n  You typically won't construct a :class:`Query`\n  by initializing it like ``Query('MyKind', dataset=...)``\n  but instead use the helper\n  :func:`gcloud.datastore.dataset.Dataset.query` method\n  which generates a query that can be executed\n  without any additional work::\n\n    >>> from gcloud import datastore\n    >>> dataset = datastore.get_dataset('dataset-id', email, key_path)\n    >>> query = dataset.query('MyKind')\n\n  :type kind: string\n  :param kind: The kind to query.\n\n  :type dataset: :class:`gcloud.datastore.dataset.Dataset`\n  :param dataset: The dataset to query.\n  \"\"\"\n\n  OPERATORS = {\n      '<': datastore_pb.PropertyFilter.LESS_THAN,\n      '<=': datastore_pb.PropertyFilter.LESS_THAN_OR_EQUAL,\n      '>': datastore_pb.PropertyFilter.GREATER_THAN,\n      '>=': datastore_pb.PropertyFilter.GREATER_THAN_OR_EQUAL,\n      '=': datastore_pb.PropertyFilter.EQUAL,\n      }\n  \"\"\"Mapping of operator strings and their protobuf equivalents.\"\"\"\n\n  def __init__(self, kind=None, dataset=None):\n    self._dataset = dataset\n    self._pb = datastore_pb.Query()\n\n    if kind:\n      self._pb.kind.add().name = kind\n\n  def _clone(self):\n    # TODO(jjg): Double check that this makes sense...\n    clone = copy.deepcopy(self)\n    clone._dataset = self._dataset  # Shallow copy the dataset.\n    return clone\n\n  def to_protobuf(self):\n    \"\"\"Convert the :class:`Query` instance to a :class:`gcloud.datastore.datastore_v1_pb2.Query`.\n\n    :rtype: :class:`gclouddatstore.datastore_v1_pb2.Query`\n    :returns: A Query protobuf that can be sent to the protobuf API.\n    \"\"\"\n    return self._pb\n\n  def filter(self, expression, value):\n    \"\"\"Filter the query based on an expression and a value.\n\n    This will return a clone of the current :class:`Query`\n    filtered by the expression and value provided.\n\n    Expressions take the form of::\n\n      .filter('<property> <operator>', <value>)\n\n    where property is a property stored on the entity in the datastore\n    and operator is one of ``OPERATORS``\n    (ie, ``=``, ``<``, ``<=``, ``>``, ``>=``)::\n\n      >>> query = Query('Person')\n      >>> filtered_query = query.filter('name =', 'James')\n      >>> filtered_query = query.filter('age >', 50)\n\n    Because each call to ``.filter()`` returns a cloned ``Query`` object\n    we are able to string these together::\n\n      >>> query = Query('Person').filter('name =', 'James').filter('age >', 50)\n\n    :type expression: string\n    :param expression: An expression of a property and an operator (ie, ``=``).\n\n    :type value: integer, string, boolean, float, None, datetime\n    :param value: The value to filter on.\n\n    :rtype: :class:`Query`\n    :returns: A Query filtered by the expression and value provided.\n    \"\"\"\n    clone = self._clone()\n\n    # Take an expression like 'property >=', and parse it into useful pieces.\n    property_name, operator = None, None\n    expression = expression.strip()\n\n    for operator_string in self.OPERATORS:\n      if expression.endswith(operator_string):\n        operator = self.OPERATORS[operator_string]\n        property_name = expression[0:-len(operator_string)].strip()\n\n    if not operator or not property_name:\n      raise ValueError('Invalid expression: \"%s\"' % expression)\n\n    # Build a composite filter AND'd together.\n    composite_filter = clone._pb.filter.composite_filter\n    composite_filter.operator = datastore_pb.CompositeFilter.AND\n\n    # Add the specific filter\n    property_filter = composite_filter.filter.add().property_filter\n    property_filter.property.name = property_name\n    property_filter.operator = operator\n\n    # Set the value to filter on based on the type.\n    attr_name, pb_value = helpers.get_protobuf_attribute_and_value(value)\n    setattr(property_filter.value, attr_name, pb_value)\n    return clone\n\n  def kind(self, *kinds):\n    \"\"\"Get or set the Kind of the Query.\n\n    .. note::\n      This is an **additive** operation.\n      That is, if the Query is set for kinds A and B,\n      and you call ``.kind('C')``,\n      it will query for kinds A, B, *and*, C.\n\n    :type kinds: string\n    :param kinds: The entity kinds for which to query.\n\n    :rtype: string or :class:`Query`\n    :returns: If no arguments, returns the kind.\n              If a kind is provided, returns a clone of the :class:`Query`\n              with those kinds set.\n    \"\"\"\n    # TODO: Do we want this to be additive?\n    #       If not, clear the _pb.kind attribute.\n    if kinds:\n      clone = self._clone()\n      for kind in kinds:\n        clone._pb.kind.add().name = kind\n      return clone\n    else:\n      return self._pb.kind\n\n  def limit(self, limit=None):\n    \"\"\"Get or set the limit of the Query.\n\n    This is the maximum number of rows (Entities) to return for this Query.\n\n    This is a hybrid getter / setter, used as::\n\n      >>> query = Query('Person')\n      >>> query = query.limit(100)  # Set the limit to 100 rows.\n      >>> query.limit()  # Get the limit for this query.\n      100\n\n    :rtype: integer, None, or :class:`Query`\n    :returns: If no arguments, returns the current limit.\n              If a limit is provided, returns a clone of the :class:`Query`\n              with that limit set.\n    \"\"\"\n    if limit:\n      clone = self._clone()\n      clone._pb.limit = limit\n      return clone\n    else:\n      return self._pb.limit\n\n  def dataset(self, dataset=None):\n    \"\"\"Get or set the :class:`gcloud.datastore.dataset.Dataset` for this Query.\n\n    This is the dataset against which the Query will be run.\n\n    This is a hybrid getter / setter, used as::\n\n      >>> query = Query('Person')\n      >>> query = query.dataset(my_dataset)  # Set the dataset.\n      >>> query.dataset()  # Get the current dataset.\n      <Dataset object>\n\n    :rtype: :class:`gcloud.datastore.dataset.Dataset`, None, or :class:`Query`\n    :returns: If no arguments, returns the current dataset.\n              If a dataset is provided, returns a clone of the :class:`Query`\n              with that dataset set.\n    \"\"\"\n    if dataset:\n      clone = self._clone()\n      clone._dataset = dataset\n      return clone\n    else:\n      return self._dataset\n\n  def fetch(self, limit=None):\n    \"\"\"Executes the Query and returns all matching entities.\n\n    This makes an API call to the Cloud Datastore,\n    sends the Query as a protobuf,\n    parses the responses to Entity protobufs,\n    and then converts them to :class:`gcloud.datastore.entity.Entity` objects.\n\n    For example::\n\n      >>> from gcloud import datastore\n      >>> dataset = datastore.get_dataset('dataset-id', email, key_path)\n      >>> query = dataset.query('Person').filter('name =', 'Sally')\n      >>> query.fetch()\n      [<Entity object>, <Entity object>, ...]\n      >>> query.fetch(1)\n      [<Entity object>]\n      >>> query.limit()\n      None\n\n    :type limit: integer\n    :param limit: An optional limit to apply temporarily to this query.\n                  That is, the Query itself won't be altered,\n                  but the limit will be applied to the query\n                  before it is executed.\n\n    :rtype: list of :class:`gcloud.datastore.entity.Entity`'s\n    :returns: The list of entities matching this query's criteria.\n    \"\"\"\n    clone = self\n\n    if limit:\n      clone = self.limit(limit)\n\n    entity_pbs = self.dataset().connection().run_query(\n        query_pb=clone.to_protobuf(), dataset_id=self.dataset().id())\n\n    return [Entity.from_protobuf(entity, dataset=self.dataset())\n            for entity in entity_pbs]\n", "path": "gcloud/datastore/query.py"}]}