Skip to content

Objects lose their custom_attributes during a save() #1395

Closed
@deveaud-m

Description

@deveaud-m

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

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