Alexander
I think optional fields are not logically compatible with unique constraint
Alexander
Cause empty value can only appear once
jorge
sorry, pip install pony not working, ERROR: Could not install packages due to an OSError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Max retries exceeded with url: /packages/68/2e/d7f36d21ce7e1df1d7a02bdb38541ccf5f9c18c2656ae3698acee29447a4/pony-0.7.16-py3-none-any.whl (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate (_ssl.c:997)')))
jorge
is it me? or should i wait?
Alexander
Hi! pip installs pony from PyPi, it does not access any Pony-specific servers. Probably, this is a problem with PyPi, and not limited to Pony
jorge
thank you so much!
Luis
Hi Alexander, I have a question, what is the best practice, I have one file with some entity's, but when load this file in different modules, the start of my application is slow, it's convenient create one file for module and class?
Example:
Modules client, sales, products, user, employees;
And I load the file in each module
Nathan
Hello, after succesfullly installing pony with Pip, i continued opening interpreter (by simply using the command ''py''.
I then tried using the ''>>> from pony.orm import *'' command and i get the following syntax errors
Nathan
Nathan
Anyone who know where I went wrong?
Nathan
Appreciate any helpp
Volbil
Don't put >>> at the beginning of command
Nathan
https://i.imgur.com/3aLbezY.png
Nathan
Don't think anything happens now
Volbil
Yep
Nathan
Aweomse, thanks
Volbil
:)
Nathan
Awesome*
Amo
Hey, I have a huge table of sensor data with da datetime timestamp and I want to get only the last value per day or month. Is there any way to achieve this with pony?
Volbil
Volbil
Something like this:
Record.select(
lambda r: r.created > MONTH_START_DATETIME and r.created < MONTH_END_DATETIME
).order_by(
Record.created
).first()
Jacob AKA Sartre
It's always going to be slower to make many searches I think
Alexander
Amo
Postgres
Amo
I know there is interval, but I try to avoid raw sql because our tests run in sqlite
Alexander
So you need a query that works both in PostgreSQL and SQLite?
Amo
Yes. Or I keep my solution because it is fast enough for now
Alexander
Something like that should be fast enough:
def monthly_data(sensor_type):
first_id_per_month = select(
(min(x.id), x.dt.year, x.dt.month)
for x in SensorData
if x.sensor_type == sensor_type
and x.dt >= datetime.now() - timedelta(days=365)
).fetch()
ids_list = [id for id, year, month in first_id_per_month]
sensor_values = select(
x for x in SensorData if x.id in ids_list
).order_by(lambda x: x.id).fetch()
return sensor_values
Alessandro
hi everybody, I have a problem. I was trying to create a dabase (here the code https://nekobin.com/cisifihola) but I keep getting this error. Anyone knows why?
Alexander
Looks like a bug. Can you show the definition of entities?
Alexander
Ah, I see it
Alexander
favorite_color = Set(int)
Set(int) is currently not supported, you can specify only entity class as a set item type.
If you need to specify multiple colors, you can use IntArray instead, or you can create a Color entity and specify it as a Set item type
Alessandro
Jan
Don't know if relevant, but: Since last ponyorm / pymysql update, I started receiving
Access denied for user 'root'@'127.0.0.1'
when trying
db.bind(...)
I am pretty sure this is due to an update with pymysql. If you are by chance encountering the same thing, make sure to check that the host is correct. Localhost is now translated to 127.0.0.1
And the user
root@127.0.0.1
was not defined for me, only for localhost. This worked fine before, but not now. Didn't update MySQL.
Lucky
editor.ponyorm.com seems down-ish.
Lucky
At least it's returning
{
"msg": "Server error"
}
all over the place
Lucky
login only worked after the 5th try
Lucky
/create-diagram doesn't seem to work at all
Alexander
Thanks for reporting! Will fix it
Lucky
👍
Alexey
Lucky
Was it a service which went down?
Alexey
the database is pretty big now, need to add more space
Lucky
Uh oh. Yeah, I've seen that each edit is making a snapshot.
Lucky
Alexey
David
Hello, is there any info about migration tool, release, and async support?
Volbil
Hello @metaprogrammer, I have question regarding for_update. I have Deposit model which looks something like that:
class Deposit(db.Entity):
_table_ = "service_deposits"
confirmed = orm.Required(bool, default=False)
amount = orm.Required(Decimal)
wallet = orm.Required("Wallet")
My question is, if I query deposit records like this Deposit.select(lambda d: not confirmed).for_update() will this lock deposit.wallet as well if I update it?
Volbil
Here is full code for better understanding:
deposits = Deposit.select(lambda d: not confirmed).for_update()
for deposit in deposits:
deposit.wallet.balance += deposit.amount # Is wallet locked here?
deposit.confirmed = True
Volbil
Ben
Hi! One question, I used to use column.converters[0].get_sql_type() to get the SQL type of a column but this seems to have stopped working in the last version of pony. Do you have an alternative to suggest?
Alexander
Hi, I think it still should work
Ben
Im getting index out of range error
Alexander
That means that the attribute does not have any column
Ben
You're right, it was because it was the reverse of another attribute
Alexander
It may be a part of one-to-one relationship with the column on the different side
Ben
Yes that was it, thanks a lot :)
Ben
Hi! I have a funky issue with an in memory SQLite database. Not sure if known or if I'm doing something wrong. Basically I have a line where I try to get an object with myobj = model.get(id=x['id']). Then on the next line I do model(**x) if not myobj. And here I get consistently an error saying the ID is duplicate "Cannot create X: instance with primary key 1 already exists". My object x is like {'id': 1, 'name': aaa}. I am using a db_session with optimisticcheck: false. Any ideas?
Ben
Additional info, if I do "orm.select(o for o in model)[:]" in the previous line it returns an empty list
Ben
so maybe something wrong with in memory SQLite?
Ben
I'm not using threading nor anything too funky, but this happens inside of a unit test if that makes a difference
Alexander
How is the primary key defined? Do you manually assign the value 1 to your model instance or use autoincrement?
Are tests running sequentially or in parallel?
Can you show a traceback?
Ben
Primary key is defined without auto-increment with "id = PrimaryKey(int)". Tests are running sequentially.
Ben
data_system/analytical_db/services/model_update_service.py:133: in _process_objects
model(**obj)
/usr/local/lib/python3.8/site-packages/pony/orm/core.py:4732: in init
entity._get_from_identity_map_(pkval, 'created', undo_funcs=undo_funcs, obj_to_init=obj)
/usr/local/lib/python3.8/site-packages/pony/orm/core.py:4412: in _get_from_identity_map_
throw(CacheIndexError, 'Cannot create %s: instance with primary key %s already exists'
Ben
that's the traceback I get. What really puzzles me is that model.get(id=1) returns None and that orm.select(o for o in model)[:] is empty on the line right before I do model(**x)
Ben
also I am in optimistic=False so I dont get why I get a cache issue
Ben
I tried doing commit and rollback on the line before but it did not work
Ben
Is there a way for me to reset the cache manually?
Alexander
The cache resets on rollback or when the db session ends. The "optimistic" option does not affect the in-memory cache of loaded objects; it is for adding/removing optimistic checks during the execution of the insert/update SQL commands.
If you can reproduce the failed test on your developer machine, you can find the line 4426 in pony.orm.core:
if obj_to_init is None:
obj = object.__new__(entity)
And add the next line:
if entity.__name__ == 'X' and pkval == (1,):
assert False
Then you will be able to see the moment when that previous object with the primary key 1 is created
Ben
I do know when it's created, though my issue is that my test fails because it tries to create a new object rather than update it when the object exists (which is part of what my test checks)