Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/planecli/utils/resolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,12 @@ async def resolve_user_async(query: str, client: PlaneClient, workspace: str) ->
raise ResourceNotFoundError("User", query)

for m in members:
if m.get("email", "").lower() == query.lower():
# SSO-backed members may have email=None (Plane returns the key with a
# null value), so `.get("email", "")` still yields None. Guard the value
# itself, not just the missing key, and skip empty emails so an empty
# query cannot accidentally match a member without an email.
email = m.get("email")
if email and email.lower() == query.lower():
return m

def user_name(u: dict) -> str:
Expand Down
35 changes: 34 additions & 1 deletion tests/test_resolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

from __future__ import annotations

from planecli.utils.resolve import ISSUE_ID_PATTERN, _is_uuid
import pytest

from planecli.exceptions import ResourceNotFoundError
from planecli.utils.resolve import ISSUE_ID_PATTERN, _is_uuid, resolve_user_async


class TestIsUUID:
Expand Down Expand Up @@ -48,3 +51,33 @@ def test_invalid_no_prefix(self):
def test_invalid_numbers_in_prefix(self):
match = ISSUE_ID_PATTERN.match("A1B-123")
assert match is None


class TestResolveUserAsyncNullEmail:
"""Plane SSO users can have email=None, which used to crash name lookups."""

MEMBERS = [
{"id": "u1", "display_name": "Patrick", "email": "patrick@example.com"},
{"id": "u2", "display_name": "黄晨旭", "email": None},
{"id": "u3", "display_name": "Terry", "email": None},
]

@pytest.fixture(autouse=True)
def _mock_members(self, monkeypatch):
async def fake_list_members(workspace):
return self.MEMBERS

# resolve_user_async imports this lazily from planecli.cache.
monkeypatch.setattr("planecli.cache.cached_list_members", fake_list_members)

async def test_fuzzy_name_lookup_with_null_email(self):
result = await resolve_user_async("黄晨旭", None, "company")
assert result["id"] == "u2"

async def test_exact_email_match_still_works(self):
result = await resolve_user_async("PATRICK@example.com", None, "company")
assert result["id"] == "u1"

async def test_empty_query_does_not_match_null_email(self):
with pytest.raises(ResourceNotFoundError):
await resolve_user_async("", None, "company")