Skip to content

Don't crash when an altered column's old class is a custom Column subclass - #1429

Merged
dantownsend merged 1 commit into
piccolo-orm:masterfrom
pavdwest:fix-alter-column-custom-class-crash
Sep 6, 2026
Merged

dantownsend merged 1 commit into
piccolo-orm:masterfrom
pavdwest:fix-alter-column-custom-class-crash

Conversation

@pavdwest

@pavdwest pavdwest commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

SchemaDiffer.alter_columns looks up UniqueGlobalNames.COLUMN_<NAME> for both the new and the old column class, to spot an import that would conflict with a name the generated migration already uses. The lookup for the new class passes a None default; the one for the old class does not, so altering a column whose previous class was a user-defined Column subclass raises

AttributeError: type object 'UniqueGlobalNames' has no attribute
'COLUMN_CUSTOMVARCHAR'

and piccolo migrations new --auto dies before writing anything.

UniqueGlobalNames only carries the built-in column classes, so a miss is the expected outcome for any subclass a user defines — which is a supported thing to do, and common for projects that wrap a column type to add a default or narrow its type. Five of the six lookups in this module already pass None; this makes the sixth behave the same way.

Closes #1428 (#1428)

…class

`SchemaDiffer.alter_columns` looks up `UniqueGlobalNames.COLUMN_<NAME>` for
both the new and the old column class, to spot an import that would conflict
with a name the generated migration already uses. The lookup for the new class
passes a `None` default; the one for the old class does not, so altering a
column whose previous class was a user-defined `Column` subclass raises

    AttributeError: type object 'UniqueGlobalNames' has no attribute
    'COLUMN_CUSTOMVARCHAR'

and `piccolo migrations new --auto` dies before writing anything.

`UniqueGlobalNames` only carries the built-in column classes, so a miss is the
expected outcome for any subclass a user defines — which is a supported thing
to do, and common for projects that wrap a column type to add a default or
narrow its type. Five of the six lookups in this module already pass `None`;
this makes the sixth behave the same way.

Closes piccolo-orm#1428
@dantownsend

Copy link
Copy Markdown
Member

Looks great, thanks! 👍

@dantownsend
dantownsend merged commit f4d2d31 into piccolo-orm:master Sep 6, 2026
41 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.

piccolo migrations new --auto crashes when an altered column's previous class was a custom Column subclass

2 participants