Skip to content

Commit 705e199

Browse files
authored
[BUGFIX] argilla-server: Prevent errors when allowed_workspaces is empty (#5273)
# Description <!-- Please include a summary of the changes and the related issue. Please also include relevant motivation and context. List any dependencies that are required for this change. --> This PR fixes errors when `allowed_workspaces` is empty in the `.oauth.yaml` file **Type of change** <!-- Please delete options that are not relevant. Remember to title the PR according to the type of change --> - Bug fix (non-breaking change which fixes an issue) **How Has This Been Tested** <!-- Please add some reference about how your feature has been tested. --> **Checklist** <!-- Please go over the list and make sure you've taken everything into account --> - I added relevant documentation - I followed the style guidelines of this project - I did a self-review of my code - I made corresponding changes to the documentation - I confirm My changes generate no new warnings - I have added tests that prove my fix is effective or that my feature works - I have added relevant notes to the CHANGELOG.md file (See https://keepachangelog.com/)
1 parent af1e488 commit 705e199

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

argilla-server/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ These are the section headers that we use:
3939

4040
### Fixed
4141

42-
- Fixed SQLite connection settings not working correctly due to a outdated conditional. ([#5149](https://github.com/argilla-io/argilla/pull/5149))
42+
- Fixed SQLite connection settings not working correctly due to an outdated conditional. ([#5149](https://github.com/argilla-io/argilla/pull/5149))
43+
- Fixed errors when `allowed_workspaces` in `.oauth.yaml` file is empty. ([#5273](https://github.com/argilla-io/argilla/pull/5273))
4344

4445
### Removed
4546

argilla-server/src/argilla_server/security/authentication/oauth2/settings.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ def from_dict(cls, settings: dict) -> "OAuth2Settings":
8383

8484
@classmethod
8585
def _build_workspaces(cls, settings: dict) -> List[AllowedWorkspace]:
86-
return [AllowedWorkspace(**workspace) for workspace in settings.pop(cls.ALLOWED_WORKSPACES_KEY, [])]
86+
allowed_workspaces = settings.pop(cls.ALLOWED_WORKSPACES_KEY, None) or []
87+
return [AllowedWorkspace(**workspace) for workspace in allowed_workspaces]
8788

8889
@classmethod
8990
def _build_providers(cls, settings: dict) -> List["OAuth2ClientProvider"]:

argilla-server/tests/unit/security/test_settings.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
14+
import json
1515
import os
16+
import tempfile
1617
from unittest import mock
1718

19+
from argilla_server.security.authentication.oauth2 import OAuth2Settings
1820
from argilla_server.security.settings import Settings
1921

2022

@@ -58,3 +60,14 @@ def test_configure_oauth_cfg():
5860
settings = Settings()
5961

6062
assert settings.oauth_cfg == oauth_cfg
63+
64+
65+
def test_configure_oauth_with_none_allowed_workspaces():
66+
with tempfile.NamedTemporaryFile(mode="wt") as file:
67+
file.writelines(["allowed_workspaces:", ""])
68+
file.flush()
69+
70+
with mock.patch.dict(os.environ, {"ARGILLA_AUTH_OAUTH_CFG": file.name}):
71+
settings = Settings()
72+
73+
assert settings.oauth.allowed_workspaces == []

0 commit comments

Comments
 (0)