Cannot deploy branch - schema difference

Feature(s) impacted

Unable to deploy a local (empty) dev branch due to schem diff with origin env (production)

Observed behavior

The command:
``
fails - and a schema diff shown only including the following difference:

{
       attributes: {
         fields: [
           {
-            hook: "onFeeChange"
           }
           ...
           ...
         ]
       }
     }

Expected behavior

Since the same .forestadmin-schema.json file was deployed (verified to be deployed correctly) to both envs - there should be no schema diffs.

Context

  • Project name: WescoverContentAdmin
  • Environment name: Production (44638) and the local one id is (104873)
  • Agent (forest package) name & version:
"meta": {
    "liana": "forest-express-mongoose",
    "liana_version": "8.7.6",
    "stack": {
      "database_type": "multiple",
      "engine": "nodejs",
      "engine_version": "16.18.0",
      "orm_version": "5.3.16"
    }
  }

forest-cli/4.2.0 darwin-arm64 node-v16.18.0

  • Database type: mongoose
  • Recent changes made on your end if any: Ensures reset envs of Dev, cleaned old branches, rebuilt using node 16 (used to be 12) and ensured same schame json file used on all envs. Created a new clean empty branch that we try to deploy.

performing the schema:diff command shows the same schema for Production, Test (72395), Dev (72437) And all have that same “hook” diff with the local dev env (104873).

Not sure what could cause such a difference in schemas.

Hello @Yoad_Snapir, and welcome back to the community,

the hook: “onFeeChange” is added to your schema due to a change hook detected in your customization:
(please find the documentation here),

Please check that your action definition for ‘Modify Commission’ is the same in production and local environments, especially regarding change hooks as per the documentation linked.

If you still encounter issues, please share your action definition in each environment so we can help you troubleshoot (via MP if sensitive).

Regards,

@Nicolas.M

Thank you @Nicolas.M!

I suspected this is the why we have this hook in the schema.
Indeed the action definition has this:

{
  field: 'Application Fee',
  description: 'Please provide new Application Fee (in Cents)',
  type: 'Number',
  hook: 'onFeeChange',
  isRequired: true,
},

And then this:

hooks: {
 ...,
change: {
    onFeeChange: async ({ fields, request, changedField }) => {
      const mpCom = fields.find(
        (field) => field.field === 'MP Commission'
      );
      const proFee = fields.find(
        (field) => field.field === 'Processing Fee'
      );
      mpCom.value = changedField.value - proFee.value;
      return fields;
    },
  },
}

BUT the same code was deployed to the local env and the live env.
This is the strange part - it is as if the prod/test/dev envs, (which are sent the same schema file generated locally) do not “accept” and store that hook in the internal schema.
Then - this difference shows up when we try to push a layout branch.

@Nicolas.M making sure you saw my reply.
Thanks.

Hello @Yoad_Snapir,
Sorry for the delay, your issue is a little hard to troubleshoot.

A couple things you can try/check while we investigate further:

  • make sure that your local branch contain changes. I don’t think that you are supposed to push an empty branch.
  • contrary to the dev environments, the production schema is NOT recomputed automatically by the agent on startup, even if your code changes. You might want to make sure that your prod schema is in sync with the code.

Regards

@Nicolas.M I will not be concerned about the empty branch deployment.
The schema:diff shows that problem already without even thinking about branch deployments.

The schema file is the same - the local dev puts it into the source report (checkin) and the production pulls it fro that same repo, same branch - they are identical.

I am now seeing this difference though - production uses forest-cli v3.x to push the schema the local env uses forest-cli v4.x
Could that cause the difference?
After all the forest-cli is not the one generating the schema, only pushes it rather - but still - do you think this could be the cause?

Hello @Yoad_Snapir,

I have escalated the question and we are still looking into it. Thanks for your patience, we will keep you updated shortly.

Looking through your schemas, it not clear why the production is missing the
hook: "onFeeChange", which should be there according to the code you shared.

Can you please share the value of your NODE_ENV variable in the different envs ?

If this is an option for you, could you please update your production schema to match the local one ? (with the expected hook property).
This should allow you to deploy the local branch.

Thanks @Nicolas.M - As you would expect my local dev (where the schema is generated) has the value “development” for “NODE_ENV” (it’s empty, development is the default afaik).
and the Production (and all remote) env has “production”.

To double check schema is the same:
I have done the following:

  1. Copied the schema from the local dev env (which is == to the one in the repo and == to the one already on the remote server)
  2. Used that schema on the remote server (just in case, although diff shows they are identical)
  3. installed on the server the forest-cli tool (version 3, and also did the same with version 4)
  4. did forest schema:apply
  5. got this result:
    Reading “.forestadmin-schema.json” from current directory…
    Using the forest environment secret found in the environment variable “FOREST_ENV_SECRET”
    Sending “.forestadmin-schema.json”…
    The schema is the same as before, nothing changed.
  6. Ran again locally forest schema:diff
  7. got again the hook as a difference.

Hi @Yoad_Snapir :wave: small question, I wonder why you use forest schema:apply instead of restarting your server after synchronizing the code (with forestadmin-schema.json)?

Good question!
We deploy to production using blue/green - so we deploy to a staging env, and them swap servers.
Thus - I need to be in control of the schema apply.

I I leave it to the server - the swapped out “old version” is started as the new “staging” and overrides the schema with the old one.

So the flow using auto apply looks like this:

  1. existing version X0 on live
  2. deploy version X1 to staging - applies X1 schema
  3. Swap in - starts staging with X1 as “live” - applies X1 to live (as we want)
  4. Swap out - starts live as with X0 as “staging” - applies X0 to live (we don’t want that)

we tries setting up the env of the staging to point at another “remote env” - but we cannot control how many restarts happens and with which env - it’s not a “clean” process.

we need tight control on schema apply thus.

Let me know if you need more info on this.

Found it ! Oh wouah after a deep research I found the culprit.
There is a missing serialization attribute inside the forest cli, who remove the hook property, on the schema:apply command.
I will fix that right away and keep you updated.
Thank’s for your feedback :pray:

1 Like

Hey @Yoad_Snapir :wave: the fix has been released now.
Can you upgrade forest-cli to the latest version (v4.2.2) and re-apply the schema of your remote env ? :pray:
Let me know.

1 Like

This solved it!
Thanks for the help here, Forest cli after all was the cause - good to know.

2 Likes