Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nc-fix/ SingleLineText Fields silently dropping larger than length values #8437

Merged
10 changes: 3 additions & 7 deletions packages/nocodb-sdk/src/lib/sqlUi/MysqlUi.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import UITypes from '../UITypes';
import { IDType } from './index';
import { IDType } from '~/lib';

const dbTypes = [
'int',
Expand Down Expand Up @@ -630,17 +630,13 @@ export class MysqlUi {

static colPropUNDisabled(col) {
// console.log(col);
if (
return !(
col.dt === 'int' ||
col.dt === 'tinyint' ||
col.dt === 'smallint' ||
col.dt === 'mediumint' ||
col.dt === 'bigint'
) {
return false;
} else {
return true;
}
);
}

static onCheckboxChangeAI(col) {
Expand Down
20 changes: 20 additions & 0 deletions packages/nocodb/src/db/BaseModelSqlv2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4492,6 +4492,8 @@ class BaseModelSqlv2 {
);
}
await this.validateOptions(column, data);
// Validates the constraints on the data based on the column definitions
this.validateConstraints(column, data);
rohittp0 marked this conversation as resolved.
Show resolved Hide resolved

// skip validation if `validate` is undefined or false
if (!column?.meta?.validate || !column?.validate) continue;
Expand Down Expand Up @@ -4527,6 +4529,24 @@ class BaseModelSqlv2 {
return true;
}

/*
* Utility method to validate database constraints
*/
protected validateConstraints(
column: Column<any>,
data: Record<string, any>,
) {
if (
typeof data[column.title] === 'string' &&
typeof column.dtxp === 'number' &&
column.dtxp < data[column.title]?.length
) {
NcError.badRequest(
`Column "${column.title}" value exceeds the maximum length of ${column.dtxp}`,
);
}
}

// method for validating otpions if column is single/multi select
protected async validateOptions(
column: Column<any>,
Expand Down
2 changes: 1 addition & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.