summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorJacob Walls <jacobtylerwalls@gmail.com>2023-08-31 20:15:22 -0400
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2023-09-01 13:24:05 +0200
commitbcd80de8b5264d8c853bbd38bfeb02279a9b3799 (patch)
tree331cb588e34e4f655279bf5026e3b03fb56f5198 /django
parent9a9620dda649dcdb685662bbd9cb409bfeff4214 (diff)
Fixed #34778 -- Avoided importing modules in startapp/startproject.
Diffstat (limited to 'django')
-rw-r--r--django/core/management/templates.py10
1 files changed, 3 insertions, 7 deletions
diff --git a/django/core/management/templates.py b/django/core/management/templates.py
index c9cdc25566..633eed781d 100644
--- a/django/core/management/templates.py
+++ b/django/core/management/templates.py
@@ -5,7 +5,7 @@ import posixpath
import shutil
import stat
import tempfile
-from importlib import import_module
+from importlib.util import find_spec
from urllib.request import build_opener
import django
@@ -275,12 +275,8 @@ class TemplateCommand(BaseCommand):
type=name_or_dir,
)
)
- # Check it cannot be imported.
- try:
- import_module(name)
- except ImportError:
- pass
- else:
+ # Check that __spec__ doesn't exist.
+ if find_spec(name) is not None:
raise CommandError(
"'{name}' conflicts with the name of an existing Python "
"module and cannot be used as {an} {app} {type}. Please try "