Skip to content

Invoice designer module#4

Draft
mborchuk wants to merge 2 commits intomainfrom
template-generator
Draft

Invoice designer module#4
mborchuk wants to merge 2 commits intomainfrom
template-generator

Conversation

@mborchuk
Copy link
Copy Markdown
Owner

@mborchuk mborchuk commented Apr 1, 2026

No description provided.

@mborchuk mborchuk self-assigned this Apr 1, 2026
'description': 'Description',
'quantity': 'Qty',
'unit_price': 'Unit Price',
'total': 'Total',

Check warning

Code scanning / CodeQL

Duplicate key in dict literal Warning

Dictionary key 'total' is subsequently
overwritten
.

Copilot Autofix

AI 1 day ago

To fix the problem, the duplicated key in the labels dictionary should be removed so that each key appears only once. Since both 'total' entries map to the same string 'Total', the safest, behavior‑preserving fix is simply to delete one of the duplicate lines and keep the other.

Concretely, in modules/invoice_designer/index.py, inside the DEFAULT_CONFIG dict, under the 'labels' sub-dictionary, remove one of the two 'total': 'Total', lines. The minimal and clearest change is to delete the earlier occurrence on line 67 and retain the later one on line 70, or vice versa; either choice yields identical runtime behavior. No new methods, imports, or definitions are required; this is just a cleanup of the literal.

Suggested changeset 1
modules/invoice_designer/index.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/modules/invoice_designer/index.py b/modules/invoice_designer/index.py
--- a/modules/invoice_designer/index.py
+++ b/modules/invoice_designer/index.py
@@ -64,7 +64,6 @@
         'description': 'Description',
         'quantity': 'Qty',
         'unit_price': 'Unit Price',
-        'total': 'Total',
         'subtotal': 'Subtotal',
         'tax': 'IVA',
         'total': 'Total',
EOF
@@ -64,7 +64,6 @@
'description': 'Description',
'quantity': 'Qty',
'unit_price': 'Unit Price',
'total': 'Total',
'subtotal': 'Subtotal',
'tax': 'IVA',
'total': 'Total',
Copilot is powered by AI and may make mistakes. Always verify output.
name = request.form.get('name', '').strip()
if not name:
flash('Template name is required.', 'danger')
return redirect(request.url)

Check warning

Code scanning / CodeQL

URL redirection from remote source Medium

Untrusted URL redirection depends on a
user-provided value
.

Copilot Autofix

AI 1 day ago

In general, to fix untrusted URL redirection you should avoid redirecting to URLs that are derived directly from the incoming request or user input. Instead, redirect to a fixed internal endpoint (e.g. url_for('invoice_designer.designer_index') or the current view’s URL), or validate that the redirect target is a safe, relative URL without an external host or scheme.

For this code, the minimal and safest fix that doesn’t change intended functionality is:

  • Replace redirect(request.url) with a redirect to the current designer page using url_for.
  • In both places where request.url is used (line 316 for missing name, and line 416 in the exception handler), route the user back to the designer index page instead of echoing the full incoming URL.

The underlying behavior remains essentially the same: on validation failure or error, the user is taken back to the designer UI. But we break the direct dependency on a potentially tainted URL. No new helpers or imports are needed because url_for and redirect are already imported at line 20.

Concretely:

  • In modules/invoice_designer/index.py, inside _save_template, change:
    • Line 316: return redirect(request.url)return redirect(url_for('invoice_designer.designer_index'))
    • Line 416: return redirect(request.url)return redirect(url_for('invoice_designer.designer_index'))
Suggested changeset 1
modules/invoice_designer/index.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/modules/invoice_designer/index.py b/modules/invoice_designer/index.py
--- a/modules/invoice_designer/index.py
+++ b/modules/invoice_designer/index.py
@@ -313,7 +313,7 @@
             name = request.form.get('name', '').strip()
             if not name:
                 flash('Template name is required.', 'danger')
-                return redirect(request.url)
+                return redirect(url_for('invoice_designer.designer_index'))
 
             # If submitted from JSON editor, use raw JSON directly
             raw_json = request.form.get('config_json_raw', '').strip()
@@ -413,7 +413,7 @@
         except Exception as e:
             self._db.session.rollback()
             flash(f'Error: {e}', 'danger')
-            return redirect(request.url)
+            return redirect(url_for('invoice_designer.designer_index'))
 
     def _delete_template(self, id):
         tpl = self.InvoiceTemplate.query.get_or_404(id)
EOF
@@ -313,7 +313,7 @@
name = request.form.get('name', '').strip()
if not name:
flash('Template name is required.', 'danger')
return redirect(request.url)
return redirect(url_for('invoice_designer.designer_index'))

# If submitted from JSON editor, use raw JSON directly
raw_json = request.form.get('config_json_raw', '').strip()
@@ -413,7 +413,7 @@
except Exception as e:
self._db.session.rollback()
flash(f'Error: {e}', 'danger')
return redirect(request.url)
return redirect(url_for('invoice_designer.designer_index'))

def _delete_template(self, id):
tpl = self.InvoiceTemplate.query.get_or_404(id)
Copilot is powered by AI and may make mistakes. Always verify output.
except Exception as e:
self._db.session.rollback()
flash(f'Error: {e}', 'danger')
return redirect(request.url)

Check warning

Code scanning / CodeQL

URL redirection from remote source Medium

Untrusted URL redirection depends on a
user-provided value
.

Copilot Autofix

AI 1 day ago

In general, the issue is fixed by not using request.url (which is derived from the incoming request, including user-controlled pieces) directly as a redirect target. Instead, redirect only to fixed, server-defined routes (for example using url_for) or to rigorously validated relative paths.

In this file, request.url is only used in _save_template when a validation error occurs (missing template name) and when an exception is caught. In both cases, we conceptually want to send the user back to the template form. Rather than redirecting to whatever URL was requested, we should redirect to the explicit create or edit endpoints. We can distinguish these cases using the tpl argument:

  • If tpl is None, we are creating a template, so redirect to the create route (e.g., invoice_designer.designer_create).
  • If tpl is not None, we are editing an existing template, so redirect to the edit route invoice_designer.designer_edit, passing id=tpl.id.

Concretely:

  • Replace redirect(request.url) at line 316 with a conditional redirect to the appropriate route via url_for.
  • Similarly, replace redirect(request.url) at line 416 in the except block with the same conditional redirect logic.
  • Use the already-imported url_for and redirect from Flask; no new imports are needed.
  • Keep the surrounding behavior (flashes, DB rollback) unchanged.
Suggested changeset 1
modules/invoice_designer/index.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/modules/invoice_designer/index.py b/modules/invoice_designer/index.py
--- a/modules/invoice_designer/index.py
+++ b/modules/invoice_designer/index.py
@@ -313,7 +313,10 @@
             name = request.form.get('name', '').strip()
             if not name:
                 flash('Template name is required.', 'danger')
-                return redirect(request.url)
+                if tpl:
+                    return redirect(url_for('invoice_designer.designer_edit', id=tpl.id))
+                else:
+                    return redirect(url_for('invoice_designer.designer_create'))
 
             # If submitted from JSON editor, use raw JSON directly
             raw_json = request.form.get('config_json_raw', '').strip()
@@ -413,7 +416,10 @@
         except Exception as e:
             self._db.session.rollback()
             flash(f'Error: {e}', 'danger')
-            return redirect(request.url)
+            if tpl:
+                return redirect(url_for('invoice_designer.designer_edit', id=tpl.id))
+            else:
+                return redirect(url_for('invoice_designer.designer_create'))
 
     def _delete_template(self, id):
         tpl = self.InvoiceTemplate.query.get_or_404(id)
EOF
@@ -313,7 +313,10 @@
name = request.form.get('name', '').strip()
if not name:
flash('Template name is required.', 'danger')
return redirect(request.url)
if tpl:
return redirect(url_for('invoice_designer.designer_edit', id=tpl.id))
else:
return redirect(url_for('invoice_designer.designer_create'))

# If submitted from JSON editor, use raw JSON directly
raw_json = request.form.get('config_json_raw', '').strip()
@@ -413,7 +416,10 @@
except Exception as e:
self._db.session.rollback()
flash(f'Error: {e}', 'danger')
return redirect(request.url)
if tpl:
return redirect(url_for('invoice_designer.designer_edit', id=tpl.id))
else:
return redirect(url_for('invoice_designer.designer_create'))

def _delete_template(self, id):
tpl = self.InvoiceTemplate.query.get_or_404(id)
Copilot is powered by AI and may make mistakes. Always verify output.
'path': '__designer__',
'_designer_id': tpl.id,
})
except Exception:

