Skip to content

Update and fix variable _create_attrs and _update_attrs#3379

Merged
JohnVillalovos merged 5 commits intopython-gitlab:mainfrom
PhilipNelson5:fix-var-attrs
Apr 20, 2026
Merged

Update and fix variable _create_attrs and _update_attrs#3379
JohnVillalovos merged 5 commits intopython-gitlab:mainfrom
PhilipNelson5:fix-var-attrs

Conversation

@PhilipNelson5
Copy link
Copy Markdown
Contributor

@PhilipNelson5 PhilipNelson5 commented Mar 26, 2026

Changes

  1. make value an optional attribute for variable updates

    When updating a CI/CD variable that has been marked "Masked and hidden", you likely do not have the value when updating. In this case, the value is None which the api rejects (400: {'value': ['is invalid']}).

  2. add masked_and_hidden the the list of optional attributes for creating variables

    When creating variables which you want to be hidden, you have to use the masked_and_hidden property.

    I don't think this was causing problems but for the sake completion and documentation I think it makes sense to include.

Documentation and testing

Please consider whether this PR needs documentation and tests. This is not required, but highly appreciated:

@PhilipNelson5
Copy link
Copy Markdown
Contributor Author

I tried running the suite of functional tests but was unable to. I got the docker containers up but they were so unstable that even adding gl = gitlab.Gitlab( ... retry_transient_errors=True) couldn't get passed the 500 errors.

I was able to run the variable tests against a live gitlab instance to demonstrate to myself the tests failed before my changes and passed after.

@PhilipNelson5 PhilipNelson5 force-pushed the fix-var-attrs branch 3 times, most recently from f968e2c to 0659a92 Compare March 28, 2026 21:23
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 28, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.75%. Comparing base (d72b378) to head (5c0652d).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3379   +/-   ##
=======================================
  Coverage   95.75%   95.75%           
=======================================
  Files         100      100           
  Lines        6125     6125           
=======================================
  Hits         5865     5865           
  Misses        260      260           
Flag Coverage Δ
api_func_v4 83.78% <ø> (+0.06%) ⬆️
cli_func_v4 78.57% <ø> (ø)
unit 90.23% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
gitlab/v4/objects/variables.py 100.00% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adjusts CI/CD variable attribute handling to support updating “masked and hidden” variables when the API doesn’t return their value, and adds functional coverage for hidden variables.

Changes:

  • Make value optional for variable updates by changing _update_attrs to require only key.
  • Allow masked_and_hidden during variable creation across instance/group/project managers.
  • Add functional tests for creating and updating hidden variables; ignore .mypy_cache/.

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.

File Description
gitlab/v4/objects/variables.py Updates create/update attribute definitions to support masked_and_hidden on create and omit value as a required update field.
tests/functional/api/test_variables.py Adds functional tests for hidden variables across instance/group/project scopes.
.gitignore Adds .mypy_cache/ to ignored files.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/functional/api/test_variables.py Outdated
Comment thread gitlab/v4/objects/variables.py Outdated
Comment thread gitlab/v4/objects/variables.py Outdated
Comment thread gitlab/v4/objects/variables.py Outdated
Comment thread gitlab/v4/objects/variables.py Outdated
Comment thread gitlab/v4/objects/variables.py
Comment thread gitlab/v4/objects/variables.py Outdated
…eate attrs

remove hidden_and_masked from admin vars api
Comment thread gitlab/v4/objects/variables.py
Remove instance test becasue it does not support masked_and_hidden
Copy link
Copy Markdown
Member

@JohnVillalovos JohnVillalovos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@JohnVillalovos JohnVillalovos merged commit 849301b into python-gitlab:main Apr 20, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants