Edis
Do you know a way to prevent that from happening?
Edis
btw i'm using sqlite
Edis
I get following problem
Edis
pony.orm.sqltranslation.IncomparableTypesError: Incomparable types 'datetime' and 'str' in expression: m.starting_at >= Match.get(id=3213173).starting_at
Edis
Seems like I have to add a detect_types=sqlite3.PARSE_DECLTYPES in the connect (didn't find how to do it with pony orm though)
Edis
https://stackoverflow.com/questions/4429788/reading-back-a-datetime-in-sqlite3/4430061
Edis
can someone help me? :D
Lucky
Shouldn't the helper table of this actually index both colums and not only network_2?
Lucky
Edis
i did, it seems to be a common issue with sqlite
Edis
i'm figuring out how to configure it with pony orm
Edis
hope i dont need to use raw sql :D
Lucky
Huh I guess you have to wait until some of those Alexs comes online
Edis
seems like that doesn't work either for me, can't manage to bind the variables
Edis
pony.orm.dbapiprovider.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 0, and there are 1 supplied.
Lucky
How is the status of that branch?
Lucky
Is there a ticket tracking what's still left to do?
Lucky
And how does one get involved?
Alexander
It is a work in progress. We have a tests with different migrations, some of them still fail. I hope I'll have enough time during the rest of August to make it working on PostgreSQL.
Lucky
How can I migrate from a SQLite database to Postgres?
Alexander
You can create two db objects with same models but different connection parameters, select objects from one database and then create similar objects in another database.
You probably need to manually split the process into sequential batches and process each batch in a separate db_session
Lucky
Aww, I was kinda hoping there would be a migration tool, figuring that one out from the given data schema, like order of the tables and such.
Edis
from enum import Enum
from datetime import datetime
from pony.orm import *
from persistence.models import db
class Match(db.Entity):
id = PrimaryKey(int)
opponent = Required(Team)
venue = Required(str)
our_score = Optional(int)
opponent_score = Optional(int)
starting_at = Optional(datetime)
is_full_time = Required(bool, default=False, sql_default=False)
on_penalties = Required(bool, default=False, sql_default=False)
season_start = Required(int)
competition = Required(str)
matchday = Required(str)
goals = Set("Goal")
Lucky
I'm trying to get a database lock for migrating with psycopg2.
But for some reason I can't get past con.cursor()…
Lucky
Lucky
Lucky
Anyone already had that issue?
Lucky
It just seem to deadlock
Lucky
Uh. seems to be an issue with the logger actually not logging the last message.
Kyle
Hi
Kyle
Is there any way to generate tables if they doesn't exists on start?
Alexander
You can create tables using db.execute(...) or taking DBAPI connection using db.get_connection()
If you want to make new tables available to Pony, you can create new db object with extended model set and bind it to the same database
Kyle
So I need to generate them first?
Kyle
I meant to auto generate them on start
Alexander
What is your use-case?
Kyle
I'd like to generate a sqlite db with tables if it doesn't exists on start
Kyle
I already have the entities defined
Alexander
db.generate_mapping(create_tables=True)
Kyle
Oh
Kyle
I was doing
Kyle
db.bind(provider='sqlite', filename='db.sqlite', create_db=True)
db.create_tables()
db.generate_mapping()
Kyle
Worked
Kyle
Thanks very much
Alexander
Sure
Kyle
Sorry for being this dumb, I searched wrong on api
Alexander
np
Edis
Edis
```
from enum import Enum
from datetime import datetime
from pony.orm import *
from persistence.models import db
class Match(db.Entity):
id = PrimaryKey(int)
opponent = Required(Team)
venue = Required(str)
our_score = Optional(int)
opponent_score = Optional(int)
starting_at = Optional(datetime)
is_full_time = Required(bool, default=False, sql_default=False)
on_penalties = Required(bool, default=False, sql_default=False)
season_start = Required(int)
competition = Required(str)
matchday = Required(str)
goals = Set("Goal")
```
Alexander
Hey, you can find them above. I've used raw sql for now to make the comparison for now.
It is possible that database row for Match[3213173] contains starting_at value in incorrect format. This is possible if you insert row directly without using Pony.
In that case, when you do Match.get(id=3213173).starting_at, Pony reads row with incorrect starting_at value from the database, cannot convert it to date and leave it as is.
Try to print it to see actual value
Anonymous
guys your SSL cert for ponyorm.org expired
Alexander
Hi! Thanks, we'll fix it
Evgeniy
Hi. Do you already have any expectations when migrations will appear in Pony?
Alexander
I have to admit that with migrations it is difficult for me to make realistic estimates. I hope that by the end of August it will be possible to use migrations for PostgreSQL
Evgeniy
yippee
Evgeniy
Alexander
It will be similar, but some functionality may be missing at start
Evgeniy
Edis
It is possible that database row for Match[3213173] contains starting_at value in incorrect format. This is possible if you insert row directly without using Pony.
In that case, when you do Match.get(id=3213173).starting_at, Pony reads row with incorrect starting_at value from the database, cannot convert it to date and leave it as is.
Try to print it to see actual value
I've only used pony to create everything (schema and entities).
This is the format I get when I print starting_at:
'2019-08-11 13:00:00+00:00'
isinstance(str, match.starting_at) returns True
Schema in sqlite looks like this
sqlite> .schema Match
CREATE TABLE IF NOT EXISTS "Match" (
"id" INTEGER NOT NULL PRIMARY KEY,
"opponent" INTEGER NOT NULL REFERENCES "Team" ("id") ON DELETE CASCADE,
"venue" TEXT NOT NULL,
"our_score" INTEGER,
"opponent_score" INTEGER,
"starting_at" DATETIME,
"is_full_time" BOOLEAN NOT NULL,
"on_penalties" BOOLEAN NOT NULL,
"season_start" INTEGER NOT NULL,
"competition" TEXT NOT NULL,
"matchday" TEXT NOT NULL
);
CREATE INDEX "idx_match__opponent" ON "Match" ("opponent");
Model like this
class Match(db.Entity):
id = PrimaryKey(int)
opponent = Required(Team)
venue = Required(str)
our_score = Optional(int)
opponent_score = Optional(int)
starting_at = Optional(datetime)
is_full_time = Required(bool, default=False, sql_default=False)
on_penalties = Required(bool, default=False, sql_default=False)
season_start = Required(int)
competition = Required(str)
matchday = Required(str)
goals = Set("Goal")
Alexander
Pony doesn't store timezone-aware datetime values into the database. This value: '2019-08-11 13:00:00+00:00' was not stored using Pony. Correct value should be '2019-08-11 13:00:00.000000'.
As datetime values stored as strings and compared as strings, you can't correctly compare as string values '2019-08-11 13:00:00+00:00' and, say, '2019-08-11 12:00:00+01:00'
Edis
Hmm, I convert the datetime to utc before saving it into the db
Edis
So that's the issue?
Edis
I'll try to debug the timestamp before storing it :D
Edis
I store it with pony
Edis
I could try to just store it without converting it to utc
Edis
I want the datetime to be machine-independend though
Alexander
Hmm, this looks like a bug that Pony does not check that datetime value is not timezone-naive #todo
Edis
Cool, it's no problem for now since I'm using raw_sql to make the comparison
Edis
But it was confusing me
Alexander
It is a problem because you can read it back correctly using Pony
Edis
I mean for me now
Edis
Not that it shouldn't be fixed
Edis
Glad I could help find a bug :D
Alexander
The fix probably be in raising an error when dt.tzinfo is not None
Alexander
I think you need to do dt = dt.replace(tzinfo=None) before assigning it to attribute
And perform the following update to fix values in the database:
db.execute("""
update "Match"
set "starting_at" = replace("starting_at", '+00:00', '')
""")
Edis
But when I read it back I'll have the same problem, right?
Edis
It will just be a hack after the update