← Winnitude! Search  ·  Reader Mode (1075 ms)
Links: Stay in Reader Retro Site Converter Retro Mode: OFF Original Page ↗
GITHUB · 10 LINKS

ProjectMergeRequest.save() discards _optional_get_attrs · Issue #2007 · python-gitlab/python-gitlab

Repository navigation

ProjectMergeRequest.save() discards _optional_get_attrs  #2007


New issue

New issue

Open

Open
ProjectMergeRequest.save() discards _optional_get_attrs #2007 Assignees nejch is assigned Labels
meta

Description

@FirefighterBlu3's profile FirefighterBlu3 opened on May 5, 2022

Description of the problem, including code/CLI snippet

When we request the MR object we can specify extra attributes to be returned to us. Once instantiated if we update part of the object and .save() it, our object loses these attributes.

Expected Behavior

The optional key:value in the MR attribute data should be retained

Actual Behavior

The keys and values for these particular attributes are lost

Specifications

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

Here is a patch to retain these attributes across the .save() method. I'm working on a PR for this but tox is blowing up.

diff --git a/gitlab/mixins.py b/gitlab/mixins.py
index 1a3ff4d..1af1b2e 100644
--- a/gitlab/mixins.py
+++ b/gitlab/mixins.py
@@ -548,11 +548,29 @@ class SaveMixin(_RestObjectBase):
         if not updated_data:
             return None
 
+        # we need to save these attribute values across the .save() method
+        # or they'll be lost. the user didn't ask us to reload the MR object
+        # so be minimal in our actions
+        save_across_update = {}
+        for attr in self.manager._optional_get_attrs:
+            find_attr = attr
+            if find_attr.startswith("include_"):
+                find_attr = find_attr[8:]
+            if find_attr in self._attrs:
+                save_across_update[find_attr] = self._attrs[find_attr]
+
         # call the manager
         obj_id = self.encoded_id
         if TYPE_CHECKING:
             assert isinstance(self.manager, UpdateMixin)
         server_data = self.manager.update(obj_id, updated_data, **kwargs)
+
+        # restore the optional requested attributes lost when we did the .save()
+        # the gitlab REST API doesn't offer a way to request these attributes
+        # during the POST operation thus we can't blindly overwrite our existing
+        # data with the new data
+        server_data.update(save_across_update)
+
         self._update_attrs(server_data)
         return server_data

Metadata

Metadata

Assignees

Labels


meta

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions