Expression NOW() not working DF 2.2

I am using DF 2.2 with Mysql database, but the expression is not working properly.
I am following the doc that is in the link below:
https://wiki.dreamfactory.com/DreamFactory/Features/Database/SQL-Field-Expressions

this is the payload that I am going:

{
  "resource": [
    {
      "login": "login",
      "encrypted_password": {
        "expression": "MD5(12345)"
      },
      "created_at": {
        "expression": "NOW()"
      },
      "updated_at": {
        "expression": "NOW()"
      }
    }
  ]
}

but the bank fields are created as follows

{
  "resource": [
    {
      "login": "login",
      "encrypted_password": "MD5(12345)"
      "created_at": "0000-00-00 00:00:00"
      "updated_at": "0000-00-00 00:00:00"
    }
  ]
}

@AlexBowen can you take this issue to the team?

1 Like

Hey @geovani thanks for bringing this to our attention.

We like to give the community an opportunity to respond, while we are also looking into it on our end in the meantime. One thing @paulo.hgf1408 can keep in mind is that if he wants a more timely reply from the DreamFactory support folks, for example within 4 business hours - 1 day, he may consider signing up for paid support.

We also encourage bugs to be reported directly on our GitHub.

This forum is mostly run and maintained by volunteer community members for the purpose of interaction, learning and support.

Thanks,
@AlexBowen

Hey @paulo.hgf1408 you may be missing a few brackets, need a default value or your <param_value> may be incorrect?

then tested all the ways that doc presents, and did not work so I decided to debug the MySQL logs to see how that was being sent by the DF and the problem is that the DF sends all with quotes, so mysql does not execute the expression,

below what the DF performs in the bank:

insert into Table (login,encrypted_password,created_at,updated_at) values ('login', 'MD5(12345)', 'NOW()', 'NOW()')

Updating the post, opened this issue in the DF repository and found that it is a bug in version 2.2

https://github.com/dreamfactorysoftware/dreamfactory/issues/85

1 Like

@geovani We have verified that expressions broke in 2.2 from @paulo.hgf1408 bug report in GitHub. I have filed a bug on our end and the team is aware.

1 Like

palliation Iā€™m using events scripts to include the time and date of the server in the fields on events post, patch and put.

this code bellow is a example:

// POST /api/v2/service_db/_table triggers script service_db._table.{table_name}.put.pre_process
// This script runs BEFORE records are written to the service_db.
// records are in array event.request.payload
var _ = require('underscore-min.js')._;

function tableContainUpdatedAt(tableName) {
    var schema = platform.api.get('db-servicos/_schema/' + tableName);

    return _.chain(schema.content.field)
        .pluck('name')
        .indexOf('updated_at')
        .value() > -1;
}

if (event.request.payload && tableContainUpdatedAt(event.resource)) {

  if(event.request.payload.resource.length) {
    _.each(event.request.payload.resource, function(record) {
        record.updated_at = new Date().toISOString();
    });
    
    event.request.content_changed = true;
  }
}

PS: its code based of post: How to assign the current user id to post api in dreamfactory?

2 Likes

You can see the fix for this in github: https://github.com/dreamfactorysoftware/dreamfactory/issues/85#issuecomment-229972356

This code shipped into production over the weekend.

1 Like