You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Objects lose their custom_attributes during a save() #1395
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:
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.
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
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.
changed the title [-]Objects loose their custom_attributes during a save()[/-][+]Objects lose their custom_attributes during a save()[/+]on May 2, 2021
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).
Activity
nejch commentedon Apr 13, 2021
Thanks @deveaud-m! Note to self:
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.refresh(), the arguments used for the originalget()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
max-wittig commentedon Apr 25, 2021
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.
nejch commentedon May 2, 2021
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 forrefresh()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.
[-]Objects loose their custom_attributes during a save()[/-][+]Objects lose their custom_attributes during a save()[/+]deveaud-m commentedon May 3, 2021
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).