Anonymous
You try set datetime with empty string
Well, I did, the string was empty.
What I also recognized with the date field is, whenever you try to give a datetime.date() object (field with values, i.e. datetime.date(2020, 20, 01)) I got the error that the value should be a string or some kind of byte value.
Anatoliy
can you show code ?
Alexander
Can you show a traceback?
Anatoliy
Anatoliy
Also you can put in date string but it shold be parse as correct date
Anonymous
The parsing works pretty fine
Anonymous
I'll try to get the got, however, I already corrected it. Maybe it was some bad duality of wrong field placement and code. I'll post it here, whenever I stumble over it once again.
Ben
Hello! I am having many issues with the trimming of strings when inserting. It seems that Pony is removing any carriage return or whitespace at the end of string when inserting into the database. However, if I check with "exists" it does not remove them. This causes issues if I check if "A " exists which return false while there is "A" in the database, when I then try to insert "A " it gets trimmed to "A" and raises an Exception.
Ben
Is there any way to disable the string trimming of whitespace globally in Pony? (I am using Postgres)
Alexander
Hi! You can specify autostrip=False for string attribute
Are you sure you really want to store values with leading/trailing spaces?
Maybe we need to autostrip string parameters too, but I'm not sure about it - it may be problematic in situations when we don't want to autostrip some specific string value
Alexey
Hey guys!
I’m going to be in San Francisco starting today till Saturday. If anyone is around, would love to meet up. 🙌
Rick
@admin spam
Alexey
Carlos
Hello everyone!
Carlos
I'm getting an error in prod that I haven't in dev
Carlos
pony.orm.core.ERDiagramError: Mapping is not generated for entity ''
Carlos
I have two entities in separate files, and I execute a logic y different files. When I go to make a method in the last file, I get that error
Carlos
But in pre-production I haven't that error
Carlos
What could be happenin?
Jim
maybe look at your import order ?
Carlos
I'm going to explain the core functionality.
I have a main.py file that execute 3 methods.
Firts method and second method are in the same file. In that file, exist the first Ponyorm entitie, and start the bind connection.
The third method, are in other file. That file is executing (its a webserver), and have a method that I call from main.py. Have the @db_session
Alexander
Are all entities belongs to the same Database object?
Alexander
it seems you need to move db.generate_mapping() to a different place
Carlos
Now I have in the correct site and works!
Carlos
Thanks! :D
Carlos
pony.orm.core.BindingError: Database object was already bound to MySQL provider
Carlos
What is this error? I'm only reading from bd
Alexander
It happens if you bind db object that was already bound.
like calling db.bind twice or doing
db = Database(**params)
...
db.bind(**params)
Carlos
how I put code here in telegram?
Carlos
for show you what's error I'm having
Alexander
Three backquotes before and after
Carlos
test
F
if it's long you can send gist/ pastebin link
Carlos
pastebin better
Carlos
https://pastebin.com/fq3jQZ12
Carlos
That are my code from my webserver that use ponyorm
Carlos
(it's launched with sudo python3, cause the port its 80)
Alexander
I don't know what's going on in your db_models file, but it seem that you never call db.generate_mapping(create_tables=True)
Carlos
Alexander
So there is a problem in your imports order
Carlos
db.bind(provider='mysql', host='localhost', user='root', passwd='', db='')
db.generate_mapping(create_tables=True)
Alexander
that code runs BEFORE you call db.generate_mapping
Alexander
You can put if before app.run line
Alexander
Would be okay
Carlos
y put a with db_session: block in the try methood
Carlos
now its working!!
Carlos
thanks everybody! :D
Anonymous
Hi, I have to switch to MariaDB for a project and saw, that Pony support only MySQLdb and pymysql. First one hasn't been updated since 2013(!), second one is from 2018. Will there be support for mysql.connector (official support for MySQL and MariaDB) as well? Regards, Thomas
Alexander
Hi Thomas! Can you open an issue for this?
Lately I wasn't too fast in replying to issues, but eventually we'll fix them
What about pymysql, do you experience some problems with it?
Anonymous
Nope, I'm using it right now since no alternatives. :) It works, but it was just a question because mysql-connector is more or less commonly used.
Alexander
I think we need to add support of mysql-connector too #todo
Abuelazo
Hi! how is the way to modify a entity?
Anonymous
yo when i do self.to_dict(related_objects=True, with_collections=True)
Anonymous
it gives me ValueError: Circular reference detected // Werkzeug Debugger
Anonymous
how to declare one-to-many relationship to avoid this error please ?
Jim
show us your cade
Jim
code
Anonymous
Jim
class Feedback(db.Entity):
_table_ = 'Feedbacks'
id = orm.PrimaryKey(int, auto=True)
items = orm.Set('FeedbackItem', reverse='feedback')
analysis = orm.Required(Analysis)
created_at = orm.Required(datetime, default=datetime.now)
updated_at = orm.Required(datetime, default=datetime.now)
def serialize(self):
return self.to_dict(related_objects=True, with_collections=True, exclude=['analysis'])
Anonymous
and
class FeedbackItem(db.Entity):
_table_ = 'FeedbackItem'
id = orm.PrimaryKey(int, auto=True)
feedback = orm.Optional('Feedback')
feedback_comments = orm.Optional(str, max_len=250, autostrip=True)
created_at = orm.Required(datetime, default=datetime.now)
updated_at = orm.Required(datetime, default=datetime.now)
def serialize(self):
return self.to_dict()
Anonymous
then i do` Feedback.select()` I expect to have a list of item imbricated..
Jim
this seems good. whick method is failing ?
Carlos
Hello everyone.
How I can visualize the content of BD using a python console?
I import pony orm and the models, I create de Database, the bind and generate mapping, and I have ERDiagramError: Mapping is not generated for entity
Alexander
Probably you are trying to work with entity before generate_mapping was called
Anonymous
i ended up implementing my own to_dict method 👍
Carlos
Hi everyone again.
In my flask server, i have a route that when I enter I bind the connect. But, when I enter by second time, throw error Database object was already bound to MySQL provider
Carlos
use db.disconnect() not works
Alexander
You need to bind before app.run()
Carlos
Alexander
you should not call bind or generate_mapping inside route handler
Alexander
It should be done one time before Flask application start
Abuelazo
Hi, I am trying to use the max function but I receive this error
The attribute must be specified for the aggregate function 'max'
My question is the following
folio = max (o.folio for or in tabla.prestado_Tool)
Alexey
Pony now support CockroachDB. Yay! 🐴
Alexey
https://www.cockroachlabs.com/blog/ponyorm-for-cockroachdb/
Matthew
Rick
@admin
Anonymous
Hi, just a quick one: is it possible to write queries with LIKE-clauses? I've seen some examples using string.startswith() or string.endswith(), but what about LIKE '%string%'. Any hints for me? Regards, Thomas
Matthew
select(x for x in X if ‘string’ in x.something)