Check notice

Code scanning / CodeQL

Empty except Note

'except' clause does nothing but pass and there is no explanatory comment.

Copilot Autofix

AI 1 day ago

In general, empty except blocks should either be removed (letting exceptions propagate) or augmented to handle the error explicitly, typically by logging, transforming, or otherwise reacting to the exception. When silent degradation is desired, logging at an appropriate level is usually the minimum acceptable handling.

For this specific case in modules/invoice_designer/index.py, the best fix that does not change functional behavior is to keep the broad except Exception: (so the method still returns [] on failure) but log the exception. The file already imports logging and defines logger, so we just need to call logger.exception(...) or logger.warning(...) with a clear message in the except block. This introduces no new dependencies and preserves the external interface of get_invoice_templates.

Concretely, in get_invoice_templates, replace the except Exception: pass block (lines 280–281) with an except Exception: block that logs the error using logger.exception("..."). No other files or imports need modification.

Suggested changeset 1
modules/invoice_designer/index.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/modules/invoice_designer/index.py b/modules/invoice_designer/index.py
--- a/modules/invoice_designer/index.py
+++ b/modules/invoice_designer/index.py
@@ -278,7 +278,7 @@
                     '_designer_id': tpl.id,
                 })
         except Exception:
-            pass
+            logger.exception("Failed to load invoice designer templates")
         return templates
 
     # ---- CRUD ----
EOF
@@ -278,7 +278,7 @@
'_designer_id': tpl.id,
})
except Exception:
pass
logger.exception("Failed to load invoice designer templates")
return templates

# ---- CRUD ----
Copilot is powered by AI and may make mistakes. Always verify output.
).fetchone()
if row:
bank = _Obj(iban=row[0] or '', swift=row[1] or '', bank_name=row[2] or '')
except Exception:

Check notice

Code scanning / CodeQL

Empty except Note

'except' clause does nothing but pass and there is no explanatory comment.

Copilot Autofix

AI 1 day ago

In general, an empty except should be replaced with either more specific exception handling or at least minimal handling like logging, plus a clear comment if intentionally ignoring the error. Here we want to preserve existing behavior: failures to query the bank or customer tables should not break the preview and should simply cause use of demo data, but the exception should be visible to maintainers.

Best fix without changing functionality:

  • Keep the try / except structure and the existing default values (bank = None with a later fallback; customer = _demo_customer()).
  • In both except Exception: blocks, add a log call using the existing logger (logging.getLogger(__name__) is already defined at line 27).
  • Add a short comment documenting that the error is intentionally ignored for preview, while being logged.
  • Use logger.exception(...) so the full traceback is captured, which is useful for debugging and does not change runtime control flow.

Concretely:

  • In modules/invoice_designer/index.py, inside _preview_template:
    • Replace the except Exception:\n pass at lines 454–455 with an except Exception: that calls logger.exception(...) and adds a brief comment.
    • Similarly replace except Exception:\n pass at lines 470–471 with an except Exception: that logs the issue with a different message.

No new imports are necessary because logger is already defined; we only modify these two small blocks.

Suggested changeset 1
modules/invoice_designer/index.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/modules/invoice_designer/index.py b/modules/invoice_designer/index.py
--- a/modules/invoice_designer/index.py
+++ b/modules/invoice_designer/index.py
@@ -452,7 +452,8 @@
             if row:
                 bank = _Obj(iban=row[0] or '', swift=row[1] or '', bank_name=row[2] or '')
         except Exception:
-            pass
+            # Log and fall back to demo bank details for preview
+            logger.exception("Failed to load default bank for invoice preview; using demo bank data.")
         if not bank:
             bank = _Obj(iban='ES00 0000 0000 0000 0000 0000', swift='ABCDESXX', bank_name='Demo Bank')
 
@@ -468,7 +469,8 @@
                                 postal_code=row[4] or '', country=row[5] or '',
                                 tax_type=row[6] or 'eu_b2b')
         except Exception:
-            pass
+            # Log and fall back to demo customer details for preview
+            logger.exception("Failed to load customer for invoice preview; using demo customer data.")
 
         invoice = _demo_invoice()
         invoice.bank = bank
