FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Objects lose their custom_attributes during a save() · Issue #1395 · python-gitlab/python-gitlab · GitHub

Repository navigation

Objects lose their custom_attributes during a save() #1395

Description

Description of the problem, including code/CLI snippet

When saving an object (e.g. User) with custom_attributes, those attributes get lost an the object needs to be synced again to recover all needed attributes:

import gitlab

gl = gitlab.Gitlab(...)
bob = gl.users.get(42, with_custom_attributes=True)
print(bob.custom_attributes)
bob.save()
print(bob.custom_attributes)

This raises AttributeError:

Traceback (most recent call last):
  File ".../lib/python3.9/site-packages/gitlab/base.py", line 59, in __getattr__
    return self.__dict__["_updated_attrs"][name]
KeyError: 'custom_attributes'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File ".../lib/python3.9/site-packages/gitlab/base.py", line 62, in __getattr__
    value = self.__dict__["_attrs"][name]
KeyError: 'custom_attributes'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File ".../lib/python3.9/site-packages/gitlab/base.py", line 82, in __getattr__
    return self.__dict__["_parent_attrs"][name]
KeyError: 'custom_attributes'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File ".../attr_test.py", line 8, in <module>
    print(f"Bob after {json.dumps(bob.custom_attributes, indent=4)}")
  File ".../lib/python3.9/site-packages/gitlab/base.py", line 84, in __getattr__
    raise AttributeError(name)
AttributeError: custom_attributes

Expected Behavior

Restore objects' custom_attributes after calling save().
This can be reproduced with Projects and Groups.

Actual Behavior

The objects must be synced again with the option with_custom_attributes=True to access custom_attributes.

Specifications

  • python-gitlab version: 2.6.0
  • API version you are using (v3/v4): v4
  • Gitlab server version (or gitlab.com): 13.10.1

Activity

  1. nejch commented on Apr 13, 2021

    Member

    Thanks @deveaud-m! Note to self:

    • for save()/update() methods the new server data alone shouldn't be used as it will mostly be just a subset of what's returned via GET.
    • for refresh(), the arguments used for the original get() should maybe be stored in the object and reused for subsequent GET requests or there will be missing attributes again.

    A similar example is here with save and sudo: #532

  2. max-wittig commented on Apr 25, 2021

    Member

    Not sure, if this is a "bug" that we can fix. We're just retrieving the info that GitLab sends. I don't think we should change that behavior.

  3. nejch commented on May 2, 2021

    Member

    Not sure, if this is a "bug" that we can fix. We're just retrieving the info that GitLab sends. I don't think we should change that behavior.

    That's true, just that in a way #1213 was a breaking change in behavior from pre-2.6.0 🤔 and can be confusing for users maybe, the way it works.

    I'm thinking an extra arg here would help cover both @deveaud-m's use case for save() and @ericfrederich's original idea for refresh() in #1155.

    I've got #1443 as an initial lightweight approach without refactoring RESTObjects too much, @deveaud-m would this cover your issue or is it still too verbose?
    Reverting this entirely would bring back the previous issue with refresh.

  4. changed the title [-]Objects loose their custom_attributes during a save()[/-] [+]Objects lose their custom_attributes during a save()[/+] on May 2, 2021
  5. deveaud-m commented on May 3, 2021

    Author

    I've got #1443 as an initial lightweight approach without refactoring RESTObjects too much, @deveaud-m would this cover your issue or is it still too verbose?
    Reverting this entirely would bring back the previous issue with refresh.

    I'm ok with this change, at least it would be stated in the documentation that objects can loose their attributes while being refreshed or saved. Users then have the choice between using the "verbose" argument to persist attributes or get a new object using the API (in case concurrent accesses to that object would have been performed on the server side).

  6. locked as resolved and limited conversation to collaborators on May 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL