|
15 | 15 | from labelbox.exceptions import InvalidQueryError, LabelboxError, ResourceNotFoundError, InvalidAttributeError |
16 | 16 | from labelbox.orm.db_object import DbObject, Updateable, Deletable |
17 | 17 | from labelbox.orm.model import Entity, Field, Relationship |
| 18 | +from labelbox.exceptions import MalformedQueryException |
18 | 19 |
|
19 | 20 | if TYPE_CHECKING: |
20 | 21 | from labelbox import Task, User, DataRow |
21 | 22 |
|
22 | 23 | logger = logging.getLogger(__name__) |
23 | 24 |
|
| 25 | +MAX_DATAROW_PER_API_OPERATION = 150000 |
| 26 | +MAX_DATAROW_WITH_METADATA = 30000 |
| 27 | + |
24 | 28 |
|
25 | 29 | class Dataset(DbObject, Updateable, Deletable): |
26 | 30 | """ A Dataset is a collection of DataRows. |
@@ -391,14 +395,18 @@ def convert_item(item): |
391 | 395 | f"Must pass an iterable to create_data_rows. Found {type(items)}" |
392 | 396 | ) |
393 | 397 |
|
| 398 | + if len(items) > MAX_DATAROW_PER_API_OPERATION: |
| 399 | + raise MalformedQueryException( |
| 400 | + f"Cannot create more than {MAX_DATAROW_PER_API_OPERATION} DataRows per function call." |
| 401 | + ) |
| 402 | + |
394 | 403 | # TODO: If any datarows contain metadata, we're limiting max # of datarows |
395 | 404 | # until we address performance issues with datarow create with metadata |
396 | | - max_datarow_with_metadata = 30_000 |
397 | | - if (len(items) > max_datarow_with_metadata): |
| 405 | + if len(items) > MAX_DATAROW_WITH_METADATA: |
398 | 406 | for row in items: |
399 | 407 | if 'metadata_fields' in row: |
400 | | - raise ValueError( |
401 | | - f"Cannot create more than {max_datarow_with_metadata} DataRows, if any DataRows contain metadata" |
| 408 | + raise MalformedQueryException( |
| 409 | + f"Cannot create more than {MAX_DATAROW_WITH_METADATA} DataRows, if any DataRows contain metadata" |
402 | 410 | ) |
403 | 411 |
|
404 | 412 | with ThreadPoolExecutor(file_upload_thread_count) as executor: |
|
0 commit comments