{"record":{"id":"7c84fdbe9ef5e1c2","repo":"django/django","slug":"subclasses-of-fileuploadhandler-must-provide-a-fil","errorCode":null,"errorMessage":"subclasses of FileUploadHandler must provide a file_complete() method","messagePattern":"subclasses of FileUploadHandler must provide a file_complete\\(\\) method","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"django/core/files/uploadhandler.py","lineNumber":143,"sourceCode":"        self.content_type_extra = content_type_extra\n\n    def receive_data_chunk(self, raw_data, start):\n        \"\"\"\n        Receive data from the streamed upload parser. ``start`` is the position\n        in the file of the chunk.\n        \"\"\"\n        raise NotImplementedError(\n            \"subclasses of FileUploadHandler must provide a receive_data_chunk() method\"\n        )\n\n    def file_complete(self, file_size):\n        \"\"\"\n        Signal that a file has completed. File size corresponds to the actual\n        size accumulated by all the chunks.\n\n        Subclasses should return a valid ``UploadedFile`` object.\n        \"\"\"\n        raise NotImplementedError(\n            \"subclasses of FileUploadHandler must provide a file_complete() method\"\n        )\n\n    def upload_complete(self):\n        \"\"\"\n        Signal that the upload is complete. Subclasses should perform cleanup\n        that is necessary for this handler.\n        \"\"\"\n        pass\n\n    def upload_interrupted(self):\n        \"\"\"\n        Signal that the upload was interrupted. Subclasses should perform\n        cleanup that is necessary for this handler.\n        \"\"\"\n        pass\n\n","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/django/django/blob/b5388a3a80cafcce2e34196d8e81cf5b48eb33bb/django/core/files/uploadhandler.py#L125-L161","documentation":"FileUploadHandler.file_complete (uploadhandler.py:143) is an abstract method raising NotImplementedError. Subclasses must finalize the upload and return an UploadedFile object once all chunks are received. A handler without it cannot close out a file upload and raises when the parser signals completion.","triggerScenarios":"A custom FileUploadHandler registered in FILE_UPLOAD_HANDLERS that omits file_complete; the upload pipeline reaches end-of-file and calls the missing method.","commonSituations":"Custom upload handler left incomplete; refactor that dropped the finalization method; misunderstanding the handler contract.","solutions":["Implement file_complete(self, file_size) returning an UploadedFile instance.","Subclass TemporaryFileUploadHandler / MemoryFileUploadHandler to inherit a correct implementation.","If your handler only observes (e.g. progress), return None from file_complete to let later handlers own the file."],"exampleFix":"// before\nclass MyHandler(FileUploadHandler):\n    def receive_data_chunk(self, raw_data, start):\n        self.buffer.write(raw_data)\n\n// after\nclass MyHandler(FileUploadHandler):\n    def receive_data_chunk(self, raw_data, start):\n        self.buffer.write(raw_data)\n    def file_complete(self, file_size):\n        self.buffer.seek(0)\n        return InMemoryUploadedFile(self.buffer, self.field_name, self.file_name, self.content_type, file_size, self.charset)","handlingStrategy":"type-guard","validationCode":"from django.core.files.uploadhandler import FileUploadHandler\n\ndef handler_implements_complete(handler_cls):\n    return handler_cls.file_complete is not FileUploadHandler.file_complete","typeGuard":"from django.core.files.uploadhandler import FileUploadHandler\n\ndef is_complete_upload_handler(handler_cls) -> bool:\n    return (handler_cls.receive_data_chunk is not FileUploadHandler.receive_data_chunk\n            and handler_cls.file_complete is not FileUploadHandler.file_complete)","tryCatchPattern":null,"preventionTips":["Ensure custom handlers return an UploadedFile from file_complete (or None to defer).","Cover both receive_data_chunk and file_complete in handler tests.","Prefer subclassing a concrete built-in handler."],"tags":["django","uploads","abstract-method","subclassing"],"backgroundTag":null,"analyzedSha":"b5388a3a80cafcce2e34196d8e81cf5b48eb33bb","analyzedAt":"2026-08-10T17:37:52.993Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}