Thanks for your responses. I've been doing quite a bit of probing and I
think I have what I need now to get the job done. Sorry for the confusion,
I wasn't being very clear.
The problem with setting active to 0 after the fact stems from the fact that
I'm only querying each database for the "active" records. The SIS database
has thousands of records of students that are no longer in the district, and
I don't need data on former students. So I query the SIS for the active
students, the ones that are going to school on the day my script runs. But
I have a list of "active" students also in my local database. When I query
for active students there, I'm getting the kids that were active a few days
ago, the last time the script was run. We may have had a student leave, and
I need to account for that so I can disable their user accounts.
I think with session.is_modified and with your suggestion to use
sqlalchemy.orm.attributes.get_history I can get all the information I need.
So, now if I start out by setting Student.active = 0 and then set
Student.active = 1 for each record I get back from the SIS, is_modified will
go back to false unless one of the other attributes changes, which is
exactly what I was hoping I could do in the first place. Then before my
commit, I can get a list or dictionary or whatever of the Student objects
that didn't get set back to active.
In doing all my probing, I found that setting a date attribute with a string
like '8/26/2011' causes is_modified to be true even if the date object
equaled date(2011, 8, 26) (ie. Student.AUPdate = '8/26/2011'), but if I
set it using datetime.strptime('8/26/2011', '%m/%d/%Y').date() then
is_modified stays false. This is important because I was seeing all sorts
of UPDATEs on records I knew had not changed when I was doing the merge, so
it was really throwing me and I couldn't tell what had truly changed.
Thanks again.
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/sqlalchemy/-/Bsbp_EKqJoMJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en.