Title: ProjectMergeRequest.save() discards _optional_get_attrs · Issue #2007 · python-gitlab/python-gitlab · GitHub
Open Graph Title: ProjectMergeRequest.save() discards _optional_get_attrs · Issue #2007 · python-gitlab/python-gitlab
X Title: ProjectMergeRequest.save() discards _optional_get_attrs · Issue #2007 · python-gitlab/python-gitlab
Description: 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 attribute...
Open Graph Description: 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 .sav...
X Description: 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 .sav...
Opengraph URL: https://github.com/python-gitlab/python-gitlab/issues/2007
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"ProjectMergeRequest.save() discards _optional_get_attrs","articleBody":"## Description of the problem, including code/CLI snippet\r\nWhen 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.\r\n\r\n## Expected Behavior\r\nThe optional key:value in the MR attribute data should be retained\r\n\r\n## Actual Behavior\r\nThe keys and values for these particular attributes are lost\r\n\r\n## Specifications\r\n\r\n - python-gitlab version:\r\n - 3.4.0 \r\n - API version you are using (v3/v4):\r\n - v4\r\n - Gitlab server version (or gitlab.com):\r\n - 13.12.10-ee\r\n\r\nHere is a patch to retain these attributes across the _.save()_ method. I'm working on a PR for this but _tox_ is blowing up.\r\n\r\n```diff\r\ndiff --git a/gitlab/mixins.py b/gitlab/mixins.py\r\nindex 1a3ff4d..1af1b2e 100644\r\n--- a/gitlab/mixins.py\r\n+++ b/gitlab/mixins.py\r\n@@ -548,11 +548,29 @@ class SaveMixin(_RestObjectBase):\r\n if not updated_data:\r\n return None\r\n \r\n+ # we need to save these attribute values across the .save() method\r\n+ # or they'll be lost. the user didn't ask us to reload the MR object\r\n+ # so be minimal in our actions\r\n+ save_across_update = {}\r\n+ for attr in self.manager._optional_get_attrs:\r\n+ find_attr = attr\r\n+ if find_attr.startswith(\"include_\"):\r\n+ find_attr = find_attr[8:]\r\n+ if find_attr in self._attrs:\r\n+ save_across_update[find_attr] = self._attrs[find_attr]\r\n+\r\n # call the manager\r\n obj_id = self.encoded_id\r\n if TYPE_CHECKING:\r\n assert isinstance(self.manager, UpdateMixin)\r\n server_data = self.manager.update(obj_id, updated_data, **kwargs)\r\n+\r\n+ # restore the optional requested attributes lost when we did the .save()\r\n+ # the gitlab REST API doesn't offer a way to request these attributes\r\n+ # during the POST operation thus we can't blindly overwrite our existing\r\n+ # data with the new data\r\n+ server_data.update(save_across_update)\r\n+\r\n self._update_attrs(server_data)\r\n return server_data\r\n\r\n```","author":{"url":"https://github.com/FirefighterBlu3","@type":"Person","name":"FirefighterBlu3"},"datePublished":"2022-05-05T13:41:21.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":6},"url":"https://github.com/2007/python-gitlab/issues/2007"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:3d649a8a-9af4-bc70-341d-8fb1bf492f0b |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8196:247705:3E4614:536DB2:6972F941 |
| html-safe-nonce | 116a0ce22eb96ff3e6febb8dfab35980e3cb315c027b31aca207564f18b353b1 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MTk2OjI0NzcwNTozRTQ2MTQ6NTM2REIyOjY5NzJGOTQxIiwidmlzaXRvcl9pZCI6IjI3MzIwNDQwMzYwODI5NTY2MDkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 72b8d6c367833b6f272b9a0c8479f723b25de55073c3ffdd3475aaabf6413096 |
| hovercard-subject-tag | issue:1226691926 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python-gitlab/python-gitlab/2007/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c84210411b7737a04a9b15a93d234aa5fc512a6619db8dfb13501a5b0cca0488/python-gitlab/python-gitlab/issues/2007 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c84210411b7737a04a9b15a93d234aa5fc512a6619db8dfb13501a5b0cca0488/python-gitlab/python-gitlab/issues/2007 |
| og:image:alt | 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 .sav... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | FirefighterBlu3 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 9946c12a4847916f32068429cb2ad536f7d8450fc8b70730d0e9aa7861057db8 |
| turbo-cache-control | no-preview |
| go-import | github.com/python-gitlab/python-gitlab git https://github.com/python-gitlab/python-gitlab.git |
| octolytics-dimension-user_id | 28886265 |
| octolytics-dimension-user_login | python-gitlab |
| octolytics-dimension-repository_id | 8077625 |
| octolytics-dimension-repository_nwo | python-gitlab/python-gitlab |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 8077625 |
| octolytics-dimension-repository_network_root_nwo | python-gitlab/python-gitlab |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | f92f1208f12997e73ccb28d2f389b2adab0c98a3 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width