shikharateverest / google-api-python-client

Automatically exported from code.google.com/p/google-api-python-client
Other
0 stars 0 forks source link

.execute() function returns value response of previous query. #277

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi,

I use python oauth2client for accessing Google Analytics Core Query Services, 
Google Drive API.

Not 100% reproducible in all cases.

What steps will reproduce the problem?
1.
file = service.files().copy(fileId=fileId,  pinned =    True,   body=body).execute()
perm = service.permissions().insert(fileId= file['id'], 
body=new_permission).execute()

2. when both statements executed multiple times in same transaction, the value 
file will be perm of previous execution.

3. More details at the end.

The execution of files().copy should give a file feed.
Instead it gives a permissions feed for files().copy

Log:
Mime type is : Google Spreadsheets
URL being requested: 
https://www.googleapis.com/drive/v2/files/0ArLMC-iWfQNCdDNGX01XS3REVWVkUk5Gc05QN
lIyemc/copy?pinned=true&alt=json
Return:{u'kind': u'drive#permission', u'etag': u'""', u'role': u'reader', 
u'type': u'anyone', u'id': u'anyone', u'selfLink': 
u'https://www.googleapis.com/drive/v2/files/1TlSv13fjr8yJQCXLAvrasGQh7oq0mqhWI2t
yLCqtEy4/permissions/anyone'}

Following Query based on above result:
URL being requested: 
https://www.googleapis.com/drive/v2/files/anyone/permissions?alt=json
An error occurred: <HttpError 404 when requesting 
https://www.googleapis.com/drive/v2/files/anyone/permissions?alt=json returned 
"File not found: anyone">

code branch revision 588 from 
https://code.google.com/p/google-api-python-client/ on Google Appengine

I clearly observed that when we a set of analytics queries in sequence, in some 
cases we observe "query3 returns value of query2" or "query2 returns value of 
query1". This use not happen very often.

We updated the api-python-client with latest code from repository and when we 
are doing a bulk test on with drive api, we observed similar kind of issue but 
this time its very often. 

The new drive API case is, we copy a file(Q1) and then add permissions to 
it(Q2). we create 4 docs(one a type: docs, Drawing, presentation, sheets) in 
one transaction with for loop. Once we do Q1, Q2 for presentation, when check 
the log response of Q1(copy doc) for sheets, .execute() command returns the 
value of Q2(add permissions) of presentation. So considering the response from 
Q1 is appropriate, when we execute Q2 for sheet based on its response from Q1, 
it will raise and exception.

Any one facing similar problems! or is there any solution for this. 

Original issue reported on code.google.com by sande...@g.advaiya.com on 11 Jun 2013 at 6:17

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
This is really hard to debug without the code that makes these "executed 
multiple times in same transaction"

Original comment by dhermes@google.com on 11 Jun 2013 at 4:21

GoogleCodeExporter commented 9 years ago
by transaction, I mean to state about single app engine request having multiple 
execute() calls, and no two requests are same.

this is a sample code:
baseFileKeys = 
{'presntation':<fileid>,'doc':<fileid>,'sheet':<fileId>,'drawing':<fileId>}
for key in baseFileKeys:
  fileId = baseFileKeys[key]
  file = service.files().copy(fileId=fileId,    pinned =    True,   body=body).execute()
  perm = service.permissions().insert(fileId= file['id'], body=new_permission).execute()

# after 3 iterations 
Mime type is : sheet
URL being requested: 
https://www.googleapis.com/drive/v2/files/0ArLMC-iWfQNCdDNGX01XS3REVWVkUk5Gc05QN
lIyemc/copy?pinned=true&alt=json
file has the following value~= Return:{u'kind': u'drive#permission', u'etag': 
u'""', u'role': u'reader', u'type': u'anyone', u'id': u'anyone', u'selfLink': 
u'https://www.googleapis.com/drive/v2/files/1TlSv13fjr8yJQCXLAvrasGQh7oq0mqhWI2t
yLCqtEy4/permissions/anyone'}

Following Query based on above result:
URL being requested: 
https://www.googleapis.com/drive/v2/files/anyone/permissions?alt=json
An error occurred: <HttpError 404 when requesting 
https://www.googleapis.com/drive/v2/files/anyone/permissions?alt=json returned 
"File not found: anyone">

Original comment by sande...@g.advaiya.com on 11 Jun 2013 at 4:35

GoogleCodeExporter commented 9 years ago
It's still very unclear, sorry.

Original comment by dhermes@google.com on 11 Jun 2013 at 10:03

GoogleCodeExporter commented 9 years ago
Below I am stated the functions that are run in sequence, illustrated the issue 
and response after each query.

#Q1
-------------------------------------------------------
file = 
service.files().copy(fileId="https://www.googleapis.com/drive/v2/files/0ArLMC-iW
fQNCdDNGX01XS3REVWVkUk5Gc05QNlIyemc/copy?pinned=true&alt=json",pinned 
=True,  body=body).execute()
URL being requested: 
https://www.googleapis.com/drive/v2/files/0ArLMC-iWfQNCdDNGX01XS3REVWVkUk5Gc05QN
lIyemc/copy?pinned=true&alt=json

#success #expected, 
Response for above execution: 
{u'mimeType': u'application/vnd.google-apps.document','id':'<new file ID>', 
u'appDataContents': False, u'labels': {u'restricted': False, u'starred': 
False,......................................

#Q2
-------------------------------------------------------
perm = service.permissions().insert(fileId= file['id'], 
body=new_permission).execute()

#success #expected, 
Response for above excution: 
{u'kind': u'drive#permission', u'etag': u'""', u'role': u'reader', u'type': 
u'anyone', u'id': u'anyone', u'selfLink': 
u'https://www.googleapis.com/drive/v2/files/1TlSv13fjr8yJQCXLAvrasGQh7oq0mqhWI2t
yLCqtEy4/permissions/anyone'}

#Q3: here raised the problem, but not 100% error every-time, .
-------------------------------------------------------
file = 
service.files().copy(fileId="https://www.googleapis.com/drive/v2/files/0ArLMC-iW
fQNCdDNGX01XS3REVWVkUk5Gc05QNlIyemc/copy?pinned=true&alt=json",pinned 
=True,  body=body).execute()
URL being requested: 
https://www.googleapis.com/drive/v2/files/0ArLMC-iWfQNCdDNGX01XS3REVWVkUk5Gc05QN
lIyemc/copy?pinned=true&alt=json

#invalid Return, 
Expecting a response like #Q1 but response for above execution is same of #Q2: 
{u'kind': u'drive#permission', u'etag': u'""', u'role': u'reader', u'type': 
u'anyone', u'id': u'anyone', u'selfLink': 
u'https://www.googleapis.com/drive/v2/files/1TlSv13fjr8yJQCXLAvrasGQh7oq0mqhWI2t
yLCqtEy4/permissions/anyone'}

#Q4 Here now from above response file['id'] would be 'anyone', but we have to 
pass a <doc Id> to grant permission
-------------------------------------------------------
perm = service.permissions().insert(fileId= file['id'], 
body=new_permission).execute()
URL being requested: 
https://www.googleapis.com/drive/v2/files/anyone/permissions?alt=json

An error follows : <HttpError 404 when requesting 
https://www.googleapis.com/drive/v2/files/anyone/permissions?alt=json returned 
"File not found: anyone">

rest breaks because of above error.
#Q5: copy 3 pending
#Q6: permissions to file created in Q5
#Q7: copy 4 pending
#Q8: permissions to file created in Q7

Original comment by sande...@g.advaiya.com on 12 Jun 2013 at 10:36

GoogleCodeExporter commented 9 years ago
Are you using mutable variables in more than one place?

Does 
fileId="https://www.googleapis.com/drive/v2/files/0ArLMC-iWfQNCdDNGX01XS3REVWVkU
k5Gc05QNlIyemc/copy?pinned=true&alt=json" actually work? Shouldn't it be 
fileId="0ArLMC-iWfQNCdDNGX01XS3REVWVkUk5Gc05QNlIyemc"?

Original comment by dhermes@google.com on 12 Jun 2013 at 5:18

GoogleCodeExporter commented 9 years ago
sorry,,, ya it should be fileId="0ArLMC-iWfQNCdDNGX01XS3REVWVkUk5Gc05QNlIyemc"..
I Just replaced the a variable in code with the url, My intension is to 
illustrate we are passing file ID here.
apart from that rest is as mentioned above...

Original comment by sande...@g.advaiya.com on 12 Jun 2013 at 6:02

GoogleCodeExporter commented 9 years ago
Is this an outstanding issue?

Original comment by jcgregorio@google.com on 5 Aug 2013 at 2:00