Skip to content
Merged
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
5 changes: 5 additions & 0 deletions pydatalab/src/pydatalab/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,11 @@ class ServerConfig(BaseSettings):
its importance when deploying a datalab instance.""",
)

MAX_BATCH_CREATE_SIZE: int = Field(
10_000,
description="Maximum number of items that can be created in a single batch operation.",
)

BACKUP_STRATEGIES: dict[str, BackupStrategy] | None = Field(
{
"daily-snapshots": BackupStrategy(
Expand Down
9 changes: 9 additions & 0 deletions pydatalab/src/pydatalab/routes/v0_1/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,15 @@ def create_samples():
request_json = request.get_json() # noqa: F821 pylint: disable=undefined-variable

sample_jsons = request_json["new_sample_datas"]

if len(sample_jsons) > CONFIG.MAX_BATCH_CREATE_SIZE:
return jsonify(
{
"status": "error",
"message": f"Batch size limit exceeded. Maximum allowed: {CONFIG.MAX_BATCH_CREATE_SIZE}, requested: {len(sample_jsons)}",
}
), 400

copy_from_item_ids = request_json.get("copy_from_item_ids")
generate_ids_automatically = request_json.get("generate_ids_automatically")

Expand Down
21 changes: 20 additions & 1 deletion webapp/src/components/BatchCreateItemModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
:model-value="modelValue"
:disable-submit="
isValidEntryID.some((e) => e) ||
(!generateIDsAutomatically && items.some((s) => !Boolean(s.item_id)))
(!generateIDsAutomatically && items.some((s) => !Boolean(s.item_id))) ||
isValidBatchSize
"
@update:model-value="$emit('update:modelValue', $event)"
>
Expand Down Expand Up @@ -48,6 +49,12 @@
max="100"
/>
</div>
<div
v-if="isValidBatchSize"
class="form-error ml-2 text-nowrap small align-self-center"
>
{{ isValidBatchSize }}
</div>
</div>
<div class="row">
<div class="col-md-6 mt-2" @click="templateIsOpen = !templateIsOpen">
Expand Down Expand Up @@ -406,6 +413,7 @@ export default {
},

serverResponses: {}, // after the server responds, store error messages if any
batchSizeError: false,
};
},
computed: {
Expand Down Expand Up @@ -435,10 +443,20 @@ export default {
return validateEntryID(item.item_id, this.takenItemIds, this.takenSampleIds);
});
},
isValidBatchSize() {
return this.batchSizeError;
},
},

watch: {
nSamples(newValue, oldValue) {
if (newValue > 100) {
this.batchSizeError = "Maximum 100 items can be created at once";
return;
} else {
this.batchSizeError = false;
}

if (newValue < oldValue) {
this.items = this.items.slice(0, newValue);
}
Expand Down Expand Up @@ -574,6 +592,7 @@ export default {
this.beforeSubmit = false;
})
.catch((error) => {
window.alert("Error with creating new items: " + error);
console.log("Error with creating new items: " + error);
});
},
Expand Down