Feature(s) impacted
Show collections rows.
Observed behavior
I run the new agent on my local dev environment, when I access to a collection it shows this error :
Expected behavior
list rows
Failure Logs
- Project name: Clevermate
- Environment name: Development | AdelDjidjik
- Agent technology: nodejs
- Agent (forest package) name & version: “@forestadmin/agent”: “^1.0.0”,
- Database type: postgres
Hello @Adel_de_Clevermate,
thanks for your message.
It is strange that you do not have error details in your agent calls.
Could you please check that your agent configuration is not production.
In the createAgent
function, the property isProduction
of the options argument should be false
Hi @Nicolas.M
Thank your for your response.
I checked this and it is at false
since on index.ts
isProduction: process.env.NODE_ENV === 'production',
and on .env
NODE_ENV=development
Thanks for your response.
I was checking this because the isProduction
flag hides errors and returns 404 errors to the frontend.
But in your case, it seems like your agent returns an actual 404 error, so it is normal that there is no stack.
What might be causing the issue is the fact that you are using a layout that is coming from a v9 version of the agent, and you are trying to connect to the new agent, which handles collection names differently.
can you check if you can access the appointments
collection ? This one should work if my guess is correct
You could try altering your collection names so that they conform to the correct format (that is in your current schema)
example:
.addDataSource(createSqlDataSource({...}), {
rename(oldCollectionName) {
return convertToSnakeCase(oldCollectionName);
},
})
1 Like
Thanks for your reply.
Effectively for appointments
it doesnt return 404 but returns a 400 instead with log :
even renaming fields: (from the docs)
import renameAllFields, {
snakeToCamelCase,
} from '@forestadmin-experimental/plugin-rename-all-fields';
..
// Renaming fields
// All field will be renamed (the handler is called once per field)
agent.use(renameAllFields, snakeToCamelCase);
For other collections, I still got 404 even using this
agent.addDataSource(
createSqlDataSource({.. }),{
rename(oldCollectionName) {
return convertToSnakeCase(oldCollectionName);
},
}
);
using function convert:
export function convertToSnakeCase(oldName: string): string{
return oldName
.replace(/([a-z])([A-Z])/g, "$1_$2") // Insert an underscore between lowercase and uppercase letters
.toLowerCase(); // Convert the entire string to lowercase
}
I wonder if anything is not well configured here? @Nicolas.M
1 Like
I tried this way to rename the field
agent.customizeCollection('appointments', collection => {
collection.renameField('date_action', 'dateAction');
})
but I still get the same error :
ValidationError: Invalid filters (The 'appointments.dateAction' field was not found. Available fields are: [u_id,name,email,date_action,action_a_mener,status,title,entity]. Please check if the field name is correct.)
Let me know if you got any idea please.
Hello @Adel_de_Clevermate,
I am a bit puzzled as to why renaming is not working as expected. There might be some underlying issue that I am not seeing. I’ll try to reproduce and let you know if a fix is required
Thanks for your patience
1 Like
I have not managed to reproduce with a simple example of migration yet.
Looking through updates for your environment in our logs, I couldnt find any new schema being posted yesterday, the last one being on 18/11/2024 18:30:31. Did you manage to start the agent completely and see your schema being sent, like this:
Could you please try again, removing the renames that dont work and let your agent sync his agent-nodejs
schema with our backend ?
Can you tell me how you connect forest agent to your postgre database? Do you use a direct SQL connection or do you go through sequelize ?
what is the naming case convention for your database tables ?
if you use a sequelize connection what are the naming options enabled ? especially underscored
While you are at it you might try tweaking those options to see if it makes a difference
Thanks
Hi @Nicolas.M , thanks for checking,
When I restart forest in local (using docker restart, or docker compose down, and docker compose up) I still got that schema is not updated
I removed the renames of collections and fields.
We re connection to databse with direct connection with url
createSqlDataSource({
uri: process.env.DATABASE_URL,
schema: process.env.DATABASE_SCHEMA,
sslMode: process.env.DATABASE_SSL_MODE as SslMode,
}),
with ssl mode is disabled.
Our DB tables and fields names are on snake case.
I have tried to reproduce again with a similar example (snake_case all around), direct SQL connection, migrating from agent sequelize-express to agent-nodejs, but still not issue on my side.
It is strange that your schema does not get updated on forestadmin.
-
Did you check in your schema file (usually named forestadmin-schema.json
and it should be included in your source control tool) that your renames had an actual impact on the collection or field names ?
-
Can you try another change (like adding a custom field), and ensure that the schema is indeed impacted and the updated schema sent to our backend ?
-
Can you also try from a brand new environment, instead of changing the agent stack of Development | AdelDjidjik
This is actually what is recommended in order to migrate to the new agent
Migration steps | Node.js Developer Guide
You can create this new environment, connect the new agent to it, ensure that it works, migrate your code customizations, and at the end copy the layout (if the schema matches), and then promote to production once ready