We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
New Django task with transaction atomic, return `None` instead of the task UUID
<!--
Please fill this template entirely and do not erase parts of it.
We reserve the right to close without a response
bug reports which are incomplete.
-->
# Checklist
<!--
To check an item on the list replace [ ] with [x].
-->
- [x] I have verified that the issue exists against the `main` branch of Celery.
- [ ] This has already been asked to the [discussions forum](https://github.com/celery/celery/discussions) first.
- [x] I have read the relevant section in the
  [contribution guide](https://docs.celeryq.dev/en/main/contributing.html#other-bugs)
  on reporting bugs.
- [x] I have checked the [issues list](https://github.com/celery/celery/issues?q=is%3Aissue+label%3A%22Issue+Type%3A+Bug+Report%22+-label%3A%22Category%3A+Documentation%22)
  for similar or identical bug reports.
- [x] I have checked the [pull requests list](https://github.com/celery/celery/pulls?q=is%3Apr+label%3A%22PR+Type%3A+Bugfix%22+-label%3A%22Category%3A+Documentation%22)
  for existing proposed fixes.
- [x] I have checked the [commit log](https://github.com/celery/celery/commits/main)
  to find out if the bug was already fixed in the main branch.
- [ ] I have included all related issues and possible duplicate issues
  in this issue (If there are none, check this box anyway).
- [ ] I have tried to reproduce the issue with [pytest-celery](https://docs.celeryq.dev/projects/pytest-celery/en/latest/userguide/celery-bug-report.html) and added the reproduction script below.

## Mandatory Debugging Information

- [ ] I have included the output of ``celery -A proj report`` in the issue.
    (if you are not able to do this, then at least specify the Celery
     version affected).
- [x] I have verified that the issue exists against the `main` branch of Celery.
- [ ] I have included the contents of ``pip freeze`` in the issue.
- [ ] I have included all the versions of all the external dependencies required
  to reproduce this bug.

## Optional Debugging Information
<!--
Try some of the below if you think they are relevant.
It will help us figure out the scope of the bug and how many users it affects.
-->
- [ ] I have tried reproducing the issue on more than one Python version
  and/or implementation.
- [ ] I have tried reproducing the issue on more than one message broker and/or
  result backend.
- [ ] I have tried reproducing the issue on more than one version of the message
  broker and/or result backend.
- [ ] I have tried reproducing the issue on more than one operating system.
- [ ] I have tried reproducing the issue on more than one workers pool.
- [ ] I have tried reproducing the issue with autoscaling, retries,
  ETA/Countdown & rate limits disabled.
- [ ] I have tried reproducing the issue after downgrading
  and/or upgrading Celery and its dependencies.

## Related Issues and Possible Duplicates
<!--
Please make sure to search and mention any related issues
or possible duplicates to this issue as requested by the checklist above.

This may or may not include issues in other repositories that the Celery project
maintains or other repositories that are dependencies of Celery.

If you don't know how to mention issues, please refer to Github's documentation
on the subject: https://help.github.com/en/articles/autolinked-references-and-urls#issues-and-pull-requests
-->

#### Related Issues

- None

#### Possible Duplicates

- None

## Environment & Settings
<!-- Include the contents of celery --version below -->
**Celery version**:
5.4.0
<!-- Include the output of celery -A proj report below -->
<details>
<summary><b><code>celery report</code> Output:</b></summary>
<p>

```
```

</p>
</details>

# Steps to Reproduce

## Required Dependencies
<!-- Please fill the required dependencies to reproduce this issue -->
- **Minimal Python Version**: N/A or Unknown
- **Minimal Celery Version**:5.4.0
- **Minimal Kombu Version**: N/A or Unknown
- **Minimal Broker Version**: N/A or Unknown
- **Minimal Result Backend Version**: N/A or Unknown
- **Minimal OS and/or Kernel Version**: N/A or Unknown
- **Minimal Broker Client Version**: N/A or Unknown
- **Minimal Result Backend Client Version**: N/A or Unknown

### Python Packages
<!-- Please fill the contents of pip freeze below -->
<details>
<summary><b><code>pip freeze</code> Output:</b></summary>
<p>

```
```

</p>
</details>

### Other Dependencies
<!--
Please provide system dependencies, configuration files
and other dependency information if applicable
-->
<details>
<p>
N/A
</p>
</details>

## Minimally Reproducible Test Case
<!--
Please provide a reproducible test case.
Refer to the Reporting Bugs section in our contribution guide.

We prefer submitting test cases in the form of a PR to our integration test suite.
If you can provide one, please mention the PR number below.
If not, please attach the most minimal code example required to reproduce the issue below.
If the test case is too large, please include a link to a gist or a repository below.

Alternatively, the pytest-celery plugin can be used to create standalone reproduction scripts
that can be added to this report. See the pytest-celery documentation for more information at
pytest-celery.readthedocs.io
-->

<details>
<p>

```python
```

</p>
</details>

# Expected Behavior
<!-- Describe in detail what you expect to happen -->
Return the correct task uuid like before the release 5.4.0
# Actual Behavior
<!--
Describe in detail what actually happened.
Please include a backtrace and surround it with triple backticks (```).
In addition, include the Celery daemon logs, the broker logs,
the result backend logs and system logs below if they will help us debug
the issue.
-->
## Issue ⚠️ 

`AttributeError: 'NoneType' object has no attribute 'id'

```python
@app.task
def example_task(id):
       try:
            obj = Model.objects.get(id=id)
            obj.number += 1
            obj.save(update_fields=["number"])
       except ObjectDoesNotExist as e:
            return "str(e)"


task = example_task.delay_on_commit(example_model_instance.id)
example_model_instance.task_uuid = task.id
```

Literally basic minimal task 😄 , but the `delay_on_commit` not return the task uuid for `AsyncResult`, and in my case django raise excpetion (rightly) AttributeError -> maybe the task with `delay_on_commit` return `None`?

docs:
```python
class DjangoTask(Task):
    """
    Extend the base :class:`~celery.app.task.Task` for Django.

    Provide a nicer API to trigger tasks at the end of the DB transaction.
    """

    def delay_on_commit(self, *args, **kwargs):
        """Call :meth:`~celery.app.task.Task.delay` with Django's ``on_commit()``."""
        return transaction.on_commit(functools.partial(self.delay, *args, **kwargs))

    def apply_async_on_commit(self, *args, **kwargs):
        """Call :meth:`~celery.app.task.Task.apply_async` with Django's ``on_commit()``."""
        return transaction.on_commit(functools.partial(self.apply_async, *args, **kwargs))
```

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `celery/contrib/django/task.py`
Content:
```
1 import functools
2 
3 from django.db import transaction
4 
5 from celery.app.task import Task
6 
7 
8 class DjangoTask(Task):
9     """
10     Extend the base :class:`~celery.app.task.Task` for Django.
11 
12     Provide a nicer API to trigger tasks at the end of the DB transaction.
13     """
14 
15     def delay_on_commit(self, *args, **kwargs):
16         """Call :meth:`~celery.app.task.Task.delay` with Django's ``on_commit()``."""
17         return transaction.on_commit(functools.partial(self.delay, *args, **kwargs))
18 
19     def apply_async_on_commit(self, *args, **kwargs):
20         """Call :meth:`~celery.app.task.Task.apply_async` with Django's ``on_commit()``."""
21         return transaction.on_commit(functools.partial(self.apply_async, *args, **kwargs))
22
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/celery/contrib/django/task.py b/celery/contrib/django/task.py
--- a/celery/contrib/django/task.py
+++ b/celery/contrib/django/task.py
@@ -12,10 +12,10 @@
     Provide a nicer API to trigger tasks at the end of the DB transaction.
     """
 
-    def delay_on_commit(self, *args, **kwargs):
+    def delay_on_commit(self, *args, **kwargs) -> None:
         """Call :meth:`~celery.app.task.Task.delay` with Django's ``on_commit()``."""
-        return transaction.on_commit(functools.partial(self.delay, *args, **kwargs))
+        transaction.on_commit(functools.partial(self.delay, *args, **kwargs))
 
-    def apply_async_on_commit(self, *args, **kwargs):
+    def apply_async_on_commit(self, *args, **kwargs) -> None:
         """Call :meth:`~celery.app.task.Task.apply_async` with Django's ``on_commit()``."""
-        return transaction.on_commit(functools.partial(self.apply_async, *args, **kwargs))
+        transaction.on_commit(functools.partial(self.apply_async, *args, **kwargs))

{"golden_diff": "diff --git a/celery/contrib/django/task.py b/celery/contrib/django/task.py\n--- a/celery/contrib/django/task.py\n+++ b/celery/contrib/django/task.py\n@@ -12,10 +12,10 @@\n     Provide a nicer API to trigger tasks at the end of the DB transaction.\n     \"\"\"\n \n-    def delay_on_commit(self, *args, **kwargs):\n+    def delay_on_commit(self, *args, **kwargs) -> None:\n         \"\"\"Call :meth:`~celery.app.task.Task.delay` with Django's ``on_commit()``.\"\"\"\n-        return transaction.on_commit(functools.partial(self.delay, *args, **kwargs))\n+        transaction.on_commit(functools.partial(self.delay, *args, **kwargs))\n \n-    def apply_async_on_commit(self, *args, **kwargs):\n+    def apply_async_on_commit(self, *args, **kwargs) -> None:\n         \"\"\"Call :meth:`~celery.app.task.Task.apply_async` with Django's ``on_commit()``.\"\"\"\n-        return transaction.on_commit(functools.partial(self.apply_async, *args, **kwargs))\n+        transaction.on_commit(functools.partial(self.apply_async, *args, **kwargs))\n", "issue": "New Django task with transaction atomic, return `None` instead of the task UUID\n<!--\r\nPlease fill this template entirely and do not erase parts of it.\r\nWe reserve the right to close without a response\r\nbug reports which are incomplete.\r\n-->\r\n# Checklist\r\n<!--\r\nTo check an item on the list replace [ ] with [x].\r\n-->\r\n- [x] I have verified that the issue exists against the `main` branch of Celery.\r\n- [ ] This has already been asked to the [discussions forum](https://github.com/celery/celery/discussions) first.\r\n- [x] I have read the relevant section in the\r\n  [contribution guide](https://docs.celeryq.dev/en/main/contributing.html#other-bugs)\r\n  on reporting bugs.\r\n- [x] I have checked the [issues list](https://github.com/celery/celery/issues?q=is%3Aissue+label%3A%22Issue+Type%3A+Bug+Report%22+-label%3A%22Category%3A+Documentation%22)\r\n  for similar or identical bug reports.\r\n- [x] I have checked the [pull requests list](https://github.com/celery/celery/pulls?q=is%3Apr+label%3A%22PR+Type%3A+Bugfix%22+-label%3A%22Category%3A+Documentation%22)\r\n  for existing proposed fixes.\r\n- [x] I have checked the [commit log](https://github.com/celery/celery/commits/main)\r\n  to find out if the bug was already fixed in the main branch.\r\n- [ ] I have included all related issues and possible duplicate issues\r\n  in this issue (If there are none, check this box anyway).\r\n- [ ] I have tried to reproduce the issue with [pytest-celery](https://docs.celeryq.dev/projects/pytest-celery/en/latest/userguide/celery-bug-report.html) and added the reproduction script below.\r\n\r\n## Mandatory Debugging Information\r\n\r\n- [ ] I have included the output of ``celery -A proj report`` in the issue.\r\n    (if you are not able to do this, then at least specify the Celery\r\n     version affected).\r\n- [x] I have verified that the issue exists against the `main` branch of Celery.\r\n- [ ] I have included the contents of ``pip freeze`` in the issue.\r\n- [ ] I have included all the versions of all the external dependencies required\r\n  to reproduce this bug.\r\n\r\n## Optional Debugging Information\r\n<!--\r\nTry some of the below if you think they are relevant.\r\nIt will help us figure out the scope of the bug and how many users it affects.\r\n-->\r\n- [ ] I have tried reproducing the issue on more than one Python version\r\n  and/or implementation.\r\n- [ ] I have tried reproducing the issue on more than one message broker and/or\r\n  result backend.\r\n- [ ] I have tried reproducing the issue on more than one version of the message\r\n  broker and/or result backend.\r\n- [ ] I have tried reproducing the issue on more than one operating system.\r\n- [ ] I have tried reproducing the issue on more than one workers pool.\r\n- [ ] I have tried reproducing the issue with autoscaling, retries,\r\n  ETA/Countdown & rate limits disabled.\r\n- [ ] I have tried reproducing the issue after downgrading\r\n  and/or upgrading Celery and its dependencies.\r\n\r\n## Related Issues and Possible Duplicates\r\n<!--\r\nPlease make sure to search and mention any related issues\r\nor possible duplicates to this issue as requested by the checklist above.\r\n\r\nThis may or may not include issues in other repositories that the Celery project\r\nmaintains or other repositories that are dependencies of Celery.\r\n\r\nIf you don't know how to mention issues, please refer to Github's documentation\r\non the subject: https://help.github.com/en/articles/autolinked-references-and-urls#issues-and-pull-requests\r\n-->\r\n\r\n#### Related Issues\r\n\r\n- None\r\n\r\n#### Possible Duplicates\r\n\r\n- None\r\n\r\n## Environment & Settings\r\n<!-- Include the contents of celery --version below -->\r\n**Celery version**:\r\n5.4.0\r\n<!-- Include the output of celery -A proj report below -->\r\n<details>\r\n<summary><b><code>celery report</code> Output:</b></summary>\r\n<p>\r\n\r\n```\r\n```\r\n\r\n</p>\r\n</details>\r\n\r\n# Steps to Reproduce\r\n\r\n## Required Dependencies\r\n<!-- Please fill the required dependencies to reproduce this issue -->\r\n- **Minimal Python Version**: N/A or Unknown\r\n- **Minimal Celery Version**:5.4.0\r\n- **Minimal Kombu Version**: N/A or Unknown\r\n- **Minimal Broker Version**: N/A or Unknown\r\n- **Minimal Result Backend Version**: N/A or Unknown\r\n- **Minimal OS and/or Kernel Version**: N/A or Unknown\r\n- **Minimal Broker Client Version**: N/A or Unknown\r\n- **Minimal Result Backend Client Version**: N/A or Unknown\r\n\r\n### Python Packages\r\n<!-- Please fill the contents of pip freeze below -->\r\n<details>\r\n<summary><b><code>pip freeze</code> Output:</b></summary>\r\n<p>\r\n\r\n```\r\n```\r\n\r\n</p>\r\n</details>\r\n\r\n### Other Dependencies\r\n<!--\r\nPlease provide system dependencies, configuration files\r\nand other dependency information if applicable\r\n-->\r\n<details>\r\n<p>\r\nN/A\r\n</p>\r\n</details>\r\n\r\n## Minimally Reproducible Test Case\r\n<!--\r\nPlease provide a reproducible test case.\r\nRefer to the Reporting Bugs section in our contribution guide.\r\n\r\nWe prefer submitting test cases in the form of a PR to our integration test suite.\r\nIf you can provide one, please mention the PR number below.\r\nIf not, please attach the most minimal code example required to reproduce the issue below.\r\nIf the test case is too large, please include a link to a gist or a repository below.\r\n\r\nAlternatively, the pytest-celery plugin can be used to create standalone reproduction scripts\r\nthat can be added to this report. See the pytest-celery documentation for more information at\r\npytest-celery.readthedocs.io\r\n-->\r\n\r\n<details>\r\n<p>\r\n\r\n```python\r\n```\r\n\r\n</p>\r\n</details>\r\n\r\n# Expected Behavior\r\n<!-- Describe in detail what you expect to happen -->\r\nReturn the correct task uuid like before the release 5.4.0\r\n# Actual Behavior\r\n<!--\r\nDescribe in detail what actually happened.\r\nPlease include a backtrace and surround it with triple backticks (```).\r\nIn addition, include the Celery daemon logs, the broker logs,\r\nthe result backend logs and system logs below if they will help us debug\r\nthe issue.\r\n-->\r\n## Issue \u26a0\ufe0f \r\n\r\n`AttributeError: 'NoneType' object has no attribute 'id'\r\n\r\n```python\r\n@app.task\r\ndef example_task(id):\r\n       try:\r\n            obj = Model.objects.get(id=id)\r\n            obj.number += 1\r\n            obj.save(update_fields=[\"number\"])\r\n       except ObjectDoesNotExist as e:\r\n            return \"str(e)\"\r\n\r\n\r\ntask = example_task.delay_on_commit(example_model_instance.id)\r\nexample_model_instance.task_uuid = task.id\r\n```\r\n\r\nLiterally basic minimal task \ud83d\ude04 , but the `delay_on_commit` not return the task uuid for `AsyncResult`, and in my case django raise excpetion (rightly) AttributeError -> maybe the task with `delay_on_commit` return `None`?\r\n\r\ndocs:\r\n```python\r\nclass DjangoTask(Task):\r\n    \"\"\"\r\n    Extend the base :class:`~celery.app.task.Task` for Django.\r\n\r\n    Provide a nicer API to trigger tasks at the end of the DB transaction.\r\n    \"\"\"\r\n\r\n    def delay_on_commit(self, *args, **kwargs):\r\n        \"\"\"Call :meth:`~celery.app.task.Task.delay` with Django's ``on_commit()``.\"\"\"\r\n        return transaction.on_commit(functools.partial(self.delay, *args, **kwargs))\r\n\r\n    def apply_async_on_commit(self, *args, **kwargs):\r\n        \"\"\"Call :meth:`~celery.app.task.Task.apply_async` with Django's ``on_commit()``.\"\"\"\r\n        return transaction.on_commit(functools.partial(self.apply_async, *args, **kwargs))\r\n```\n", "before_files": [{"content": "import functools\n\nfrom django.db import transaction\n\nfrom celery.app.task import Task\n\n\nclass DjangoTask(Task):\n    \"\"\"\n    Extend the base :class:`~celery.app.task.Task` for Django.\n\n    Provide a nicer API to trigger tasks at the end of the DB transaction.\n    \"\"\"\n\n    def delay_on_commit(self, *args, **kwargs):\n        \"\"\"Call :meth:`~celery.app.task.Task.delay` with Django's ``on_commit()``.\"\"\"\n        return transaction.on_commit(functools.partial(self.delay, *args, **kwargs))\n\n    def apply_async_on_commit(self, *args, **kwargs):\n        \"\"\"Call :meth:`~celery.app.task.Task.apply_async` with Django's ``on_commit()``.\"\"\"\n        return transaction.on_commit(functools.partial(self.apply_async, *args, **kwargs))\n", "path": "celery/contrib/django/task.py"}], "after_files": [{"content": "import functools\n\nfrom django.db import transaction\n\nfrom celery.app.task import Task\n\n\nclass DjangoTask(Task):\n    \"\"\"\n    Extend the base :class:`~celery.app.task.Task` for Django.\n\n    Provide a nicer API to trigger tasks at the end of the DB transaction.\n    \"\"\"\n\n    def delay_on_commit(self, *args, **kwargs) -> None:\n        \"\"\"Call :meth:`~celery.app.task.Task.delay` with Django's ``on_commit()``.\"\"\"\n        transaction.on_commit(functools.partial(self.delay, *args, **kwargs))\n\n    def apply_async_on_commit(self, *args, **kwargs) -> None:\n        \"\"\"Call :meth:`~celery.app.task.Task.apply_async` with Django's ``on_commit()``.\"\"\"\n        transaction.on_commit(functools.partial(self.apply_async, *args, **kwargs))\n", "path": "celery/contrib/django/task.py"}]}