Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle ImportError when installing country fixtures #30055

Merged
merged 2 commits into from
Mar 2, 2022

Conversation

sagarvora
Copy link
Collaborator

This change is required for moving regional functionality into a separate app. os.path.exists succeeds on erpnext/regional/india even after pulling ERPNext with India-specific code removed. This is because git does not remove empty folders when pulling changes.

Solution: Allow ImportError to pass silently instead of checking path. This would mean that install_country_fixtures will work only if country/setup.py or country/setup/__init__.py file is found. ImportError is the parent exception of ModuleNotFoundError, which is what was getting raised previously:

Traceback (most recent call last):
12:00:28 web.1            |   File "apps/erpnext/erpnext/setup/doctype/company/company.py", line 429, in install_country_fixtures
12:00:28 web.1            |     frappe.get_attr(module_name)(company, False)
12:00:28 web.1            |   File "apps/frappe/frappe/__init__.py", line 1224, in get_attr
12:00:28 web.1            |     return getattr(get_module(modulename), methodname)
12:00:28 web.1            |   File "apps/frappe/frappe/__init__.py", line 1000, in get_module
12:00:28 web.1            |     return importlib.import_module(modulename)
12:00:28 web.1            |   File "/usr/lib/python3.9/importlib/__init__.py", line 127, in import_module
12:00:28 web.1            |     return _bootstrap._gcd_import(name[level:], package, level)
12:00:28 web.1            |   File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
12:00:28 web.1            |   File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
12:00:28 web.1            |   File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked
12:00:28 web.1            | ModuleNotFoundError: No module named 'erpnext.regional.india.setup'

@github-actions github-actions bot added the needs-tests This PR needs automated unit-tests. label Mar 2, 2022
@sagarvora sagarvora added Skip Manual Testing The changes in this PR does not require manual testing and removed needs-tests This PR needs automated unit-tests. labels Mar 2, 2022
@ankush ankush merged commit 90af40a into frappe:develop Mar 2, 2022
@ankush
Copy link
Member

ankush commented Mar 2, 2022

Doesn't require backport I think.

Add label if reqd.

@sagarvora sagarvora deleted the fix-install-fixtures branch March 2, 2022 08:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Skip Manual Testing The changes in this PR does not require manual testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants