Skip to content

Commit 112f5c6

Browse files
BenjaminCharmesml-evspre-commit-ci[bot]
authored
Limit batch interface to 100 items in UI and 10,000 via API (#1213)
Co-authored-by: Matthew Evans <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 57652b8 commit 112f5c6

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

pydatalab/src/pydatalab/config.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,11 @@ class ServerConfig(BaseSettings):
239239
its importance when deploying a datalab instance.""",
240240
)
241241

242+
MAX_BATCH_CREATE_SIZE: int = Field(
243+
10_000,
244+
description="Maximum number of items that can be created in a single batch operation.",
245+
)
246+
242247
BACKUP_STRATEGIES: dict[str, BackupStrategy] | None = Field(
243248
{
244249
"daily-snapshots": BackupStrategy(

pydatalab/src/pydatalab/routes/v0_1/items.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,15 @@ def create_samples():
662662
request_json = request.get_json() # noqa: F821 pylint: disable=undefined-variable
663663

664664
sample_jsons = request_json["new_sample_datas"]
665+
666+
if len(sample_jsons) > CONFIG.MAX_BATCH_CREATE_SIZE:
667+
return jsonify(
668+
{
669+
"status": "error",
670+
"message": f"Batch size limit exceeded. Maximum allowed: {CONFIG.MAX_BATCH_CREATE_SIZE}, requested: {len(sample_jsons)}",
671+
}
672+
), 400
673+
665674
copy_from_item_ids = request_json.get("copy_from_item_ids")
666675
generate_ids_automatically = request_json.get("generate_ids_automatically")
667676

webapp/src/components/BatchCreateItemModal.vue

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
:model-value="modelValue"
55
:disable-submit="
66
isValidEntryID.some((e) => e) ||
7-
(!generateIDsAutomatically && items.some((s) => !Boolean(s.item_id)))
7+
(!generateIDsAutomatically && items.some((s) => !Boolean(s.item_id))) ||
8+
isValidBatchSize
89
"
910
@update:model-value="$emit('update:modelValue', $event)"
1011
>
@@ -48,6 +49,12 @@
4849
max="100"
4950
/>
5051
</div>
52+
<div
53+
v-if="isValidBatchSize"
54+
class="form-error ml-2 text-nowrap small align-self-center"
55+
>
56+
{{ isValidBatchSize }}
57+
</div>
5158
</div>
5259
<div class="row">
5360
<div class="col-md-6 mt-2" @click="templateIsOpen = !templateIsOpen">
@@ -406,6 +413,7 @@ export default {
406413
},
407414
408415
serverResponses: {}, // after the server responds, store error messages if any
416+
batchSizeError: false,
409417
};
410418
},
411419
computed: {
@@ -435,10 +443,20 @@ export default {
435443
return validateEntryID(item.item_id, this.takenItemIds, this.takenSampleIds);
436444
});
437445
},
446+
isValidBatchSize() {
447+
return this.batchSizeError;
448+
},
438449
},
439450
440451
watch: {
441452
nSamples(newValue, oldValue) {
453+
if (newValue > 100) {
454+
this.batchSizeError = "Maximum 100 items can be created at once";
455+
return;
456+
} else {
457+
this.batchSizeError = false;
458+
}
459+
442460
if (newValue < oldValue) {
443461
this.items = this.items.slice(0, newValue);
444462
}
@@ -574,6 +592,7 @@ export default {
574592
this.beforeSubmit = false;
575593
})
576594
.catch((error) => {
595+
window.alert("Error with creating new items: " + error);
577596
console.log("Error with creating new items: " + error);
578597
});
579598
},

0 commit comments

Comments
 (0)