Skip to content

Commit

Permalink
fix(Datastore):Properly remove redundant keys from request options
Browse files Browse the repository at this point in the history
  • Loading branch information
yash30201 authored May 7, 2024
2 parents 14fc795 + b9f0661 commit c6275bd
Showing 1 changed file with 27 additions and 21 deletions.
48 changes: 27 additions & 21 deletions Datastore/src/Operation.php
Original file line number Diff line number Diff line change
Expand Up @@ -454,19 +454,19 @@ public function lookup(array $keys, array $options = [])
$serviceKeys[] = $key->keyObject();
});

list($data, $optionalArgs) = $this->splitOptionalArgs($options, [
'transaction',
'className',
'sort',
'readTime',
'readConsistency'
]);
list($data, $optionalArgs) = $this->splitOptionalArgs($options);
$data += $this->readOptions($options) + [
'projectId' => $this->projectId,
'databaseId' => $this->databaseId,
'keys' => $this->keysList($serviceKeys),
];

// Remove redundant keys for request.
$this->pluckArray(
['transaction', 'className', 'sort', 'readTime', 'readConsistency'],
$data
);

$request = $this->serializer->decodeMessage(new LookupRequest(), $data);

$res = $this->requestHandler->sendRequest(
Expand Down Expand Up @@ -585,13 +585,14 @@ public function runQuery(QueryInterface $query, array $options = [])
$runQueryObj->queryKey() => $requestQueryArr,
] + $this->readOptions($options) + $options;

list($data, $optionalArgs) = $this->splitOptionalArgs($req, [
'className',
'namespaceId',
'readTime',
'readConsistency',
'transaction'
]);
list($data, $optionalArgs) = $this->splitOptionalArgs($req);

// Remove redundant keys for request.
$this->pluckArray(
['className', 'namespaceId', 'readTime', 'readConsistency', 'transaction'],
$data
);

if (isset($data['query'])) {
$data['query'] = $this->parseQuery($data['query']);
}
Expand Down Expand Up @@ -679,12 +680,13 @@ public function runAggregationQuery(AggregationQuery $runQueryObj, array $option
),
] + $requestQueryArr + $this->readOptions($options) + $options;

list($data, $optionalArgs) = $this->splitOptionalArgs($req, [
'namespaceId',
'readTime',
'readConsistency',
'transaction'
]);
list($data, $optionalArgs) = $this->splitOptionalArgs($req);

// Remove redundant keys for request.
$this->pluckArray(
['namespaceId', 'readTime', 'readConsistency', 'transaction'],
$data
);

if (isset($data['aggregationQuery'])) {
if (isset($data['aggregationQuery']['nestedQuery'])) {
Expand Down Expand Up @@ -764,7 +766,11 @@ public function commit(array $mutations, array $options = [])
// Remove 'transaction' if set to `null` to avoid serialization error
unset($options['transaction']);
}
list($data, $optionalArgs) = $this->splitOptionalArgs($options, ['allowOverwrite', 'baseVersion']);
list($data, $optionalArgs) = $this->splitOptionalArgs($options);

// Remove redundant keys for request.
$this->pluckArray(['allowOverwrite', 'baseVersion'], $data);

$request = $this->serializer->decodeMessage(new CommitRequest(), $data);
$res = $this->requestHandler->sendRequest(
DatastoreClient::class,
Expand Down

0 comments on commit c6275bd

Please sign in to comment.