Skip to content

Pydantic serializer warnings #65

Description

@Calabashmc

I'm using a jinja2 template for my email. My function:

def send_email(subject, addresses, template='email.html', template_params=None, attachments=[]):
    if template_params is None:
        template_params = {}

    message = Message(
        subject=subject,
        recipients=addresses,
        template_body=template_params,
        attachments=attachments
    )

    try:
        run_async_in_thread(
            mail.send_message(message, template_name=template)
        )

    except Exception as e:
        flash(f"Error sending email: {str(e)}")
        raise

Template:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>{{ subject }}</title>
</head>
<body>
    <p>Hello {{ name }},</p>
    <p>Your ticket <strong>{{ ticket_number }}</strong> has been updated.</p>
    <p>Timestamp: {{ time_stamp }}</p>
    <p><a href="{{ ticket_url }}">View Ticket</a></p>
</body>
</html>

This set up works, I get the email but I get the following warning most of the time but not always:

UserWarning: Pydantic serializer warnings:
  PydanticSerializationUnexpectedValue: Expected `list[any]` but got `str` with value `'!DOCTYPE html>\n<html la.../div>\n</body>\n</html>'` - serialized value may not be as expected
  PydanticSerializationUnexpectedValue: Expected `dict[any, any]` but got `str` with value `'!DOCTYPE html>\n<html la.../div>\n</body>\n</html>'` - serialized value may not be as expected
  return self.__pydantic_serializer__.to_python(

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions