Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
98da4089
Kaydet (Commit)
98da4089
authored
Eki 31, 2014
tarafından
Markus Holtermann
Kaydeden (comit)
Tim Graham
Eki 31, 2014
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #23670 -- Prevented partial import state during module autodiscovery
Thanks kostko for the report.
üst
c0c1bb9e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
18 deletions
+48
-18
module_loading.py
django/utils/module_loading.py
+18
-18
another_good_module.py
tests/utils_tests/test_module/another_good_module.py
+5
-0
test_module_loading.py
tests/utils_tests/test_module_loading.py
+25
-0
No files found.
django/utils/module_loading.py
Dosyayı görüntüle @
98da4089
...
...
@@ -64,26 +64,26 @@ def autodiscover_modules(*args, **kwargs):
register_to
=
kwargs
.
get
(
'register_to'
)
for
app_config
in
apps
.
get_app_configs
():
# Attempt to import the app's module.
try
:
if
register_to
:
before_import_registry
=
copy
.
copy
(
register_to
.
_registry
)
for
module_to_search
in
args
:
# Attempt to import the app's module.
try
:
if
register_to
:
before_import_registry
=
copy
.
copy
(
register_to
.
_registry
)
for
module_to_search
in
args
:
import_module
(
'
%
s.
%
s'
%
(
app_config
.
name
,
module_to_search
))
except
:
# Reset the model registry to the state before the last import as
# this import will have to reoccur on the next request and this
# could raise NotRegistered and AlreadyRegistered exceptions
#
(see #8245).
if
register_to
:
register_to
.
_registry
=
before_import_registry
# Decide whether to bubble up this error. If the app just
# doesn't have an admin module
, we can ignore the error
# attempting to import it, otherwise we want it to bubble up.
if
module_has_submodule
(
app_config
.
module
,
module_to_search
):
raise
except
:
# Reset the registry to the state before the last import
# as this import will have to reoccur on the next request and
# this could raise NotRegistered and AlreadyRegistered
# exceptions
(see #8245).
if
register_to
:
register_to
.
_registry
=
before_import_registry
# Decide whether to bubble up this error. If the app just
# doesn't have the module in question
, we can ignore the error
# attempting to import it, otherwise we want it to bubble up.
if
module_has_submodule
(
app_config
.
module
,
module_to_search
):
raise
if
sys
.
version_info
[:
2
]
>=
(
3
,
3
):
...
...
tests/utils_tests/test_module/another_good_module.py
Dosyayı görüntüle @
98da4089
from
.
import
site
content
=
'Another Good Module'
site
.
_registry
.
update
({
'lorem'
:
'ipsum'
,
})
tests/utils_tests/test_module_loading.py
Dosyayı görüntüle @
98da4089
...
...
@@ -155,6 +155,15 @@ class ModuleImportTestCase(IgnoreDeprecationWarningsMixin, unittest.TestCase):
@modify_settings
(
INSTALLED_APPS
=
{
'append'
:
'utils_tests.test_module'
})
class
AutodiscoverModulesTestCase
(
SimpleTestCase
):
def
tearDown
(
self
):
sys
.
path_importer_cache
.
clear
()
sys
.
modules
.
pop
(
'utils_tests.test_module.another_bad_module'
,
None
)
sys
.
modules
.
pop
(
'utils_tests.test_module.another_good_module'
,
None
)
sys
.
modules
.
pop
(
'utils_tests.test_module.bad_module'
,
None
)
sys
.
modules
.
pop
(
'utils_tests.test_module.good_module'
,
None
)
sys
.
modules
.
pop
(
'utils_tests.test_module'
,
None
)
def
test_autodiscover_modules_found
(
self
):
autodiscover_modules
(
'good_module'
)
...
...
@@ -172,12 +181,28 @@ class AutodiscoverModulesTestCase(SimpleTestCase):
def
test_autodiscover_modules_several_found
(
self
):
autodiscover_modules
(
'good_module'
,
'another_good_module'
)
def
test_autodiscover_modules_several_found_with_registry
(
self
):
from
.test_module
import
site
autodiscover_modules
(
'good_module'
,
'another_good_module'
,
register_to
=
site
)
self
.
assertEqual
(
site
.
_registry
,
{
'lorem'
:
'ipsum'
})
def
test_validate_registry_keeps_intact
(
self
):
from
.test_module
import
site
with
six
.
assertRaisesRegex
(
self
,
Exception
,
"Some random exception."
):
autodiscover_modules
(
'another_bad_module'
,
register_to
=
site
)
self
.
assertEqual
(
site
.
_registry
,
{})
def
test_validate_registry_resets_after_erroneous_module
(
self
):
from
.test_module
import
site
with
six
.
assertRaisesRegex
(
self
,
Exception
,
"Some random exception."
):
autodiscover_modules
(
'another_good_module'
,
'another_bad_module'
,
register_to
=
site
)
self
.
assertEqual
(
site
.
_registry
,
{
'lorem'
:
'ipsum'
})
def
test_validate_registry_resets_after_missing_module
(
self
):
from
.test_module
import
site
autodiscover_modules
(
'does_not_exist'
,
'another_good_module'
,
'does_not_exist2'
,
register_to
=
site
)
self
.
assertEqual
(
site
.
_registry
,
{
'lorem'
:
'ipsum'
})
class
ProxyFinder
(
object
):
def
__init__
(
self
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment