GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Google cloud python API returns None for blob.owner attribute · Issue #136 · googleapis/python-storage

This repository was archived by the owner on Mar 31, 2026. It is now read-only.
This repository was archived by the owner on Mar 31, 2026. It is now read-only.

Google cloud python API returns None for blob.owner attribute #136

Copy link
Copy link
Closed
#146
Closed
Google cloud python API returns None for blob.owner attribute#136
#146
Copy link
Assignees
HemangChothani
Labels
api: storageIssues related to the googleapis/python-storage API.priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Description

@jorvis
jorvis
opened on May 6, 2020
Issue body actions

I have created a Google bucket with "Fine-grained access control" and a few users have uploaded files to it. Using the python API I can't seem to get any information on who uploaded each. The blob.owner property just returns None:

sclient = storage.Client(project=GCLOUD_PROJECT)
bucket = storage.bucket.Bucket(client=sclient, name=GCLOUD_BUCKET)
blob = bucket.get_blob('foo.bar')
blob.reload()
print(blob.owner)

I'm calling reload() there because the documentation states it's required to pull some attributes from the server. All other properties I try print fine (size, updated, etag, md5_hash, etc.).

How can I recover the uploader identification?

Environment details

  • OS type and version: Ubuntu 18.04
  • Python version: 3.7.0
  • pip version: 18.1
  • google-cloud-storage version: 1.20.0

Steps to reproduce

  1. Place file in google bucket
  2. Attempt to use API to get owner information from the blob

Code example

    bucket = storage.bucket.Bucket(client=sclient, name=GCLOUD_BUCKET)
    blob = bucket.get_blob('foo.bar')
    blob.reload()
    print(blob.owner)

Stack trace

Doesn't error - just returns None

Activity

  1. product-auto-label
    added
    api: storageIssues related to the googleapis/python-storage API.
    on May 6, 2020
  2. jorvis commented on May 6, 2020

    @jorvis
    jorvis
    on May 6, 2020
    Author
    More actions

    As a note, I put this on StackOverflow first and another user verified the same problem.

    https://stackoverflow.com/questions/61466801/google-cloud-python-api-returns-none-for-blob-owner-attribute?noredirect=1#comment109019518_61466801

  3. HemangChothani commented on May 7, 2020

    @HemangChothani
    HemangChothani
    on May 7, 2020
    Contributor
    More actions

    @jorvis As i found in the documentation here, first you need to set the owner locally and then you can retrieve it.

    Sample:

    OWNER = {"entity": "project-owner-12345", "entityId": "23456"}
    properties = {"owner": OWNER}
    blob._properties.update(properties)
    blob.patch()
    print (blob.owner)
    

    Else other info about blob you can found through acl.

    print (list(blob.acl))
    
  4. yoshi-automation
    added
    triage meI really want to be triaged.
    on May 7, 2020
  5. jorvis commented on May 7, 2020

    @jorvis
    jorvis
    on May 7, 2020
    Author
    More actions

    So if you have 10 people on a gcloud project and each of them can upload to the bucket, there's no way to find out who uploaded to the bucket unless each of them did these steps to set their own owner IDs?

  6. HemangChothani commented on May 8, 2020

    @HemangChothani
    HemangChothani
    on May 8, 2020
    Contributor
    More actions

    Pulling in @frankyn who know more and better about this. Could you please comment on this?

  7. HemangChothani
    added
    type: questionRequest for information or clarification. Not an issue.
    and removed
    triage meI really want to be triaged.
    on May 11, 2020
  8. frankyn
    added
    type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
    and removed
    type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
    on May 13, 2020
  9. frankyn commented on May 13, 2020

    @frankyn
    frankyn
    on May 13, 2020
    Contributor
    More actions

    Hi @jorvis,

    Per documentation: https://cloud.google.com/storage/docs/access-control/lists#defaultobjects

    If you make an authenticated request to upload an object and do not specify any object ACLs when you upload it, then you are listed as the owner of the object and the predefined projectPrivate ACL is applied to the object by default. This means:
    
    You (the person who uploaded the object) are listed as the object owner. Object ownership cannot be changed by modifying ACLs. You can change object ownership only by overwriting an object.
    
    You (the object owner) are granted OWNER permission on the object. If you attempt to give less than OWNER permission to the owner, Cloud Storage automatically escalates the permission to OWNER.
    
    The project owners and project editors group have OWNER permission on the object.
    
    The project team members group has READER permission on the object.
    

    Took me a little while to figure out what was going wrong, thank you for your patience.

    The issue is owner is only populated when projection=full but by default Blob.reload() uses projection=noAcl therefore owner is not populated. In order to fix this, the library should add a parameter for projection on Blob.reload(). @HemangChothani could you take a look at this?

    A workaround for this is to use:

    from google.cloud import storage
    import time
    
    client = storage.Client()
    
    bucket = client.get_bucket("bucket-name")
    print(bucket.iam_configuration.uniform_bucket_level_access_enabled)
    blob = bucket.blob("assets/test.mp4")
    blob.patch() # nothing is updated but uses `projection=full`
    print(blob.owner)
    Reacted by Héctor Otero Mediero and saorio
  10. frankyn
    added
    type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
    and removed
    type: questionRequest for information or clarification. Not an issue.
    on May 13, 2020
  11. frankyn
    assigned
    HemangChothani
    on May 13, 2020
  12. frankyn
    added
    priority: p2Moderately-important priority. Fix may not be included in next release.
    on May 13, 2020
  13. frankyn
    closed this as completedin #146on May 15, 2020
  14. jorvis commented on May 15, 2020

    @jorvis
    jorvis
    on May 15, 2020
    Author
    More actions

    Thanks all!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @HemangChothani
    HemangChothani

Labels

api: storageIssues related to the googleapis/python-storage API.priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.