Skip to content

Fix BranchProtection.restrictions raising AttributeError - #3527

Open
Noethix55555 wants to merge 1 commit into
PyGithub:mainfrom
Noethix55555:fix/branchprotection-restrictions-attribute
Open

Fix BranchProtection.restrictions raising AttributeError#3527
Noethix55555 wants to merge 1 commit into
PyGithub:mainfrom
Noethix55555:fix/branchprotection-restrictions-attribute

Conversation

@Noethix55555

Copy link
Copy Markdown
Contributor

Fixes #3526.

Problem

BranchProtection.restrictions raises AttributeError: 'dict' object has no attribute 'value' whenever push restrictions are present. The property returns self._restrictions.value, but _useAttributes stored the raw API dict instead of wrapping it like every other attribute. The absent-restrictions case only worked because NotSet.value is None.

Solution

Wrap the value with _makeDictAttribute, consistent with how all other attributes are handled:

self._restrictions = self._makeDictAttribute(attributes["restrictions"])

The _user_push_restrictions / _team_push_restrictions lines are left unchanged since they read raw URL strings and already work.

Tests

Added two regression tests in tests/BranchProtection.py that construct a BranchProtection offline (mock requester, no network):

  • testRestrictionsPopulated builds a populated top-level restrictions object and asserts bp.restrictions["users"] / ["teams"] round-trip.
  • testRestrictionsAbsent asserts an absent restrictions still yields None.

The populated test fails on main with the reported AttributeError and passes with the fix.

The restrictions property returns self._restrictions.value, but
_useAttributes stored the raw dict instead of wrapping it. When push
restrictions are present, accessing the property raised
AttributeError: 'dict' object has no attribute 'value'. Wrap the value
with _makeDictAttribute like every other attribute.
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.

BranchProtection.restrictions raises AttributeError when push restrictions are present

1 participant