Skip to content

Usage of JSON(none_as_null=True) with CockroachDB causes infinite diffs in Alembic #291

@NotJustPizza

Description

@NotJustPizza

Description

Trying to set JSON(none_as_null=True) for SQLAlchemy models causes constant diffs in Alembic.

FYA: @gordthompson

Reproduction:

Setup:

from sqlalchemy import Column, DateTime, JSON
from sqlalchemy.orm import declarative_base

Base = declarative_base()

class TestModel(Base):
    __tablename__ = "test"

    id = Column(Integer, primary_key=True)
    mydata = Columnt(JSON(none_as_null=True))

Run commands:
alembic revision -m init --autogenerate
alembic upgrade head
alembic check

Alembic output:

INFO     Context impl CockroachDBImpl.                                                                     
INFO     Will assume non-transactional DDL.                                                               
INFO     Detected type change from JSONB(astext_type=Text()) to JSON(none_as_null=True) on 'test.mydata'   compare.py:1003
ERROR    New upgrade operations detected: [[('modify_type', None, 'test', 'mydata', {'existing_nullable':  messaging.py:71
         True, 'existing_server_default': False, 'existing_comment': None}, JSONB(astext_type=Text()),                                   
         JSON(none_as_null=True))]]          

Versions

OS: Windows 11 OR Docker Image python:3.13.11-slim-trixie
Python: 3.13.11
Alembic: 1.17.2
SQLAlchemy: 2.0.46 (latest)
Database: Cockroach 25.4.2 or Docker Image cockroachdb/cockroach:v25.4.2
DBAPI: sqlalchemy-cockroachdb 2.0.4.dev0 from main branch (sha: d57d176be810c75696678efc04493f51fdecfa85)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions