mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-10-31 05:05:42 +00:00 
			
		
		
		
	Plugin load fix (#3768)
* Catch potential secondary PackageNotFoundError * Plugin template tweaks
This commit is contained in:
		| @@ -65,6 +65,7 @@ def handle_error(error, do_raise: bool = True, do_log: bool = True, log_name: st | ||||
|     """Handles an error and casts it as an IntegrationPluginError.""" | ||||
|     package_path = traceback.extract_tb(error.__traceback__)[-1].filename | ||||
|     install_path = sysconfig.get_paths()["purelib"] | ||||
|  | ||||
|     try: | ||||
|         package_name = pathlib.Path(package_path).relative_to(install_path).parts[0] | ||||
|     except ValueError: | ||||
| @@ -92,9 +93,10 @@ def handle_error(error, do_raise: bool = True, do_log: bool = True, log_name: st | ||||
|         log_error({package_name: str(error)}, **log_kwargs) | ||||
|  | ||||
|     if do_raise: | ||||
|         # do a straight raise if we are playing with enviroment variables at execution time, ignore the broken sample | ||||
|         # do a straight raise if we are playing with environment variables at execution time, ignore the broken sample | ||||
|         if settings.TESTING_ENV and package_name != 'integration.broken_sample' and isinstance(error, IntegrityError): | ||||
|             raise error  # pragma: no cover | ||||
|  | ||||
|         raise IntegrationPluginError(package_name, str(error)) | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -340,9 +340,14 @@ class InvenTreePlugin(VersionMixin, MixinBase, MetaBase): | ||||
|         # Try simple metadata lookup | ||||
|         try: | ||||
|             meta = metadata(cls.__name__) | ||||
|         # Simpel lookup did not work - get data from module | ||||
|         # Simple lookup did not work - get data from module | ||||
|         except PackageNotFoundError: | ||||
|  | ||||
|             try: | ||||
|                 meta = metadata(cls.__module__.split('.')[0]) | ||||
|             except PackageNotFoundError: | ||||
|                 # Not much information we can extract at this point | ||||
|                 return {} | ||||
|  | ||||
|         return { | ||||
|             'author': meta['Author-email'], | ||||
|   | ||||
| @@ -7,7 +7,7 @@ | ||||
|  | ||||
|  | ||||
| {% block heading %} | ||||
| {% blocktrans with name=plugin.human_name %}Plugin details for {{name}}{% endblocktrans %} | ||||
| {% trans "Plugin" %}: <em>{{ plugin.human_name }}</em> | ||||
| {% endblock %} | ||||
|  | ||||
| {% block content %} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user