@ponyorm

Страница 40 из 75
Juan
22.08.2017
10:06:51
Do I need to change my MariaDB engine to fix this error? (1071, 'Specified key was too long; max key length is 767 bytes')

Xunto
22.08.2017
10:15:20
No, you just need shorter table or fieled name, I think.

Luckydonald
22.08.2017
10:16:42
Yeah, the 3rd digit

Google
Matthew
22.08.2017
17:26:30
If you need a specific bug fix, you can easily reference a specific git commit until the next proper release

Святослав
22.08.2017
20:45:12
Release frequency it's a part of "production ready" status

Matthew
24.08.2017
13:59:58
File "/root/app/.env/local/lib/python2.7/site-packages/pony/orm/core.py", line 427, in new_func finally: db_session.exit(exc_type, exc, tb) File "/root/app/.env/local/lib/python2.7/site-packages/pony/orm/core.py", line 396, in exit for cache in _get_caches(): cache.release() File "/root/app/.env/local/lib/python2.7/site-packages/pony/orm/core.py", line 1566, in release cache.close(rollback=False) File "/root/app/.env/local/lib/python2.7/site-packages/pony/orm/core.py", line 1592, in close for obj in cache.objects: TypeError: 'NoneType' object is not iterable

is this a known pony bug?

Alexander
24.08.2017
14:01:34
Did you use strict=True param for db_session?

Matthew
24.08.2017
14:02:22
yes

Alexander
24.08.2017
14:03:52
Yes, this but is known. Fix is already on GitHub. It will be part of next release. You can use GitHub version or do not use this param.

Matthew
24.08.2017
14:04:26
thank you!

Alexander
24.08.2017
14:04:50
No problem

Jared
30.08.2017
09:00:46
Howdy - just wondering if I'm wrong in noticing there is no way to tick "unsigned" on an int in the online designer tool? Should I create an issue on github?

Alexander
30.08.2017
09:06:03
You are right, we need to fix it

Jared
30.08.2017
09:07:54
Ok - thanks :)

And thanks for Pony :D

Google
Alexander
30.08.2017
09:08:50
You are welcome :)

Alexander
30.08.2017
15:46:10
Hey, @mr_agb. We fixed all bugs you have mentioned: - incorrect index and foreign key names when schema name is specified for table; - problem with primary key column which is a part of a secondary index. Also now you able explicitly specify fk_name for relationship attributes.

Alexander
30.08.2017
15:57:36
In development version of Pony we added sql_debugging decorator which can be used to enable SQL logging for specific function: @sql_debugging def some_function(): <some queries> Also you can use it as a context manager: with sql_debugging: <some queries> By default it enables logging of SQL queries, but it is possible to use it to suppress SQL logging of some code: with sql_debugging(debug=False): <some queries> When logging is enabled, Pony log SQL queries, but not SQL parameter values, because they can consists sensitive information. Sometimes it may be helpful to log parameter values as well to debug some complex issues. Now you can enable logging of parameters in the following way: with sql_debugging(show_values=True): <some queries> Also, now you can specify sql_debug and show_values flags right for db_session decorator/context manager: @db_session(sql_debug=True, show_values=True) def some_function() ... These features are available on GitHub, and will be part of 0.7.4 release

Also, we plan to deprecate sql_debug function in favor of set_sql_debug function to avoid confusion between sql_debug and sql_debugging names

Also SQL debug flag is thread-local now

Matthew
31.08.2017
07:35:03
sql_debugging looks cool :)

Does it include query execution times?

Alexander
31.08.2017
07:38:53
You mean 'does it show how much time query was executing?'?

Alexander
31.08.2017
07:43:34
At this moment to see statistics you need to look at db.local_stats. But in the future we can add some summary statistics output to sql_debugging

Matthew
31.08.2017
07:44:24
Alexander 1: Yep Alexander 2: Cool :)

Luckydonald
31.08.2017
21:59:41
Alexander 1: Yep Alexander 2: Cool :)
I think we have at least 4 now

Micaiah
01.09.2017
03:01:41
2nd on thank you for Pony, doubley so when migrations come out ;)

Matthew
01.09.2017
12:47:10
I just found this while searching for pony stuff:

https://pypi.python.org/pypi/flask-ponywhoosh

Alexander
01.09.2017
12:49:22
That's interesting

