Skip to content

Project Push Rules not returning response #2990

Open
@calnighters

Description

@calnighters

Description of the problem, including code/CLI snippet

When calling the gitlab API to get a projects push rules after looping over a list of projects, the API will fail at projects that havent been pre-looked at in the UI. I am able to manually call the URL using the .http_get method and it returns None as expected. Once I have viewed the push rules in the UI for a project, then the call is successful and it moves on to the next project where this will happen again.

try:
    root_group = gl.groups.get(ROOT_GROUP_ID)
except gitlab.exceptions.GitlabGetError:
    sys.exit(f"Group '{ROOT_GROUP_ID}' does not exist.")

groups = [root_group]
groups.extend([gl.groups.get(gr.id) for gr in root_group.descendant_groups.list(get_all=True)])

projects = [gl.projects.get(gr.id) for gr in root_group.projects.list(include_subgroups=True, get_all=True)]

def push_rules_update(entity, full_path):
    push_rules_config, config_name = find_config(full_path, 'push_rules')
    print(f"Updating '{entity.id} - {full_path}' with '{config_name} push_rules'")
    pr = None
    try:
        pr = entity.pushrules.get()
    except gitlab.exceptions.GitlabGetError:
        pass
    if pr is None:
        entity.pushrules.create(push_rules_config)
    else:
        for key, value in push_rules_config.items():
            setattr(pr, key, value)
        pr.save()
    print(f"Updated '{entity.id} - {full_path}' with '{config_name} push_rules'") 

def approval_rules_update(entity, full_path):
    if isinstance(entity, gitlab.v4.objects.Project):
        print(entity)

def update(entity, full_path):
    push_rules_update(entity, full_path)
    # approval_rules_update(entity, full_path)

# for group in groups:
#     update(group, group.full_path)

gl.enable_debug()
push_rule = gl.http_get('/projects/14756/push_rule')
print(push_rule)
for project in projects:
    update(project, project.path_with_namespace)

Expected Behavior

Be able to view project push rules without navigating to them in the UI first.

Actual Behavior

Unable to view project push rules without navigating to them in the Ui first.

Specifications

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

Please see below logs which show the successful manual call at the top to the same project which fails at the bottom.

DEBUG:http.client:send: b'GET /api/v4/projects/14756/push_rule HTTP/1.1\r\nHost: REVOKED\r\nUser-Agent: python-gitlab/4.11.1\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\nContent-type: application/json\r\nPRIVATE-TOKEN: [MASKED]\r\n\r\n'
DEBUG:http.client:reply: 'HTTP/1.1 200 OK\r\n'
DEBUG:http.client:header: Date: Fri, 20 Sep 2024 15:04:27 GMT
DEBUG:http.client:header: Content-Type: application/json
DEBUG:http.client:header: Content-Length: 4
DEBUG:http.client:header: Connection: keep-alive
DEBUG:http.client:header: Server: nginx
DEBUG:http.client:header: Cache-Control: max-age=0, private, must-revalidate
DEBUG:http.client:header: Etag: W/"74234e98afe7498fb5daf1f36ac2d78a"
DEBUG:http.client:header: Vary: Origin
DEBUG:http.client:header: X-Content-Type-Options: nosniff
DEBUG:http.client:header: X-Frame-Options: SAMEORIGIN
DEBUG:http.client:header: X-Gitlab-Meta: {"correlation_id":"01J87ZD13M8950KYFPRB1RXKEB","version":"1"}
DEBUG:http.client:header: X-Request-Id: 01J87ZD13M8950KYFPRB1RXKEB
DEBUG:http.client:header: X-Runtime: 0.071143
DEBUG:http.client:header: Strict-Transport-Security: max-age=31536000; includeSubdomains
DEBUG:http.client:header: Referrer-Policy: same-origin
DEBUG:urllib3.connectionpool:https://REVOKED:443 "GET /api/v4/projects/14756/push_rule HTTP/11" 200 4
None


Updating '16741 - tact/public/gitlab/gitlab-repo-updater' with 'tact push_rules'
DEBUG:http.client:send: b'GET /api/v4/projects/16741/push_rule HTTP/1.1\r\nHost: REVOKED\r\nUser-Agent: python-gitlab/4.11.1\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\nContent-type: application/json\r\nPRIVATE-TOKEN: [MASKED]\r\n\r\n'
DEBUG:http.client:reply: 'HTTP/1.1 200 OK\r\n'
DEBUG:http.client:header: Date: Fri, 20 Sep 2024 15:04:27 GMT
DEBUG:http.client:header: Content-Type: application/json
DEBUG:http.client:header: Transfer-Encoding: chunked
DEBUG:http.client:header: Connection: keep-alive
DEBUG:http.client:header: Server: nginx
DEBUG:http.client:header: Vary: Accept-Encoding
DEBUG:http.client:header: Cache-Control: max-age=0, private, must-revalidate
DEBUG:http.client:header: Etag: W/"8bf014cf030396a6e72a556569dba651"
DEBUG:http.client:header: Vary: Origin
DEBUG:http.client:header: X-Content-Type-Options: nosniff
DEBUG:http.client:header: X-Frame-Options: SAMEORIGIN
DEBUG:http.client:header: X-Gitlab-Meta: {"correlation_id":"01J87ZD1621Y2E85ZF8KQFKP1E","version":"1"}
DEBUG:http.client:header: X-Request-Id: 01J87ZD1621Y2E85ZF8KQFKP1E
DEBUG:http.client:header: X-Runtime: 0.081929
DEBUG:http.client:header: Strict-Transport-Security: max-age=31536000; includeSubdomains
DEBUG:http.client:header: Referrer-Policy: same-origin
DEBUG:http.client:header: Content-Encoding: gzip
DEBUG:urllib3.connectionpool:https://REVOKED:443 "GET /api/v4/projects/16741/push_rule HTTP/11" 200 None
DEBUG:http.client:send: b'PUT /api/v4/projects/16741/push_rule HTTP/1.1\r\nHost: REVOKED\r\nUser-Agent: python-gitlab/4.11.1\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\nContent-type: application/json\r\nContent-Length: 57\r\nPRIVATE-TOKEN: [MASKED]\r\n\r\n'
DEBUG:http.client:send: b'{"commit_message_regex": ".*", "branch_name_regex": ".*"}'
DEBUG:http.client:reply: 'HTTP/1.1 200 OK\r\n'
DEBUG:http.client:header: Date: Fri, 20 Sep 2024 15:04:27 GMT
DEBUG:http.client:header: Content-Type: application/json
DEBUG:http.client:header: Transfer-Encoding: chunked
DEBUG:http.client:header: Connection: keep-alive
DEBUG:http.client:header: Server: nginx
DEBUG:http.client:header: Vary: Accept-Encoding
DEBUG:http.client:header: Cache-Control: max-age=0, private, must-revalidate
DEBUG:http.client:header: Etag: W/"8bf014cf030396a6e72a556569dba651"
DEBUG:http.client:header: Vary: Origin
DEBUG:http.client:header: X-Content-Type-Options: nosniff
DEBUG:http.client:header: X-Frame-Options: SAMEORIGIN
DEBUG:http.client:header: X-Gitlab-Meta: {"correlation_id":"01J87ZD18VZHQZ9ZK2E8BAKAQW","version":"1"}
DEBUG:http.client:header: X-Request-Id: 01J87ZD18VZHQZ9ZK2E8BAKAQW
DEBUG:http.client:header: X-Runtime: 0.093720
DEBUG:http.client:header: Strict-Transport-Security: max-age=31536000; includeSubdomains
DEBUG:http.client:header: Referrer-Policy: same-origin
DEBUG:http.client:header: Content-Encoding: gzip
DEBUG:urllib3.connectionpool:https://REVOKED:443 "PUT /api/v4/projects/16741/push_rule HTTP/11" 200 None
Updated '16741 - tact/public/gitlab/gitlab-repo-updater' with 'tact push_rules'
Updating '16063 - tact/public/argocd/argocd-keycloak-auth' with 'tact push_rules'
DEBUG:http.client:send: b'GET /api/v4/projects/16063/push_rule HTTP/1.1\r\nHost: REVOKED\r\nUser-Agent: python-gitlab/4.11.1\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\nContent-type: application/json\r\nPRIVATE-TOKEN: [MASKED]\r\n\r\n'
DEBUG:http.client:reply: 'HTTP/1.1 200 OK\r\n'
DEBUG:http.client:header: Date: Fri, 20 Sep 2024 15:04:27 GMT
DEBUG:http.client:header: Content-Type: application/json
DEBUG:http.client:header: Transfer-Encoding: chunked
DEBUG:http.client:header: Connection: keep-alive
DEBUG:http.client:header: Server: nginx
DEBUG:http.client:header: Vary: Accept-Encoding
DEBUG:http.client:header: Cache-Control: max-age=0, private, must-revalidate
DEBUG:http.client:header: Etag: W/"094a0aa47dff6be0c2ab86ffd1077d10"
DEBUG:http.client:header: Vary: Origin
DEBUG:http.client:header: X-Content-Type-Options: nosniff
DEBUG:http.client:header: X-Frame-Options: SAMEORIGIN
DEBUG:http.client:header: X-Gitlab-Meta: {"correlation_id":"01J87ZD1BZJKYDXH257G949PN3","version":"1"}
DEBUG:http.client:header: X-Request-Id: 01J87ZD1BZJKYDXH257G949PN3
DEBUG:http.client:header: X-Runtime: 0.089399
DEBUG:http.client:header: Strict-Transport-Security: max-age=31536000; includeSubdomains
DEBUG:http.client:header: Referrer-Policy: same-origin
DEBUG:http.client:header: Content-Encoding: gzip
DEBUG:urllib3.connectionpool:https://REVOKED:443 "GET /api/v4/projects/16063/push_rule HTTP/11" 200 None
DEBUG:http.client:send: b'PUT /api/v4/projects/16063/push_rule HTTP/1.1\r\nHost: REVOKED\r\nUser-Agent: python-gitlab/4.11.1\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\nContent-type: application/json\r\nContent-Length: 57\r\nPRIVATE-TOKEN: [MASKED]\r\n\r\n'
DEBUG:http.client:send: b'{"commit_message_regex": ".*", "branch_name_regex": ".*"}'
DEBUG:http.client:reply: 'HTTP/1.1 200 OK\r\n'
DEBUG:http.client:header: Date: Fri, 20 Sep 2024 15:04:27 GMT
DEBUG:http.client:header: Content-Type: application/json
DEBUG:http.client:header: Transfer-Encoding: chunked
DEBUG:http.client:header: Connection: keep-alive
DEBUG:http.client:header: Server: nginx
DEBUG:http.client:header: Vary: Accept-Encoding
DEBUG:http.client:header: Cache-Control: max-age=0, private, must-revalidate
DEBUG:http.client:header: Etag: W/"094a0aa47dff6be0c2ab86ffd1077d10"
DEBUG:http.client:header: Vary: Origin
DEBUG:http.client:header: X-Content-Type-Options: nosniff
DEBUG:http.client:header: X-Frame-Options: SAMEORIGIN
DEBUG:http.client:header: X-Gitlab-Meta: {"correlation_id":"01J87ZD1EZQAM237N53FP1044J","version":"1"}
DEBUG:http.client:header: X-Request-Id: 01J87ZD1EZQAM237N53FP1044J
DEBUG:http.client:header: X-Runtime: 0.079044
DEBUG:http.client:header: Strict-Transport-Security: max-age=31536000; includeSubdomains
DEBUG:http.client:header: Referrer-Policy: same-origin
DEBUG:http.client:header: Content-Encoding: gzip
DEBUG:urllib3.connectionpool:https://REVOKED:443 "PUT /api/v4/projects/16063/push_rule HTTP/11" 200 None
Updated '16063 - tact/public/argocd/argocd-keycloak-auth' with 'tact push_rules'
Updating '15681 - tact/public/gitlab-profile' with 'tact push_rules'
DEBUG:http.client:send: b'GET /api/v4/projects/15681/push_rule HTTP/1.1\r\nHost: REVOKED\r\nUser-Agent: python-gitlab/4.11.1\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\nContent-type: application/json\r\nPRIVATE-TOKEN: [MASKED]\r\n\r\n'
DEBUG:http.client:reply: 'HTTP/1.1 200 OK\r\n'
DEBUG:http.client:header: Date: Fri, 20 Sep 2024 15:04:27 GMT
DEBUG:http.client:header: Content-Type: application/json
DEBUG:http.client:header: Transfer-Encoding: chunked
DEBUG:http.client:header: Connection: keep-alive
DEBUG:http.client:header: Server: nginx
DEBUG:http.client:header: Vary: Accept-Encoding
DEBUG:http.client:header: Cache-Control: max-age=0, private, must-revalidate
DEBUG:http.client:header: Etag: W/"7e4d121807009c9b06ce1f6bd637e8c6"
DEBUG:http.client:header: Vary: Origin
DEBUG:http.client:header: X-Content-Type-Options: nosniff
DEBUG:http.client:header: X-Frame-Options: SAMEORIGIN
DEBUG:http.client:header: X-Gitlab-Meta: {"correlation_id":"01J87ZD1HMTKWY7VVJF0Y6DBGJ","version":"1"}
DEBUG:http.client:header: X-Request-Id: 01J87ZD1HMTKWY7VVJF0Y6DBGJ
DEBUG:http.client:header: X-Runtime: 0.090885
DEBUG:http.client:header: Strict-Transport-Security: max-age=31536000; includeSubdomains
DEBUG:http.client:header: Referrer-Policy: same-origin
DEBUG:http.client:header: Content-Encoding: gzip
DEBUG:urllib3.connectionpool:https://REVOKED:443 "GET /api/v4/projects/15681/push_rule HTTP/11" 200 None
DEBUG:http.client:send: b'PUT /api/v4/projects/15681/push_rule HTTP/1.1\r\nHost: REVOKED\r\nUser-Agent: python-gitlab/4.11.1\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\nContent-type: application/json\r\nContent-Length: 57\r\nPRIVATE-TOKEN: [MASKED]\r\n\r\n'
DEBUG:http.client:send: b'{"commit_message_regex": ".*", "branch_name_regex": ".*"}'
DEBUG:http.client:reply: 'HTTP/1.1 200 OK\r\n'
DEBUG:http.client:header: Date: Fri, 20 Sep 2024 15:04:27 GMT
DEBUG:http.client:header: Content-Type: application/json
DEBUG:http.client:header: Transfer-Encoding: chunked
DEBUG:http.client:header: Connection: keep-alive
DEBUG:http.client:header: Server: nginx
DEBUG:http.client:header: Vary: Accept-Encoding
DEBUG:http.client:header: Cache-Control: max-age=0, private, must-revalidate
DEBUG:http.client:header: Etag: W/"7e4d121807009c9b06ce1f6bd637e8c6"
DEBUG:http.client:header: Vary: Origin
DEBUG:http.client:header: X-Content-Type-Options: nosniff
DEBUG:http.client:header: X-Frame-Options: SAMEORIGIN
DEBUG:http.client:header: X-Gitlab-Meta: {"correlation_id":"01J87ZD1MP2G48FV3DC01P6MNM","version":"1"}
DEBUG:http.client:header: X-Request-Id: 01J87ZD1MP2G48FV3DC01P6MNM
DEBUG:http.client:header: X-Runtime: 0.122944
DEBUG:http.client:header: Strict-Transport-Security: max-age=31536000; includeSubdomains
DEBUG:http.client:header: Referrer-Policy: same-origin
DEBUG:http.client:header: Content-Encoding: gzip
DEBUG:urllib3.connectionpool:https://REVOKED:443 "PUT /api/v4/projects/15681/push_rule HTTP/11" 200 None
Updated '15681 - tact/public/gitlab-profile' with 'tact push_rules'
Updating '15536 - tact/public/argocd/argocd-helm-chart' with 'tact push_rules'
DEBUG:http.client:send: b'GET /api/v4/projects/15536/push_rule HTTP/1.1\r\nHost: REVOKED\r\nUser-Agent: python-gitlab/4.11.1\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\nContent-type: application/json\r\nPRIVATE-TOKEN: [MASKED]\r\n\r\n'
DEBUG:http.client:reply: 'HTTP/1.1 200 OK\r\n'
DEBUG:http.client:header: Date: Fri, 20 Sep 2024 15:04:28 GMT
DEBUG:http.client:header: Content-Type: application/json
DEBUG:http.client:header: Transfer-Encoding: chunked
DEBUG:http.client:header: Connection: keep-alive
DEBUG:http.client:header: Server: nginx
DEBUG:http.client:header: Vary: Accept-Encoding
DEBUG:http.client:header: Cache-Control: max-age=0, private, must-revalidate
DEBUG:http.client:header: Etag: W/"7218ebd650220722b291064ff0e9f020"
DEBUG:http.client:header: Vary: Origin
DEBUG:http.client:header: X-Content-Type-Options: nosniff
DEBUG:http.client:header: X-Frame-Options: SAMEORIGIN
DEBUG:http.client:header: X-Gitlab-Meta: {"correlation_id":"01J87ZD1S0KB8WSX0NWQEQ538Z","version":"1"}
DEBUG:http.client:header: X-Request-Id: 01J87ZD1S0KB8WSX0NWQEQ538Z
DEBUG:http.client:header: X-Runtime: 0.097663
DEBUG:http.client:header: Strict-Transport-Security: max-age=31536000; includeSubdomains
DEBUG:http.client:header: Referrer-Policy: same-origin
DEBUG:http.client:header: Content-Encoding: gzip
DEBUG:urllib3.connectionpool:https://REVOKED:443 "GET /api/v4/projects/15536/push_rule HTTP/11" 200 None
DEBUG:http.client:send: b'PUT /api/v4/projects/15536/push_rule HTTP/1.1\r\nHost: REVOKED\r\nUser-Agent: python-gitlab/4.11.1\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\nContent-type: application/json\r\nContent-Length: 57\r\nPRIVATE-TOKEN: [MASKED]\r\n\r\n'
DEBUG:http.client:send: b'{"commit_message_regex": ".*", "branch_name_regex": ".*"}'
DEBUG:http.client:reply: 'HTTP/1.1 200 OK\r\n'
DEBUG:http.client:header: Date: Fri, 20 Sep 2024 15:04:28 GMT
DEBUG:http.client:header: Content-Type: application/json
DEBUG:http.client:header: Transfer-Encoding: chunked
DEBUG:http.client:header: Connection: keep-alive
DEBUG:http.client:header: Server: nginx
DEBUG:http.client:header: Vary: Accept-Encoding
DEBUG:http.client:header: Cache-Control: max-age=0, private, must-revalidate
DEBUG:http.client:header: Etag: W/"7218ebd650220722b291064ff0e9f020"
DEBUG:http.client:header: Vary: Origin
DEBUG:http.client:header: X-Content-Type-Options: nosniff
DEBUG:http.client:header: X-Frame-Options: SAMEORIGIN
DEBUG:http.client:header: X-Gitlab-Meta: {"correlation_id":"01J87ZD1W8WZ55M3P0G0Z15GR2","version":"1"}
DEBUG:http.client:header: X-Request-Id: 01J87ZD1W8WZ55M3P0G0Z15GR2
DEBUG:http.client:header: X-Runtime: 0.077882
DEBUG:http.client:header: Strict-Transport-Security: max-age=31536000; includeSubdomains
DEBUG:http.client:header: Referrer-Policy: same-origin
DEBUG:http.client:header: Content-Encoding: gzip
DEBUG:urllib3.connectionpool:https://REVOKED:443 "PUT /api/v4/projects/15536/push_rule HTTP/11" 200 None
Updated '15536 - tact/public/argocd/argocd-helm-chart' with 'tact push_rules'
Updating '14756 - tact/public/gitlab/gitlab-pipelines' with 'tact push_rules'
DEBUG:http.client:send: b'GET /api/v4/projects/14756/push_rule HTTP/1.1\r\nHost: REVOKED\r\nUser-Agent: python-gitlab/4.11.1\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\nContent-type: application/json\r\nPRIVATE-TOKEN: [MASKED]\r\n\r\n'
DEBUG:http.client:reply: 'HTTP/1.1 200 OK\r\n'
DEBUG:http.client:header: Date: Fri, 20 Sep 2024 15:04:28 GMT
DEBUG:http.client:header: Content-Type: application/json
DEBUG:http.client:header: Content-Length: 4
DEBUG:http.client:header: Connection: keep-alive
DEBUG:http.client:header: Server: nginx
DEBUG:http.client:header: Cache-Control: max-age=0, private, must-revalidate
DEBUG:http.client:header: Etag: W/"74234e98afe7498fb5daf1f36ac2d78a"
DEBUG:http.client:header: Vary: Origin
DEBUG:http.client:header: X-Content-Type-Options: nosniff
DEBUG:http.client:header: X-Frame-Options: SAMEORIGIN
DEBUG:http.client:header: X-Gitlab-Meta: {"correlation_id":"01J87ZD1YXNBM5TQWPGP3NYWT6","version":"1"}
DEBUG:http.client:header: X-Request-Id: 01J87ZD1YXNBM5TQWPGP3NYWT6
DEBUG:http.client:header: X-Runtime: 0.062822
DEBUG:http.client:header: Strict-Transport-Security: max-age=31536000; includeSubdomains
DEBUG:http.client:header: Referrer-Policy: same-origin
DEBUG:urllib3.connectionpool:https://REVOKED:443 "GET /api/v4/projects/14756/push_rule HTTP/11" 200 4
Traceback (most recent call last):
  File "/home/u.7843152-3/gitlab-repo-updater/configure.py", line 95, in <module>
    update(project, project.path_with_namespace)
  File "/home/u.7843152-3/gitlab-repo-updater/configure.py", line 85, in update
    push_rules_update(entity, full_path)
  File "/home/u.7843152-3/gitlab-repo-updater/configure.py", line 69, in push_rules_update
    pr = entity.pushrules.get()
         ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/linuxbrew/.linuxbrew/Cellar/[email protected]/3.12.3/lib/python3.12/site-packages/gitlab/v4/objects/push_rules.py", line 64, in get
    return cast(ProjectPushRules, super().get(**kwargs))
                                  ^^^^^^^^^^^^^^^^^^^^^
  File "/home/linuxbrew/.linuxbrew/Cellar/[email protected]/3.12.3/lib/python3.12/site-packages/gitlab/exceptions.py", line 344, in wrapped_f
    return f(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^
  File "/home/linuxbrew/.linuxbrew/Cellar/[email protected]/3.12.3/lib/python3.12/site-packages/gitlab/mixins.py", line 159, in get
    return self._obj_cls(self, server_data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/linuxbrew/.linuxbrew/Cellar/[email protected]/3.12.3/lib/python3.12/site-packages/gitlab/base.py", line 62, in __init__
    raise GitlabParsingError(
gitlab.exceptions.GitlabParsingError: Attempted to initialize RESTObject with a non-dictionary value: None
This likely indicates an incorrect or malformed server response.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions