Skip to content
Discussion options

You must be logged in to vote

Yes, with a SQLAlchemy TypeDecorator passed as sa_type. SQLModel never converts the value itself. For IPv4Address / IPv6Address it only picks AutoString as the column type (get_sqlalchemy_type), and AutoString has no bind step, so the ipaddress object goes to the driver as is. Whether that works then depends on the driver. On SQLite, a plain ip: IPv4Address field fails the same way once the attribute holds an IPv4Address object:

sqlite3.ProgrammingError: Error binding parameter 1: type 'IPv4Address' is not supported

A decorator that does the conversion in both directions:

from ipaddress import IPv4Address, IPv6Address, ip_address

from pydantic.networks import IPvAnyAddress
from sqlalchemy.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@nicklockhart-fullfibre
Comment options

Answer selected by nicklockhart-fullfibre
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
2 participants