Smart Action - Prefill a form with default values not working in Production

Feature(s) impacted

Smart Action - Prefill a form with default values, using the hook feature

Observed behavior

The input is prefilled in development environment but when I try it in production, it does not work anymore.
Forest throws the following error : An error occured on form load. Check your server logs for more details.

Expected behavior

I expect the input to prefill the value, which is the actual behaviour in development.

Failure Logs

My server logs :

Processing by ForestLiana::ActionsController#load as JSON
2022-01-11T18:45:52.824157+00:00 app[web.1]: I, [2022-01-11T18:45:52.824135 #4]  INFO -- : [b5a53444-521c-4593-a922-997cd3b8d8f7]   Parameters: {"data"=>{"attributes"=>{"ids"=>["2"], "collection_name"=>"TransferCode", "parent_collection_name"=>nil, "parent_collection_id"=>nil, "parent_association_name"=>nil, "all_records"=>false, "all_records_subset_query"=>{}, "all_records_ids_excluded"=>[], "smart_action_id"=>"888a90b0-83f5-11ea-864f-09ec8b4f03af"}, "type"=>"action-requests"}, "timezone"=>"Europe/Paris", "action_name"=>"creer-un-versement-membre"}
2022-01-11T18:45:52.824286+00:00 app[web.1]: W, [2022-01-11T18:45:52.824263 #4]  WARN -- : [b5a53444-521c-4593-a922-997cd3b8d8f7] HTTP Origin header (https://app.forestadmin.com) didn't match request.base_url (https://ichangedthenameofmyapp.herokuapp.com)
2022-01-11T18:45:52.824526+00:00 app[web.1]: I, [2022-01-11T18:45:52.824490 #4]  INFO -- : [b5a53444-521c-4593-a922-997cd3b8d8f7] Completed 422 Unprocessable Entity in 0ms (ActiveRecord: 0.0ms)
2022-01-11T18:45:52.825099+00:00 app[web.1]: F, [2022-01-11T18:45:52.825064 #4] FATAL -- : [b5a53444-521c-4593-a922-997cd3b8d8f7]
2022-01-11T18:45:52.825101+00:00 app[web.1]: F, [2022-01-11T18:45:52.825088 #4] FATAL -- : [b5a53444-521c-4593-a922-997cd3b8d8f7] ActionController::InvalidAuthenticityToken (ActionController::InvalidAuthenticityToken):

Context

  • Project name: Culturepay
  • Environment name: Production
    I am using forest_liana (7.4.5)

Hello @juliepierre ! :wave: Welcome to our community :tada: :confetti_ball:

Thanks for this detailed thread. :pray:
I just need a few other information to help us find the culprit.

  • Can also provide the details about the error received from your agent, it would help ? This can be done using the developer tools of your browser → Network tab.
  • Could you, also, share the code of the smart action load hooks ?

Thanks in advance.

Kind regards,
Morgan

Hello Morgan !

Sure, there you have. FYI, I reproduced the issue on my staging environment, so here you will have the details from my staging app, but it is exactly the same issue on the live app.

The code of the smart action with the hooks

action "Créer un Versement Membre",
    type: 'single',
    fields: [
    {
      field: 'Montant en centimes',
      description: "Renseigner le montant du Versement Membre en centimes",
      type: 'Number',
      is_required: true
    },
    {
      field: 'Description',
      description: "Ajouter une description",
      type: 'String',
      is_required: true
    }],
    hooks: {
      :load => -> (context){
        description = context[:fields].find{|field| field[:field] == 'Description'}

        id = context[:params][:data][:attributes][:ids][0]
        transfer_code = TransferCode.find(id)

        description[:value] = "Versement #{transfer_code.member.company_name} #{transfer_code.validity_month.strftime('%m/%Y')}"

        return context[:fields]
      }
    }

The error from client
[forest] 🌳🌳🌳 Unexpected error on Smart Action Form load hook retrieval HttpError: HTTP Error 422: Unprocessable Entity

Failure ~>

Request details ~>

And the whole Request Headers ~>

POST /forest/actions/creer-un-versement-membre/hooks/load?timezone=Europe%2FParis HTTP/1.1
Host: staging-culturepay.herokuapp.com
Connection: keep-alive
Content-Length: 324
sec-ch-ua: " Not A;Brand";v="99", "Chromium";v="96", "Google Chrome";v="96"
Accept: application/json
Content-Type: application/json
Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.eyJpZCI6IjE5NTQ1IiwiZW1haWwiOiJqdWxpZS5waWVycmUzQGdtYWlsLmNvbSIsImZpcnN0X25hbWUiOiJKdWxpZSIsImxhc3RfbmFtZSI6IlBpZXJyZSIsInRlYW0iOiI-IERhaWx5IE9wcyIsInJvbGUiOm51bGwsInRhZ3MiOltdLCJyZW5kZXJpbmdfaWQiOiI1ODU0NiIsImV4cCI6IjE2NDE5ODU1MjIifQ.JoCHlS6IGD_fGQUMRU1tVnBoNf_Q8kYVJuGOPRUY1PE
sec-ch-ua-mobile: ?0
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36
sec-ch-ua-platform: "macOS"
Origin: https://app.forestadmin.com
Sec-Fetch-Site: cross-site
Sec-Fetch-Mode: cors
Sec-Fetch-Dest: empty
Referer: https://app.forestadmin.com/
Accept-Encoding: gzip, deflate, br
Accept-Language: fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7

Hey @juliepierre :wave:

The logs you mentionned in your first message indicate ActionController::InvalidAuthenticityToken.
Would it be possible to see the associated code ? (As DM if you consider it private, here otherwise)

Thanks :pray: