My SuiteCRM log has been regularly inundated with ‘date conversion’ errors for a long time. It seems like a lot of other people have similar issues:
- Conversion of 2018-08-04 23:44:59 from user format d/m/Y h:ia failed
- Workflow - [ERROR] fromUser: Conversion of 2022-10-26 16:26:40 from user format Y-m-d h:i a failed
- Workflow per module, how many can I set up on 1 module
- Some repeated errors in log
- Error message in Suite CRM logs
After tracing my issue down, it seems to be that it is triggered when I save a Case. I have Workflows set up to trigger upon saving a Case so I did some digging and it appears that my issue is related to the user being null when a Workflow is running.
My error, specifically, usually looks similar to this in the log:
Thu Feb 2 06:45:19 2023 [25099][316cc89c-7590-6a43-308c-57923a9221a7][ERROR] fromUser: Conversion of 2023-02-02 14:45:16 from user format m-d-Y h:iA failed
I suspect the error is being thrown by the fromUser function in include/TimeDate.php around line 810:
public function fromUser($date, User $user = null)
{
$res = null;
try {
$res = SugarDateTime::createFromFormat($this->get_date_time_format($user), $date, $this->_getUserTZ($user));
} catch (Exception $e) {
$GLOBALS['log']->error("fromUser: Conversion of $date exception: {$e->getMessage()}");
}
if (!($res instanceof DateTime)) {
$uf = $this->get_date_time_format($user);
$GLOBALS['log']->error("fromUser: Conversion of $date from user format $uf failed");
return null;
}
return $res;
}
So that tells me that $res is not an instance of DateTime (it’s most likely null). I checked by adding debug statements that $user is null when fromUser is called.
Then I can see that fromUser() is being called from the fromUserType function around line 831:
public function fromUserType($date, $type, $user = null)
{
switch ($type) {
case "date":
return $this->fromUserDate($date, $user);
break;
case 'time':
return $this->fromUserTime($date, $user);
break;
case 'datetime':
case 'datetimecombo':
default:
return $this->fromUser($date, $user);
}
}
I can see in modules/AOW_WorkFlow/AOW_WorkFlow.php around line 643 there’s the following lines in the check_valid_bean function which call “fromUserType” without specifying a user.
if ($this->flow_run_on) {
$dateEntered = $timedate->fromUserType($this->date_entered, 'datetime')
?: $timedate->fromDbType($this->date_entered, 'datetime');
$beanDateEntered = $timedate->fromUserType($bean->date_entered, 'datetime')
?: $timedate->fromDbType($bean->date_entered, 'datetime');
$beanDateModified = $timedate->fromUserType($bean->date_modified, 'datetime')
?: $timedate->fromDbType($bean->date_modified, 'datetime');
So check_valid_bean() is trying to get datetime info in a user’s format before falling back to using the default datetime format of the database. I don’t follow the logic here though: fromUserType() seems to require a user (though the function allows $user to be optional by falling back to a null user if a user is not provided) but the Workflow does not pass a user so it seems like fromUserType is not really doing anything there except spitting out the error in the suitecrm.log each time check_valid_bean() runs.
It seems to me, that unless the AOW Workflow is supposed to run as a specific user (or inherit the user from the record being saved), the call to fromUserType is always going to fail and, perhaps, it should be removed from those assignments so it stops spamming the log.
- Does anyone have any insight into this?
- Are Workflows supposed to run as a specific (or programmatically-determined) user?
- Is there any reason fromUserType needs to be called in check_valid_bean()?
- At the very least, should the fromUser error in the logs be downgraded to warn or info?
Thanks!