@ponyorm

Страница 47 из 75
Neal
07.11.2017
01:55:42
I just reproduced the error acidentally. I have been using version 0.6.5 in development environment. But same error occurs when I just update to 0.7.1 and 0.7.3

Alexander
07.11.2017
01:57:50
Do you reproduced it in the development evironment?

Neal
07.11.2017
02:02:30
But that's because I add user.delete(); user.save() in development environment,?. I just overeacted. Sorry...

Alexander
08.11.2017
07:25:16
https://github.com/ponyorm/pony/tree/orm-migrations/pony/migrate

Google
Bonbot
08.11.2017
07:25:18
https://github.com/ponyorm/pony/tree/orm-migrations/pony/migrate
Permanent link to the file pony/migrate mentioned. (?)

Nickolai
08.11.2017
12:10:27
How to use create_or_update in Pony? I cant find in docs

Alexander
08.11.2017
12:18:15
Pony don't have create_or_update method yet. You can do something like that: params = {'foo': x, 'bar': y} obj = MyObject.get(**params) or MyObject(**params) obj.some_field = updated_value

If you want to use native SQL method for create_or_update, you can write raw SQL query

Bjorn
14.11.2017
15:27:11
Hi - I'm running tests with pony and have discovered something peculiar. The main code is: /tests/client_test.py client_test.py uses a BaseService.py that is in /framework/BaseService.py BaseService.py imports pony and creates a db using: self._database.bind('sqlite', filename=self.config_class.DATABASE_URI, create_db=True) The problem is that when /test/client.py runs, it creates the database in /framework !!! As code should write in its working directory, i.e. /tests/ writing in its own directory is obviously wrong. I have nailed the bug down to: pony==0.7.3 package pony.utils: def absolutize_path( ... ) where this magic happens:



My guts tell me that line 225 should be os.getcwd() instead.

Hacking into the sys._getframe should only be used in interactive mode.

(which is checked for in line 228)

Google
Bjorn
17.11.2017
11:21:03
{it could of course also be me who is an idiot, as I perhaps should use absolute paths instead...}

Valery
17.11.2017
11:33:46
I've also faced with that magic in attempts to pass is_path parameter to sqlite

(it can be used to get some extended features of in-memory databases like shared cache)

Bjorn
17.11.2017
11:56:16
Hmmm.... I'm not too fond of that. In all cases the write should be to os.getcwd(). Not to an import.

Alexander
17.11.2017
12:48:25
Hi, this is long-standing behavior. The reason for it is mod_wsgi. Initially mod_wsgi was the most popular way to use Pony with "real" web-server. And in mod_wsgi the current working directory is set to some obscure path. So, the typical error was, the user creates a sample application to use from mod_wsgi, and specifyes in it db = Database('sqlite', 'mydatabase.sqlite', create_db=True) When the script is running locally, using CherryPy or Flask, it creates a database file in a current working directory, that is, typically the same directory where the script placed. A user populate the database with some example data, and then run the application under mod_wsgi. But then he encounters a strange bug: the database is empty! Although, the user sees that the populated database lies right here.

So relative filenames were just unusable for that reason. And because of this, some frameworks, like Django, just forbid to use relative path in settings: https://stackoverflow.com/questions/28635405/why-absolute-paths-in-django-settings

We had that option too, it was possible to raise an error when the user provide a relative path to the database, in order to prevent that obscure error. But then we thought, if relative path in its usual meaning cannot be used, why not allow them, but with the different meaning, "relative to the file where the database object is defined". Sometimes it is useful.

And, you always can specify absolute path to be exact.

Maybe it is possible to change that behavior now, but (1) it breaks backward compatibility, (2) "real" relative path can still be unreliable, for example if you have multiple scripts placed in different directories which all import the same db object, and (3) "relative to db object" semantics is quite handy sometimes

Bjorn
17.11.2017
14:14:02
Hi - Sorry for the silence: My team has settled on using absolute paths for good. ? (bug report cancelled ??)

Lars
17.11.2017
21:01:33
Is there a way to add a computed property to an entity that will be included by default in to_dict?

I've just overridden to_dict in my entity to take care of it, but I was wondering if there was a better way.

I think sqlalchemy calls this "hybrid attributes"...

Alexander
17.11.2017
21:36:45
Hi, we want to add hybrid attributes soon, but this task turns out to be surprisingly difficult. Right now you need to override to_dict

Lars
17.11.2017
21:36:56
Okay, thanks!

Richie
22.11.2017
00:28:48
Hi all

I ve using Pony for my small project and I am very happy to use it especially because the syntax is very pythonic way.

Alexander
22.11.2017
00:34:02
You asked info about lastest release, idk why did you delete your message but if you care... Here you can read info about it https://github.com/ponyorm/pony/releases/tag/0.7.3

Richie
22.11.2017
00:34:18
I am going to check it right now , thanks..

Alexander
22.11.2017
00:36:05
Or here https://blog.ponyorm.com/2017/10/23/pony-orm-release-0-7-3/

Google
Richie
22.11.2017
00:39:15
Thanks for your fast response

Alexander
22.11.2017
00:39:51
No problem

Ahmad Ghulam
22.11.2017
03:08:52
hi.. im new to pony, now im doing validation before inserting data into the database, what your suggestion for doing the validation, is it before the insert using entity_hook, or plain validation before initiating new entity instance?

Matthew
22.11.2017
10:12:54
What kind of an application is it? If it's a web app, I validate in my Forms (WTForms or Django Forms)

In general, I validate outside of the model

Sometimes after validation it won't make sense to make an instance of the model, for example if a required piece of data is missing or invalid

