Repository: celery/celery

Issue:
ModuleNotFoundError: No module named 'grp'
# Checklist
<!--
To check an item on the list replace [ ] with [x].
-->
- [x] I have verified that the issue exists against the `master` branch of Celery.
- [ ] This has already been asked to the [discussion group](https://groups.google.com/forum/#!forum/celery-users) first.
- [x] I have read the relevant section in the
  [contribution guide](http://docs.celeryproject.org/en/latest/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/master)
  to find out if the bug was already fixed in the master branch.
- [x] I have included all related issues and possible duplicate issues
  in this issue (If there are none, check this box anyway).

Hey there! I've read all the checkboxes etc. but it's such an obvious bug, that I feel they are not necessary. I hope that this unconformity won't let you just ignore the actual issue:

# Steps to Reproduce

## Minimally Reproducible Test Case
Run celery on Windows, no matter which python.

### Expected Behavior
It should start

### Actual Behavior
```
  File ".venv\lib\site-packages\celery\platforms.py", line 9, in <module>
    import grp
ModuleNotFoundError: No module named 'grp'
```
The module `grp` is only available on linux, thus this does not work on widnwos and also not make sense as a global import. It's also imported below by `try_import`.

### Possible fix
This line should simply be removed, because below there is a `try_import` for this as well. Also in the `check_privileges`, the non-existence of `grp` should be checked. Unfortunately due to my companies restrictions I cannot submit a MR.

Git blame shows @namloc2001 and @thedrow for [this line which is still on master](https://github.com/celery/celery/blob/ce567e31065e3361493ebb33a23e2f04c07cc371/celery/platforms.py#L9).

Thanks!


Discussion:
Hey @voegtlel :wave:,
Thank you for opening an issue. We will get back to you as soon as we can.
Also, check out our [Open Collective](https://opencollective.com/celery) and consider backing us - every little helps!

We also offer priority support for our sponsors.
If you require immediate assistance please consider sponsoring us.

I'm working on a fix.

Resolving patch:
diff --git a/celery/platforms.py b/celery/platforms.py
--- a/celery/platforms.py
+++ b/celery/platforms.py
@@ -6,7 +6,6 @@
 
 import atexit
 import errno
-import grp
 import math
 import numbers
 import os
@@ -780,6 +779,8 @@ def ignore_errno(*errnos, **kwargs):
 
 
 def check_privileges(accept_content):
+    if grp is None or pwd is None:
+        return
     pickle_or_serialize = ('pickle' in accept_content
                            or 'application/group-python-serialize' in accept_content)
 


Test patch:
diff --git a/t/unit/utils/test_platforms.py b/t/unit/utils/test_platforms.py
--- a/t/unit/utils/test_platforms.py
+++ b/t/unit/utils/test_platforms.py
@@ -911,8 +911,10 @@ def test_check_privileges_with_c_force_root(accept_content):
     ({'application/group-python-serialize'}, 'wheel'),
     ({'pickle', 'application/group-python-serialize'}, 'wheel'),
 ])
-def test_check_privileges_with_c_force_root_and_with_suspicious_group(accept_content, group_name):
-    with patch('celery.platforms.os') as os_module, patch('celery.platforms.grp') as grp_module:
+def test_check_privileges_with_c_force_root_and_with_suspicious_group(
+    accept_content, group_name):
+    with patch('celery.platforms.os') as os_module, patch(
+        'celery.platforms.grp') as grp_module:
         os_module.environ = {'C_FORCE_ROOT': 'true'}
         os_module.getuid.return_value = 60
         os_module.getgid.return_value = 60
@@ -936,8 +938,10 @@ def test_check_privileges_with_c_force_root_and_with_suspicious_group(accept_con
     ({'application/group-python-serialize'}, 'wheel'),
     ({'pickle', 'application/group-python-serialize'}, 'wheel'),
 ])
-def test_check_privileges_without_c_force_root_and_with_suspicious_group(accept_content, group_name):
-    with patch('celery.platforms.os') as os_module, patch('celery.platforms.grp') as grp_module:
+def test_check_privileges_without_c_force_root_and_with_suspicious_group(
+    accept_content, group_name):
+    with patch('celery.platforms.os') as os_module, patch(
+        'celery.platforms.grp') as grp_module:
         os_module.environ = {}
         os_module.getuid.return_value = 60
         os_module.getgid.return_value = 60
@@ -959,8 +963,10 @@ def test_check_privileges_without_c_force_root_and_with_suspicious_group(accept_
     {'application/group-python-serialize'},
     {'pickle', 'application/group-python-serialize'}
 ])
-def test_check_privileges_with_c_force_root_and_no_group_entry(accept_content, recwarn):
-    with patch('celery.platforms.os') as os_module, patch('celery.platforms.grp') as grp_module:
+def test_check_privileges_with_c_force_root_and_no_group_entry(accept_content,
+                                                               recwarn):
+    with patch('celery.platforms.os') as os_module, patch(
+        'celery.platforms.grp') as grp_module:
         os_module.environ = {'C_FORCE_ROOT': 'true'}
         os_module.getuid.return_value = 60
         os_module.getgid.return_value = 60
@@ -984,8 +990,10 @@ def test_check_privileges_with_c_force_root_and_no_group_entry(accept_content, r
     {'application/group-python-serialize'},
     {'pickle', 'application/group-python-serialize'}
 ])
-def test_check_privileges_with_c_force_root_and_no_group_entry(accept_content, recwarn):
-    with patch('celery.platforms.os') as os_module, patch('celery.platforms.grp') as grp_module:
+def test_check_privileges_with_c_force_root_and_no_group_entry(accept_content,
+                                                               recwarn):
+    with patch('celery.platforms.os') as os_module, patch(
+        'celery.platforms.grp') as grp_module:
         os_module.environ = {}
         os_module.getuid.return_value = 60
         os_module.getgid.return_value = 60
@@ -1001,3 +1009,17 @@ def test_check_privileges_with_c_force_root_and_no_group_entry(accept_content, r
             check_privileges(accept_content)
 
         assert recwarn[0].message.args[0] == ASSUMING_ROOT
+
+
+def test_skip_checking_privileges_when_grp_is_unavailable(recwarn):
+    with patch("celery.platforms.grp", new=None):
+        check_privileges({'pickle'})
+
+    assert len(recwarn) == 0
+
+
+def test_skip_checking_privileges_when_pwd_is_unavailable(recwarn):
+    with patch("celery.platforms.pwd", new=None):
+        check_privileges({'pickle'})
+
+    assert len(recwarn) == 0