Skip to content

Commit 5e1c50b

Browse files
committed
feat(comment-file): lazy files initialization
1 parent b6a2a49 commit 5e1c50b

3 files changed

Lines changed: 36 additions & 2 deletions

File tree

invenio_requests/records/api.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
from invenio_records.dumpers import SearchDumper
1818
from invenio_records.systemfields import ConstantField, DictField, ModelField
1919
from invenio_records_resources.records.api import FileRecord, Record
20-
from invenio_records_resources.records.systemfields import FilesField, IndexField
20+
from invenio_records_resources.records.systemfields import IndexField
21+
22+
from invenio_requests.records.systemfields.files import RequestFilesField
2123

2224
from ..customizations import RequestState as State
2325
from .dumpers import (
@@ -215,7 +217,7 @@ class Request(Record):
215217
bucket = ModelField(dump=False)
216218

217219
# Files NOT dumped or stored in JSON - internal only
218-
files = FilesField(
220+
files = RequestFilesField(
219221
store=False, # Don't serialize to request JSON
220222
dump=False, # Don't include in dumps()
221223
file_cls=RequestFile,
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# Copyright (C) 2026 CERN.
4+
#
5+
# Invenio-Requests is free software; you can redistribute it and/or modify
6+
# it under the terms of the MIT License; see LICENSE file for more details.
7+
8+
"""Files field allow for explicit setting after initialization."""
9+
10+
from invenio_records_resources.records.systemfields.files.field import FilesField
11+
12+
13+
class RequestFilesField(FilesField):
14+
"""Request Files system field."""
15+
16+
def __init__(self, *args, **kwargs):
17+
"""Initialize the RequestFilesField."""
18+
super().__init__(*args, **kwargs)
19+
20+
#
21+
# Data descriptor methods (i.e. attribute access)
22+
#
23+
def __set__(self, record, value):
24+
"""Set the request's files field."""
25+
assert record is not None
26+
27+
self.set_dictkey(record, value)

invenio_requests/services/files/service.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ def create_file(self, identity, id_, key, stream, content_length, uow=None):
6565
key_root, key_ext = splitext(key)
6666
unique_key = f"{key_root}-{unique_id}{key_ext}"
6767

68+
# Lazy files enable initialization (for requests created before request files support)
69+
if request.files is None:
70+
# RequestFilesField allows to set the files field after initialization.
71+
request.files = {"enabled": True}
72+
6873
# Lazy bucket initialization
6974
if request.files.bucket is None:
7075
request.files.create_bucket()

0 commit comments

Comments
 (0)