Skip to content

Commit 934eda0

Browse files
authored
Fix: Make grain optional (default None) in GroupByParam (#104)
* Make grain optional in GroupByParam * Update contextmanager return types from Iterator to Generator for basedpyright compatibility * Use existing customer__customer_type categorical dimension for test
1 parent 0ed3848 commit 934eda0

9 files changed

Lines changed: 21 additions & 13 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
kind: Fixes
2+
body: Make grain optional (default None) in GroupByParam so categorical group_by dimensions do not require a grain field
3+
time: 2026-05-21T21:08:10.518263-07:00

dbtsl/api/adbc/client/asyncio.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import asyncio
22
from contextlib import asynccontextmanager
3-
from typing import AsyncIterator, Optional
3+
from typing import AsyncGenerator, Optional
44

55
import pyarrow as pa
66
from typing_extensions import Self, Unpack
@@ -34,7 +34,7 @@ def __init__(
3434
self._loop = asyncio.get_running_loop()
3535

3636
@asynccontextmanager
37-
async def session(self) -> AsyncIterator[Self]:
37+
async def session(self) -> AsyncGenerator[Self, None]:
3838
"""Open a connection in the underlying ADBC driver.
3939
4040
All requests made during the same session will reuse the same connection.

dbtsl/api/adbc/client/sync.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from contextlib import contextmanager
2-
from typing import Iterator, Optional
2+
from typing import Generator, Optional
33

44
import pyarrow as pa
55
from typing_extensions import Self, Unpack
@@ -32,7 +32,7 @@ def __init__(
3232
super().__init__(server_host, environment_id, auth_token, url_format)
3333

3434
@contextmanager
35-
def session(self) -> Iterator[Self]:
35+
def session(self) -> Generator[Self, None, None]:
3636
"""Open a connection in the underlying ADBC driver.
3737
3838
All requests made during the same session will reuse the same connection.

dbtsl/api/graphql/client/asyncio.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import time
33
from builtins import TimeoutError as BuiltinTimeoutError
44
from contextlib import asynccontextmanager
5-
from typing import AsyncIterator, Dict, Optional, Union
5+
from typing import AsyncGenerator, Dict, Optional, Union
66

77
import pyarrow as pa
88
from gql import gql
@@ -83,7 +83,7 @@ def _create_transport(self, url: str, headers: Dict[str, str]) -> AIOHTTPTranspo
8383
)
8484

8585
@asynccontextmanager
86-
async def session(self) -> AsyncIterator[Self]:
86+
async def session(self) -> AsyncGenerator[Self, None]:
8787
"""Open a session in the underlying aiohttp transport.
8888
8989
A "session" is a TCP connection with the server. All operations

dbtsl/api/graphql/client/sync.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import time
22
from contextlib import contextmanager
3-
from typing import Dict, Iterator, Optional, Union
3+
from typing import Dict, Generator, Optional, Union
44

55
import pyarrow as pa
66
from gql import gql
@@ -71,7 +71,7 @@ def _create_transport(self, url: str, headers: Dict[str, str]) -> RequestsHTTPTr
7171
)
7272

7373
@contextmanager
74-
def session(self) -> Iterator[Self]:
74+
def session(self) -> Generator[Self, None, None]:
7575
"""Open a session in the underlying requests transport.
7676
7777
A "session" is a TCP connection with the server. All operations

dbtsl/api/shared/query_params.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class GroupByParam:
1717

1818
name: str
1919
type: GroupByType
20-
grain: Optional[str]
20+
grain: Optional[str] = None
2121

2222

2323
@dataclass(frozen=True)

dbtsl/client/asyncio.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from contextlib import asynccontextmanager
2-
from typing import AsyncIterator, Optional, Union
2+
from typing import AsyncGenerator, Optional, Union
33

44
from typing_extensions import Self
55

@@ -49,7 +49,7 @@ def __init__(
4949
)
5050

5151
@asynccontextmanager
52-
async def session(self) -> AsyncIterator[Self]:
52+
async def session(self) -> AsyncGenerator[Self, None]:
5353
"""Establish a connection with the dbt Semantic Layer's servers."""
5454
if self._has_session:
5555
raise ValueError("Cannot open session within session.")

dbtsl/client/sync.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from contextlib import contextmanager
2-
from typing import Iterator, Optional, Union
2+
from typing import Generator, Optional, Union
33

44
from typing_extensions import Self
55

@@ -49,7 +49,7 @@ def __init__(
4949
)
5050

5151
@contextmanager
52-
def session(self) -> Iterator[Self]:
52+
def session(self) -> Generator[Self, None, None]:
5353
"""Establish a connection with the dbt Semantic Layer's servers."""
5454
if self._has_session:
5555
raise ValueError("Cannot open session within session.")

tests/query_test_cases.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,9 @@
5151
GroupByParam(name="metric_time", grain="week", type=GroupByType.DIMENSION),
5252
],
5353
},
54+
# group by param object without grain (categorical dimension)
55+
{
56+
"metrics": ["order_total"],
57+
"group_by": [GroupByParam(name="customer__customer_type", type=GroupByType.DIMENSION)],
58+
},
5459
]

0 commit comments

Comments
 (0)