EOF
@@ -452,7 +452,8 @@
if row:
bank = _Obj(iban=row[0] or '', swift=row[1] or '', bank_name=row[2] or '')
except Exception:
pass
# Log and fall back to demo bank details for preview
logger.exception("Failed to load default bank for invoice preview; using demo bank data.")
if not bank:
bank = _Obj(iban='ES00 0000 0000 0000 0000 0000', swift='ABCDESXX', bank_name='Demo Bank')

@@ -468,7 +469,8 @@
postal_code=row[4] or '', country=row[5] or '',
tax_type=row[6] or 'eu_b2b')
except Exception:
pass
# Log and fall back to demo customer details for preview
logger.exception("Failed to load customer for invoice preview; using demo customer data.")

invoice = _demo_invoice()
invoice.bank = bank
Copilot is powered by AI and may make mistakes. Always verify output.
textColor=accent, spaceAfter=4, alignment=2)
s_title_c = ParagraphStyle('dtc', fontSize=title_fs, fontName=font_b,
textColor=accent, spaceAfter=4, alignment=1)
s_section = ParagraphStyle('ds', fontSize=10, fontName=font_b,

Check notice

Code scanning / CodeQL

Unused local variable Note

Variable s_section is not used.

Copilot Autofix

AI 1 day ago

To fix a genuine “unused local variable” while preserving behavior, either remove the unnecessary assignment (if it truly has no side effects) or rename the variable to indicate it is intentionally unused. Here, the right-hand side is a constructor call (ParagraphStyle(...)), which is free of side effects in normal usage but might be relied upon in subtle ways (e.g., style registration). To avoid any risk, we should keep the assignment but rename the variable so static analysis understands it is intentionally unused.

The single best change here is to rename s_section on line 651 to something that clearly marks it as unused, for example unused_s_section. This satisfies the naming convention accepted by CodeQL (it contains unused) and does not change any functionality, since the name was not referenced elsewhere. No imports, methods, or additional definitions are needed—only the variable name in that line in modules/invoice_designer/index.py should be updated.

Suggested changeset 1
modules/invoice_designer/index.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/modules/invoice_designer/index.py b/modules/invoice_designer/index.py
--- a/modules/invoice_designer/index.py
+++ b/modules/invoice_designer/index.py
@@ -648,8 +648,8 @@
                                textColor=accent, spaceAfter=4, alignment=2)
     s_title_c = ParagraphStyle('dtc', fontSize=title_fs, fontName=font_b,
                                textColor=accent, spaceAfter=4, alignment=1)
-    s_section = ParagraphStyle('ds', fontSize=10, fontName=font_b,
-                               textColor=accent, spaceAfter=4)
+    unused_s_section = ParagraphStyle('ds', fontSize=10, fontName=font_b,
+                                       textColor=accent, spaceAfter=4)
     s_normal = ParagraphStyle('dn', fontSize=10, fontName=font,
                               textColor=text_c, leading=13)
     s_small = ParagraphStyle('dsm', fontSize=9, fontName=font,
EOF
@@ -648,8 +648,8 @@
textColor=accent, spaceAfter=4, alignment=2)
s_title_c = ParagraphStyle('dtc', fontSize=title_fs, fontName=font_b,
textColor=accent, spaceAfter=4, alignment=1)
s_section = ParagraphStyle('ds', fontSize=10, fontName=font_b,
textColor=accent, spaceAfter=4)
unused_s_section = ParagraphStyle('ds', fontSize=10, fontName=font_b,
textColor=accent, spaceAfter=4)
s_normal = ParagraphStyle('dn', fontSize=10, fontName=font,
textColor=text_c, leading=13)
s_small = ParagraphStyle('dsm', fontSize=9, fontName=font,
Copilot is powered by AI and may make mistakes. Always verify output.
textColor=accent, spaceAfter=4, alignment=1)
s_section = ParagraphStyle('ds', fontSize=10, fontName=font_b,
textColor=accent, spaceAfter=4)
s_normal = ParagraphStyle('dn', fontSize=10, fontName=font,

Check notice

Code scanning / CodeQL

Unused local variable Note

Variable s_normal is not used.

Copilot Autofix

AI 1 day ago

To fix an unused local variable, either delete it or rename it to clearly indicate that it is intentionally unused. Here, s_normal is one of many style variables defined together and appears to serve no purpose, so the best fix without changing functionality is to remove its definition entirely. This does not affect the behavior of the function, because no code reads s_normal.

Concretely, in modules/invoice_designer/index.py, within the function where the reportlab styles are defined (around lines 645–669), remove the line that assigns s_normal. No additional imports or definitions are needed, and no other references need updating because s_normal is not used anywhere.

Suggested changeset 1
modules/invoice_designer/index.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/modules/invoice_designer/index.py b/modules/invoice_designer/index.py
--- a/modules/invoice_designer/index.py
+++ b/modules/invoice_designer/index.py
@@ -650,8 +650,6 @@
                                textColor=accent, spaceAfter=4, alignment=1)
     s_section = ParagraphStyle('ds', fontSize=10, fontName=font_b,
                                textColor=accent, spaceAfter=4)
