Skip to content

Commit cff8ad0

Browse files
authored
Replace dynamic code execution with dynamic import in reports (senaite#2078)
* Replace dynamic code execution with dynamic import in reports * Use importlib instead of __import__ * Add changelog entry * Add missing line break in senaitesetup.py
1 parent 5b3b7d8 commit cff8ad0

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

CHANGES.rst

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Changelog
55
2.3.0 (unreleased)
66
------------------
77

8+
- #2078 Replace dynamic code execution with dynamic import in reports
89
- #2083 Lookup workflow action redirect URL from request first
910
- #2082 Include sample ID in form ID for lab, field and qc analyses listings
1011
- #2075 Allow to override logo and styles in new SENAITE Setup

src/bika/lims/browser/reports/__init__.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
# Copyright 2018-2021 by it's authors.
1919
# Some rights reserved, see README and LICENSE.
2020

21+
import importlib
2122
import os
2223

2324
from bika.lims import bikaMessageFactory as _
@@ -257,11 +258,11 @@ def __call__(self):
257258
else:
258259
module = "bika.lims.browser.reports.%s" % report_id
259260
try:
260-
exec ("from %s import Report" % module)
261+
Report = getattr(importlib.import_module(module), "Report")
261262
# required during error redirect: the report must have a copy of
262263
# additional_reports, because it is used as a surrogate view.
263264
Report.additional_reports = self.additional_reports
264-
except ImportError:
265+
except (ImportError, AttributeError):
265266
message = "Report %s.Report not found (shouldn't happen)" % module
266267
self.logger.error(message)
267268
self.context.plone_utils.addPortalMessage(message, 'error')

src/senaite/core/content/senaitesetup.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -171,4 +171,5 @@ def setSiteLogoCSS(self, value):
171171
"""Set the site logo
172172
"""
173173
mutator = self.mutator("site_logo_css")
174-
return mutator(self, value)
174+
return mutator(self, value)
175+

0 commit comments

Comments
 (0)