Ahmad Ghulam
22.11.2017
10:18:54
an API, using falcon..

Matthew
22.11.2017
10:20:17
so do it in the code before creating the model instance

Ahmad Ghulam
22.11.2017
10:21:01
Ok

and thanks..

Matthew
22.11.2017
10:23:27
no problem

Valery
22.11.2017
11:13:39
Not sure if it's a good idea but you can use class method of model to create instance. Class method allows you keep validation code not so far from model and don't initialize instance if data is wrong.

Ahmad Ghulam
22.11.2017
12:49:54
yes, I've​ been thinking something like that, but haven't really know how to do it properly, since I use schematics library to do the validations duplicating pony entities into schemas is not ideal I think.. Maybe I might try that one..

Xunto
22.11.2017
14:43:32
https://github.com/ponyorm/pony/issues/315 hmmm

Henri
22.11.2017
19:28:01
Have joined the framework benchmark with Morepath using Pony (on Python 3).

https://www.techempower.com/benchmarks/previews/round15/#section=data-r15&hw=ph&test=db&l=zijzen

Difficult to compare as Morepath is the only framework which uses Pony. But looks promising. Especially the tests using the database where Pony is involved.

Alexander
22.11.2017
19:33:52
Hmm, I see Morepath, but I don't see Pony in this list. Do you mean that all Morepath results are with Pony?

Henri
22.11.2017
19:35:10
Yes at least the ones which uses the database.

Alexander
22.11.2017
19:37:39
So, if I read correctly, Morepath+Pony is approximately two times faster than Django

Google
Henri
22.11.2017
19:41:51
Depending which test but yeah a big difference. BTW json and plain text tests doesn't use the database. The others do.

Especially when you take into account that it's Python 3 and compare it with the PY3 versions of the other frameworks it looks quite amazing.

Alexey
22.11.2017
19:51:06
That's great!

Alexander
22.11.2017
19:54:33
Yeah. In fact, in terms of speed, I think Pony still has some room for growth ) The current code was written just from "theoretical" point of view, and profiling on real application may find some local bottlenecks which can be optimized even more

But even now it looks quite good

Richie
22.11.2017
23:17:15
great to hear thta\

Henri
23.11.2017
08:43:16
BTW the source code of the benchmark is here : https://github.com/TechEmpower/FrameworkBenchmarks/tree/master/frameworks/Python/morepath

Bonbot
23.11.2017
08:43:18
Bulat
24.11.2017
03:53:21
Hi! I am new to Pony, and got stuck with MySQL. I have a table of users, and datetime field in it, and pony's mysql connector raises exception during parsing '0000-00-00 00:00:00', which is returned for NULL datetime fields lib/python2.7/site-packages/pony/orm/dbproviders/mysql.py", line 334, in str2datetime return datetime(*imap(int, s.split())) ValueError: year is out of range

How can I make Pony treat this value as None ?

stsouko
24.11.2017
06:11:56
Use custom datetime type class

Juan
24.11.2017
18:45:31
Hello everybody, anyone know how to make a custom autoincrement like primary key? E.g. RCRD_001, RCRD_002, RCRD_003, etc. Thank you so much.

Alexander
24.11.2017
19:24:14
Hi Juan. What database do you use?

Angel
25.11.2017
15:12:00
/effect@bonbot

/eduvote@bonbot

/whereami@bonbot

/whereami@bonbot

Chukwudi
25.11.2017
15:14:55
/whereami@bonbot

Juan
25.11.2017
15:47:58
Alexander
25.11.2017
15:53:37
I think it is better to have integer primary key, because it is smaller and more efficient. But if you really need a string key, you can probalby declare it as a secondary key using nullable UNIQUE column and initialize it using an AFTER INSERT trigger

Google
Alexander
25.11.2017
16:07:05
With pony you can have a string primary key, but if it includes some "counter" you need to process it somewhere. You can store the counter value in a separate table, and use to construct primary key in Pony: class Counter(db.Entity): entity_name = PrimaryKey(str) value = Required(int, default=0) class MyEntity(db.Entity): number = PrimaryKey(str) foo = Required(str) bar = Required(str) @classmethod def make(cls, **kwargs): cls_name = cls.__name__ counter = Counter.get(entity_name=cls_name) \ or Counter(entity_name=cls_name) counter.value += 1 number = 'RCRD_%d' % counter.value return cls(number=number, **kwargs) ... with db_session: obj = MyEntity.make(foo='foo', bar='bar') But it will be less efficient then using integer autoincrement primary keys

Bonbot
25.11.2017
17:06:00
/eduvote@bonbot
/eduvote – prints syntax /eduvote email – stores mail /eduvote [email] vote [times] – casts vote. A vote can be a upper or lower case letter or a number: A-E, a-e, 1-5. If no [email] is given, the stored one is used. You can list values to randomly choose from: Either as list C,D,E or as range C-E.

/whereami@bonbot
You are at Pony ORM @ponyorm (supergroup#-1001084448691)

/whereami@bonbot
You are at Pony ORM @ponyorm (supergroup#-1001084448691)

/whereami@bonbot
You are at Pony ORM @ponyorm (supergroup#-1001084448691)

Chukwudi
25.11.2017
17:13:41
@bonbot Who are you?

Bulat
26.11.2017
04:45:55
Use custom datetime type class
Sorry, I'm not sure if this will fix the problem? str2datetime is assigned into the conv, which is converters I guess, like this conv[FIELD_TYPE.TIMESTAMP] = str2datetime conv[FIELD_TYPE.DATETIME] = str2datetime I can't see if custom datetime class can somehow affect this I've even tried using str, instead of datetime class, but didn't succeed. It raises exception way before getting to my object

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