-    s_normal = ParagraphStyle('dn', fontSize=10, fontName=font,
-                              textColor=text_c, leading=13)
     s_small = ParagraphStyle('dsm', fontSize=9, fontName=font,
                              textColor=text_c, leading=12)
     s_small_r = ParagraphStyle('dsmr', fontSize=9, fontName=font,
EOF
@@ -650,8 +650,6 @@
textColor=accent, spaceAfter=4, alignment=1)
s_section = ParagraphStyle('ds', fontSize=10, fontName=font_b,
textColor=accent, spaceAfter=4)
s_normal = ParagraphStyle('dn', fontSize=10, fontName=font,
textColor=text_c, leading=13)
s_small = ParagraphStyle('dsm', fontSize=9, fontName=font,
textColor=text_c, leading=12)
s_small_r = ParagraphStyle('dsmr', fontSize=9, fontName=font,
Copilot is powered by AI and may make mistakes. Always verify output.
textColor=accent, alignment=0)
s_total_val = ParagraphStyle('dtv', fontSize=13, fontName=font_b,
textColor=text_c, alignment=2)
s_meta_label = ParagraphStyle('dml', fontSize=8, fontName=font,

Check notice

Code scanning / CodeQL

Unused local variable Note

Variable s_meta_label is not used.

Copilot Autofix

AI 1 day ago

In general, to fix an "unused local variable" warning, either remove the unused variable (if it truly is not needed) or, if it must remain for documentation or future use, rename it to follow an "unused" naming convention (e.g. _, _unused_meta_label, or unused_meta_label) so tools and readers understand it is intentionally unused.

Here, the simplest and least intrusive fix is to delete the unused s_meta_label definition on line 669 while leaving the right-hand side expression only if it has side effects. In this case, ParagraphStyle(...) is a pure constructor call with no side effects other than object creation, so we can safely remove the entire line without changing behavior. No other code is shown that depends on s_meta_label, and keeping the style for hypothetical future use is not necessary for correctness. Therefore, in modules/invoice_designer/index.py, in the function where styles are defined (around lines 645–672), remove the line that defines s_meta_label. No imports or additional definitions are needed.

Suggested changeset 1
modules/invoice_designer/index.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/modules/invoice_designer/index.py b/modules/invoice_designer/index.py
--- a/modules/invoice_designer/index.py
+++ b/modules/invoice_designer/index.py
@@ -666,8 +666,6 @@
                                    textColor=accent, alignment=0)
     s_total_val = ParagraphStyle('dtv', fontSize=13, fontName=font_b,
                                  textColor=text_c, alignment=2)
-    s_meta_label = ParagraphStyle('dml', fontSize=8, fontName=font,
-                                  textColor=colors.HexColor('#999999'))
     s_meta_val = ParagraphStyle('dmv', fontSize=10, fontName=font_b,
                                 textColor=text_c)
 
EOF
@@ -666,8 +666,6 @@
textColor=accent, alignment=0)
s_total_val = ParagraphStyle('dtv', fontSize=13, fontName=font_b,
textColor=text_c, alignment=2)
s_meta_label = ParagraphStyle('dml', fontSize=8, fontName=font,
textColor=colors.HexColor('#999999'))
s_meta_val = ParagraphStyle('dmv', fontSize=10, fontName=font_b,
textColor=text_c)

Copilot is powered by AI and may make mistakes. Always verify output.
textColor=text_c, alignment=2)
s_meta_label = ParagraphStyle('dml', fontSize=8, fontName=font,
textColor=colors.HexColor('#999999'))
s_meta_val = ParagraphStyle('dmv', fontSize=10, fontName=font_b,

Check notice

Code scanning / CodeQL

Unused local variable Note

Variable s_meta_val is not used.

Copilot Autofix

AI 1 day ago

In general, an unused local variable should either be removed (if it serves no purpose and its initializer has no side effects) or renamed to indicate that it is intentionally unused (e.g., _ or a name containing unused). Here, the ParagraphStyle construction has no side effects beyond creating an object, and s_meta_val is not used anywhere, so the best fix that preserves existing functionality is to remove this unused assignment entirely.

Concretely, in modules/invoice_designer/index.py, within the section where various ParagraphStyle instances are created, you should delete the line that defines s_meta_val (line 671 in the snippet). No additional imports, methods, or definitions are required. The surrounding style variables (s_meta_label, etc.) remain unchanged.

Suggested changeset 1
modules/invoice_designer/index.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/modules/invoice_designer/index.py b/modules/invoice_designer/index.py
--- a/modules/invoice_designer/index.py
+++ b/modules/invoice_designer/index.py
@@ -668,8 +668,6 @@
                                  textColor=text_c, alignment=2)
     s_meta_label = ParagraphStyle('dml', fontSize=8, fontName=font,
                                   textColor=colors.HexColor('#999999'))
-    s_meta_val = ParagraphStyle('dmv', fontSize=10, fontName=font_b,
-                                textColor=text_c)
 
     def _style_for_slot(slot):
         """Return (text_style, alignment) based on slot position."""
EOF
@@ -668,8 +668,6 @@
textColor=text_c, alignment=2)
s_meta_label = ParagraphStyle('dml', fontSize=8, fontName=font,
textColor=colors.HexColor('#999999'))
s_meta_val = ParagraphStyle('dmv', fontSize=10, fontName=font_b,
textColor=text_c)

def _style_for_slot(slot):
"""Return (text_style, alignment) based on slot position."""
Copilot is powered by AI and may make mistakes. Always verify output.
else:
img.hAlign = 'LEFT'
return img
except Exception:

Check notice

Code scanning / CodeQL

Empty except Note

'except' clause does nothing but pass and there is no explanatory comment.

Copilot Autofix

AI 1 day ago

In general, to fix empty except blocks, either handle the error (e.g., log, clean up, apply fallback behavior) or narrow the exception type and document why it is safe to ignore. Here, we should preserve the current behavior of not raising errors to the caller, but avoid silently swallowing all information.

The best low-impact fix is to add logging inside the except block, using the existing logger defined at the top of the file. We keep return None as the outcome so behavior remains unchanged from the caller’s perspective. We also slightly narrow the except if possible; however, we do not know all exception types that storage.get, _io.BytesIO, or Image may raise, so keeping Exception is reasonable but we’ll log the exception object.

Concretely, in modules/invoice_designer/index.py, around lines 693–707, we will replace:

            try:
                result = storage.get(c['logo_path'])
                if result:
                    ...
                    return img
            except Exception:
                pass
            return None

with:

            try:
                result = storage.get(c['logo_path'])
                if result:
                    ...
                    return img
            except Exception as exc:
                logger.warning("Failed to load or render invoice logo from path %r: %s", c.get('logo_path'), exc)
            return None

This uses the already-imported logging module and logger instance, adds diagnostic information, and preserves the final return None behavior.

Suggested changeset 1
modules/invoice_designer/index.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/modules/invoice_designer/index.py b/modules/invoice_designer/index.py
--- a/modules/invoice_designer/index.py
+++ b/modules/invoice_designer/index.py
@@ -703,8 +703,12 @@
                     else:
                         img.hAlign = 'LEFT'
                     return img
-            except Exception:
-                pass
+            except Exception as exc:
+                logger.warning(
+                    "Failed to load or render invoice logo from path %r: %s",
+                    c.get('logo_path'),
+                    exc,
+                )
             return None
 
         if block_id == 'title':
EOF
@@ -703,8 +703,12 @@
else:
img.hAlign = 'LEFT'
return img
except Exception:
pass
except Exception as exc:
logger.warning(
"Failed to load or render invoice logo from path %r: %s",
c.get('logo_path'),
exc,
)
return None

if block_id == 'title':
Copilot is powered by AI and may make mistakes. Always verify output.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants