2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-19 05:25:42 +00:00

Catch error when incorrect date format string is passed

This commit is contained in:
Oliver
2022-03-24 11:56:39 +11:00
parent b720c2e431
commit 31b71fe29f
2 changed files with 18 additions and 1 deletions

View File

@ -8,6 +8,7 @@ over and above the built-in Django tags.
from datetime import date, datetime
import os
import sys
import logging
from django.utils.html import format_html
@ -31,6 +32,9 @@ from plugin.models import PluginSetting
register = template.Library()
logger = logging.getLogger('inventree')
@register.simple_tag()
def define(value, *args, **kwargs):
"""
@ -65,7 +69,11 @@ def render_date(context, date_object):
return None
# If a string is passed, first convert it to a datetime
date_object = date.fromisoformat(date_object)
try:
date_object = date.fromisoformat(date_object)
except ValueError:
logger.warning(f"Tried to convert invalid date string: {date_object}")
return None
# We may have already pre-cached the date format by calling this already!
user_date_format = context.get('user_date_format', None)