I'm trying to write an idempotent migration script and avoid updates when column values don't change. I can see that sqlalchemy-continuum usually does this, but I've found a case where different float representations seems to break that and I get unnecessary, empty record revisions.
Is there a recommended pattern for dealing with that? Details follow.
I added logging every time is_modified says an object has changed to see what's triggering the empty changesets.
records = session.query(MyModel)
for record in records:
prior_value = record_value
record.value = value
if session.is_modified(record):
LOGGER.info("prior value: %.16f value: %.16f - %d %s",
prior_value, value, record.id, changeset(record))
I see this on every run where the changeset winds up empty, so it seems SQLA sees it as a change, which triggers continuum. But then later on continuum sees no change set and PropertyModTrackerPlugin doesn't flag value as modified.
Sorry, but I cannot find a simple repro for this. It's in a script copying data from two different database engines (sqlite -> postgres). The source is a REAL in sqlite read through SQLA inspection, Table(autoload=True). The target is a double precision in Postgres defined in SQLA as a Float.
I'm trying to write an idempotent migration script and avoid updates when column values don't change. I can see that sqlalchemy-continuum usually does this, but I've found a case where different float representations seems to break that and I get unnecessary, empty record revisions.
Is there a recommended pattern for dealing with that? Details follow.
I added logging every time
is_modified
says an object has changed to see what's triggering the empty changesets.I see this on every run where the changeset winds up empty, so it seems SQLA sees it as a change, which triggers continuum. But then later on continuum sees no change set and PropertyModTrackerPlugin doesn't flag
value
as modified.A check for how many revisions were made to the record:
Output:
Sorry, but I cannot find a simple repro for this. It's in a script copying data from two different database engines (sqlite -> postgres). The source is a
REAL
in sqlite read through SQLA inspection,Table(autoload=True)
. The target is adouble precision
in Postgres defined in SQLA as aFloat
.