Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api_log_mail/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@
"api_log",
"mail",
],
"data": ["data/mail_template.xml"],
}
47 changes: 47 additions & 0 deletions api_log_mail/data/mail_template.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!--
~ Copyright 2025 Simone Rubino - PyTech
~ License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
-->
<odoo noupdate="1">
<record id="email_template_fastapi_error" model="mail.template">

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: api_log_mail is a generic module so it should not mention fastapi.
Please either remove the fastapi mentions, or move this to the fastapi_log_mail module.
Note that the migration from 16.0 should work as expected: for instance, if you rename the XMLID you should call https://oca.github.io/openupgradelib/API.html#openupgradelib.openupgrade.rename_xmlids.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chore: Please inform the user in readme/CONFIGURE.md that this template exists and should be properly configured/customized.

<field name="name">FastAPI: Error</field>
<field name="model_id" ref="api_log.model_api_log" />
<field
name="email_from"
>{{object.collection_ref.user_id.email or object.env.ref('base.partner_root').email}}</field>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: The field user_id does not exist in a generic collection, it is only present when the collection is a fastapi.endpoint record.
Please remove it if you choose to keep the template in this module.

<field
name="email_to"
>{{object.collection_ref.company_id.scheduler_error_email_address}}</field>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: The field scheduler_error_email_address does not exist, so rendering the template raises

[...]
UserError: Failed to render inline_template template: {{object.collection_ref.company_id.scheduler_error_email_address}}
Error details: AttributeError("'res.company' object has no attribute 'scheduler_error_email_address'") while evaluating
'object.collection_ref.company_id.scheduler_error_email_address'

It would be a nice addition to the module, or you can just pick the email of the admin user.

After you fix it, remember to add a test so that there won't be a regression in the future, as suggested in:

As a general rule, a bug fix should come with a unittest which would fail without the fix itself. This is to assure that regression will not happen in the future.

(from https://github.com/OCA/odoo-community.org/blob/master/website/Contribution/CONTRIBUTING.rst#6tests)

<field name="subject">Odoo FastAPI Error</field>
<field name="auto_delete" eval="False" />
<field name="body_html" type="html">

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: This prints out a nicely formatted email 🤗
Image

<div>
<t t-set="endpoint_name" t-value="object.collection_ref.name" />
<t t-set="request_url" t-value="object.request_url" />
<t t-set="request_method" t-value="object.request_method" />
<t t-set="headers" t-value="object.request_headers" />
<t t-set="exception" t-value="object.response_body" />
<t t-set="exception_stack" t-value="object.stack_trace" />

<p>Error in FastAPI call</p>
<p>FastAPI endpoint: <t t-out="endpoint_name" /></p>
<p>Request: [<t t-out="request_method" />] <t t-out="request_url" /></p>
<p>
Headers:
<ul>
<li t-foreach="headers.items()" t-as="hd">
<t t-out="hd[0]" />: <t t-out="hd[1]" />
</li>
</ul>
</p>
<p>
Exception: <t t-out="exception" />
</p>
<p>
Stack trace: <pre t-out="exception_stack" />
</p>
</div>
</field>
</record>
</odoo>
3 changes: 3 additions & 0 deletions api_log_mail/models/api_log_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ class APILogCollection(models.AbstractModel):
domain=[("model_id.model", "=", "api.log")],
string="Error E-mail Template",
help="An email based on this template will be sent when an error is logged.",
default=lambda self: self.env.ref(
"api_log_mail.email_template_fastapi_error", False
),
)
api_log_mail_exception_activity_type_id = fields.Many2one(
comodel_name="mail.activity.type",
Expand Down
Loading