url
stringlengths
53
56
repository_url
stringclasses
1 value
labels_url
stringlengths
67
70
comments_url
stringlengths
62
65
events_url
stringlengths
60
63
html_url
stringlengths
41
46
id
int64
450k
1.69B
node_id
stringlengths
18
32
number
int64
1
2.72k
title
stringlengths
1
209
user
dict
labels
list
state
stringclasses
1 value
locked
bool
2 classes
assignee
null
assignees
sequence
milestone
null
comments
sequence
created_at
unknown
updated_at
unknown
closed_at
unknown
author_association
stringclasses
3 values
active_lock_reason
stringclasses
2 values
body
stringlengths
0
104k
reactions
dict
timeline_url
stringlengths
62
65
performed_via_github_app
null
state_reason
stringclasses
2 values
draft
bool
2 classes
pull_request
dict
https://api.github.com/repos/coleifer/peewee/issues/314
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/314/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/314/comments
https://api.github.com/repos/coleifer/peewee/issues/314/events
https://github.com/coleifer/peewee/pull/314
28,606,035
MDExOlB1bGxSZXF1ZXN0MTMxMDQ2NDY=
314
Default logger handler if none is specified
{ "login": "bndr", "id": 1145456, "node_id": "MDQ6VXNlcjExNDU0NTY=", "avatar_url": "https://avatars.githubusercontent.com/u/1145456?v=4", "gravatar_id": "", "url": "https://api.github.com/users/bndr", "html_url": "https://github.com/bndr", "followers_url": "https://api.github.com/users/bndr/followers", "following_url": "https://api.github.com/users/bndr/following{/other_user}", "gists_url": "https://api.github.com/users/bndr/gists{/gist_id}", "starred_url": "https://api.github.com/users/bndr/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/bndr/subscriptions", "organizations_url": "https://api.github.com/users/bndr/orgs", "repos_url": "https://api.github.com/users/bndr/repos", "events_url": "https://api.github.com/users/bndr/events{/privacy}", "received_events_url": "https://api.github.com/users/bndr/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Works for me, thanks!\n" ]
"2014-03-03T08:41:39"
"2014-06-24T04:48:28"
"2014-03-03T15:02:55"
CONTRIBUTOR
null
This should stop showing warnings: "No handlers could be found for logger "peewee"" if no handler is specified.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/314/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/314/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/314", "html_url": "https://github.com/coleifer/peewee/pull/314", "diff_url": "https://github.com/coleifer/peewee/pull/314.diff", "patch_url": "https://github.com/coleifer/peewee/pull/314.patch", "merged_at": "2014-03-03T15:02:55" }
https://api.github.com/repos/coleifer/peewee/issues/313
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/313/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/313/comments
https://api.github.com/repos/coleifer/peewee/issues/313/events
https://github.com/coleifer/peewee/issues/313
28,448,577
MDU6SXNzdWUyODQ0ODU3Nw==
313
Playhouse GFK issue with IN statement
{ "login": "thibaultmeyer", "id": 1005086, "node_id": "MDQ6VXNlcjEwMDUwODY=", "avatar_url": "https://avatars.githubusercontent.com/u/1005086?v=4", "gravatar_id": "", "url": "https://api.github.com/users/thibaultmeyer", "html_url": "https://github.com/thibaultmeyer", "followers_url": "https://api.github.com/users/thibaultmeyer/followers", "following_url": "https://api.github.com/users/thibaultmeyer/following{/other_user}", "gists_url": "https://api.github.com/users/thibaultmeyer/gists{/gist_id}", "starred_url": "https://api.github.com/users/thibaultmeyer/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/thibaultmeyer/subscriptions", "organizations_url": "https://api.github.com/users/thibaultmeyer/orgs", "repos_url": "https://api.github.com/users/thibaultmeyer/repos", "events_url": "https://api.github.com/users/thibaultmeyer/events{/privacy}", "received_events_url": "https://api.github.com/users/thibaultmeyer/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Thanks, looking.\n", "The attribute error shouldn't occur, but I will also add that unfortunately you cannot query GFK's like that.\n\nYour query:\n\n``` python\nTag.select().where(Tag.object << Photo.select().where(Photo.published==True))\n```\n\nTo accomplish what you're going for, you'll want to:\n\n``` python\n published_photos = Photo.select().where(Photo.published == True)\n Tag.select().where(\n (Tag.object_id << published_photos.select(Photo.id)) &\n (Tag.object_type == Photo._meta.db_table))\n```\n", "I have the following model using GFK:\n\n``` python\n\nclass Subscription(GFKModel):\n subscriber_type = CharField(null=True)\n subscriber_id = IntegerField(null=True)\n subscriber = GFKField('subscriber_type', 'subscriber_id')\n\n resource_type = CharField(null=True)\n resource_id = IntegerField(null=True)\n resource = GFKField('resource_type', 'resource_id')\n\n class Meta:\n indexes = (\n ((\n 'subscriber_type',\n 'subscriber_id',\n 'resource_type',\n 'resource_id',\n ), True),\n )\n```\n\nAnd I use this helper for a get_or_create (notice the double workaround, because each simpler alternative doesn't work):\n\n``` python\n\n\ndef subscribe(subscriber, resource):\n # HACK workaround for using get_or_create / create_or_get with GFKFields.\n try:\n # HACK workaround for querying equality of GFKField. I'd love to do the following:\n # Subscription.get(\n # (Subscription.subscriber == subscriber) &\n # (Subscription.resource == resource))\n\n sub = Subscription.get(\n (Subscription.subscriber_id == subscriber._get_pk_value()) &\n (Subscription.subscriber_type == subscriber._meta.db_table) &\n (Subscription.resource_id == resource._get_pk_value()) &\n (Subscription.resource_type == resource._meta.db_table))\n\n created = False\n\n except Subscription.DoesNotExist:\n sub = Subscription.create(\n subscriber=subscriber,\n resource=resource,\n )\n\n created = True\n\n return sub, created\n\n```\n\nIs this limitation by design? (@coleifer earlier said \"you cannot query GFKs like that\")\n\nWould peewee accept a PR that promotes the GFKField class to something else than just 'object' to be more friendly to querying? Is this extremely difficult?\n", "It is not difficult, but semantics other than equality and inequality would\nbe weird. I'll look at implementing this.\nOn Jan 20, 2016 12:32 AM, \"Francisco Demartino\" notifications@github.com\nwrote:\n\n> I have the following model using GFK:\n> \n> class Subscription(GFKModel):\n> subscriber_type = CharField(null=True)\n> subscriber_id = IntegerField(null=True)\n> subscriber = GFKField('subscriber_type', 'subscriber_id')\n> \n> ```\n> resource_type = CharField(null=True)\n> resource_id = IntegerField(null=True)\n> resource = GFKField('resource_type', 'resource_id')\n> \n> class Meta:\n> indexes = (\n> ((\n> 'subscriber_type',\n> 'subscriber_id',\n> 'resource_type',\n> 'resource_id',\n> ), True),\n> )\n> ```\n> \n> And I use this helper for a get_or_create (notice the double workaround,\n> because each simpler alternative doesn't work):\n> \n> def subscribe(subscriber, resource):\n> # HACK workaround for using get_or_create / create_or_get with GFKFields.\n> try:\n> # HACK workaround for querying equality of GFKField. I'd love to do the following:\n> # Subscription.get(\n> # (Subscription.subscriber == subscriber) &\n> # (Subscription.resource == resource))\n> \n> ```\n> sub = Subscription.get(\n> (Subscription.subscriber_id == subscriber._get_pk_value()) &\n> (Subscription.subscriber_type == subscriber._meta.db_table) &\n> (Subscription.resource_id == resource._get_pk_value()) &\n> (Subscription.resource_type == resource._meta.db_table))\n> \n> created = False\n> \n> except Subscription.DoesNotExist:\n> sub = Subscription.create(\n> subscriber=subscriber,\n> resource=resource,\n> )\n> \n> created = True\n> \n> return sub, created\n> ```\n> \n> Is this limitation by design? (@coleifer https://github.com/coleifer\n> earlier said \"you cannot query GFKs like that\")\n> \n> Would peewee accept a PR that promotes the GFKField class to something\n> else than just 'object' to be more friendly to querying? Is this extremely\n> difficult?\n> \n> —\n> Reply to this email directly or view it on GitHub\n> https://github.com/coleifer/peewee/issues/313#issuecomment-173108828.\n", "Thank you, Charles!\n\nFor an example of \"real-world\" code look here:\nhttps://github.com/franciscod/telegram-universal-forwarder-bot/blob/master/models.py\nhttps://github.com/franciscod/telegram-universal-forwarder-bot/blob/master/resources/util.py\n", "nice, thanks!\n", "@coleifer Does the new GFK API impact `create_or_get()`?\n", "It should, but I will add a test-case.\n", "Turns out it did not, but it does with the latest commit referenced.\n", "woohoo! thank you so much!\n" ]
"2014-02-27T19:49:35"
"2016-01-21T15:32:06"
"2016-01-20T17:09:46"
NONE
null
Hi, i have an issue with the Generic FK (playhouse) when I apply the MySQL IN statement. ``` python class Tag(Model): tag = CharField() object_type = CharField(null=True) object_id = IntegerField(null=True) object = GFKField('object_type', 'object_id') class Blog(Model): tags = ReverseGFK(Tag, 'object_type', 'object_id') class Photo(Model): tags = ReverseGFK(Tag, 'object_type', 'object_id') published = BooleanField() ``` ``` python Tag.select().where(Tag.object << Photo.select().where(Photo.published==True)) ``` ``` python 80 instance._obj_cache[self.att_name] = rel_obj 81 return instance._obj_cache.get(self.att_name) ---> 82 return self.field 83 84 def __set__(self, instance, value): AttributeError: 'GFKField' object has no attribute 'field' ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/313/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/313/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/312
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/312/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/312/comments
https://api.github.com/repos/coleifer/peewee/issues/312/events
https://github.com/coleifer/peewee/pull/312
28,090,405
MDExOlB1bGxSZXF1ZXN0MTI4MjA1MjI=
312
Added a debug feature for the Database class
{ "login": "pydeveloper94", "id": 6692874, "node_id": "MDQ6VXNlcjY2OTI4NzQ=", "avatar_url": "https://avatars.githubusercontent.com/u/6692874?v=4", "gravatar_id": "", "url": "https://api.github.com/users/pydeveloper94", "html_url": "https://github.com/pydeveloper94", "followers_url": "https://api.github.com/users/pydeveloper94/followers", "following_url": "https://api.github.com/users/pydeveloper94/following{/other_user}", "gists_url": "https://api.github.com/users/pydeveloper94/gists{/gist_id}", "starred_url": "https://api.github.com/users/pydeveloper94/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/pydeveloper94/subscriptions", "organizations_url": "https://api.github.com/users/pydeveloper94/orgs", "repos_url": "https://api.github.com/users/pydeveloper94/repos", "events_url": "https://api.github.com/users/pydeveloper94/events{/privacy}", "received_events_url": "https://api.github.com/users/pydeveloper94/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I'm not sure I understand these changes.\n", "http://peewee.readthedocs.org/en/latest/peewee/cookbook.html#logging-queries\n", "The developer is not able to choose whether or not they want to disable the logger providing debug output. You gave a solution here, https://github.com/coleifer/peewee/issues/254, to write\n\n```\nimport logging\nlogger = logging.getLogger('peewee')\nlogger.addHandler(logging.NullHandler())\n```\n\nbut the person who raised this issue stated that the code provided did not work. When I added these lines to my code base, it did not fix the logger problem.\n\nI think it would be favorable to enable logging while instantiating the database object by changing the debug keyword argument, which I added.\n\nWhen I first came across the log message being printed into the console, I thought there was an error with my code, but it was just because logging is not disabled by default.\n", "> You might try then peewee_logger.handlers = []. The logging docs are pretty helpful.\n\nFrom my final comment in the issue you referenced.\n", "The log framework has multiple log levels so you can subscribe to the ones you care about. Adding another layer of API in-between seems redundant, so I'm going to close this.\n" ]
"2014-02-22T06:08:21"
"2014-07-01T00:04:31"
"2014-02-23T13:22:12"
NONE
null
I changed the Database class so that you can choose to enable logging. For example, ``` db = SqliteDatabase('data.sqlite3', debug=True) ``` will enable the logger to log messages onto the console while the python interpreter is running.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/312/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/312/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/312", "html_url": "https://github.com/coleifer/peewee/pull/312", "diff_url": "https://github.com/coleifer/peewee/pull/312.diff", "patch_url": "https://github.com/coleifer/peewee/pull/312.patch", "merged_at": null }
https://api.github.com/repos/coleifer/peewee/issues/311
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/311/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/311/comments
https://api.github.com/repos/coleifer/peewee/issues/311/events
https://github.com/coleifer/peewee/issues/311
27,742,392
MDU6SXNzdWUyNzc0MjM5Mg==
311
Bulk loading
{ "login": "coleifer", "id": 119974, "node_id": "MDQ6VXNlcjExOTk3NA==", "avatar_url": "https://avatars.githubusercontent.com/u/119974?v=4", "gravatar_id": "", "url": "https://api.github.com/users/coleifer", "html_url": "https://github.com/coleifer", "followers_url": "https://api.github.com/users/coleifer/followers", "following_url": "https://api.github.com/users/coleifer/following{/other_user}", "gists_url": "https://api.github.com/users/coleifer/gists{/gist_id}", "starred_url": "https://api.github.com/users/coleifer/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/coleifer/subscriptions", "organizations_url": "https://api.github.com/users/coleifer/orgs", "repos_url": "https://api.github.com/users/coleifer/repos", "events_url": "https://api.github.com/users/coleifer/events{/privacy}", "received_events_url": "https://api.github.com/users/coleifer/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "http://peewee.readthedocs.org/en/latest/peewee/cookbook.html#bulk-inserts\n", "Hey, did you ever finish the page for bulk inserts? I'm having very poor performance inserting bulk data with `atomic` and `insert_many` on my model?\n", "http://docs.peewee-orm.com/en/latest/peewee/querying.html#bulk-inserts\n\nWhat database? Poor compared to what? \n", "I'm using a sqlite database. Even for a relatively simple insert of about 2000 rows of 5 ints (per row) it takes about 5 seconds for peewee to insert.\n", "I upgraded my sqlite version. Before I was only able to insert about 200 rows per transaction due to that version of sqlite's SQLITE_MAX_VARIABLE_NUMBER. I can now insert over 40,000 rows in one `with db.atomic():` block, however it can take as long as 80 seconds to complete the insert. Any ideas on what I can do with peewee to speed this up? I have millions of rows that I would like to insert.\n", "I'm really sorry to bother you, @coleifer , but I have one more question. Based on what I've been reading, it seems that for doing large bulk inserts it's better to insert the data into a table without an index and then build the index for the table later. Is this possible to do with peewee? If this isn't the correct place for this question let me know and I'll post it elsewhere. I wasn't able to find anything on SO regarding the topic for peewee.\n", "There's a great StackOverflow thread on speeding up SQLite inserts. Summary of tips:\n- Create your indexes afterwards.\n- Use PRAGMA synchronous=0; when inserting\n- Use bulk insert syntax\n- Use transactions\n- Batch it up.\n\nFor peewee, you can create the tables and indexes separately by running:\n\n``` python\ndb = SqliteDatabase(...)\n\ndb.create_table(ModelClass)\ndb.create_table(Model2)\n\n# do insert\n\nModelClass.create_indexes()\nModel2.create_indexes()\n```\n", "Sorry to get back to you so late, I didn't see this email. Thanks for the\nresponse, I really appreciate it. I was able to speed up the insert by\nturning off auto-indexing and doing the other things you mentioned from SO\ndiscussions. I may be doing another large insert again this week and I'll\ntry your suggestions regarding peewee's `create_indexes` method. Thanks again for your input!\n\nOn Mon, May 30, 2016 at 6:35 PM, Charles Leifer notifications@github.com\nwrote:\n\n> There's a great StackOverflow thread on speeding up SQLite inserts.\n> Summary of tips:\n> - Create your indexes afterwards.\n> - Use PRAGMA synchronous=0; when inserting\n> - Use bulk insert syntax\n> - Use transactions\n> - Batch it up.\n> \n> For peewee, you can create the tables and indexes separately by running:\n> \n> db = SqliteDatabase(...)\n> \n> db.create_table(ModelClass)\n> db.create_table(Model2)\n> \n> # do insert\n> \n> ModelClass.create_indexes()\n> Model2.create_indexes()\n> \n> —\n> You are receiving this because you commented.\n> Reply to this email directly, view it on GitHub\n> https://github.com/coleifer/peewee/issues/311#issuecomment-222565897,\n> or mute the thread\n> https://github.com/notifications/unsubscribe/AHP3Bx0A1GZZlqlCNTZnmZLztVwkmCoYks5qG3Q-gaJpZM4BilCr\n> .\n" ]
"2014-02-17T19:05:42"
"2016-06-01T15:26:28"
"2014-02-20T17:26:36"
OWNER
null
Bulk loading performance improvements, see Maxime's post on mailing list. ``` $ python AAA.py How many lines to insert ?50000 One Big Query ('Done in ',0.3364,'seconds') Many queries, no transaction ('Done in ',453.3142,'seconds') Many queries, using transaction ('Done in ',9.6940,'seconds') ``` ``` python #!/usr/bin/python # -*-coding:Utf-8 -* from peewee import * from peewee import RawQuery import time db = MySQLDatabase('*****',user='root',passwd='*****') class Message(Model) : messId = IntegerField(primary_key=True) messState = CharField() class Meta: database = db @staticmethod def massAdditionTest(idList,state): print("One Big Query") Message.drop_table() Message.create_table() start = time.time() if len(idList)>0 : sql = list() args = list() for id in idList : sql.append( '(%s,%s)' ) args += [id,state] sql = 'INSERT INTO `message` (`messId`,`messState`) VALUES ' + ','.join(sql) q = RawQuery(Message,sql,*args) q.execute() end = time.time() print('Done in ',end-start,'seconds') print("Many queries, no transaction") Message.drop_table() Message.create_table() start = time.time() if len(idList)>0: for id in idList : Message.create(messId=id,messState=state) end = time.time() print('Done in ',end-start,'seconds') print("Many queries, using transaction") Message.drop_table() Message.create_table() start = time.time() if len(idList)>0: with db.transaction(): for id in idList : Message.create(messId=id,messState=state) end = time.time() print('Done in ',end-start,'seconds') if __name__ == "__main__": n = input('How many lines to insert ?') Message.massAdditionTest(range(n),'test') ``` > So I said something wrong : the 'transaction' method is much more better than the one without transaction. > But it is also true that the first method is much quicker. > > Is there a way to do it with peewee without using the RawQuery ?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/311/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/311/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/310
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/310/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/310/comments
https://api.github.com/repos/coleifer/peewee/issues/310/events
https://github.com/coleifer/peewee/issues/310
27,666,937
MDU6SXNzdWUyNzY2NjkzNw==
310
pwiz breaks with a table named `servers` on mysql
{ "login": "g3rv4", "id": 6250774, "node_id": "MDQ6VXNlcjYyNTA3NzQ=", "avatar_url": "https://avatars.githubusercontent.com/u/6250774?v=4", "gravatar_id": "", "url": "https://api.github.com/users/g3rv4", "html_url": "https://github.com/g3rv4", "followers_url": "https://api.github.com/users/g3rv4/followers", "following_url": "https://api.github.com/users/g3rv4/following{/other_user}", "gists_url": "https://api.github.com/users/g3rv4/gists{/gist_id}", "starred_url": "https://api.github.com/users/g3rv4/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/g3rv4/subscriptions", "organizations_url": "https://api.github.com/users/g3rv4/orgs", "repos_url": "https://api.github.com/users/g3rv4/repos", "events_url": "https://api.github.com/users/g3rv4/events{/privacy}", "received_events_url": "https://api.github.com/users/g3rv4/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Are you sure the problem is the foreign key to `servers`? Can you create a test-case?\n", "I'd love to. Do you have an example of a test case? I'm just getting started with python\n", "I don't see `servers` listed in mysql's reserved words list: https://dev.mysql.com/doc/refman/5.5/en/reserved-words.html\n", "I don't think that's a reserved word in mysql, sorry if I gave you that impression. I think it's something in pwiz.py that doesn't let it work with a table named `servers`. In order to replicate, I created a new database with this table\n\n```\nCREATE TABLE `servers` (\n `id` INT NOT NULL AUTO_INCREMENT,\n `ip` VARCHAR(50) NULL,\n PRIMARY KEY (`id`));\n```\n\nCreated a new project and installed\n\n```\nPyMySQL==0.6.1\npeewee==2.2.1\n```\n\nThen, I ran `python env\\Scripts\\pwiz.py -e mysql -u user -P pass peewee` inside the virtualenv, and this is what it returned\n\n```\nfrom peewee import *\n\ndatabase = MySQLDatabase('peewee', **{'user': 'user', 'passwd': 'pass'})\n\nclass UnknownFieldType(object):\n pass\n\nclass BaseModel(Model):\n class Meta:\n database = database\n\nclass Servers(BaseModel):\n db = CharField(max_length=64, db_column='Db')\n host = CharField(max_length=64, db_column='Host')\n server_name = IntegerField(db_column='Server_name')\n\n class Meta:\n db_table = 'servers'\n```\n\nYou can see that pwiz created a class named Servers, but it doesn't have the `ip` field that's on the table `servers`.\n\nIf you also have a FK to your `servers` table, pwiz just breaks... to show this, I created another table and added a FK to `servers` running this query\n\n```\nCREATE TABLE `accounts` (\n `id` INT NOT NULL AUTO_INCREMENT,\n `server_id` INT NULL,\n `name` VARCHAR(45) NULL,\n `password` VARCHAR(45) NULL,\n PRIMARY KEY (`id`),\n INDEX `server` (`server_id` ASC),\n CONSTRAINT `server`\n FOREIGN KEY (`server_id`)\n REFERENCES `servers` (`id`)\n ON DELETE NO ACTION\n ON UPDATE NO ACTION);\n```\n\nNow, when I execute `python env\\Scripts\\pwiz.py -e mysql -u user -P pass peewee` I get\n\n```\nTraceback (most recent call last):\n File \"env\\Scripts\\pwiz.py\", line 540, in <module>\n print_models(options.engine, database, tables, **connect)\n File \"env\\Scripts\\pwiz.py\", line 444, in print_models\n models, table_to_model, table_fks, col_meta = introspect(db, schema)\n File \"env\\Scripts\\pwiz.py\", line 419, in introspect\n table_columns[rel_table][rel_pk].field_class = PrimaryKeyField\nKeyError: 'id'\n```\n\nI was able to replicate this in an Ubuntu as well.\n", "I spent some time messing around with this and you're totally right. Apologies -- I never use MySQL and needed to install it and test to see what exactly was going on.\n", "No need to apologize at all :) let me know if I can give you a hand. I'm totally new at Python but your project has helped me a lot already\n", "There was a bug in the introspection of primary keys w/mysql. Fixed in 20329564fc740bc94e0751a94cd6def88b36da5b\n" ]
"2014-02-16T09:11:01"
"2014-02-19T14:31:10"
"2014-02-19T14:31:10"
NONE
null
If you have a table named `servers` on mysql (and a FK to it), pwiz fails with ``` Traceback (most recent call last): File "env/bin/pwiz.py", line 540, in <module> print_models(options.engine, database, tables, **connect) File "env/bin/pwiz.py", line 444, in print_models models, table_to_model, table_fks, col_meta = introspect(db, schema) File "env/bin/pwiz.py", line 419, in introspect table_columns[rel_table][rel_pk].field_class = PrimaryKeyField KeyError: 'id' ``` but if you don't have FK, pwiz just generates ``` from peewee import * database = MySQLDatabase('db', **{'user': 'user', 'passwd': 'pwd'}) class UnknownFieldType(object): pass class BaseModel(Model): class Meta: database = database class Servers(BaseModel): db = CharField(db_column='Db', max_length=64) host = CharField(db_column='Host', max_length=64) server_name = IntegerField(db_column='Server_name') username = CharField(db_column='Username', max_length=64) class Meta: db_table = 'servers' ``` Which is also wrong. I'd add a list of RESERVED_TABLE_NAMES as you currently have RESERVED_WORDS for the columns.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/310/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/310/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/309
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/309/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/309/comments
https://api.github.com/repos/coleifer/peewee/issues/309/events
https://github.com/coleifer/peewee/issues/309
27,497,074
MDU6SXNzdWUyNzQ5NzA3NA==
309
How to reference specific field with ForeignKeyField
{ "login": "wcbeard", "id": 379413, "node_id": "MDQ6VXNlcjM3OTQxMw==", "avatar_url": "https://avatars.githubusercontent.com/u/379413?v=4", "gravatar_id": "", "url": "https://api.github.com/users/wcbeard", "html_url": "https://github.com/wcbeard", "followers_url": "https://api.github.com/users/wcbeard/followers", "following_url": "https://api.github.com/users/wcbeard/following{/other_user}", "gists_url": "https://api.github.com/users/wcbeard/gists{/gist_id}", "starred_url": "https://api.github.com/users/wcbeard/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/wcbeard/subscriptions", "organizations_url": "https://api.github.com/users/wcbeard/orgs", "repos_url": "https://api.github.com/users/wcbeard/repos", "events_url": "https://api.github.com/users/wcbeard/events{/privacy}", "received_events_url": "https://api.github.com/users/wcbeard/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I've got a commit or two towards making this work, almost there.\n", "Added. http://peewee.readthedocs.org/en/latest/peewee/api.html#ForeignKeyField\n" ]
"2014-02-13T06:21:20"
"2014-02-18T21:22:03"
"2014-02-18T21:22:03"
NONE
null
I'm trying to find a way to use a `ForeignKeyField` that refers to a specific field of another model, rather than the entire model itself. I believe in Django's ORM it's the [`to_field`](https://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.ForeignKey.to_field) attribute. Looking at the [source code](https://github.com/coleifer/peewee/blob/master/peewee.py#L826), there doesn't appear to be any option for this, but rather a check to make sure that `related_name` doesn't conflict with any of the model's field names (`if self.related_name in self.rel_model._meta.fields`...). If there is no way to currently specify the field, would it be a feasible future enhancement for peewee?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/309/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/309/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/308
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/308/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/308/comments
https://api.github.com/repos/coleifer/peewee/issues/308/events
https://github.com/coleifer/peewee/pull/308
27,414,293
MDExOlB1bGxSZXF1ZXN0MTI0NTEzNTI=
308
refactored _parse to run isinstance less.
{ "login": "danthedeckie", "id": 1070206, "node_id": "MDQ6VXNlcjEwNzAyMDY=", "avatar_url": "https://avatars.githubusercontent.com/u/1070206?v=4", "gravatar_id": "", "url": "https://api.github.com/users/danthedeckie", "html_url": "https://github.com/danthedeckie", "followers_url": "https://api.github.com/users/danthedeckie/followers", "following_url": "https://api.github.com/users/danthedeckie/following{/other_user}", "gists_url": "https://api.github.com/users/danthedeckie/gists{/gist_id}", "starred_url": "https://api.github.com/users/danthedeckie/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/danthedeckie/subscriptions", "organizations_url": "https://api.github.com/users/danthedeckie/orgs", "repos_url": "https://api.github.com/users/danthedeckie/repos", "events_url": "https://api.github.com/users/danthedeckie/events{/privacy}", "received_events_url": "https://api.github.com/users/danthedeckie/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I had shied away from this previously because I didn't want to tangle up `Node` objects with their SQL representations, but this has actually caused some pain when wanting to add new Node types (i.e. the `unknown` grossness). Maybe this is a good path forward, I certainly have been aware that the recent refactorings would hurt performance a bit, but figured it would be negligible since most time is spent in the DB anyways... but I always like fast.\n\nThank you very much for this work, I think it's a good start and I'll investigate a similar approach.\n", "Cool! :-) I really like peewee, I love how simple the whole thing is for library users, and only being one file, etc. Thanks very much for your work on it.\n", "I did some profiling (ran the benchmark suite with cProfile). Here are some baseline results:\n\nhttps://gist.github.com/coleifer/9da9e7683530342b7de2\n", "Closing this and have marked it as a to-do item.\n" ]
"2014-02-12T07:13:19"
"2014-07-06T01:50:20"
"2014-04-22T14:23:28"
NONE
null
I was importing some data, and found it running slower than I thought it should. I profiled, and found that the `_parse` function was taking the longest, and that `isinstance` was getting called 259579 times, which was taking a good chunk of it. I've (very naively) refactored the `QueryCompiler._parse_node` function to call out to per-object methods (which for now is called `_parse_me`, but that's easily changed). This reduces the calls to `isinstance` down to 97122, and shaves a 10% off my data import time. Is this a line of optimising worth pursuing?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/308/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/308/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/308", "html_url": "https://github.com/coleifer/peewee/pull/308", "diff_url": "https://github.com/coleifer/peewee/pull/308.diff", "patch_url": "https://github.com/coleifer/peewee/pull/308.patch", "merged_at": null }
https://api.github.com/repos/coleifer/peewee/issues/307
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/307/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/307/comments
https://api.github.com/repos/coleifer/peewee/issues/307/events
https://github.com/coleifer/peewee/issues/307
27,410,336
MDU6SXNzdWUyNzQxMDMzNg==
307
request: reflect major changes in the source code tarball in the ChangeLog
{ "login": "pitchforks", "id": 4378791, "node_id": "MDQ6VXNlcjQzNzg3OTE=", "avatar_url": "https://avatars.githubusercontent.com/u/4378791?v=4", "gravatar_id": "", "url": "https://api.github.com/users/pitchforks", "html_url": "https://github.com/pitchforks", "followers_url": "https://api.github.com/users/pitchforks/followers", "following_url": "https://api.github.com/users/pitchforks/following{/other_user}", "gists_url": "https://api.github.com/users/pitchforks/gists{/gist_id}", "starred_url": "https://api.github.com/users/pitchforks/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/pitchforks/subscriptions", "organizations_url": "https://api.github.com/users/pitchforks/orgs", "repos_url": "https://api.github.com/users/pitchforks/repos", "events_url": "https://api.github.com/users/pitchforks/events{/privacy}", "received_events_url": "https://api.github.com/users/pitchforks/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "This was an oversight on my part. I re-pushed the 2.2.1 release so hopefully that fixes things. Thank you for bringing this to my attention.\n" ]
"2014-02-12T05:06:26"
"2014-02-12T16:30:22"
"2014-02-12T16:30:22"
NONE
null
I have noticed that the source code tarball for 2.2.1 is much smaller. Apparently it's because 2.2.1 doesn't ship docs in HTML form anymore. There wasn't anything in the ChangeLog about it so I've only noticed it when my build script failed and I had a closer look at what's going on. This is a low priority request, since I'm only packaging peewee for myself, so feel free to close the issue as soon as you read it. While the main purpose of the ChangeLog is to cover functional changes in the software, covering up details about such major source code tarball changes will be helpful to packagers. Now, since one has to build the docs himself, Sphinx becomes a build dependency if docs are needed, it will be nice to add this somewhere, perhaps a line in README?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/307/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/307/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/306
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/306/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/306/comments
https://api.github.com/repos/coleifer/peewee/issues/306/events
https://github.com/coleifer/peewee/pull/306
27,359,768
MDExOlB1bGxSZXF1ZXN0MTI0MjEzNTE=
306
fix the on_update on a foreign key
{ "login": "matrixise", "id": 38737, "node_id": "MDQ6VXNlcjM4NzM3", "avatar_url": "https://avatars.githubusercontent.com/u/38737?v=4", "gravatar_id": "", "url": "https://api.github.com/users/matrixise", "html_url": "https://github.com/matrixise", "followers_url": "https://api.github.com/users/matrixise/followers", "following_url": "https://api.github.com/users/matrixise/following{/other_user}", "gists_url": "https://api.github.com/users/matrixise/gists{/gist_id}", "starred_url": "https://api.github.com/users/matrixise/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/matrixise/subscriptions", "organizations_url": "https://api.github.com/users/matrixise/orgs", "repos_url": "https://api.github.com/users/matrixise/repos", "events_url": "https://api.github.com/users/matrixise/events{/privacy}", "received_events_url": "https://api.github.com/users/matrixise/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Whoops, thanks!\n" ]
"2014-02-11T16:10:04"
"2014-06-26T21:10:31"
"2014-02-11T16:12:19"
CONTRIBUTOR
null
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/306/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/306/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/306", "html_url": "https://github.com/coleifer/peewee/pull/306", "diff_url": "https://github.com/coleifer/peewee/pull/306.diff", "patch_url": "https://github.com/coleifer/peewee/pull/306.patch", "merged_at": "2014-02-11T16:12:19" }
https://api.github.com/repos/coleifer/peewee/issues/305
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/305/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/305/comments
https://api.github.com/repos/coleifer/peewee/issues/305/events
https://github.com/coleifer/peewee/issues/305
27,192,618
MDU6SXNzdWUyNzE5MjYxOA==
305
Metaclass conflict
{ "login": "soasme", "id": 369081, "node_id": "MDQ6VXNlcjM2OTA4MQ==", "avatar_url": "https://avatars.githubusercontent.com/u/369081?v=4", "gravatar_id": "", "url": "https://api.github.com/users/soasme", "html_url": "https://github.com/soasme", "followers_url": "https://api.github.com/users/soasme/followers", "following_url": "https://api.github.com/users/soasme/following{/other_user}", "gists_url": "https://api.github.com/users/soasme/gists{/gist_id}", "starred_url": "https://api.github.com/users/soasme/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/soasme/subscriptions", "organizations_url": "https://api.github.com/users/soasme/orgs", "repos_url": "https://api.github.com/users/soasme/repos", "events_url": "https://api.github.com/users/soasme/events{/privacy}", "received_events_url": "https://api.github.com/users/soasme/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "it's more of a python problem rather than a peewee one.\n\nI think letting `UserMeta` inherit `BaseModel` should resolve this issue\n" ]
"2014-02-08T03:56:54"
"2014-02-08T10:26:46"
"2014-02-08T10:26:46"
CONTRIBUTOR
null
Are there any suggestions to solve the metaclass conflict problem? ``` python from peewee import Model, SqliteDatabase, CharField db = SqliteDatabase('/tmp/conflict.db') class UserMeta(type): def __new__(mcs, name, bases, dct): return super(UserMeta, mcs).__new__(mcs, name, bases, dct) class User(Model): __metaclass__ = UserMeta name = CharField() class Meta: database = db User.create_table() user = User.create(name='bob') print user import os os.remove('/tmp/conflict.db') ``` ``` Traceback (most recent call last): File "a.py", line 10, in <module> class User(Model): File "a.py", line 8, in __new__ return super(UserMeta, mcs).__new__(mcs, name, bases, dct) TypeError: Error when calling the metaclass bases metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/305/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/305/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/304
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/304/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/304/comments
https://api.github.com/repos/coleifer/peewee/issues/304/events
https://github.com/coleifer/peewee/pull/304
27,096,630
MDExOlB1bGxSZXF1ZXN0MTIyOTMxMDE=
304
Fixes index creation problems with schema
{ "login": "giohappy", "id": 571129, "node_id": "MDQ6VXNlcjU3MTEyOQ==", "avatar_url": "https://avatars.githubusercontent.com/u/571129?v=4", "gravatar_id": "", "url": "https://api.github.com/users/giohappy", "html_url": "https://github.com/giohappy", "followers_url": "https://api.github.com/users/giohappy/followers", "following_url": "https://api.github.com/users/giohappy/following{/other_user}", "gists_url": "https://api.github.com/users/giohappy/gists{/gist_id}", "starred_url": "https://api.github.com/users/giohappy/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/giohappy/subscriptions", "organizations_url": "https://api.github.com/users/giohappy/orgs", "repos_url": "https://api.github.com/users/giohappy/repos", "events_url": "https://api.github.com/users/giohappy/events{/privacy}", "received_events_url": "https://api.github.com/users/giohappy/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Thanks!\n" ]
"2014-02-06T23:33:45"
"2014-06-16T14:18:43"
"2014-02-06T23:58:48"
CONTRIBUTOR
null
Fixes https://github.com/coleifer/peewee/issues/303
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/304/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/304/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/304", "html_url": "https://github.com/coleifer/peewee/pull/304", "diff_url": "https://github.com/coleifer/peewee/pull/304.diff", "patch_url": "https://github.com/coleifer/peewee/pull/304.patch", "merged_at": "2014-02-06T23:58:48" }
https://api.github.com/repos/coleifer/peewee/issues/303
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/303/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/303/comments
https://api.github.com/repos/coleifer/peewee/issues/303/events
https://github.com/coleifer/peewee/issues/303
27,093,328
MDU6SXNzdWUyNzA5MzMyOA==
303
CREATE INDEX on ForeignKey crashes during table creation
{ "login": "giohappy", "id": 571129, "node_id": "MDQ6VXNlcjU3MTEyOQ==", "avatar_url": "https://avatars.githubusercontent.com/u/571129?v=4", "gravatar_id": "", "url": "https://api.github.com/users/giohappy", "html_url": "https://github.com/giohappy", "followers_url": "https://api.github.com/users/giohappy/followers", "following_url": "https://api.github.com/users/giohappy/following{/other_user}", "gists_url": "https://api.github.com/users/giohappy/gists{/gist_id}", "starred_url": "https://api.github.com/users/giohappy/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/giohappy/subscriptions", "organizations_url": "https://api.github.com/users/giohappy/orgs", "repos_url": "https://api.github.com/users/giohappy/repos", "events_url": "https://api.github.com/users/giohappy/events{/privacy}", "received_events_url": "https://api.github.com/users/giohappy/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Fix https://github.com/coleifer/peewee/pull/304\n" ]
"2014-02-06T22:46:36"
"2014-02-06T23:58:48"
"2014-02-06T23:58:48"
CONTRIBUTOR
null
When doing MyModel.create_table(), MyModel containing a ForeignKeyField, the creation of the related index doesn't work, because it complains that the relation is missing (MyModel's table) I've also notices that the CREATE INDEX sql misses the table schema. I've tried fixing it at line https://github.com/coleifer/peewee/blob/master/peewee.py#L1321 : tbl_name = ('.').join([model_class._meta.schema,model_class._meta.db_table]) but this doesn't solve the problem. Maybe the table hasn't been created yet when the create index is issued? Am I doing something wrong?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/303/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/303/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/302
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/302/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/302/comments
https://api.github.com/repos/coleifer/peewee/issues/302/events
https://github.com/coleifer/peewee/issues/302
26,837,044
MDU6SXNzdWUyNjgzNzA0NA==
302
Update/Refresh Field List
{ "login": "bndr", "id": 1145456, "node_id": "MDQ6VXNlcjExNDU0NTY=", "avatar_url": "https://avatars.githubusercontent.com/u/1145456?v=4", "gravatar_id": "", "url": "https://api.github.com/users/bndr", "html_url": "https://github.com/bndr", "followers_url": "https://api.github.com/users/bndr/followers", "following_url": "https://api.github.com/users/bndr/following{/other_user}", "gists_url": "https://api.github.com/users/bndr/gists{/gist_id}", "starred_url": "https://api.github.com/users/bndr/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/bndr/subscriptions", "organizations_url": "https://api.github.com/users/bndr/orgs", "repos_url": "https://api.github.com/users/bndr/repos", "events_url": "https://api.github.com/users/bndr/events{/privacy}", "received_events_url": "https://api.github.com/users/bndr/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "This would be a great feature but if you take a look at some of the existing schema migration tools you might be surprised how tricky this is.\n\nCurrently peewee has a helper in `playhouse.migrate` but i've only tested it with postgres. Schema migrations in sqlite are tricky because it only supports adding columns. For now these are the best options.\n" ]
"2014-02-03T21:04:23"
"2014-02-03T22:05:27"
"2014-02-03T22:05:27"
CONTRIBUTOR
null
Hi! I would like to suggest implementing some sort of refresh_table method, which will add/delete Fields of the Model. For example I have a model: ``` class Pets(Model): name = CharField() ``` Then I do `Pets.create_table()` now I have the relevant table in my database, after some time (usually during development) I decide that I need another field: ``` class Pets(Model): name = CharField() ownerName = CharField() ``` But now the Model isn't in sync with the table in the database, and I get Errors like: `"Unknown column 't1.ownerName' in 'field list'"` It would be quite useful have some sort of refresh/update/alter_table method that would update the relevant fields, instead of adding the fields manually or dropping and recreating the table. Thoughts?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/302/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/302/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/301
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/301/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/301/comments
https://api.github.com/repos/coleifer/peewee/issues/301/events
https://github.com/coleifer/peewee/issues/301
26,823,309
MDU6SXNzdWUyNjgyMzMwOQ==
301
How to check
{ "login": "kramer65", "id": 596581, "node_id": "MDQ6VXNlcjU5NjU4MQ==", "avatar_url": "https://avatars.githubusercontent.com/u/596581?v=4", "gravatar_id": "", "url": "https://api.github.com/users/kramer65", "html_url": "https://github.com/kramer65", "followers_url": "https://api.github.com/users/kramer65/followers", "following_url": "https://api.github.com/users/kramer65/following{/other_user}", "gists_url": "https://api.github.com/users/kramer65/gists{/gist_id}", "starred_url": "https://api.github.com/users/kramer65/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/kramer65/subscriptions", "organizations_url": "https://api.github.com/users/kramer65/orgs", "repos_url": "https://api.github.com/users/kramer65/repos", "events_url": "https://api.github.com/users/kramer65/events{/privacy}", "received_events_url": "https://api.github.com/users/kramer65/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "This isn't really appropriate for GH issues. Try the [peewee mailing list](groups.google.com/group/peewee-orm) or irc (freenode #peewee).\n", "Since you're stuck, though, you might try something like this:\n\n``` python\n\n(User\n .select()\n .where(fn.Exists(\n Message.select().where(Message.user == User.id))))\n```\n" ]
"2014-02-03T18:08:33"
"2014-02-03T19:16:01"
"2014-02-03T18:48:47"
NONE
null
I'm trying to write a query which should return all names of Users which have at least one message associated with them. My models look like this: ``` class User(db.Model): name = CharField() class Message(db.Model): user = ForeignKeyField(User, related_name='messages') text = TextField() ``` and I currently try this as follows: ``` usersWithAtLeastOneMessage = User.select().where((fn.Count(User.messages) > 0) for u in usersWithAtLeastOneMessage: print u.name ``` Unfortunately, this gives me an error saying `OperationalError: misuse of aggregate function Count()`. Does anybody know how I can get all users which have at least one Message? All tips are welcome!
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/301/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/301/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/300
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/300/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/300/comments
https://api.github.com/repos/coleifer/peewee/issues/300/events
https://github.com/coleifer/peewee/issues/300
26,743,303
MDU6SXNzdWUyNjc0MzMwMw==
300
pwiz foreign key regex for sqlite
{ "login": "coleifer", "id": 119974, "node_id": "MDQ6VXNlcjExOTk3NA==", "avatar_url": "https://avatars.githubusercontent.com/u/119974?v=4", "gravatar_id": "", "url": "https://api.github.com/users/coleifer", "html_url": "https://github.com/coleifer", "followers_url": "https://api.github.com/users/coleifer/followers", "following_url": "https://api.github.com/users/coleifer/following{/other_user}", "gists_url": "https://api.github.com/users/coleifer/gists{/gist_id}", "starred_url": "https://api.github.com/users/coleifer/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/coleifer/subscriptions", "organizations_url": "https://api.github.com/users/coleifer/orgs", "repos_url": "https://api.github.com/users/coleifer/repos", "events_url": "https://api.github.com/users/coleifer/events{/privacy}", "received_events_url": "https://api.github.com/users/coleifer/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[]
"2014-02-01T17:43:32"
"2014-02-02T15:51:42"
"2014-02-02T15:51:42"
OWNER
null
Recent changes to the definition of foreign keys has caused pwiz to break when introspecting peewee-created sqlite tables. Here is the table definition from peewee 2.1.6: ``` sql CREATE TABLE "fkpk" ( "col_types_id" INTEGER NOT NULL PRIMARY KEY REFERENCES "coltypes" ("f11") ); ``` Here it is for 2.2.0, broken: ``` sql CREATE TABLE "fkpk" ( "col_types_id" INTEGER NOT NULL PRIMARY KEY, FOREIGN KEY ("col_types_id") REFERENCES "coltypes" ("f11") ); ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/300/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/300/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/299
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/299/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/299/comments
https://api.github.com/repos/coleifer/peewee/issues/299/events
https://github.com/coleifer/peewee/pull/299
26,664,365
MDExOlB1bGxSZXF1ZXN0MTIwNzEwMDQ=
299
readthedocs.org theme
{ "login": "bahrunnur", "id": 2069852, "node_id": "MDQ6VXNlcjIwNjk4NTI=", "avatar_url": "https://avatars.githubusercontent.com/u/2069852?v=4", "gravatar_id": "", "url": "https://api.github.com/users/bahrunnur", "html_url": "https://github.com/bahrunnur", "followers_url": "https://api.github.com/users/bahrunnur/followers", "following_url": "https://api.github.com/users/bahrunnur/following{/other_user}", "gists_url": "https://api.github.com/users/bahrunnur/gists{/gist_id}", "starred_url": "https://api.github.com/users/bahrunnur/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/bahrunnur/subscriptions", "organizations_url": "https://api.github.com/users/bahrunnur/orgs", "repos_url": "https://api.github.com/users/bahrunnur/repos", "events_url": "https://api.github.com/users/bahrunnur/events{/privacy}", "received_events_url": "https://api.github.com/users/bahrunnur/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I think I'm going to pass on merging, thank you though.\n" ]
"2014-01-31T09:06:36"
"2014-06-23T01:00:46"
"2014-01-31T13:42:16"
NONE
null
I like the new theme on readthedocs.org, so I intregate it with local build docs and adding a little .gitignore for convenient what do you think?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/299/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/299/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/299", "html_url": "https://github.com/coleifer/peewee/pull/299", "diff_url": "https://github.com/coleifer/peewee/pull/299.diff", "patch_url": "https://github.com/coleifer/peewee/pull/299.patch", "merged_at": null }
https://api.github.com/repos/coleifer/peewee/issues/298
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/298/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/298/comments
https://api.github.com/repos/coleifer/peewee/issues/298/events
https://github.com/coleifer/peewee/issues/298
26,580,090
MDU6SXNzdWUyNjU4MDA5MA==
298
Cascade doesn't seem to exist anymore?
{ "login": "b1naryth1ef", "id": 599433, "node_id": "MDQ6VXNlcjU5OTQzMw==", "avatar_url": "https://avatars.githubusercontent.com/u/599433?v=4", "gravatar_id": "", "url": "https://api.github.com/users/b1naryth1ef", "html_url": "https://github.com/b1naryth1ef", "followers_url": "https://api.github.com/users/b1naryth1ef/followers", "following_url": "https://api.github.com/users/b1naryth1ef/following{/other_user}", "gists_url": "https://api.github.com/users/b1naryth1ef/gists{/gist_id}", "starred_url": "https://api.github.com/users/b1naryth1ef/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/b1naryth1ef/subscriptions", "organizations_url": "https://api.github.com/users/b1naryth1ef/orgs", "repos_url": "https://api.github.com/users/b1naryth1ef/repos", "events_url": "https://api.github.com/users/b1naryth1ef/events{/privacy}", "received_events_url": "https://api.github.com/users/b1naryth1ef/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Well you're right, that arg is replaced with `on_delete` and `on_update`. I need to push a documentation update. Neither is responsible for dropping a table with the cascade option. I think you're right that, while I see the code for this the important part is unreachable. I'll have two fixes coming.\n", "This should now be fixed. To drop a table w/cascade you can call:\n\n``` python\nModelClass.drop_table(cascade=True)\n```\n" ]
"2014-01-30T07:55:36"
"2014-01-30T10:43:43"
"2014-01-30T10:43:43"
NONE
null
I'm trying to figure out if I'm going crazy, or if the docs are out of date. Having any ForeignKeyField with cascade=True, errors out with the following: Code: ``` python ForeignKeyField(Category, cascade=True) ``` Throws: ``` python Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 823, in __init__ super(ForeignKeyField, self).__init__(*args, **kwargs) TypeError: __init__() got an unexpected keyword argument 'cascade' ``` Looking at source, it seems this doesn't exist anymore (or at least not anywhere I can find it in the 2.2 branch of things). Was this supposed to be removed? Am I missing something obvious (very likely)? I'm trying to find the right way to drop a table w/ cascade (sense that also seems like it was removed, or at least is unusable).
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/298/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/298/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/297
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/297/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/297/comments
https://api.github.com/repos/coleifer/peewee/issues/297/events
https://github.com/coleifer/peewee/pull/297
26,565,485
MDExOlB1bGxSZXF1ZXN0MTIwMTc1NDY=
297
Add version information
{ "login": "c4urself", "id": 391030, "node_id": "MDQ6VXNlcjM5MTAzMA==", "avatar_url": "https://avatars.githubusercontent.com/u/391030?v=4", "gravatar_id": "", "url": "https://api.github.com/users/c4urself", "html_url": "https://github.com/c4urself", "followers_url": "https://api.github.com/users/c4urself/followers", "following_url": "https://api.github.com/users/c4urself/following{/other_user}", "gists_url": "https://api.github.com/users/c4urself/gists{/gist_id}", "starred_url": "https://api.github.com/users/c4urself/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/c4urself/subscriptions", "organizations_url": "https://api.github.com/users/c4urself/orgs", "repos_url": "https://api.github.com/users/c4urself/repos", "events_url": "https://api.github.com/users/c4urself/events{/privacy}", "received_events_url": "https://api.github.com/users/c4urself/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "OMG, this change is so amazing; please have my babies.\n", "`__version__` is better than `VERSION`, I think.\n", "**version** added. Thanks for bringing this up!\n", ":thumbsup: thanks!\n" ]
"2014-01-30T00:15:35"
"2014-06-27T18:15:18"
"2014-01-30T10:30:44"
NONE
null
This is super useful for debugging purposes, seeing as peewee is just one big file it's nice to open it and see the VERSION information.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/297/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/297/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/297", "html_url": "https://github.com/coleifer/peewee/pull/297", "diff_url": "https://github.com/coleifer/peewee/pull/297.diff", "patch_url": "https://github.com/coleifer/peewee/pull/297.patch", "merged_at": null }
https://api.github.com/repos/coleifer/peewee/issues/296
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/296/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/296/comments
https://api.github.com/repos/coleifer/peewee/issues/296/events
https://github.com/coleifer/peewee/issues/296
26,565,299
MDU6SXNzdWUyNjU2NTI5OQ==
296
How to select a field with DB function?
{ "login": "giohappy", "id": 571129, "node_id": "MDQ6VXNlcjU3MTEyOQ==", "avatar_url": "https://avatars.githubusercontent.com/u/571129?v=4", "gravatar_id": "", "url": "https://api.github.com/users/giohappy", "html_url": "https://github.com/giohappy", "followers_url": "https://api.github.com/users/giohappy/followers", "following_url": "https://api.github.com/users/giohappy/following{/other_user}", "gists_url": "https://api.github.com/users/giohappy/gists{/gist_id}", "starred_url": "https://api.github.com/users/giohappy/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/giohappy/subscriptions", "organizations_url": "https://api.github.com/users/giohappy/orgs", "repos_url": "https://api.github.com/users/giohappy/repos", "events_url": "https://api.github.com/users/giohappy/events{/privacy}", "received_events_url": "https://api.github.com/users/giohappy/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Ok, I found it out:\n\nMyModel.select(fn.ST_AsText(MyModel.geom).alias('point'))\n" ]
"2014-01-30T00:11:15"
"2014-01-30T00:42:14"
"2014-01-30T00:41:48"
CONTRIBUTOR
null
This is the inverse of https://github.com/coleifer/peewee/issues/292 In this case I need to obtain a field with a DB function. Eg SELECT ST_AsText(geom)
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/296/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/296/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/295
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/295/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/295/comments
https://api.github.com/repos/coleifer/peewee/issues/295/events
https://github.com/coleifer/peewee/issues/295
26,552,739
MDU6SXNzdWUyNjU1MjczOQ==
295
Git database driver
{ "login": "grimnight", "id": 1737541, "node_id": "MDQ6VXNlcjE3Mzc1NDE=", "avatar_url": "https://avatars.githubusercontent.com/u/1737541?v=4", "gravatar_id": "", "url": "https://api.github.com/users/grimnight", "html_url": "https://github.com/grimnight", "followers_url": "https://api.github.com/users/grimnight/followers", "following_url": "https://api.github.com/users/grimnight/following{/other_user}", "gists_url": "https://api.github.com/users/grimnight/gists{/gist_id}", "starred_url": "https://api.github.com/users/grimnight/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/grimnight/subscriptions", "organizations_url": "https://api.github.com/users/grimnight/orgs", "repos_url": "https://api.github.com/users/grimnight/repos", "events_url": "https://api.github.com/users/grimnight/events{/privacy}", "received_events_url": "https://api.github.com/users/grimnight/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I don't see any reason not to just use Git-ORM.\n\nIf someone wanted to build a dp-api 2.0 driver for git, then something like that would be possible with peewee, but until then just stuck w/git-orm. Cool project, btw, hadn't heard of it.\n" ]
"2014-01-29T20:55:10"
"2014-01-29T21:19:55"
"2014-01-29T21:19:55"
NONE
null
Is it possible to add [Git-ORM](https://pypi.python.org/pypi/git-orm) like functionality to peewee using database drivers? Since peewee has such a collection of [addons](http://peewee.readthedocs.org/en/latest/peewee/playhouse.html), I was wondering if that was possible. [Git-ORM](https://pypi.python.org/pypi/git-orm) uses [Pygit2](https://pypi.python.org/pypi/pygit2) but [Dulwich](https://pypi.python.org/pypi/dulwich) is pure Python, so both would be good choices. I ask this because [Git-ORM](https://pypi.python.org/pypi/git-orm) is Python 3 only and it has seen little development lately (and it doesn't support remove). What I am asking is, is it even possible or would it be too difficult?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/295/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/295/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/294
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/294/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/294/comments
https://api.github.com/repos/coleifer/peewee/issues/294/events
https://github.com/coleifer/peewee/pull/294
26,543,568
MDExOlB1bGxSZXF1ZXN0MTIwMDQzOTI=
294
fixed tipo (_meta -> meta)
{ "login": "giohappy", "id": 571129, "node_id": "MDQ6VXNlcjU3MTEyOQ==", "avatar_url": "https://avatars.githubusercontent.com/u/571129?v=4", "gravatar_id": "", "url": "https://api.github.com/users/giohappy", "html_url": "https://github.com/giohappy", "followers_url": "https://api.github.com/users/giohappy/followers", "following_url": "https://api.github.com/users/giohappy/following{/other_user}", "gists_url": "https://api.github.com/users/giohappy/gists{/gist_id}", "starred_url": "https://api.github.com/users/giohappy/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/giohappy/subscriptions", "organizations_url": "https://api.github.com/users/giohappy/orgs", "repos_url": "https://api.github.com/users/giohappy/repos", "events_url": "https://api.github.com/users/giohappy/events{/privacy}", "received_events_url": "https://api.github.com/users/giohappy/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[]
"2014-01-29T18:55:17"
"2014-06-25T23:09:50"
"2014-01-29T19:19:09"
CONTRIBUTOR
null
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/294/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/294/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/294", "html_url": "https://github.com/coleifer/peewee/pull/294", "diff_url": "https://github.com/coleifer/peewee/pull/294.diff", "patch_url": "https://github.com/coleifer/peewee/pull/294.patch", "merged_at": "2014-01-29T19:19:09" }
https://api.github.com/repos/coleifer/peewee/issues/293
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/293/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/293/comments
https://api.github.com/repos/coleifer/peewee/issues/293/events
https://github.com/coleifer/peewee/pull/293
26,508,619
MDExOlB1bGxSZXF1ZXN0MTE5ODM5ODA=
293
Added an itemselector for hstore fields
{ "login": "zdxerr", "id": 368272, "node_id": "MDQ6VXNlcjM2ODI3Mg==", "avatar_url": "https://avatars.githubusercontent.com/u/368272?v=4", "gravatar_id": "", "url": "https://api.github.com/users/zdxerr", "html_url": "https://github.com/zdxerr", "followers_url": "https://api.github.com/users/zdxerr/followers", "following_url": "https://api.github.com/users/zdxerr/following{/other_user}", "gists_url": "https://api.github.com/users/zdxerr/gists{/gist_id}", "starred_url": "https://api.github.com/users/zdxerr/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/zdxerr/subscriptions", "organizations_url": "https://api.github.com/users/zdxerr/orgs", "repos_url": "https://api.github.com/users/zdxerr/repos", "events_url": "https://api.github.com/users/zdxerr/events{/privacy}", "received_events_url": "https://api.github.com/users/zdxerr/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Nice!! Thank you. Also thank you for the test case.\n" ]
"2014-01-29T09:52:02"
"2014-07-06T01:50:28"
"2014-01-29T14:16:31"
CONTRIBUTOR
null
I added an itemgetter to the hstore field, which returns an expression the selects the corresponding key from the hstore. Now you can do stuff like: ``` Test.select(Test.data['key']) ``` and ``` OP_MATCH = 'match' def match(left, right): return Expression(left, OP_MATCH, Param(right)) PostgresqlExtDatabase.register_ops({ OP_MATCH: '~*', }) Test.select().where(match(Test.data['key'], 'some regular expression.*')) ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/293/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/293/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/293", "html_url": "https://github.com/coleifer/peewee/pull/293", "diff_url": "https://github.com/coleifer/peewee/pull/293.diff", "patch_url": "https://github.com/coleifer/peewee/pull/293.patch", "merged_at": "2014-01-29T14:16:31" }
https://api.github.com/repos/coleifer/peewee/issues/292
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/292/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/292/comments
https://api.github.com/repos/coleifer/peewee/issues/292/events
https://github.com/coleifer/peewee/issues/292
26,484,968
MDU6SXNzdWUyNjQ4NDk2OA==
292
How to define a field wich requires to call DB function?
{ "login": "giohappy", "id": 571129, "node_id": "MDQ6VXNlcjU3MTEyOQ==", "avatar_url": "https://avatars.githubusercontent.com/u/571129?v=4", "gravatar_id": "", "url": "https://api.github.com/users/giohappy", "html_url": "https://github.com/giohappy", "followers_url": "https://api.github.com/users/giohappy/followers", "following_url": "https://api.github.com/users/giohappy/following{/other_user}", "gists_url": "https://api.github.com/users/giohappy/gists{/gist_id}", "starred_url": "https://api.github.com/users/giohappy/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/giohappy/subscriptions", "organizations_url": "https://api.github.com/users/giohappy/orgs", "repos_url": "https://api.github.com/users/giohappy/repos", "events_url": "https://api.github.com/users/giohappy/events{/privacy}", "received_events_url": "https://api.github.com/users/giohappy/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Yeah that's a bit tricky, but it should be possible. Did you try something like:\n\n``` python\nclass PointField(Field):\n db_field = 'point' # Assuming you would hook this up to a field type registered w/the db.\n\n def db_value(self, value):\n if value:\n return fn.St_PointFromText(value)\n```\n\n**EDIT** nevermind, that won't work as it's only called on parameters that are being 'interpolated' into the query.\n", "I'm not sure the best way to make this DRY, but you could try:\n\n``` python\nclass PointField(Field):\n db_field = 'point'\n\ndef pft(value):\n return fn.St_PointFromText(value)\n\nCoord.insert(point=pft('34.40032,10.1010101'))\nCoord.update(point=pft('35.303,10.101')).where(Coord.id == 3)\nCoord.select().where(\n Coord.point == pft('35.303,10.101'))\n```\n", "Here's something that hopefully helps:\n\n``` python\nfrom peewee import *\n\nclass PointField(Field):\n db_field = 'point'\n\ndb = SqliteDatabase(':memory:')\ndb.register_fields({'point': 'POINT'})\n\nclass Coord(Model):\n point = PointField()\n\n class Meta:\n database = db\n\ndef pft(v):\n return fn.St_PointFromText(v)\n\ncoords = '38.9717,95.2353'\nprint Coord.insert(point=pft(coords))\nprint Coord.update(point=pft(coords)).where(Coord.point == pft('39.0,96.0'))\nprint Coord.select().where(Coord.point == pft(coords))\n```\n\n---\n\n```\n<class '__main__.Coord'> INSERT INTO \"coord\" (\"point\") VALUES (St_PointFromText(?)) ['38.9717,95.2353']\n<class '__main__.Coord'> UPDATE \"coord\" SET \"point\" = St_PointFromText(?) WHERE (\"point\" = St_PointFromText(?)) ['38.9717,95.2353', '39.0,96.0']\n<class '__main__.Coord'> SELECT t1.\"id\", t1.\"point\" FROM \"coord\" AS t1 WHERE (t1.\"point\" = St_PointFromText(?)) ['38.9717,95.2353']\n```\n", "Thanks! I will give it a try asap. The trick was the use of the fn stuff ;)\n", "It works perfectly!\n" ]
"2014-01-28T23:06:27"
"2014-01-30T00:16:18"
"2014-01-29T18:57:34"
CONTRIBUTOR
null
I would need to manage GIS data creation, given the DB support it (eg PostGIS for Postgresql, MySQL a bit by default, Spatialite for Sqlite). The minimal requirement is to define a field which can wrap the value with a DB function. Eg, to save a point with PostGIS, I could call "St_PointFromText(string_value)", and "St_AsText" to retrieve it. I can't figure out how this could be done with a custom field...
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/292/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/292/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/291
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/291/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/291/comments
https://api.github.com/repos/coleifer/peewee/issues/291/events
https://github.com/coleifer/peewee/pull/291
26,406,568
MDExOlB1bGxSZXF1ZXN0MTE5Mjc1ODY=
291
Added db schema support
{ "login": "giohappy", "id": 571129, "node_id": "MDQ6VXNlcjU3MTEyOQ==", "avatar_url": "https://avatars.githubusercontent.com/u/571129?v=4", "gravatar_id": "", "url": "https://api.github.com/users/giohappy", "html_url": "https://github.com/giohappy", "followers_url": "https://api.github.com/users/giohappy/followers", "following_url": "https://api.github.com/users/giohappy/following{/other_user}", "gists_url": "https://api.github.com/users/giohappy/gists{/gist_id}", "starred_url": "https://api.github.com/users/giohappy/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/giohappy/subscriptions", "organizations_url": "https://api.github.com/users/giohappy/orgs", "repos_url": "https://api.github.com/users/giohappy/repos", "events_url": "https://api.github.com/users/giohappy/events{/privacy}", "received_events_url": "https://api.github.com/users/giohappy/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I opted for a slightly different refactoring which you can see in cfc7c3db6987cfe1ad087d645477bd1cb8c864e8 and 7a831badaa43347fa717718c9669f617bb5949e4. The end result should be the same as what you have here.\n\nI also chose `schema` instead of `db_schema`. `db_table` is a holdover from Django, but going forward I'd like to switch it to just `table`.\n\nThanks for your work. Additionally, if you'd like to submit code in the future, please shoot for pep8 and 79-char lines.\n", "I didn't receive your comment. I will try to follow the 79-char lines rule ;) (I already tend to respect PEP8)\n" ]
"2014-01-28T00:11:56"
"2014-06-16T14:18:53"
"2014-01-29T02:45:43"
CONTRIBUTOR
null
Added db_schema do Model meta options. I've refactored Entity to skip empty strings (e.g. when db_schema is empty or None)
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/291/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/291/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/291", "html_url": "https://github.com/coleifer/peewee/pull/291", "diff_url": "https://github.com/coleifer/peewee/pull/291.diff", "patch_url": "https://github.com/coleifer/peewee/pull/291.patch", "merged_at": null }
https://api.github.com/repos/coleifer/peewee/issues/290
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/290/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/290/comments
https://api.github.com/repos/coleifer/peewee/issues/290/events
https://github.com/coleifer/peewee/issues/290
26,213,312
MDU6SXNzdWUyNjIxMzMxMg==
290
Sub-select in from clause
{ "login": "coleifer", "id": 119974, "node_id": "MDQ6VXNlcjExOTk3NA==", "avatar_url": "https://avatars.githubusercontent.com/u/119974?v=4", "gravatar_id": "", "url": "https://api.github.com/users/coleifer", "html_url": "https://github.com/coleifer", "followers_url": "https://api.github.com/users/coleifer/followers", "following_url": "https://api.github.com/users/coleifer/following{/other_user}", "gists_url": "https://api.github.com/users/coleifer/gists{/gist_id}", "starred_url": "https://api.github.com/users/coleifer/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/coleifer/subscriptions", "organizations_url": "https://api.github.com/users/coleifer/orgs", "repos_url": "https://api.github.com/users/coleifer/repos", "events_url": "https://api.github.com/users/coleifer/events{/privacy}", "received_events_url": "https://api.github.com/users/coleifer/received_events", "type": "User", "site_admin": false }
[ { "id": 191751, "node_id": "MDU6TGFiZWwxOTE3NTE=", "url": "https://api.github.com/repos/coleifer/peewee/labels/Feature", "name": "Feature", "color": "02e10c", "default": false, "description": null } ]
closed
false
null
[]
null
[ "peewee's APIs are geared towards selecting from a table. `Model.select()` implies that you are selecting from the table represented by `Model` and want to be returned `Model` instances (excepting special cases like `.scalar()`, `.aggregate()`, `.tuples()`, `.dicts()`).\n\nI haven't really put much effort into making it work with a sub-select in the from clause, partially because it doesn't fit very well into the rubric of returning model instances. I see the value of sub-selects, just haven't built it out yet.\n\nI think it'd be a good feature so I'll look into how to handle this.\n", "I believe the commit I just pushed 22ce07c will make it possible to achieve the queries you've listed. Take a look at the included testcase. I'm still not sure this is going to be a flexible enough solution to handle some of the other cases that come to mind, though. Particularly to select from multiple tables and join in the where clause.\n" ]
"2014-01-24T01:20:14"
"2014-01-27T15:17:13"
"2014-01-27T15:17:13"
OWNER
null
I'm using peewee2.1 with python3.3 and an sqlite3.7 database. I want to perform certain SELECT queries in which: I first select some aggregate (count, sum), grouping by some id column; then I then select from the results of (1), aggregating over its aggregate. For example, I want in some cases to count the number of rows in (1) that have each aggregated value. My database has an 'Event' table with 1 record per event, and a 'Ticket' table with 1..N tickets per event. Each ticket record contains the event's id as a foreign key. Each ticket also contains a 'seats' column that specifies the number of seats purchased. (A "ticket" is really best thought of as a purchase transaction for 1 or more seats at the event.) Below are two examples of working SQLite queries of this sort that give me the desired results: ``` sql SELECT ev_tix, count(1) AS ev_tix_n FROM (SELECT count(1) AS ev_tix FROM ticket GROUP BY event_id) GROUP BY ev_tix ``` ``` sql SELECT seat_tot, count(1) AS seat_tot_n FROM (SELECT sum(seats) AS seat_tot FROM ticket GROUP BY event_id) GROUP BY seat_tot ``` I can execute these through peewee as raw queries, but I don't know how to do them using peewee directly. Specifically, I don't know how to select on the inner query's aggregate (count or sum) when specifying the outer query. I can of course specify an alias for that aggregate, but it seems I can't use that alias in the outer query. Is it in fact possible to do these selects without relying on raw queries? If so, how? Note that I ran into a separate problem conducting these through peewee as raw queries when I updgraded from peewee 2.1.5 to 2.1.7. You can see my separate post about that: https://groups.google.com/forum/#!topic/peewee-orm/ZIXEJzTFxxY. Thanks for your help!
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/290/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/290/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/289
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/289/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/289/comments
https://api.github.com/repos/coleifer/peewee/issues/289/events
https://github.com/coleifer/peewee/issues/289
25,959,277
MDU6SXNzdWUyNTk1OTI3Nw==
289
simple functional way to create models
{ "login": "leliel12", "id": 299010, "node_id": "MDQ6VXNlcjI5OTAxMA==", "avatar_url": "https://avatars.githubusercontent.com/u/299010?v=4", "gravatar_id": "", "url": "https://api.github.com/users/leliel12", "html_url": "https://github.com/leliel12", "followers_url": "https://api.github.com/users/leliel12/followers", "following_url": "https://api.github.com/users/leliel12/following{/other_user}", "gists_url": "https://api.github.com/users/leliel12/gists{/gist_id}", "starred_url": "https://api.github.com/users/leliel12/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/leliel12/subscriptions", "organizations_url": "https://api.github.com/users/leliel12/orgs", "repos_url": "https://api.github.com/users/leliel12/repos", "events_url": "https://api.github.com/users/leliel12/events{/privacy}", "received_events_url": "https://api.github.com/users/leliel12/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Thanks for your interest in peewee and for sharing your code. I'm not sure this belongs as a github issue, as I use this to track bugs and new features, as opposed to snippets.\n" ]
"2014-01-21T01:42:54"
"2014-01-21T01:58:14"
"2014-01-21T01:58:10"
NONE
null
I actually working on tool for generate "dimension tables" for pentaho. I write this simple snippet for create models in more functional way. ``` python #!/usr/bin/env python # -*- coding: utf-8 -*- from peewee import * def create_model(model_name, supercls=(Model,), meta={}, **fields): """Create a model in functional way This 2 codes are equivalent >>> db = SqliteDatabase("foo.db") >>> class MyModel(Model): ... name = TextField() ... flag = BooleanField() ... ... class Meta: ... database = db >>> db = SqliteDatabase("foo.db") >>> MyModel = create_model("MyModel", ... meta={"database": db}, ... name=TextField(), ... flag=Booleanfield() ...) """ fields["Meta"] = type("Meta", (), meta) model = type(model_name, supercls, fields) return model ``` Maybe it will be useful for another developers to merge inside peewee (i replace sqlalchemy with this fragment of code)
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/289/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/289/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/288
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/288/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/288/comments
https://api.github.com/repos/coleifer/peewee/issues/288/events
https://github.com/coleifer/peewee/issues/288
25,894,886
MDU6SXNzdWUyNTg5NDg4Ng==
288
Use of super on old style class `Model`
{ "login": "soasme", "id": 369081, "node_id": "MDQ6VXNlcjM2OTA4MQ==", "avatar_url": "https://avatars.githubusercontent.com/u/369081?v=4", "gravatar_id": "", "url": "https://api.github.com/users/soasme", "html_url": "https://github.com/soasme", "followers_url": "https://api.github.com/users/soasme/followers", "following_url": "https://api.github.com/users/soasme/following{/other_user}", "gists_url": "https://api.github.com/users/soasme/gists{/gist_id}", "starred_url": "https://api.github.com/users/soasme/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/soasme/subscriptions", "organizations_url": "https://api.github.com/users/soasme/orgs", "repos_url": "https://api.github.com/users/soasme/repos", "events_url": "https://api.github.com/users/soasme/events{/privacy}", "received_events_url": "https://api.github.com/users/soasme/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I thought `Model` _was_ a new-style class?\n", "Oops, it seems that pyflake does not have enough intelligence to recognize these styles:\n\n``` python\ndef with_metaclass(meta, base=object):\n return meta(\"NewBase\", (base,), {})\n\nclass BaseModel(type):\n def __new__(cls, name, bases, attrs):\n return super(BaseModel, cls).__new__(cls, name, bases, attrs)\n\nclass Model(with_metaclass(BaseModel)):\n def save(self):\n pass\n\nclass MyModel(Model):\n def save(self): # [E1002, MyModel.save] Use of super on an old style class\n super(MyModel, self).save()\n```\n" ]
"2014-01-20T02:16:22"
"2014-01-20T03:21:07"
"2014-01-20T03:21:07"
CONTRIBUTOR
null
I got an pyflake error on overriding `Model#save` method: > [E1002, MyModel.save] Use of super on an old style class Here is the example: ``` python # -*- coding: utf-8 -*- from peewee import Model class MyModel(Model): def save(self, *args, **kw): return super(MyModel, self).save(*args, **kw) a = MyModel() print MyModel.mro() # [<class '__main__.MyModel'>, <class 'peewee.Model'>, <class 'peewee.NewBase'>, <type 'object'>] ``` Is it possible to turn `Model` class to a `new-style` class?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/288/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/288/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/287
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/287/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/287/comments
https://api.github.com/repos/coleifer/peewee/issues/287/events
https://github.com/coleifer/peewee/issues/287
25,736,072
MDU6SXNzdWUyNTczNjA3Mg==
287
postgresql: invalid last insert id when setting id manually
{ "login": "appetito", "id": 557573, "node_id": "MDQ6VXNlcjU1NzU3Mw==", "avatar_url": "https://avatars.githubusercontent.com/u/557573?v=4", "gravatar_id": "", "url": "https://api.github.com/users/appetito", "html_url": "https://github.com/appetito", "followers_url": "https://api.github.com/users/appetito/followers", "following_url": "https://api.github.com/users/appetito/following{/other_user}", "gists_url": "https://api.github.com/users/appetito/gists{/gist_id}", "starred_url": "https://api.github.com/users/appetito/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/appetito/subscriptions", "organizations_url": "https://api.github.com/users/appetito/orgs", "repos_url": "https://api.github.com/users/appetito/repos", "events_url": "https://api.github.com/users/appetito/events{/privacy}", "received_events_url": "https://api.github.com/users/appetito/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "> may be we must use \"INSERT **\\* RETURNING id\"?\n\nThat is a postgres feature, unfortunately it won't work for Sqlite or MySQL... Setting an auto-incrementing ID manually is frowned on, but if you are bulk-loading data or for some reason need to control the ids, see these docs for some tips:\n\nhttp://peewee.readthedocs.org/en/latest/peewee/cookbook.html#bulk-loading-data-or-manually-specifying-primary-keys\n" ]
"2014-01-16T16:14:38"
"2014-01-16T16:20:14"
"2014-01-16T16:20:14"
NONE
null
``` In [17]: cat = Category.create(name='a') In [18]: cat.id Out[18]: 1L In [19]: cat = Category.create(name='b') In [21]: cat.id Out[21]: 2L In [22]: cat = Category.create(name='c', id=100) In [23]: cat.id Out[23]: 2L ========= select * from categories; id | parent_id | name -----+-----------+------ 1 | | a 2 | | b 100 | | c (3 rows) ``` may be we must use "INSERT **\* RETURNING id"?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/287/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/287/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/286
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/286/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/286/comments
https://api.github.com/repos/coleifer/peewee/issues/286/events
https://github.com/coleifer/peewee/pull/286
25,727,372
MDExOlB1bGxSZXF1ZXN0MTE1NzkyMDQ=
286
fix #281
{ "login": "appetito", "id": 557573, "node_id": "MDQ6VXNlcjU1NzU3Mw==", "avatar_url": "https://avatars.githubusercontent.com/u/557573?v=4", "gravatar_id": "", "url": "https://api.github.com/users/appetito", "html_url": "https://github.com/appetito", "followers_url": "https://api.github.com/users/appetito/followers", "following_url": "https://api.github.com/users/appetito/following{/other_user}", "gists_url": "https://api.github.com/users/appetito/gists{/gist_id}", "starred_url": "https://api.github.com/users/appetito/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/appetito/subscriptions", "organizations_url": "https://api.github.com/users/appetito/orgs", "repos_url": "https://api.github.com/users/appetito/repos", "events_url": "https://api.github.com/users/appetito/events{/privacy}", "received_events_url": "https://api.github.com/users/appetito/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Fixed in 3b8048d. Nice work debugging, thanks for the fix!\n" ]
"2014-01-16T14:16:09"
"2014-06-25T06:45:21"
"2014-01-16T16:04:50"
NONE
null
my try to fix #281 i am debug this script on my database and see that column order in the `columns` and in the `curs.description` does not match.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/286/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/286/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/286", "html_url": "https://github.com/coleifer/peewee/pull/286", "diff_url": "https://github.com/coleifer/peewee/pull/286.diff", "patch_url": "https://github.com/coleifer/peewee/pull/286.patch", "merged_at": null }
https://api.github.com/repos/coleifer/peewee/issues/285
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/285/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/285/comments
https://api.github.com/repos/coleifer/peewee/issues/285/events
https://github.com/coleifer/peewee/pull/285
25,703,589
MDExOlB1bGxSZXF1ZXN0MTE1NjU5Mjg=
285
Docs for `is_dirty` and `dirty_fields`.
{ "login": "soasme", "id": 369081, "node_id": "MDQ6VXNlcjM2OTA4MQ==", "avatar_url": "https://avatars.githubusercontent.com/u/369081?v=4", "gravatar_id": "", "url": "https://api.github.com/users/soasme", "html_url": "https://github.com/soasme", "followers_url": "https://api.github.com/users/soasme/followers", "following_url": "https://api.github.com/users/soasme/following{/other_user}", "gists_url": "https://api.github.com/users/soasme/gists{/gist_id}", "starred_url": "https://api.github.com/users/soasme/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/soasme/subscriptions", "organizations_url": "https://api.github.com/users/soasme/orgs", "repos_url": "https://api.github.com/users/soasme/repos", "events_url": "https://api.github.com/users/soasme/events{/privacy}", "received_events_url": "https://api.github.com/users/soasme/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[]
"2014-01-16T05:02:38"
"2014-06-23T15:14:36"
"2014-01-16T16:34:13"
CONTRIBUTOR
null
Some trivial docs.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/285/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/285/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/285", "html_url": "https://github.com/coleifer/peewee/pull/285", "diff_url": "https://github.com/coleifer/peewee/pull/285.diff", "patch_url": "https://github.com/coleifer/peewee/pull/285.patch", "merged_at": "2014-01-16T16:34:13" }
https://api.github.com/repos/coleifer/peewee/issues/284
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/284/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/284/comments
https://api.github.com/repos/coleifer/peewee/issues/284/events
https://github.com/coleifer/peewee/pull/284
25,702,436
MDExOlB1bGxSZXF1ZXN0MTE1NjUzMDY=
284
Model should be prepared after creation.
{ "login": "soasme", "id": 369081, "node_id": "MDQ6VXNlcjM2OTA4MQ==", "avatar_url": "https://avatars.githubusercontent.com/u/369081?v=4", "gravatar_id": "", "url": "https://api.github.com/users/soasme", "html_url": "https://github.com/soasme", "followers_url": "https://api.github.com/users/soasme/followers", "following_url": "https://api.github.com/users/soasme/following{/other_user}", "gists_url": "https://api.github.com/users/soasme/gists{/gist_id}", "starred_url": "https://api.github.com/users/soasme/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/soasme/subscriptions", "organizations_url": "https://api.github.com/users/soasme/orgs", "repos_url": "https://api.github.com/users/soasme/repos", "events_url": "https://api.github.com/users/soasme/events{/privacy}", "received_events_url": "https://api.github.com/users/soasme/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Good point, thanks!\n" ]
"2014-01-16T04:16:10"
"2014-07-06T01:50:35"
"2014-01-16T04:20:25"
CONTRIBUTOR
null
It's weird that prepared just happened after select query.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/284/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/284/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/284", "html_url": "https://github.com/coleifer/peewee/pull/284", "diff_url": "https://github.com/coleifer/peewee/pull/284.diff", "patch_url": "https://github.com/coleifer/peewee/pull/284.patch", "merged_at": "2014-01-16T04:20:25" }
https://api.github.com/repos/coleifer/peewee/issues/283
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/283/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/283/comments
https://api.github.com/repos/coleifer/peewee/issues/283/events
https://github.com/coleifer/peewee/pull/283
25,701,432
MDExOlB1bGxSZXF1ZXN0MTE1NjQ4MDU=
283
Dirty Flag
{ "login": "soasme", "id": 369081, "node_id": "MDQ6VXNlcjM2OTA4MQ==", "avatar_url": "https://avatars.githubusercontent.com/u/369081?v=4", "gravatar_id": "", "url": "https://api.github.com/users/soasme", "html_url": "https://github.com/soasme", "followers_url": "https://api.github.com/users/soasme/followers", "following_url": "https://api.github.com/users/soasme/following{/other_user}", "gists_url": "https://api.github.com/users/soasme/gists{/gist_id}", "starred_url": "https://api.github.com/users/soasme/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/soasme/subscriptions", "organizations_url": "https://api.github.com/users/soasme/orgs", "repos_url": "https://api.github.com/users/soasme/repos", "events_url": "https://api.github.com/users/soasme/events{/privacy}", "received_events_url": "https://api.github.com/users/soasme/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Nice, thanks for this.\n" ]
"2014-01-16T03:43:45"
"2014-06-29T11:07:49"
"2014-01-16T04:21:41"
CONTRIBUTOR
null
Update all fields on saving will increase probability of `lost update`. Such as: TransactionA do not update username field TransactionB update username field TransactionB save TransactionA save. then we will lost username modification in TransactionB. But if we just update necessary fields without username in TransactionA, it's okay. we can easily call `model.save(only=model.dirty_fields)` to fix that.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/283/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/283/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/283", "html_url": "https://github.com/coleifer/peewee/pull/283", "diff_url": "https://github.com/coleifer/peewee/pull/283.diff", "patch_url": "https://github.com/coleifer/peewee/pull/283.patch", "merged_at": "2014-01-16T04:21:41" }
https://api.github.com/repos/coleifer/peewee/issues/282
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/282/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/282/comments
https://api.github.com/repos/coleifer/peewee/issues/282/events
https://github.com/coleifer/peewee/issues/282
25,588,301
MDU6SXNzdWUyNTU4ODMwMQ==
282
Support postgres column type 'json'
{ "login": "extesy", "id": 65872, "node_id": "MDQ6VXNlcjY1ODcy", "avatar_url": "https://avatars.githubusercontent.com/u/65872?v=4", "gravatar_id": "", "url": "https://api.github.com/users/extesy", "html_url": "https://github.com/extesy", "followers_url": "https://api.github.com/users/extesy/followers", "following_url": "https://api.github.com/users/extesy/following{/other_user}", "gists_url": "https://api.github.com/users/extesy/gists{/gist_id}", "starred_url": "https://api.github.com/users/extesy/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/extesy/subscriptions", "organizations_url": "https://api.github.com/users/extesy/orgs", "repos_url": "https://api.github.com/users/extesy/repos", "events_url": "https://api.github.com/users/extesy/events{/privacy}", "received_events_url": "https://api.github.com/users/extesy/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "@extesy -- peewee does not currently come with a JSON field type (if it did, it would be part of `playhouse.postgres_ext`). It sounds like you may have started an implementation of one, otherwise I'm not sure how you have been using the field? Additionally, are you registering a json adapter or using any psycopg2 APIs?\n\nThe more information you can provide the better, thanks!\n", "The only thing I came up so far is to override default psycopg2's json handler by `psycopg2.extras.register_default_json(loads=lambda x: x)` but it looks like hack, not a normal approach to the problem. I've been using peewee only and this workaround is the only case where I use psycopg2 directly.\n\nI think you are right and new JsonField needs to be added to playhouse.postgres_ext, similar to existing HStoreField, etc.\n", "I've added a _very minimal_ Json field. I plan on adding support for the `->` and `->>` operators, but since these are chainable I'd like to think about the implementation a bit.\n", "633e5307d0fe19b3e299f2d6c5d7cd3ee1fd24ca\n" ]
"2014-01-14T17:01:38"
"2014-01-15T04:50:17"
"2014-01-15T04:50:17"
NONE
null
Currently there is a problem with this column type because psycopg always unpacks json column data into a dict during load, and packs it during save (see _json.py file from psycopg2). When peewee tries to interpret this dict as text, this causes python to serialize it, and this serialization makes it json-incompatible now so you can't save it back anymore. Two possible alternatives are: either do what psycopg is doing and always treat this column as dict instead of string, or wrap it into json.dumps before exposing to the user and json.loads before passing to psycopg level. I'd personally prefer first option - seems cleaner.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/282/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/282/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/281
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/281/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/281/comments
https://api.github.com/repos/coleifer/peewee/issues/281/events
https://github.com/coleifer/peewee/issues/281
25,522,759
MDU6SXNzdWUyNTUyMjc1OQ==
281
pwiz.py and postgres - invalid field types
{ "login": "appetito", "id": 557573, "node_id": "MDQ6VXNlcjU1NzU3Mw==", "avatar_url": "https://avatars.githubusercontent.com/u/557573?v=4", "gravatar_id": "", "url": "https://api.github.com/users/appetito", "html_url": "https://github.com/appetito", "followers_url": "https://api.github.com/users/appetito/followers", "following_url": "https://api.github.com/users/appetito/following{/other_user}", "gists_url": "https://api.github.com/users/appetito/gists{/gist_id}", "starred_url": "https://api.github.com/users/appetito/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/appetito/subscriptions", "organizations_url": "https://api.github.com/users/appetito/orgs", "repos_url": "https://api.github.com/users/appetito/repos", "events_url": "https://api.github.com/users/appetito/events{/privacy}", "received_events_url": "https://api.github.com/users/appetito/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I tested this by hand. I typed in some models to recreate your schema (what pwiz _should_ have generated), then created the tables and ran pwiz against them.\n\n``` python\n# Models I typed in by hand:\nclass Category(BaseModel):\n name = CharField(max_length=500)\n parent = ForeignKeyField('self', null=True)\n\n class Meta:\n db_table = 'categories'\n\nclass Product(BaseModel):\n name = CharField(max_length=500)\n category = ForeignKeyField(Category)\n type = CharField(max_length=10)\n price = IntegerField()\n bid = IntegerField()\n available = BooleanField()\n description = TextField()\n picture = CharField(max_length=500)\n author = CharField(max_length=500)\n publisher = CharField(max_length=500)\n year = IntegerField()\n isbn = CharField(max_length=50)\n binding = CharField(max_length=500)\n page_extent = IntegerField()\n\n class Meta:\n db_table = 'products'\n```\n\nHere is what postgres shows me:\n\n```\n Table \"public.categories\"\n Column | Type | Modifiers \n-----------+------------------------+---------------------------------------------------------\n id | integer | not null default nextval('categories_id_seq'::regclass)\n name | character varying(500) | not null\n parent_id | integer | \nIndexes:\n \"categories_pkey\" PRIMARY KEY, btree (id)\n \"categories_parent_id\" btree (parent_id)\nForeign-key constraints:\n \"categories_parent_id_fkey\" FOREIGN KEY (parent_id) REFERENCES categories(id)\nReferenced by:\n TABLE \"categories\" CONSTRAINT \"categories_parent_id_fkey\" FOREIGN KEY (parent_id) REFERENCES categories(id)\n TABLE \"products\" CONSTRAINT \"products_category_id_fkey\" FOREIGN KEY (category_id) REFERENCES categories(id)\n\n Table \"public.products\"\n Column | Type | Modifiers \n-------------+------------------------+-------------------------------------------------------\n id | integer | not null default nextval('products_id_seq'::regclass)\n name | character varying(500) | not null\n category_id | integer | not null\n type | character varying(10) | not null\n price | integer | not null\n bid | integer | not null\n available | boolean | not null\n description | text | not null\n picture | character varying(500) | not null\n author | character varying(500) | not null\n publisher | character varying(500) | not null\n year | integer | not null\n isbn | character varying(50) | not null\n binding | character varying(500) | not null\n page_extent | integer | not null\nIndexes:\n \"products_pkey\" PRIMARY KEY, btree (id)\n \"products_category_id\" btree (category_id)\nForeign-key constraints:\n \"products_category_id_fkey\" FOREIGN KEY (category_id) REFERENCES categories(id)\n```\n\nHere is what I get when I run pwiz against the generated tables:\n\n``` python\nclass Categories(BaseModel):\n name = CharField(max_length=500)\n parent = ForeignKeyField(null=True, db_column='parent_id', rel_model='self')\n\n class Meta:\n db_table = 'categories'\n\nclass Products(BaseModel):\n author = CharField(max_length=500)\n available = BooleanField()\n bid = IntegerField()\n binding = CharField(max_length=500)\n category = ForeignKeyField(db_column='category_id', rel_model=Categories)\n description = TextField()\n isbn = CharField(max_length=50)\n name = CharField(max_length=500)\n page_extent = IntegerField()\n picture = CharField(max_length=500)\n price = IntegerField()\n publisher = CharField(max_length=500)\n type = CharField(max_length=10)\n year = IntegerField()\n\n class Meta:\n db_table = 'products'\n```\n\nAs you can see, the generated code looks correct. Can you dump your schema? I'd like to see in more detail what CREATE statements were used to generate those models. Also could you include your postgres and psycopg2 versions?\n", "Also, could you run the following query and paste the output?\n\n``` sql\nselect oid, typname from pg_type where typname not like '\\_%' order by oid limit 50;\n```\n", "```\nCREATE TABLE categories(\n id SERIAL PRIMARY KEY,\n parent_id INTEGER,\n name VARCHAR(500),\n FOREIGN KEY (parent_id) REFERENCES categories\n);\n\n\nCREATE TABLE products(\n id BIGSERIAL PRIMARY KEY,\n name VARCHAR(500),\n category_id INTEGER,\n type VARCHAR(10),\n price INTEGER,\n bid INTEGER,\n available BOOLEAN DEFAULT false,\n description TEXT,\n picture VARCHAR(500),\n author VARCHAR(500),\n publisher VARCHAR(500),\n year INTEGER,\n isbn VARCHAR(50),\n binding VARCHAR(500),\n page_extent INTEGER,\n FOREIGN KEY (category_id) REFERENCES categories\n);\n```\n\n```\nselect oid, typname from pg_type where typname not like '\\_%' order by oid limit 50;\n\n oid | typname \n------+--------------\n 16 | bool\n 17 | bytea\n 18 | char\n 19 | name\n 20 | int8\n 21 | int2\n 22 | int2vector\n 23 | int4\n 24 | regproc\n 25 | text\n 26 | oid\n 27 | tid\n 28 | xid\n 29 | cid\n 30 | oidvector\n 71 | pg_type\n 75 | pg_attribute\n 81 | pg_proc\n 83 | pg_class\n 142 | xml\n 194 | pg_node_tree\n 210 | smgr\n 600 | point\n 601 | lseg\n 602 | path\n 603 | box\n 604 | polygon\n 628 | line\n 650 | cidr\n 700 | float4\n 701 | float8\n 702 | abstime\n 703 | reltime\n 704 | tinterval\n 705 | unknown\n 718 | circle\n 790 | money\n 829 | macaddr\n 869 | inet\n 1033 | aclitem\n 1042 | bpchar\n 1043 | varchar\n 1082 | date\n 1083 | time\n 1114 | timestamp\n 1184 | timestamptz\n 1186 | interval\n 1248 | pg_database\n 1266 | timetz\n 1560 | bit\n(50 rows)\n```\n\npsycopg2==2.5.2\npostgres (PostgreSQL) 9.1.11\n", "My list matches yours (with the exception of the JSON type since I'm using 9.3). Not sure, do you have any ideas what might be going on? It's extra strange that some of the varchar() columns are recognized correctly (products.name) while others are not (products.author).\n\nDo you have any other tables in this database? Is there any chance you could give me a dump of the schema only?\n", "Using the `CREATE TABLE` statements you provided, I created the tables locally and ran pwiz -- the output looked correct:\n\n``` python\nclass Categories(BaseModel):\n name = CharField(max_length=500, null=True)\n parent = ForeignKeyField(null=True, db_column='parent_id', rel_model='self')\n\n class Meta:\n db_table = 'categories'\n\nclass Products(BaseModel):\n author = CharField(max_length=500, null=True)\n available = BooleanField(null=True)\n bid = IntegerField(null=True)\n binding = CharField(max_length=500, null=True)\n category = ForeignKeyField(null=True, db_column='category_id', rel_model=Categories)\n description = TextField(null=True)\n isbn = CharField(max_length=50, null=True)\n name = CharField(max_length=500, null=True)\n page_extent = IntegerField(null=True)\n picture = CharField(max_length=500, null=True)\n price = IntegerField(null=True)\n publisher = CharField(max_length=500, null=True)\n type = CharField(max_length=10, null=True)\n year = IntegerField(null=True)\n\n class Meta:\n db_table = 'products'\n```\n", "i must look closer, thanks\n", "Please reopen if you find anything or have any new info.\n" ]
"2014-01-13T19:46:07"
"2014-01-16T14:16:09"
"2014-01-15T14:02:20"
NONE
null
## Db schema is: ``` Table "public.categories" Column | Type | Modifiers -----------+------------------------+--------------------------------------------------------- id | integer | not null default nextval('categories_id_seq'::regclass) parent_id | integer | name | character varying(500) | Table "public.products" Column | Type | Modifiers -------------+------------------------+------------------------------------------------------- id | bigint | not null default nextval('products_id_seq'::regclass) name | character varying(500) | category_id | integer | type | character varying(10) | price | integer | bid | integer | available | boolean | default false description | text | picture | character varying(500) | author | character varying(500) | publisher | character varying(500) | year | integer | isbn | character varying(50) | binding | character varying(500) | page_extent | integer | ``` ## Models made by pwiz ``` class Categories(BaseModel): name = IntegerField(null=True) parent = ForeignKeyField(null=True, db_column='parent_id', rel_model='self') class Meta: db_table = 'categories' class Products(BaseModel): author = IntegerField(null=True) available = CharField(null=True) bid = CharField(null=True) binding = CharField(max_length=500, null=True) category = ForeignKeyField(null=True, db_column='category_id', rel_model=Categories) description = TextField(null=True) isbn = IntegerField(null=True) name = CharField(max_length=500, null=True) page_extent = BigIntegerField(null=True) picture = BooleanField(null=True) price = CharField(null=True) publisher = IntegerField(null=True) type = IntegerField(null=True) year = CharField(null=True) class Meta: db_table = 'products' ``` bloody mess peewee==2.1.7
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/281/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/281/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/280
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/280/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/280/comments
https://api.github.com/repos/coleifer/peewee/issues/280/events
https://github.com/coleifer/peewee/issues/280
25,469,481
MDU6SXNzdWUyNTQ2OTQ4MQ==
280
Foreign key attribute access in join
{ "login": "bndr", "id": 1145456, "node_id": "MDQ6VXNlcjExNDU0NTY=", "avatar_url": "https://avatars.githubusercontent.com/u/1145456?v=4", "gravatar_id": "", "url": "https://api.github.com/users/bndr", "html_url": "https://github.com/bndr", "followers_url": "https://api.github.com/users/bndr/followers", "following_url": "https://api.github.com/users/bndr/following{/other_user}", "gists_url": "https://api.github.com/users/bndr/gists{/gist_id}", "starred_url": "https://api.github.com/users/bndr/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/bndr/subscriptions", "organizations_url": "https://api.github.com/users/bndr/orgs", "repos_url": "https://api.github.com/users/bndr/repos", "events_url": "https://api.github.com/users/bndr/events{/privacy}", "received_events_url": "https://api.github.com/users/bndr/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "When you access the `lat` and `lon` attrs, you need to do so from the `Place` model. You need to wrap your comparisons in parens because of operator precedence. Lastly, the usage of the `math` module won't work at all the way you're trying to use it. You will need to use database functions.\n\nI did not test the code below, but hopefully this helps get you on the right track:\n\n``` python\nToPlace = Place.alias()\nFromPlace = Place.alias()\ntrips = (\n Trip\n .select()\n .join(ToPlace, on=(Trip.to_place == ToPlace.id))\n .switch(Trip)\n .join(FromPlace, on=(Trip.from_place == FromPlace.id))\n .where(\n (Trip.date >= date) &\n (Trip.status == 'active') &\n (fn.Acos(\n (fn.Cos(fn.Radians(FromPlace.lat)) * fn.Cos(rLat) * fn.Cos(fn.Radians(FromPlace.lon) - rLon)) +\n (fn.Sin(fn.Radians(FromPlace.lat)) * fn.Sin(rLat)) * earth_radius)) < radius))\n```\n", "Thanks! Your answer helped a lot! I finally got it working.\n\nI'll just write some keywords here, so that people looking for the same thing, could find it: peewee great circle distance haversine formula, two gps points\n" ]
"2014-01-12T20:45:24"
"2014-01-13T19:43:55"
"2014-01-13T15:31:57"
CONTRIBUTOR
null
Hi! So I've run in to a bit of a problem. I have models: ``` class Trip(AbstractModel): date = DateTimeField() from_place = ForeignKeyField(Place, related_name="place_from") to_place = ForeignKeyField(Place, related_name="place_to") ``` ``` class Place(AbstractModel): name = CharField(unique=True) lat = FloatField() lon = FloatField() type_ = CharField() ``` And I need to calculate the great circle distance formula (Get the places around the from_place with predefined radius) ``` rLat = math.radians(from_.lat) rLon = math.radians(from_.lon) earth_radius = 6371 # km # Great circle distance formula trips = Trip.select().join(Place).where( Trip.to_place == to_.id & Trip.date >= date & Trip.status == "active").where( (math.acos( math.cos(math.radians(Trip.from_place.lat)) * math.cos( rLat) * math.cos(math.radians(Trip.from_place.lon) - rLon) + math.sin(math.radians(Trip.from_place.lat)) * math.sin(rLat)) * earth_radius) < radius) ``` The problem is that I can't access Trip.place_from.lat attribute. I get an error: `AttributeError: 'ForeignKeyField' object has no attribute 'lat'` Is there anyway to fix this/do this type of query? Or will I have to write this as raw SQL?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/280/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/280/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/279
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/279/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/279/comments
https://api.github.com/repos/coleifer/peewee/issues/279/events
https://github.com/coleifer/peewee/issues/279
25,437,787
MDU6SXNzdWUyNTQzNzc4Nw==
279
Slow queries
{ "login": "coleifer", "id": 119974, "node_id": "MDQ6VXNlcjExOTk3NA==", "avatar_url": "https://avatars.githubusercontent.com/u/119974?v=4", "gravatar_id": "", "url": "https://api.github.com/users/coleifer", "html_url": "https://github.com/coleifer", "followers_url": "https://api.github.com/users/coleifer/followers", "following_url": "https://api.github.com/users/coleifer/following{/other_user}", "gists_url": "https://api.github.com/users/coleifer/gists{/gist_id}", "starred_url": "https://api.github.com/users/coleifer/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/coleifer/subscriptions", "organizations_url": "https://api.github.com/users/coleifer/orgs", "repos_url": "https://api.github.com/users/coleifer/repos", "events_url": "https://api.github.com/users/coleifer/events{/privacy}", "received_events_url": "https://api.github.com/users/coleifer/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "You have multiple O(n) queries lurking in that loop. Every foreign key resolution (`row.test.name`, `row.component.n`) triggers as query.\n\nYou can accomplish this in O(1) queries (tested locally using sqlite). Try this:\n\n``` python\nrows = (\n Execution\n .select(\n Execution,\n Test,\n Component)\n .join(Test).switch(Execution)\n .join(Component))\n\nfor row in rows:\n print row.identifier, row.test.name, row.component.n, row.component.v\n```\n\nI tried to get it to \"pre-fetch\" the `kernel` and `tool` attributes, but this did not work as I intended...I'll look into that, but hopefully this should help speed up your query.\n", "Hey,\n\nhere is what I got:\n\n```\nIn [17]: data = db.Execution.select(db.Test,db.Result,db.Arch,db.Component,db.Phase,db.Tester).join(db.Test).switch(db.Execution).join(db.Result).switch(db.Execution).join(db.Arch).switch(db.Execution).join(db.Component).switch(db.Execution).join(db.Phase).switch(db.Execution).join(db.Tester).switch(db.Execution)\n\nIn [18]: for row in data:\n ....: print row.identifier, row.test.name, row.component.n, row.component.v\n ....: \n ....: \n---------------------------------------------------------------------------\nKeyError Traceback (most recent call last)\n\n/home/tpelka/workspace/desktopqe-resultsDB/<ipython console> in <module>()\n\n/usr/lib/python2.6/site-packages/peewee.pyc in next(self)\n 1190 return inst\n 1191 \n-> 1192 obj = self.iterate()\n 1193 self._result_cache.append(obj)\n 1194 self.__ct += 1\n\n/usr/lib/python2.6/site-packages/peewee.pyc in iterate(self)\n 1178 self.initialize(self.cursor.description)\n 1179 self._initialized = True\n-> 1180 return self.process_row(row)\n 1181 \n 1182 def iterator(self):\n\n/usr/lib/python2.6/site-packages/peewee.pyc in process_row(self, row)\n 1298 def process_row(self, row):\n 1299 collected = self.construct_instance(row)\n-> 1300 instances = self.follow_joins(collected)\n 1301 for i in instances:\n 1302 i.prepared()\n\n/usr/lib/python2.6/site-packages/peewee.pyc in follow_joins(self, collected)\n 1319 \n 1320 def follow_joins(self, collected):\n-> 1321 prepared = [collected[self.model]]\n 1322 for (lhs, attr, rhs) in self.join_map:\n 1323 inst = collected[lhs]\n\nKeyError: <class 'db.Execution'>\n```\n", "```\n<cleifer> i can't replicate b/c i don't have model definitions for phase, result or tester\n<cleifer> tpelka, ^^\n<tpelka> cleifer: let me send you the model and addtodb.py \n<tpelka> github?\n<tpelka> cleifer: can I attache files to github?\n<cleifer> make a gist then link it?\n<cleifer> that might b easiest\n<tpelka> grr Unfortunately we don't support that file type yet. Please use PNG, GIF, or JPG. \n<tpelka> https://gist.github.com/tompelka/8400960 = db.py\n<cleifer> thanks!\n<tpelka> https://gist.github.com/tompelka/8400976 = addtodb.py\n<tpelka> cleifer: in this case I should change memory to some sqlite file right?\n<cleifer> no worries\n```\n", "I modified your test code and was not able to replicate the error. The big change was to add `Execution` to the list of tables selected.\n\n``` python\nfrom peewee import *\nfrom peewee import create_model_tables\nfrom peewee import Expression\nimport datetime\nimport os\n\n# for\nOP_REGEXP = 'regexp'\n\n# server not defined, create it in memory\ndatabase = SqliteDatabase(':memory:')\n\n# model definitions -- the standard \"pattern\" is to define a base model class\n# that specifies which database to use. then, any subclasses will automatically\n# use the correct storage.\nclass BaseModel(Model):\n class Meta:\n database = database\n\n\n# test db table\nclass Test(BaseModel):\n parent = ForeignKeyField('self', related_name='children', null=True, cascade=True)\n name = TextField()\n\n\n# hw db table\nclass Hw(BaseModel):\n name = TextField()\n vendor = TextField()\n device = TextField()\n codec = TextField(default=\"\")\n\n\n# status db table\nclass Status(BaseModel):\n name = TextField()\n\n\n# result db table\nclass Result(BaseModel):\n status = ForeignKeyField(Status)\n num_passed = IntegerField()\n num_failed = IntegerField()\n num_skipped = IntegerField(null=True)\n\n\n# release db table\nclass Release(BaseModel):\n major = TextField()\n minor = TextField()\n is_zstream = BooleanField(default=False)\n\n\n# arch db table\nclass Arch(BaseModel):\n name = TextField()\n\n\n# component db table\nclass Component(BaseModel):\n n = TextField()\n v = TextField()\n r = TextField()\n rhel = ForeignKeyField(Release)\n\n\n# phase db table\nclass Phase(BaseModel):\n name = TextField()\n\n\n# tester db table\nclass Tester(BaseModel):\n login = TextField()\n full_name = TextField()\n\n\n# execution db table\nclass Execution(BaseModel):\n time = DateTimeField(default=datetime.datetime.now, help_text=\"Insert time\")\n log = TextField()\n identifier = TextField()\n tcmsID = TextField(null=True)\n beakerID = TextField(null=True)\n test = ForeignKeyField(Test)\n hw = ForeignKeyField(Hw, null=True)\n result = ForeignKeyField(Result)\n release = ForeignKeyField(Release)\n arch = ForeignKeyField(Arch)\n component = ForeignKeyField(Component, related_name='component_ver')\n kernel = ForeignKeyField(Component, related_name='kernel_ver', null=True)\n tool = ForeignKeyField(Component, related_name='tool_ver', null=True)\n phase = ForeignKeyField(Phase)\n tester = ForeignKeyField(Tester)\n note = TextField()\n is_valid = BooleanField(default=False)\n\n class Meta:\n order_by = ('time',)\n\ncreate_model_tables([Test, Hw, Result, Status, Release, Arch, Component, Phase, Tester, Execution])\n\nt1 = Test.create(name='t1')\nt2 = Test.create(name='t2')\nhw1 = Hw.create(name='hw1', vendor='', device='')\nhw2 = Hw.create(name='hw2', vendor='', device='')\nr1 = Release.create(major='1', minor='0')\nr2 = Release.create(major='2', minor='0')\na1 = Arch.create(name='a1')\na2 = Arch.create(name='a2')\nc1 = Component.create(n='c1', v='', r='', rhel=r1)\nc2 = Component.create(n='c2', v='', r='', rhel=r1)\nk1 = Component.create(n='k1', v='', r='', rhel=r1)\nk2 = Component.create(n='k2', v='', r='', rhel=r1)\no1 = Component.create(n='o1', v='', r='', rhel=r1)\no2 = Component.create(n='o2', v='', r='', rhel=r1)\np1 = Phase.create(name='p1')\np2 = Phase.create(name='p2')\nts1 = Tester.create(login='tester1', full_name='')\nts2 = Tester.create(login='tester2', full_name='')\ns1 = Status.create(name='s1')\ns2 = Status.create(name='s2')\nrs1 = Result.create(status=s1, num_passed=0, num_failed=0)\nrs2 = Result.create(status=s2, num_passed=0, num_failed=0)\n\nfor i in range(10):\n n1 = 'e%s' % i\n n2 = 'e%s' % (i + 10)\n Execution.create(\n log=n1,\n identifier=n1,\n test=t1,\n hw=hw1,\n result=rs1,\n arch=a1,\n release=r1,\n component=c1,\n kernel=k1,\n tool=o1,\n phase=p1,\n tester=ts1,\n note=n1)\n Execution.create(\n log=n2,\n identifier=n2,\n test=t2,\n hw=hw2,\n result=rs2,\n arch=a2,\n release=r2,\n component=c2,\n kernel=k2,\n tool=o2,\n phase=p2,\n tester=ts2,\n note=n2)\n\nimport logging\nlogger = logging.getLogger('peewee')\nlogger.setLevel(logging.DEBUG)\nlogger.addHandler(logging.StreamHandler())\n\nrows = (\n Execution\n .select(\n Execution,\n Test,\n Result,\n Arch,\n Component,\n Phase,\n Tester)\n .join(Test).switch(Execution)\n .join(Result).switch(Execution)\n .join(Arch).switch(Execution)\n .join(Component).switch(Execution)\n .join(Phase).switch(Execution)\n .join(Tester).switch(Execution))\n\nfor row in rows:\n print row.identifier, row.test.name, row.component.n, row.component.v\n```\n\nOutput:\n\n```\n('\nSELECT \n t1.\"id\", t1.\"time\", t1.\"log\", t1.\"identifier\", t1.\"tcmsID\", t1.\"beakerID\", t1.\"test_id\", t1.\"hw_id\", t1.\"result_id\", t1.\"release_id\", t1.\"arch_id\", t1.\"component_id\", t1.\"kernel_id\", t1.\"tool_id\", t1.\"phase_id\", t1.\"tester_id\", t1.\"note\", t1.\"is_valid\", \n t2.\"id\", t2.\"parent_id\", t2.\"name\", \n t3.\"id\", t3.\"status_id\", t3.\"num_passed\", t3.\"num_failed\", t3.\"num_skipped\", \n t4.\"id\", t4.\"name\", \n t5.\"id\", t5.\"n\", t5.\"v\", t5.\"r\", t5.\"rhel_id\", \n t6.\"id\", t6.\"name\", \n t7.\"id\", t7.\"login\", t7.\"full_name\" \nFROM \"execution\" AS t1 \nINNER JOIN \"test\" AS t2 ON (t1.\"test_id\" = t2.\"id\") \nINNER JOIN \"result\" AS t3 ON (t1.\"result_id\" = t3.\"id\") \nINNER JOIN \"arch\" AS t4 ON (t1.\"arch_id\" = t4.\"id\") \nINNER JOIN \"component\" AS t5 ON (t1.\"component_id\" = t5.\"id\") \nINNER JOIN \"phase\" AS t6 ON (t1.\"phase_id\" = t6.\"id\") \nINNER JOIN \"tester\" AS t7 ON (t1.\"tester_id\" = t7.\"id\") \nORDER BY t1.\"time\" ASC', [])\n\ne0 t1 c1 \ne10 t2 c2 \ne1 t1 c1 \ne11 t2 c2 \ne2 t1 c1 \ne12 t2 c2 \ne3 t1 c1 \ne13 t2 c2 \ne4 t1 c1 \ne14 t2 c2 \ne5 t1 c1 \ne15 t2 c2 \ne6 t1 c1 \ne16 t2 c2 \ne7 t1 c1 \ne17 t2 c2 \ne8 t1 c1 \ne18 t2 c2 \ne9 t1 c1 \ne19 t2 c2\n```\n", "@tompelka -- I added `Release` to the list of selected tables and joins it still works:\n\n``` python\nrows = (\n Execution\n .select(\n Execution,\n Test,\n Result,\n Release,\n Arch,\n Component,\n Phase,\n Tester)\n .join(Test).switch(Execution)\n .join(Result).switch(Execution)\n .join(Release).switch(Execution)\n .join(Arch).switch(Execution)\n .join(Component).switch(Execution)\n .join(Phase).switch(Execution)\n .join(Tester).switch(Execution))\n```\n\nYou mentioned in IRC that it was still slow...can you share the code you're using in the loop? Depending on what attributes you access you may be triggering more queries.\n" ]
"2014-01-11T04:58:51"
"2014-01-13T20:36:36"
"2014-01-13T20:36:36"
OWNER
null
Hi I have following issue with fetching data from MySQL. My app is based on initial peewee example (https://github.com/coleifer/peewee/blob/master/example/app.py). My db model (shorten): ``` python db.py --------------------------------- #!/usr/bin/env python # -*- coding: utf-8 -*- from peewee import * from peewee import Expression import datetime import ConfigParser import os # for OP_REGEXP = 'regexp' config = ConfigParser.ConfigParser() config.read('config.cfg') DB = config.get('database', 'db') HOST = config.get('database', 'host') USER = config.get('database', 'user') PASSWORD = config.get('database', 'password') DEBUG = int(os.getenv('RESULTS_DEBUG', 0)) == 1 # create a database instance -- our models will use this database to # persist information if DEBUG: database = SqliteDatabase(':memory:') else: database = MySQLDatabase(DB, autocommit=False, host=HOST, user=USER, passwd=PASSWORD) # model definitions -- the standard "pattern" is to define a base model class # that specifies which database to use. then, any subclasses will automatically # use the correct storage. class BaseModel(Model): class Meta: database = database # test db table class Test(BaseModel): parent = ForeignKeyField('self', related_name='children', null=True, cascade=True) name = TextField() # hw db table class Hw(BaseModel): name = TextField() vendor = TextField() device = TextField() codec = TextField(default="") # release db table class Release(BaseModel): major = TextField() minor = TextField() is_zstream = BooleanField(default=False) # arch db table class Arch(BaseModel): name = TextField() # component db table class Component(BaseModel): n = TextField() v = TextField() r = TextField() rhel = ForeignKeyField(Release) # execution db table class Execution(BaseModel): time = DateTimeField(default=datetime.datetime.now, help_text="Insert time") log = TextField() identifier = TextField() test = ForeignKeyField(Test) hw = ForeignKeyField(Hw, null=True) release = ForeignKeyField(Release) arch = ForeignKeyField(Arch) component = ForeignKeyField(Component, related_name='component_ver') kernel = ForeignKeyField(Component, related_name='kernel_ver', null=True) tool = ForeignKeyField(Component, related_name='tool_ver', null=True) note = TextField() class Meta: order_by = ('time',) EOF ----------------------------------------- ``` I have 21 records in execution table selecting all of them takes to long, like 30 sec. ``` python import db rows = db.Execution.select() for row in rows: print row.identifier, row.test.name, row.component.n, row.component.v ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/279/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/279/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/278
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/278/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/278/comments
https://api.github.com/repos/coleifer/peewee/issues/278/events
https://github.com/coleifer/peewee/pull/278
24,993,729
MDExOlB1bGxSZXF1ZXN0MTExOTU4OTg=
278
Use wraps decorator so we don't lose the identity of the decorated function
{ "login": "lucasmarshall", "id": 885074, "node_id": "MDQ6VXNlcjg4NTA3NA==", "avatar_url": "https://avatars.githubusercontent.com/u/885074?v=4", "gravatar_id": "", "url": "https://api.github.com/users/lucasmarshall", "html_url": "https://github.com/lucasmarshall", "followers_url": "https://api.github.com/users/lucasmarshall/followers", "following_url": "https://api.github.com/users/lucasmarshall/following{/other_user}", "gists_url": "https://api.github.com/users/lucasmarshall/gists{/gist_id}", "starred_url": "https://api.github.com/users/lucasmarshall/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/lucasmarshall/subscriptions", "organizations_url": "https://api.github.com/users/lucasmarshall/orgs", "repos_url": "https://api.github.com/users/lucasmarshall/repos", "events_url": "https://api.github.com/users/lucasmarshall/events{/privacy}", "received_events_url": "https://api.github.com/users/lucasmarshall/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Thanks!\n", "Sure thing.\n" ]
"2014-01-02T23:24:19"
"2014-07-06T01:50:38"
"2014-01-02T23:24:53"
CONTRIBUTOR
null
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/278/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/278/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/278", "html_url": "https://github.com/coleifer/peewee/pull/278", "diff_url": "https://github.com/coleifer/peewee/pull/278.diff", "patch_url": "https://github.com/coleifer/peewee/pull/278.patch", "merged_at": "2014-01-02T23:24:53" }
https://api.github.com/repos/coleifer/peewee/issues/277
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/277/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/277/comments
https://api.github.com/repos/coleifer/peewee/issues/277/events
https://github.com/coleifer/peewee/issues/277
24,913,702
MDU6SXNzdWUyNDkxMzcwMg==
277
where() calls are not chainable with update()
{ "login": "grantcox", "id": 186808, "node_id": "MDQ6VXNlcjE4NjgwOA==", "avatar_url": "https://avatars.githubusercontent.com/u/186808?v=4", "gravatar_id": "", "url": "https://api.github.com/users/grantcox", "html_url": "https://github.com/grantcox", "followers_url": "https://api.github.com/users/grantcox/followers", "following_url": "https://api.github.com/users/grantcox/following{/other_user}", "gists_url": "https://api.github.com/users/grantcox/gists{/gist_id}", "starred_url": "https://api.github.com/users/grantcox/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/grantcox/subscriptions", "organizations_url": "https://api.github.com/users/grantcox/orgs", "repos_url": "https://api.github.com/users/grantcox/repos", "events_url": "https://api.github.com/users/grantcox/events{/privacy}", "received_events_url": "https://api.github.com/users/grantcox/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Thank you so much for bringing this to my attention, you are absolutely right.\n" ]
"2013-12-31T07:21:23"
"2013-12-31T14:41:59"
"2013-12-31T14:41:59"
NONE
null
The documentation (http://peewee.readthedocs.org/en/latest/peewee/api.html#Query.where) states that "where() calls are chainable. Multiple calls will be “AND”-ed together.". This works for SelectQuery: ``` Model.select().where(Model.id == 1).where(Model.status == 5) SELECT ... FROM `model` AS t1 WHERE ((t1.`id`=1) AND (t1.`status`=5)) ``` But does not work for UpdateQuery - only the final where() clause is included in the generated query. ``` Model.update(status=-1).where(Model.id == 1).where(Model.status == 5).execute() UPDATE `model` SET `status`=-1 WHERE (`status`=5) ``` In this example the Model.id == 1 clause has been dropped, causing a dangerous update. The clauses are all correctly included if they are specified in a single where(): ``` Model.update(status=-1).where((Model.id == 1) & (Model.status == 5)).execute() UPDATE `model` SET `status`=-1 WHERE ((`id`=1) AND (`status`=5)) ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/277/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/277/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/276
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/276/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/276/comments
https://api.github.com/repos/coleifer/peewee/issues/276/events
https://github.com/coleifer/peewee/issues/276
24,852,638
MDU6SXNzdWUyNDg1MjYzOA==
276
Problem related_name collision ?
{ "login": "ghost", "id": 10137, "node_id": "MDQ6VXNlcjEwMTM3", "avatar_url": "https://avatars.githubusercontent.com/u/10137?v=4", "gravatar_id": "", "url": "https://api.github.com/users/ghost", "html_url": "https://github.com/ghost", "followers_url": "https://api.github.com/users/ghost/followers", "following_url": "https://api.github.com/users/ghost/following{/other_user}", "gists_url": "https://api.github.com/users/ghost/gists{/gist_id}", "starred_url": "https://api.github.com/users/ghost/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/ghost/subscriptions", "organizations_url": "https://api.github.com/users/ghost/orgs", "repos_url": "https://api.github.com/users/ghost/repos", "events_url": "https://api.github.com/users/ghost/events{/privacy}", "received_events_url": "https://api.github.com/users/ghost/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Since `Schuelerkontakt` extends `Kontakt`, it also includes copies of the various foreign keys. For instance `typ = ForeignKeyField(Kontakttyp, related_name='typ_des_kontakts')`.\n\nThat sets up an attribute on `Kontakttyp` named `typ_des_kontakts` that initially points to `Kontakt`. When we get to `Schuelerkontakt` (which has the same `typ = ForeignKeyField(...)` because of inheritance) the related name collides with the existing one.\n\nMy suggestion would be to rewrite your models like so:\n\n``` python\nclass Kontakt(SqliteModel):\n typ = ForeignKeyField(Kontakttyp,\n related_name='typ_des_kontakts')\n bezeichner = CharField(max_length=40)\n kategorie = ForeignKeyField(Kontaktkategorie,\n null=True,\n related_name='kategorie_des_kontakts')\n\n def __unicode__(self):\n return u\"%s: %s \" % (self.typ, self.bezeichner)\n if self.kontaktkategorie:\n return out + \"[%s]\" % (self.kategorie,)\n\n\nclass Schuelerkontakt(Kontakt):\n typ = ForeignKeyField(Kontakttyp,\n related_name='typ_des_schueler_kontakts')\n schueler = ForeignKeyField(Schueler,\n related_name='kontakt_des_schuelers')\n kategorie = ForeignKeyField(Kontaktkategorie,\n null=True,\n related_name='kategorie_des_shuelerkontakts')\n\n\nclass Lehrerkontakt(Kontakt):\n typ = ForeignKeyField(Kontakttyp,\n related_name='typ_des_lehrer_kontakts')\n lehrer = ForeignKeyField(Lehrkraft,\n related_name='kontakt_der_lehrkraft')\n kategorie = ForeignKeyField(Kontaktkategorie,\n null=True,\n related_name='kategorie_des_lehrerkontakts')\n```\n\nPardon me if I butchered the names.\n\n---\n\nAs an aside, just wanted to make sure you understood how model inheritance works. It does not do anything clever as far as multi-table joins or polymorphism at the row-level.\n", "Thanks,\n\ni should have red your docs in detail - sorry. The document part [Inheriting model metadata](http://peewee.readthedocs.org/en/latest/peewee/models.html#inheriting-model-metadata) has gone unnoticed to my _/head/null_ :(\n", "No prob, the inheritance stuff can be very confusing.\n" ]
"2013-12-28T22:48:54"
"2013-12-29T16:13:44"
"2013-12-29T16:13:32"
NONE
null
If i try to import the following module i got the error: ``` Traceback (most recent call last): File "<stdin>", line 1, in <module> File "db.py", line 102, in <module> class Schuelerkontakt(Kontakt): File "/usr/lib/python2.7/site-packages/peewee.py", line 2570, in __new__ attr.add_to_class(cls, name) File "/usr/lib/python2.7/site-packages/peewee.py", line 800, in add_to_class raise AttributeError(error % params) AttributeError: Foreign key: schuelerkontakt.typ related name "typ_des_kontakts" collision with foreign key using same related_name. ``` I'm not able to fix it. _same related_name_ - i don't see this related_name twice? The Module: ``` from peewee import * database = SqliteDatabase(None) class SqliteModel(Model): """abstract class """ class Meta: database = database def __str__(self): return self.__unicode__().encode(ENC) def __repr__(self): return "<%s>" % (self.__str__(),) class SimpleModel(SqliteModel): """abstract class """ name = CharField(max_length=50) ### real class Kontakttyp(SimpleModel): beschreibung = CharField(max_length=20, null=True) class Kontaktkategorie(SimpleModel): beschreibung = CharField(max_length=30, null=True) class Person(SqliteModel): nachname = CharField(max_length=40) vorname = CharField(max_length=25) gebdat = DateField(null=True) def __unicode__(self): out = u"%s %s" % (self.nachname, self.vorname) if self.gebdat: out += " (%s)" % (self.gebdat,) return out def __cmp__(self, o): if not isinstance(o, Person): err = "only Schueler objects comparable" raise ValueError(err) if o.nachname > self.nachname: return -1 elif o.nachname == self.nachname: if o.vorname > self.vorname: return -1 elif o.vorname == self.vorname: return 0 else: return 1 else: return 1 class Lehrkraft(Person): kuerzel = CharField(max_length=3) klasse = CharField(max_length=3, null=True) class Meta: order_by = ('nachname', 'vorname') class Schueler(Person): klasse = CharField(max_length=3) zweig = CharField(null=True, max_length=4) spitzname = CharField(max_length=20, null=True) class Meta: order_by = ('nachname', 'vorname') def __unicode__(self): out = Person.__unicode__(self) if self.zweig: out += " [Klasse: %s (%s)]" % (self.klasse, self.zweig) else: out += " [Klasse: %s]" % (self.klasse,) return out class Kontakt(SqliteModel): typ = ForeignKeyField(Kontakttyp, related_name='typ_des_kontakts') bezeichner = CharField(max_length=40) kategorie = ForeignKeyField(Kontaktkategorie, null=True, related_name='kategorie_des_kontakts') def __unicode__(self): return u"%s: %s " % (self.typ, self.bezeichner) if self.kontaktkategorie: return out + "[%s]" % (self.kategorie,) class Schuelerkontakt(Kontakt): schueler = ForeignKeyField(Schueler, related_name='kontakt_des_schuelers') class Lehrerkontakt(Kontakt): lehrer = ForeignKeyField(Lehrkraft, related_name='kontakt_der_lehrkraft') ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/276/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/276/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/275
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/275/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/275/comments
https://api.github.com/repos/coleifer/peewee/issues/275/events
https://github.com/coleifer/peewee/issues/275
24,779,520
MDU6SXNzdWUyNDc3OTUyMA==
275
some error on foreign_key with Version 2.1.7
{ "login": "ghost", "id": 10137, "node_id": "MDQ6VXNlcjEwMTM3", "avatar_url": "https://avatars.githubusercontent.com/u/10137?v=4", "gravatar_id": "", "url": "https://api.github.com/users/ghost", "html_url": "https://github.com/ghost", "followers_url": "https://api.github.com/users/ghost/followers", "following_url": "https://api.github.com/users/ghost/following{/other_user}", "gists_url": "https://api.github.com/users/ghost/gists{/gist_id}", "starred_url": "https://api.github.com/users/ghost/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/ghost/subscriptions", "organizations_url": "https://api.github.com/users/ghost/orgs", "repos_url": "https://api.github.com/users/ghost/repos", "events_url": "https://api.github.com/users/ghost/events{/privacy}", "received_events_url": "https://api.github.com/users/ghost/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "This error affected py3k, which I don't regularly test -- my fault. I've fixed and re-pushed to PYPI as 2.1.7.\n" ]
"2013-12-26T06:41:47"
"2013-12-26T15:18:23"
"2013-12-26T15:18:23"
NONE
null
When I up to 2.1.7 today, tables con't create 。But in 2.16 I know it works good。 Below is what happened when I use it with Python3 and MySQL. Traceback (most recent call last): File "E:/Work/Python/notepy/model/model.py", line 74, in <module> PostTag.create_table() File "C:\Python33\lib\site-packages\peewee.py", line 2683, in create_table db.create_table(cls) File "C:\Python33\lib\site-packages\peewee.py", line 2116, in create_table return self.execute_sql(qc.create_table(model_class, safe)) File "C:\Python33\lib\site-packages\peewee.py", line 1229, in create_table return ' '.join(self.create_table_sql(model_class, safe)) File "C:\Python33\lib\site-packages\peewee.py", line 1223, in create_table_sql columns.append(' '.join(foreign_key)) AttributeError: 'map' object has no attribute 'append'
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/275/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/275/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/274
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/274/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/274/comments
https://api.github.com/repos/coleifer/peewee/issues/274/events
https://github.com/coleifer/peewee/issues/274
24,759,083
MDU6SXNzdWUyNDc1OTA4Mw==
274
Missing ChangeLog on PyPi and in release tarballs
{ "login": "pitchforks", "id": 4378791, "node_id": "MDQ6VXNlcjQzNzg3OTE=", "avatar_url": "https://avatars.githubusercontent.com/u/4378791?v=4", "gravatar_id": "", "url": "https://api.github.com/users/pitchforks", "html_url": "https://github.com/pitchforks", "followers_url": "https://api.github.com/users/pitchforks/followers", "following_url": "https://api.github.com/users/pitchforks/following{/other_user}", "gists_url": "https://api.github.com/users/pitchforks/gists{/gist_id}", "starred_url": "https://api.github.com/users/pitchforks/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/pitchforks/subscriptions", "organizations_url": "https://api.github.com/users/pitchforks/orgs", "repos_url": "https://api.github.com/users/pitchforks/repos", "events_url": "https://api.github.com/users/pitchforks/events{/privacy}", "received_events_url": "https://api.github.com/users/pitchforks/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "That makes sense. I only recently started tracking changes between versions so I wasn't actually sure anyone even looked at the releases on GH.\n\nIs there a special way to do this, or just make a `CHANGELOG` file in the repo and bundle it with the package?\n" ]
"2013-12-25T01:00:50"
"2013-12-27T15:44:15"
"2013-12-27T15:44:15"
NONE
null
I am using https://pypi.python.org/pypi/peewee to track peewee for new releases. Unfortunately it doesn't include a ChangeLog, so I have to come to https://github.com/coleifer/peewee/releases to read it. The release tarball also doesn't seem to bundle a ChangeLog file. Would it be possible to have a ChangeLog file in the release tarball, as well as having it listed on https://pypi.python.org/pypi/peewee, for convenience?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/274/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/274/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/273
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/273/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/273/comments
https://api.github.com/repos/coleifer/peewee/issues/273/events
https://github.com/coleifer/peewee/issues/273
24,722,814
MDU6SXNzdWUyNDcyMjgxNA==
273
Circular references
{ "login": "coleifer", "id": 119974, "node_id": "MDQ6VXNlcjExOTk3NA==", "avatar_url": "https://avatars.githubusercontent.com/u/119974?v=4", "gravatar_id": "", "url": "https://api.github.com/users/coleifer", "html_url": "https://github.com/coleifer", "followers_url": "https://api.github.com/users/coleifer/followers", "following_url": "https://api.github.com/users/coleifer/following{/other_user}", "gists_url": "https://api.github.com/users/coleifer/gists{/gist_id}", "starred_url": "https://api.github.com/users/coleifer/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/coleifer/subscriptions", "organizations_url": "https://api.github.com/users/coleifer/orgs", "repos_url": "https://api.github.com/users/coleifer/repos", "events_url": "https://api.github.com/users/coleifer/events{/privacy}", "received_events_url": "https://api.github.com/users/coleifer/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "This is partially fixed by d5a5a86a14b7d631ef8b8b3759bfd8345def9b56 which makes it possible to use `Proxy` with `ForeignKeyField`. Unfortunately, Postgresql will complain about the `create table` queries generated so I'll need to work around this.\n", "http://peewee.readthedocs.org/en/latest/peewee/cookbook.html#circular-foreign-key-dependencies\n" ]
"2013-12-23T20:26:12"
"2013-12-24T17:59:44"
"2013-12-24T17:59:44"
OWNER
null
It would be nice to support circular references between tables: ``` python class User(Model): username = CharField() last_post = ForeignKeyField(Post, null=True) # error class Post(Model): author = ForeignKeyField(User, related_name='posts') title = CharField() ``` Self-referential FKs are possible using the magic string `'self'` but this is not possible between tables.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/273/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/273/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/272
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/272/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/272/comments
https://api.github.com/repos/coleifer/peewee/issues/272/events
https://github.com/coleifer/peewee/pull/272
24,659,935
MDExOlB1bGxSZXF1ZXN0MTEwMzI1ODI=
272
Add a missing property copying in Node.clone.
{ "login": "xiaq", "id": 582021, "node_id": "MDQ6VXNlcjU4MjAyMQ==", "avatar_url": "https://avatars.githubusercontent.com/u/582021?v=4", "gravatar_id": "", "url": "https://api.github.com/users/xiaq", "html_url": "https://github.com/xiaq", "followers_url": "https://api.github.com/users/xiaq/followers", "following_url": "https://api.github.com/users/xiaq/following{/other_user}", "gists_url": "https://api.github.com/users/xiaq/gists{/gist_id}", "starred_url": "https://api.github.com/users/xiaq/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/xiaq/subscriptions", "organizations_url": "https://api.github.com/users/xiaq/orgs", "repos_url": "https://api.github.com/users/xiaq/repos", "events_url": "https://api.github.com/users/xiaq/events{/privacy}", "received_events_url": "https://api.github.com/users/xiaq/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I'm not sure why this is missing but let's add it back. Thanks!\n" ]
"2013-12-21T04:21:26"
"2014-07-06T01:50:39"
"2013-12-21T13:45:00"
CONTRIBUTOR
null
I guess it's truly missing, not intended?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/272/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/272/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/272", "html_url": "https://github.com/coleifer/peewee/pull/272", "diff_url": "https://github.com/coleifer/peewee/pull/272.diff", "patch_url": "https://github.com/coleifer/peewee/pull/272.patch", "merged_at": "2013-12-21T13:45:00" }
https://api.github.com/repos/coleifer/peewee/issues/271
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/271/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/271/comments
https://api.github.com/repos/coleifer/peewee/issues/271/events
https://github.com/coleifer/peewee/issues/271
24,649,703
MDU6SXNzdWUyNDY0OTcwMw==
271
DB errors are sometimes obscured
{ "login": "MichaelBlume", "id": 208853, "node_id": "MDQ6VXNlcjIwODg1Mw==", "avatar_url": "https://avatars.githubusercontent.com/u/208853?v=4", "gravatar_id": "", "url": "https://api.github.com/users/MichaelBlume", "html_url": "https://github.com/MichaelBlume", "followers_url": "https://api.github.com/users/MichaelBlume/followers", "following_url": "https://api.github.com/users/MichaelBlume/following{/other_user}", "gists_url": "https://api.github.com/users/MichaelBlume/gists{/gist_id}", "starred_url": "https://api.github.com/users/MichaelBlume/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/MichaelBlume/subscriptions", "organizations_url": "https://api.github.com/users/MichaelBlume/orgs", "repos_url": "https://api.github.com/users/MichaelBlume/repos", "events_url": "https://api.github.com/users/MichaelBlume/events{/privacy}", "received_events_url": "https://api.github.com/users/MichaelBlume/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Can you provide more information? How can I replicate this?\n", "Here are some examples:\n\n``` python\nIn [1]: from peewee import *\n\nIn [2]: db = PostgresqlDatabase('doesnotexist')\n\nIn [3]: db.connect()\nOperationalError: FATAL: database \"doesnotexist\" does not exist\n\nIn [4]: db = PostgresqlDatabase('peewee_test', user='invalid_user')\n\nIn [5]: db.connect()\nOperationalError: FATAL: role \"invalid_user\" does not exist\n```\n", "```\nPython 2.7.3 (default, Aug 1 2012, 05:14:39) \n[GCC 4.6.3] on linux2\nType \"help\", \"copyright\", \"credits\" or \"license\" for more information.\n>>> from peewee import *\n>>> \n>>> db = SqliteDatabase('people.db')\n>>> \n>>> class Person(Model):\n... name = CharField()\n... birthday = DateField()\n... is_relative = BooleanField()\n... class Meta:\n... database = db\n... \n>>> def identity(x):\n... return x\n... \n>>> persons_named_bob = Person.select().where(Person.name == \"Bob\")\n>>> map(identity, persons_named_bob)\nNo handlers could be found for logger \"peewee\"\nTraceback (most recent call last):\n File \"<stdin>\", line 1, in <module>\nTypeError: argument 2 to map() must support iteration\n```\n", "Gotcha, thank you for the example. So there's an error which isn't caught until the query is evaluated.\n\nSee the note in the docs: http://peewee.readthedocs.org/en/latest/peewee/cookbook.html#creating-a-database-connection-and-tables\n\n> While it is not necessary to explicitly connect to the database before using it, managing connections explicitly is a good practice. This way if the connection fails, the exception can be caught during the “connect” step, rather than some arbitrary time later when a query is executed.\n\nSo putting `db.connect()` before your call to `map` will catch an error creating the connection.\n", "As for `map` swallowing exceptions, that does not appear to be a problem with peewee specifically:\n\n``` python\nIn [15]: map(identity, None)\n---------------------------------------------------------------------------\nTypeError Traceback (most recent call last)\n<ipython-input-15-7e3da6cfa2ca> in <module>()\n----> 1 map(identity, None)\n\nTypeError: argument 2 to map() must support iteration\n\nIn [16]: map(identity, 1.0)\n---------------------------------------------------------------------------\nTypeError Traceback (most recent call last)\n<ipython-input-16-df55ff2dd812> in <module>()\n----> 1 map(identity, 1.0)\n\nTypeError: argument 2 to map() must support iteration\n```\n", "Ah, I see the problem better now:\n\n```\nIn [10]: class BadIter(object):\n ....: def next(self):\n ....: raise Exception()\n ....: \n\nIn [13]: class BadIterable(object):\n ....: def __iter__(self):\n ....: return BadIter()\n ....: \n\nIn [19]: def identity(x):\n ....: return x\n ....: \n\nIn [20]: map(identity, BadIterable())\n---------------------------------------------------------------------------\nException Traceback (most recent call last)\n<ipython-input-20-f77dd3200d2b> in <module>()\n----> 1 map(identity, BadIterable())\n\n<ipython-input-10-d95eda570961> in next(self)\n 1 class BadIter(object):\n 2 def next(self):\n----> 3 raise Exception()\n 4 \n\nException: \n\nIn [21]: class WorseIterable(object):\n ....: def __iter__(self):\n ....: raise Exception()\n ....: \n\nIn [22]: map(identity, WorseIterable())\n---------------------------------------------------------------------------\nTypeError Traceback (most recent call last)\n<ipython-input-22-1cbe60ec7e3b> in <module>()\n----> 1 map(identity, WorseIterable())\n\nTypeError: argument 2 to map() must support iteration\n```\n\nSo an exception in `next()` will propagate, but an exception in `__iter__()` will be obscured _by python itself_. I'd just about call that a Python bug.\n", "Looks like it's fixed in Python 3 though, so there's another reason for us all to migrate =)\n\nThanks!\n", "Sure thing, thanks for the code -- I'm sure this will be useful if this crops up again!\n" ]
"2013-12-20T21:42:14"
"2013-12-20T22:44:07"
"2013-12-20T22:09:41"
NONE
null
when I connect to a DB with bad credentials, select a list of items, and then do a map on that list, the fact that the connection failed doesn't surface until I perform the map, and Python obscures the connection error by just telling me TypeError: argument 2 to map() must support iteration'
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/271/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/271/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/270
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/270/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/270/comments
https://api.github.com/repos/coleifer/peewee/issues/270/events
https://github.com/coleifer/peewee/issues/270
24,378,022
MDU6SXNzdWUyNDM3ODAyMg==
270
Issues with CompositeKey
{ "login": "coleifer", "id": 119974, "node_id": "MDQ6VXNlcjExOTk3NA==", "avatar_url": "https://avatars.githubusercontent.com/u/119974?v=4", "gravatar_id": "", "url": "https://api.github.com/users/coleifer", "html_url": "https://github.com/coleifer", "followers_url": "https://api.github.com/users/coleifer/followers", "following_url": "https://api.github.com/users/coleifer/following{/other_user}", "gists_url": "https://api.github.com/users/coleifer/gists{/gist_id}", "starred_url": "https://api.github.com/users/coleifer/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/coleifer/subscriptions", "organizations_url": "https://api.github.com/users/coleifer/orgs", "repos_url": "https://api.github.com/users/coleifer/repos", "events_url": "https://api.github.com/users/coleifer/events{/privacy}", "received_events_url": "https://api.github.com/users/coleifer/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "So on the model `B` somewhere we would need to have columns mapped to `A.id` and `A.description`. Then introduce a FK constraint and accessor that would do the right joins.\n", "Does it make sense to add a `CompositeForeignKey`, so you'd end up with something like:\n\n``` python\n\nclass A(ContextModel):\n id = IntegerField()\n another_thing = CharField()\n description = TextField()\n\n class Meta: \n primary_key = CompositeKey('id', 'description') \n\nclass B(ContextModel):\n a_id = IntegerField()\n a_description = TextField()\n a = CompositeForeignKey(A, 'a_id', 'a_description')\n```\n", "I think it does. If you think that's the best way to go. \nWhat's the difference between inspecting inside ForeignKey whether the target model's key is a CompositeKey against creating a new class for the CompositeForeignKey? \n\nBut again, I think the fix you propose does the job pretty well. thanks!\n", "> What's the difference between inspecting inside ForeignKey whether the target model's key is a CompositeKey against creating a new class for the CompositeForeignKey?\n\nIn a typical model the `ForeignKeyField` is a single column on a table (hence, it subclasses Field). When you want to foreign-key to a model with a composite pk, you would need multiple columns (to mirror the columns making up the primary key).\n", "What will happen in such case?\n\n```\nclass A(ContextModel):\n id = IntegerField()\n another_thing = CharField()\n description = TextField()\n\n class Meta:\n indexes = (( 'a_id', 'a_description'), True) ,\n\nclass B(ContextModel):\n a_id = IntegerField()\n a_description = TextField()\n a = CompositeForeignKey(A, 'a_id', 'a_description')\n```\n", "@akaRem -- what do you mean?\n", "I'm going to close this for now.\n", "@coleifer Any progress on this ? It still crashes with the same exception.\n\nIf it's not peewee goal, it would be worth to mention it in docs, because \n\n> Peewee has very basic support for composite keys\n\nIs not enough.\n", "I think I'm running into this too, I want to have a composite foreign key like so:\n\n``` python\n# coding=utf-8\nfrom peewee import *\n\ndb = SqliteDatabase('dump4.db')\n\nclass BaseModel(Model):\n\n class Meta:\n database = db\n\nclass table_A(BaseModel):\n tabA_id = IntegerField(primary_key=True, index=True)\n colA_data = IntegerField(index=True)\n\n\nclass table_C(BaseModel):\n tabA_id = ForeignKeyField(table_A, related_name='cs')\n tabC_id = IntegerField()\n colC_data = BooleanField()\n\n class Meta:\n primary_key = CompositeKey('tabA_id', 'tabC_id', 'colC_data')\n\n\nclass table_B(BaseModel):\n tabA_id = ForeignKeyField(table_A, related_name='bs')\n tabB_id = IntegerField()\n colB_data = BooleanField()\n\n class Meta:\n primary_key = CompositeKey('tabA_id', 'tabB_id', 'colB_data')\n\nclass table_D(BaseModel):\n tabA_id = ForeignKeyField(table_A, related_name='ds')\n tabD_id = IntegerField()\n tabB_id = ForeignKeyField(table_B, related_name='ds')\n colB_data = ForeignKeyField(table_B)\n colD_data = TextField()\n\n class Meta:\n primary_key = CompositeKey('tabA_id', 'tabD_id',\n 'colB_data')\n\n\ndef main():\n tables = [\n table_A, table_B,\n table_C, table_D,\n ]\n db.connect()\n db.drop_tables(tables, safe=True)\n db.create_tables(tables, safe=True)\n #populate_db(db)\n print('DB done')\n\n\nif __name__ == '__main__':\n main()\n```\n\nWith peewee 2.4.7 on python 3.4.3 I get:\n\n```\nTraceback (most recent call last):\n File \"test4.py\", line 58, in <module>\n main()\n File \"test4.py\", line 52, in main\n db.create_tables(tables, safe=True)\n File \"/Users/jimd/Desktop/p/sec/parse4/lib/python3.4/site-packages/peewee.py\", line 2959, in create_tables\n create_model_tables(models, fail_silently=safe)\n File \"/Users/jimd/Desktop/p/sec/parse4/lib/python3.4/site-packages/peewee.py\", line 4049, in create_model_tables\n m.create_table(**create_table_kwargs)\n File \"/Users/jimd/Desktop/p/sec/parse4/lib/python3.4/site-packages/peewee.py\", line 3798, in create_table\n db.create_table(cls)\n File \"/Users/jimd/Desktop/p/sec/parse4/lib/python3.4/site-packages/peewee.py\", line 2956, in create_table\n return self.execute_sql(*qc.create_table(model_class, safe))\n File \"/Users/jimd/Desktop/p/sec/parse4/lib/python3.4/site-packages/peewee.py\", line 1666, in inner\n return self.parse_node(fn(*args, **kwargs))\n File \"/Users/jimd/Desktop/p/sec/parse4/lib/python3.4/site-packages/peewee.py\", line 1694, in _create_table\n columns.append(self.field_definition(field))\n File \"/Users/jimd/Desktop/p/sec/parse4/lib/python3.4/site-packages/peewee.py\", line 1644, in field_definition\n column_type = self.get_column_type(field.get_db_field())\n File \"/Users/jimd/Desktop/p/sec/parse4/lib/python3.4/site-packages/peewee.py\", line 1119, in get_db_field\n return self.to_field.get_db_field()\nAttributeError: 'CompositeKey' object has no attribute 'get_db_field'\n```\n\nI can get around it by making the tabB_id field increment so it'll be independent of the colB_data Boolean, and create a second id field that will be equal across the true/false sides of the boolean, but that just feels a little ugly in my third normalised heart.\n", "Are there any plans to address this issue? Your `CompositeForeignKey` solution would put this into a better state than it is today.\n", "Yeah...I'm not sure what to do really and have been wavering about doing anything really. Adding `CompositeForeignKey` just seemed like a big hack, to be honest. It doesn't really do anything except provide a handy way of accessing a related object, but you could just as easily implement this using a simple property.\n\nWhat are the benefits of adding this to peewee?\n", "@coleifer Being able to reference a foreign composite key is pretty useful, and peewee doesn't have much support for it. For example, suppose we're representing all employees in a company, which is composed of many subsidiaries. Each subsidiary has its own method of allocating employee IDs, therefore it's possible that two different employees from two different subsidiaries have the same employee ID, and thus the natural key for a table of employees of the parent company is a composite key of the subsidiary and the employee ID. So we have:\n\n``` python\nfrom peewee import *\n\ndb = SqliteDatabase('example.db')\n\nclass BaseModel(Model):\n class Meta:\n database = db\n\nclass Subsidiary(BaseModel):\n name = CharField()\n\nclass Employee(BaseModel):\n subsidiary = ForeignKeyField(Subsidiary)\n employee = IntegerField()\n\n class Meta:\n primary_key = CompositeKey('subsidiary', 'employee')\n\nclass CompanyHierarchy(BaseModel):\n manager = ForeignKeyField(Employee, related_name='subordinates')\n subordinate = ForeignKeyField(Employee, related_name='managers')\n\nif __name__ == '__main__':\n Employee.create_table()\n CompanyHierarchy.create_table()\n```\n\nCreating the tables this way can make doing bulk updates much easier (e.g., using MySQL we could use `INSERT ... ON DUPLICATE KEY UPDATE ...` with the `employee` table), but peewee throws an exception when given this code.\n\nWhile this bit of code may seem fairly contrived, a coworker ran into a very similar situation and we had to work around it in a non-optimal way by enforcing desired constraints in code instead of the database and losing the ability to use the aforementioned `INSERT ... ON DUPLICATE KEY UPDATE ...`.\n", "Gotcha, I guess the weird thing there is that `CompanyHierarchy`, to match `Employee`, should really have two columns: `subsidiary_id` and `employee_id` instead of a single \"composite foreign key\". Then a unique constraint defined in the `CompanyHierarchy.Meta`.\n", "I really just can't bring myself to add a `CompositeForeignKey` object, it feels too hacky.\n", "Do you have anything new to add to this issue? I just came across it myself. :)\n", "Same here, would be great to have it implemented", "@coleifer I'd think the non-hacky thing to do would be to make foreign keys composite in general. So, even if it winds up being a bit hacky having foreign key fields as a child of fields and a separate CompositeForeignKey, it would still be a step in the right direction.", "I have this issue too, it's still a problem. Is there any news?", "I still dislike having some kind of a ForeignKeyField that points to a CompositePrimaryKey. You can always add a foreign key constraint and a handy property in-place of some kind of \"CompositeForeignKeyField\"." ]
"2013-12-16T20:54:44"
"2017-07-07T04:15:45"
"2017-07-07T04:15:45"
OWNER
null
I have two models. Model A has a CompositeKey as primary_key, defined as indicated in [0]. Model B references model A with a ForeignKeyField(A) as indicated in [1]. Its seems that something is wrongly defined and raises an exception when tables are created in sqlite engine. Below is the full code reproducing the problem. Any help would be appreciated, Thanks in advance! [0] http://peewee.readthedocs.org/en/latest/peewee/api.html#CompositeKey [1] http://peewee.readthedocs.org/en/latest/peewee/api.html#ForeignKeyField ``` python context_db = SqliteDatabase(":memory:") class ContextModel(Model): class Meta: database = context_db class A(ContextModel): id = IntegerField() another_thing = CharField() description = TextField() class Meta: primary_key = CompositeKey('id','description') class B(ContextModel): fk = ForeignKeyField(A) A.create_table() B.create_table() ``` And the second invocation raises: ``` python /.../python2.7/site-packages/peewee-2.1.6-py2.7.egg/peewee.pyc in get_db_field(self) 709 to_pk = self.rel_model._meta.primary_key 710 if not isinstance(to_pk, PrimaryKeyField): --> 711 return to_pk.get_db_field() 712 return super(ForeignKeyField, self).get_db_field() 713 AttributeError: 'CompositeKey' object has no attribute 'get_db_field' ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/270/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/270/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/269
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/269/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/269/comments
https://api.github.com/repos/coleifer/peewee/issues/269/events
https://github.com/coleifer/peewee/issues/269
23,967,523
MDU6SXNzdWUyMzk2NzUyMw==
269
Fx places.sqlite not fit for pwiz.py
{ "login": "ricardogithub", "id": 3900829, "node_id": "MDQ6VXNlcjM5MDA4Mjk=", "avatar_url": "https://avatars.githubusercontent.com/u/3900829?v=4", "gravatar_id": "", "url": "https://api.github.com/users/ricardogithub", "html_url": "https://github.com/ricardogithub", "followers_url": "https://api.github.com/users/ricardogithub/followers", "following_url": "https://api.github.com/users/ricardogithub/following{/other_user}", "gists_url": "https://api.github.com/users/ricardogithub/gists{/gist_id}", "starred_url": "https://api.github.com/users/ricardogithub/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/ricardogithub/subscriptions", "organizations_url": "https://api.github.com/users/ricardogithub/orgs", "repos_url": "https://api.github.com/users/ricardogithub/repos", "events_url": "https://api.github.com/users/ricardogithub/events{/privacy}", "received_events_url": "https://api.github.com/users/ricardogithub/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "> A second thing is: it is usually a good thing not to silently make assumptions, like emitting an UnknownFieldType as mentioned above.\n\npwiz emits `UnknownFieldType` because it is unknown...exactly because we don't want to be making assumptions. See: http://www.sqlite.org/datatype3.html .\n\nI don't see any problem with adding `long` -> `BigIntegerField`. I'm not sure about some others. Maybe it makes sense to put a comment after the `UnknownFieldType` indicating the column type in the table definition.\n", "In my particular case the three additions to the mapping array seem to work, but I have not tested it extensively. \n\nGood suggestion about the column type hint. \n\nBTW In general I agree with you about the assumptions, but..._places.sqlite_ happened to be the first database I tried to introspect. I can't believe I was the first one till now to pick places.sqlite :-> \n\nLuckily I stayed on board, but maybe others did not, and moved on to another ORM solution. And that is really too bad, because peewee deserves better than a first crappy experience with pwiz due to some non-standard, but very common database :-) Keep up the good work. \n", "I'm sorry you were disappointed with the generated code.\n", "I've added some logic to display the raw underlying data type. With sqlite you can enter in any garbage you want...this is perfectly valid:\n\n``` sql\ncreate table walrus (tusk ivory, whisker blubber);\n```\n\npwiz will now return:\n\n``` python\nclass Walrus(BaseModel):\n tusk = UnknownFieldType(null=True) # ivory\n whisker = UnknownFieldType(null=True) # blubber\n\n class Meta:\n db_table = 'walrus'\n```\n" ]
"2013-12-09T15:04:33"
"2013-12-10T06:19:09"
"2013-12-10T06:18:49"
NONE
null
In fact, it is the other way around :-) Firefox's **places.sqlite** database (and propably others too) use a slighty modified field model, which is not supported by pwiz.py. What I found is that Firefox at least uses non-standard datatypes _long_ and _longvarchar_, and also can use fields _without_ a proper type denotation. The _mapping_-array of the SqliteIntrospector of pwiz.py does not support this, and silently emits _UnknownFieldType_ instances in theses cases. First. It is easily fixed by adding three lines to the mapping array: 'long': BigIntegerField, 'longvarchar': TextField, '': TextField, A second thing is: it is usually a good thing not to silently make assumptions, like emitting an UnknownFieldType as mentioned above. The least _pwizz.py_ should do is give a warning. It would be nice if these things can be added to the script, perhaps only if a special engine flag has been set.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/269/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/269/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/268
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/268/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/268/comments
https://api.github.com/repos/coleifer/peewee/issues/268/events
https://github.com/coleifer/peewee/pull/268
23,877,359
MDExOlB1bGxSZXF1ZXN0MTA2MDQwMTg=
268
Adds support for nested transactions to postgres via savepoints
{ "login": "jhorman", "id": 323697, "node_id": "MDQ6VXNlcjMyMzY5Nw==", "avatar_url": "https://avatars.githubusercontent.com/u/323697?v=4", "gravatar_id": "", "url": "https://api.github.com/users/jhorman", "html_url": "https://github.com/jhorman", "followers_url": "https://api.github.com/users/jhorman/followers", "following_url": "https://api.github.com/users/jhorman/following{/other_user}", "gists_url": "https://api.github.com/users/jhorman/gists{/gist_id}", "starred_url": "https://api.github.com/users/jhorman/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/jhorman/subscriptions", "organizations_url": "https://api.github.com/users/jhorman/orgs", "repos_url": "https://api.github.com/users/jhorman/repos", "events_url": "https://api.github.com/users/jhorman/events{/privacy}", "received_events_url": "https://api.github.com/users/jhorman/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Interesting PR. I'm actually looking at refactoring the transaction code to use a stack for #265 , though I did not plan on implementing nested txns using savepoints.\n\nI'm not sure I like overloading `begin` to now mean \"create a savepoint\". Same for `rollback`. These should always mean either begin a transaction or roll it back.\n", "Ok, now I only will create a savepoint in `begin()` for the nested transactions.\n\nIn Postgres there is no notion of nested transactions via `BEGIN`. A 2nd call to `BEGIN` will just be ignored. Their recommendation is to create a save point if the intention is to support nesting. That is what the 2nd commit now does. Only nested rollback/commit now release/rollback the savepoints.\n\nThis change now supports #265 I believe, on Postgres at least. I think that MySQL would be the same basically, at least with InnoDB.\n\nI like this approach vs having to force the user to think about savepoints, and how nesting is supported across `Database` implementations. This just says that peewee will support nesting, and the details are up to the `Database` implementation.\n", "> I like this approach vs having to force the user to think about savepoints.\n\nThat's a valid point.\n", "It looks like MySQL and Sqlite support savepoints as well. Have you looking into how this PR works with those databases?\n", "Rather than expose savepoints as nested transactions, I've created a new method / context manager.\n\n``` python\n\nwith db.savepoint():\n do stuff\n```\n", "I like adding explicit savepoint support, but are you saying you don't want to support nested transactions in postgres like this?\n", "Well, I added support for nesting calls to `transaction`, but the transactions are not nested per-se. I will add support for savepoints as a separate API using an approach similar to the transaction context mgr.\n", "Added savepoint support:\n\n``` python\nwith db.transaction():\n # etc\n with db.savepoint():\n # etc\n with db.savepoint():\n # etc\n```\n", "Cool, I'll check it out.\n" ]
"2013-12-06T18:51:37"
"2014-07-06T01:50:41"
"2013-12-12T19:31:57"
CONTRIBUTOR
null
Postgres supports nested transactions by way of savepoints. http://www.postgresql.org/docs/9.3/static/sql-savepoint.html An example usage is ``` sql BEGIN; INSERT INTO table1 VALUES (1); SAVEPOINT my_savepoint; INSERT INTO table1 VALUES (2); ROLLBACK TO SAVEPOINT my_savepoint; INSERT INTO table1 VALUES (3); COMMIT; ``` This patch adds savepoint support to the peewee PostgresqlDatabase. As is, PostgresqlDatabase doesn't implement begin, or support nested transactions. With this change nested transactions will only setup/rollback/release savepoints, the outermost transaction will do the commit/rollback. begin: now creates a savepoint, and increments the nesting depth. commit: releases the savepoint, and calls commit if not still nested. rollback: rolls back to the savepoint, and calls rollback if not still nested.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/268/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/268/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/268", "html_url": "https://github.com/coleifer/peewee/pull/268", "diff_url": "https://github.com/coleifer/peewee/pull/268.diff", "patch_url": "https://github.com/coleifer/peewee/pull/268.patch", "merged_at": null }
https://api.github.com/repos/coleifer/peewee/issues/267
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/267/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/267/comments
https://api.github.com/repos/coleifer/peewee/issues/267/events
https://github.com/coleifer/peewee/issues/267
23,677,152
MDU6SXNzdWUyMzY3NzE1Mg==
267
Self-referencing subquery not possible?
{ "login": "shai126", "id": 5904710, "node_id": "MDQ6VXNlcjU5MDQ3MTA=", "avatar_url": "https://avatars.githubusercontent.com/u/5904710?v=4", "gravatar_id": "", "url": "https://api.github.com/users/shai126", "html_url": "https://github.com/shai126", "followers_url": "https://api.github.com/users/shai126/followers", "following_url": "https://api.github.com/users/shai126/following{/other_user}", "gists_url": "https://api.github.com/users/shai126/gists{/gist_id}", "starred_url": "https://api.github.com/users/shai126/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/shai126/subscriptions", "organizations_url": "https://api.github.com/users/shai126/orgs", "repos_url": "https://api.github.com/users/shai126/repos", "events_url": "https://api.github.com/users/shai126/events{/privacy}", "received_events_url": "https://api.github.com/users/shai126/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "If you're referencing the same table multiple times in the query you need to call `Model.alias()`.\n\n``` python\nclass Game(Model):\n some_fields\n\nG2 = Game.alias()\nGame.select(\n Game, \n G2.select(fn.Sum(G2.something)).where(G2.some_field == Game.another_field).alias('xxx'))\n```\n\nI haven't tried the above, so not 100% sure.\n", "I'm pretty sure this is one of the things I tried which didn't work, but\nI'm on the road just now so will take another look tomorrow and let you\nknow for sure - either that it does in fact work or exactly how it fails.\nCheers\nOn 4 Dec 2013 23:43, \"Charles Leifer\" notifications@github.com wrote:\n\n> If you're referencing the same table multiple times in the query you need\n> to call Model.alias().\n> \n> class Game(Model):\n> some_fields\n> G2 = Game.alias()Game.select(\n> Game,\n> G2.select(fn.Sum(G2.something)).where(G2.some_field == Game.another_field).alias('xxx'))\n> \n> I haven't tried the above, so not 100% sure.\n> \n> —\n> Reply to this email directly or view it on GitHubhttps://github.com/coleifer/peewee/issues/267#issuecomment-29858012\n> .\n", "One quirk of the implementation is that calling `G2.select()` doesn't work as you'd expect. With a bit of experimentation, I came up with this (and added a unit test to document it):\n\n``` python\n UA = User.alias()\n inner = SelectQuery(UA, fn.Sum(UA.id)).where(UA.id == User.id)\n query = User.select(User, inner.alias('xxx'))\n sql, params = query.sql()\n self.assertEqual(\n sql,\n 'SELECT t1.\"id\", t1.\"username\", (SELECT Sum(t2.\"id\") FROM \"users\" AS t2 WHERE (t2.\"id\" = t1.\"id\")) AS xxx FROM \"users\" AS t1')\n```\n\nMy previous example should be correct except that instead of `G2.select(...)` you should call `SelectQuery(G2, ...)`.\n", "All should be fixed in c530906878b45d7d2eede616a3cc10238a9118a1\n\nMakes it possible to write:\n\n``` python\nUA = User.alias()\ninner = UA.select(fn.Sum(UA.id)).where(UA.id == User.id)\nquery = User.select(User, inner.alias('xxx'))\n```\n" ]
"2013-12-03T21:52:54"
"2013-12-05T14:49:52"
"2013-12-05T14:49:52"
NONE
null
_(I posted this earlier today as a comment on #156, then realised that as #156 is closed I don't know if that was the right place to post or not. Please feel free to delete whichever one is in the wrong place)_ 65118b2c7aa4b6ed671de9d8b951f409cf657d18 works as a fix for the example given in #156, but it seems that this fix is limited to ONLY working if the subquery is selecting from a different table than the outer/main query? In other words, is there any way to do: ``` SELECT g1.*, ( SELECT SUM(g2.something) FROM games AS g2 WHERE g2.some_field = g1.another_field ) AS xxx FROM games AS g1 ``` i.e. subqueries that select from one alias of `games` whilst also referencing the outer (main) alias of `games`. Seems impossible using the subquery support in 65118b2c7aa4b6ed671de9d8b951f409cf657d18 – maybe I'm just missing something but it seems no amount or permutation of `.alias()`ing seems to solve this one... Happy to supply more info if you need. **Update:** have carried on investigating. Looks like at any given time, an instance of `alias_map` can only hold one of each model class as its keys, which is causing the problem. Perhaps if the `alias_map` could take `ModelAlias` instances as keys as well as `Model`s we could get around this somehow? Or, again, am I just missing something obvious that's already implemented...
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/267/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/267/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/266
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/266/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/266/comments
https://api.github.com/repos/coleifer/peewee/issues/266/events
https://github.com/coleifer/peewee/issues/266
23,655,200
MDU6SXNzdWUyMzY1NTIwMA==
266
pwiz error with leading underscore in column names
{ "login": "vincentdavis", "id": 232564, "node_id": "MDQ6VXNlcjIzMjU2NA==", "avatar_url": "https://avatars.githubusercontent.com/u/232564?v=4", "gravatar_id": "", "url": "https://api.github.com/users/vincentdavis", "html_url": "https://github.com/vincentdavis", "followers_url": "https://api.github.com/users/vincentdavis/followers", "following_url": "https://api.github.com/users/vincentdavis/following{/other_user}", "gists_url": "https://api.github.com/users/vincentdavis/gists{/gist_id}", "starred_url": "https://api.github.com/users/vincentdavis/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/vincentdavis/subscriptions", "organizations_url": "https://api.github.com/users/vincentdavis/orgs", "repos_url": "https://api.github.com/users/vincentdavis/repos", "events_url": "https://api.github.com/users/vincentdavis/events{/privacy}", "received_events_url": "https://api.github.com/users/vincentdavis/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Can you share the table definition from whatever database engine you're using? i.e. the `CREATE TABLE` query.\n", "CREATE TABLE `jeffco_2009` (\n `_id` int(11) NOT NULL AUTO_INCREMENT,\n `lat` float NOT NULL,\n `lon` float NOT NULL,\n `altatd` varchar(100) DEFAULT NULL,\n `anxyr` varchar(100) DEFAULT NULL,\n `asmasdimp` varchar(100) DEFAULT NULL,\n `asmasdlnd` varchar(100) DEFAULT NULL,\n `asmasdprs` varchar(100) DEFAULT NULL,\n `asmasdtot` varchar(100) DEFAULT NULL,\n `asmbseimp` varchar(100) DEFAULT NULL,\n `asmbselnd` varchar(100) DEFAULT NULL,\n `asmbseprs` varchar(100) DEFAULT NULL,\n `asmbsetot` varchar(100) DEFAULT NULL,\n `asmdt` varchar(100) DEFAULT NULL,\n `atd` varchar(100) DEFAULT NULL,\n `bpctycd` varchar(100) DEFAULT NULL,\n `chgdt002` varchar(100) DEFAULT NULL,\n `cmnadrnbr` varchar(100) DEFAULT NULL,\n `comara` varchar(100) DEFAULT NULL,\n `dba` varchar(100) DEFAULT NULL,\n `dedtyp` varchar(100) DEFAULT NULL,\n `dedtyp2` varchar(100) DEFAULT NULL,\n `dedtyp3` varchar(100) DEFAULT NULL,\n `dedtyp4` varchar(100) DEFAULT NULL,\n `demyr` varchar(100) DEFAULT NULL,\n `excyr` varchar(100) DEFAULT NULL,\n `fi` varchar(100) DEFAULT NULL,\n `genbil` varchar(100) DEFAULT NULL,\n `genbil1` varchar(100) DEFAULT NULL,\n `genbil2` varchar(100) DEFAULT NULL,\n `genbil3` varchar(100) DEFAULT NULL,\n `genpd` varchar(100) DEFAULT NULL,\n `impara` varchar(100) DEFAULT NULL,\n `incyr` varchar(100) DEFAULT NULL,\n `lglblk` varchar(100) DEFAULT NULL,\n `lglblk2` varchar(100) DEFAULT NULL,\n `lglblk3` varchar(100) DEFAULT NULL,\n `lglblk4` varchar(100) DEFAULT NULL,\n `lglkey` varchar(100) DEFAULT NULL,\n `lglkey2` varchar(100) DEFAULT NULL,\n `lglkey3` varchar(100) DEFAULT NULL,\n `lglkey4` varchar(100) DEFAULT NULL,\n `lgllot` varchar(100) DEFAULT NULL,\n `lgllot2` varchar(100) DEFAULT NULL,\n `lgllot3` varchar(100) DEFAULT NULL,\n `lgllot4` varchar(100) DEFAULT NULL,\n `lglqtr` varchar(100) DEFAULT NULL,\n `lglqtr2` varchar(100) DEFAULT NULL,\n `lglqtr3` varchar(100) DEFAULT NULL,\n `lglqtr4` varchar(100) DEFAULT NULL,\n `lglrcp` varchar(100) DEFAULT NULL,\n `lglrcp2` varchar(100) DEFAULT NULL,\n `lglrcp3` varchar(100) DEFAULT NULL,\n `lglrcp4` varchar(100) DEFAULT NULL,\n `lglrng` varchar(100) DEFAULT NULL,\n `lglrng2` varchar(100) DEFAULT NULL,\n `lglrng3` varchar(100) DEFAULT NULL,\n `lglrng4` varchar(100) DEFAULT NULL,\n `lglsec` varchar(100) DEFAULT NULL,\n `lglsec2` varchar(100) DEFAULT NULL,\n `lglsec3` varchar(100) DEFAULT NULL,\n `lglsec4` varchar(100) DEFAULT NULL,\n `lglsqft` varchar(100) DEFAULT NULL,\n `lglsqft2` varchar(100) DEFAULT NULL,\n `lglsqft3` varchar(100) DEFAULT NULL,\n `lglsqft4` varchar(100) DEFAULT NULL,\n `lglsubcd` varchar(100) DEFAULT NULL,\n `lglsubcd2` varchar(100) DEFAULT NULL,\n `lglsubcd3` varchar(100) DEFAULT NULL,\n `lglsubcd4` varchar(100) DEFAULT NULL,\n `lgltwn` varchar(100) DEFAULT NULL,\n `lgltwn2` varchar(100) DEFAULT NULL,\n `lgltwn3` varchar(100) DEFAULT NULL,\n `lgltwn4` varchar(100) DEFAULT NULL,\n `lndara` varchar(100) DEFAULT NULL,\n `mailctynam` varchar(100) DEFAULT NULL,\n `mailstenam` varchar(100) DEFAULT NULL,\n `mailstrdir` varchar(100) DEFAULT NULL,\n `mailstrnam` varchar(100) DEFAULT NULL,\n `mailstrnbr` varchar(100) DEFAULT NULL,\n `mailstrsfx` varchar(100) DEFAULT NULL,\n `mailstrtyp` varchar(100) DEFAULT NULL,\n `mailstrunt` varchar(100) DEFAULT NULL,\n `mailzip4` varchar(100) DEFAULT NULL,\n `mailzip5` varchar(100) DEFAULT NULL,\n `morelgl` varchar(100) DEFAULT NULL,\n `moreown` varchar(100) DEFAULT NULL,\n `moresls` varchar(100) DEFAULT NULL,\n `morestt` varchar(100) DEFAULT NULL,\n `moreval` varchar(100) DEFAULT NULL,\n `nhdnam` varchar(100) DEFAULT NULL,\n `nhdnbr` varchar(100) DEFAULT NULL,\n `ownico` varchar(100) DEFAULT NULL,\n `ownnam` varchar(100) DEFAULT NULL,\n `ownnam2` varchar(100) DEFAULT NULL,\n `ownnam3` varchar(100) DEFAULT NULL,\n `parid` varchar(100) DEFAULT NULL,\n `paycd` varchar(100) DEFAULT NULL,\n `prpctynam` varchar(100) DEFAULT NULL,\n `prpstenam` varchar(100) DEFAULT NULL,\n `prpstrdir` varchar(100) DEFAULT NULL,\n `prpstrnam` varchar(100) DEFAULT NULL,\n `prpstrnum` varchar(100) DEFAULT NULL,\n `prpstrsfx` varchar(100) DEFAULT NULL,\n `prpstrtyp` varchar(100) DEFAULT NULL,\n `prpstrunt` varchar(100) DEFAULT NULL,\n `prpzip4` varchar(100) DEFAULT NULL,\n `prpzip5` varchar(100) DEFAULT NULL,\n `prsbuscd1` varchar(100) DEFAULT NULL,\n `prsbuscd2` varchar(100) DEFAULT NULL,\n `pyrtotval` varchar(100) DEFAULT NULL,\n `qual` varchar(100) DEFAULT NULL,\n `relsch` varchar(100) DEFAULT NULL,\n `sch` varchar(100) DEFAULT NULL,\n `sid` varchar(100) DEFAULT NULL,\n `sidasm` varchar(100) DEFAULT NULL,\n `siddst` varchar(100) DEFAULT NULL,\n `slsamt` varchar(100) DEFAULT NULL,\n `slsamt2` varchar(100) DEFAULT NULL,\n `slsamt3` varchar(100) DEFAULT NULL,\n `slsamt4` varchar(100) DEFAULT NULL,\n `slscd` varchar(100) DEFAULT NULL,\n `slscd2` varchar(100) DEFAULT NULL,\n `slscd3` varchar(100) DEFAULT NULL,\n `slscd4` varchar(100) DEFAULT NULL,\n `slsdt` varchar(100) DEFAULT NULL,\n `slsdt2` varchar(100) DEFAULT NULL,\n `slsdt3` varchar(100) DEFAULT NULL,\n `slsdt4` varchar(100) DEFAULT NULL,\n `sts` varchar(100) DEFAULT NULL,\n `sttbstare2` varchar(100) DEFAULT NULL,\n `sttbstare3` varchar(100) DEFAULT NULL,\n `sttbstare4` varchar(100) DEFAULT NULL,\n `sttbstarea` varchar(100) DEFAULT NULL,\n `sttbsttyp` varchar(100) DEFAULT NULL,\n `sttbsttyp2` varchar(100) DEFAULT NULL,\n `sttbsttyp3` varchar(100) DEFAULT NULL,\n `sttbsttyp4` varchar(100) DEFAULT NULL,\n `sttgartyp` varchar(100) DEFAULT NULL,\n `sttgartyp2` varchar(100) DEFAULT NULL,\n `sttgartyp3` varchar(100) DEFAULT NULL,\n `sttgartyp4` varchar(100) DEFAULT NULL,\n `sttgrsare2` varchar(100) DEFAULT NULL,\n `sttgrsare3` varchar(100) DEFAULT NULL,\n `sttgrsare4` varchar(100) DEFAULT NULL,\n `sttgrsarea` varchar(100) DEFAULT NULL,\n `sttnbrbld2` varchar(100) DEFAULT NULL,\n `sttnbrbld3` varchar(100) DEFAULT NULL,\n `sttnbrbld4` varchar(100) DEFAULT NULL,\n `sttnbrbldg` varchar(100) DEFAULT NULL,\n `sttnbrflr` varchar(100) DEFAULT NULL,\n `sttnbrflr2` varchar(100) DEFAULT NULL,\n `sttnbrflr3` varchar(100) DEFAULT NULL,\n `sttnbrflr4` varchar(100) DEFAULT NULL,\n `sttnbrunt` varchar(100) DEFAULT NULL,\n `sttnbrunt2` varchar(100) DEFAULT NULL,\n `sttnbrunt3` varchar(100) DEFAULT NULL,\n `sttnbrunt4` varchar(100) DEFAULT NULL,\n `sttstrc` varchar(100) DEFAULT NULL,\n `sttstrc2` varchar(100) DEFAULT NULL,\n `sttstrc3` varchar(100) DEFAULT NULL,\n `sttstrc4` varchar(100) DEFAULT NULL,\n `stttypcns` varchar(100) DEFAULT NULL,\n `stttypcns2` varchar(100) DEFAULT NULL,\n `stttypcns3` varchar(100) DEFAULT NULL,\n `stttypcns4` varchar(100) DEFAULT NULL,\n `stttypuse` varchar(100) DEFAULT NULL,\n `stttypuse2` varchar(100) DEFAULT NULL,\n `stttypuse3` varchar(100) DEFAULT NULL,\n `stttypuse4` varchar(100) DEFAULT NULL,\n `sttyrblt` varchar(100) DEFAULT NULL,\n `sttyrblt2` varchar(100) DEFAULT NULL,\n `sttyrblt3` varchar(100) DEFAULT NULL,\n `sttyrblt4` varchar(100) DEFAULT NULL,\n `subnam` varchar(100) DEFAULT NULL,\n `taxcls` varchar(100) DEFAULT NULL,\n `taxcls2` varchar(100) DEFAULT NULL,\n `taxcls3` varchar(100) DEFAULT NULL,\n `taxcls4` varchar(100) DEFAULT NULL,\n `taxcls5` varchar(100) DEFAULT NULL,\n `taxcls6` varchar(100) DEFAULT NULL,\n `totacr` varchar(100) DEFAULT NULL,\n `totactimpv` varchar(100) DEFAULT NULL,\n `totactlndv` varchar(100) DEFAULT NULL,\n `totactval` varchar(100) DEFAULT NULL,\n `totbsea` varchar(100) DEFAULT NULL,\n `totbseimpa` varchar(100) DEFAULT NULL,\n `totbselnda` varchar(100) DEFAULT NULL,\n `ttd` varchar(100) DEFAULT NULL,\n `usrflda` varchar(100) DEFAULT NULL,\n `usrfldb` varchar(100) DEFAULT NULL,\n `usrfldc` varchar(100) DEFAULT NULL,\n `usrfldd` varchar(100) DEFAULT NULL,\n `valacr` varchar(100) DEFAULT NULL,\n `valacr2` varchar(100) DEFAULT NULL,\n `valacr3` varchar(100) DEFAULT NULL,\n `valacr4` varchar(100) DEFAULT NULL,\n `valacr5` varchar(100) DEFAULT NULL,\n `valacr6` varchar(100) DEFAULT NULL,\n `valact` varchar(100) DEFAULT NULL,\n `valact2` varchar(100) DEFAULT NULL,\n `valact3` varchar(100) DEFAULT NULL,\n `valact4` varchar(100) DEFAULT NULL,\n `valact5` varchar(100) DEFAULT NULL,\n `valact6` varchar(100) DEFAULT NULL,\n `valactchg` varchar(100) DEFAULT NULL,\n `valactchg2` varchar(100) DEFAULT NULL,\n `valactchg3` varchar(100) DEFAULT NULL,\n `valactchg4` varchar(100) DEFAULT NULL,\n `valactchg5` varchar(100) DEFAULT NULL,\n `valactchg6` varchar(100) DEFAULT NULL,\n `valcomchg` varchar(100) DEFAULT NULL,\n `valflag` varchar(100) DEFAULT NULL,\n `valflag2` varchar(100) DEFAULT NULL,\n `valflag3` varchar(100) DEFAULT NULL,\n `valflag4` varchar(100) DEFAULT NULL,\n `valflag5` varchar(100) DEFAULT NULL,\n `valflag6` varchar(100) DEFAULT NULL,\n PRIMARY KEY (`_id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=234318 ;\n" ]
"2013-12-03T16:37:48"
"2013-12-06T15:59:17"
"2013-12-06T15:59:17"
NONE
null
column named _id in database. pwiz returns a model as follows in my example class Jeffco_2009(BaseModel): = IntegerField(db_column='_id') altatd = CharField(null=True)
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/266/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/266/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/265
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/265/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/265/comments
https://api.github.com/repos/coleifer/peewee/issues/265/events
https://github.com/coleifer/peewee/issues/265
23,638,686
MDU6SXNzdWUyMzYzODY4Ng==
265
It would be nice to support nested transactions within commit_on_success
{ "login": "ricoboni", "id": 1664502, "node_id": "MDQ6VXNlcjE2NjQ1MDI=", "avatar_url": "https://avatars.githubusercontent.com/u/1664502?v=4", "gravatar_id": "", "url": "https://api.github.com/users/ricoboni", "html_url": "https://github.com/ricoboni", "followers_url": "https://api.github.com/users/ricoboni/followers", "following_url": "https://api.github.com/users/ricoboni/following{/other_user}", "gists_url": "https://api.github.com/users/ricoboni/gists{/gist_id}", "starred_url": "https://api.github.com/users/ricoboni/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/ricoboni/subscriptions", "organizations_url": "https://api.github.com/users/ricoboni/orgs", "repos_url": "https://api.github.com/users/ricoboni/repos", "events_url": "https://api.github.com/users/ricoboni/events{/privacy}", "received_events_url": "https://api.github.com/users/ricoboni/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Great catch, I'm actually surprised this hasn't come up before!\n", "This has been fixed. See testcase: 54b655c8469fd0f22608ac55f681d99ffab72316\n", "Reopening.\n", "I didn't like my implementation and have re-written it. New code is in 727299c323f97fb3a5c82c2ca88b1a0adb9ad06f and tests in 318ff7b3ca9689a537999cb923845d6d54014514\n", "Seems very nice. Thank you!\n" ]
"2013-12-03T12:17:41"
"2013-12-12T10:06:54"
"2013-12-12T04:52:09"
NONE
null
Sometimes we have an operation that uses itself the `commit_on_success` decorator but it needs to call another operation using `commit_on_success`. The current version just commits the inner part regardless the erros that may occur in the outer part. I've solved this problem as bellow, but maybe it worth to have it integrated on peewee. (And maybe better designed) ``` class CustomMySQLDatabase(peewee.MySQLDatabase): def commit_on_success(self, func): def inner(*args, **kwargs): orig = self.get_autocommit() if self.autocommit and not orig: # Consideramos aqui que estamos ja dentro de uma transacao return func(*args, **kwargs) else: self.set_autocommit(False) self.begin() try: res = func(*args, **kwargs) self.commit() except: self.rollback() raise else: return res finally: self.set_autocommit(orig) return inner ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/265/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/265/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/264
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/264/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/264/comments
https://api.github.com/repos/coleifer/peewee/issues/264/events
https://github.com/coleifer/peewee/issues/264
23,549,865
MDU6SXNzdWUyMzU0OTg2NQ==
264
CSV loader example needs additional import
{ "login": "vincentdavis", "id": 232564, "node_id": "MDQ6VXNlcjIzMjU2NA==", "avatar_url": "https://avatars.githubusercontent.com/u/232564?v=4", "gravatar_id": "", "url": "https://api.github.com/users/vincentdavis", "html_url": "https://github.com/vincentdavis", "followers_url": "https://api.github.com/users/vincentdavis/followers", "following_url": "https://api.github.com/users/vincentdavis/following{/other_user}", "gists_url": "https://api.github.com/users/vincentdavis/gists{/gist_id}", "starred_url": "https://api.github.com/users/vincentdavis/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/vincentdavis/subscriptions", "organizations_url": "https://api.github.com/users/vincentdavis/orgs", "repos_url": "https://api.github.com/users/vincentdavis/repos", "events_url": "https://api.github.com/users/vincentdavis/events{/privacy}", "received_events_url": "https://api.github.com/users/vincentdavis/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[]
"2013-12-02T03:01:00"
"2013-12-02T04:22:48"
"2013-12-02T04:22:48"
NONE
null
So it is obvious that for the CSV loader example to run it needs from peewee import * But it would be nice to add it to the example http://peewee.readthedocs.org/en/latest/peewee/playhouse.html#csv-loader
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/264/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/264/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/263
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/263/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/263/comments
https://api.github.com/repos/coleifer/peewee/issues/263/events
https://github.com/coleifer/peewee/issues/263
23,452,626
MDU6SXNzdWUyMzQ1MjYyNg==
263
Allow asynchronous queries
{ "login": "sametmax", "id": 1673950, "node_id": "MDQ6VXNlcjE2NzM5NTA=", "avatar_url": "https://avatars.githubusercontent.com/u/1673950?v=4", "gravatar_id": "", "url": "https://api.github.com/users/sametmax", "html_url": "https://github.com/sametmax", "followers_url": "https://api.github.com/users/sametmax/followers", "following_url": "https://api.github.com/users/sametmax/following{/other_user}", "gists_url": "https://api.github.com/users/sametmax/gists{/gist_id}", "starred_url": "https://api.github.com/users/sametmax/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/sametmax/subscriptions", "organizations_url": "https://api.github.com/users/sametmax/orgs", "repos_url": "https://api.github.com/users/sametmax/repos", "events_url": "https://api.github.com/users/sametmax/events{/privacy}", "received_events_url": "https://api.github.com/users/sametmax/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "This is an interesting request, but it's so big I'm not sure how to address it. Since I intend to keep compatibility with 2.6 for quite some time, I think it's not really possible. Also, my experience with \"async\" in python has been limited to gevent and I don't feel very comfortable with the new APIs (`yield from`, `Task`, `coroutine`, etc).\n\nDo you have any more thoughts or information to add?\n", "I don't, and I'm not expecting peewee to change any time soon. I am \nvery aware that these things are hard and take time, therefor I'm \nopening this ticket now so the communuty can start the process slowly \nbut early.\n\nI am myself not yet comfortable with asyncio but since I'm forced to \nstart thinking about it in my own work, if I got any idea popping, I'll \ncome back here with a proposal.\n\nLe ven. 29 nov. 2013 05:42:40 CET, Charles Leifer a écrit :\n\n> This is an interesting request, but it's so big I'm not sure how to\n> address it. Since I intend to keep compatibility with 2.6 for quite\n> some time, I think it's not really possible. My experience with\n> \"async\" in python has been limited to gevent and I also don't feel\n> very comfortable with the new APIs (|yield from|, |Task|, |coroutine|,\n> etc).\n> \n> Do you have any more thoughts or information to add?\n> \n> —\n> Reply to this email directly or view it on GitHub\n> https://github.com/coleifer/peewee/issues/263#issuecomment-29496462.\n", "Thanks for the message @sametmax. Based on my understanding of the new asyncio library, I'm going to go out on a limb here and say that I don't think peewee will be adding support.\n- A new \"asyncio-aware\" driver would need to be written for each database.\n- All code that connects to the db and makes queries in peewee would need to be rewritten, i.e. `yield from db.connect(...)`, `yield from db.execute()` and `yield from cursor.fetchXXX()`.\n- Any application using peewee would need to be rewritten where it makes queries: `yield from Model.select().where(...)`\n\nHave a look at the [examples](https://code.google.com/p/tulip/source/browse/examples/fetch1.py) to see how the structure of the application changes when you start using the `yield from` syntax. Using callbacks is no better, IMO.\n", "I understand. Best solution would be to have the common code, such as \nthe query builder, in one module (well, wrapper, since peewee is a one \nfile lib), the sync API code in another module, and the async API code \nin a third module.\n\nAnd allow something like :\n\nfrom peewee import blabla # sync\nfrom peewee.async import blabla # async\n\nOr make peewee decoupled enough so that it's possible to build an async \nlib on top of it wall async_peewee.\n\nBut I get it, it's a lot of work, and when you already have coded the \nORM, how to have the time to do this ? I'm not even offering to do it \nbecause I'm well aware it's so huge.\n\nAnyway, thanks for answering.\n\nLe ven. 29 nov. 2013 17:20:19 CET, Charles Leifer a écrit :\n\n> Thanks for the message @sametmax https://github.com/sametmax. Based\n> on my understanding of the new asyncio library, I'm going to go out on\n> a limb here and say that I don't think peewee will be adding support.\n> - A new \"asyncio-aware\" driver would need to be written for each\n> database.\n> - All code that connects to the db and makes queries in peewee would\n> need to be rewritten, i.e. |yield from db.connect(...)|, |yield\n> from db.execute()| and |yield from cursor.fetchXXX()|.\n> - Any application using peewee would need to be rewritten where it\n> makes queries: |yield from Model.select().where(...)|\n> \n> Have a look at the examples\n> https://code.google.com/p/tulip/source/browse/examples/fetch1.py to\n> see how the structure of the application changes when you start using\n> the |yield from| syntax. Using callbacks is no better, IMO.\n> \n> —\n> Reply to this email directly or view it on GitHub\n> https://github.com/coleifer/peewee/issues/263#issuecomment-29525538.\n", "Just to add to this discussion, I've had positive experiences with the way Guido's NDB handles async operations.\n\nIf in the future you are ever in need of any ideas, here are the docs:\nhttps://developers.google.com/appengine/docs/python/ndb/async\n", "We can use [Trollius](http://trollius.readthedocs.org/) for Py2/3 when needed. Much like asyncio, but it has friendly grammer for Py2(`yield From(do_something())`, `raise Return(value)`).\n", "Thanks a bunch for the links - I will read up on them.\n", "I've just tried a flask+peewee app with uwsgi+gevent+psycogreen.gevent.patch_psycopg -- in theory, this should patch psycopg so that calling code (such as peewee) can use it as if it were still blocking, see https://bitbucket.org/dvarrazzo/psycogreen\n\nWhen I try this, peewee gives me:\n\n```\npeewee.ProgrammingError: execute cannot be used while an asynchronous query is underway\n```\n\nAm I expecting too much?\n", "Strange...I've used psycopg2 with gevent and not had any issues. The code I used was similar to the monkeypatch you linked up @cpbotha . One thing you might check is that the gevent monkeypatch needs to be the first thing that happens.\n\nSo the entry-point to your application would look like this:\n\n``` python\nfrom gevent import monkey\nmonkey.patch_all()\nfrom psycopg2_green_monkeypatch import whatever\nwhatever()\n\n# here begins your actual code...\n```\n", "Thanks for helping me with this!\n\nI already have in my wsgi.py (entry point for uwsgi):\n\n```\nimport gevent\nimport gevent.monkey\ngevent.monkey.patch_all()\n\nimport psycogreen.gevent\npsycogreen.gevent.patch_psycopg()\n\nimport main;main.init();from cnids.app import fapp\n```\n\nWith \"normal\" DB access (RESTful via browser), I see no issues. However, I do see the ProgrammingError exception when I do `ab -c 3 -n 10 URL` (3 concurrent requesters)\n\nAnything else I could look at? (this is with peewee 2.2.3)\n", "Strange... I'm not sure what might be happening.\n", "Seems it has happened before: https://bitbucket.org/dvarrazzo/psycogreen-hg/issue/1/databaseerror-execute-used-with\n\nThe explanation offered is issue would occur when two queries are done using two different cursors on the same database connection. Does that make sense?\n\nThe reporter of that bug then wrote a blog post with a solution http://www.manasupo.com/2012/03/geventpsycopg2-execute-cannot-be-used.html where the simply do the psycopg2 monkey-patching before the fork.\n\nI don't understand why that fixed the problem in their case. In my case, the monkey patching is done before forking, if I may judge by the uwsgi log file (my \"MONKEY PATCHING YEAH!\" output appears once, before the the three worker processes report for duty):\n\n```\nmapped 4368256 bytes (4265 KB) for 300 cores\n*** Operational MODE: preforking+async ***\nMONKEY PATCHING YEAH!\nDatabase migration not required.\nWSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x10035d0 pid: 30745 (default app)\n*** uWSGI is running in multiple interpreter mode ***\nspawned uWSGI master process (pid: 30745)\nspawned uWSGI worker 1 (pid: 30751, cores: 100)\nspawned uWSGI worker 2 (pid: 30752, cores: 100)\nspawned uWSGI worker 3 (pid: 30753, cores: 100)\n*** running gevent loop engine [addr:0x485620] ***\n```\n\nI'm putting this here as a log for future travellers. Any tips would be welcome of course!\n", "In Momoko (Tornado wrapping of psycopg2), they had to build in more explicit handling of busy database connections to work around this issue: https://github.com/Tsumanga-Studios/momoko/commit/e4752c9cbb13e185ae996ce945faa646bd46508c\n\nThis was supposed to be a short experiment to benchmark multi-process uwsgi+flask-peewee against multi-process+asnyc+flask-peewee. I think I should let it go, as they say. :)\n\nThanks in any case!\n", "> The explanation offered is issue would occur when two queries are done using two different cursors on the same database connection. Does that make sense?\n\nAre you using `threadlocals=True` with your database connection? e.g.\n\n``` python\ndb = PostgresqlDatabase('foo', threadlocals=True)\n```\n", "If I could fly over there and buy you a beer I would!!\n\nYou even documented it: https://github.com/coleifer/flask-peewee/blob/master/docs/gevent.rst\n\nI don't understand why my searching didn't take me there, but I'm happy that you've solved it! (in my app.py, I added a 'threalocals' key to the DATABASE configuration dictionary.\n\nWhat impact does that setting have in a non-greened environment?\n\nThanks again,\nCharl\n", "In a non-greened environment if you were using a multi-threaded WSGI server, then your connections would be opened per-thread.\n", "I think we just need a separate package, let's say 'aiopeewee', providing asyncio interface. We're using peewee with Tornado+asyncio, so I think we'll start porting it shortly. Meanwhile we use 'run_in_executor' for performing slow requests asynchronously.\n", "And I'm not sure yet do we actually need porting or just a couple of wrappers and asyncio powered database backend classes.\n", "You will need more than that actually because the nature of the API\nitself is synchronous.\n\nE.G : when you access an attribute in peewee, it can fire an new query:\nproduct.shop.name will make a query to get the shop by default.\n\nYou'll probably need to return a promise for very thing that should\nreturn a an object or queryset.\n\nNow if you do that in a template :\n\n{{ product.shop.name }}\n\nThings get funny, because most template don't have a way to handle\npromises (no callback, no yield, etc).\n\nPlus, there are not just promises, but also deferred and futures,\ndepending of the framework. So you'll need a different backup for the\nasync event loop AND for the result wrapper.\n\nIt's a lot of work, it's hard. But if you do it, peewee will be actually\nthe ONLY Python ORM dealing with these issues properly. And hence, I\ngarantie i will be used much, much more. Technically, you'll be front\npage in python subreddit and hackernews the day of the release.\nEverybody is waiting for something like this, because right now,\neverybody uses hacks (defer to threads, mongodb motor, gevent monkey\npatching...) and big solutions like Django ORM or SQLAlchemy stated\nofficially they didn't want to do it in the current context.\n\nUnfortunatly, I don't know any way to do async with most DB without\nusing a compiled drivers for it. sqlite3 stdlib driver is syncronous if\nI recall, so you won't have the \"wow out of the box experience you\nshould have.\n\nI would make it something la peewee.async, instead of a separate lib. It\nwould make adoption much easier. But maybe that's just me.\n\nLe 26/09/2014 11:18, Alexey a écrit :\n\n> And I'm not sure yet do we actually need porting or just a couple of\n> wrappers and asyncio powered database backend classes.\n> \n> —\n> Reply to this email directly or view it on GitHub\n> https://github.com/coleifer/peewee/issues/263#issuecomment-56938305.\n", "Hi everyone :) I've just published a kind of working proto: https://github.com/05bit/peewee-async\n\nI think basic async support may also be useful, we can deal with related objects by sending explicit prefetch queries. And yes, async queries are difficult to support in templates (without rewriting template engine), so I think it's more suitable for API services where we generally just need to serialise to JSON.\n", "Just published alpha v0.0.2 on PyPi and here's the docs: https://python-aiopeewee.readthedocs.org Interface seems working and simple one and I think it's now rather close to stable version. But internals don't really shine, I've started issue to discuss better integration with peewee: https://github.com/05bit/python-aiopeewee/issues/1\n", "Has anything happened since then?", "Use gevent" ]
"2013-11-28T14:29:52"
"2022-11-22T22:59:36"
"2014-04-05T17:16:42"
NONE
null
Hard one, as peewee has been built on top of synchronous DB driver up untill then, but with Python 3.4 comming and shipping with asyncio + yield from, this can be an interesting for Python 3 users.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/263/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/263/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/262
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/262/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/262/comments
https://api.github.com/repos/coleifer/peewee/issues/262/events
https://github.com/coleifer/peewee/issues/262
23,387,239
MDU6SXNzdWUyMzM4NzIzOQ==
262
Type/Range Checking Input?
{ "login": "twodayslate", "id": 1085707, "node_id": "MDQ6VXNlcjEwODU3MDc=", "avatar_url": "https://avatars.githubusercontent.com/u/1085707?v=4", "gravatar_id": "", "url": "https://api.github.com/users/twodayslate", "html_url": "https://github.com/twodayslate", "followers_url": "https://api.github.com/users/twodayslate/followers", "following_url": "https://api.github.com/users/twodayslate/following{/other_user}", "gists_url": "https://api.github.com/users/twodayslate/gists{/gist_id}", "starred_url": "https://api.github.com/users/twodayslate/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/twodayslate/subscriptions", "organizations_url": "https://api.github.com/users/twodayslate/orgs", "repos_url": "https://api.github.com/users/twodayslate/repos", "events_url": "https://api.github.com/users/twodayslate/events{/privacy}", "received_events_url": "https://api.github.com/users/twodayslate/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Depends on how you're saving that value. If you're calling `Model.save()` then just override the `save` method and add the check there. If you're calling `Model.insert()` you may have to implement it as a check constraint in your db.\n", "Does the option argument not do it?\n", "> Does the option argument not do it?\n\nCould you be more specific which option? Also, how did you plan on inserting these values -- using `Modelsave()` or `Model.insert()`?\n", "I use `Model.create()`\n\nI misspoke. I meant `choices` not `option`. Under the Fields argument list in the API there is a `choices` option. Other libraries I have used have used this as a range feature. `choices=range(1,5)`\n\nI'm in IRC now but I feel like this could help other people as well.\n", "Cool, well since you're using `create()` you can override save:\n\n``` python\nclass MyModel(Model):\n some_val = FloatField()\n\n def save(self, *args, **kwargs):\n if self.some_val < 1 or self.some_val > 5:\n raise ValueError('\"some_val\" must be between 1.0 and 5.0')\n return super(MyModel, self).save(*args, **kwargs)\n```\n\nThe `choices` argument exists solely as metadata and is not validated (either in python or in the database). So even if you used an integral range (which itself doesn't exactly mean \"any floating point between 1.0 and 5.0\") peewee will not complain.\n" ]
"2013-11-27T13:40:28"
"2013-11-27T15:11:21"
"2013-11-27T15:11:21"
NONE
null
Is it possible to do range checking on an insert? For example, when inserting a float it must be between 1.0 and 5.0
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/262/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/262/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/261
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/261/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/261/comments
https://api.github.com/repos/coleifer/peewee/issues/261/events
https://github.com/coleifer/peewee/issues/261
23,351,462
MDU6SXNzdWUyMzM1MTQ2Mg==
261
DDL generation is brittle
{ "login": "coleifer", "id": 119974, "node_id": "MDQ6VXNlcjExOTk3NA==", "avatar_url": "https://avatars.githubusercontent.com/u/119974?v=4", "gravatar_id": "", "url": "https://api.github.com/users/coleifer", "html_url": "https://github.com/coleifer", "followers_url": "https://api.github.com/users/coleifer/followers", "following_url": "https://api.github.com/users/coleifer/following{/other_user}", "gists_url": "https://api.github.com/users/coleifer/gists{/gist_id}", "starred_url": "https://api.github.com/users/coleifer/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/coleifer/subscriptions", "organizations_url": "https://api.github.com/users/coleifer/orgs", "repos_url": "https://api.github.com/users/coleifer/repos", "events_url": "https://api.github.com/users/coleifer/events{/privacy}", "received_events_url": "https://api.github.com/users/coleifer/received_events", "type": "User", "site_admin": false }
[ { "id": 191751, "node_id": "MDU6TGFiZWwxOTE3NTE=", "url": "https://api.github.com/repos/coleifer/peewee/labels/Feature", "name": "Feature", "color": "02e10c", "default": false, "description": null } ]
closed
false
null
[]
null
[ "I can finally close this!\n", "What do you mean?\n", "Sorry, blaming incorrectly. It worked fine. \n" ]
"2013-11-26T22:03:15"
"2014-02-19T18:51:34"
"2014-01-29T14:57:58"
OWNER
null
Currently the DDL generation code is very brittle. The upside is that in the simple case it "just works" and isn't much code. Examples: - #259 - #147 Perhaps the DDL code should be implemented using `QueryCompiler` (or a subclass).
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/261/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/261/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/260
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/260/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/260/comments
https://api.github.com/repos/coleifer/peewee/issues/260/events
https://github.com/coleifer/peewee/issues/260
23,333,821
MDU6SXNzdWUyMzMzMzgyMQ==
260
strict mode
{ "login": "ricardogithub", "id": 3900829, "node_id": "MDQ6VXNlcjM5MDA4Mjk=", "avatar_url": "https://avatars.githubusercontent.com/u/3900829?v=4", "gravatar_id": "", "url": "https://api.github.com/users/ricardogithub", "html_url": "https://github.com/ricardogithub", "followers_url": "https://api.github.com/users/ricardogithub/followers", "following_url": "https://api.github.com/users/ricardogithub/following{/other_user}", "gists_url": "https://api.github.com/users/ricardogithub/gists{/gist_id}", "starred_url": "https://api.github.com/users/ricardogithub/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/ricardogithub/subscriptions", "organizations_url": "https://api.github.com/users/ricardogithub/orgs", "repos_url": "https://api.github.com/users/ricardogithub/repos", "events_url": "https://api.github.com/users/ricardogithub/events{/privacy}", "received_events_url": "https://api.github.com/users/ricardogithub/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Won't the database raise an exception in the event you execute a bad query?\n", "I did not mean handling exceptions triggered by the RDBMS, that is working OK, seems. I meant strictness in the parsing and processing of model definitions, e.g. the following attribute definition: \n\n```\n field = CharField(unigue=True) # misspelled keyword unique\n```\n\nAt run-time I did not get a warning or exception from peewee, and peewee will 'just' generate code for the RDBMS. The created table is not as intended, since the unique index is missing. The program seems to work allright, at first glance, but duplicate records may (and in my case will) occur in the table. \n\nI like Peewee. Great job so far. It may be lightweight, but it should do a proper job :-)\n\nTo summarize: more strict parsing of the model is really useful and needed. \n", "The `kwargs` parameter of a field object's `__init__()` method is being used to populate arbitrary field attributes, so I'm not sure how to add protection against misspellings.\n", "To clarify, since _anything_ could be a valid keyword argument, I'm not sure how to fix this.\n", "A bit challenged by coleifer last remark, I decided to have a look at the peewee code myself. I was struck by the small size of the program, really. It looks good, and as such is a good display of the power of the Python language. \n\nI don't agree that anything could be a valid keyword. Just put all in a dict, and use that dict to check the passed keyword/value pairs. Just by adding a few lines of code to add to the **init** method of the Field class, just before the invocation of the super-method, enables me to signal my misspellings - at least:\n\n```\n for key in kwargs:\n if key not in ['null', 'index', 'unique' .... 'sequence']:\n print \"Error with passed key: \" + key\n```\n\nI left out a few keywords here in this pseudo-code fragment. Anyway, it should be referencing a constant list declared somewhere in top of the program. I think there are some more places in the code that could benefit of this little construct.\n" ]
"2013-11-26T18:10:15"
"2013-11-30T13:30:01"
"2013-11-27T14:06:27"
NONE
null
Writing a Model will generate code for the RDBMS of choice, if the create_table() method is called. I noticed that there seems to be no check on the actual response of the RDBMS. See my issue #259, which illustrated that peewee generates a statements for MySQL, but a faulty one, in that particular example. Is there any possiblity to add a sort of 'strictness' switch to peewee? This 'strictness' should not only apply to feedback from the RDBMS while generating an index, but also help to avoid misspelled words, e.g. unigue in stead of unique, which was not noticed by me until I discovered that the anticipated index creation was not promoted to the database.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/260/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/260/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/259
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/259/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/259/comments
https://api.github.com/repos/coleifer/peewee/issues/259/events
https://github.com/coleifer/peewee/issues/259
23,333,271
MDU6SXNzdWUyMzMzMzI3MQ==
259
unique index on TextField
{ "login": "ricardogithub", "id": 3900829, "node_id": "MDQ6VXNlcjM5MDA4Mjk=", "avatar_url": "https://avatars.githubusercontent.com/u/3900829?v=4", "gravatar_id": "", "url": "https://api.github.com/users/ricardogithub", "html_url": "https://github.com/ricardogithub", "followers_url": "https://api.github.com/users/ricardogithub/followers", "following_url": "https://api.github.com/users/ricardogithub/following{/other_user}", "gists_url": "https://api.github.com/users/ricardogithub/gists{/gist_id}", "starred_url": "https://api.github.com/users/ricardogithub/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/ricardogithub/subscriptions", "organizations_url": "https://api.github.com/users/ricardogithub/orgs", "repos_url": "https://api.github.com/users/ricardogithub/repos", "events_url": "https://api.github.com/users/ricardogithub/events{/privacy}", "received_events_url": "https://api.github.com/users/ricardogithub/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "MySQL is very strange!\n", "I think this should probably be rolled into a larger issue to refactor the DDL generation code.\n", "Closing in favor of 261.\n" ]
"2013-11-26T18:01:06"
"2013-11-26T22:03:35"
"2013-11-26T22:03:35"
NONE
null
MySQL requires a maximum number of characters that will be relevant for an unique index on longtext fields, whilst the actual field may and will be much larger. Seems this is not possible to define in pw while creating a new table. I am not aware of the same issue in supported rdbms, but is there a possibility to add this now already, or in a future release?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/259/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/259/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/258
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/258/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/258/comments
https://api.github.com/repos/coleifer/peewee/issues/258/events
https://github.com/coleifer/peewee/issues/258
23,287,676
MDU6SXNzdWUyMzI4NzY3Ng==
258
Proposal: Peewee should provide a standard definition of database errors and wrap the database driver errors in those
{ "login": "gciding", "id": 769267, "node_id": "MDQ6VXNlcjc2OTI2Nw==", "avatar_url": "https://avatars.githubusercontent.com/u/769267?v=4", "gravatar_id": "", "url": "https://api.github.com/users/gciding", "html_url": "https://github.com/gciding", "followers_url": "https://api.github.com/users/gciding/followers", "following_url": "https://api.github.com/users/gciding/following{/other_user}", "gists_url": "https://api.github.com/users/gciding/gists{/gist_id}", "starred_url": "https://api.github.com/users/gciding/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/gciding/subscriptions", "organizations_url": "https://api.github.com/users/gciding/orgs", "repos_url": "https://api.github.com/users/gciding/repos", "events_url": "https://api.github.com/users/gciding/events{/privacy}", "received_events_url": "https://api.github.com/users/gciding/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Yes, I agree.\n", "I've added standard exceptions and wrapped the connect / close / execute methods to ensure they raise the \"peewee\" version where possible:\n\n2d6f43358ebdacb12a6d7319f3fc2c699f22a053\n" ]
"2013-11-26T01:20:25"
"2013-11-27T22:24:50"
"2013-11-27T22:24:50"
NONE
null
Peewee acts as an ORM and therefore it is not necessary to import the raw/underlying database python library when you create a database. However, if you want to perform tasks that rely on processing underlying errors (such as a databse Integrity Error) you will need to import the underlying database library. To illustrate a situation where it becomes necessary to import `sqlite3` in order to process integrity violations, I have set out a use case. #### Existing Behavior (plahouse.py:Loader) If you wanted to import rows of data and, lets say, one of those rows violated a unique constraint on the table, Peewee will log an error as well as well as raise the _underlying_ exception. So, just say I wanted to ignore duplicates in my import, I could subclass the `Loader` class and override the `load` method: ``` python import sqlite3 from playhouse import Loader class IgnoreDuplicatesLoader(Loader): """ A loader that will continue importing even if it sees a duplicate value. Duplicate Values will be skipped. """ def load(self): if not self.fields: self.analyze_csv() if not self.field_names and not self.has_header: self.field_names = [ 'field_%d' % i for i in range(len(self.fields))] with self.get_reader(self.filename, **self.reader_kwargs) as reader: if not self.field_names: self.field_names = map(self.clean_field_name, reader.next()) elif self.has_header: reader.next() ModelClass = self.get_model_class(self.field_names, self.fields) with self.database.transaction(): ModelClass.create_table(True) for row in reader: try: insert = {} for field_name, value in zip(self.field_names, row): if value: insert[field_name] = value.decode('utf-8') if insert: ModelClass.insert(**insert).execute() except sqlite3.IntegrityError, e: print e print "Continuing..." continue return ModelClass ``` Note that I had to import `sqlite3` in order to catch that error. This means that this module code is now tied to an SQLite implementation, and someone cannot change the DB backend without it breaking. #### Proposed Operation Peewee should raise it's own errors which map to the underlying error raised by the database. So in the above situation, `sqlite3.IntegrityError` would map to `peewee.IntegrityError`
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/258/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/258/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/257
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/257/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/257/comments
https://api.github.com/repos/coleifer/peewee/issues/257/events
https://github.com/coleifer/peewee/issues/257
23,284,719
MDU6SXNzdWUyMzI4NDcxOQ==
257
Playouse - CSV Loader - should accept file object, or handle files in universal-newline mode
{ "login": "gciding", "id": 769267, "node_id": "MDQ6VXNlcjc2OTI2Nw==", "avatar_url": "https://avatars.githubusercontent.com/u/769267?v=4", "gravatar_id": "", "url": "https://api.github.com/users/gciding", "html_url": "https://github.com/gciding", "followers_url": "https://api.github.com/users/gciding/followers", "following_url": "https://api.github.com/users/gciding/following{/other_user}", "gists_url": "https://api.github.com/users/gciding/gists{/gist_id}", "starred_url": "https://api.github.com/users/gciding/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/gciding/subscriptions", "organizations_url": "https://api.github.com/users/gciding/orgs", "repos_url": "https://api.github.com/users/gciding/repos", "events_url": "https://api.github.com/users/gciding/events{/privacy}", "received_events_url": "https://api.github.com/users/gciding/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Agreed, good idea.\n", "Added in 04129b097ceaf0a7a8f93ddff072d8f4b3131348\n" ]
"2013-11-26T00:07:08"
"2013-11-27T22:50:03"
"2013-11-27T22:50:03"
NONE
null
In file `playhouse/csv_loader.py` When you use `load_csv`, it expects a filename of the CSV file. If the CSV file has been saved in a slightly different format with respect to New Lines (which is common with csv files generated by MS Excel), the standard `open(filename, 'r')` won't work. ``` Error: new-line character seen in unquoted field - do you need to open the file in universal-newline mode? ``` The code which opens the provided filename should read `open(filename, 'rU')` or alternatively, you should be able to provide the function a file object.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/257/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/257/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/256
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/256/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/256/comments
https://api.github.com/repos/coleifer/peewee/issues/256/events
https://github.com/coleifer/peewee/issues/256
23,097,019
MDU6SXNzdWUyMzA5NzAxOQ==
256
comments on code
{ "login": "akaRem", "id": 1472728, "node_id": "MDQ6VXNlcjE0NzI3Mjg=", "avatar_url": "https://avatars.githubusercontent.com/u/1472728?v=4", "gravatar_id": "", "url": "https://api.github.com/users/akaRem", "html_url": "https://github.com/akaRem", "followers_url": "https://api.github.com/users/akaRem/followers", "following_url": "https://api.github.com/users/akaRem/following{/other_user}", "gists_url": "https://api.github.com/users/akaRem/gists{/gist_id}", "starred_url": "https://api.github.com/users/akaRem/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/akaRem/subscriptions", "organizations_url": "https://api.github.com/users/akaRem/orgs", "repos_url": "https://api.github.com/users/akaRem/repos", "events_url": "https://api.github.com/users/akaRem/events{/privacy}", "received_events_url": "https://api.github.com/users/akaRem/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Noted, thank you!\n" ]
"2013-11-21T20:57:45"
"2013-11-23T23:29:43"
"2013-11-23T23:29:43"
NONE
null
Could you, please, add more comments on PeeWee's code? You've made very cool and interesting framework. And I'd like to study how it works and get involved into development. But.. in many places its hard to understand which functions do what and why. BTW, Flask-style comments are the best i've ever seen.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/256/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/256/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/255
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/255/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/255/comments
https://api.github.com/repos/coleifer/peewee/issues/255/events
https://github.com/coleifer/peewee/issues/255
23,096,322
MDU6SXNzdWUyMzA5NjMyMg==
255
proposal on QueryCompiler._parse()
{ "login": "akaRem", "id": 1472728, "node_id": "MDQ6VXNlcjE0NzI3Mjg=", "avatar_url": "https://avatars.githubusercontent.com/u/1472728?v=4", "gravatar_id": "", "url": "https://api.github.com/users/akaRem", "html_url": "https://github.com/akaRem", "followers_url": "https://api.github.com/users/akaRem/followers", "following_url": "https://api.github.com/users/akaRem/following{/other_user}", "gists_url": "https://api.github.com/users/akaRem/gists{/gist_id}", "starred_url": "https://api.github.com/users/akaRem/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/akaRem/subscriptions", "organizations_url": "https://api.github.com/users/akaRem/orgs", "repos_url": "https://api.github.com/users/akaRem/repos", "events_url": "https://api.github.com/users/akaRem/events{/privacy}", "received_events_url": "https://api.github.com/users/akaRem/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I'm not sure I agree with this proposal. The \"cost\" of evaluating a SQL expression only occurs once, when the SQL is generated and handed off to the cursor, so I'm not sure I see the need to refactor this for performance. Additionally `isinstance()` is more flexible than calling `type()` because it understands derived classes.\n" ]
"2013-11-21T20:47:53"
"2013-11-23T23:27:21"
"2013-11-23T23:27:21"
NONE
null
You have very long if-elif-elif-...else in QueryCompiler._parse(), where it mostly works with sql, params.. It would be better to use this something like this construction: ``` def non_inline_function(a,b,c): # do some /1 # do some /2 # do some /3 return ('sql', 'pqrams') mapper = { Func: lambda a,b,c: (func_A(a,b), func_B(c)) # very simple, inline Clause: non_inline_function # not simple, defined above Param: ... # etc } # or, may be some variant with closure def parse(node, alias_map, conv): try: sql, params = mapper[type(node)](node, alias_map, conv) except KeyError: # other more common or more complicated situations pass ``` So peewee will not loop over all ef-elif-elif-.. and will use "cached" lambdas (or even not lambdas). It would be speed-up (may be not big, but.. speed-up) with cost of readability (it is possible to make it even more readable). Right now this function is actually dispatches conversions depending on node type, so why not to make it in more traditional way?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/255/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/255/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/254
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/254/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/254/comments
https://api.github.com/repos/coleifer/peewee/issues/254/events
https://github.com/coleifer/peewee/issues/254
22,995,610
MDU6SXNzdWUyMjk5NTYxMA==
254
Peewee now logs Errors that were previously caught
{ "login": "chrismatta", "id": 2523087, "node_id": "MDQ6VXNlcjI1MjMwODc=", "avatar_url": "https://avatars.githubusercontent.com/u/2523087?v=4", "gravatar_id": "", "url": "https://api.github.com/users/chrismatta", "html_url": "https://github.com/chrismatta", "followers_url": "https://api.github.com/users/chrismatta/followers", "following_url": "https://api.github.com/users/chrismatta/following{/other_user}", "gists_url": "https://api.github.com/users/chrismatta/gists{/gist_id}", "starred_url": "https://api.github.com/users/chrismatta/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/chrismatta/subscriptions", "organizations_url": "https://api.github.com/users/chrismatta/orgs", "repos_url": "https://api.github.com/users/chrismatta/repos", "events_url": "https://api.github.com/users/chrismatta/events{/privacy}", "received_events_url": "https://api.github.com/users/chrismatta/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "The only things peewee logs are:\n- debug: log every query\n- error: log queries that result in errors\n\nSo if you do not want these errors, you can just add a null handler to the logger:\n\n``` python\nimport logging\nlogger = logging.getLogger('peewee')\nlogger.addHandler(logging.NullHandler()) # suppress logging\n```\n", "Thanks, do you have any insight in an alternative way to update a record on duplicate keys? \n", "I think the way you're doing it makes sense. Do I need to address anything else regarding the behavior of the logging?\n", "Adding a NullHandler() didn't seem to work, it's still logging every duplicate record insert error, here's my logging section definition in the module that calls the db stuff:\n\n```\nlogging.basicConfig()\npeewee_logger = logging.getLogger('peewee')\npeewee_logger.addHandler(logging.NullHandler())\nlogger = logging.getLogger(__name__)\nlogger.setLevel(logging.INFO)\n```\n", "I use this technique a lot and know that the save() may or may not succeed, that's the whole point of catching it, I don't need to know about the error. I would however like to know about OTHER SQL errors that I may or may not be catching. This seems like I may need to change my technique for updating existing records so as to not run afoul of all these errors.\n", "Turns out I use the other technique (check for existence catch DoesNotExist then create) a lot more, so I just switched over to that. This is fine now, sorry for the trouble.\n", "> Adding a NullHandler() didn't seem to work, it's still logging every duplicate record insert error, here's my logging section definition in the module that calls the db stuff:\n\nYou might try then `peewee_logger.handlers = []`. The logging docs are pretty helpful.\n\n> Turns out I use the other technique (check for existence catch DoesNotExist then create) a lot more, so I just switched over to that. This is fine now, sorry for the trouble.\n\nSounds good!\n", "Attempting to insert a record and relying on the referential integrity of the database to tell you if a row is present is a very common use case. Having peewee spam the logger with this information (especially when it is caught) is silly.\n\nImagine you are inserting 10 million rows into a database. About 10% of your records have duplicate keys in one table or another. Checking before every insert would double the amount of DB queries required to complete the task.\n\nTurning off logging for peewee is a nuclear solution to this issue since it will disable your ability to see any other useful messages. Also setting the level above error would essentially only permit critical messages to pass through.\n\nI really appreciate the detail which peewee uses for the logger and how easy it is to see what's going on. However sending an exception to the logger inside of the library doesn't allow your library user to properly handle the exception. Even though its caught, your logs would still be full of exceptions.\n", "I totally agree with the last comment. I'm fighting with the same issue. I don't want to lose all the error traces just to ignore something that is not an error. \n\nI don't want to miss the oportunity to tell you what a great framework. Good job. Thanks a lot.\n", "> I really appreciate the detail which peewee uses for the logger and how easy it is to see what's going on. However sending an exception to the logger inside of the library doesn't allow your library user to properly handle the exception. Even though its caught, your logs would still be full of exceptions.\n\nWhat would you like to see instead?\n", "I would prefer that peewee did not log the exception to the logger but instead allowed the project that includes peewee to handle and/or log the error.\n\nFrom the perspective of a library which is solely included in another project, peewee should not impair the ability of the project owner to appropriately catch and handle errors. I would expect the library to throw the exception and be done.\n", "> I would prefer that peewee did not log the exception to the logger but instead allowed the project that includes peewee to handle and/or log the error.\n\nThat makes sense to me.\n", "Thank you!\n" ]
"2013-11-20T14:50:19"
"2014-04-01T14:26:52"
"2014-04-01T14:17:10"
NONE
null
I think this has to do with the 2.1.5 `sql_error_handler`. Previously to know if I should update a record I would try a save and catch a MySQL IntegrityError, then I would update any fields in the duplicate record like this: ``` class BaseModel(Model): class Meta: database = mysql_db class User(BaseModel): firstname = CharField(index=True) lastname = CharField(index=True) zipcode = IntegerField() class Meta: db_table = 'user' indexes = ( (('firstname', 'lastname'), True), ) def main(): User.create_table(True) users = [('Joe', 'Dirt', 11111), ('Ron', 'Burgundy', 22222), ('Joe', 'Dirt', 33333)] for user in users: firstname, lastname, zipcode = user user_inst = User(firstname=firstname, lastname=lastname, zipcode=zipcode) try: user_inst.save() except IntegrityError: User.update( zipcode=zipcode ).where( User.firstname == firstname, User.lastname == lastname ).execute() ``` And this still works but now the peewee module is logging SQL errors: ``` ERROR:peewee:Error executing query INSERT INTO `user` (`lastname`, `firstname`, `zipcode`) VALUES (%s, %s, %s) ([u'Dirt', u'Joe', 33333]) ``` I'd rather it didn't log those errors at all, but the only way to suppress them that I can see is to disable peewee logging at the logging.ERROR level and I don't think that's wise. I like this technique better than doing a try `.get()` for each record and inserting on a `DoesNotExist` exception catch, but I don't like all the errors, any way around it?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/254/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/254/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/253
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/253/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/253/comments
https://api.github.com/repos/coleifer/peewee/issues/253/events
https://github.com/coleifer/peewee/issues/253
22,896,572
MDU6SXNzdWUyMjg5NjU3Mg==
253
How to use limit()?
{ "login": "kramer65", "id": 596581, "node_id": "MDQ6VXNlcjU5NjU4MQ==", "avatar_url": "https://avatars.githubusercontent.com/u/596581?v=4", "gravatar_id": "", "url": "https://api.github.com/users/kramer65", "html_url": "https://github.com/kramer65", "followers_url": "https://api.github.com/users/kramer65/followers", "following_url": "https://api.github.com/users/kramer65/following{/other_user}", "gists_url": "https://api.github.com/users/kramer65/gists{/gist_id}", "starred_url": "https://api.github.com/users/kramer65/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/kramer65/subscriptions", "organizations_url": "https://api.github.com/users/kramer65/orgs", "repos_url": "https://api.github.com/users/kramer65/repos", "events_url": "https://api.github.com/users/kramer65/events{/privacy}", "received_events_url": "https://api.github.com/users/kramer65/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I think that's, oddly, correct. I ran this in postgresql:\n\n``` sql\n# select count(*) from entry limit 10;\n count \n-------\n 118\n(1 row)\n```\n\nIf you wrap the select you get what you expect:\n\n``` sql\nselect count(*) from (select 1 from entry limit 10) _;\n count \n-------\n 10\n(1 row)\n```\n\nI added a commit (304c054c99277) so you can accomplish this in peewee:\n\n``` python\nTicket.select().limit(1).wrapped_count(clear_limit=False)\n```\n" ]
"2013-11-19T09:08:00"
"2013-11-19T10:57:00"
"2013-11-19T10:57:00"
NONE
null
I'm trying to use limit as follows: ``` one_ticket = Ticket.select().limit(1) print one_ticket.count() ``` This prints out 5 however. Does anybody know what's wrong here?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/253/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/253/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/252
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/252/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/252/comments
https://api.github.com/repos/coleifer/peewee/issues/252/events
https://github.com/coleifer/peewee/pull/252
22,869,131
MDExOlB1bGxSZXF1ZXN0MTAwNjY2MDY=
252
Allow null column migrations
{ "login": "cam-stitt", "id": 186643, "node_id": "MDQ6VXNlcjE4NjY0Mw==", "avatar_url": "https://avatars.githubusercontent.com/u/186643?v=4", "gravatar_id": "", "url": "https://api.github.com/users/cam-stitt", "html_url": "https://github.com/cam-stitt", "followers_url": "https://api.github.com/users/cam-stitt/followers", "following_url": "https://api.github.com/users/cam-stitt/following{/other_user}", "gists_url": "https://api.github.com/users/cam-stitt/gists{/gist_id}", "starred_url": "https://api.github.com/users/cam-stitt/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/cam-stitt/subscriptions", "organizations_url": "https://api.github.com/users/cam-stitt/orgs", "repos_url": "https://api.github.com/users/cam-stitt/repos", "events_url": "https://api.github.com/users/cam-stitt/events{/privacy}", "received_events_url": "https://api.github.com/users/cam-stitt/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I'm not sure I follow these changes.\n", "I think it can be closed. It was for a specific thing I had been working on but I don't think it is actually needed :)\n" ]
"2013-11-18T21:35:40"
"2014-07-06T01:50:42"
"2013-11-20T00:30:32"
NONE
null
Just a simple option that allows people to force it to try to add the column if null is True. I need this for my migrator at https://github.com/cam-stitt/arnold.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/252/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/252/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/252", "html_url": "https://github.com/coleifer/peewee/pull/252", "diff_url": "https://github.com/coleifer/peewee/pull/252.diff", "patch_url": "https://github.com/coleifer/peewee/pull/252.patch", "merged_at": null }
https://api.github.com/repos/coleifer/peewee/issues/251
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/251/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/251/comments
https://api.github.com/repos/coleifer/peewee/issues/251/events
https://github.com/coleifer/peewee/issues/251
22,785,662
MDU6SXNzdWUyMjc4NTY2Mg==
251
select .. where .. - recursive iterable parsing in where clause
{ "login": "akaRem", "id": 1472728, "node_id": "MDQ6VXNlcjE0NzI3Mjg=", "avatar_url": "https://avatars.githubusercontent.com/u/1472728?v=4", "gravatar_id": "", "url": "https://api.github.com/users/akaRem", "html_url": "https://github.com/akaRem", "followers_url": "https://api.github.com/users/akaRem/followers", "following_url": "https://api.github.com/users/akaRem/following{/other_user}", "gists_url": "https://api.github.com/users/akaRem/gists{/gist_id}", "starred_url": "https://api.github.com/users/akaRem/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/akaRem/subscriptions", "organizations_url": "https://api.github.com/users/akaRem/orgs", "repos_url": "https://api.github.com/users/akaRem/repos", "events_url": "https://api.github.com/users/akaRem/events{/privacy}", "received_events_url": "https://api.github.com/users/akaRem/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Do you mind trying this out?\n\n``` python\nparam = Param([(1, 2), (3, 4)])\nprint MyModel.select().where(MyModel.some_tree == param).sql()\n```\n", "@coleifer \n\nThis does not convert param (1):\n\n```\np = peewee.Param([1,2])\nprint MyModel.select().where(MyModel.some_tree == p).sql()\n\n('SELECT t1.\"id\", t1.\"some_value\", t1.\"some_tree\" FROM \"mymodel\" AS t1 WHERE (t1.\"some_tree\" = %s)', [[1, 2]])\n```\n\nThis does convert param (2):\n\n```\np = peewee.Param(MyModel.some_tree.db_value([1,2]))\nprint MyModel.select().where(MyModel.some_tree == p).sql()\n\n('SELECT t1.\"id\", t1.\"some_value\", t1.\"some_tree\" FROM \"mymodel\" AS t1 WHERE (t1.\"some_tree\" = %s)', ['000001.000002'])\n```\n\nThis fails on trying to convert converted value (as expected) (3): \n\n```\np = MyModel.some_tree.db_value([1,2])\nprint MyModel.select().where(MyModel.some_tree == p).sql()\n```\n\nYes, I found the working way for this query (2), but it looks too verbose.\n`Param` is good and it works as expected in all cases (1-2).\n\nBut I still think that behavior of `.where(field == value)` is not evident. And this operator shall just cast `value` to `db_value` (and not iterate over it) as `.where(field << iterable)` shall iterate over `iterable` once and not recursive.\nWhat do you think?\n", "The reason why `.where(field << value)` is recursive is because it needs to handle the (fairly common) case of subqueries, i.e. `WHERE id IN (SELECT ...)`.\n\nI'll look into this some more and see if there's a better fix, though.\n", "@coleifer \nI think that the most sane way is to check types in every operator, which may (by design) handle pythonic value:\n- subclass of `Node` -> handle like `Node`\n- `iterable` in places where iterables are ok -> iterate\n- everything else -> cast to db_value\n", "Adding the context \"where iterables are ok\" is what concerns me about that plan.\n", "@coleifer \n\nIve made some monkey-patch draft for this problem.\n\n```\n# -*- coding: utf-8 -*-\nfrom psycopg2ct import compat\n\ncompat.register()\n\nimport peewee\n\n\ndef patch():\n list_to_cast = ['__eq__']\n list_to_map = ['__lshift__']\n\n patched = {}\n\n def mutate_with_cast(op):\n original = peewee.Node.__dict__[op]\n\n def mutated(self, rhs):\n if not isinstance(rhs, peewee.Node):\n rhs = peewee.Param(self.db_value(rhs))\n return original(self, rhs)\n\n patched[op] = mutated\n\n def mutate_with_map(op):\n original = peewee.Node.__dict__[op]\n\n def mutated(self, rhs):\n rhs = [i if isinstance(i, peewee.Node) else peewee.Param(self.db_value(i)) for i in rhs]\n return original(self, rhs)\n\n patched[op] = mutated\n\n map(mutate_with_cast, list_to_cast)\n map(mutate_with_map, list_to_map)\n\n peewee.Node.__dict__.update(patched)\n\n\npatch()\n\nimport playhouse.postgres_ext as pp\n\n\nclass IntLTreeField(peewee.Field):\n db_field = 'ltree'\n template = '%(column_type)s'\n\n def field_attributes(self):\n return {\n 'length': 6,\n }\n\n def db_value(self, value):\n formatter = \"{{:0{length:}}}\".format(**self.attributes)\n return '.'.join(map(formatter.format, value))\n\n def python_value(self, value):\n return map(int, value.split('.'))\n\n\npp.PostgresqlExtDatabase.register_fields({'ltree': 'LTREE'})\n\ndb = pp.PostgresqlExtDatabase('mydb')\n\n\nclass MyModel(peewee.Model):\n class Meta:\n database = db\n\n some_value = peewee.IntegerField()\n some_tree = IntLTreeField(length=6)\n\n\nprint MyModel.select().where(MyModel.some_tree == [1, 2]).sql()\nprint MyModel.select().where(MyModel.some_tree << [[1, 2], [2, 3]]).sql()\n```\n\nOutputs:\n\n```\n ('SELECT t1.\"id\", t1.\"some_value\", t1.\"some_tree\" FROM \"mymodel\" AS t1 WHERE (t1.\"some_tree\" = %s)', ['000001.000002'])\n ('SELECT t1.\"id\", t1.\"some_value\", t1.\"some_tree\" FROM \"mymodel\" AS t1 WHERE (t1.\"some_tree\" IN (%s, %s))', ['000001.000002', '000002.000003'])\n```\n\nLooks like it work. :)\n\n.. but it needs to add each op into corresponding list to patch. \n.. and to rewrite some mappings depending on import style. \n\nWhat do you think?\n", "That's definitely an approach I had not thought of. I do have a concern, though, about changing the data at the time the expression is evaluated in python. My preference w/the 2.0 rewrite has been to do these kinds of things in the `QueryCompiler`. I understand that the way the `QueryCompiler` handles lists is not ideal for situations where you're trying to pass the list to `db_value`, however I'd rather not change the data at expression evaluation time.\n", "Why not? If you compare 2 **complicated** values where one is a db-type, and other is a py-type, then one of them shall be casted to proper type (or at least to good type for query placeholders). \n\nThe questions are: which of them shall be casted (A), and who is responsible for that (B)?\n\nA. When we prepare query for db, it's obvious, that all shall be casted into db-values. When we getting something from db, we convert it into py-value. And not vice-versa.\n\nB. We have (as i suppose) 4 places, where these values can be converted:\n1) somewhere inside db or in query line;\n2) somewhere inside peewee, when query is about to execute;\n3) somewhere inside peewee, when query is building;\n4) manually.\n\nThe 1-st is bad.Because we use db as data-storage and we try not to move any business-logic into it. Also, unreasonable complicated queries are not good. Ex:\n\nTheese queries\n\n```\nSELECT * FROM my_table WHERE tree ~ \"%s.%s.%s\".%s\".%s.%s\" ::ltree\nSELECT * FROM my_table WHERE tree ~ \"%s.%s.%s\".%s\".%s\" ::ltree\nSELECT * FROM my_table WHERE tree ~ \"%s.%s\" ::ltree\n```\n\nare the same as this:\n\n```\nSELECT * FROM my_table WHERE tree ~ \"%s\" ::ltree \n```\n\nThe 2-nd is bad too, because we need to \"remember\" conversion functions for each field of each model involved into query. It complicates peewee's logic and brings lots of unnecessary overheads. \nThe 3-rd is better, because we convert and 'freeze' parameters right at the place and time, when and where we build query.\nThe 4-th - Manual operations - ? No. \n", "So the crux of the problem is that peewee handles lists differently than other values. You want to be able to pass the list unmodified into the `db_value()` method of the field. There is a mechanism for that (`Param`) but it isn't doing the right thing -- I think the fix is to make `Param` use `db_value()` when possible.\n\nWhat do you think?\n\n``` diff\ndiff --git a/peewee.py b/peewee.py\nindex 2386dab..8ab17c0 100644\n--- a/peewee.py\n+++ b/peewee.py\n@@ -45,6 +45,7 @@ __all__ = [\n 'JOIN_LEFT_OUTER',\n 'Model',\n 'MySQLDatabase',\n+ 'Param',\n 'PostgresqlDatabase',\n 'prefetch',\n 'PrimaryKeyField',\n@@ -838,6 +839,7 @@ class QueryCompiler(object):\n node.nodes, alias_map, conv, ' ')\n elif isinstance(node, Param):\n params = [node.value]\n+ unknown = True\n elif isinstance(node, R):\n sql = node.value\n params = []\n```\n\nThe way you would use it would be:\n\n``` python\nfrom peewee import *\n\nclass IntLTreeField(Field):\n db_field = 'ltree'\n template = '%(column_type)s'\n\n def field_attributes(self):\n return {'length': 6}\n\n def db_value(self, value):\n formatter = \"{{:0{length:}}}\".format(**self.attributes)\n return '.'.join(map(formatter.format, value))\n\n def python_value(self, value):\n return map(int, value.split('.'))\n\nclass MyModel(Model):\n some_tree = IntLTreeField()\n\nprint MyModel.select().where(MyModel.some_tree == Param([1, 2])).sql()\ntrees = [\n Param([1, 2]),\n Param([3, 4])]\nprint MyModel.select().where(MyModel.some_tree << trees).sql()\n```\n\nPrints:\n('SELECT t1.\"id\", t1.\"some_tree\" FROM \"mymodel\" AS t1 WHERE (t1.\"some_tree\" = ?)', ['000001.000002'])\n('SELECT t1.\"id\", t1.\"some_tree\" FROM \"mymodel\" AS t1 WHERE (t1.\"some_tree\" IN (?, ?))', ['000001.000002', '000003.000004'])\n", "Added in 51c949c7a7d5f8969ef77611c2c8016b692df00b\n", "I like it!\n", "Cool, thanks for talking this one through w/me!\n" ]
"2013-11-16T21:50:09"
"2013-11-20T16:49:14"
"2013-11-20T16:41:09"
NONE
null
Im on Mac OS X 10.9 with PyPy 2.1.0 and PostgreSQL 9.3.1, having peewee 2.1.5 and psycopg2ct 2.4.4 I study how peewee builds SQL strings Trying to implement postgresql's ltree: ``` class IntLTreeField(peewee.Field): db_field = 'ltree' template = '%(column_type)s' def field_attributes(self): return { 'length': 6, } def db_value(self, value): formatter = "{{:0{length:}}}".format(**self.attributes) return '.'.join(map(formatter.format, value)) def python_value(self, value): return map(int, value.split('.')) ``` Then - watch the SQL: ``` print MyModel.select().where(MyModel.some_tree == [(1,2),(3,4)]).sql() ``` Stacktrace: ``` /Users/user/Projects/pypy/bin/pypy /Users/user/Projects/pypy-flask/peewee-test.py ('SELECT t1."id", t1."some_value", t1."some_tree" FROM "mymodel" AS t1 WHERE (t1."some_value" = %s)', [6]) CREATE TABLE "mymodel" ("id" INTEGER NOT NULL PRIMARY KEY, "some_value" INTEGER NOT NULL, "some_tree" LTREE NOT NULL) Traceback (most recent call last): File "app_main.py", line 72, in run_toplevel File "/Users/user/Projects/pypy-flask/peewee-test.py", line 60, in <module> print MyModel.select().where(MyModel.some_tree == [(1,2),(3,4)]).sql() File "/Users/user/Projects/pypy/site-packages/peewee.py", line 1686, in sql 1 return self.compiler().generate_select(self) File "/Users/user/Projects/pypy/site-packages/peewee.py", line 987, in generate_select where, w_params = self.parse_query_node(query._where, alias_map) File "/Users/user/Projects/pypy/site-packages/peewee.py", line 905, in parse_query_node return self.parse_node(node, alias_map) File "/Users/user/Projects/pypy/site-packages/peewee.py", line 863, in parse_node sql, params, unknown = self._parse(node, alias_map, conv) File "/Users/user/Projects/pypy/site-packages/playhouse/postgres_ext.py", line 140, in _parse node, alias_map, conv) File "/Users/user/Projects/pypy/site-packages/peewee.py", line 819, in _parse rhs, rparams = self.parse_node(node.rhs, alias_map, conv) File "/Users/user/Projects/pypy/site-packages/peewee.py", line 863, in parse_node sql, params, unknown = self._parse(node, alias_map, conv) File "/Users/user/Projects/pypy/site-packages/playhouse/postgres_ext.py", line 140, in _parse node, alias_map, conv) File "/Users/user/Projects/pypy/site-packages/peewee.py", line 847, in _parse sql, params = self.parse_node_list(node, alias_map, conv) File "/Users/user/Projects/pypy/site-packages/peewee.py", line 880, in parse_node_list node_sql, node_params = self.parse_node(node, alias_map, conv) File "/Users/user/Projects/pypy/site-packages/peewee.py", line 863, in parse_node sql, params, unknown = self._parse(node, alias_map, conv) File "/Users/user/Projects/pypy/site-packages/playhouse/postgres_ext.py", line 140, in _parse node, alias_map, conv) File "/Users/user/Projects/pypy/site-packages/peewee.py", line 847, in _parse sql, params = self.parse_node_list(node, alias_map, conv) File "/Users/user/Projects/pypy/site-packages/peewee.py", line 880, in parse_node_list node_sql, node_params = self.parse_node(node, alias_map, conv) File "/Users/user/Projects/pypy/site-packages/peewee.py", line 865, in parse_node params = [conv.db_value(i) for i in params] File "/Users/user/Projects/pypy-flask/peewee-test.py", line 32, in db_value return '.'.join(map(formatter.format, value)) TypeError: 'int' object is not iterable Process finished with exit code 1 ``` .. `MyModel.select().where(MyModel.some_tree == [1,2]).sql()` raises too; and even with `[((1,2),),((3,4),)]` or `[1,2]` The problem looks like parser tries to recursive convert each item from each nested iterable in db_value(..). And it tries to make SQL like this: `SELECT ... FROM ... WHERE "some_tree" = (({1},{2}),({3},{4}))` (here `{1}` means `MyModel.some_tree.db_value(1))`. I don't know if `((1,2),(3,4))` is Ok in `WHERE` clause in PostgreSQL, but I've never seen constructions like this before.. Also it makes impossible to use iterables as python representation of db values at all.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/251/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/251/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/250
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/250/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/250/comments
https://api.github.com/repos/coleifer/peewee/issues/250/events
https://github.com/coleifer/peewee/issues/250
22,784,028
MDU6SXNzdWUyMjc4NDAyOA==
250
playhouse PostgresqlExtDatabase/PostgresqlExtCompiler
{ "login": "akaRem", "id": 1472728, "node_id": "MDQ6VXNlcjE0NzI3Mjg=", "avatar_url": "https://avatars.githubusercontent.com/u/1472728?v=4", "gravatar_id": "", "url": "https://api.github.com/users/akaRem", "html_url": "https://github.com/akaRem", "followers_url": "https://api.github.com/users/akaRem/followers", "following_url": "https://api.github.com/users/akaRem/following{/other_user}", "gists_url": "https://api.github.com/users/akaRem/gists{/gist_id}", "starred_url": "https://api.github.com/users/akaRem/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/akaRem/subscriptions", "organizations_url": "https://api.github.com/users/akaRem/orgs", "repos_url": "https://api.github.com/users/akaRem/repos", "events_url": "https://api.github.com/users/akaRem/events{/privacy}", "received_events_url": "https://api.github.com/users/akaRem/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "The problem is in how you're instantiating the compiler. Try this instead, it will work:\n\n``` python\ncompiler = db.compiler()\nprint compiler.create_table(MyModel)\n```\n", "@coleifer Thanks! It works.\n", "Awesome!\n" ]
"2013-11-16T20:10:34"
"2013-11-17T13:09:29"
"2013-11-16T22:55:37"
NONE
null
Im on Mac OS X 10.9 with PyPy 2.1.0 and PostgreSQL 9.3.1, having peewee 2.1.5 and psycopg2ct 2.4.4 I study how peewee builds SQL strings When I trying to use Postgres extension like this: ``` # -*- coding: utf-8 -*- from psycopg2ct import compat compat.register() import peewee as pw import playhouse.postgres_ext as pp db = pp.PostgresqlExtDatabase('mydb') class MyModel(pw.Model): class Meta: database = db some_value = pw.IntegerField() some_uuid = pp.UUIDField() print pp.PostgresqlExtCompiler().create_table(MyModel) ``` I Have this error message: ``` /Users/user/Projects/pypy/bin/pypy /Users/user/Projects/pypy-flask/pp-test.py Traceback (most recent call last): File "app_main.py", line 72, in run_toplevel File "/Users/user/Projects/pypy-flask/pp-test.py", line 17, in <module> print pp.PostgresqlExtCompiler().create_table(MyModel) File "/Users/user/Projects/pypy/site-packages/peewee.py", line 1102, in create_table return ' '.join(self.create_table_sql(model_class, safe)) File "/Users/user/Projects/pypy/site-packages/peewee.py", line 1093, in create_table_sql columns = map(self.field_sql, meta.get_fields()) File "/Users/user/Projects/pypy/site-packages/peewee.py", line 1061, in field_sql attrs['column_type'] = self.get_field(field.get_db_field()) File "/Users/user/Projects/pypy/site-packages/peewee.py", line 795, in get_field return self._field_map[f] KeyError: 'uuid' Process finished with exit code 1 ``` These errors go away if I add `'uuid'` to `PostgresqlExtCompiler.field_map`: ``` # -*- coding: utf-8 -*- from psycopg2ct import compat compat.register() import peewee as pw import playhouse.postgres_ext as pp pp.PostgresqlExtCompiler().field_map['uuid'] = 'UUID' db = pp.PostgresqlExtDatabase('mydb') class MyModel(pw.Model): class Meta: database = db some_value = pw.IntegerField() some_uuid = pp.UUIDField() print pp.PostgresqlExtCompiler().create_table(MyModel) # but this also patches pw.QueryCompiler: import pprint pprint.pprint(pw.QueryCompiler.field_map) /Users/user/Projects/pypy/bin/pypy /Users/user/Projects/pypy-flask/pp-test.py CREATE TABLE "mymodel" ("id" INTEGER NOT NULL PRIMARY KEY, "some_value" INTEGER NOT NULL, "some_uuid" UUID NOT NULL) {'bigint': 'BIGINT', 'blob': 'BLOB', 'bool': 'SMALLINT', 'date': 'DATE', 'datetime': 'DATETIME', 'decimal': 'DECIMAL', 'double': 'REAL', 'float': 'REAL', 'int': 'INTEGER', 'primary_key': 'INTEGER', 'string': 'VARCHAR', 'text': 'TEXT', 'time': 'TIME', 'uuid': 'UUID'} Process finished with exit code 0 ``` **The question is:** Am I doing something wrong? Or is it really need to add custom field types to `QueryCompiler`? Or is it a bug in `PostgresqlExtDatabase.register_fields(...)` (or, may be, somewhere else)?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/250/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/250/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/249
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/249/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/249/comments
https://api.github.com/repos/coleifer/peewee/issues/249/events
https://github.com/coleifer/peewee/issues/249
22,673,306
MDU6SXNzdWUyMjY3MzMwNg==
249
How to do an internal reference to the model itself?
{ "login": "kramer65", "id": 596581, "node_id": "MDQ6VXNlcjU5NjU4MQ==", "avatar_url": "https://avatars.githubusercontent.com/u/596581?v=4", "gravatar_id": "", "url": "https://api.github.com/users/kramer65", "html_url": "https://github.com/kramer65", "followers_url": "https://api.github.com/users/kramer65/followers", "following_url": "https://api.github.com/users/kramer65/following{/other_user}", "gists_url": "https://api.github.com/users/kramer65/gists{/gist_id}", "starred_url": "https://api.github.com/users/kramer65/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/kramer65/subscriptions", "organizations_url": "https://api.github.com/users/kramer65/orgs", "repos_url": "https://api.github.com/users/kramer65/repos", "events_url": "https://api.github.com/users/kramer65/events{/privacy}", "received_events_url": "https://api.github.com/users/kramer65/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Check out http://peewee.readthedocs.org/en/latest/peewee/models.html#self-referential-foreign-keys\n\ntl;dr\n\n``` python\nadded_by = ForeignKeyField('self', related_name='users_created')\n```\n" ]
"2013-11-14T16:20:41"
"2013-11-14T17:16:10"
"2013-11-14T17:16:10"
NONE
null
I'm building a website in which Admins (which are of course also regular Users) can add new users. For this reason, my User model looks something like this: ``` class User(db.Model, BaseUser): username = CharField() password = CharField() added_by = ForeignKeyField(User, related_name='users_created') ``` Unfortunately, this throws a `NameError: name 'User' is not defined.` Is there a way to do this using peewee?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/249/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/249/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/248
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/248/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/248/comments
https://api.github.com/repos/coleifer/peewee/issues/248/events
https://github.com/coleifer/peewee/issues/248
22,414,215
MDU6SXNzdWUyMjQxNDIxNQ==
248
How to select on basis of ForeignKeyField.attribute == 'something'
{ "login": "kerqicce", "id": 5898015, "node_id": "MDQ6VXNlcjU4OTgwMTU=", "avatar_url": "https://avatars.githubusercontent.com/u/5898015?v=4", "gravatar_id": "", "url": "https://api.github.com/users/kerqicce", "html_url": "https://github.com/kerqicce", "followers_url": "https://api.github.com/users/kerqicce/followers", "following_url": "https://api.github.com/users/kerqicce/following{/other_user}", "gists_url": "https://api.github.com/users/kerqicce/gists{/gist_id}", "starred_url": "https://api.github.com/users/kerqicce/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/kerqicce/subscriptions", "organizations_url": "https://api.github.com/users/kerqicce/orgs", "repos_url": "https://api.github.com/users/kerqicce/repos", "events_url": "https://api.github.com/users/kerqicce/events{/privacy}", "received_events_url": "https://api.github.com/users/kerqicce/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "You're close, but you will need to perform a join. Check out the docs on joining: http://peewee.readthedocs.org/en/latest/peewee/querying.html#joining-tables\n\n``` python\nresult = Secondary.select().join(Primary).where(Primary.prim_attr == 'something')\n```\n" ]
"2013-11-10T18:39:53"
"2013-11-10T22:55:13"
"2013-11-10T22:55:13"
NONE
null
I have two models: ``` class Primary(db.Model): prim_attr = CharField() class Secondary(db.Model): primary = ForeignKeyField(Primary, related_name='secondaries') sec_attr = IntegerField() ``` I want to get all secondary items where the primary.prim_attr equals 'something'. So I tried to do like this: ``` result = Secondary.select().where(Secondary.primary.prim_attr == 'something') ``` But I get an error: AttributeError: 'ForeignKeyField' object has no attribute 'prim_attr'. I can get the Primary object first, and then insert in the second query like this: ``` result = Secondary.select().where(Secondary.primary == primaryObject) ``` But it is easier if I can do it in one line. Is that possible?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/248/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/248/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/247
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/247/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/247/comments
https://api.github.com/repos/coleifer/peewee/issues/247/events
https://github.com/coleifer/peewee/issues/247
22,405,658
MDU6SXNzdWUyMjQwNTY1OA==
247
How to return choice of a IntegerField as string?
{ "login": "kerqicce", "id": 5898015, "node_id": "MDQ6VXNlcjU4OTgwMTU=", "avatar_url": "https://avatars.githubusercontent.com/u/5898015?v=4", "gravatar_id": "", "url": "https://api.github.com/users/kerqicce", "html_url": "https://github.com/kerqicce", "followers_url": "https://api.github.com/users/kerqicce/followers", "following_url": "https://api.github.com/users/kerqicce/following{/other_user}", "gists_url": "https://api.github.com/users/kerqicce/gists{/gist_id}", "starred_url": "https://api.github.com/users/kerqicce/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/kerqicce/subscriptions", "organizations_url": "https://api.github.com/users/kerqicce/orgs", "repos_url": "https://api.github.com/users/kerqicce/repos", "events_url": "https://api.github.com/users/kerqicce/events{/privacy}", "received_events_url": "https://api.github.com/users/kerqicce/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Typically I store my choices in a class-level constant so they are easier to access and compare against:\n\n``` python\n\nclass Something(Model):\n FOO_YES = 1\n FOO_NO = 2\n FOO_CHOICES = (\n (FOO_YES, 'Yes'),\n (FOO_NO, 'No'))\n foo = IntegerField(choices=FOO_CHOICES)\n\n def __unicode__(self):\n return dict(self.FOO_CHOICES)[self.foo]\n```\n", "Thanks to you. That is a super good tip! I am going to use it immediately!!\n" ]
"2013-11-10T12:01:40"
"2013-11-10T17:45:20"
"2013-11-10T14:43:00"
NONE
null
I have one table with an IntegerField and in it two choices: ``` class Something(db.Model): myattr = IntegerField(choices=((1, 'option one'), (2, 'option two'))) def __unicode__(self): return myattr ``` The **unicode**() method obviously just return the integer 1 or 2. How can I return strings of the choices ('option one' or 'option two')? Thank you
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/247/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/247/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/246
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/246/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/246/comments
https://api.github.com/repos/coleifer/peewee/issues/246/events
https://github.com/coleifer/peewee/issues/246
22,394,814
MDU6SXNzdWUyMjM5NDgxNA==
246
How to create conditional transactions?
{ "login": "kerqicce", "id": 5898015, "node_id": "MDQ6VXNlcjU4OTgwMTU=", "avatar_url": "https://avatars.githubusercontent.com/u/5898015?v=4", "gravatar_id": "", "url": "https://api.github.com/users/kerqicce", "html_url": "https://github.com/kerqicce", "followers_url": "https://api.github.com/users/kerqicce/followers", "following_url": "https://api.github.com/users/kerqicce/following{/other_user}", "gists_url": "https://api.github.com/users/kerqicce/gists{/gist_id}", "starred_url": "https://api.github.com/users/kerqicce/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/kerqicce/subscriptions", "organizations_url": "https://api.github.com/users/kerqicce/orgs", "repos_url": "https://api.github.com/users/kerqicce/repos", "events_url": "https://api.github.com/users/kerqicce/events{/privacy}", "received_events_url": "https://api.github.com/users/kerqicce/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Check your database's documentation on `SELECT FOR UPDATE` ([link to peewee docs](http://peewee.readthedocs.org/en/latest/peewee/api.html#SelectQuery.for_update)).\n\nIf you're using postgres, here are some docs. http://www.postgresql.org/docs/9.0/static/sql-select.html#SQL-FOR-UPDATE-SHARE\n\nDoes this answer your question?\n", "Thank you very much for the information. This is a perfect answers to my question!\n\nI have never worked with FOR UPDATE before, but I will read in the PostgreSQL documentation about it. Do I need any addon to peewee for this, or will it work with PostgreSQL out of the box?\n\nDo you know if there is any peewee example code using for_update?\n", "It will work out of the box. The tests are the only place there is example code for this feature, around line 3085.\n" ]
"2013-11-09T22:07:57"
"2013-11-10T14:40:47"
"2013-11-10T14:40:47"
NONE
null
Hello Coleifer. Thank you for creating so good software, we love using it! Today we looked at code in which we need to make something like conditional transactions. I do not know if that is an official name, but for us this means that we want to check if a certain value is present in the database. If it is, we want to do some insert, and if it is not, we want to do a different insert. But in the time between the read and the insert, a different process could have inserted the searched for record, which would create inconsistencies. My question being: we can include the select into the transaction like in the code below. This seems to work, but will that indeed make the select, the if statement, and the write all together atomic? In other wording; will this make it impossible to insert a user with username 'someUserName' between the read, and the write? ``` with db.transaction(): result = User.select().where(User.username == 'someUserName') if result.count() == 0: insertObj = Something() insertObj.someattr = 123 insertObj.save() elif result.count() == 1: insertObj = Something() insertObj.someattr = 456 insertObj.save() ``` Also: is using result.count() the correct way to see if there is one occurrence, or is there a better/faster/more efficient way?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/246/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/246/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/245
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/245/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/245/comments
https://api.github.com/repos/coleifer/peewee/issues/245/events
https://github.com/coleifer/peewee/issues/245
22,382,883
MDU6SXNzdWUyMjM4Mjg4Mw==
245
Redundant __future__ import
{ "login": "tyteen4a03", "id": 440015, "node_id": "MDQ6VXNlcjQ0MDAxNQ==", "avatar_url": "https://avatars.githubusercontent.com/u/440015?v=4", "gravatar_id": "", "url": "https://api.github.com/users/tyteen4a03", "html_url": "https://github.com/tyteen4a03", "followers_url": "https://api.github.com/users/tyteen4a03/followers", "following_url": "https://api.github.com/users/tyteen4a03/following{/other_user}", "gists_url": "https://api.github.com/users/tyteen4a03/gists{/gist_id}", "starred_url": "https://api.github.com/users/tyteen4a03/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/tyteen4a03/subscriptions", "organizations_url": "https://api.github.com/users/tyteen4a03/orgs", "repos_url": "https://api.github.com/users/tyteen4a03/repos", "events_url": "https://api.github.com/users/tyteen4a03/events{/privacy}", "received_events_url": "https://api.github.com/users/tyteen4a03/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "This is not fixed in tests.py.\n" ]
"2013-11-09T09:10:11"
"2013-11-12T04:31:16"
"2013-11-09T17:02:03"
NONE
null
Since Peewee supports Python 2.6+, the `from __future__ import with_statement` is unnecessary.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/245/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/245/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/244
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/244/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/244/comments
https://api.github.com/repos/coleifer/peewee/issues/244/events
https://github.com/coleifer/peewee/issues/244
21,949,259
MDU6SXNzdWUyMTk0OTI1OQ==
244
Presumably internal debug message gets printed to stderr
{ "login": "pitchforks", "id": 4378791, "node_id": "MDQ6VXNlcjQzNzg3OTE=", "avatar_url": "https://avatars.githubusercontent.com/u/4378791?v=4", "gravatar_id": "", "url": "https://api.github.com/users/pitchforks", "html_url": "https://github.com/pitchforks", "followers_url": "https://api.github.com/users/pitchforks/followers", "following_url": "https://api.github.com/users/pitchforks/following{/other_user}", "gists_url": "https://api.github.com/users/pitchforks/gists{/gist_id}", "starred_url": "https://api.github.com/users/pitchforks/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/pitchforks/subscriptions", "organizations_url": "https://api.github.com/users/pitchforks/orgs", "repos_url": "https://api.github.com/users/pitchforks/repos", "events_url": "https://api.github.com/users/pitchforks/events{/privacy}", "received_events_url": "https://api.github.com/users/pitchforks/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Peewee supports logging using python's standard library logging module. The logger can help you debug queries and also supports logging exceptions executing queries. Python docs have you covered: \n\nhttp://docs.python.org/3.1/library/logging.html#configuring-logging-for-a-library\n" ]
"2013-11-01T09:57:46"
"2013-11-01T13:41:36"
"2013-11-01T13:41:36"
NONE
null
Few days ago I have upgraded from 2.1.4 to 2.1.5 and now everytime my CLI program runs, it dumps this line to stdout: ``` No handlers could be found for logger "peewee" ``` I have searched for this text in the sources for 2.1.5 but didn't find anything. This looks related to logging module but my own program doesn't make use of logging module at all.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/244/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/244/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/243
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/243/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/243/comments
https://api.github.com/repos/coleifer/peewee/issues/243/events
https://github.com/coleifer/peewee/issues/243
21,467,490
MDU6SXNzdWUyMTQ2NzQ5MA==
243
Model cache being inconsistent when the value is set by id
{ "login": "ricoboni", "id": 1664502, "node_id": "MDQ6VXNlcjE2NjQ1MDI=", "avatar_url": "https://avatars.githubusercontent.com/u/1664502?v=4", "gravatar_id": "", "url": "https://api.github.com/users/ricoboni", "html_url": "https://github.com/ricoboni", "followers_url": "https://api.github.com/users/ricoboni/followers", "following_url": "https://api.github.com/users/ricoboni/following{/other_user}", "gists_url": "https://api.github.com/users/ricoboni/gists{/gist_id}", "starred_url": "https://api.github.com/users/ricoboni/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/ricoboni/subscriptions", "organizations_url": "https://api.github.com/users/ricoboni/orgs", "repos_url": "https://api.github.com/users/ricoboni/repos", "events_url": "https://api.github.com/users/ricoboni/events{/privacy}", "received_events_url": "https://api.github.com/users/ricoboni/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Thanks!\n" ]
"2013-10-23T16:47:52"
"2013-10-23T17:25:05"
"2013-10-23T17:24:58"
NONE
null
Project have a ForeignKeyField referencing Client The output is from my projects iPython shell ``` In [1]: p = Project.get(id=581) In [2]: p.client Out[2]: <models.Client at 0x1f6d790> In [3]: p.client.id Out[3]: 115 In [4]: p.client = 123 In [5]: p.client.id Out[5]: 115 ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/243/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/243/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/242
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/242/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/242/comments
https://api.github.com/repos/coleifer/peewee/issues/242/events
https://github.com/coleifer/peewee/issues/242
21,423,745
MDU6SXNzdWUyMTQyMzc0NQ==
242
Postgres Mixed Encoding SQLASCII Issue
{ "login": "caelx", "id": 1686351, "node_id": "MDQ6VXNlcjE2ODYzNTE=", "avatar_url": "https://avatars.githubusercontent.com/u/1686351?v=4", "gravatar_id": "", "url": "https://api.github.com/users/caelx", "html_url": "https://github.com/caelx", "followers_url": "https://api.github.com/users/caelx/followers", "following_url": "https://api.github.com/users/caelx/following{/other_user}", "gists_url": "https://api.github.com/users/caelx/gists{/gist_id}", "starred_url": "https://api.github.com/users/caelx/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/caelx/subscriptions", "organizations_url": "https://api.github.com/users/caelx/orgs", "repos_url": "https://api.github.com/users/caelx/repos", "events_url": "https://api.github.com/users/caelx/events{/privacy}", "received_events_url": "https://api.github.com/users/caelx/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Just out of curiosity have you tried messing with the encoding on the connection object?\n", "Thanks for getting back to me.\n\nYes, the database is set for client encoding USASCII but I tried changing it to UTF8. This did not help though because there were still unicode conversion errors for some of the characters which aren't valid UTF8 characters.\n\nThe invalid characters were \\x93 and \\x94\n", "OK, cool. Well it looks like I can register those converters on the connection, so this should be pretty straightforward to fix.\n", "Thanks!\n\nThis project is giving me a hell of a headache, appreciate this\n", "Should be fixed in f1607416474ae99ccc16b058172cbce9d0ebd230 .\n\nYou'll need to turn off the unicode converter registration code:\n\n``` python\ndb = PostgresqlDatabase('...')\ndb.register_unicode = False # disables registering the unicode handlers on a per-connection basis.\n```\n\nIf for some reason this doesn't solve your problem please reopen.\n" ]
"2013-10-22T23:05:48"
"2013-10-23T16:03:47"
"2013-10-23T16:03:47"
NONE
null
I have to deal with a postgres database which has mixed encodings (mix utf-8 and latin1) in some of the text fields. Now I don't know what kind of monster doesn't properly encode text before it gets inserted into the database, but it is what it is. I created a ByteArrayField to deal with the raw text, but I was still getting errors. After tracing them, it's related to the following lines where you force everything to be unicode: if psycopg2: import psycopg2.extensions psycopg2.extensions.register_type(psycopg2.extensions.UNICODE) psycopg2.extensions.register_type(psycopg2.extensions.UNICODEARRAY) Commenting out the extensions fixes it for me, I know it's terrible practice and but it would be nice to have this as a configurable setting so that in the future I don't have to modify the peewee source. Thank you very much!
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/242/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/242/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/241
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/241/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/241/comments
https://api.github.com/repos/coleifer/peewee/issues/241/events
https://github.com/coleifer/peewee/pull/241
21,416,863
MDExOlB1bGxSZXF1ZXN0OTMwOTAyOA==
241
cookbook.rst: clarify threadlocals vs check_same_threads
{ "login": "shamrin", "id": 510678, "node_id": "MDQ6VXNlcjUxMDY3OA==", "avatar_url": "https://avatars.githubusercontent.com/u/510678?v=4", "gravatar_id": "", "url": "https://api.github.com/users/shamrin", "html_url": "https://github.com/shamrin", "followers_url": "https://api.github.com/users/shamrin/followers", "following_url": "https://api.github.com/users/shamrin/following{/other_user}", "gists_url": "https://api.github.com/users/shamrin/gists{/gist_id}", "starred_url": "https://api.github.com/users/shamrin/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/shamrin/subscriptions", "organizations_url": "https://api.github.com/users/shamrin/orgs", "repos_url": "https://api.github.com/users/shamrin/repos", "events_url": "https://api.github.com/users/shamrin/events{/privacy}", "received_events_url": "https://api.github.com/users/shamrin/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Cheers!\n" ]
"2013-10-22T20:58:40"
"2014-07-01T20:36:27"
"2013-10-22T21:12:36"
CONTRIBUTOR
null
Hopefully this makes the distinction between `threadlocals = True` and `check_same_thread = False` clearer. See also my other issue: mrjoes/flask-admin#348.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/241/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/241/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/241", "html_url": "https://github.com/coleifer/peewee/pull/241", "diff_url": "https://github.com/coleifer/peewee/pull/241.diff", "patch_url": "https://github.com/coleifer/peewee/pull/241.patch", "merged_at": "2013-10-22T21:12:36" }
https://api.github.com/repos/coleifer/peewee/issues/240
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/240/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/240/comments
https://api.github.com/repos/coleifer/peewee/issues/240/events
https://github.com/coleifer/peewee/issues/240
21,279,470
MDU6SXNzdWUyMTI3OTQ3MA==
240
Incompleted transactions with PostgreSQL
{ "login": "rudyryk", "id": 4500, "node_id": "MDQ6VXNlcjQ1MDA=", "avatar_url": "https://avatars.githubusercontent.com/u/4500?v=4", "gravatar_id": "", "url": "https://api.github.com/users/rudyryk", "html_url": "https://github.com/rudyryk", "followers_url": "https://api.github.com/users/rudyryk/followers", "following_url": "https://api.github.com/users/rudyryk/following{/other_user}", "gists_url": "https://api.github.com/users/rudyryk/gists{/gist_id}", "starred_url": "https://api.github.com/users/rudyryk/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/rudyryk/subscriptions", "organizations_url": "https://api.github.com/users/rudyryk/orgs", "repos_url": "https://api.github.com/users/rudyryk/repos", "events_url": "https://api.github.com/users/rudyryk/events{/privacy}", "received_events_url": "https://api.github.com/users/rudyryk/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Sorry, I missed a couple of updates :( After updating works great! :+1: \n", "No, bug is still present in 2.1.4 and in current development version with Python 3.3 at least. (Last time I just reproduced it incorrectly).\n", "You will need to issue a `rollback`, if you are using the database in autocommit mode:\n\n``` python\nUser.create(username='test')\ntry:\n User.create(username='test') # error\nexcept:\n db.rollback()\n# Continue as normal.\n```\n", "Sure, that's workaround. It seems that I should wrap **every** save / update / create into `try..except` block and that's not really good. I think rollback by default would be correct for autocommit mode. Am I missing something?\n", "Well, I think it's developer's responsibility to handle application level errors e.g.:\n\n``` Python\ntry:\n User.create(username='test') # error\nexcept User.ValidationError:\n pass # do something\n```\n\nAnd I think database level errors should be handled under the hood in 'autopilot' mode - which is 'autocommit' mode.\n\nDoes that sound reasonable? :)\n", "I think I can write an implementation and I'd want to work out good design solution :)\n\nAnother smaller problem I faced with explicit rollback is that I have to import global database `db` object:\n\n``` Python\nUser.create(username='test')\ntry:\n User.create(username='test') # error\nexcept:\n db.rollback()\n```\n\nI think `Model.get_database()` method would be nicer.\n", "> Sure, that's workaround.\n\nIn my opinion it is not a workaround -- if you do not handle transactions or application errors properly peewee won't try to figure out how to fix it for you.\n\nThere are a number of transaction helpers that can help you avoid the \"wrap every query\" part:\n- http://peewee.readthedocs.org/en/latest/peewee/cookbook.html#working-with-transactions\n- http://peewee.readthedocs.org/en/latest/peewee/api.html#Database.commit_on_success\n", "Ok, I see the point. My suggestion is consider `autocommit` mode like \"I don't want to know about transactions at all\".\n", "Right, and that's how it works, but if you trigger an `IntegrityError` in postgres it will mess up your implied transaction and you will have to roll it back yourself. You could subclass `PostgresqlDatabase` and just roll back if you encounter an error but I wouldn't recommend it.\n\nClosing this as it is expected behavior.\n", "Ok, then :) May be this should be highlighted somewhere is docs. I didn't actually expect that common single wrong `save` call may lock the whole database connection.\n", "Just want to chime in that this is unexpected to me as well.\n\n@coleifer, in response to\n\n> My suggestion is consider autocommit mode like \"I don't want to know about transactions at all\".\n\nyou say,\n\n> Right, and that's how it works, but if you trigger an IntegrityError in postgres it will mess up your implied transaction and you will have to roll it back yourself.\n\nBut the whole idea of a having to rollback an \"implied transaction\" seems at odds with the stated notion of \"I don't want to know about transactions.\"\n\nI don't see a circumstance where code with `autocommit=True` would ever _not_ want an automatic rollback. Am I missing something?\n", "My expectation of what is \"reasonable\" behavior for these connections is\nbased on my experience using Django, which may be the root of the issue\nhere, since this is how Django treats integrity errors with psycopg2.\n\nI agree, it is weird to roll back a transaction you never opened because\nyou encountered an error. At this point I'm not sure how many folks out\nthere have written code to handle the rollback() call, but I'm open to the\nidea of rolling back automatically.\n\nOn Fri, Jan 10, 2014 at 7:07 PM, Tim Conkling notifications@github.comwrote:\n\n> Just want to chime in that this is unexpected to me as well.\n> \n> @coleifer https://github.com/coleifer, in response to\n> \n> My suggestion is consider autocommit mode like \"I don't want to know about\n> transactions at all\".\n> \n> you say,\n> \n> Right, and that's how it works, but if you trigger an IntegrityError in\n> postgres it will mess up your implied transaction and you will have to roll\n> it back yourself.\n> \n> But the whole idea of a having to rollback an \"implied transaction\" seems\n> at odds with the stated notion of \"I don't want to know about transactions.\"\n> \n> I don't see a circumstance where code with autocommit=True would ever\n> _not_ want an automatic rollback. Am I missing something?\n> \n> —\n> Reply to this email directly or view it on GitHubhttps://github.com/coleifer/peewee/issues/240#issuecomment-32081866\n> .\n", "As a new user of peewee (which is great - thanks for creating & maintaining it!), I'm very much in favor of changing the default; the current behavior was confusing to me when I switched my underlying database from sqlite to postgres and started getting errors about open transactions that had not existed with sqlite. Of course, I don't have tons of code to maintain that uses peewee that would be negatively affected by this change.\n\nRegardless, I'd argue that - semantically speaking - `autocommit`'s current behavior is broken.\n", "Added fbd6c20aa3fa75b1a92b74030f201d0e43304e28 which adds a new parameter to the `Database` class `autorollback`:\n\n``` python\ndb = PostgresqlDatabase('my_db', autocommit=True, autorollback=True)\n```\n", "Docs: http://peewee.readthedocs.org/en/latest/peewee/api.html#database-and-its-subclasses\n", "I was hit by this issue too. The default value for `autorollback` parameter is wrong, but I guess it's set this way to maintain backward compatibility?\r\n\r\nNevertheless I assumed a rollback would be issued in case of any exception, but apparently I was wrong...", "What do you mean it's wrong? It's documented as being `False`.", "Yes, it is. But as pointed out in previous comments most people rely on deafults and this is not the expected behavior in most cases.", "@romanek-adam But it is documented and backward compatible! It's generally not a good idea to change defaults one day.\r\n\r\nProbably it would be good to add some notes on `autorollback` to [Transactions section in docs](\r\nhttp://peewee.readthedocs.io/en/latest/peewee/transactions.html)" ]
"2013-10-20T12:36:16"
"2017-02-14T09:31:12"
"2014-01-12T16:48:00"
NONE
null
How to deal with incompleted transactions in PostgreSQL? It seems we can't make queries after single transaction fail. Instead we get: **psycopg2.InternalError: current transaction is aborted, commands ignored until end of transaction block** Here's minimal code sample to reproduce the issue: ``` Python import peewee db = peewee.PostgresqlDatabase( database='test', host='localhost', port=None, user='test', password=None) class User(peewee.Model): username = peewee.CharField(max_length=50, unique=True) class Meta: database = db User.create_table() User.create(username='test') ``` So, I get single user with username "test". If I try to create another one, I'll get an error: ``` Python >>> User.create(username='test') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Users/test/.virtualenvs/test/lib/python3.3/site-packages/peewee.py", line 2193, in create inst.save(force_insert=True) File "/Users/test/.virtualenvs/test/lib/python3.3/site-packages/peewee.py", line 2278, in save new_pk = insert.execute() File "/Users/test/.virtualenvs/test/lib/python3.3/site-packages/peewee.py", line 1623, in execute return self.database.last_insert_id(self._execute(), self.model_class) File "/Users/test/.virtualenvs/test/lib/python3.3/site-packages/peewee.py", line 1314, in _execute return self.database.execute_sql(sql, params, self.require_commit) File "/Users/test/.virtualenvs/test/lib/python3.3/site-packages/peewee.py", line 1721, in execute_sql res = cursor.execute(sql, params or ()) psycopg2.IntegrityError: duplicate key value violates unique constraint "user_username" DETAIL: Key (username)=(test) already exists. ``` And that's predictable and fine! (By the way, how should we catch this kind of exception?) But when I try to make another request, it fails: ``` Python >>> User.get(username='test') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Users/test/.virtualenvs/test/lib/python3.3/site-packages/peewee.py", line 2203, in get return sq.get() File "/Users/test/.virtualenvs/test/lib/python3.3/site-packages/peewee.py", line 1521, in get return clone.execute().next() File "/Users/test/.virtualenvs/test/lib/python3.3/site-packages/peewee.py", line 1556, in execute self._qr = ResultWrapper(self.model_class, self._execute(), query_meta) File "/Users/test/.virtualenvs/test/lib/python3.3/site-packages/peewee.py", line 1314, in _execute return self.database.execute_sql(sql, params, self.require_commit) File "/Users/test/.virtualenvs/test/lib/python3.3/site-packages/peewee.py", line 1721, in execute_sql res = cursor.execute(sql, params or ()) psycopg2.InternalError: current transaction is aborted, commands ignored until end of transaction block ``` And I need to drop database connection and create a new one to make it work again.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/240/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/240/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/239
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/239/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/239/comments
https://api.github.com/repos/coleifer/peewee/issues/239/events
https://github.com/coleifer/peewee/issues/239
21,141,336
MDU6SXNzdWUyMTE0MTMzNg==
239
Add support for MySQL connection recycling
{ "login": "arnuschky", "id": 179920, "node_id": "MDQ6VXNlcjE3OTkyMA==", "avatar_url": "https://avatars.githubusercontent.com/u/179920?v=4", "gravatar_id": "", "url": "https://api.github.com/users/arnuschky", "html_url": "https://github.com/arnuschky", "followers_url": "https://api.github.com/users/arnuschky/followers", "following_url": "https://api.github.com/users/arnuschky/following{/other_user}", "gists_url": "https://api.github.com/users/arnuschky/gists{/gist_id}", "starred_url": "https://api.github.com/users/arnuschky/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/arnuschky/subscriptions", "organizations_url": "https://api.github.com/users/arnuschky/orgs", "repos_url": "https://api.github.com/users/arnuschky/repos", "events_url": "https://api.github.com/users/arnuschky/events{/privacy}", "received_events_url": "https://api.github.com/users/arnuschky/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Now that I think of it, this issue maybe more appropriate for flask-peewee, but I am not sure.\n", "I'm a little unclear on how your particular issue is arising. If you're using flask-peewee's `Database` object, it should be opening and closing the connection on each request. If you're using a multi-threaded wsgi server have you tried configuring your database with `threadlocals=True`? That would eliminate the possibility that a second thread is closing the conn opened by the first thread.\n", "Yes, we are using gunicorn with multiple workers and without threadlocals=True. Must have missed it in the docs (now I even found another old issue regarding this)! I guess that his issue is invalid then, but I will test first.\n", "You could use `sql_error_handler` to handle this problem. Anyway, this problem is caused by the connection is idle for a long time(longer than timeout seconds, default 28800 seconds)\n", "@arnuschky let me know if `threadlocals` resolved it!\n", "It seems to resolve the problem. Thanks!\n", "`threadlocals=True` can not resolved this issue~\nafter 28800 seconds, Error Msg ‘MySQL server has gone away’ appear agian!\n\n---\n\nread peewee doc again, use mysql_db.connect() & mysql_db.close() for each request in CherryPy.\n", "You can also check out http://docs.peewee-orm.com/en/latest/peewee/playhouse.html#pool for connection pooling and recycling.\n", "Thanks for your big help. `playhouse.pool` is the final solution which I needed~\n", "I use peewee with flask.\n\nPeewee database connection : \n\n```\ndb = PooledMySQLDatabase(database,**{\n \"passwd\": password, \"user\": user,\n \"max_connections\":None,\"stale_timeout\":None,\n \"threadlocals\" : True\n })\n\n@app.before_request\ndef before_request():\n db.connect()\n\n@app.teardown_request\ndef teardown_request(exception):\n db.close()\n```\n\nAfter mysql error that \"MySQL server has gone away (error(32, 'Broken pipe'))\", select queries works without problem, but insert,update,delete queries don't work.\n\nOn insert,update,delete queries works behind(in mysql) but peewee throw this errors.\n\n```\n(2006, \"MySQL server has gone away (error(32, 'Broken pipe'))\")\n```\n", "That's odd, not sure what that might mean.\n", "@coleifer I have two different applications with peewee and flask. They have same problem. Select queries has no problem but insert,update,delete always throws error which above. I will do test with an basic peewee and flask app and I will write the result of the test.\n" ]
"2013-10-17T09:26:05"
"2015-12-12T15:45:41"
"2013-10-18T14:12:59"
NONE
null
We're getting the following error on our flask project: ``` SQLError: (OperationalError) (2006, ‘MySQL server has gone away’) ``` This problem was implicitly mentioned in https://github.com/coleifer/peewee/issues/222 for example. SQLalchemy addresses the problem as follows: https://github.com/mitsuhiko/flask-sqlalchemy/commit/05c51933c4972b47c1420fdc29429da9b67b75d8 Associated issue: https://github.com/mitsuhiko/flask-sqlalchemy/issues/2 Would it be possible to implement this in PeeWee as well?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/239/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/239/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/238
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/238/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/238/comments
https://api.github.com/repos/coleifer/peewee/issues/238/events
https://github.com/coleifer/peewee/issues/238
20,957,609
MDU6SXNzdWUyMDk1NzYwOQ==
238
Can't refer to model which not exists yet
{ "login": "wtld", "id": 1318746, "node_id": "MDQ6VXNlcjEzMTg3NDY=", "avatar_url": "https://avatars.githubusercontent.com/u/1318746?v=4", "gravatar_id": "", "url": "https://api.github.com/users/wtld", "html_url": "https://github.com/wtld", "followers_url": "https://api.github.com/users/wtld/followers", "following_url": "https://api.github.com/users/wtld/following{/other_user}", "gists_url": "https://api.github.com/users/wtld/gists{/gist_id}", "starred_url": "https://api.github.com/users/wtld/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/wtld/subscriptions", "organizations_url": "https://api.github.com/users/wtld/orgs", "repos_url": "https://api.github.com/users/wtld/repos", "events_url": "https://api.github.com/users/wtld/events{/privacy}", "received_events_url": "https://api.github.com/users/wtld/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "By default you can use topic.post_set.\nIf you change topic = ForeignKeyField(Topic) to topic = ForeignKeyField(Topic,related_name='posts')\nyou can use topic.posts.\n", "Unfortunately peewee does not support this kind of relationship. This is partly a limitation of python, but also in part due to my own feeling that these kinds of circular dependencies indicate a problem with the schema.\n\nTo work around you really only have one option:\n\n``` python\nclass Topic(Model):\n title = CharField()\n last_post_id = IntegerField(null=True)\n\n @property\n def last_post(self):\n return Post.get(Post.id == self.last_post_id)\n\nclass Post(Model):\n topic = ForeignKeyField(Topic)\n body = CharField()\n```\n" ]
"2013-10-14T13:51:28"
"2013-10-15T01:31:22"
"2013-10-15T01:31:22"
NONE
null
``` python class Topic(Model): title = CharField() last_post = ForeignKeyField(Post) class Post(Model): topic = ForeignKeyField(Topic) body = CharField() ``` How to refer 'Post' model from 'Topic' model?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/238/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/238/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/237
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/237/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/237/comments
https://api.github.com/repos/coleifer/peewee/issues/237/events
https://github.com/coleifer/peewee/issues/237
20,669,381
MDU6SXNzdWUyMDY2OTM4MQ==
237
Is it possible to use getter in the model class?
{ "login": "a-nanasov", "id": 1544480, "node_id": "MDQ6VXNlcjE1NDQ0ODA=", "avatar_url": "https://avatars.githubusercontent.com/u/1544480?v=4", "gravatar_id": "", "url": "https://api.github.com/users/a-nanasov", "html_url": "https://github.com/a-nanasov", "followers_url": "https://api.github.com/users/a-nanasov/followers", "following_url": "https://api.github.com/users/a-nanasov/following{/other_user}", "gists_url": "https://api.github.com/users/a-nanasov/gists{/gist_id}", "starred_url": "https://api.github.com/users/a-nanasov/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/a-nanasov/subscriptions", "organizations_url": "https://api.github.com/users/a-nanasov/orgs", "repos_url": "https://api.github.com/users/a-nanasov/repos", "events_url": "https://api.github.com/users/a-nanasov/events{/privacy}", "received_events_url": "https://api.github.com/users/a-nanasov/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "That is an interesting setup. Unfortunately, due to the way peewee uses metaclasses, you cannot define your fields in `__init__`. I assume in practice there's a reason you're using a property -- perhaps to modify the value in the database column? Try:\n\n``` python\n\nclass Location(db.Model):\n name_column = CharField(unique=True)\n\n class Meta:\n db_table = 'locations'\n\n @property\n def name(self):\n return self.name_column\n```\n" ]
"2013-10-08T10:02:47"
"2013-10-08T15:06:49"
"2013-10-08T15:06:49"
NONE
null
Hi, I've tried to use @propery decorator with getter function: ``` python class Location(db.Model): def __init__(self): self._name = CharField(unique = True) @property def name(self): return self._name class Meta: db_table = 'locations' ``` but got the following SQL query `<SELECT t1.`id`FROM`locations`AS t1 WHERE ('<property object at 0x031E0E40>' = 'loc01')>` Could you please provide an example for getter? Thanks in advance!
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/237/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/237/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/236
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/236/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/236/comments
https://api.github.com/repos/coleifer/peewee/issues/236/events
https://github.com/coleifer/peewee/issues/236
20,396,778
MDU6SXNzdWUyMDM5Njc3OA==
236
AttributeError with multiple ForeignKeyField to the same table.
{ "login": "andmart", "id": 303252, "node_id": "MDQ6VXNlcjMwMzI1Mg==", "avatar_url": "https://avatars.githubusercontent.com/u/303252?v=4", "gravatar_id": "", "url": "https://api.github.com/users/andmart", "html_url": "https://github.com/andmart", "followers_url": "https://api.github.com/users/andmart/followers", "following_url": "https://api.github.com/users/andmart/following{/other_user}", "gists_url": "https://api.github.com/users/andmart/gists{/gist_id}", "starred_url": "https://api.github.com/users/andmart/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/andmart/subscriptions", "organizations_url": "https://api.github.com/users/andmart/orgs", "repos_url": "https://api.github.com/users/andmart/repos", "events_url": "https://api.github.com/users/andmart/events{/privacy}", "received_events_url": "https://api.github.com/users/andmart/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Sorry. I forgot to write peewee's version. 2.1.4\n", "This is because there are two foreign keys to the same model on `Student`. Specify `related_name` attributes (the backref on `Parent`):\n\n``` python\nclass Student(Model):\n name = CharField()\n father = ForeignKeyField(Parent, related_name='father_students')\n mother = ForeignKeyField(Parent, related_name='mother_students')\n```\n\nThis is a new error that is raised because both parent fks would use the same backref (`student_set`), which is ambiguous.\n", "But when a large database is generated with Pwiz, related_names are not written, and the models.py is unusable (except if I edit models.py by hand, but it's tedious...)\n", "> But when a large database is generated with Pwiz, related_names are not written, and the models.py is unusable (except if I edit models.py by hand, but it's tedious...)\n\nWhat would you propose?\n", "As a begginer in ORM, not relevant things I guess :)\nMaybe Pwiz could be improved to automatically add \"related_name=XXX\" statement in those cases?\nYou are better than me to know if it's relevant or not ^^\nFor my purposes, I dit by hand on a 2000 lines models file. It's not as long as it sounds, but the problem is that people using pwiz won't know how to solve the problem (maybe a little update on the documentation about this \"issue\" would be suitable). \n", "Charles,\ncould peewee use the attribute name in place of class name to reference to set?\n", "I agree that it would be nice if pwiz generated working models out of the box, no matter the names. Couldn't it simply use the field name of the referenced model to this effect, i.e. set it as a default `related_name`? Whether it's `father_students`, `fathers`, `mother_students` or what not wouldn't really matter since you can always change it when you find it too awkward.\n", "I'll look into it, but I'm going to go out on a limb and say that `pwiz` does a pretty damn good job at what it does.\n", "I agree! I actually just found out about peewee and used it to generate models for quite large existing databases. With search/replace, I had fixed all problems within minutes. I'm already pretty amazed as it is! This is awesome! :-)\n" ]
"2013-10-02T14:18:10"
"2015-01-22T19:50:12"
"2013-10-02T16:21:32"
NONE
null
Charles, Here a simple example to reproduce: ``` python from peewee import * class Parent(Model): name = CharField() class Student(Model): name = CharField() father = ForeignKeyField(Parent) mother = ForeignKeyField(Parent) ``` ``` AttributeError: Foreign key: student.mother related name "student_set" collision with foreign key using same related_name. ``` It seems that peewee tries to make a set with all the references to same table, but there is case where the attributes are different.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/236/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/236/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/235
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/235/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/235/comments
https://api.github.com/repos/coleifer/peewee/issues/235/events
https://github.com/coleifer/peewee/issues/235
20,155,187
MDU6SXNzdWUyMDE1NTE4Nw==
235
handle error by flashing error msg in admin during data entry
{ "login": "beebek", "id": 1183800, "node_id": "MDQ6VXNlcjExODM4MDA=", "avatar_url": "https://avatars.githubusercontent.com/u/1183800?v=4", "gravatar_id": "", "url": "https://api.github.com/users/beebek", "html_url": "https://github.com/beebek", "followers_url": "https://api.github.com/users/beebek/followers", "following_url": "https://api.github.com/users/beebek/following{/other_user}", "gists_url": "https://api.github.com/users/beebek/gists{/gist_id}", "starred_url": "https://api.github.com/users/beebek/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/beebek/subscriptions", "organizations_url": "https://api.github.com/users/beebek/orgs", "repos_url": "https://api.github.com/users/beebek/repos", "events_url": "https://api.github.com/users/beebek/events{/privacy}", "received_events_url": "https://api.github.com/users/beebek/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "You will need to implement that yourself by overriding `ModelAdmin.save_model`.\n" ]
"2013-09-27T07:00:54"
"2013-09-27T15:11:28"
"2013-09-27T15:11:28"
NONE
null
``` class Organization(db.Model): name = TextField(default="", unique=True) def save(self, *args, **kwargs): if not self.get_id(): # this is the first time saving self.create_folder() return super(Organization, self).save(*args, **kwargs) def __unicode__(self): return self.name def create_folder(self): if not os.path.exists(get_project_path(), 'forms', self.name): os.mkdir(os.path.join(get_project_path(), 'forms', self.name)) ``` After solving issue #234, I am into another problem. If the user enters same name, can a message be flashed, stating that the name already exists in flask-peewee admin ?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/235/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/235/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/234
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/234/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/234/comments
https://api.github.com/repos/coleifer/peewee/issues/234/events
https://github.com/coleifer/peewee/issues/234
20,055,461
MDU6SXNzdWUyMDA1NTQ2MQ==
234
create a folder during database creation
{ "login": "beebek", "id": 1183800, "node_id": "MDQ6VXNlcjExODM4MDA=", "avatar_url": "https://avatars.githubusercontent.com/u/1183800?v=4", "gravatar_id": "", "url": "https://api.github.com/users/beebek", "html_url": "https://github.com/beebek", "followers_url": "https://api.github.com/users/beebek/followers", "following_url": "https://api.github.com/users/beebek/following{/other_user}", "gists_url": "https://api.github.com/users/beebek/gists{/gist_id}", "starred_url": "https://api.github.com/users/beebek/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/beebek/subscriptions", "organizations_url": "https://api.github.com/users/beebek/orgs", "repos_url": "https://api.github.com/users/beebek/repos", "events_url": "https://api.github.com/users/beebek/events{/privacy}", "received_events_url": "https://api.github.com/users/beebek/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Edit: fixed formatting\n", "Typically this is something you would do before saving the model to the database:\n\n``` python\n\norg = Organization(form_folder='whatever')\norg.save() # actually save to the db, create the folder\n```\n\nYou would implement this:\n\n``` python\n\nclass Organization(db.Model):\n name = TextField(default='')\n form_folder = TextField(default='')\n\n def save(self, *args, **kwargs):\n if not self.get_id(): # this is the first time saving\n self.create_folder()\n return super(Organization, self).save(*args, **kwargs)\n```\n", "Thanks. :)\n" ]
"2013-09-25T16:59:24"
"2013-09-27T07:01:13"
"2013-09-26T16:41:26"
NONE
null
I have a simple model ``` python class Organization(db.Model): name = TextField(default="") form_folder = TextField(default="") def __unicode__(self): return self.name ``` When the user passes the form_folder name, I need to create a folder with the same name. Is it possible to use some constructor and create it?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/234/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/234/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/233
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/233/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/233/comments
https://api.github.com/repos/coleifer/peewee/issues/233/events
https://github.com/coleifer/peewee/issues/233
19,984,296
MDU6SXNzdWUxOTk4NDI5Ng==
233
Case stmt for peewee
{ "login": "stanegit", "id": 3876591, "node_id": "MDQ6VXNlcjM4NzY1OTE=", "avatar_url": "https://avatars.githubusercontent.com/u/3876591?v=4", "gravatar_id": "", "url": "https://api.github.com/users/stanegit", "html_url": "https://github.com/stanegit", "followers_url": "https://api.github.com/users/stanegit/followers", "following_url": "https://api.github.com/users/stanegit/following{/other_user}", "gists_url": "https://api.github.com/users/stanegit/gists{/gist_id}", "starred_url": "https://api.github.com/users/stanegit/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/stanegit/subscriptions", "organizations_url": "https://api.github.com/users/stanegit/orgs", "repos_url": "https://api.github.com/users/stanegit/repos", "events_url": "https://api.github.com/users/stanegit/events{/privacy}", "received_events_url": "https://api.github.com/users/stanegit/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Funny you should ask that! I've just been looking at making this easier to accomplish. Currently you have to do some messy stuff with `Clause` and `R`.\n", "I hope you can do \"magic\" :)\n", "Something like sqlalchemy would be perfecet\n\ncase([\n (CcnDef.w_pci.code,'PCI'),\n (CcnDef.w_cath.code,'CATH'),\n ],else_=\"None\").label('PCI_OR_CATH')\n", "Usage is in the testcase, but it is pretty similar to the SQA example you pasted. Let me know if you have any questions or trouble w/it\n", "Thx when I get chance I'll test it, but look good , as always :)\n" ]
"2013-09-24T15:08:56"
"2013-09-24T18:56:02"
"2013-09-24T17:02:41"
NONE
null
Hi , thx for peewee , can we do CASE() stmt with peewee?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/233/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/233/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/232
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/232/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/232/comments
https://api.github.com/repos/coleifer/peewee/issues/232/events
https://github.com/coleifer/peewee/issues/232
19,909,386
MDU6SXNzdWUxOTkwOTM4Ng==
232
update password also while updating the record
{ "login": "beebek", "id": 1183800, "node_id": "MDQ6VXNlcjExODM4MDA=", "avatar_url": "https://avatars.githubusercontent.com/u/1183800?v=4", "gravatar_id": "", "url": "https://api.github.com/users/beebek", "html_url": "https://github.com/beebek", "followers_url": "https://api.github.com/users/beebek/followers", "following_url": "https://api.github.com/users/beebek/following{/other_user}", "gists_url": "https://api.github.com/users/beebek/gists{/gist_id}", "starred_url": "https://api.github.com/users/beebek/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/beebek/subscriptions", "organizations_url": "https://api.github.com/users/beebek/orgs", "repos_url": "https://api.github.com/users/beebek/repos", "events_url": "https://api.github.com/users/beebek/events{/privacy}", "received_events_url": "https://api.github.com/users/beebek/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "No, `set_password` is a method on the `User` model, but once you call `.update()` you are working with a `Query` object which doesn't have that method.\n\nYou can do:\n\n``` python\nfrom flask_peewee.utils import make_password\n\n(User\n .update(\n organization_name=organization_name,\n username=username,\n email=email,\n password=make_password(request.form['password']))\n .where(User.id == int(request.form['id']))\n .execute())\n```\n", "Thanks, it was the solution\nBy the way I'm using flask-peewee as well in one of my project.\nGreat Works. cheers !!\n" ]
"2013-09-23T13:40:25"
"2013-09-23T14:27:06"
"2013-09-23T13:57:18"
NONE
null
I have a simple query e.g. user = User.update(organization_name=organization_name, username=username, email=email, active=active, admin=admin, created_date=created_date, role=role).where(User.id==int(request.form['user_id'])) # user.set_password(request.form['password']) user.execute( Is there any way so that I can update the password. It says AttributeError: "'UpdateQuery' object has no attribute 'set_password'" BESIDE THAT, everything is working fine. Just want to let the user change their password. Great Thanks
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/232/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/232/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/231
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/231/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/231/comments
https://api.github.com/repos/coleifer/peewee/issues/231/events
https://github.com/coleifer/peewee/issues/231
19,342,202
MDU6SXNzdWUxOTM0MjIwMg==
231
Class with multiple foreign key references to the same table throws error
{ "login": "chrismatta", "id": 2523087, "node_id": "MDQ6VXNlcjI1MjMwODc=", "avatar_url": "https://avatars.githubusercontent.com/u/2523087?v=4", "gravatar_id": "", "url": "https://api.github.com/users/chrismatta", "html_url": "https://github.com/chrismatta", "followers_url": "https://api.github.com/users/chrismatta/followers", "following_url": "https://api.github.com/users/chrismatta/following{/other_user}", "gists_url": "https://api.github.com/users/chrismatta/gists{/gist_id}", "starred_url": "https://api.github.com/users/chrismatta/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/chrismatta/subscriptions", "organizations_url": "https://api.github.com/users/chrismatta/orgs", "repos_url": "https://api.github.com/users/chrismatta/repos", "events_url": "https://api.github.com/users/chrismatta/events{/privacy}", "received_events_url": "https://api.github.com/users/chrismatta/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "This is happening in 2.1.4, I just tested it in 2.1.0 and it seems to be working fine.\n", "Do you have a foreign key on `InvArray` named `invhostdr_set`?\n", "No, I don't. I only have one foreign key on InvArray that points to a different table, InvLocation.\n", "Try setting the `related_name` attribute on either `primary_array` or `secondary_array`.\n", "Still the same error, does this look right?\n\n```\nclass InvHostDr(BaseModel):\n comment = TextField()\n primary_array = ForeignKeyField(\n db_column='primary_array_id', related_name=\"primary\", rel_model=InvArray)\n primary_host = ForeignKeyField(\n db_column='primary_host_id', rel_model=InvHost)\n primary_project_host = ForeignKeyField(\n db_column='primary_project_host_id', rel_model=PrjProjectHost)\n primary_shadowimage = TextField()\n primary_volumes = TextField()\n replication_group = CharField()\n secondary_array = ForeignKeyField(\n db_column='secondary_array_id', related_name=\"secondary\", rel_model=InvArray)\n secondary_host = ForeignKeyField(\n db_column='secondary_host_id', rel_model=InvHost)\n secondary_project_host = ForeignKeyField(\n db_column='secondary_project_host_id', rel_model=PrjProjectHost)\n secondary_shadowimage = TextField()\n secondary_volumes = TextField()\n\n class Meta:\n db_table = 'inv_host_dr'\n```\n", "You will want to add related name attributes for all `secondary_host` and `secondary_project_host` -- any time you have multiple foreign keys to the same table you will need to specify a related name to avoid collisions.\n", "What is colliding here? Is it the field in InvZoneSet colliding with it's own related name? I'm not sure why there needs to be a different name, \n\n```\nclass InvZoneSet(BaseModel):\n fabric = ForeignKeyField(db_column='fabric_id', rel_model=InvFabric)\n name = CharField()\n sibling = IntegerField(db_column='sibling_id')\n vsan = ForeignKeyField(db_column='vsan_id', related_name=\"vsan\", rel_model=InvFabric)\n\n class Meta:\n db_table = 'inv_zone_set'\n```\n\nerror:\n\n```\nAttributeError: Foreign key: invzoneset.vsan related name \"vsan\" collision with field of the same name.\n```\n", "Does `InvFabric` have a field name `vsan`?\n", "The field name in the database for InvZoneSet is is `vsan_id`, the field name for InvFabric is `vsan` is that still considered a collision?\n", "Sorry, my mistake, they're both `vsan_id`. What exactly is colliding if there are two references to the same table in one class? They have different field names, and it will be likely that the referenced table will have the same field name as the class that's referencing it, no?\n", "The fact that they are accessed in python using the same identifier (vsan).\n", "Ok, I resolved this, thanks.\n", "Charles,\n\nI'm facing the same problem.\n\nHere a simple example to reproduce:\n\n``` python\nfrom peewee import *\n\nclass Parent(Model):\n name = CharField()\n\nclass Student(Model):\n name = CharField()\n father = ForeignKeyField(Parent)\n mother = ForeignKeyField(Parent)\n```\n\nIt seems that peewee tries to make a set with all the references to same table, but there is case where the attributes are different.\n" ]
"2013-09-11T19:46:52"
"2013-10-01T23:06:10"
"2013-09-19T21:06:11"
NONE
null
After upgrading this class throws an error: ``` class InvHostDr(BaseModel): comment = TextField() primary_array = ForeignKeyField( db_column='primary_array_id', rel_model=InvArray) primary_host = ForeignKeyField( db_column='primary_host_id', rel_model=InvHost) primary_project_host = ForeignKeyField( db_column='primary_project_host_id', rel_model=PrjProjectHost) primary_shadowimage = TextField() primary_volumes = TextField() replication_group = CharField() secondary_array = ForeignKeyField( db_column='secondary_array_id', rel_model=InvArray) secondary_host = ForeignKeyField( db_column='secondary_host_id', rel_model=InvHost) secondary_project_host = ForeignKeyField( db_column='secondary_project_host_id', rel_model=PrjProjectHost) secondary_shadowimage = TextField() secondary_volumes = TextField() class Meta: db_table = 'inv_host_dr' ``` Here's the error: `AttributeError: Foreign key: invhostdr.primary_array related name "invhostdr_set" collision with foreign key using same related_name.` I'm not even calling this class in the code, it errors when the module is initialized.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/231/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/231/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/230
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/230/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/230/comments
https://api.github.com/repos/coleifer/peewee/issues/230/events
https://github.com/coleifer/peewee/issues/230
19,179,073
MDU6SXNzdWUxOTE3OTA3Mw==
230
db migration
{ "login": "beebek", "id": 1183800, "node_id": "MDQ6VXNlcjExODM4MDA=", "avatar_url": "https://avatars.githubusercontent.com/u/1183800?v=4", "gravatar_id": "", "url": "https://api.github.com/users/beebek", "html_url": "https://github.com/beebek", "followers_url": "https://api.github.com/users/beebek/followers", "following_url": "https://api.github.com/users/beebek/following{/other_user}", "gists_url": "https://api.github.com/users/beebek/gists{/gist_id}", "starred_url": "https://api.github.com/users/beebek/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/beebek/subscriptions", "organizations_url": "https://api.github.com/users/beebek/orgs", "repos_url": "https://api.github.com/users/beebek/repos", "events_url": "https://api.github.com/users/beebek/events{/privacy}", "received_events_url": "https://api.github.com/users/beebek/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Peewee has support for simple migrations using postgresql:\n\nhttp://peewee.readthedocs.org/en/latest/peewee/playhouse.html#basic-schema-migrations\n\nCurrently I do not have plans to enhance this module or add support for other database engines.\n" ]
"2013-09-09T06:47:37"
"2013-09-09T10:24:49"
"2013-09-09T10:24:49"
NONE
null
It would be great If there is db migration as well.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/230/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/230/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/229
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/229/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/229/comments
https://api.github.com/repos/coleifer/peewee/issues/229/events
https://github.com/coleifer/peewee/issues/229
19,067,184
MDU6SXNzdWUxOTA2NzE4NA==
229
Join "on" clause does not accept a conjunction or disjunction.
{ "login": "rammie", "id": 554792, "node_id": "MDQ6VXNlcjU1NDc5Mg==", "avatar_url": "https://avatars.githubusercontent.com/u/554792?v=4", "gravatar_id": "", "url": "https://api.github.com/users/rammie", "html_url": "https://github.com/rammie", "followers_url": "https://api.github.com/users/rammie/followers", "following_url": "https://api.github.com/users/rammie/following{/other_user}", "gists_url": "https://api.github.com/users/rammie/gists{/gist_id}", "starred_url": "https://api.github.com/users/rammie/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/rammie/subscriptions", "organizations_url": "https://api.github.com/users/rammie/orgs", "repos_url": "https://api.github.com/users/rammie/repos", "events_url": "https://api.github.com/users/rammie/events{/privacy}", "received_events_url": "https://api.github.com/users/rammie/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Try adding a `.alias('foo')` to your expression.\n", "Sweet, that works! Thanks once again, peewee rulz.\n", "Probably needs a better error message, glad you're liking peewee!\n", "@rammie -- Do you mind sharing the join that caused this error?\n", "``` python\nfrom peewee import *\n\nclass T2(Model):\n f2 = CharField()\n\nclass T3(Model):\n f3 = CharField()\n\nclass T(Model):\n f2 = ForeignKeyField(T2)\n f3 = ForeignKeyField(T3)\n\nclass TAccessLog(Model):\n t = ForeignKeyField(T)\n u = ForeignKeyField(T3)\n\nu = T3.select().get()\nT.select(T, T.f2, T.f3, TAccessLog).switch(T).join(T3).switch(T).join(T2).switch(T).join(\n TAccessLog, JOIN_LEFT_OUTER, on=(\n (TAccessLog.u == u) & (TAccessLog.t == T.id)\n ).alias(\"taccesslog\")\n).switch(T)\n```\n\nI haven't tested it after simplifying it and extracting it from the codebase. Also, I'm not sure if the initial joins matter. If you remove the alias from the query, something like this should do the trick.\n", "Hi question when you writing a join you end up with query like this\n\nexp.\nSELECT t1.\\* FROM blog AS t1\nINNER JOIN user AS t2\n ON t1.user_id = t2.id\nWHERE\n t1.status = ? AND\n t2.is_staff = ?\n\nNow , can you control how output query look like , so \"INNER JOIN user AS t2\" can be changed with\n\"INNER JOIN user AS USER\", \n\nit would be great if we can control how table is aliased in class construction\n\nclass User(Model):\n class Meta:\n table_alias = 'USER'\n", "@stanegit -- currently that is not controllable...what's your use-case?\n", "In company there are \"conventions\" when you do joins (could be a lot of them) that table aliases are always the same (it is easier to grok the huge query).\n", "hi i have those models\n\n``` python\nclass Category(BaseModel):\n category_id = BigIntegerField(primary_key=True)\n category_name = CharField(max_length=255)\n\n class Meta:\n db_table = 'category'\n\nclass ItemCategory(BaseModel):\n added_date = DateTimeField(null=True)\n category_id = BigIntegerField()\n item_id = BigIntegerField()\n item_type_id = PrimaryKeyField()\n\n class Meta:\n db_table = 'item_category'\n```\n\ni run this sql\n\n``` python\nquery = Category.select(Category, ItemCategory)\nquery = query.join( ItemCategory, JOIN_LEFT_OUTER, on=(\n (Category.category_id==ItemCategory.category_id ) & ( ItemCategory.item_type_id==2 )\n )\n)\n```\n\nwhen i try to get rows with foreach it throws that error\n**target_attr = self.on.lhs.name . AttributeError: 'Expression' object has no attribute 'name'**\n\n``` python\nfor c in query:\n print c\n```\n\nis it bug or i am doing something wrong?\n\ni put console screenshoot below\n![screen shot 2014-10-21 at 19 23 43](https://cloud.githubusercontent.com/assets/1669906/4722253/ad6b5b90-593e-11e4-8e31-6f1fc1e80d96.png)\n", "Fixed in https://github.com/coleifer/peewee/commit/9f27f1b05dfb67ffce2bcc0e43943aa9833b8a0e\n", "Thanks.\nis it fixed when we install by pip ? or we will fix manually?\n", "I'll need to issue a new release. You can work around by filtering on `ItemCategory.item_type_id == 2` in the WHERE clause instead of the join predicate.\n", "Or use `naive()` query, it seems to work fine.\n" ]
"2013-09-05T18:45:49"
"2014-10-22T05:04:24"
"2014-10-21T16:40:37"
NONE
null
I ran into this issue while trying to do a left join which requires multiple conditions in the on clause. Here is a traceback of the issue: ``` Traceback (most recent call last): ... File "python2.7/site-packages/peewee.py", line 1650, in __iter__ return iter(self.execute()) File "python2.7/site-packages/peewee.py", line 1643, in execute self._qr = ResultWrapper(self.model_class, self._execute(), query_meta) File "python2.7/site-packages/peewee.py", line 1190, in __init__ self.column_map, self.join_map = self.prepare() File "python2.7/site-packages/peewee.py", line 1226, in prepare fk_name = join.on._alias or join.on.lhs.name AttributeError: 'Expr' object has no attribute 'name' ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/229/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/229/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/228
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/228/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/228/comments
https://api.github.com/repos/coleifer/peewee/issues/228/events
https://github.com/coleifer/peewee/issues/228
18,755,129
MDU6SXNzdWUxODc1NTEyOQ==
228
Change >> to a NOT IN instead of IS
{ "login": "kolanos", "id": 17498, "node_id": "MDQ6VXNlcjE3NDk4", "avatar_url": "https://avatars.githubusercontent.com/u/17498?v=4", "gravatar_id": "", "url": "https://api.github.com/users/kolanos", "html_url": "https://github.com/kolanos", "followers_url": "https://api.github.com/users/kolanos/followers", "following_url": "https://api.github.com/users/kolanos/following{/other_user}", "gists_url": "https://api.github.com/users/kolanos/gists{/gist_id}", "starred_url": "https://api.github.com/users/kolanos/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/kolanos/subscriptions", "organizations_url": "https://api.github.com/users/kolanos/orgs", "repos_url": "https://api.github.com/users/kolanos/repos", "events_url": "https://api.github.com/users/kolanos/events{/privacy}", "received_events_url": "https://api.github.com/users/kolanos/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Unfortunately this is not going to change any time soon. I made a decision a while ago that `IS` would be treated as a separate lookup even if it is only ever used with `NULL`. Similarly, negation is always handled by the unary negation operator and is not special cased.\n" ]
"2013-08-29T20:26:22"
"2013-08-29T20:57:04"
"2013-08-29T20:57:04"
NONE
null
Since `.where(field << (...)` equates to a `WHERE field IN (...)`, it stands to reason that a `.where(field >> (...)` would equate to `WHERE field NOT IN (...)`. Then a `.where(field == None)` would equate to `WHERE field IS NULL` and `.where(field != None)` equates to `WHERE field IS NOT NULL`. Does that not make more sense?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/228/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/228/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/227
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/227/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/227/comments
https://api.github.com/repos/coleifer/peewee/issues/227/events
https://github.com/coleifer/peewee/pull/227
18,580,885
MDExOlB1bGxSZXF1ZXN0Nzg3NDI3MA==
227
wrong MySQLDatabase field override key for bool
{ "login": "spenthil", "id": 110513, "node_id": "MDQ6VXNlcjExMDUxMw==", "avatar_url": "https://avatars.githubusercontent.com/u/110513?v=4", "gravatar_id": "", "url": "https://api.github.com/users/spenthil", "html_url": "https://github.com/spenthil", "followers_url": "https://api.github.com/users/spenthil/followers", "following_url": "https://api.github.com/users/spenthil/following{/other_user}", "gists_url": "https://api.github.com/users/spenthil/gists{/gist_id}", "starred_url": "https://api.github.com/users/spenthil/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/spenthil/subscriptions", "organizations_url": "https://api.github.com/users/spenthil/orgs", "repos_url": "https://api.github.com/users/spenthil/repos", "events_url": "https://api.github.com/users/spenthil/events{/privacy}", "received_events_url": "https://api.github.com/users/spenthil/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[]
"2013-08-27T00:08:21"
"2014-07-02T20:27:48"
"2013-08-27T15:07:34"
CONTRIBUTOR
null
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/227/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/227/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/227", "html_url": "https://github.com/coleifer/peewee/pull/227", "diff_url": "https://github.com/coleifer/peewee/pull/227.diff", "patch_url": "https://github.com/coleifer/peewee/pull/227.patch", "merged_at": "2013-08-27T15:07:34" }
https://api.github.com/repos/coleifer/peewee/issues/226
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/226/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/226/comments
https://api.github.com/repos/coleifer/peewee/issues/226/events
https://github.com/coleifer/peewee/pull/226
18,509,967
MDExOlB1bGxSZXF1ZXN0Nzg0MDQ2MA==
226
Added kwargs to ModelOptions for further customization
{ "login": "cam-stitt", "id": 186643, "node_id": "MDQ6VXNlcjE4NjY0Mw==", "avatar_url": "https://avatars.githubusercontent.com/u/186643?v=4", "gravatar_id": "", "url": "https://api.github.com/users/cam-stitt", "html_url": "https://github.com/cam-stitt", "followers_url": "https://api.github.com/users/cam-stitt/followers", "following_url": "https://api.github.com/users/cam-stitt/following{/other_user}", "gists_url": "https://api.github.com/users/cam-stitt/gists{/gist_id}", "starred_url": "https://api.github.com/users/cam-stitt/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/cam-stitt/subscriptions", "organizations_url": "https://api.github.com/users/cam-stitt/orgs", "repos_url": "https://api.github.com/users/cam-stitt/repos", "events_url": "https://api.github.com/users/cam-stitt/events{/privacy}", "received_events_url": "https://api.github.com/users/cam-stitt/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I added another commit that removed the forced auto_increment no matter what. I feel like people should be able to set the pk on an item even if there is an auto_increment.\n", "Both of your changes should now be merged in (more or less). Thank you!\n" ]
"2013-08-24T17:56:50"
"2014-07-06T01:50:53"
"2013-08-27T15:14:39"
NONE
null
This allows people to add more options to the model, for example if used with a serializer that looks for excluded fields: ``` class User(Model): class Meta: excludes = ['id'] ``` The kwargs that would be used is unique for each use case.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/226/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/226/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/226", "html_url": "https://github.com/coleifer/peewee/pull/226", "diff_url": "https://github.com/coleifer/peewee/pull/226.diff", "patch_url": "https://github.com/coleifer/peewee/pull/226.patch", "merged_at": null }
https://api.github.com/repos/coleifer/peewee/issues/225
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/225/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/225/comments
https://api.github.com/repos/coleifer/peewee/issues/225/events
https://github.com/coleifer/peewee/pull/225
18,451,883
MDExOlB1bGxSZXF1ZXN0NzgxMDM1OQ==
225
add auto reconnect in execute_sql
{ "login": "beanyoung", "id": 973789, "node_id": "MDQ6VXNlcjk3Mzc4OQ==", "avatar_url": "https://avatars.githubusercontent.com/u/973789?v=4", "gravatar_id": "", "url": "https://api.github.com/users/beanyoung", "html_url": "https://github.com/beanyoung", "followers_url": "https://api.github.com/users/beanyoung/followers", "following_url": "https://api.github.com/users/beanyoung/following{/other_user}", "gists_url": "https://api.github.com/users/beanyoung/gists{/gist_id}", "starred_url": "https://api.github.com/users/beanyoung/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/beanyoung/subscriptions", "organizations_url": "https://api.github.com/users/beanyoung/orgs", "repos_url": "https://api.github.com/users/beanyoung/repos", "events_url": "https://api.github.com/users/beanyoung/events{/privacy}", "received_events_url": "https://api.github.com/users/beanyoung/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Because `OperationalError` might signify other things than just a closed connection, I'm not too excited about merging this. Perhaps you can subclass your `Database` class and add this logic yourself?\n", "Check out 51c66e7ed6bcc56940eb39d30c6d9333290e9b55 (and the subsequent commits). You can now define a `sql_error_handler` on your database subclass, which should hopefully help solve your problem.\n", "In case you're interested, I've got a mixin for retrying failed queries in 017e4e4952f0b429dd21f0e90465a0f644cf6015 . Docs:\n\nhttp://docs.peewee-orm.com/en/latest/peewee/database.html#automatic-reconnect\n" ]
"2013-08-23T03:10:24"
"2015-11-22T05:10:37"
"2013-08-23T21:04:51"
NONE
null
I use peewee with tornado, and all requests share one database connection, but when something wrong happens with database, the connection will be unavaliable. So I added a `try exception` block in `execute_sql()`, and this works fine for me.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/225/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/225/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/225", "html_url": "https://github.com/coleifer/peewee/pull/225", "diff_url": "https://github.com/coleifer/peewee/pull/225.diff", "patch_url": "https://github.com/coleifer/peewee/pull/225.patch", "merged_at": null }
https://api.github.com/repos/coleifer/peewee/issues/224
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/224/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/224/comments
https://api.github.com/repos/coleifer/peewee/issues/224/events
https://github.com/coleifer/peewee/pull/224
18,316,008
MDExOlB1bGxSZXF1ZXN0NzczNzE3NA==
224
python3 compatibility fix
{ "login": "lemanyk", "id": 266274, "node_id": "MDQ6VXNlcjI2NjI3NA==", "avatar_url": "https://avatars.githubusercontent.com/u/266274?v=4", "gravatar_id": "", "url": "https://api.github.com/users/lemanyk", "html_url": "https://github.com/lemanyk", "followers_url": "https://api.github.com/users/lemanyk/followers", "following_url": "https://api.github.com/users/lemanyk/following{/other_user}", "gists_url": "https://api.github.com/users/lemanyk/gists{/gist_id}", "starred_url": "https://api.github.com/users/lemanyk/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/lemanyk/subscriptions", "organizations_url": "https://api.github.com/users/lemanyk/orgs", "repos_url": "https://api.github.com/users/lemanyk/repos", "events_url": "https://api.github.com/users/lemanyk/events{/privacy}", "received_events_url": "https://api.github.com/users/lemanyk/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[]
"2013-08-20T19:28:43"
"2014-07-06T01:50:56"
"2013-08-25T01:18:28"
NONE
null
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/224/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/224/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/224", "html_url": "https://github.com/coleifer/peewee/pull/224", "diff_url": "https://github.com/coleifer/peewee/pull/224.diff", "patch_url": "https://github.com/coleifer/peewee/pull/224.patch", "merged_at": null }
https://api.github.com/repos/coleifer/peewee/issues/223
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/223/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/223/comments
https://api.github.com/repos/coleifer/peewee/issues/223/events
https://github.com/coleifer/peewee/pull/223
18,031,083
MDExOlB1bGxSZXF1ZXN0NzU4OTczMg==
223
cookbook: missing execute in atomic update docs
{ "login": "spenthil", "id": 110513, "node_id": "MDQ6VXNlcjExMDUxMw==", "avatar_url": "https://avatars.githubusercontent.com/u/110513?v=4", "gravatar_id": "", "url": "https://api.github.com/users/spenthil", "html_url": "https://github.com/spenthil", "followers_url": "https://api.github.com/users/spenthil/followers", "following_url": "https://api.github.com/users/spenthil/following{/other_user}", "gists_url": "https://api.github.com/users/spenthil/gists{/gist_id}", "starred_url": "https://api.github.com/users/spenthil/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/spenthil/subscriptions", "organizations_url": "https://api.github.com/users/spenthil/orgs", "repos_url": "https://api.github.com/users/spenthil/repos", "events_url": "https://api.github.com/users/spenthil/events{/privacy}", "received_events_url": "https://api.github.com/users/spenthil/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "damn that was fast.\n\n![f80b33b86bcb4d7934e879db667d2fbd](https://f.cloud.github.com/assets/110513/959369/a9f3fcd0-0483-11e3-8fd2-174fa8d25e7c.gif)\n" ]
"2013-08-14T01:46:04"
"2014-06-25T05:53:56"
"2013-08-14T01:47:07"
CONTRIBUTOR
null
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/223/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/223/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/223", "html_url": "https://github.com/coleifer/peewee/pull/223", "diff_url": "https://github.com/coleifer/peewee/pull/223.diff", "patch_url": "https://github.com/coleifer/peewee/pull/223.patch", "merged_at": "2013-08-14T01:47:06" }
https://api.github.com/repos/coleifer/peewee/issues/222
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/222/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/222/comments
https://api.github.com/repos/coleifer/peewee/issues/222/events
https://github.com/coleifer/peewee/issues/222
17,857,221
MDU6SXNzdWUxNzg1NzIyMQ==
222
test_multiple_writers from ConcurrencyTestCase fails occasionally
{ "login": "sYnfo", "id": 1011548, "node_id": "MDQ6VXNlcjEwMTE1NDg=", "avatar_url": "https://avatars.githubusercontent.com/u/1011548?v=4", "gravatar_id": "", "url": "https://api.github.com/users/sYnfo", "html_url": "https://github.com/sYnfo", "followers_url": "https://api.github.com/users/sYnfo/followers", "following_url": "https://api.github.com/users/sYnfo/following{/other_user}", "gists_url": "https://api.github.com/users/sYnfo/gists{/gist_id}", "starred_url": "https://api.github.com/users/sYnfo/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/sYnfo/subscriptions", "organizations_url": "https://api.github.com/users/sYnfo/orgs", "repos_url": "https://api.github.com/users/sYnfo/repos", "events_url": "https://api.github.com/users/sYnfo/events{/privacy}", "received_events_url": "https://api.github.com/users/sYnfo/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Thank you for mentioning this, I will look into it.\n", "I think the problem is the threads are waiting for locks to release and give up. I noticed the time it took to run the tests was pretty high (versus ~4.4 seconds on my machine).\n\n```\nRan 107 tests in 570.951s # 2.0.9\n\nRan 127 tests in 273.637s # 2.1.4\n```\n\n> The timeout parameter specifies how long the connection should wait for the lock to go away until raising an exception. The default for the timeout parameter is 5.0 (five seconds).\n\nLooks like the tests are timing out, so two ideas come to mind:\n1. Raise the timeout.\n2. Use an in-memory sqlite database for this test.\n", "OK, an in-memory database won't work since in-memory databases only exist for their connection.\n", "@coleifer \nI think this also happens for MySQL. In somehow different way....\nSometimes multiple read will cause error.\nI don't know whether I should open a new issue..lol\nWhen I perform several requests nearly at the same time, there is around one tenth of the time I got\n\n```\n File \"/Data/filmsoc/src/src/peewee/peewee.py\", line 1627, in get\n return clone.execute().next()\n File \"/Data/filmsoc/src/src/peewee/peewee.py\", line 1663, in execute\n self._qr = ResultWrapper(model_class, self._execute(), query_meta)\n File \"/Data/filmsoc/src/src/peewee/peewee.py\", line 1420, in _execute\n return self.database.execute_sql(sql, params, self.require_commit)\n File \"/Data/filmsoc/src/src/peewee/peewee.py\", line 1824, in execute_sql\n res = cursor.execute(sql, params or ())\n File \"/usr/local/lib/python2.7/dist-packages/MySQLdb/cursors.py\", line 201, in execute\n self.errorhandler(self, exc, value)\n File \"/usr/local/lib/python2.7/dist-packages/MySQLdb/connections.py\", line 36, in defaulterrorhandler\n raise errorclass, errorvalue\nOperationalError: (2006, 'MySQL server has gone away')\n```\n\nI tried to switch MySQLdb to pyMySQL....But this doesn't help.\nI tried to increase the timeout in my `/etc/mysql/my.cnf`, but this problem still happens.\nFYI, I am using MySQL 5.5.32 and the Database is InnoDB. Both peewee 2.1.3 and 2.1.4 have this issue.\nI wonder whether this is a configuration error (my fault)...Or maybe others are also facing this issue.\n", "@johnmave126 -- are these errors happening with the test suite, or with your application? You said requests so is this a web app? How are you handling opening and closing the connection to the db?\n", "@coleifer \nIt is with my application.\nI just now found some hints in it. I found when I set threadlocals to True, the problem is away.\nIn fact I am using Flask + flask-peewee, and before I didn't realize there is an option to set threadlocals.\nI am now opening an issue in flask-peewee to add some hints in the docs.\n" ]
"2013-08-09T11:04:55"
"2014-03-13T01:44:14"
"2013-08-09T14:20:32"
CONTRIBUTOR
null
it seems to be very rare, I've only seen it happen once for 2.0.9 [0] and once for 2.1.4 [1] in ~30 builds. Sorry if opening an issue is not the right thing to do, just figured you may want to know. :) [0] http://koji.fedoraproject.org/koji/getfile?taskID=5763686&name=build.log [1] http://koji.fedoraproject.org/koji/getfile?taskID=5783003&name=build.log
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/222/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/222/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/221
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/221/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/221/comments
https://api.github.com/repos/coleifer/peewee/issues/221/events
https://github.com/coleifer/peewee/issues/221
17,641,676
MDU6SXNzdWUxNzY0MTY3Ng==
221
Allow to define database dynamically
{ "login": "rudyryk", "id": 4500, "node_id": "MDQ6VXNlcjQ1MDA=", "avatar_url": "https://avatars.githubusercontent.com/u/4500?v=4", "gravatar_id": "", "url": "https://api.github.com/users/rudyryk", "html_url": "https://github.com/rudyryk", "followers_url": "https://api.github.com/users/rudyryk/followers", "following_url": "https://api.github.com/users/rudyryk/following{/other_user}", "gists_url": "https://api.github.com/users/rudyryk/gists{/gist_id}", "starred_url": "https://api.github.com/users/rudyryk/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/rudyryk/subscriptions", "organizations_url": "https://api.github.com/users/rudyryk/orgs", "repos_url": "https://api.github.com/users/rudyryk/repos", "events_url": "https://api.github.com/users/rudyryk/events{/privacy}", "received_events_url": "https://api.github.com/users/rudyryk/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "See #210 and the docs on proxy:\n\nhttp://peewee.readthedocs.org/en/latest/peewee/playhouse.html#proxy\n\nThis has come up a couple times so I will try to make the docs more obvious on this.\n", "That's great! Yes, a short reference in main docs chapter about models would solve it, I think. Thank you! :)\n", "a piggyback question: how can I dynamically use same models on multiple databases simultaneously?\n\nlike in many testing environment, for the same software we defined `devint`, `qa`, `prod` environment, those are running same model, just connection to same version of database-server running on different host, now for some cases, need to access both qa and prod database?\n\n``` python\ndatabase_qa = db_url.connect('mysql://qa-database-host/...')\ndatabase_host = db_url.connect('mysql://prod-database-host/...')\n\nclass ModelSite(Model):\n Field1 = ...\n Field2 = ...\n class Meta:\n database_table = 'api_site'\n\nclass ModelB(Model):\n Field1 = ...\n Field2 = ...\n class Meta:\n database_table = 'api_task'\n\nclass ModelC(Model):\n ...\n```\n\nI have multiple models (mapping to multiple tables in a database) in `qa` environment, and have exact same models in `prod` database; for an analyzing program, it needs to connect both databases by the same set of models, what's the best practice to do so?\n\nthis question is not just dynamically switching database at program initialization time, but it want to keep both connections at runtime? I can think of keeping a copy of this model definition for every environment, but is there a better way to reuse same set of model class definition?\n", "So you literally, while your app is running, want it to be connected to both a QA environment and a Prod environment?\n", "right, `'qa'` and `'prod'` are just examples here, it can be anything when users want to connect multiple database but using the same set of tables schema / models;\n\nI know in some design, it's has advantage of create a separate database for each customer, in each database, use multiple tables as before, each table is mapping to a Peewee Model here; multiple database can be on a same mysql server or can be on different mysql server, that design also serves like manual data sharding;\n\nso forgot about the qa/prod; I wonder how does peewee support multiple connection to different databases but using the same set of models ? all connection open / close are happening at runtime, depends on input\n", "I'm reopening as a reminder to respond. You've asked a good question and I'd like to write a thorough response.\n", "Docs: http://docs.peewee-orm.com/en/latest/peewee/database.html#using-multiple-databases\n\nSo, by default (unless you specify `threadlocals=False` when instantiating your database), peewee will maintain a connection-per-thread. The interfaces are:\n- `connect()` -- create a connection\n- `get_conn()` -- get the current thread's connection, creating one if it does not exist.\n- `close()` -- close the connection for the current thread.\n\nIf you have two database instances, then they will each have their own connection.\n\nPeewee models access their database via `Model._meta.database`. This attribute can be set **or changed** during run-time. So if you want to use the same models with different databases, it's literally as simple as setting `MyModel._meta.database = some_db`. While this isn't really a common pattern, or one peewee was originally designed to support, it's definitely possible.\n\nI wrote a helper called [Using](http://docs.peewee-orm.com/en/latest/peewee/database.html#using-multiple-databases) that makes this a bit easier. `Using` takes a database and a list of models and acts as either a decorator or a context manager. For the duration of the wrapped block, the models will use a _separately managed_ connection to the specified database.\n\nThe key phrase is _separately managed_. This means that when you use the `Using()` helper, when you enter the wrapped block a new connection is opened to the given database (despite whether there's already one open for that thread). When you exit the block, that connection is closed. And for the duration of the block, the models you passed in will all be pointing at the database specified as the first parameter of `Using`.\n\nDepending on your use-case, this may be all you need. Or you can write your own tooling that handles manipulating `Model._meta.database`.\n\nTo get a better understanding of peewee's connection management, you can read the documents linked below, or read the code -- the entire peewee module can be read in one sitting.\n- http://charlesleifer.com/blog/managing-database-connections-with-peewee/\n- http://docs.peewee-orm.com/en/latest/peewee/database.html#advanced-connection-management\n- http://docs.peewee-orm.com/en/latest/peewee/playhouse.html#connection-pool\n", "that `Using` context manager is somewhat interesting, another use case I can think of is a data migration project I am working on, from the old mysql database, we want to migrate to the latest postgres to utilize the `BinaryJSONField`, because the old design in mysql was a LONGTEXT wrapper of JSONField, when this field grows into megabytes, to update a small portion of this json text isn't very efficient; \nbut it depends on the migration plan may run a couple of months or longer before we can fully shutdown the old service on mysql, this migration project is designed as a RESTful service for UI to call, for each Table entry individually; So in this migration service code, it has to maintain two connections, to mysql and to postgres at same time; while we'll still like to reuse the Model definition code as much as possible, because the biggest change is the old LONGTEXT based JSONField wrapper to postgres native BinaryJSONField; this part will really need a good design, to hold two pooled connection and gives models freedom to access either one\n\nwhile the old design is on django on mysql, but django is really old, although 1.9 has postgres JSONField support, I feel new design should switch to peewee + flask (or some other light weight framework), what would you think @coleifer ? do you see anyone did some comparison ? performance / flexibility / ... ? thanks\n1. http://docs.peewee-orm.com/en/latest/peewee/playhouse.html#postgres-ext-api-notes\n2. https://docs.djangoproject.com/en/1.9/ref/contrib/postgres/fields/#jsonfield\n", "Hi,\r\n\r\nIs `Using` helper still available in latest peewee?\r\n\r\nI am trying to connect to different sqlite databases from different threads at same time, using same models.py (with Proxy)\r\nLet me explain - A request is received on my backend and a thread is being opened. The thread accesses sqlite_1.db with models.py (proxy.initialize) , makes some python calculations for lets say 20 seconds, and then returns a data, selected from the sqlite_1.db.\r\nIn meantime another request comes from another user, that wants to operate on sqlite_2.db, but using the same models.py (and of course, `proxy.initialize(sqlite_2.db)`). New thread is opened and total operation time for this action is 1s. It finishes a lot before the first thread.\r\nSo when the first thread tries to execute a select query on a model from models.py, the DB has changed and it will be executed on sqlite_2.db instead of sqlite_1.db. \r\n\r\nAny solution for this situation, or I should swtich from multiple DBs that I want to change per request to a one DB?\r\n\r\nThanks", "This is the new way: http://docs.peewee-orm.com/en/latest/peewee/api.html#Database.bind_ctx", "Is `bind_ctx` thread safe? Can I bind the same model to different databases in separate threads?\r\n\r\nIf it's possible can you point me to how this works? From my investigation it seems that `bind_ctx` just monkey patches the class attributes with which database to use so if you set it in one thread you'd overwrite whatever it was set to in another thread, is my understanding correct?", "It is *not* thread-safe, no. Database *connections* are thread-safe, but the database attribute itself is not.", "Would you consider a design change where you actually bind models to a database, instead of the other way around?\r\n\r\nBeing unable to use two or more databases simultaneously is limiting.¹ The workarounds to do it anyway are somewhat clumsy. And assuming by default that the developer will initialise his database before declaring his models, even if there are workarounds (like DatabaseProxy), is frankly limiting, and again, results in some weird code.\r\n\r\nAlso it doesn't make sense to import models to access the database (that has been bound to them beforehand, and we can only hope that this has been done: no way to type-check that), instead of actually importing the database object…\r\n\r\nI know, Django does that, but it's a fully-fledged framework, a swiss-knife to do it all, and making bold assumptions on how developer should organise his code and initialise his application is therefore somewhat more \"excusable\"…\r\n\r\nNow, for a tiny library (and being a tiny library is actually a nice thing), that is supposed to provide access to different SQL databases, I expect it to do just that for me, without forcing on me some strange design patterns.\r\n\r\n¹ My simple use-case: I just created a local SQLite database with some data for analytics. Now that I tested my code and I am ready to deploy it, I would like to export the crafted data to a production-ready MySQL database for further analysis. Otherwise, it will take several hours to compute everything from scratch.", "I believe that the vast, vast majority of people use peewee with a single database. The exception is those who want to unit-test, and for their use-case the database proxy / deferred initialization is sufficient. There are ways to change database dynamically at run-time, which are well-documented.\r\n\r\nI can't imagine penalizing the most common use-case to support a very niche usage of running the same models against multiple databases at the same time. Similarly, it seems your problem is you want to export sqlite and import into mysql, and have just assumed that you have to do it with peewee. There are many other ways to accomplish this, dumping to csv being a very good option.", "I understand, my point is not only to suit other use-cases, but rather to come up with a better design, that would be nicer to use, and being suitable for less frequent use-cases would just be a side-effect.\r\n\r\nThis could be something similar to the sessions used in SQLAlchemy:\r\n\r\nhttps://docs.sqlalchemy.org/en/13/orm/tutorial.html\r\n\r\n(I actually used SQLAlchemy before, but this time, I got interested in peewee for its simplicity, SQLAlchemy is a bit of a labyrinth)\r\n\r\nWe could still come up with a simple API, something like:\r\n\r\n```python\r\ndb = connect(\"...\")\r\n# select query\r\ndb.select(User.id, User.name).from(User).where(User.email == 'admin@localhost')\r\n# insert query\r\nu = User(id=1, name=\"Alfred\", email=\"alfred@localhost\")\r\ndb.insert(u)\r\n```\r\n\r\nAnother benefit of such API is that it will appear less \"magic\", things will look more straightforward and explicit.\r\n\r\nAnyway, you wrote a great library, and I thank you for that (and for keeping the issues so tidy!), it's obviously your decision, you have a better view on your own project philosophy, and if I was able to communicate clearly my idea, I am happy with that, whatever path you take :)", "I appreciate that you mean well, but I think you are not considering:\r\n\r\n* peewee has a lot of users, I will never break backwards compatibility in such a fundamental way.\r\n* the *vast* majority of users will only ever use peewee with a single database, but even those who wish to unit-test with a test db will find the current APIs well-suited to the task\r\n\r\npeewee was created because I dislike many aspects of sqlalchemy's design and find it unintuitive and magical - sessions especially.\r\n\r\nThe APIs you are suggesting can already be used with peewee's lower-level query builder interfaces, anyways. You are welcome to explore them -- see `Table` and related classes.", "\"I believe that the vast, vast majority of people use peewee with a single database. \"\r\n\r\nYes. But still some situation for multi database.\r\n\r\nSome application create db for every user. All db have same table. When different user request api. Using `bind_ctx` in one thread the model will change at runtime. And it don't have solution but only use lock to bind model to one db.\r\n\r\nIf we have session concept , One thread have multi session. different session the model using different database. That will be very helpful.\r\n\r\n", "You can subclass the `peewee.Metadata` and make the `database` attribute thread-local. I believe this would address your issue.\r\n\r\n```python\r\n\r\nclass ThreadLocalDbMetadata(Metadata):\r\n ...\r\n\r\nclass BaseModel(Model):\r\n class Meta:\r\n model_metadata_class = ThreadLocalDbMetadata\r\n```", "Thanks. I have two question on this:\r\n\r\n1. It seem need change code to do \"make the database attribute thread-local.\" I am not sure I can make it work.\r\n And it will not be such easy work like `class _ConnectionLocal(_ConnectionState, threading.local): pass`\r\n\r\n2. For my understand. `threading.local` is for single thread. When using fastapi framework, the different requests will be handled in one thread. Is it still address my issue?\r\n", "Never heard of it, not sure if it's multi-threaded (which is what I thought you were asking about).", "@jiamo `fastapi` is an async framework, and `peewee` was not initially designed to work in async app.", "Purely as an FYI - before this thread existed when doing data transformation work, I solved the problem of connecting to multiple databases simply by having my models in a module and then importing that same module multiple times into different namespaces, and using the `DatabaseProxy()` to delay connection timing so I can connect to two different databases.\r\n\r\nSo as an initial test with my models in `MyApp.MyModels` like:\r\n\r\n database_connector = DatabaseProxy()\r\n \r\n class BaseModel(Model):\r\n class Meta:\r\n database = database_connector\r\n \r\n class MyModel(BaseModel):\r\n ...\r\n\r\nIn `Main.py` I had:\r\n\r\n import MyApp.MyModels as SourceData\r\n import MyApp.MyModels as DestinationData\r\n \r\n db_source = ...\r\n SourceData.database_connector.initialize(db_source)\r\n db_destination = ...\r\n DestinationData.database_connector.initialize(db_destination)\r\n \r\n inputData = SourceData.MyModel.select(...).dicts()\r\n\r\n for record in inputData:\r\n ...\r\n\r\nThis all works fine for me. I find that keeping the namespace prefixes of 'SourceData' and 'DestinationData' helped code clarity.", "I also found this issue by referring to how to write to another DB in multiple threads with the same model.\r\nI think it's an uncommon usage, but I'd like you to add a statement to the Thread Safety section of the document that it doesn't support this case.\r\nhttp://docs.peewee-orm.com/en/latest/peewee/database.html#thread-safety\r\n", "https://github.com/coleifer/peewee/issues/221#issuecomment-687625709 is probably the best way to do this in a thread-safe manner.", "@coleifer thanks for a great orm. I'm a bit lost on what's required to \" make the database attribute thread-local\" https://github.com/coleifer/peewee/issues/221#issuecomment-687625709\r\n\r\nMust one use threading.local and change how self.database is defined? Thanks\r\n ", "@coleifer I implemented as follows which seems to work in my tests. Please advise if you suggest I add anything else.\r\n\r\n```\r\nclass ThreadLocalDbMetadata(Metadata):\r\n def __init__(self, model, database=None, *args, **kwargs):\r\n super(ThreadLocalDbMetadata, self).__init__(model, database=None, *args, **kwargs)\r\n self.database = database\r\n\r\n thread_data = threading.local()\r\n\r\n @property\r\n def database(self):\r\n if hasattr(self.thread_data, \"database\"):\r\n return self.thread_data.database\r\n\r\n return None\r\n\r\n @database.setter\r\n def database(self, database):\r\n self.thread_data.database = database\r\n```" ]
"2013-08-05T15:45:52"
"2021-05-03T15:07:52"
"2016-03-30T02:56:48"
NONE
null
Peewee is awesome :+1: :) I'm using Peewee in my Tornado-powered project and I need to define database connection dynamically, like that: ``` python import tornado from peewee import * class Application(tornado.web.Application): def __init__(self, **kwargs): # Some init stuff ... # Setup DB and Models self.database = PostgresqlDatabase('mydb', user='postgres') import myapp.users.models as users self.User = self._get_model(users.User, self.database) # etc... def _get_model(self, model, db): model._meta.database = db model.create_table(True) return model ``` So, I'm using private undocumented `_meta` property and I'm not feeling ok about that and I'm not sure what is the best design decision for that. Anybody have ideas?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/221/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/221/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/220
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/220/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/220/comments
https://api.github.com/repos/coleifer/peewee/issues/220/events
https://github.com/coleifer/peewee/issues/220
17,374,454
MDU6SXNzdWUxNzM3NDQ1NA==
220
SelectQuery loads all models into memory at once
{ "login": "extesy", "id": 65872, "node_id": "MDQ6VXNlcjY1ODcy", "avatar_url": "https://avatars.githubusercontent.com/u/65872?v=4", "gravatar_id": "", "url": "https://api.github.com/users/extesy", "html_url": "https://github.com/extesy", "followers_url": "https://api.github.com/users/extesy/followers", "following_url": "https://api.github.com/users/extesy/following{/other_user}", "gists_url": "https://api.github.com/users/extesy/gists{/gist_id}", "starred_url": "https://api.github.com/users/extesy/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/extesy/subscriptions", "organizations_url": "https://api.github.com/users/extesy/orgs", "repos_url": "https://api.github.com/users/extesy/repos", "events_url": "https://api.github.com/users/extesy/events{/privacy}", "received_events_url": "https://api.github.com/users/extesy/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "This problem can partially be addressed by using this:\n\nhttp://peewee.readthedocs.org/en/latest/peewee/cookbook.html#iterating-over-lots-of-rows\n", "There is also http://initd.org/psycopg/docs/usage.html#server-side-cursors but peewee ~~does not have support for this feature currently~~. Although looking at the docs it should be possible to use it by combining peewee queries with a bit of SQL.\n", "@coleifer I've just tried both `.execute().iterator()` and `.naive().iterator()` but that didn't change anything at all - same 250mb of memory. My for loop looks like this:\n\n```\nfor book in Book.select().where(Book.merchant == m).order_by(Book.last_checked_at).naive().iterator():\n```\n\nAm I doing it wrong?\n", "Try this one:\n\n``` python\n\nbooks = Book.select().where(Book.merchant == m).order_by(Book.last_checked_at).naive()\nbooks_qr = books.execute()\nfor book in books_qr.iterator():\n # ... etc ...\n```\n\nWhat I'm curious about is whether this memory usage is related to caching instances on the results wrapper (so that iterating a query multiple times does not cause multiple queries), or is just due to the way psycopg2 handles large result sets.\n", "No changes using your variant either. How can I confirm if the caching happens on peewee side or psycopg2 side?\n", "I'm willing to wager the issue is with psycopg2. Per the docs (http://initd.org/psycopg/docs/usage.html#server-side-cursors) it sounds like unless you're using server-side cursors all results will be sent to the client:\n\n> When a database query is executed, the Psycopg cursor usually fetches all the records returned by the backend, transferring them to the client process. If the query returned an huge amount of data, a proportionally large amount of memory will be allocated by the client.\n\nMaybe it's time to look into adding support for server-side cursors?\n", "That would be awesome! PostgreSQL is the best open-source database and having pewee support server-side cursors will be great for large datasets.\n", "Added support for named cursors in 9a751322 -- to use them define your db using the \"postgres extensions\" db:\n\n``` python\n\nfrom playhouse.postgres_ext import PostgresqlExtDatabase\n\ndb = PostgresqlExtDatabase('my_db', server_side_cursors=True)\n```\n\nNow any select query will be executed using a server-side cursor. There's a catch, though... There are slightly different calling semantics when using a named cursor (which I will add to the docs eventually, but can be found more or less on psycopg2's docs).\n\nhttp://initd.org/psycopg/docs/usage.html#server-side-cursors\n", "Docs: http://peewee.readthedocs.org/en/latest/peewee/playhouse.html#server-side-cursors\n", "@coleifer Thanks for adding server-side cursors support! Could you please also clarify one thing?\n\nSince I use the same db for all models, this `server_side_cursors` flag will affect all of them. Does that mean I'll have to change all `select` queries in my project to also call `commit`? Is there any way to use server-side cursors for one particular `select` and not everywhere else where I don't need it?\n", "I'll see about making it work a query at a time. The way the code is organized this will be a bit trickier but it should be possible.\n", "Updated: http://peewee.readthedocs.org/en/latest/peewee/playhouse.html#server-side-cursors\n\nNow you just need to use `PostgresqlExtDatabase` and wrap your query in `ServerSide` -- no need to pass `server_side_cursors=True` unless you want _all_ queries to use them.\n", "Much better, thank you!\n" ]
"2013-07-30T02:27:17"
"2013-08-07T02:42:12"
"2013-08-07T00:44:53"
NONE
null
I have a code like this: ``` for book in Book.select().where(Book.merchant == m).order_by(Book.last_checked_at): ``` And there are approximately 100k rows in the table (PostgreSQL). When I don't use any `limit` functions, peewee loads all those 100k rows at the very beginning of the loop and that takes 250mb of memory. When I use `limit(1000)` it only takes 30mb. Is there any way to use cursors to pull models incrementally when they are requested by for loop and not read entire table into memory?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/220/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/220/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/219
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/219/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/219/comments
https://api.github.com/repos/coleifer/peewee/issues/219/events
https://github.com/coleifer/peewee/issues/219
17,150,778
MDU6SXNzdWUxNzE1MDc3OA==
219
Native UUID field
{ "login": "charlierm", "id": 1155497, "node_id": "MDQ6VXNlcjExNTU0OTc=", "avatar_url": "https://avatars.githubusercontent.com/u/1155497?v=4", "gravatar_id": "", "url": "https://api.github.com/users/charlierm", "html_url": "https://github.com/charlierm", "followers_url": "https://api.github.com/users/charlierm/followers", "following_url": "https://api.github.com/users/charlierm/following{/other_user}", "gists_url": "https://api.github.com/users/charlierm/gists{/gist_id}", "starred_url": "https://api.github.com/users/charlierm/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/charlierm/subscriptions", "organizations_url": "https://api.github.com/users/charlierm/orgs", "repos_url": "https://api.github.com/users/charlierm/repos", "events_url": "https://api.github.com/users/charlierm/events{/privacy}", "received_events_url": "https://api.github.com/users/charlierm/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Check out the `playhouse` package, bundled with peewee, as it has support for postgres' UUID field:\n\nhttp://peewee.readthedocs.org/en/latest/peewee/playhouse.html#UUIDField\n", "My mistake, Apologies!\n\nThank you!\n", "No problem, I need to make the playhouse stuff more obvious as there's some pretty fun toys in there!\n" ]
"2013-07-24T11:07:14"
"2013-07-24T13:05:21"
"2013-07-24T13:03:53"
NONE
null
I am unsure as to whether this is suitable, however, it would be beneficial to have a UUID field built into Peewee. PostgreSQL has a native UUID datatype, it could use this when possible, falling back to char when it's not available. UUIDs are popular, it would be lovely to have them built in if only for the convenience!
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/219/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/219/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/218
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/218/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/218/comments
https://api.github.com/repos/coleifer/peewee/issues/218/events
https://github.com/coleifer/peewee/issues/218
17,009,659
MDU6SXNzdWUxNzAwOTY1OQ==
218
Problem with InsertQuery() returning AutoIncremented value
{ "login": "odonnellryan", "id": 1455825, "node_id": "MDQ6VXNlcjE0NTU4MjU=", "avatar_url": "https://avatars.githubusercontent.com/u/1455825?v=4", "gravatar_id": "", "url": "https://api.github.com/users/odonnellryan", "html_url": "https://github.com/odonnellryan", "followers_url": "https://api.github.com/users/odonnellryan/followers", "following_url": "https://api.github.com/users/odonnellryan/following{/other_user}", "gists_url": "https://api.github.com/users/odonnellryan/gists{/gist_id}", "starred_url": "https://api.github.com/users/odonnellryan/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/odonnellryan/subscriptions", "organizations_url": "https://api.github.com/users/odonnellryan/orgs", "repos_url": "https://api.github.com/users/odonnellryan/repos", "events_url": "https://api.github.com/users/odonnellryan/events{/privacy}", "received_events_url": "https://api.github.com/users/odonnellryan/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Hey @odonnellryan no need to apologize, thank you for opening the issue. It seems to me that this would be addressing the effect rather than the cause, which is that your model does not have `auto_increment` set to `True`. Do you mind sharing the model definition that is causing this problem?\n\nFor a small example why I don't like returning the `lastrowid` -- consider if you're using a non-integer primary key... In the following code we insert a row, and give it a primary key of `\"one\"`, but sqlite will return the rowid as `1` (since it is the first row inserted into the table).\n\n``` python\nIn [1]: import sqlite3\n\nIn [2]: conn=sqlite3.connect(':memory:')\n\nIn [3]: curs = conn.cursor()\n\nIn [4]: curs.execute('create table foo (id text primary key, data text\nOut[4]: <sqlite3.Cursor at 0x21e41f0>\n\nIn [5]: res = curs.execute('insert into foo (id, data) values (?, ?)', ['one\n\nIn [6]: res.lastrowid\nOut[6]: 1\n```\n", "Closing pending feedback from @odonnellryan \n" ]
"2013-07-20T18:34:02"
"2013-07-22T02:23:57"
"2013-07-22T02:23:57"
NONE
null
I couldn't get InsertQuery to return the AutoIncremented value upon an Execute. It has (only) returned None for me. Seems to be a problem with this if statement: if model._meta.auto_increment: I've replaced it with: `def last_insert_id(self, cursor, model): if not cursor.lastrowid: return None return cursor.lastrowid` WARNING/DISCLAIMER: I haven't tested this solution, or am I an expert at Python (by any stretch of the means). If you believe I'm doing something horribly wrong, please correct me. lastrowid will return 0 value if it can not return the autoincremented value, from what I can tell. I apologize if I'm mistaken here! New to the open source community. Thanks for writing such a great library, guys!
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/218/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/218/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/217
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/217/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/217/comments
https://api.github.com/repos/coleifer/peewee/issues/217/events
https://github.com/coleifer/peewee/issues/217
16,908,366
MDU6SXNzdWUxNjkwODM2Ng==
217
Where is Q?
{ "login": "andr0s", "id": 298775, "node_id": "MDQ6VXNlcjI5ODc3NQ==", "avatar_url": "https://avatars.githubusercontent.com/u/298775?v=4", "gravatar_id": "", "url": "https://api.github.com/users/andr0s", "html_url": "https://github.com/andr0s", "followers_url": "https://api.github.com/users/andr0s/followers", "following_url": "https://api.github.com/users/andr0s/following{/other_user}", "gists_url": "https://api.github.com/users/andr0s/gists{/gist_id}", "starred_url": "https://api.github.com/users/andr0s/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/andr0s/subscriptions", "organizations_url": "https://api.github.com/users/andr0s/orgs", "repos_url": "https://api.github.com/users/andr0s/repos", "events_url": "https://api.github.com/users/andr0s/events{/privacy}", "received_events_url": "https://api.github.com/users/andr0s/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "If you check, you can see in the notes on upgrading from 1.0 -> 2.0 the API changed and there is no `Q` anymore as the preferred way to query is by referencing the fields directly: http://peewee.readthedocs.org/en/latest/peewee/upgrading.html#upgrading\n\nFor backwards compatibility, `.filter()` can be used along with `DQ` (django Q).\n\nSo, you should be able to use .filter and DQ in your code but just know that there is a much better API if you want it!\n", "Hmmm ok thanks, but I think it would be better to update the docs... At least, note that Q has been renamed to DQ (I didn't try to use it because I wasn't sure that DQ is not 'delete query' =))\n", "I will add that to the upgrading notes, I just realized I didn't include that! Sorry for the confusion.\n", "Added to http://peewee.readthedocs.org/en/latest/peewee/upgrading.html#changes-from-version-1-0\n" ]
"2013-07-18T08:16:41"
"2013-07-18T23:08:35"
"2013-07-18T23:08:35"
NONE
null
So the docs stated that I can use something like this: objs = Obj.filter(Q(name='a') | Q(surname='b')) But when I'm trying to do this, Python simply can't find Q object. I tried to search the source code, but with no luck (found only DQ but not sure it's what I need). I'm porting some existing Django code to peewee for some reasons, and I was upset to see that the compatibility (beautifully stated in the docs) is broken (?). The bad thing here is that the code relies on building custom filtering a lot, so the Q objects is chained many times, combined in many ways so I'd strongly prefer to avoid any modifications. I'm using the peewee version installed using pip (not sure what number it is).
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/217/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/217/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/216
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/216/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/216/comments
https://api.github.com/repos/coleifer/peewee/issues/216/events
https://github.com/coleifer/peewee/issues/216
16,739,664
MDU6SXNzdWUxNjczOTY2NA==
216
Multiple ForeignKeyField in one Model cause failure on deletion
{ "login": "johnmave126", "id": 1661662, "node_id": "MDQ6VXNlcjE2NjE2NjI=", "avatar_url": "https://avatars.githubusercontent.com/u/1661662?v=4", "gravatar_id": "", "url": "https://api.github.com/users/johnmave126", "html_url": "https://github.com/johnmave126", "followers_url": "https://api.github.com/users/johnmave126/followers", "following_url": "https://api.github.com/users/johnmave126/following{/other_user}", "gists_url": "https://api.github.com/users/johnmave126/gists{/gist_id}", "starred_url": "https://api.github.com/users/johnmave126/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/johnmave126/subscriptions", "organizations_url": "https://api.github.com/users/johnmave126/orgs", "repos_url": "https://api.github.com/users/johnmave126/repos", "events_url": "https://api.github.com/users/johnmave126/events{/privacy}", "received_events_url": "https://api.github.com/users/johnmave126/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Following the validation that ensures a related_name cannot override a field on the related model, I have made it raise an `AttributeError` if you attempt to create two foreign keys with the same related_name.\n\nThank you for finding this!\n", "But the case provided is that two foreign keys with no related_name assigned on `__init__`.\nThat is, they will both be assigned `'%s_set' % (model_class._meta.name)` as their related_name\nAlso, I don't think giving two foreign keys with no specified related_name in one Model is something weird...\n", "@johnmave126 -- If I understand correctly you do not like this fix. The rationale is:\n\nCurrently if you set the `related_name` attribute to the value of a field on the related model, it will raise an `AttributeError`, e.g.:\n\n``` python\n\nclass A(Model):\n foo = CharField()\n bs = CharField()\n\nclass B(Model):\n a = ForeignKeyField(related_name='bs') # AttributeError\n```\n\nIt made sense to me to put the same requirement on related names. Thus, if one `related_name` stomps on another `related_name`, raise an `AttributeError`. To me, this is symmetrical and clean.\n\nThe following will result in `AttributeError`:\n\n``` python\n\nclass A(Model):\n pass\nclass B(Model):\n a1 = ForeignKeyField(A)\n a2 = ForeignKeyField(A) # AttributeError since related name stomps on related name for a1\n\n### similarly\nclass A(Model):\n pass\nclass B(Model):\n a1 = ForeignKeyField(related_name='bs')\n a2 = ForeignKeyField(related_name='bs') # AttributeError\n```\n", "@coleifer \nI don't mean I dislike it. I merely mean it might not be a perfect fix on semantical view.\nCurrently I understand it in this way (might not be appropriate, please correct me if I am wrong)\nSetting an explicit related_name means that the rel_model cares about this relationship, or, the entry is meaningful to the rel_model. \nSetting an implicit related_name means that rel_model does not care about this relationship, or, the foreign key is a unilateral referrer from model to rel_model. This relationship is hidden to rel_model (although in fact it is not).\nI don't know how others look at the meaning of foreign keys, my understanding may not be a well accepted one. So please clarify it a little bit if I've gone too far. Thank you for your great peewee!\n", "Ah, that makes sense. Unfortunately, peewee will always create the backref. That has been the default behavior since the initial release so I can't change it now without worrying about breaking code that relies on the auto-generated related_name.\n\nGlad you're liking peewee, thank you for bringing this to my attention!\n", "@coleifer \nI thought about this issue these days and I have some ideas. These ideas are so primitive that I just post them here FYI.\nI think the following behaviour is acceptable and will not cause compatibility problem.\n1. Allow multiple `ForeignKeyField` without explicit `related_name`\n2. Forbid multiple `ForeignKeyField` with same explicit `related_name`\n\nThis behaviour will not cause compatibility problem because the behaviour of explicit `related_name` is unchanged. The change of anonymous `ForeignKeyField` will not affect the execution of current projects based on peewee because these project have no way to and should not back reference these `ForeignKeyField` in the `rel_model`.\n\nHowever, I could not think of an elegant and unified implementation for this behaviour.\nI thought of a dirty solution to construct a list specially for implicit `ForeignKeyField`, but apparently it is too dirty and break the simplicity in the definition of `ForeignKeyField`.\nI also thought of alter the naming scheme on backref of implicit `ForeignKeyField`, but this seems too naive.\nIf anyone notices this and has a better patch, it would be very nice.\n" ]
"2013-07-15T05:04:29"
"2013-07-20T10:58:55"
"2013-07-15T15:03:52"
NONE
null
Reproduction: Using MySQL innoDB (With Foreign Key Constraint check on) peewee version: HEAD of master branch ``` python class SampleA(Model): pass class SampleB(Model): s1 = ForeignKeyField(SampleA, null=True) s2 = ForeignKeyField(SampleA, null=True) instance1 = SampleA.create() instance2 = SampleB.create(s1=instance1, s2=instance2) instance1.delete_instance(recursive=True) # SQL fail on this statement ``` Cause: in class ForeignKeyField -> add_to_class ``` python model_class._meta.fields[self.name] = self model_class._meta.columns[self.db_column] = self self.related_name = self._related_name or '%s_set' % (model_class._meta.name) # this statement ``` ``` python model_class._meta.rel[self.name] = self self.rel_model._meta.reverse_rel[self.related_name] = self # this statement ``` Two ForeignKeyField without related_name assigned will share the same related_name. The latter one will override the former one in meta definition. On deletion, in class Model -> dependencies ``` python for rel_name, fk in klass._meta.reverse_rel.items(): # this statement rel_model = fk.model_class ``` The transversal will ignore the former field, thus not update it. The internal foreign key check by MySQL innoDB will fail on such condition. Possible Fix: 1. Make reverse_rel something like MultiDict instead of a Dict 2. Using different naming scheme for different ForeignKeyField in the same Model P.S.: If your fix might change the structure of current database, wish that you could release a tool to update the current structure.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/216/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/216/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/215
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/215/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/215/comments
https://api.github.com/repos/coleifer/peewee/issues/215/events
https://github.com/coleifer/peewee/issues/215
16,739,136
MDU6SXNzdWUxNjczOTEzNg==
215
Provide information on escaping and SQL injection
{ "login": "arnuschky", "id": 179920, "node_id": "MDQ6VXNlcjE3OTkyMA==", "avatar_url": "https://avatars.githubusercontent.com/u/179920?v=4", "gravatar_id": "", "url": "https://api.github.com/users/arnuschky", "html_url": "https://github.com/arnuschky", "followers_url": "https://api.github.com/users/arnuschky/followers", "following_url": "https://api.github.com/users/arnuschky/following{/other_user}", "gists_url": "https://api.github.com/users/arnuschky/gists{/gist_id}", "starred_url": "https://api.github.com/users/arnuschky/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/arnuschky/subscriptions", "organizations_url": "https://api.github.com/users/arnuschky/orgs", "repos_url": "https://api.github.com/users/arnuschky/repos", "events_url": "https://api.github.com/users/arnuschky/events{/privacy}", "received_events_url": "https://api.github.com/users/arnuschky/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Thanks! Your issue-resolving efficiency is really great!\n" ]
"2013-07-15T04:25:09"
"2013-07-15T14:48:26"
"2013-07-15T14:40:09"
NONE
null
Unfortunately, there seems to be no mentioning of proper escaping using peewee. Is it done automatically? Do we have to do something? How to protect against SQL injection and similar attacks? It would be useful if this could be mentioned in the docs somewhere.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/215/reactions", "total_count": 1, "+1": 1, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/215/timeline
null
completed
null
null