Nikolay
Not that anyone would use upper case lambda arg names
Alexander
Thanks for reporting, I'll look into it #todo
In general I recommend to use lowercased names for lambda arguments and iterator variables
Damiano
Is it safe to install Pony 0.7.13?
Alexander
Yes
Genesis Shards Community
hi, need help with error
server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
used a thread
Genesis Shards Community
Alexander help me, please!
Genesis Shards Community
thread = Thread(target=db.agregar_paciente, args=(row_data[0], row_data[1], row_data[2], row_data[3], row_data[4], row_data[5],
row_data[6].strip(), row_data[7], row_data[8], row_data[9], row_data[10], row_data[11], row_data[12],
row_data[13], row_data[14], row_data[15], row_data[16], row_data[17], row_data[18],
row_data[19], row_data[20].strip(),))
# thread.daemon = True
thread.start()
Genesis Shards Community
por que me sale este error:
pony.orm.dbapiprovider.OperationalError: could not connect to server: Connection timed out (0x0000274C/10060)
Is the server running on host "56.39.151.144" and accepting
TCP/IP connections on port 5432?
Xavier
This seems to be a postgres error
Genesis Shards Community
Nikolay
Does this error still occur if you do not use a separate thread? Also this looks to be a completely different error from the one you posted earlier.
Nikolay
Nikolay
so which error do you have?
Genesis Shards Community
Matthew
https://github.com/PostgresApp/PostgresApp/issues/331#issuecomment-231018190
Matthew
try rebooting
Nikolay
If you have "localhost" in your db.bind arguments you can try replacing it with "127.0.0.1" if it still throws this error after the reboot.
You can also try connecting to your database using a client like DBeaver Community. If you can't connect with dbeaver then it's definitely not a ponyorm issue.
Genesis Shards Community
parece ser un problema de multiples thread insertando registros al mismo tiempo
Genesis Shards Community
will there be a way to insert 900000 records in less time with ponyorm?
Genesis Shards Community
with pony?
Jake A
Use SQL directly to insert that many, don't use the full ORM, all the overhead of the objects etc will crush your execution tiime.
Genesis Shards Community
in this case I load a csv file and it has 924987 records, via web with flask and python
Nikolay
It doesn't look like pony has any special method to mass insert large amount of rows
Nikolay
so yeah, i guess this is a question for developers
https://t.me/ponyorm/12850
Nikolay
For now if you find pony speed unacceptable for this usecase you can try using underlying pyscopg2 directly
Genesis Shards Community
I do it with the pony because I compare the records to see if there was a change
Lucky
Is https://editor.ponyorm.org down?
Alexander
.com
Lucky
Well that is confusing.
Lucky
But yeah, that was the issue
Lucky
Hey, I'm trying to build the top one database structure.
Basically in python I what the Chat object have a welcome and an rule field, both containing a Message.
And the Message should contain a single chat variable to link back to the Chat.
Lucky
I belive the top one would be how the database representation would probably need to look like
Lucky
How would I do that the best way?
Can I simply add two @propertys to Chat doing some join with the MessageOfChat tables to return a Message?
Lucky
Basically I try to move from mongo to SQL
Lucky
But I don't wanna clutter it with
welcome_text, welcome_set_by, welcome_update,
rules_text, rules_set_by, rules_update etc.
Lucky
Lucky
I belive this would be the best way.
However it is throwing the error:
Something went wrong: Attribute Welcome.chat conflicts with attribute Rules.chat because both entities inherit from Message. To fix this, move attribute definition to base class
Lucky
@metaprogrammer @akozlovsky
In the editor, setting the discriminator type fails.
Lucky
It always resets to None.
Lucky
Actually I would consider it a bug that those don't work. If the type of the variable would differ, that's a bug, but not the same.
Lucky
Alexander
Yeah, without Pony you just have two additional columns in Chat table. Pony does the same, just has two "fake" attributes in Message entity. Maybe late we can hide them
Lucky
Like the only limitation here is Pony saying that is an error.
Lucky
Which is not really a problem to do in a database…
Lucky
I mean if I could do
_welcome_chat = Optional('Chat', column='chat_id')
_rules_chat = Optional('Chat', column='chat_id')
Lucky
I mean what does it do to retrieve the values?
I imagine this is what pony does internally when I call chat.rules:
class Chat(…):
id = 123
rules = Optional(type='Message', column='rules')
@property
def rules(self):
orm.sql(f'SELECT FROM Messages WHERE'\
f' classtype = '{rules.type}' AND {rules.column} = '{self.id}'
)
Lucky
Like if you'd change https://github.com/ponyorm/pony/blob/1b6b27557f1900686069f950a7f8dc3266f38e52/pony/orm/core.py#L3824
if prev is not attr: throw(ERDiagramError,…
to
if prev != attr: throw(ERDiagramError,…
Why wouldn't that work?
Lucky
Like from an "is attribute the very same attibute" check to "is attribute a different attribute in terms of definition"?
Lucky
I mean that would be the workaround.
class Chad(db.Entity):
id = PrimaryKey(int, auto=True)
rules = Optional('RulesMessage')
welcome = Optional('WelcomeMessage')
_ignore_me = Set('Message')
class Message(db.Entity):
id = PrimaryKey(int, auto=True)
chat = Required(Chad)
class RulesMessage(Message):
_ignore_me_1 = Required(Chad)
class WelcomeMessage(Message):
_ignore_me_2 = Required(Chad)
Lucky
Vitaliy
Hello @metaprogrammer !
I found a bug in latest pony related to time difference.
I execute such a query:
select((s.user.id, s.url, str(datetime.utcnow()), s.lastseen, s.lastseen - datetime.utcnow()) for s in Session if s.lastseen > datetime.utcnow() - timedelta(days=1)).order_by('desc(s.lastseen)')
then q.limit(5).show() returns something like at screenshot bellow.
As we can see, pony treats timedeltas less than 1 hour always positive. I digged into pony/converting.py:203 and found following:
def str2timedelta(s):
if '.' in s:
s, fractional = s.split('.')
microseconds = int((fractional + '000000')[:6])
else: microseconds = 0
h, m, s = imap(int, s.split(':'))
td = timedelta(hours=abs(h), minutes=m, seconds=s, microseconds=microseconds)
return -td if h < 0 else td
I think there should be like this:
def str2timedelta(s):
negative = s.startswith('-')
if '.' in s:
s, fractional = s.split('.')
microseconds = int((fractional + '000000')[:6])
else: microseconds = 0
h, m, s = imap(int, s.split(':'))
td = timedelta(hours=abs(h), minutes=m, seconds=s, microseconds=microseconds)
return -td if negative else td
Vitaliy
Alexander
Hello @metaprogrammer !
I found a bug in latest pony related to time difference.
I execute such a query:
select((s.user.id, s.url, str(datetime.utcnow()), s.lastseen, s.lastseen - datetime.utcnow()) for s in Session if s.lastseen > datetime.utcnow() - timedelta(days=1)).order_by('desc(s.lastseen)')
then q.limit(5).show() returns something like at screenshot bellow.
As we can see, pony treats timedeltas less than 1 hour always positive. I digged into pony/converting.py:203 and found following:
def str2timedelta(s):
if '.' in s:
s, fractional = s.split('.')
microseconds = int((fractional + '000000')[:6])
else: microseconds = 0
h, m, s = imap(int, s.split(':'))
td = timedelta(hours=abs(h), minutes=m, seconds=s, microseconds=microseconds)
return -td if h < 0 else td
I think there should be like this:
def str2timedelta(s):
negative = s.startswith('-')
if '.' in s:
s, fractional = s.split('.')
microseconds = int((fractional + '000000')[:6])
else: microseconds = 0
h, m, s = imap(int, s.split(':'))
td = timedelta(hours=abs(h), minutes=m, seconds=s, microseconds=microseconds)
return -td if negative else td
Hi Vitaliy! Are you using PostgreSQL?
Vitaliy
No, I’ve migrated to MySQL
Alexander
I think you are right, this is a bug. I'll fix it
🔎 D̥ͦi̥ͦm̥ͦ
Hi guys,
I am a 1st-day Pony user,
trying to use existing Oracle database
CREATE TABLE ASSET
(
ASSET_SKEY NUMBER NOT NULL ,
...
name VARCHAR2(64) NULL ,
notes VARCHAR2(256) NULL ,
cost NUMBER NULL ,
EXPIRATION_DATE DATE NULL ,
SN VARCHAR2(32) NULL
);
ALTER TABLE ASSET
ADD PRIMARY KEY (ASSET_SKEY);
from pony.orm import *
set_sql_debug(True)
db = Database()
db.bind('oracle', *DB_CONNECTION_DETAILS)
class Asset(db.Entity):
asset_skey = PrimaryKey(int),
...
name = Optional(str),
notes = Optional(str),
cost = Optional(int),
expiration_date = Optional(datetime),
sn = Optional(str)
db.generate_mapping()
It tries to run the
SELECT "ASSET"."ID", "ASSET"."SN" FROM "ASSET" "ASSET" WHERE 0 = 1
and raises the cx_Oracle.DatabaseError: ORA-00904: "ASSET"."ID": invalid identifier
Is there a way to hint Pony that *primary key column name* is not 'id'?
Alexander
Hi! If you define Asset model as
class Asset(db.Entity):
asset_skey = PrimaryKey(int),
...
Pony should understand that the primary key is ASSET_SKEY and not ID
So I'm not really understand the reason of the error
🔎 D̥ͦi̥ͦm̥ͦ
OUCH,
note the commas in class declaration (the code was auto-generated)
Alexander
Ah, that's the reason
Evgeniy
Hey guys! I recently decided to compare the performance of pony ORM with SQLAlchemy.
I posted results on Hackernoon:
https://hackernoon.com/performance-testing-of-python-orms-based-on-the-tpc-c-benchmark-ae3g3yis
Your feedback is very appreciated
Lucky
Lucky
In the #editor there is a #bug where setting the discriminator type always fails. It always ends up None, no matter what I set in there.
Alexander
Hi Luckydonald! Thanks for bringing our attention to this bug. I hope I will have a time today to look into it
Lucky
https://editor.ponyorm.com/user/luckydonald/export1_1/designer
Lucky
I have no clue what's wrong there.
Lucky
How do I manually generate an SQL create statement from pony database definitions?
This online tool isn't working out
Nikolay
Nikolay
Is there a way to "properly" insert a new related object i using raw sql?
Consider this code. There's already a single parent created in the db. Uncommenting the # parent.children.load() line leads to
pony.orm.core.UnrepeatableReadError: Phantom object Child[19] appeared in collection Parent[1].children
is there a way to avoid that without rolling back the session? E.g. this happens without explicit children.load if parent is a newly created and committed instance instead of fetched-by-id one.
I'm using raw_sql insert because I want to use ON CONFLICT DO NOTHING to implement get-or-create that doesn't require a rollback. I want to avoid rollback because i'm using long-ish lived db sessions and re-fetching all objects after a rollback seems very very inconvenient if at all possible.
Nikolay
Perhaps there's a way to insert an object with ON CONFLICT DO NOTHING without writing full raw sql insert, but I couldn't find one.
Jacob
csa3d
say I have an existing SQLite db with a model that takes one required string. The load routine uses db.generate_mapping(create_tables=True. After some population/usage, I decide I want to add an optional boolean to said model. Using the same load routine, I receive an error pony.orm.dbapiprovider.OperationalError: no such column: MyModel.my_boolean
csa3d
my impression from the docs was that the create_tables would handle this addition, but that is obviously wrong assumption. What is the proper way to add additional model attributes to existing dbs?
csa3d
class Colors(db.Entity):
name = pony.orm.Required(str)
csa3d
to
csa3d
class Colors(db.Entity):
name = pony.orm.Required(str)
primary = pony.orm.Optional(bool)