Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error during merge after async task

I have an application which basically calls multiple webservices, stores the data received from those webservices and renders it to the user. I have an async task that call all the webservices and it looks something like this:

List<Promise> t = new ArrayList<Promise>()
def TIMEOUT_TIME = 6

    t[0] = task {
        def responseFrom0 = webserviceRequestService.getResponse(0)
        if(responseFrom0){
            return responseFrom0
        }
    }

    t[1] = task {
        def responseFrom1 = webserviceRequestService.getResponse(1)
        if(responseFrom1){
            return responseFrom1
        }
    }

The action getResponse looks something like this:

    List<ResponseResult> result = new ArrayList<TravelQuote>()

    try {
        wsClient = prepareRequestMap()
        wsResponse = externalWebservice.getQuotes(wsClient)
        wsResponse.responseList.each  {
            ResponseResult responseResult = new ResponseResult()

            //populate properties of ResponseResult
            responseResult.save(failOnError:true, flush:true)
            result.add(responseResult)

        }

    } catch(Exception e){
        log.error e.message
        e.printStackTrace()
    }

    return result

And at the end, I collect all the responses from all webservices like this:

    result.each {
        if(it){
            try{
                it=it.merge()                                       
            }catch (Exception e){
                log.error("Error occured while merging responses... : ${e.message}")
            }

        }
    }

Now, the issue here is I get this exception from the last block of code

not-null property references a null or transient value: ResponseResult.dateCreated; nested exception is org.hibernate.PropertyValueException: not-null property references a null or transient value: ResponseResult.dateCreated

The dateCreated comes from this class which I have implemented on all of my domain classes.

abstract class AbstractPersistentObject implements Serializable{
    static final long serialVersionUID = 1L;    
    Date dateCreated
    Date lastUpdated    
}

The weird thing about this issue is, this happens only on production environment, no matter what I do, I cannot replicate this in any other environments. And also, once this happens, the server just throws that particular issue every time that code is run until the server is restarted. After a restart, this code works fine.

I am running out of ideas, anyone has any ideas?

like image 365
Eddard Stark Avatar asked Oct 31 '22 12:10

Eddard Stark


1 Answers

The answer seems to be in the exception thrown: the external web service returns record(s) without value for dateCreated field.

In my experience data from production environments almost always contains missing or improperly formatted values. You should account for that by changing the definition of ResponseResult.dateCreated to allow null values and handle this scenario in your code.

like image 86
Lukasz Korzeniowski Avatar answered Nov 15 '22 11:11

Lukasz Korzeniowski