I just had a major realization...stared at the code for a few minutes (for the 100th time) and realized this probably happens because I pass in a string when I create the object, and then if I access it before it saves to the DB it never gets parsed. That explains everything. I can't believe it took me half a year to have that 10-second realization. I promise I've spent countless of hours trying to figure this out, the fact that the realization came right after I sent the original email here is just a coincidence (or just magic, idk). Oh well. Would have been nice if the string got parsed directly when the object got created, instead of only when DB interaction occurs, but understandable if that's not how things work.
On Wednesday, November 14, 2018 at 9:55:26 PM UTC-5, Fredrik Blomqvist wrote: > > Hello, > > I've had this "ghost" issue for about half a year now, every now and then. > Essentially, I have a model with a DATERANGE column (to match my PostgreSQL > daterange column). "Most" of the time this works out well. However, > sometimes, seemingly depending on the exact code path (or something else > unexpected) the value from this column will not get parsed into a DateRange > object, but will instead be returned as a string (the string representation > of what's stored in the DB column). There is nothing wrong with the string > (e.g. it's exactly what is in the DB), but it should always be a DateRange > object (to be able to utilize methods such as lower/upper etc.). I took a > break from this project for a while but decided to now get to the bottom of > this issue. Sometimes I'll have it, make some random changes, and suddenly > it's gone for another few weeks or month. Then it'll show up again > eventually. Now, it doesn't happen every run. When it shows up, there are > usually a few of the tests that fail due to it, and then others that work > fine (because they get the expected DateRange object). I have not been able > to find a pattern of which code paths that cause this. At the moment, I > have one test that fails every run due to it, no others. If I run the tests > using the debugger I get a few more that fail (including the original one). > Very odd. > > My initial question is if anything has any idea (of the top of their head) > why this happens? I'm not sure if this has anything to do with SQLAlchemy. > It sorta sounds like an error with psycopg2. > > Best, > Fredrik > -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.
