Skip to content

Exception Value: api_request() got an unexpected keyword argument 'extra_api_info' #831

Closed
@RomainFayolle

Description

@RomainFayolle

Hi,

I'm having an issue on google-cloud-storage 2.3.0, I also tried it with 2.5.0. I use Django and I have a file model that is linked to GCS. When getting the size of the file I have an error: Exception Value: api_request() got an unexpected keyword argument 'extra_api_info'
I fixed the issue by downgrading google-cloud-storage to 1.44.0 as suggested in this stack overflow issue

Environment details

  • OS: Ubuntu 20.04.2 LTS
  • Python version: 3.8.10
  • pip version: 19.0.3
  • google-cloud-storage version: 2.3.0 and 2.5.0
  • Django: 3.2.13
  • Django Rest Framework: 3.13.1

Steps to reproduce

  1. Create a Django model
  2. Set a size @Property
  3. Try to get the size property

Code example

class MyFileClass(models.Model):
    file = models.FileField(
        verbose_name=_('File'),
        upload_to='path_to_upload',
        null=False
    )

    @property
    def size(self):
        return self.file.size if self.file else None

Stack trace

Traceback (most recent call last):
  File "/home/ubuntu/my_project/ve/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/home/ubuntu/my_project/ve/lib/python3.8/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/ubuntu/my_project/ve/lib/python3.8/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "/home/ubuntu/my_project/ve/lib/python3.8/site-packages/rest_framework/viewsets.py", line 125, in view
    return self.dispatch(request, *args, **kwargs)
  File "/home/ubuntu/my_project/ve/lib/python3.8/site-packages/rest_framework/views.py", line 509, in dispatch
    response = self.handle_exception(exc)
  File "/home/ubuntu/my_project/ve/lib/python3.8/site-packages/rest_framework/views.py", line 469, in handle_exception
    self.raise_uncaught_exception(exc)
  File "/home/ubuntu/my_project/ve/lib/python3.8/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception
    raise exc
  File "/home/ubuntu/my_project/ve/lib/python3.8/site-packages/rest_framework/views.py", line 506, in dispatch
    response = handler(request, *args, **kwargs)
  File "/home/ubuntu/my_project/ve/lib/python3.8/site-packages/rest_framework/mixins.py", line 43, in list
    return self.get_paginated_response(serializer.data)
  File "/home/ubuntu/my_project/ve/lib/python3.8/site-packages/rest_framework/serializers.py", line 768, in data
    ret = super().data
  File "/home/ubuntu/my_project/ve/lib/python3.8/site-packages/rest_framework/serializers.py", line 253, in data
    self._data = self.to_representation(self.instance)
  File "/home/ubuntu/my_project/ve/lib/python3.8/site-packages/rest_framework/serializers.py", line 686, in to_representation
    return [
  File "/home/ubuntu/my_project/ve/lib/python3.8/site-packages/rest_framework/serializers.py", line 687, in <listcomp>
    self.child.to_representation(item) for item in iterable
  File "/home/ubuntu/my_project/my_app/serializers.py", line 65, in to_representation
    return super().to_representation(instance)
  File "/home/ubuntu/my_project/ve/lib/python3.8/site-packages/rest_framework/serializers.py", line 509, in to_representation
    attribute = field.get_attribute(instance)
  File "/home/ubuntu/my_project/ve/lib/python3.8/site-packages/rest_framework/fields.py", line 457, in get_attribute
    return get_attribute(instance, self.source_attrs)
  File "/home/ubuntu/my_project/ve/lib/python3.8/site-packages/rest_framework/fields.py", line 97, in get_attribute
    instance = getattr(instance, attr)
  File "/home/ubuntu/my_project/my_app/models.py", line 181, in size
    return self.file.size if self.file else None
  File "/home/ubuntu/my_project/ve/lib/python3.8/site-packages/django/db/models/fields/files.py", line 71, in size
    return self.storage.size(self.name)
  File "/home/ubuntu/my_project/ve/lib/python3.8/site-packages/storages/backends/gcloud.py", line 246, in size
    blob = self._get_blob(name)
  File "/home/ubuntu/my_project/ve/lib/python3.8/site-packages/storages/backends/gcloud.py", line 237, in _get_blob
    blob = self.bucket.get_blob(name)
  File "/home/ubuntu/my_project/ve/lib/python3.8/site-packages/google/cloud/storage/bucket.py", line 1218, in get_blob
    blob.reload(
  File "/home/ubuntu/my_project/ve/lib/python3.8/site-packages/google/cloud/storage/_helpers.py", line 238, in reload
    api_response = client._get_resource(
  File "/home/ubuntu/my_project/ve/lib/python3.8/site-packages/google/cloud/storage/client.py", line 366, in _get_resource
    return self._connection.api_request(
  File "/home/ubuntu/my_project/ve/lib/python3.8/site-packages/google/cloud/storage/_http.py", line 73, in api_request
    return call()
  File "/home/ubuntu/my_project/ve/lib/python3.8/site-packages/google/api_core/retry.py", line 286, in retry_wrapped_func
    return retry_target(
  File "/home/ubuntu/my_project/ve/lib/python3.8/site-packages/google/api_core/retry.py", line 189, in retry_target
    return target()

Exception Type: TypeError at /my_view
Exception Value: api_request() got an unexpected keyword argument 'extra_api_info'

Everything is done under the hood, I'm not using api_request() myself. Django is when trying to get the size parameter of my file by using google-cloud-storage.
CC @RignonNoel

Metadata

Metadata

Assignees

Labels

api: storageIssues related to the googleapis/python-storage API.priority: p2Moderately-important priority. Fix may not be included in next release.type: questionRequest for information or clarification. Not an issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions