Skip to content

Over-long snapshot name 500s with the raw database error #8576

Closed

Description

@cstns

PUT /api/v1/snapshots/:id with a name longer than 255 characters returns:

500 value too long for type character varying(255)

The raw driver error goes straight to the caller. ProjectSnapshot.name is a DataTypes.STRING, so VARCHAR(255), and updateSnapshot in forge/db/controllers/Snapshot.js checks only that the name isn't blank:

if (hasProperty(options, 'name') && (typeof options.name !== 'string' || options.name.trim() === '')) {
    throw new ValidationError('Snapshot name is required')
}

255 characters works, 256 doesn't. Same story for the blank name just above it, which throws a sequelize ValidationError that nothing maps to a status code, so that one also comes back as a 500 (500 Snapshot name is required).

Worth knowing this only bites on postgres. SQLite ignores the declared column width, so on the default dev database an over-long name just saves, and a unit test on that backend wouldn't catch it.

Probably wants a length check next to the blank check, and both mapped to a 400 rather than falling through to the error handler. Related to #8568, which is the same shape of thing on the import route.

Also worth a thought: the name is validated trimmed but stored untrimmed, so " padded " is accepted and kept with the padding, which renders identically to "padded" in most places.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:apiWork on the platform APItype:bugSomething isn't working

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions