← 返回首页
Update and fix variable _create_attrs and _update_attrs by PhilipNelson5 · Pull Request #3379 · python-gitlab/python-gitlab · GitHub
Skip to content

Navigation Menu

Toggle navigation
Sign in
Appearance settings
Search or jump to...

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Include my email address so I can be contacted

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Resetting focus
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) dotfile  (1) All 2 file types selected Viewed files
Conversations
Failed to load comments. Retry
Loading
Jump to
Jump to file
Failed to load files. Retry
Loading
Diff view
Unified
Split
Hide whitespace
Apply and reload
Show whitespace
Diff view
Unified
Split
Hide whitespace
Apply and reload
1 change: 1 addition & 0 deletions .gitignore
Show comments View file Edit file Delete file Open in desktop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ docs/_build
.tox
.venv/
venv/
.mypy_cache/

# Include tracked hidden files and directories in search and diff tools
!.dockerignore
Expand Down
57 changes: 50 additions & 7 deletions gitlab/v4/objects/variables.py
Show comments View file Edit file Delete file Open in desktop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,19 @@ class VariableManager(CRUDMixin[Variable]):
_path = "/admin/ci/variables"
_obj_cls = Variable
_create_attrs = RequiredOptional(
required=("key", "value"), optional=("protected", "variable_type", "masked")
required=("key", "value"),
optional=("description", "masked", "protected", "raw", "variable_type"),
)
_update_attrs = RequiredOptional(
required=("key", "value"), optional=("protected", "variable_type", "masked")
required=("key",),
optional=(
"description",
"masked",
"protected",
"raw",
"value",
"variable_type",
),
)


Expand All @@ -43,10 +52,28 @@ class GroupVariableManager(CRUDMixin[GroupVariable]):
_obj_cls = GroupVariable
_from_parent_attrs = {"group_id": "id"}
_create_attrs = RequiredOptional(
required=("key", "value"), optional=("protected", "variable_type", "masked")
required=("key", "value"),
optional=(
"description",
"environment_scope",
"masked",
"masked_and_hidden",
"protected",
"raw",
"variable_type",
),
)
_update_attrs = RequiredOptional(
required=("key", "value"), optional=("protected", "variable_type", "masked")
required=("key",),
optional=(
"description",
"environment_scope",
"masked",
"protected",
"raw",
"value",
Comment thread
JohnVillalovos marked this conversation as resolved.
Show resolved Hide resolved
"variable_type",
),
)


Expand All @@ -60,9 +87,25 @@ class ProjectVariableManager(CRUDMixin[ProjectVariable]):
_from_parent_attrs = {"project_id": "id"}
_create_attrs = RequiredOptional(
required=("key", "value"),
optional=("protected", "variable_type", "masked", "environment_scope"),
optional=(
"description",
"environment_scope",
"masked",
"masked_and_hidden",
"protected",
"raw",
"variable_type",
),
Comment thread
JohnVillalovos marked this conversation as resolved.
Show resolved Hide resolved
)
_update_attrs = RequiredOptional(
required=("key", "value"),
optional=("protected", "variable_type", "masked", "environment_scope"),
required=("key",),
optional=(
"description",
"environment_scope",
"masked",
"protected",
"raw",
"value",
"variable_type",
),
)
36 changes: 36 additions & 0 deletions tests/functional/api/test_variables.py
Show comments View file Edit file Delete file Open in desktop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,39 @@ def test_project_variables(project):
assert variable.value == "new_value1"

variable.delete()


def test_hidden_group_variables(group):
variable = group.variables.create(
{"key": "key1", "value": "secret_value", "masked_and_hidden": True}
)

variable = group.variables.get(variable.key)
assert variable.value is None
assert variable.description is None
assert variable in group.variables.list()

variable.description = "new_description"
variable.save()
variable = group.variables.get(variable.key)
assert variable.description == "new_description"

variable.delete()


def test_hidden_project_variables(project):
variable = project.variables.create(
{"key": "key1", "value": "secret_value", "masked_and_hidden": True}
)

variable = project.variables.get(variable.key)
assert variable.value is None
assert variable.description is None
assert variable in project.variables.list()

variable.description = "new_description"
variable.save()
variable = project.variables.get(variable.key)
assert variable.description == "new_description"

variable.delete()
Toggle all file notes Toggle all file annotations

Footer

© 2026 GitHub, Inc.