I have a Next.js project where I'm using Prisma to read from Postgresql.
I have code like:
const rows = await prisma.receipts.findMany({
where: {
action_receipts: {
// https://www.prisma.io/docs/concepts/components/prisma-client/filtering-and-sorting#filter-on-relations
signer_account_id: {
equals: accountName,
},
},
},
orderBy: {
included_in_block_timestamp: 'desc',
},
take: 2,
});
I'm often getting errors like:
error: PrismaClientUnknownRequestError:
Invalid `prisma.receipts.findMany()` invocation:
Error occurred during query execution:
ConnectorError(ConnectorError { user_facing_error: None, kind: QueryError(Error { kind: Db, cause: Some(DbError { severity: "ERROR", parsed_severity: Some(Error), code: SqlState("42P05"), message: "prepared statement \"s0\" already exists", detail: None, hint: None, position: None, where_: None, schema: None, table: None, column: None, datatype: None, constraint: None, file: Some("prepare.c"), line: Some(480), routine: Some("StorePreparedStatement") }) }) })
(Sometimes instead of "s0" it says something else though, such as "s8".)
What does this mean, and how can I avoid it?
It seems like the problem often goes away if I stop my local server and wait a minute and then start again via yarn dev and then try my Prisma query again. But I'm oblivious to the root cause, which I want to identify and solve.
I restarted the project on superbase and it worked.
Go to the settings on the supabase project file and click on restart project
Related
I am using prisma to update some fields but i am getting error.
I am using unique id to update the data.
Before update i am able to get all the data from table so prisma is working on select
const cartUpdate = await prisma.custom_checkout__c.update({
where: {
id: uniqueId,
},
data: {
status__c: 'Checkout completed',
coupon_code__c: coupon,
checkout_id__c: result.subscription.id,
}
})
Error is below
PrismaClientUnknownRequestError:
Invalid `prisma.custom_checkout__c.update()` invocation:
Error occurred during query execution:
ConnectorError(ConnectorError { user_facing_error: None, kind: QueryError(Error { kind: Db, cause: Some(DbError { severity: "ERROR", parsed_severity: Some(Error), code: SqlState(E42883), message: "function get_xmlbinary() does not exist", detail: None, hint: Some("No function matches the given name and argument types. You might need to add explicit type casts."), position: Some(Internal { position: 2, query: "(get_xmlbinary() = 'base64')" }), where_: Some("PL/pgSQL function hc_custom_checkout__c_status() line 3 at IF"), schema: None, table: None, column: None, datatype: None, constraint: None, file: Some("parse_func.c"), line: Some(629), routine: Some("ParseFuncOrColumn") }) }) })
at RequestHandler.handleRequestError (/Users/bi
Sequelize version: 6.13.0
Database version: PostgreSQL 13.3
Whenever there's an issue with a query, Sequelize doesn't tell me the actual issue. For example, this old Stack Overflow post shows Sequelize displaying an error that a column is unknown. In my case, I receive a generic error message and need to manually inspect the queries and my database tables to find out what's wrong. Here's an example:
const user = await User.findByPk(params.id);
const settings = await Setting.findAll({ attributes: ['id', 'key', 'defaultValue'] });
const userSettings = await user.getUserSettings({ attributes: ['id', 'key', 'value'] });
This will produce the following SQL:
Executing (default): SELECT "id", "name", "email", "password", "referralCode", "referredByUserId", "bio", "twitterUrl", "facebookUrl", "instagramUrl", "createdAt", "updatedAt" FROM "Users" AS "User" WHERE "User"."id" = '1';
Executing (default): SELECT "id", "key", "defaultValue" FROM "Settings" AS "Setting";
Executing (default): SELECT "id", "key", "value" FROM "UserSettings" AS "UserSetting" WHERE "UserSetting"."userId" = 1;
And here's the error message:
/home/user/app/backend/node_modules/sequelize/lib/dialects/postgres/query.js:76
const errForStack = new Error();
^
Error:
at Query.run (/home/user/app/backend/node_modules/sequelize/lib/dialects/postgres/query.js:76:25)
at /home/user/app/backend/node_modules/sequelize/lib/sequelize.js:642:28
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at PostgresQueryInterface.select (/home/user/app/backend/node_modules/sequelize/lib/dialects/abstract/query-interface.js:979:12)
at Function.findAll (/home/user/app/backend/node_modules/sequelize/lib/model.js:1789:21)
at HasMany.get (/home/user/app/backend/node_modules/sequelize/lib/associations/has-many.js:228:21)
I had to manually check my database tables, and I found out that the key column is not present on the UserSettings table.
Why doesn't Sequelize tell me this on any of my models? Is there some configuration I'm missing?
As #Anatoly mentioned in the comments, I just needed to catch the errors in try-catch block, like this for example:
try {
const user = await User.findByPk(params.id);
const settings = await Setting.findAll({ attributes: ['id', 'key', 'defaultValue'] });
const userSettings = await user.getUserSettings({ attributes: ['id', 'key', 'value'] });
} catch (e) {
console.log(e);
next(e);
}
Coming from a Ruby on Rails background, I had expected the errors to be shown in the output of my terminal running the Express server, but that doesn't seem to be the case.
Thanks #Anatoly, debugging will be a lot easier now!
I'm getting the error
Invalid exit definition ("success"). Must be a dictionary-- i.e. plain JavaScript object like `{}`.
Invalid exit definition ("error"). Must be a dictionary-- i.e. plain JavaScript object like `{}`.
when doing sails lift. The error is on getRole.js
module.exports = {
friendlyName: 'Get Role',
description: '',
inputs: {
user_id: {
friendlyName: 'User Id',
description: 'The ID of the user to check role',
type: 'string',
required: true
}
},
exits: {
success: function (role){
return role;
},
error: function (message) {
return message;
}
},
fn: function (inputs, exits) {
User.findOne({ id: inputs.user_id } , function (err, user) {
if (err) return exits.err(err);
return exits.success(user.role);
});
}
};
This is a new error, and looking at my git, nothing has changed in my code since it successfully compiled. I understand the Sails version (v1.0) I'm using in beta, so I'm taking that into account.
Exits cannot be defined as functions. There is a special syntax (Machine Spec) to define exits. In your example this should work:
exits: {
error: {
description: 'Unexpected error occurred.',
},
success: {
description: 'Role was succesffuly fetched'
}
},
You can read more info about helper exits here: https://next.sailsjs.com/documentation/concepts/helpers
May changes occur on the last release 1.0.0-38. I've not checked underneath yet, but the way to execute helpers changed: on .exec() I get errors. Now, use .switch();
I am having an issue getting validation error messages to attach to the error object in sails v1.0. I am using the sails-hook-validate module.
User model:
module.exports = {
attributes: {
name: {
type: 'string',
required: true,
}
},
validationMessages: {
name: {
required: 'Name is required'
},
},
};
Running User.create in the sails console:
sails> User.create({}).exec(err => console.log(err.toJSON()));
{ error: 'E_UNKNOWN',
status: 500,
summary: 'Encountered an unexpected error',
Errors: undefined }
It appears sails-hook-validate is modifying the error object in some way, but it doesn't seem to be adding my custom error message in any way. Does anybody know how to get sails-hook-validate to work in Sails v1.0?
Sails v1 dramatically changed how validation errors are formatted and sails-hook-validate hasn't been updated to handle Sails v1 yet.
Sails-hook-validate is a third party hook and I dont think its been updated to work with Sails V1.
As #jeffery mentioned the structure of validation errors did change slightly in Sails V1 but there could be other changes that are effecting this hook.
I have a sails app working against a legacy database (MySQL) and I would like to perform integration tests. I am using fixtures to load data into a separate test database using barrels. When I run my tests I get an error:
[Error (E_UNKNOWN) Encountered an unexpected error] Details: Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1
Interview.js api/models/Interview.js:
module.exports = {
tableName: 'interview',
attributes: {
interviewId: {
type: 'integer',
columnName: 'interview_id',
primaryKey: true,
unique: true
},
...
}
};
interview.json tests/fixtures:
[
{
"interviewId": 1,
"title": "some string",
"createdDate": "2015-11-23T09:09:03.000Z",
"lastModified": "2015-11-23T09:09:03.000Z"
},
{...}
]
test environment config/env/test.js :
models: {
connection: 'test',
migrate: 'drop',
autoPK: false,
autoCreatedAt: false,
autoUpdatedAt: false
}
The problem seems to lie in defining a primary key in the schema rather than letting sails create one automatically. If I remove the interviewId field from the model and set autoPK: true it works. But this does not accurately represent my data structure.
App info:
sails#0.11.2 sails-mysql#0.11.2 waterline#0.10.27 barrels#1.6.2 node v0.12.7
Many thanks,
Andy