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 — Storage: bucket.labels surprisingly returns a deepcopy · Issue #3710 · googleapis/google-cloud-python

Storage: bucket.labels surprisingly returns a deepcopy #3710

New issue
Copy link
New issue
Copy link
Closed
Closed
Storage: bucket.labels surprisingly returns a deepcopy#3710
Copy link
Assignees
tseaver
Labels
api: storageIssues related to the Cloud Storage API.

Description

@theacodes
theacodes
opened on Aug 1, 2017
Issue body actions

I expected this to work:

    bucket = storage_client.get_bucket(bucket_name)
    bucket.labels['example'] = 'label'
    bucket.patch()

Turns out bucket.labels returns a deepcopy, so I have to do this instead:

    bucket = storage_client.get_bucket(bucket_name)
    labels = bucket.labels
    labels['example'] = 'label'
    bucket.labels = labels
    bucket.patch()

Activity

  1. theacodes
    added
    api: storageIssues related to the Cloud Storage API.
    DevEx
    on Aug 1, 2017
  2. dhermes commented on Aug 1, 2017

    @dhermes
    dhermes
    on Aug 1, 2017
    Contributor
    More actions

    I'm not sure what the right move is. There are definitely pros and cons here, i.e. I can imagine a user surprised they mutated the Bucket when they didn't intend to.

  3. theacodes commented on Aug 1, 2017

    @theacodes
    theacodes
    on Aug 1, 2017
    ContributorAuthor
    More actions

    Yeah I agree. Could we at least document it better? The docstring for labels is actually totally wrong: https://google-cloud-python.readthedocs.io/en/latest/storage/buckets.html#google.cloud.storage.bucket.Bucket.labels

  4. dhermes
    added
    docs
    on Aug 1, 2017
  5. dhermes commented on Aug 1, 2017

    @dhermes
    dhermes
    on Aug 1, 2017
    Contributor
    More actions

    Copy-pasta strikes again!

  6. tseaver
    self-assigned this
    on Aug 1, 2017
  7. tseaver commented on Aug 1, 2017

    @tseaver
    tseaver
    on Aug 1, 2017
    Contributor
    More actions

    The other properties which contain non-scalar values (cors, lifecycle_rules) also return copies. I'm working on a PR which adds the following note (modified to use values appropriate to each one):

            .. note::
    
               The getter for this property returns a list which contains 
               *copies* of the bucket's CORS policy mappings.  Mutating the list
               or one of its dicts has no effect unless you then re-assign the
               dict via the setter.  E.g.:
    
               >>> cors = bucket.cors
               >>> cors.append({'origin': '/foo', ...})
               >>> del policies[0]
               >>> bucket.cors = cors
  8. tseaver
    closed this as completedin #3712on Aug 1, 2017
  9. tseaver
    added a commit that references this issue on Aug 1, 2017

    Document deepcopy semantics of complex bucket properties. (#3712)

    This issue will close once commit ac23b77 is merged into the 'main' branch.
    ac23b77
  10. landrito
    added 3 commits that reference this issue on Aug 21, 2017

    Document deepcopy semantics of complex bucket properties. (googleapis…

    This issue will close once commit ee66cab is merged into the 'master' branch.
    ee66cab

    Document deepcopy semantics of complex bucket properties. (googleapis…

    This issue will close once commit fbc3a57 is merged into the 'master' branch.
    fbc3a57

    Document deepcopy semantics of complex bucket properties. (googleapis…

    This issue will close once commit 24c5554 is merged into the 'master' branch.
    24c5554
  11. parthea
    added a commit that references this issue on Jun 4, 2023

    chore: move samples from python-docs-sample to here (#29)

    This issue will close once commit 8d9e265 is merged into the 'main' branch.
    8d9e265
  12. parthea
    added a commit that references this issue on Mar 9, 2026

    Document deepcopy semantics of complex bucket properties. (#3712)

    This issue will close once commit e2974a8 is merged into the 'main' branch.
    e2974a8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @tseaver
    tseaver

Labels

api: storageIssues related to the Cloud Storage API.

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.