What user do AOW Workflows run as?

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:

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!

I think workflows don’t run as any specific user.

This error appears in every SuiteCRM installation, and it is safe to ignore. I would appreciate a fix, though, just to remove log spam. I guess it’s just a matter of adding in a check in the function.

It’s probably safer to leave the function there, just omit the logging of the error, unless you can find a way to run that function from a user context, so you can really understand what it is supposed to do in those cases…

I’m facing the same type of issue, so just thought I’d add my additional troubleshooting info here. We were having issues with an ‘error occurred while saving record’ toast on saving an Account, and logs of ‘fromUser: Conversion of 2023-06-26 03:52:11 from user format m/d/Y H:i failed’.

Before finding this topic I’d done basically the same investigation as above, finding that the check_valid_bean function makes the calls that result in the error.

The call for $this->date_entered works as that date is in the correct format (2021/07/07 09:08)
But the calls for $bean->date_entered and $bean->date_modified don’t as their format is wrong (2023-06-27 01:24:15).

I don’t know where those bean dates are generated and why the format is like that? I’m not familiar enough with the code, all I’m trying to do is troubleshoot a client’s errors after upgrading them v8.