-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
defaults with decimal places in them are reported differently on MariaDB, need to add decimal point for reflection #5744
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
Comments
hi there - let me illustrate a proper MCVE for the behavior you describe. note also that the issue template requests that you tell us what kind of database you're using; "10.5.5" seems to be a version number and does not tell us what database this is. Below is an illustration of the table given and your test script; it works without error as automap reflects that the "value1" column has a server default on it, so you will note it's not included in the INSERT. Please run this test case and feel free to modify it, including database in use, to illustrate how you are getting your results. thanks! from sqlalchemy import create_engine
from sqlalchemy import table
from sqlalchemy.ext.automap import automap_base
from sqlalchemy.orm import Session
engine = create_engine("sqlite://", echo=True)
with engine.begin() as conn:
conn.execute(
"""
CREATE TABLE fact_table (
id INTEGER PRIMARY KEY,
first INTEGER,
value1 DOUBLE DEFAULT 0,
value2 DOUBLE
)
"""
)
session = Session(engine)
base = automap_base()
base.prepare(engine, reflect=True)
table = getattr(base.classes, "fact_table")
kwargs = {"first": 200016, "value2": 1.0}
entry = table(**kwargs)
session.add(entry)
session.commit() output, after reflection queries are run: 2020-12-03 08:24:36,341 INFO sqlalchemy.engine.base.Engine BEGIN (implicit)
2020-12-03 08:24:36,341 INFO sqlalchemy.engine.base.Engine INSERT INTO fact_table (first, value2) VALUES (?, ?)
2020-12-03 08:24:36,341 INFO sqlalchemy.engine.base.Engine (200016, 1.0)
2020-12-03 08:24:36,342 INFO sqlalchemy.engine.base.Engine COMMIT
|
Hello @zzzeek , thank you for your reply. I added information about differences between our codes. Check it now and tell me if I should provide something more. |
hey there - just for future reference, the database you're using is MariaDB as the issue does not exist on MySQL, these are important details that help us to isolate the issue. |
for workaround you will need to provide a partial model with this column present:
|
Mike Bayer has proposed a fix for this issue in the master branch: Reflect decimal points in MariaDB non-quoted numeric defaults https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/2397 |
Mike Bayer has proposed a fix for this issue in the rel_1_3 branch: Reflect decimal points in MariaDB non-quoted numeric defaults https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/2398 |
Fixed issue where reflecting a server default on MariaDB only that contained a decimal point in the value would fail to be reflected correctly, leading towards a reflected table that lacked any server default. Fixes: #5744 Change-Id: Ifc5960928685a906558ba84ed6f59eecb3b1c358 (cherry picked from commit 7fb41cf)
Suppose I have table main_table with columns:
id (AUTO_INCREMENT), first (int), value1 (double with default=0), value2 (double)
Using code
I got an error
{"error": 500, "message": "(pymysql.err.IntegrityError) (1048, \"Column 'value1' cannot be null\")
It happens when
value1
doesn't accept null value.I'd like to ignore this and add entry after all
value1
is not obligatory (has default).Versions.
Edit:
MariaDB 10.5.5
SHOW CREATE TABLE main_table;
:db_connect = 'mysql+pymysql://[...]'
(fact_table is just a string with "main_table" inside)
The text was updated successfully, but these errors were encountered: