Repository: paperless-ngx/paperless-ngx

Issue:
mail import error in 2.00 beta rc1
### Description

mails with pdf attachments are not processed. have not changed anything since the last version
![error](https://github.com/paperless-ngx/paperless-ngx/assets/123741690/383e605d-f34e-4639-bd3a-5fbb155cb488)


### Steps to reproduce

send mail with attachment pdf
![email](https://github.com/paperless-ngx/paperless-ngx/assets/123741690/04fe1f19-c85d-40e7-a6c1-42ed72f20048)


### Webserver logs

```bash
[2023-11-15 07:00:01,496] [DEBUG] [paperless_mail] Account paperless@elgabo.ch: Processing 1 rule(s)

[2023-11-15 07:00:01,501] [DEBUG] [paperless_mail] Rule paperless@elgabo.ch.Paperless: Selecting folder INBOX

[2023-11-15 07:00:01,536] [DEBUG] [paperless_mail] Rule paperless@elgabo.ch.Paperless: Searching folder with criteria (SINCE 16-Oct-2023)

[2023-11-15 07:00:02,006] [DEBUG] [paperless_mail] Skipping mail <imap_tools.message.MailMessage object at 0x7f5cd177fe90>, already processed.

[2023-11-15 07:00:03,710] [DEBUG] [paperless_mail] Skipping mail <imap_tools.message.MailMessage object at 0x7f5cd1773f10>, already processed.

[2023-11-15 07:00:04,648] [DEBUG] [paperless_mail] Skipping mail <imap_tools.message.MailMessage object at 0x7f5cd149a510>, already processed.

[2023-11-15 07:00:05,025] [DEBUG] [paperless_mail] Rule paperless@elgabo.ch.Paperless: Processing mail Fwd: Abholschein 67074 - Gebäudebeschriftung from gabriel.wehle@elgabo.ch with 1 attachment(s)

[2023-11-15 07:00:05,539] [INFO] [paperless_mail] Rule paperless@elgabo.ch.Paperless: Consuming attachment Abholschein 67074 - Gebäudebeschriftung.pdf from mail Fwd: Abholschein 67074 - Gebäudebeschriftung from gabriel.wehle@elgabo.ch

[2023-11-15 07:00:06,596] [DEBUG] [paperless_mail] Rule paperless@elgabo.ch.Paperless: Processed 1 matching mail(s)

[2023-11-15 07:10:00,848] [DEBUG] [paperless_mail] Processing mail account paperless@elgabo.ch
```


### Browser logs

_No response_

### Paperless-ngx version

2.00 beta rc1

### Host OS

synology

### Installation method

Docker - official image

### Browser

Firefox

### Configuration changes

_No response_

### Other

_No response_


Discussion:
I cant reproduce this. Does the celery result give more info? Under the Django admin e.g. /admin/django_celery_results/taskresult/
Unfortunately I have the same issue. 
For me the django log says:

![image](https://github.com/paperless-ngx/paperless-ngx/assets/129696204/74d18814-11f2-4493-989d-825faef028c0)


Thanks for the help, just trying to track down where this is. one more and if not then I’ll let the backend team take a look, how about the processedmail eg /admin/paperless_mail/processedmail/ ?
Sure, glad I can help 😃 

The processedmail says:

`
Fehler:
Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/celery/app/trace.py", line 477, in trace_task
R = retval = fun(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/celery/app/trace.py", line 760, in __protected_call__
return self.run(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/paperless/src/documents/tasks.py", line 164, in consume_file
overrides.update(template_overrides)
File "/usr/src/paperless/src/documents/data_models.py", line 56, in update
self.tag_ids.extend(other.tag_ids)
TypeError: 'NoneType' object is not iterable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/django_celery_results/backends/database.py", line 292, in trigger_callback
ret = j(timeout=app.conf.result_chord_join_timeout, propagate=True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/celery/result.py", line 775, in join
value = result.get(
^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/celery/result.py", line 247, in get
self.maybe_throw(callback=callback)
File "/usr/local/lib/python3.11/site-packages/celery/result.py", line 365, in maybe_throw
self.throw(value, self._to_remote_traceback(tb))
File "/usr/local/lib/python3.11/site-packages/celery/result.py", line 358, in throw
self.on_ready.throw(*args, **kwargs)
File "/usr/local/lib/python3.11/site-packages/vine/promises.py", line 235, in throw
reraise(type(exc), exc, tb)
File "/usr/local/lib/python3.11/site-packages/vine/utils.py", line 27, in reraise
raise value
TypeError: 'NoneType' object is not iterable `

And another one:

`Status:
FAILED
Fehler:
Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/celery/app/trace.py", line 477, in trace_task
R = retval = fun(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/celery/app/trace.py", line 760, in __protected_call__
return self.run(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/paperless/src/documents/tasks.py", line 164, in consume_file
overrides.update(template_overrides)
File "/usr/src/paperless/src/documents/data_models.py", line 56, in update
self.tag_ids.extend(other.tag_ids)
TypeError: 'NoneType' object is not iterable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/django_celery_results/backends/database.py", line 292, in trigger_callback
ret = j(timeout=app.conf.result_chord_join_timeout, propagate=True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/celery/result.py", line 775, in join
value = result.get(
^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/celery/result.py", line 247, in get
self.maybe_throw(callback=callback)
File "/usr/local/lib/python3.11/site-packages/celery/result.py", line 365, in maybe_throw
self.throw(value, self._to_remote_traceback(tb))
File "/usr/local/lib/python3.11/site-packages/celery/result.py", line 358, in throw
self.on_ready.throw(*args, **kwargs)
File "/usr/local/lib/python3.11/site-packages/vine/promises.py", line 235, in throw
reraise(type(exc), exc, tb)
File "/usr/local/lib/python3.11/site-packages/vine/utils.py", line 27, in reraise
raise value
TypeError: 'NoneType' object is not iterable `
One of the overrides for tags is None, when updating from a template.  Not sure which, but we need some additional checks for the state in there.

Resolving patch:
diff --git a/src/documents/data_models.py b/src/documents/data_models.py
--- a/src/documents/data_models.py
+++ b/src/documents/data_models.py
@@ -48,31 +48,32 @@ def update(self, other: "DocumentMetadataOverrides") -> "DocumentMetadataOverrid
             self.storage_path_id = other.storage_path_id
         if self.owner_id is None:
             self.owner_id = other.owner_id
+
         # merge
-        # TODO: Handle the case where other is also None
         if self.tag_ids is None:
             self.tag_ids = other.tag_ids
-        else:
+        elif other.tag_ids is not None:
             self.tag_ids.extend(other.tag_ids)
+
         if self.view_users is None:
             self.view_users = other.view_users
-        else:
+        elif other.view_users is not None:
             self.view_users.extend(other.view_users)
+
         if self.view_groups is None:
             self.view_groups = other.view_groups
-        else:
+        elif other.view_groups is not None:
             self.view_groups.extend(other.view_groups)
+
         if self.change_users is None:
             self.change_users = other.change_users
-        else:
+        elif other.change_users is not None:
             self.change_users.extend(other.change_users)
+
         if self.change_groups is None:
             self.change_groups = other.change_groups
-        else:
-            self.change_groups = [
-                *self.change_groups,
-                *other.change_groups,
-            ]
+        elif other.change_groups is not None:
+            self.change_groups.extend(other.change_groups)
         return self
 
 
diff --git a/src/paperless_mail/mail.py b/src/paperless_mail/mail.py
--- a/src/paperless_mail/mail.py
+++ b/src/paperless_mail/mail.py
@@ -617,7 +617,7 @@ def _handle_message(self, message, rule: MailRule) -> int:
             f"{len(message.attachments)} attachment(s)",
         )
 
-        tag_ids = [tag.id for tag in rule.assign_tags.all()]
+        tag_ids: list[int] = [tag.id for tag in rule.assign_tags.all()]
         doc_type = rule.assign_document_type
 
         if (


Test patch: