Skip to content

Commit 5179dab

Browse files
author
Val Brodsky
committed
Try and fix method capture
1 parent 5140584 commit 5179dab

File tree

3 files changed

+35
-14
lines changed

3 files changed

+35
-14
lines changed

libs/labelbox/src/labelbox/client.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,12 @@ def enable_experimental(self) -> bool:
156156
def app_url(self) -> str:
157157
return self._request_client.app_url
158158

159+
def set_sdk_method(self, sdk_method: str):
160+
self._request_client.sdk_method = sdk_method
161+
162+
def unset_sdk_method(self):
163+
self._request_client.sdk_method = None
164+
159165
def execute(
160166
self,
161167
query=None,

libs/labelbox/src/labelbox/pagination.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
# Size of a single page in a paginated query.
22
from abc import ABC, abstractmethod
3-
from typing import Any, Callable, Dict, List, Optional, Tuple, Type, Union
4-
5-
from typing import TYPE_CHECKING
3+
from typing import (
4+
TYPE_CHECKING,
5+
Any,
6+
Callable,
7+
Dict,
8+
List,
9+
Optional,
10+
Tuple,
11+
Type,
12+
Union,
13+
)
14+
15+
from lbox.call_info import call_info_as_str
616

717
if TYPE_CHECKING:
818
from labelbox import Client
919
from labelbox.orm.db_object import DbObject
1020

1121
_PAGE_SIZE = 100
1222

13-
1423
class PaginatedCollection:
1524
"""An iterable collection of database objects (Projects, Labels, etc...).
1625
@@ -49,9 +58,11 @@ def __init__(
4958
self._fetched_all = False
5059
self._data: List[Dict[str, Any]] = []
5160
self._data_ind = 0
61+
self._client = client
62+
self._client.set_sdk_method(call_info_as_str())
5263

5364
pagination_kwargs = {
54-
"client": client,
65+
"client": self._client,
5566
"obj_class": obj_class,
5667
"dereferencing": dereferencing,
5768
"experimental": experimental,
@@ -72,11 +83,13 @@ def __iter__(self):
7283
def __next__(self):
7384
if len(self._data) <= self._data_ind:
7485
if self._fetched_all:
86+
self._client.unset_sdk_method()
7587
raise StopIteration()
7688

7789
page_data, self._fetched_all = self.paginator.get_next_page()
7890
self._data.extend(page_data)
7991
if len(page_data) == 0:
92+
self._client.unset_sdk_method()
8093
raise StopIteration()
8194

8295
rval = self._data[self._data_ind]

libs/lbox-clients/src/lbox/request_client.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def call_info():
3939
method_name = "Unknown"
4040
prefix = ""
4141
class_name = ""
42-
skip_methods = ["wrapper", "__init__"]
42+
skip_methods = ["wrapper", "__init__", "execute"]
4343
skip_classes = ["PaginatedCollection", "_CursorPagination", "_OffsetPagination"]
4444

4545
try:
@@ -51,14 +51,16 @@ def call_info():
5151
class_name = call_info.frame.f_locals.get(
5252
"self", None
5353
).__class__.__name__
54-
55-
if method_name not in skip_methods and class_name not in skip_classes:
56-
if TEST_FILE_PATTERN.search(call_info.filename):
57-
prefix = "test:"
58-
else:
59-
if class_name == "NoneType":
60-
class_name = ""
61-
break
54+
print(call_info.frame.f_locals)
55+
import pdb; pdb.set_trace()
56+
if method_name not in skip_methods:
57+
if class_name not in skip_classes:
58+
if TEST_FILE_PATTERN.search(call_info.filename):
59+
prefix = "test:"
60+
else:
61+
if class_name == "NoneType":
62+
class_name = ""
63+
break
6264

6365
except Exception:
6466
pass

0 commit comments

Comments
 (0)