Browse Source

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

* fix: added column length validation to sdk and service

* Apply suggestions from coderabbit

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* fix: remove length validator from SDK

* fix: use dtxp instead of clen

* fix: check if string before checking length

* refactor: rollback pnpm-lock.yaml

* fix: handle dtxp is not number

* refactor: rolled back pnpm-lock.yaml

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
pull/8618/head
Rohit 6 months ago committed by GitHub
parent
commit
71e6b59b78
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 10
      packages/nocodb-sdk/src/lib/sqlUi/MysqlUi.ts
  2. 20
      packages/nocodb/src/db/BaseModelSqlv2.ts
  3. 2
      pnpm-lock.yaml

10
packages/nocodb-sdk/src/lib/sqlUi/MysqlUi.ts

@ -1,5 +1,5 @@
import UITypes from '../UITypes';
import { IDType } from './index';
import { IDType } from '~/lib';
const dbTypes = [
'int',
@ -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) {

20
packages/nocodb/src/db/BaseModelSqlv2.ts

@ -4479,6 +4479,8 @@ class BaseModelSqlv2 {
);
}
await this.validateOptions(column, data);
// Validates the constraints on the data based on the column definitions
this.validateConstraints(column, data);
// skip validation if `validate` is undefined or false
if (!column?.meta?.validate || !column?.validate) continue;
@ -4514,6 +4516,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>,

2
pnpm-lock.yaml

@ -28424,4 +28424,4 @@ packages:
name: xlsx
version: 0.19.3
engines: {node: '>=0.8'}
hasBin: true
hasBin: true
Loading…
Cancel
Save