Riccardo
02.09.2017
23:50:23
Hello people, first of all thanks a lot for the great work. I'm really enjoying using ponyorm Dumb question: what's the correct way to retrieve the value of a column from a query result, if the column name is inserted by an user? Eg. I have this code: column_name = "some_column_name" user_id = 1234 u = User[user_id] how can I get/change the column_name value of u? I tried with a wild print(u[column_name]), but it's not the way I tried to take a look at the docs/examples and google something, but I haven't been able to find an inspiration :(

Alexander
02.09.2017
23:56:20
I think that u in your case is entity, so it has no column. It has several attributes which of them have one or more columns.

User[1234] is the line of code which means like: "Give me object from entity User with primary key 1234".

Alexander
03.09.2017
00:55:45
You can use standard Python getattr function: u = User[user_id] value = getattr(u, column_name) print(value)

Riccardo
03.09.2017
11:19:30
I think that u in your case is entity, so it has no column. It has several attributes which of them have one or more columns.
Shouldn't it be just one entity corresponding to the user with ID 1234? I mean, I am able to access the column content from u.some_column_name ?

Google
Riccardo
03.09.2017
11:21:06
You can use standard Python getattr function: u = User[user_id] value = getattr(u, column_name) print(value)
I thought about this after closing up everything eh, thanks. Will try today

Alexander
03.09.2017
11:35:50
According to Pony terminology: User is an entity class. Corresponds with a table in the database. u = User[123] is an entity instance (also may be called as entity object). Corresponds with a row in a table. User.name is an entity attribute. Corresponds with a column in a table. Some attributes are virtual, and don't have corresponding column. Most typical examples are collections, like User.posts

Richie
03.09.2017
13:00:34
Does Pony is ready for Production / Deployments?

Matthew
03.09.2017
13:01:10
In my experience, yes

Alexander
03.09.2017
13:07:27
It depends on, whether you need migrations to modify database schema. Official migration tool is not ready at this moment, we are working on it and hope it will be released soon. Until this moment, you can do migrations manually, typically it is easy to write ALTER TABLE command if you know the syntax. Another option is to use migration tool written by @luckydonald: https://github.com/luckydonald/pony_up

Richie
03.09.2017
13:26:05
so anything is ready enough except only it's migration tool ?

Alexander
03.09.2017
13:35:13
I think yes. There are things that we plan to add in the future, like, upsert operation, abstract base entity classes, support of SELECT ... FROM (SELECT ...) queries, better to_json API, but even without these things PonyORM is ready enough

Richie
03.09.2017
13:40:43
Okay,, I just make the GUI for my applications., I ll try to make the database using Pony

wish me luck

I don't have to use pony to migrate database right?

Alexander
03.09.2017
13:47:06
Last years we used pony to develop fineartbiblio.com. It is a site with a pretty complex database schema. On this site we write migrations manually. Typically it is pretty easy to formulate necessary ALTER TABLE command. The benefits of migration tool is that it can be executed as a part of automatic deployment process. Also, it can generate simple migrations automatically which may be convenient for people who doesn't know the syntax

stsouko
04.09.2017
09:35:39
hello! for query: E.select(lambda x: not x.a) I get: SELECT "x"."id", "x"."a" FROM "schema"."a" "x" WHERE NOT (length("x"."a") > 0) db: class A(db.Entity): _table_ = '%s_a' % schema if DEBUG else (schema, 'a') id = PrimaryKey(int, auto=True) a = Optional(str)

why not WHERE (length("x"."a") == 0) or another

I use postgres

stsouko
04.09.2017
09:58:02
Yes. Thank you.

Alexander
04.09.2017
10:00:44
Can you post this sql? I'm wondering.

stsouko
04.09.2017
10:04:29
E.select(lambda x: x.a is None) => WHERE "x"."a" IS NULL

Alexander
04.09.2017
10:06:04
Yes, does it work as you expect? Cause PostgreSQL does not threat empty string as NULL, as I remember.

Google
Matthew
04.09.2017
10:07:10
The default for Optional(str) is NULL / None

so it's not an empty string

I sometimes do Optional(unicode, default='') where it makes sense

Alexander
04.09.2017
10:10:20
I just clarified that moment. Because I saw comparing length with zero.

That if he needs empty strings that way will work in Oracle, not Postrgre.

Xunto
04.09.2017
10:52:18
Is there a way to fetch specific field after filtering? For example: select(application for application in orm.Applications).filter(labda a.year == 2017).get(lambda a: a.id) So I get filtered applications' ids.

Matthew
04.09.2017
10:53:22
An inefficient option is [x.id for x in select(application for application in orm.Applications).filter(labda a.year == 2017).get(lambda a: a.id)]

Xunto
04.09.2017
10:55:56
Yeah, I already did it but as it builds SQL query it should be possible to fetch records without fetching whole object (lazy isn't good solution too).

Alexander
04.09.2017
11:02:16
If you know in advance than you need that specific attribute, you can write query = select(a.id for a in orm.Applications) query = query.filter(lambda: a.year == 2017) Note that in that case I don't specify lambda argument in filter, because an argument will refer to a.id expression, and we need access original object instead If the attribute name is not known in advance, you can use getattr function: attr_name = <get attr name> query = select(getattr(a, attr_name) for a in orm.Applications) query = query.filter(lambda: a.year == 2017) There is an open issue with getattr: https://github.com/ponyorm/pony/issues/223 I'll try to fix it

Xunto
04.09.2017
11:06:55
Wow, that's not really intuitive. I can't even imagine what will happen on double for query.

But on other hand it just use name that I've defined in select.

I wonder if linter will cry about it.

yeah, it will

I think it would be better to have something like .map() for query result that will take a lambda that will process something that will be result of generator in select (just like in filter)

As an option atleast

Alexander
04.09.2017
11:13:30
It will. I have a plan to introduce another method where that will use original names from the query, but have it explicitly specified as lambda arguments. Right now in expression: select(a.b for a in X).filter(lambda y: y > z) y refers to query result a.b, the name of y argument may be any name With new where method: select(a.b for a in X).where(lambda a: a.c > z) a will refer to loop variable with the same name

I think it is a good idea to implement map method. I think we should add it

Jared
04.09.2017
17:08:35
Hello all - I've hit a snag using Python Pandas where I have some NaN values which I have to manually cast to None before storing to a DB using Pony. I was wondering if there was any thoughts around NaN values being understood as Null in Pony? Any reason this is a bad idea?

Matthew
04.09.2017
20:05:03
Hello all - I've hit a snag using Python Pandas where I have some NaN values which I have to manually cast to None before storing to a DB using Pony. I was wondering if there was any thoughts around NaN values being understood as Null in Pony? Any reason this is a bad idea?
Where I want to cast a string to None (not with Pandas but in similar situations), I do "v or None", where v is the variable, so '' would be cast to None, maybe you can do that with NaN?

Google
Jared
04.09.2017
20:16:11
Unfortunately it's not so simple. Though it's not terribly complicated either. If my dataframe (think if it as an excel table with labelled columns) has some column 'Name' I need to type: dataframe['Name'] = dataframe['Name'].where((pd.notnull(dataframe['Name'])), None) Yuck! That is just a result of the design of Pandas however. It is an otherwise beautiful library and I don't mean to cast a shadow on it. I just wondered if there were some way to specify what maps to NULL in Pony, or if NaN was considered a member of that list.

Alexander
04.09.2017
20:22:48
I think it is possible to store NaN as a valid float value, at least in some database. So it may be logically not correct to always convert it to None. I think, when you assign value to pony, you almost certainly have some code like pony_object = MyEntity( attr1=<some complex expr>, attr2=<another complex expr>) or pony_object.attr = <some complex expr> You can write a simple function NaNtoNone and then use it in a following way: pony_object = MyEntity( attr1=NaNtoNone(<some complex expr>), attr2=NaNtoNone(<another complex expr>)) or pony_object.attr = NaNtoNone(<some complex expr>)

Jared
04.09.2017
21:33:06
I think it is possible to store NaN as a valid float value, at least in some database. So it may be logically not correct to always convert it to None. I think, when you assign value to pony, you almost certainly have some code like pony_object = MyEntity( attr1=<some complex expr>, attr2=<another complex expr>) or pony_object.attr = <some complex expr> You can write a simple function NaNtoNone and then use it in a following way: pony_object = MyEntity( attr1=NaNtoNone(<some complex expr>), attr2=NaNtoNone(<another complex expr>)) or pony_object.attr = NaNtoNone(<some complex expr>)
I looked it up and you're right at least for Postgres (https://www.postgresql.org/docs/9.3/static/datatype-numeric.html) That's a nice work around you suggested too. Personally I am going to go with a similar approach: python pony_object = MyEntity(**panda2pony(my_dictlike_pandas_object)) which will hide the other gory details I've not mentioned. By the way how do you colour your text in Telegram? Sorry to be off-topic.

Alexander
04.09.2017
21:42:29
I use single backquotes around a single word or triple-backquotes before and after a code block

But Telegram doesn't do color-hinglighting yet, as far as I know

Jared
04.09.2017
22:09:18
Oh, I'm looking at my mobile and not seeing colour but on my browser on PC I saw your code in blue, but my own markdown had no colour. Ubuntu+Firefox. Interesting to note. Thanks.

Matthew
05.09.2017
09:25:07
Is there an easy way in pony to say "only select records with an even id", aka modulus of 2?

Use case is splitting some cpu intensive work between a few processes

Doesn't need to be a perfectly even split

Alexander
05.09.2017
10:03:48
select(x for x in MyEntity if raw_sql("x.id % 2") == 0)

Matthew
05.09.2017
10:27:37
Is that supported in all pony supported databases?

Alexander
05.09.2017
10:31:09
It should work in SQLite, PostgreSQL and MySQL. For Oracle it is necessary to write raw_sql("MOD(x.id, 2)") instead.

Matthew
05.09.2017
11:02:32
Cool, thanks, I will use it then. One day it would be nice to have pony translate % into sql

Xunto
06.09.2017
13:04:35
Maybe it's not a bad idea to implement some db specific functions for databases that have this function and raise exception if current driver doesn't support it.

Alexander
06.09.2017
13:34:57
Yes, I think it is possible. Regarding % operations, I agree that we need to add support of it in all databases

Matthew
07.09.2017
14:58:21
select(u for u in User if raw_sql("u.id % 4") == 0).random(5) gives TypeError: 'dict' object does not support indexing

Страница 40 из 75