Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Library throws 'super' object has no attribute 'coerce' when column value is null() #55

Open
eskuat opened this issue Sep 5, 2023 · 4 comments

Comments

@eskuat
Copy link

eskuat commented Sep 5, 2023

Code to reproduce the exception

from sqlalchemy import Column
from sqlalchemy import create_engine, null, Integer
from sqlalchemy.dialects.sqlite import JSON
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy_json import mutable_json_type

Base = declarative_base()
eng = create_engine("sqlite://")


class JTable(Base):
    __tablename__ = 'jtable'
    id = Column(Integer, primary_key=True)
    value = Column(mutable_json_type(JSON, nested=True))


def create_table():
    conn = eng.connect()
    conn.execute(
        """
        CREATE TABLE IF NOT EXISTS jtable  (
            id INTEGER PRIMARY KEY,
            value TEXT NULL
        );
        """
    )


if __name__ == "__main__":
    create_table()
    # throws - AttributeError: 'super' object has no attribute 'coerce'
    row = JTable(value=null())

This seem very similar to #10 and probably can be solved by adding similar checks.
I can prepare a PR if necessary

@edelooff
Copy link
Owner

edelooff commented Sep 7, 2023

It sure looks like one of the paths is checked but the other one is left open. I'm curious if we really need two checks, or if the null() object compares equal to None, which would keep it a little more succinct.

Would happily accept a pr for this.

@eskuat
Copy link
Author

eskuat commented Nov 6, 2023

Would happily accept a pr for this.

Could you please take a look at PR ?

@BillSeitz
Copy link

I get this same error in flask/SqlAlchemy when trying to set a non-null value on a column. (Talking to postgresql.)
node.node_data = node_data

Or is there some other barely-related stupid mistake I'm making?

sqlalchemy-json_error 2023-11-26 at 3 34 57 PM

@chamini2
Copy link

I am seeing this happen when the JSON passed is a string (which is valid json)

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

No branches or pull requests

4 participants