Changes in response doesn't stick

I’m having some difficulties trying to change the response from a GET request. In the get.post_proccess for a given table I’m modifying the event.response object but the changes doesn’t stick!

Here is a simple example to illustrate what is happening. If I use this script in the get.post_process of a table, it has no effect:

event.response = ""; OR event.response = {}

(By “no effect” I mean I get all the records as if the response were not changed)

This script has the same result (no effect to the response):

return "";

In the thread Server-side filter returns SQL error when using “contains” or “starts with” clauses @toddappleton told about a similar problem that would be fixed in release 2.1. Today I upgraded to the latest version and I believe I’m running 2.1, although the version differs in the Admin Panel:

When I check the CHANGELOG.md file in htdocs/vendor/dreamfactory/df-core it shows information about version 0.2.3, which makes me believe I’m running DF 2.1.

I know the script has been run because I add some print commands and I see the messages in the logs.

Why am I not being able to change the response? Any help will be much appreciated.

P.S.: I forgot to mention that I’m running a Bitnami image at AWS.

Thanks,

Elvis

If the admin app Config screen doesn’t show your DreamFactory Version as 2.1.0, then your update was not completed successfully.

Perform the update process again, and pay close attention to the output in your terminal. If you have any warnings or errors you’ll need to address them.
Without knowing any more about your setup, I’d guess your pull in the main repo had issues. Feel free to post any errors you encounter and need help with.

Hi Drew,

Regardless the update issue, I think Elvis is having the same issue as I reported here.

Was this confirmed as a bug?
Best regards

Gabriel

Hi Drew,

I repeated the upgrade procedure following the instructions from the wiki and the result is the same.

Here you have the full output of the upgrade process. I can’t see anything that could point some error:

root@ip-000-000-000-000:/opt/bitnami/apps/dreamfactory/htdocs# git checkout masterAlready on 'master'
Your branch is up-to-date with 'origin/master'.
root@ip-000-000-000-000:/opt/bitnami/apps/dreamfactory/htdocs# git pull origin master
From https://github.com/dreamfactorysoftware/dreamfactory
 * branch            master     -> FETCH_HEAD
Already up-to-date.
root@ip-000-000-000-000:/opt/bitnami/apps/dreamfactory/htdocs# php composer.phar self-update
Updating to version d6d0435c5437111e42a123b06e4071e26ba7cb6e.
    Downloading: 100%
Use composer self-update --rollback to return to version cff35071b68e286f68ac64908c990c15b3ac4a0d
root@ip-000-000-000-000:/opt/bitnami/apps/dreamfactory/htdocs# php composer.phar install --no-dev
Loading composer repositories with package information
Installing dependencies from lock file
Nothing to install or update
Generating autoload files
> php artisan clear-compiled
> php artisan optimize
Generating optimized class loader
Compiling common classes
> php artisan dreamfactory:pull-migrations
Copying 2015_05_02_134911_update_user_table_for_oauth_support.php from /opt/bitnami/apps/dreamfactory/htdocs/vendor/dreamfactory/df-oauth/database/migrations
Copying 2015_03_11_143913_create_rackspace_tables.php from /opt/bitnami/apps/dreamfactory/htdocs/vendor/dreamfactory/df-rackspace/database/migrations
Copying 2015_08_24_180219_default_schema_only.php from /opt/bitnami/apps/dreamfactory/htdocs/vendor/dreamfactory/df-sqldb/database/migrations
Copying 2015_02_03_161456_create_sqldb_tables.php from /opt/bitnami/apps/dreamfactory/htdocs/vendor/dreamfactory/df-sqldb/database/migrations
Copying 2015_02_03_161457_create_mongodb_tables.php from /opt/bitnami/apps/dreamfactory/htdocs/vendor/dreamfactory/df-mongodb/database/migrations
Copying 2015_05_04_034605_create_adldap_tables.php from /opt/bitnami/apps/dreamfactory/htdocs/vendor/dreamfactory/df-adldap/database/migrations
Copying 2015_11_17_181913_ad_enhancements.php from /opt/bitnami/apps/dreamfactory/htdocs/vendor/dreamfactory/df-adldap/database/migrations
Copying 2015_05_21_190727_create_user_config_table.php from /opt/bitnami/apps/dreamfactory/htdocs/vendor/dreamfactory/df-user/database/migrations
Copying 2015_07_10_161839_create_user_custom_table.php from /opt/bitnami/apps/dreamfactory/htdocs/vendor/dreamfactory/df-user/database/migrations
Copying 2015_02_03_161457_create_salesforce_tables.php from /opt/bitnami/apps/dreamfactory/htdocs/vendor/dreamfactory/df-salesforce/database/migrations
Copying 2016_01_21_213101_add_curl_options.php from /opt/bitnami/apps/dreamfactory/htdocs/vendor/dreamfactory/df-rws/database/migrations
Copying 2015_03_20_205504_create_remote_web_service_tables.php from /opt/bitnami/apps/dreamfactory/htdocs/vendor/dreamfactory/df-rws/database/migrations
Copying 2015_02_03_161457_create_couchdb_tables.php from /opt/bitnami/apps/dreamfactory/htdocs/vendor/dreamfactory/df-couchdb/database/migrations
Copying 2015_03_10_135522_create_aws_tables.php from /opt/bitnami/apps/dreamfactory/htdocs/vendor/dreamfactory/df-aws/database/migrations
Copying 2015_11_10_225902_db_foreign_key.php from /opt/bitnami/apps/dreamfactory/htdocs/vendor/dreamfactory/df-core/database/migrations
Copying 2015_11_06_155036_db_function.php from /opt/bitnami/apps/dreamfactory/htdocs/vendor/dreamfactory/df-core/database/migrations
Copying 2015_01_27_190908_create_system_tables.php from /opt/bitnami/apps/dreamfactory/htdocs/vendor/dreamfactory/df-core/database/migrations
Copying 2015_08_25_202632_db_alias.php from /opt/bitnami/apps/dreamfactory/htdocs/vendor/dreamfactory/df-core/database/migrations
Copying 2015_03_20_205504_create_soap_service_tables.php from /opt/bitnami/apps/dreamfactory/htdocs/vendor/dreamfactory/df-soap/database/migrations
Finished pulling migrations from /opt/bitnami/apps/dreamfactory/htdocs/vendor/ to /opt/bitnami/apps/dreamfactory/htdocs/database/migrations/.
|> php artisan dreamfactory:homestead-config
root@ip-000-000-000-000:/opt/bitnami/apps/dreamfactory/htdocs#
root@ip-000-000-000-000:/opt/bitnami/apps/dreamfactory/htdocs#
root@ip-000-000-000-000:/opt/bitnami/apps/dreamfactory/htdocs#
root@ip-000-000-000-000:/opt/bitnami/apps/dreamfactory/htdocs#
root@ip-000-000-000-000:/opt/bitnami/apps/dreamfactory/htdocs#
root@ip-000-000-000-000:/opt/bitnami/apps/dreamfactory/htdocs#
root@ip-000-000-000-000:/opt/bitnami/apps/dreamfactory/htdocs# php artisan migrate --seed
Nothing to migrate.
Service Type resources updated: system, swagger, event, script, local_file, local_email, smtp_email, mailgun_email, mandrill_email
Seeded: DreamFactory\Core\Database\Seeds\ServiceTypeSeeder
Seeded: DreamFactory\Core\Database\Seeds\SystemResourceSeeder
Seeded: DreamFactory\Core\Database\Seeds\ScriptTypeSeeder
Seeded: DreamFactory\Core\Database\Seeds\ServiceSeeder
Seeded: DreamFactory\Core\Database\Seeds\DbTableExtrasSeeder
Seeded: DreamFactory\Core\Database\Seeds\AppSeeder
Seeded: DreamFactory\Core\Database\Seeds\DatabaseSeeder
Seeded: DreamFactory\Core\SqlDb\Database\Seeds\ServiceTypeSeeder
Seeded: DreamFactory\Core\SqlDb\Database\Seeds\DbTableExtrasSeeder
Seeded: DreamFactory\Core\SqlDb\Database\Seeds\DbFieldExtrasSeeder
Seeded: DreamFactory\Core\SqlDb\Database\Seeds\ServiceSeeder
Seeded: DreamFactory\Core\SqlDb\Database\Seeds\DatabaseSeeder
Seeded: DreamFactory\Core\MongoDb\Database\Seeds\DatabaseSeeder
Seeded: DreamFactory\Core\CouchDb\Database\Seeds\DatabaseSeeder
Seeded: DreamFactory\Core\Rws\Database\Seeds\DatabaseSeeder
Seeded: DreamFactory\Core\Soap\Database\Seeds\DatabaseSeeder
Seeded: DreamFactory\Core\Aws\Database\Seeds\DatabaseSeeder
Seeded: DreamFactory\Core\Rackspace\Database\Seeds\DatabaseSeeder
Seeded: DreamFactory\Core\Salesforce\Database\Seeds\DatabaseSeeder
Seeded: DreamFactory\Core\User\Database\Seeds\EmailTemplateSeeder
Seeded: DreamFactory\Core\User\Database\Seeds\ServiceTypeSeeder
Seeded: DreamFactory\Core\User\Database\Seeds\EmailServiceSeeder
Seeded: DreamFactory\Core\User\Database\Seeds\UserServiceSeeder
Seeded: DreamFactory\Core\User\Database\Seeds\ResourceSeeder
Seeded: DreamFactory\Core\User\Database\Seeds\DatabaseSeeder
Seeded: DreamFactory\Core\OAuth\Database\Seeds\DatabaseSeeder
Seeded: DreamFactory\Core\ADLdap\Database\Seeds\DbTableExtrasSeeder
Service Type resources updated: adldap, ldap
Seeded: DreamFactory\Core\ADLdap\Database\Seeds\ServiceTypeSeeder
Seeded: DreamFactory\Core\ADLdap\Database\Seeds\DatabaseSeeder
root@ip-000-000-000-000:/opt/bitnami/apps/dreamfactory/htdocs#
root@ip-000-000-000-000:/opt/bitnami/apps/dreamfactory/htdocs#
root@ip-000-000-000-000:/opt/bitnami/apps/dreamfactory/htdocs#
root@ip-000-000-000-000:/opt/bitnami/apps/dreamfactory/htdocs#
root@ip-000-000-000-000:/opt/bitnami/apps/dreamfactory/htdocs#
root@ip-000-000-000-000:/opt/bitnami/apps/dreamfactory/htdocs#
root@ip-000-000-000-000:/opt/bitnami/apps/dreamfactory/htdocs#
root@ip-000-000-000-000:/opt/bitnami/apps/dreamfactory/htdocs#
root@ip-000-000-000-000:/opt/bitnami/apps/dreamfactory/htdocs#
root@ip-000-000-000-000:/opt/bitnami/apps/dreamfactory/htdocs#
root@ip-000-000-000-000:/opt/bitnami/apps/dreamfactory/htdocs#
root@ip-000-000-000-000:/opt/bitnami/apps/dreamfactory/htdocs# php artisan cache:clear
Application cache cleared!
root@ip-000-000-000-000:/opt/bitnami/apps/dreamfactory/htdocs#
root@ip-000-000-000-000:/opt/bitnami/apps/dreamfactory/htdocs#
root@ip-000-000-000-000:/opt/bitnami/apps/dreamfactory/htdocs#
root@ip-000-000-000-000:/opt/bitnami/apps/dreamfactory/htdocs# ../../../ctlscript.sh restart
/opt/bitnami/config/monit/conf.d/apache.conf:3: Warning: Program does not exist: '/opt/bitnami/apache2/scripts/ctl.sh'
/opt/bitnami/config/monit/conf.d/apache.conf:4: Warning: Program does not exist: '/opt/bitnami/apache2/scripts/ctl.sh'
/opt/bitnami/nginx/scripts/ctl.sh : Nginx stopped
/opt/bitnami/php/scripts/ctl.sh : php-fpm stopped
/opt/bitnami/mysql/scripts/ctl.sh : mysql stopped
160215 15:13:31 mysqld_safe Logging to '/opt/bitnami/mysql/data/mysqld.log'.
160215 15:13:31 mysqld_safe Starting mysqld.bin daemon with databases from /opt/bitnami/mysql/data
/opt/bitnami/mysql/scripts/ctl.sh : mysql  started at port 3306
/opt/bitnami/mongodb/scripts/ctl.sh : mongodb stopped
/opt/bitnami/mongodb/scripts/ctl.sh : mongodb started at port 27017
/opt/bitnami/php/scripts/ctl.sh : php-fpm started
/opt/bitnami/nginx/scripts/ctl.sh : Nginx started
/opt/bitnami/config/monit/conf.d/apache.conf:3: Warning: Program does not exist: '/opt/bitnami/apache2/scripts/ctl.sh'
/opt/bitnami/config/monit/conf.d/apache.conf:4: Warning: Program does not exist: '/opt/bitnami/apache2/scripts/ctl.sh'
root@ip-000-000-000-000:/opt/bitnami/apps/dreamfactory/htdocs#

I know the subject of this thread is not related to the platform version, but I’m posting all this output believing it has something to do with the problem of the changes in the response for a request.

Elvis_Fernandes,
You need to set ‘content_changed’ to true (or 1).

if (event.response.content.resource) {
lodash._.each (event.response.content.resource, function( record ) {

    record.extraField = 'Feed the dog.';
});

event.response.content_changed = 1;
}

Documented here: https://wiki.dreamfactory.com/DreamFactory/Features/Scripting#Resources_Available_To_A_Script

2 Likes

Thank you, @gjhall01.

This wasn’t documented at the time of the OP.