Skip to content

fix: harden table-ID sequence names in SequenceCheck (invalid names, typo auto-fix, save validation)#623

Merged
yamelsenih merged 1 commit into
solop-develop:developfrom
EdwinBetanc0urt:bugfix/sequencecheck-harden-table-id-sequence-name
Jul 8, 2026
Merged

fix: harden table-ID sequence names in SequenceCheck (invalid names, typo auto-fix, save validation)#623
yamelsenih merged 1 commit into
solop-develop:developfrom
EdwinBetanc0urt:bugfix/sequencecheck-harden-table-id-sequence-name

Conversation

@EdwinBetanc0urt

Copy link
Copy Markdown
Member

Problem

Running the Sequence Check process fails with a PostgreSQL syntax error for sequences flagged IsTableID='Y' whose name is not a valid identifier:

DB.executeUpdate: CREATE SEQUENCE ATAJO DE COMANDOS PDV_SEQ INCREMENT 1 MINVALUE 0 MAXVALUE 99999999 START 1000000
org.postgresql.util.PSQLException: ERROR: syntax error at or near "DE"

A table-ID sequence name must be a valid SQL identifier because the native sequence is created/consumed as <Name>_SEQ. Some records are document sequences mis-flagged as IsTableID='Y', and their names contain spaces. The failed CREATE SEQUENCE also aborts the transaction, so the corrected AD_Sequence record is not saved.

Changes

This hardens table-ID sequence names in three layers:

  1. Skip invalid names when creating the native sequence (createMissingNativeSequence): validate the name is a SQL identifier before issuing CREATE SEQUENCE; otherwise log a warning (with Name + AD_Sequence_ID) and skip.

  2. Auto-fix typos (fixTableSequenceName): if an invalid name's canonical form (whitespace → _) matches a real table (case-insensitive) that has a <name>_ID column, correct the stored name to the real AD_Table.TableName (exact casing). This rescues records that were simple typos so they validate and get their native sequence.

  3. Prevent bad data at the source (MSequence.beforeSave): reject saving a sequence flagged IsTableID='Y' when its name is not a valid identifier. Document sequences (IsTableID='N') are unaffected and may keep spaces/accents.

How to test

  1. With SYSTEM_NATIVE_SEQUENCE=Y, have an AD_Sequence with IsTableID='Y' and a name containing spaces.
  2. Run the Sequence Check process.
  3. Before: PSQLException: syntax error, transaction aborted.
  4. After:
    • If the canonical name matches a real table → the sequence is renamed and validated (log: Sequence name fixed => ...).
    • Otherwise → a WARNING identifying the misconfigured record; no exception; the process continues.
  5. Try saving an AD_Sequence with IsTableID='Y' and a spaced name → rejected with a validation message.

Notes

  • Behavior-preserving for valid table-ID sequence names and for document sequences.
  • Touches SequenceCheck.java and MSequence.java.
  • Layers 2 and 3 are more opinionated (data auto-correction and save validation); can be split out if reviewers prefer the minimal crash-fix (layer 1) alone.

🤖 Generated with Claude Code

…typo auto-fix, save validation)

## Problem

Running the Sequence Check process fails with a PostgreSQL syntax error for
sequences flagged IsTableID='Y' whose name is not a valid identifier:

    CREATE SEQUENCE ATAJO DE COMANDOS PDV_SEQ INCREMENT 1 MINVALUE 0 MAXVALUE 99999999 START 1000000
    org.postgresql.util.PSQLException: ERROR: syntax error at or near "DE"

A table-ID sequence name must be a valid SQL identifier because the native
sequence is created/consumed as <Name>_SEQ. Some records are document
sequences mis-flagged as IsTableID='Y', and their names contain spaces. The
failed CREATE SEQUENCE also aborts the transaction, so the corrected
AD_Sequence record is not saved.

## Changes

1. Skip invalid names when creating the native sequence
   (createMissingNativeSequence): validate the name is a SQL identifier before
   issuing CREATE SEQUENCE; otherwise log a warning (with Name + AD_Sequence_ID)
   and skip.

2. Auto-fix typos (fixTableSequenceName): if an invalid name's canonical form
   (whitespace -> '_') matches a real table (case-insensitive) that has a
   <name>_ID column, correct the stored name to the real AD_Table.TableName
   (exact casing). This rescues records that were simple typos so they validate
   and get their native sequence.

3. Prevent bad data at the source (MSequence.beforeSave): reject saving a
   sequence flagged IsTableID='Y' when its name is not a valid identifier.
   Document sequences (IsTableID='N') are unaffected and may keep spaces/accents.

## Notes

- Behavior-preserving for valid table-ID sequence names and for document sequences.
- Touches SequenceCheck.java and MSequence.java.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@yamelsenih yamelsenih merged commit 7056b59 into solop-develop:develop Jul 8, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants