Владимир
Thank you so much!
Alexander
Sure
Adam
Hello im getting this error:
Traceback (most recent call last):
File "<pyshell#5>", line 2, in <module>
show(db.Hash.get(id=1))
File "C:\Users\Adam\AppData\Local\Programs\Python\Python39\lib\site-packages\pony\orm\core.py", line 6492, in show
QueryResult([ x ], None, x.class, None).show()
File "C:\Users\Adam\AppData\Local\Programs\Python\Python39\lib\site-packages\pony\orm\core.py", line 6311, in init
translator = query._translator
AttributeError: 'list' object has no attribute '_translator'
Alexander
Which pony version do you use?
Adam
0.7.14
Alexander
Try to upgrade to 0.7.16, it might be fixed there
Adam
from 0.7.16:
Traceback (most recent call last):
File "<pyshell#4>", line 2, in <module>
show(db.Hash.get(id=1))
File "C:\Users\Adam\AppData\Local\Programs\Python\Python39\lib\site-packages\pony\orm\core.py", line 6478, in show
QueryResult([ x ], None, x.class, None).show()
File "C:\Users\Adam\AppData\Local\Programs\Python\Python39\lib\site-packages\pony\orm\core.py", line 6297, in init
translator = query._translator
AttributeError: 'list' object has no attribute '_translator'
Alexander
@metaprogrammer any thoughts? Thats a bug for sure, but im not sure about that 'show' usage
Alexander
Yep, this is a bug in a show() function, hopefully we'll fix it soon
Santosh
How do we aggregate by month or hour or weekly daily, with timestamp field
Santosh
@metaprogrammer , is this possible
Santosh
Time stamp is yyyy-mm-dd hh:mm
Alexander
Do you use SQLite?
Santosh
MySQL
Alexander
How the timestamp attribute is defined?
Alexander
Is the column created by Pony?
Santosh
Santosh
Do you use SQLite?
If it's easy with sqlite, I can switch, but still would like to know for MySQL as well
Alexander
Can you show the attribute definition?
Santosh
date = Required(datetime)
Alexander
I think for this type of queries it is easier to use raw SQL query. In MySQL it should be something:
# aggregate by month
cursor = db.execute("""
SELECT YEAR(t1."date") y, MONTH(t1."date") m, SUM(t1.some_column) x
FROM mytable t1
GROUP BY YEAR(t1."date"), MONTH(t1."date")
""")
# aggregate by hour
cursor = db.execute("""
SELECT DATE(t1."date") dt, HOUR(t1."date") h, SUM(t1.some_column)
FROM mytable t1
GROUP BY DATE(t1."date"), HOUR(t1."date")
""")
# aggregate by week
cursor = db.execute("""
SELECT YEARWEEK(t1."date") yw, SUM(t1.some_column)
FROM mytable t1
GROUP BY YEARWEEK(t1."date")
""")
Ronaldo
bv
Santosh
Santosh
Then also raw SQL or is it possible with pony
Alexander
In SQLite, it is also easier to write as a raw SQL query. There is nothing wrong with SQL queries; they are not second-class citizens. If the query should return entity objects, it is better to do it as an ORM query to get objects instead of rows. But if the query should return aggregated data, it is not necessary to write a complex query using ORM if it is possible to write a more straightforward SQL query
Karsten
Hello, I have a little problem. I am writing some time in a sqlite database. The column is of type TIME. When I read the field again, I get a string back. This error has only recently appeared. So far it had always worked. Has something changed in one version? Here is the code:
write
time_to = time(int(lst_t_to[0]), int(lst_t_to[1])) if len(lst_t_to) > 1 else None
and read
tmp_val = row.time_from.strftime("%H:%M") if type(row.time_from) == time else ''
Alexander
Hi! How do you retrieve values from the database, do you use Pony query or SQL query?
Karsten
Hello, I have a little problem. I am writing some time in a sqlite database. The column is of type TIME. When I read the field again, I get a string back. This error has only recently appeared. So far it had always worked. Has something changed in one version? Here is the code:
write
time_to = time(int(lst_t_to[0]), int(lst_t_to[1])) if len(lst_t_to) > 1 else None
and read
tmp_val = row.time_from.strftime("%H:%M") if type(row.time_from) == time else ''
Excuse me ! Here again ...
😂😂
Alexander
How do you obtain row?
Karsten
i use Pony
Karsten
This is how I add the record (see time_from and time_to)
def add_blz_event(net, reporter, reporter_func, event_time, line, train, location, code, code_description,
category, comment, from_location, to_location, dist_manually,
distance, time_from, time_to, delay, operator, creation_time):
try:
blz_event = BlzEvent(net=net,
reporter=reporter,
reporter_func=reporter_func,
event_time=event_time,
line=line,
train=train,
location=location,
code=code,
code_description=code_description,
category=category,
comment=comment,
from_location=from_location,
to_location=to_location,
dist_manually=dist_manually,
distance=distance,
time_from=time_from,
time_to=time_to,
delay=delay,
operator=operator,
creation_time=creation_time)
flush()
return blz_event
except Exception as ex:
return -1
And this is how I read data sets again :
def get_all_in_time_delta(t_from: datetime, t_to: datetime, net: str, item_group_selection: ViewMode):
try:
if item_group_selection == ViewMode.ALL:
return (select(r for r in BlzEvent if r.event_time >= t_from and
r.event_time <= t_to and
r.net == net).order_by(BlzEvent.event_time)).fetch()
elif item_group_selection == ViewMode.ACTIVATED:
return (select(r for r in BlzEvent if r.event_time >= t_from and
r.event_time <= t_to and
r.net == net and
r.action == '').order_by(BlzEvent.event_time)).fetch()
elif item_group_selection == ViewMode.DEACTIVATED:
return (select(r for r in BlzEvent if r.event_time >= t_from and
r.event_time <= t_to and
r.net == net and
r.action != '').order_by(BlzEvent.event_time)).fetch()
except Exception as ex:
return ''
I haven't changed anything in the code. However, all of a sudden this error pops up !
Alexander
Thanks, I was able to reproduce it. Looks like a bug, will fix it
Karsten
thank you !
Jan
https://stackoverflow.com/a/51671882/15748681
At this moment Pony does not support get_or_create as a single command, we plan to add it later
Is this statement still up to date?
Alexander
Basically best option for get or create imo is
obj = Entity.get(..) or Entity(...)
Jan
Oh yes, that looks neat
Jan
Thanks
Adam
does pony work with mariadb?
Volbil
Hi! Pony officially does not support MariaDB at this moment, but mostly it should work. MariaDB has different syntax for JSON expressions in queries, so JSON expressions may not work
Adam
thanks for the heads up, wondering what provider to use
Alexander
For those who may be concerned, my thoughts and feelings about the war
https://www.facebook.com/alexander.kozlovsky.96/posts/4798429240225275
stsouko
👍
João Rosal
Volbil
Matthew
Good post Alexander!
Robert
Jacob AKA Sartre
Jacob AKA Sartre
I wanted to ask something about Pony. We have an app that runs 4 client computers each running 15 threads concurrent.futures very rapidly and the host postgre is on another machine. The CPU on the DB host is often going into 98% usage and we are gettign [Errno 24] on the clients. Any tips what direction i should be looking? I think I'm mamaging db_sessions wrong.
Jacob AKA Sartre
Jacob AKA Sartre
Volbil
Volbil
You can increase this limit
Volbil
https://unix.stackexchange.com/questions/8945/how-can-i-increase-open-files-limit-for-all-processes#8949
Jacob AKA Sartre
Thank you.
Jacob AKA Sartre
I was also wondering, maybe anyone has tried the Cockroach db. How does it compare with Postgre with Pony? Is it friendly for a lot of connections and resource efficient?
Jacob AKA Sartre
Genesis Shards Community
Hello, why the error, I did not find a solution
Genesis Shards Community
please, help me!
Volbil
Try newer version, like 3.8-3.9
Genesis Shards Community
until yesterday it was ok, today I restarted the server and generated this error
Genesis Shards Community
i not found solution
Genesis Shards Community
Why does this error appear, the truth is that I can't find it anywhere
Volbil
What database you using?
Genesis Shards Community
mysql
Volbil
There's link inside error, have you checked it?
Volbil
There might be an issue with your db instance
Genesis Shards Community
when I use the id of the normal table it shows me, but when I want to use another field, it throws that error
Volbil
Can you show code?
Genesis Shards Community
class Articulo(db.Entity):
id_empresa = Required(Empresas)
agencia = Required(str, 3)
codigo = PrimaryKey(str, 25)
nombre = Required(str, 200)
descripcioncorta = Optional(str, 200)
descripcionlarga = Optional(str, 200)
referencia = Optional(str, 200)
unidad = Required(Tabla06)
costo = Required(Decimal, 20, 7)
precio1 = Optional(Decimal, 20, 7)
precio2 = Optional(Decimal, 20, 7)
precio3 = Optional(Decimal, 20, 7)
precio4 = Optional(Decimal, 20, 7)
existencia = Optional(Decimal, 20, 7)
comprometido = Optional(Decimal, 20, 7)
minimo = Optional(Decimal, 20, 7)
maximo = Optional(Decimal, 20, 7)
costo_ant = Optional(Decimal, 20, 7)
costo_prom = Optional(Decimal, 20, 7)
fechamodifi = Optional(datetime)
categoria = Required(Categoria)
idproveedor = Required(Proveedores)
porcen1 = Optional(Decimal, 20, 2)
porcen2 = Optional(Decimal, 20, 2)
porcen3 = Optional(Decimal, 20, 2)
porcen4 = Optional(Decimal, 20, 2)
servicio = Required(int, sql_default=0)
compuesto = Required(int, sql_default=0)
lote = Required(int, sql_default=0)
receta = Required(int, sql_default=0)
peso = Required(Decimal, 20, 2)
reservado = Required(Decimal, 20, 2)
categoria_old = Optional(str, 20)
proveedo_old = Optional(str, 20)
bonificacion = Optional(int, sql_default=0)
foto = Optional(str, 250)
nombrefoto = Optional(str, 250)
codigoalternativo = Optional(str, 25)
fraccion = Required(int, sql_default=0)
cantidadfraccion = Optional(Decimal, 20, 2)
unidadfraccion = Optional(str, 3)
empaque = Required(int)
utilidadmin = Optional(Decimal, 20, 2)
icbper = Required(int, sql_default=0)
idmarca = Optional(int)
tallacolor = Optional(int, sql_default=0)
combustible = Optional(int, sql_default=0)
serie = Optional(int, sql_default=0)
usuario_add = Required(str, 10)
usuario_mod = Optional(str, 10)
fechaadd = Optional(datetime)
idmarca_old = Optional(str, 200)
codigoProductoSUNAT = Optional(str, 20)
avanzadas = Optional(int, sql_default=0)
ventasinstock = Optional(int, sql_default=0)
refrigerado = Optional(int, sql_default=0)
antibiotico = Optional(int, sql_default=0)
fraccionable = Optional(int, sql_default=0)
tomapedido = Optional(int, sql_default=0)
tiendavirtual = Optional(int, sql_default=0)
estado = Required(int, sql_default=1)
articulotag = Set('ArticuloTag')
compatibles = Set('Compatibles')
escalas = Set('Escalas')
lotes = Set('Lotes')
existencias = Set('Existencia')
promodet = Set('Promodet')
listaprecios = Set('Listaprecios')
kardex = Set('Kardex')
opermv = Set('Opermv')
promocab = Set('Promocab')
Genesis Shards Community
@db_session
def ver_articulos_all(self):
articulo = Existencia.select(lambda a: a.codigo != '77779902')
data = []
for a in articulo:
nombre = a.nombre
row = {
'codigo': a.codigo,
'nombre': nombre,
'unidad': a.unidad.codigo,
'servicio': a.servicio,
'compuesto': a.compuesto,
'lote': a.lote,
'receta': a.receta,
'bonificacion': a.bonificacion,
'codigoalternativo': a.codigoalternativo,
'icbper': a.icbper,
'costo': "{0:.2f}".format(a.costo),
'descuento': "{0:.2f}".format(0.00),
'igv': "{0:.2f}".format(0.00),
'afectacion': '10',
'dispensador': '',
'unidad_min': '',
'numero_lote': '',
'tipodetalle': '1',
'contiene': 1,
'cantidad': 1,
'listaprecio': 'PRECIO01',
'precio': self.ver_precio_uno(a.codigo),
'existencia': "{0:.2f}".format(a.existencia),
'estado': a.estado
}
data.append(row)
return True, data
Genesis Shards Community
it is
Genesis Shards Community
😢😭
Genesis Shards Community
it is a error more complicated!
Александр
Всем добра! Не пойму... миграции есть или еще в разработке? Если есть то где почитать мануал по ним?
Ben
I have a silly question: is it expected to get duplicate key error when having an Optional column with a unique index (the column type is string)?
Ben
aaah only if it's ''