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
timestamp[s]
updated_at
timestamp[s]
closed_at
timestamp[s]
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/514
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/514/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/514/comments
https://api.github.com/repos/coleifer/peewee/issues/514/events
https://github.com/coleifer/peewee/issues/514
55,682,558
MDU6SXNzdWU1NTY4MjU1OA==
514
UUID foreign keys are not cast properly
{ "login": "alexlatchford", "id": 628146, "node_id": "MDQ6VXNlcjYyODE0Ng==", "avatar_url": "https://avatars.githubusercontent.com/u/628146?v=4", "gravatar_id": "", "url": "https://api.github.com/users/alexlatchford", "html_url": "https://github.com/alexlatchford", "followers_url": "https://api.github.com/users/alexlatchford/followers", "following_url": "https://api.github.com/users/alexlatchford/following{/other_user}", "gists_url": "https://api.github.com/users/alexlatchford/gists{/gist_id}", "starred_url": "https://api.github.com/users/alexlatchford/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/alexlatchford/subscriptions", "organizations_url": "https://api.github.com/users/alexlatchford/orgs", "repos_url": "https://api.github.com/users/alexlatchford/repos", "events_url": "https://api.github.com/users/alexlatchford/events{/privacy}", "received_events_url": "https://api.github.com/users/alexlatchford/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Awesome thanks charles!\n" ]
2015-01-27T22:16:08
2015-01-29T06:12:46
2015-01-29T02:17:14
CONTRIBUTOR
null
Found this out by trying to use prefetch and it failing for no reason. I thought it was a problem with the id_map not find the appropriate relation to match on because the data is coming back but simply it's a type mismatch, one is a string and the other is a UUID thus no match :( https://github.com/coleifer/peewee/blob/2.4.6/peewee.py#L3963 Example: ``` python class Parent(Model): uuid = UUIDField(primary_key=True) class Child(Model): name = CharField() parent = ForeignKeyField(Parent) parents = Parent.select() children = Child.select() parents_prefetch = prefetch(parents, children) ``` This should show you the problem. Take a close look at the keys in the id_map, they're the problem :) I've also tried to get `.aggregate_rows()` to work to no avail too, guessing it's the same root problem. Thanks again for the great library Charles!
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/514/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/514/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/513
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/513/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/513/comments
https://api.github.com/repos/coleifer/peewee/issues/513/events
https://github.com/coleifer/peewee/pull/513
55,511,597
MDExOlB1bGxSZXF1ZXN0MjgwNDQyNTU=
513
query results length
{ "login": "dpep", "id": 918804, "node_id": "MDQ6VXNlcjkxODgwNA==", "avatar_url": "https://avatars.githubusercontent.com/u/918804?v=4", "gravatar_id": "", "url": "https://api.github.com/users/dpep", "html_url": "https://github.com/dpep", "followers_url": "https://api.github.com/users/dpep/followers", "following_url": "https://api.github.com/users/dpep/following{/other_user}", "gists_url": "https://api.github.com/users/dpep/gists{/gist_id}", "starred_url": "https://api.github.com/users/dpep/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/dpep/subscriptions", "organizations_url": "https://api.github.com/users/dpep/orgs", "repos_url": "https://api.github.com/users/dpep/repos", "events_url": "https://api.github.com/users/dpep/events{/privacy}", "received_events_url": "https://api.github.com/users/dpep/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Can you define \"exploded\"?\n", "There is already the `SelectQuery.count()` method, which handles some edge-cases, so I'm loth to add another method that does the same thing.\n", "exploded = throws an exception\n\n> TypeError: object of type 'SelectQuery' has no len()\n\nit just felt like the query results object is an iterable container class that should implement the len() function so you can figure out how many results were returned prior to iterating through them. otherwise, you have to do something like\n\n```\nfor res in results:\n do_stuff_with_res(res)\n count += 1\nprint \"you have %d results\" % count\n```\n\nusing Select.count() requires that you either only want a count and not the resulting rows, or else that you have to use two queries. one snag i found:\n\n> Note that it is not uncommon for databases to report -1 after a select statement for performance reasons. (The exact number may not be known before the first records are returned to the application.) - https://code.google.com/p/pyodbc/wiki/Cursor\n\nthis might explain all the Travis failures\n", "There are quite a few test failures resulting from peewee checking the truthiness of the value.\n", "If you want the length of the result set, you can always do `len(list(query))`.\n\nI think I'm going to pass on merging this and mark wontfix.\n", "Why not adding this to SelectQuery:\n\n```\n def __len__(self):\n return self.count()\n```\n\nCalling `len` is very pythonic, and is missing imho.\n\n> If you want the length of the result set, you can always do len(list(query)).\n\nIs this issuing a count on db level, or python level?\n", "As I mentioned above, there are places that check the truthiness of a query variable. Adding a `__len__` method would cause the interpreter to use the query's count for the truth check.\n\nThis may be worth looking into, though.\n", "I looked again and whatever tests had been failing appear to have been fixed. I've added your changes.\n" ]
2015-01-26T17:29:22
2015-10-31T05:40:21
2015-10-31T03:55:05
CONTRIBUTOR
null
a couple times i tried to call len() on the results of a query and it exploded...figured this would be good functionality to add. if you only want a count, i realize that a SELECT COUNT(*) should be used, but there are also times when it would be nice to see how many results i got and use them
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/513/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/513/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/513", "html_url": "https://github.com/coleifer/peewee/pull/513", "diff_url": "https://github.com/coleifer/peewee/pull/513.diff", "patch_url": "https://github.com/coleifer/peewee/pull/513.patch", "merged_at": null }
https://api.github.com/repos/coleifer/peewee/issues/512
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/512/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/512/comments
https://api.github.com/repos/coleifer/peewee/issues/512/events
https://github.com/coleifer/peewee/issues/512
55,342,782
MDU6SXNzdWU1NTM0Mjc4Mg==
512
Support UNION ALL
{ "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
[]
2015-01-23T22:44:11
2015-01-24T23:59:19
2015-01-24T23:59:19
OWNER
null
Add support for UNION ALL queries.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/512/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/512/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/511
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/511/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/511/comments
https://api.github.com/repos/coleifer/peewee/issues/511/events
https://github.com/coleifer/peewee/pull/511
55,226,767
MDExOlB1bGxSZXF1ZXN0Mjc4ODk5MDg=
511
default values
{ "login": "dpep", "id": 918804, "node_id": "MDQ6VXNlcjkxODgwNA==", "avatar_url": "https://avatars.githubusercontent.com/u/918804?v=4", "gravatar_id": "", "url": "https://api.github.com/users/dpep", "html_url": "https://github.com/dpep", "followers_url": "https://api.github.com/users/dpep/followers", "following_url": "https://api.github.com/users/dpep/following{/other_user}", "gists_url": "https://api.github.com/users/dpep/gists{/gist_id}", "starred_url": "https://api.github.com/users/dpep/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/dpep/subscriptions", "organizations_url": "https://api.github.com/users/dpep/orgs", "repos_url": "https://api.github.com/users/dpep/repos", "events_url": "https://api.github.com/users/dpep/events{/privacy}", "received_events_url": "https://api.github.com/users/dpep/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Peewee makes a point of not setting default DB values, so the current behavior is correct.\n", "was it too complicated to get right across platforms?\n", "My feeling was that it could lead to confusing behavior on the python side. If you really want it, you can always use SQL to accomplish default DB values, but it wasn't something I wanted to add to peewee.\n" ]
2015-01-22T23:53:34
2015-01-23T00:46:26
2015-01-23T00:03:13
CONTRIBUTOR
null
field default values were being ignored for column creations and modifications. this change ensures that a field marked with a default value creates a default value in the db. tested this change through the standard Model table creation and schema migrator add_column() function, in mysql and sqlite
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/511/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/511/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/511", "html_url": "https://github.com/coleifer/peewee/pull/511", "diff_url": "https://github.com/coleifer/peewee/pull/511.diff", "patch_url": "https://github.com/coleifer/peewee/pull/511.patch", "merged_at": null }
https://api.github.com/repos/coleifer/peewee/issues/510
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/510/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/510/comments
https://api.github.com/repos/coleifer/peewee/issues/510/events
https://github.com/coleifer/peewee/issues/510
55,202,261
MDU6SXNzdWU1NTIwMjI2MQ==
510
Duplicate field names after stripping '_id' suffix
{ "login": "teeberg", "id": 199071, "node_id": "MDQ6VXNlcjE5OTA3MQ==", "avatar_url": "https://avatars.githubusercontent.com/u/199071?v=4", "gravatar_id": "", "url": "https://api.github.com/users/teeberg", "html_url": "https://github.com/teeberg", "followers_url": "https://api.github.com/users/teeberg/followers", "following_url": "https://api.github.com/users/teeberg/following{/other_user}", "gists_url": "https://api.github.com/users/teeberg/gists{/gist_id}", "starred_url": "https://api.github.com/users/teeberg/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/teeberg/subscriptions", "organizations_url": "https://api.github.com/users/teeberg/orgs", "repos_url": "https://api.github.com/users/teeberg/repos", "events_url": "https://api.github.com/users/teeberg/events{/privacy}", "received_events_url": "https://api.github.com/users/teeberg/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "That was an awesome response time! :-) Thanks so much!\n", "NP! I really appreciate the bug report.\n" ]
2015-01-22T20:09:41
2015-01-23T07:10:54
2015-01-23T01:24:58
NONE
null
For reasons that are beyond me, I'm working on a database that often has fields which have the same name except for the `_id` part at the end, that is one called e.g. `language` and one `language_id`. Generating models for this table using pwiz gives me model definitions like: ``` language = CharField() language = IntegerField(db_column='language_id') ``` Other than that, amazing how little tweaking I had to do! Thank you for the awesome ORM!
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/510/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/510/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/509
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/509/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/509/comments
https://api.github.com/repos/coleifer/peewee/issues/509/events
https://github.com/coleifer/peewee/pull/509
55,142,358
MDExOlB1bGxSZXF1ZXN0Mjc4MzUzMTQ=
509
Revert "Fix Model.create_table(fail_silently=True) if schema is used."
{ "login": "stas", "id": 112147, "node_id": "MDQ6VXNlcjExMjE0Nw==", "avatar_url": "https://avatars.githubusercontent.com/u/112147?v=4", "gravatar_id": "", "url": "https://api.github.com/users/stas", "html_url": "https://github.com/stas", "followers_url": "https://api.github.com/users/stas/followers", "following_url": "https://api.github.com/users/stas/following{/other_user}", "gists_url": "https://api.github.com/users/stas/gists{/gist_id}", "starred_url": "https://api.github.com/users/stas/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/stas/subscriptions", "organizations_url": "https://api.github.com/users/stas/orgs", "repos_url": "https://api.github.com/users/stas/repos", "events_url": "https://api.github.com/users/stas/events{/privacy}", "received_events_url": "https://api.github.com/users/stas/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I took a different approach that should work the same.\n", "Thanks for taking care of it!\n" ]
2015-01-22T11:27:23
2015-01-22T18:20:46
2015-01-22T17:42:00
NONE
null
This commit introduces a regression by overwriting the `PostgresqlDatabase.get_tables()` default value for `schema`. ``` python (Pdb) db <playhouse.pool.PooledPostgresqlExtDatabase object at 0xb620964c> (Pdb) db.get_tables(schema=None) [] (Pdb) db.get_tables() [u'migration', u'users'] ``` One of the affected projects is https://github.com/cam-stitt/arnold Basically migrations no longer go down. @dkorduban sorry to ask for a revert, please provide and update the tests if you really want to fix this issue. @coleifer please try to encourage the presence of tests in contributions :cry:
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/509/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/509/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/509", "html_url": "https://github.com/coleifer/peewee/pull/509", "diff_url": "https://github.com/coleifer/peewee/pull/509.diff", "patch_url": "https://github.com/coleifer/peewee/pull/509.patch", "merged_at": null }
https://api.github.com/repos/coleifer/peewee/issues/508
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/508/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/508/comments
https://api.github.com/repos/coleifer/peewee/issues/508/events
https://github.com/coleifer/peewee/pull/508
55,132,243
MDExOlB1bGxSZXF1ZXN0Mjc4Mjg4MjI=
508
primary null values
{ "login": "dpep", "id": 918804, "node_id": "MDQ6VXNlcjkxODgwNA==", "avatar_url": "https://avatars.githubusercontent.com/u/918804?v=4", "gravatar_id": "", "url": "https://api.github.com/users/dpep", "html_url": "https://github.com/dpep", "followers_url": "https://api.github.com/users/dpep/followers", "following_url": "https://api.github.com/users/dpep/following{/other_user}", "gists_url": "https://api.github.com/users/dpep/gists{/gist_id}", "starred_url": "https://api.github.com/users/dpep/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/dpep/subscriptions", "organizations_url": "https://api.github.com/users/dpep/orgs", "repos_url": "https://api.github.com/users/dpep/repos", "events_url": "https://api.github.com/users/dpep/events{/privacy}", "received_events_url": "https://api.github.com/users/dpep/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Cool, thnx!\n" ]
2015-01-22T09:37:07
2015-01-22T21:32:03
2015-01-22T17:43:49
CONTRIBUTOR
null
MySQL does not allow primary key fields to be null. while it silently swallows any request to allow null values, this library ought to point out the failure to users
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/508/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/508/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/508", "html_url": "https://github.com/coleifer/peewee/pull/508", "diff_url": "https://github.com/coleifer/peewee/pull/508.diff", "patch_url": "https://github.com/coleifer/peewee/pull/508.patch", "merged_at": "2015-01-22T17:43:49" }
https://api.github.com/repos/coleifer/peewee/issues/507
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/507/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/507/comments
https://api.github.com/repos/coleifer/peewee/issues/507/events
https://github.com/coleifer/peewee/pull/507
55,132,068
MDExOlB1bGxSZXF1ZXN0Mjc4Mjg3MTQ=
507
key renames
{ "login": "dpep", "id": 918804, "node_id": "MDQ6VXNlcjkxODgwNA==", "avatar_url": "https://avatars.githubusercontent.com/u/918804?v=4", "gravatar_id": "", "url": "https://api.github.com/users/dpep", "html_url": "https://github.com/dpep", "followers_url": "https://api.github.com/users/dpep/followers", "following_url": "https://api.github.com/users/dpep/following{/other_user}", "gists_url": "https://api.github.com/users/dpep/gists{/gist_id}", "starred_url": "https://api.github.com/users/dpep/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/dpep/subscriptions", "organizations_url": "https://api.github.com/users/dpep/orgs", "repos_url": "https://api.github.com/users/dpep/repos", "events_url": "https://api.github.com/users/dpep/events{/privacy}", "received_events_url": "https://api.github.com/users/dpep/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[]
2015-01-22T09:35:20
2018-01-31T12:42:24
2018-01-31T12:42:24
CONTRIBUTOR
null
MySQL does wierd things when altering the columns of unique or primary keys. It acts as though the user is tring to duplicate the field, rather than simply changing / renaming it (see error messages below). Dropping these keywords from the query gives us the descired outcome anyway (keys remain keys without need to reiterate their definition). wasn't sure whether it was better to leave the code in and comment it out with an explanation or go the cleaner route... Warning: Duplicate index 'old_id' defined on the table 'test.data'. This is deprecated and will be disallowed in a future release. peewee.OperationalError: (1068, 'Multiple primary key defined')
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/507/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/507/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/507", "html_url": "https://github.com/coleifer/peewee/pull/507", "diff_url": "https://github.com/coleifer/peewee/pull/507.diff", "patch_url": "https://github.com/coleifer/peewee/pull/507.patch", "merged_at": null }
https://api.github.com/repos/coleifer/peewee/issues/506
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/506/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/506/comments
https://api.github.com/repos/coleifer/peewee/issues/506/events
https://github.com/coleifer/peewee/issues/506
55,120,106
MDU6SXNzdWU1NTEyMDEwNg==
506
Not support self aggregate alias join any more?
{ "login": "BusyJay", "id": 1701473, "node_id": "MDQ6VXNlcjE3MDE0NzM=", "avatar_url": "https://avatars.githubusercontent.com/u/1701473?v=4", "gravatar_id": "", "url": "https://api.github.com/users/BusyJay", "html_url": "https://github.com/BusyJay", "followers_url": "https://api.github.com/users/BusyJay/followers", "following_url": "https://api.github.com/users/BusyJay/following{/other_user}", "gists_url": "https://api.github.com/users/BusyJay/gists{/gist_id}", "starred_url": "https://api.github.com/users/BusyJay/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/BusyJay/subscriptions", "organizations_url": "https://api.github.com/users/BusyJay/orgs", "repos_url": "https://api.github.com/users/BusyJay/repos", "events_url": "https://api.github.com/users/BusyJay/events{/privacy}", "received_events_url": "https://api.github.com/users/BusyJay/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Ouch, thanks! Will look into this after I get off work today.\n", "Should be fixed in f4481d14d8fc08b5c4c9964d7838af2866f021fd\n", "I'll re-push 2.4.6\n", "verified, thx!\n" ]
2015-01-22T06:43:27
2015-01-25T04:43:11
2015-01-22T18:36:12
NONE
null
Hi, before release 2.4.6, I was able to find out the most recent 5 articles and its comments via: ``` article = Article.select(Article).order_by( Article.publish_time.desc()).paginate(1, 5).alias("ar") for a in Article.select(Article, Comment).join(Comment).join( article, on=(Article.id==article.c.id)).aggregate_rows(): print a ``` But after upgrade to 2.4.6,it raise exception as follow: ``` /home/me/devenv/pyvirt/lib/python2.7/site-packages/peewee.pyc in next(self) 1774 return inst 1775 -> 1776 obj = self.iterate() 1777 self._result_cache.append(obj) 1778 self.__ct += 1 /home/me/devenv/pyvirt/lib/python2.7/site-packages/peewee.pyc in iterate(self) 2040 else: 2041 backref = current._meta.reverse_rel_for_model( -> 2042 join.dest, join.on) 2043 if not backref: 2044 continue /home/me/devenv/pyvirt/lib/python2.7/site-packages/peewee.pyc in reverse_rel_for_model(self, model, field_obj) 3562 3563 def reverse_rel_for_model(self, model, field_obj=None): -> 3564 return model._meta.rel_for_model(self.model_class, field_obj) 3565 3566 def rel_exists(self, model): AttributeError: 'SelectQuery' object has no attribute '_meta' ``` A quick test snippets: ``` import peewee import datetime db = peewee.SqliteDatabase(":memory:") class BaseModel(peewee.Model): class Meta: database = db class Article(peewee.Model): id = peewee.PrimaryKeyField() publish_time = peewee.DateTimeField(default=datetime.datetime.now) class Comment(peewee.Model): id = peewee.PrimaryKeyField() owner_id = peewee.ForeignKeyField(Article) db.connect() db.create_tables([Article, Comment], True) for _ in xrange(21): t1 = Article.create() Comment.create(owner_id=t1) Comment.create(owner_id=t1) article = Article.select(Article).order_by( Article.publish_time.desc()).paginate(1, 5).alias("ar") for a in Article.select(Article, Comment).join(Comment).join( article, on=(Article.id==article.c.id)).aggregate_rows(): print a ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/506/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/506/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/505
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/505/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/505/comments
https://api.github.com/repos/coleifer/peewee/issues/505/events
https://github.com/coleifer/peewee/pull/505
55,100,784
MDExOlB1bGxSZXF1ZXN0Mjc4MTAwNzI=
505
playhouse.migration bug fix
{ "login": "dpep", "id": 918804, "node_id": "MDQ6VXNlcjkxODgwNA==", "avatar_url": "https://avatars.githubusercontent.com/u/918804?v=4", "gravatar_id": "", "url": "https://api.github.com/users/dpep", "html_url": "https://github.com/dpep", "followers_url": "https://api.github.com/users/dpep/followers", "following_url": "https://api.github.com/users/dpep/following{/other_user}", "gists_url": "https://api.github.com/users/dpep/gists{/gist_id}", "starred_url": "https://api.github.com/users/dpep/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/dpep/subscriptions", "organizations_url": "https://api.github.com/users/dpep/orgs", "repos_url": "https://api.github.com/users/dpep/repos", "events_url": "https://api.github.com/users/dpep/events{/privacy}", "received_events_url": "https://api.github.com/users/dpep/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Thanks!\n" ]
2015-01-22T01:02:32
2015-01-22T03:26:24
2015-01-22T02:07:16
CONTRIBUTOR
null
this variable was mis-labeled such that migrations crashed if any column contained extra attributes, like 'auto_increment'. this fixes it
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/505/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/505/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/505", "html_url": "https://github.com/coleifer/peewee/pull/505", "diff_url": "https://github.com/coleifer/peewee/pull/505.diff", "patch_url": "https://github.com/coleifer/peewee/pull/505.patch", "merged_at": "2015-01-22T02:07:16" }
https://api.github.com/repos/coleifer/peewee/issues/504
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/504/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/504/comments
https://api.github.com/repos/coleifer/peewee/issues/504/events
https://github.com/coleifer/peewee/issues/504
54,889,340
MDU6SXNzdWU1NDg4OTM0MA==
504
Constraints not created by db.create_table(Class1), yes by db.create_tables([Class1])
{ "login": "chrisinmtown", "id": 10234212, "node_id": "MDQ6VXNlcjEwMjM0MjEy", "avatar_url": "https://avatars.githubusercontent.com/u/10234212?v=4", "gravatar_id": "", "url": "https://api.github.com/users/chrisinmtown", "html_url": "https://github.com/chrisinmtown", "followers_url": "https://api.github.com/users/chrisinmtown/followers", "following_url": "https://api.github.com/users/chrisinmtown/following{/other_user}", "gists_url": "https://api.github.com/users/chrisinmtown/gists{/gist_id}", "starred_url": "https://api.github.com/users/chrisinmtown/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/chrisinmtown/subscriptions", "organizations_url": "https://api.github.com/users/chrisinmtown/orgs", "repos_url": "https://api.github.com/users/chrisinmtown/repos", "events_url": "https://api.github.com/users/chrisinmtown/events{/privacy}", "received_events_url": "https://api.github.com/users/chrisinmtown/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "The `db.create_table()` method will only create the table, not any of the indexes or constraints. To create a table for a model along with constraints, use `ModelClass.create_table()` or if creating multiple tables, `db.create_tables()`. I understand this is confusing and will update the docs to clarify the difference.\n", "I thank you for updating the documentation. Forgive my grumbling, but my programmer's heart is saddened by enshrining in code & doc different behaviors for functions that at first glance seem to be nearly identical, just one works on a single argument and the other on a list of arguments. \n", "There are historical reasons for this, but I do agree that it can be confusing. The documentation examples all should be showing either `Model.create_table()` or `Database.create_tables()`.\n" ]
2015-01-20T14:31:42
2015-01-24T22:52:43
2015-01-22T18:37:30
NONE
null
In peewee 2.4.5 my tests show that methods create_table() and create_tables() differ in creation of uniqueness constraints. If I use db.create_table(Class1) then my request for uniqueness constraints is silently ignored. If I use db.create_tables([Class1]) then the constraints are created as expected. I'm using MySQL 5.5, connector is PyMySQL 0.6.3. The model below is directly from the documentation; mine is very similar. ``` class Transaction(Model): from_acct = CharField() to_acct = CharField() amount = DecimalField() date = DateTimeField() class Meta: indexes = ( # create a unique on from/to/date (('from_acct', 'to_acct', 'date'), True), # create a non-unique on from/to (('from_acct', 'to_acct'), False), ) ``` I expect a clause in the table definition something like this (sorry this is typed not pasted): ``` UNIQUE KEY `from_acct_to_acct_date` (`from_acct`,`to_acct`,`date`) ``` I was put on the trail by issue https://github.com/coleifer/peewee/issues/211. This is quite a subtle difference! Please harmonize. Thanks for listening and for a very, very useful package.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/504/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/504/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/503
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/503/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/503/comments
https://api.github.com/repos/coleifer/peewee/issues/503/events
https://github.com/coleifer/peewee/issues/503
54,589,189
MDU6SXNzdWU1NDU4OTE4OQ==
503
2.4.5 increased our query count in places we were using aggregate_rows()
{ "login": "jturmel", "id": 37833, "node_id": "MDQ6VXNlcjM3ODMz", "avatar_url": "https://avatars.githubusercontent.com/u/37833?v=4", "gravatar_id": "", "url": "https://api.github.com/users/jturmel", "html_url": "https://github.com/jturmel", "followers_url": "https://api.github.com/users/jturmel/followers", "following_url": "https://api.github.com/users/jturmel/following{/other_user}", "gists_url": "https://api.github.com/users/jturmel/gists{/gist_id}", "starred_url": "https://api.github.com/users/jturmel/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/jturmel/subscriptions", "organizations_url": "https://api.github.com/users/jturmel/orgs", "repos_url": "https://api.github.com/users/jturmel/repos", "events_url": "https://api.github.com/users/jturmel/events{/privacy}", "received_events_url": "https://api.github.com/users/jturmel/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "And by \"in our code\", I meant \"in our tests\"\n", "Interesting -- can you share any of the code or a representative example?\n", "I think perhaps 4c38abd5ea and #482 might be related.\n", "```\nclass Item(DateTimeModel, LocalizedModel, BaseModel):\n name_en = CharField()\n name_es = CharField(null=True)\n description_en = TextField(null=True)\n description_es = TextField(null=True)\n disclaimer_en = CharField(null=True)\n disclaimer_es = CharField(null=True)\n image_url = CharField(null=True)\n labels = JSONArrayField(null=True)\n status = CharField(choices=constants.STATUSES_FULL)\n style = ForeignKeyField(rel_model=Style)\n\nclass Category(DateTimeModel, LocalizedModel, BaseModel):\n parent = ForeignKeyField(rel_model='self', null=True)\n name_en = CharField()\n name_es = CharField(null=True)\n description_en = TextField(null=True)\n description_es = TextField(null=True)\n disclaimer_en = CharField(null=True)\n disclaimer_es = CharField(null=True)\n image_url = CharField(null=True)\n start_at = DateTimeField(null=True)\n end_at = DateTimeField(null=True)\n sort_order = FloatField(default=0)\n is_featured = BooleanField(default=False)\n status = CharField(choices=constants.STATUSES_FULL)\n\nclass CategoryItem(DateTimeModel, BaseModel):\n category = ForeignKeyField(rel_model=Category, on_delete='CASCADE', related_name=\"items\")\n item = ForeignKeyField(rel_model=Item, on_delete='CASCADE', related_name=\"categories\")\n sort_order = FloatField(default=0)\n\n class Meta:\n db_table = 'CategoryItem'\n primary_key = CompositeKey('category', 'item')\n\nclass StyleCategory(DateTimeModel, BaseModel):\n name = CharField()\n\nclass Style(DateTimeModel, BaseModel):\n id = IntegerField(primary_key=True, default=0)\n name = CharField()\n comments = TextField(null=True)\n status = CharField(choices=constants.STATUSES_FULL)\n category = ForeignKeyField(rel_model=StyleCategory)\n\nclass StyleVariant(DateTimeModel, LocalizedModel, BaseModel):\n id = IntegerField(primary_key=True, default=0)\n style = ForeignKeyField(rel_model=Style, on_delete='CASCADE', related_name='variants')\n name_en = CharField()\n name_es = CharField(null=True)\n\nitems = (\n sql.Item.select(\n sql.Item, sql.CategoryItem, sql.Category, sql.Style, sql.StyleVariant)\n .join(sql.CategoryItem, JOIN_LEFT_OUTER)\n .join(sql.Category, JOIN_LEFT_OUTER)\n .switch(sql.Item)\n .join(sql.Style)\n .join(sql.StyleVariant, JOIN_LEFT_OUTER)\n)\n\nwhere = []\nwhere.append(sql.Category.id == params[‘category_id'])\nitems = items.order_by(sql.CategoryItem.sort_order.asc())\n\nif where:\n items = items.where(reduce(operator.and_, where))\n\nitems = list(items.aggregate_rows())\n```\n", "I was hoping for something a little more compact..lol. But I think I've identified the issue and am working on tests/fixes.\n", "@jturmel -- I see that in your query you are doing:\n\n``` python\n .switch(sql.Item)\n .join(sql.Style)\n```\n\nBut I don't see a foreign key between Item and Style. How does this work?\n", "Sorry, was abstracting some of the business specifics...\n\nItem has (updated post above to reflect this):\n style = ForeignKeyField(rel_model=Style)\n", "I've got to be frank, your code you pasted does absolutely nothing to help me :)\n", "No problem, too little context:\n\n```\nclass Item(DateTimeModel, LocalizedModel, BaseModel):\n name_en = CharField()\n name_es = CharField(null=True)\n description_en = TextField(null=True)\n description_es = TextField(null=True)\n disclaimer_en = CharField(null=True)\n disclaimer_es = CharField(null=True)\n image_url = CharField(null=True)\n labels = JSONArrayField(null=True)\n status = CharField(choices=constants.STATUSES_FULL)\n style = ForeignKeyField(rel_model=Style)\n```\n", "No, I mean the whole block. It's massive with all sorts of extraneous fields. I don't know why it's creating the query dynamically, nor do I understand what the expected results are.\n", "@jturmel -- can you produce a _minimal_ example query that replicates the problem? I'm working on it on my end, but am having trouble replicating.\n", "Okay, here's a standalone test that uses Sqlite so should be easy to just run on your end.\n\nhttps://gist.github.com/jturmel/64f7527c4f225b591494\n\nRun under 2.4.4 = 1 query\nRun under 2.4.5 = 5 queries\n", "I'm running this with current peewee master and the test script runs without problems.\n", "Also thank you very much for distilling this down into a small example. I really appreciate it!\n", "EDIT: Actually nevermind, I get the error now. My bad.\n", "The plot thickens... I checked out version 2.4.4 and now instead of 5 queries I am getting 3:\n\n``` sql\n('SELECT \"t1\".\"id\", \"t1\".\"name\", \"t1\".\"style_id\", \"t2\".\"category_id\", \"t2\".\"item_id\", \"t2\".\"sort_order\", \"t3\".\"id\", \"t3\".\"parent_id\", \"t3\".\"sort_order\", \"t4\".\"id\", \"t4\".\"category_id\", \"t5\".\"id\", \"t5\".\"style_id\" FROM \"item\" AS t1 LEFT OUTER JOIN \"categoryitem\" AS t2 ON (\"t1\".\"id\" = \"t2\".\"item_id\") INNER JOIN \"style\" AS t4 ON (\"t1\".\"style_id\" = \"t4\".\"id\") LEFT OUTER JOIN \"stylevariant\" AS t5 ON (\"t5\".\"style_id\" = \"t4\".\"id\") LEFT OUTER JOIN \"category\" AS t3 ON (\"t2\".\"category_id\" = \"t3\".\"id\") WHERE (\"t3\".\"id\" = ?) ORDER BY \"t2\".\"sort_order\" ASC', [1])\n('SELECT \"t1\".\"id\", \"t1\".\"parent_id\", \"t1\".\"sort_order\" FROM \"category\" AS t1 WHERE (\"t1\".\"id\" = ?) LIMIT 1', [1])\n('SELECT \"t1\".\"id\", \"t1\".\"name\", \"t1\".\"style_id\" FROM \"item\" AS t1 WHERE (\"t1\".\"id\" = ?) LIMIT 1', [1])\n```\n\nI made some tweaks to the current version of Python and I am able to get 3 queries, but neither under 2.4.4 or 2.4.5 do I get just one.\n\nThe issue revolves around the way the CompositeKey interacts with the aggregate result wrapper. If I remove the `primary_key = CompositeKey(...)` line then I get a single query.\n\nIs it possible that you all changed that in your code and that's what is causing the test failure?\n", "We just upgraded from 2.4.4 to 2.4.5 to get the latest improvements/fixes\nfor other things and notices this regression and messed with it a bit to\ntry and figure out what was going on but without all the domain knowledge\nit's difficult to dive in so we just ended up rolling back to 2.4.4.\n\nNot sure why it's giving you 3 vs 1 (vs 5) -- the composite key is to\nenforce one of association of item to category (unique key)... any other\nthoughts/ideas?\n\nOn Sat, Jan 17, 2015 at 8:59 PM, Charles Leifer [email protected]\nwrote:\n\n> The plot thickens... I checked out version 2.4.4 and now instead of 5\n> queries I am getting 3:\n> \n> ('SELECT \"t1\".\"id\", \"t1\".\"name\", \"t1\".\"style_id\", \"t2\".\"category_id\", \"t2\".\"item_id\", \"t2\".\"sort_order\", \"t3\".\"id\", \"t3\".\"parent_id\", \"t3\".\"sort_order\", \"t4\".\"id\", \"t4\".\"category_id\", \"t5\".\"id\", \"t5\".\"style_id\" FROM \"item\" AS t1 LEFT OUTER JOIN \"categoryitem\" AS t2 ON (\"t1\".\"id\" = \"t2\".\"item_id\") INNER JOIN \"style\" AS t4 ON (\"t1\".\"style_id\" = \"t4\".\"id\") LEFT OUTER JOIN \"stylevariant\" AS t5 ON (\"t5\".\"style_id\" = \"t4\".\"id\") LEFT OUTER JOIN \"category\" AS t3 ON (\"t2\".\"category_id\" = \"t3\".\"id\") WHERE (\"t3\".\"id\" = ?) ORDER BY \"t2\".\"sort_order\" ASC', [1])\n> ('SELECT \"t1\".\"id\", \"t1\".\"parent_id\", \"t1\".\"sort_order\" FROM \"category\" AS t1 WHERE (\"t1\".\"id\" = ?) LIMIT 1', [1])\n> ('SELECT \"t1\".\"id\", \"t1\".\"name\", \"t1\".\"style_id\" FROM \"item\" AS t1 WHERE (\"t1\".\"id\" = ?) LIMIT 1', [1])\n> \n> I made some tweaks to the current version of Python and I am able to get 3\n> queries, but neither under 2.4.4 or 2.4.5 do I get just one.\n> \n> The issue revolves around the way the CompositeKey interacts with the\n> aggregate result wrapper. If I remove the primary_key = CompositeKey(...)\n> line then I get a single query.\n> \n> Is it possible that you all changed that in your code and that's what is\n> causing the test failure?\n> \n> —\n> Reply to this email directly or view it on GitHub\n> https://github.com/coleifer/peewee/issues/503#issuecomment-70394533.\n", "The problem had to do with the composite primary key. When building the identity map, peewee asks for the primary keys of the constructed instances (to map them back later when constructing the model graph). The problem was that getting the PK value of a composite key field was resolving the foreign keys, triggering 2 extra queries per iteration (one for the category and one for the item). Since there's two iterations, 4 extra queries.\n\nI fixed this by forcing peewee to use the raw field data when mapping composite keys, avoiding the extra lookups.\n", "Great!\n\nFTR, just now I created an entirely new Python env, installed nose and peewee 2.4.4 and was able to see the 3 vs 5 query (as opposed to 1 vs 5 I was seeing in our site's environment) -- that said it's probably not worth figuring out the difference there as it looks like you've figured it out.\n\nThink there should be tests like what I sent as a case so there aren't future regressions on this specifically?\n", "Yeah, see 6fb024372cc77ccae47fb04624840bbee1a84df6\n" ]
2015-01-16T15:43:40
2015-01-18T03:54:08
2015-01-18T03:47:09
NONE
null
In our code we have asserts for query counts to make sure they don't get out of hand by us doing something stupid or Peewee changing in an unexpected way. Once we upgraded from 2.4.4 to 2.4.5 several of our queries with JOINS that were doing one query regressed back to N+1 queries.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/503/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/503/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/502
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/502/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/502/comments
https://api.github.com/repos/coleifer/peewee/issues/502/events
https://github.com/coleifer/peewee/issues/502
54,575,364
MDU6SXNzdWU1NDU3NTM2NA==
502
ManyToManyField in Shortcuts
{ "login": "karelv", "id": 787006, "node_id": "MDQ6VXNlcjc4NzAwNg==", "avatar_url": "https://avatars.githubusercontent.com/u/787006?v=4", "gravatar_id": "", "url": "https://api.github.com/users/karelv", "html_url": "https://github.com/karelv", "followers_url": "https://api.github.com/users/karelv/followers", "following_url": "https://api.github.com/users/karelv/following{/other_user}", "gists_url": "https://api.github.com/users/karelv/gists{/gist_id}", "starred_url": "https://api.github.com/users/karelv/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/karelv/subscriptions", "organizations_url": "https://api.github.com/users/karelv/orgs", "repos_url": "https://api.github.com/users/karelv/repos", "events_url": "https://api.github.com/users/karelv/events{/privacy}", "received_events_url": "https://api.github.com/users/karelv/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Yeah, it's currently only in master. I will be pushing a new version soon which will contain the field.\n" ]
2015-01-16T13:30:21
2015-01-16T15:16:59
2015-01-16T15:16:59
NONE
null
ManyToManyField in Shortcuts module is not working in 2.4.5 ``` py from playhouse.shortcuts import ManyToManyField ``` yields in: ``` from playhouse.shortcuts import ManyToManyField ImportError: cannot import name 'ManyToManyField' ``` So it finds the module, but not the class ManyToManyField... Note: I refer to the example at: http://peewee.readthedocs.org/en/latest/peewee/querying.html#manytomanyfield Where the import statement is used.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/502/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/502/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/501
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/501/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/501/comments
https://api.github.com/repos/coleifer/peewee/issues/501/events
https://github.com/coleifer/peewee/issues/501
54,542,120
MDU6SXNzdWU1NDU0MjEyMA==
501
Why is so much of the logic in a single file?
{ "login": "ianks", "id": 3303032, "node_id": "MDQ6VXNlcjMzMDMwMzI=", "avatar_url": "https://avatars.githubusercontent.com/u/3303032?v=4", "gravatar_id": "", "url": "https://api.github.com/users/ianks", "html_url": "https://github.com/ianks", "followers_url": "https://api.github.com/users/ianks/followers", "following_url": "https://api.github.com/users/ianks/following{/other_user}", "gists_url": "https://api.github.com/users/ianks/gists{/gist_id}", "starred_url": "https://api.github.com/users/ianks/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/ianks/subscriptions", "organizations_url": "https://api.github.com/users/ianks/orgs", "repos_url": "https://api.github.com/users/ianks/repos", "events_url": "https://api.github.com/users/ianks/events{/privacy}", "received_events_url": "https://api.github.com/users/ianks/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "A single file, that's all you need!\n\nIf it were to get to 10K lines I would consider splitting it up, but I don't imagine it will get that big. The code is also already broken up into the core and the `playhouse` extensions collection.\n\nLook around at sqlalchemy, you'll see a number of 3K line files. Django has several 1K+ line files.\n", "My experience of new comer is that this is not so welcoming:\n- I'm missing an overview of the API structure: who inherits who? which logical groups do we have (Model, Fields, Query, Database…)? Where should I go to understand this piece of logic?\n- each time a search for something in the code, I'm missing the context (which class am I? Where in the class hierarchy?)\n- my _own_ perception is that files bigger than around 1k lines are bad practice (mainly for readability, i.e. reasons exposed before), so seeing this huge file made me a bit reluctant being confident in peewee as a serious project when I first considered it for a new project I'm starting\n\nAlso, I'd suggest to namespace `playhouse` (and call it something more expected like \"extras\" or \"extensions\"). I've been reluctant using playhouse module at the first time, because the name suggested me it was more about `playground` or `examples` actual extensions. Also, I was more or less feeling peewee was more of a POC/pet project because of that.\n\nMy two cents… ;)\n", "Peewee has always been a single module. It will remain that way. Honestly there are very few concepts in peewee, and if you read through the entire source, you will have a good grasp on it. Projects that are big, like some other orms, you can't reasonably read. And there's no cohesive order, either. Peewee reads like a book, in order.\n\nGood point about playhouse, need to make it clear those are extensions.\n", "Not to start again the discussion, but for the record: one other drawback about the single file package I've run into: git(hub) blame and history are very noisy because all changes are in the same file, and thus imho hardly usable.\n" ]
2015-01-16T05:51:33
2016-01-29T08:39:21
2015-01-16T18:50:46
NONE
null
Is there a reason that peewee.py contains so much of the logic? Surely this can be broken up into different files. Is there an advantage to doing it this way?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/501/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/501/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/500
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/500/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/500/comments
https://api.github.com/repos/coleifer/peewee/issues/500/events
https://github.com/coleifer/peewee/issues/500
54,508,298
MDU6SXNzdWU1NDUwODI5OA==
500
error with DateTimeField
{ "login": "daufinsyd", "id": 1218113, "node_id": "MDQ6VXNlcjEyMTgxMTM=", "avatar_url": "https://avatars.githubusercontent.com/u/1218113?v=4", "gravatar_id": "", "url": "https://api.github.com/users/daufinsyd", "html_url": "https://github.com/daufinsyd", "followers_url": "https://api.github.com/users/daufinsyd/followers", "following_url": "https://api.github.com/users/daufinsyd/following{/other_user}", "gists_url": "https://api.github.com/users/daufinsyd/gists{/gist_id}", "starred_url": "https://api.github.com/users/daufinsyd/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/daufinsyd/subscriptions", "organizations_url": "https://api.github.com/users/daufinsyd/orgs", "repos_url": "https://api.github.com/users/daufinsyd/repos", "events_url": "https://api.github.com/users/daufinsyd/events{/privacy}", "received_events_url": "https://api.github.com/users/daufinsyd/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "What do the dates in your table look like? Can you show me some examples?\n", "it's\n15/01/2015 22:15\n", "OK, that's the problem. You'll need to subclass `DateTimeField` and specify the `formats` parameter, e.g.\n\n``` python\nclass CustomDateTimeField(DateTimeField):\n formats = ['%d/%m/%Y %H:%M'] + DateTimeField.formats\n```\n" ]
2015-01-15T21:42:28
2015-01-15T23:00:53
2015-01-15T23:00:53
NONE
null
Hello, I can't filter objects from with DateTimeField (with Sqlite), it always return > File "/usr/local/lib/python3.4/dist-packages/peewee.py", line 2825, in execute_sql > cursor.execute(sql, params or ()) > peewee.OperationalError: user-defined function raised exception I have something like this: > class A(Model): > dateA = DateTimeField() > def Function(self): > for a in (A.select().where(A.dateA.year == 2015)): > print('smthg') but if I use > for a in (A.select().where(A.dateA == datetime.datime.now()): It works and > print(A.select().where(A.dateA.year == 2015).count()) > raise the same error. i use sqlite and connect the db with: > db = SqliteDatabase('db.sqlite') > def connectDb(): > db.connect() > db.create_tables([A], true) type: > a = A.get(id=1) > type(a.dateA) > <class str> I didn't found any solution over Internet, do you have any idea ? Thank you
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/500/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/500/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/499
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/499/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/499/comments
https://api.github.com/repos/coleifer/peewee/issues/499/events
https://github.com/coleifer/peewee/issues/499
54,395,037
MDU6SXNzdWU1NDM5NTAzNw==
499
pylint doesn't see some peewee Model fields
{ "login": "richey-v", "id": 6144958, "node_id": "MDQ6VXNlcjYxNDQ5NTg=", "avatar_url": "https://avatars.githubusercontent.com/u/6144958?v=4", "gravatar_id": "", "url": "https://api.github.com/users/richey-v", "html_url": "https://github.com/richey-v", "followers_url": "https://api.github.com/users/richey-v/followers", "following_url": "https://api.github.com/users/richey-v/following{/other_user}", "gists_url": "https://api.github.com/users/richey-v/gists{/gist_id}", "starred_url": "https://api.github.com/users/richey-v/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/richey-v/subscriptions", "organizations_url": "https://api.github.com/users/richey-v/orgs", "repos_url": "https://api.github.com/users/richey-v/repos", "events_url": "https://api.github.com/users/richey-v/events{/privacy}", "received_events_url": "https://api.github.com/users/richey-v/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Can you please format your issue? You can edit it and apply markdown style.\n", "If a model has an auto-increment integer primary key named `id`, the convention is to omit defining it explicitly. This convention comes from Django and I like it. If you want to fix it, just add this field definition to your models:\n\n``` python\nid = PrimaryKeyField()\n```\n\nAlso I see in your schema the foreign keys are `NOT NULL` but in peewee they are marked `null=True` -- you might want to remove that.\n" ]
2015-01-14T23:58:41
2015-01-15T23:35:11
2015-01-15T23:35:11
NONE
null
I'm using peewee with Flask. I have an existing MySQL database and used pwiz to generate a decent model of it. Functionally, everything is working fine, but pylint still complains about a Model field being not detected. Here is the SQL: ``` SQL CREATE TABLE name_instance ( id INT NOT NULL AUTO_INCREMENT, name_id INT NOT NULL, alias_id INT UNIQUE, PRIMARY KEY (id), FOREIGN KEY (name_id) REFERENCES name_variation (id) ON DELETE CASCADE, FOREIGN KEY (alias_id) REFERENCES name_variation (id) ON DELETE CASCADE ); ``` Here is the pwiz-generated class: ``` python class NameInstance(BaseModel): alias = ForeignKeyField(db_column='alias_id', null=True, rel_model=NameVariation, related_name='aliases', to_field='id', unique=True) name = ForeignKeyField(db_column='name_id', rel_model=NameVariation, related_name='names', to_field='id') class Meta: db_table = 'name_instance' ``` In Flask code, I can do this without pylint complaining: ``` python NameInstance.get(NameInstance.name == name_inst_id) ``` but pylint complains about "id" not defined in the following line: ``` python NameInstance.get(NameInstance.id == name_inst_id ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/499/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/499/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/498
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/498/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/498/comments
https://api.github.com/repos/coleifer/peewee/issues/498/events
https://github.com/coleifer/peewee/issues/498
53,788,891
MDU6SXNzdWU1Mzc4ODg5MQ==
498
Custom field not getting parsed using alias
{ "login": "BusyJay", "id": 1701473, "node_id": "MDQ6VXNlcjE3MDE0NzM=", "avatar_url": "https://avatars.githubusercontent.com/u/1701473?v=4", "gravatar_id": "", "url": "https://api.github.com/users/BusyJay", "html_url": "https://github.com/BusyJay", "followers_url": "https://api.github.com/users/BusyJay/followers", "following_url": "https://api.github.com/users/BusyJay/following{/other_user}", "gists_url": "https://api.github.com/users/BusyJay/gists{/gist_id}", "starred_url": "https://api.github.com/users/BusyJay/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/BusyJay/subscriptions", "organizations_url": "https://api.github.com/users/BusyJay/orgs", "repos_url": "https://api.github.com/users/BusyJay/repos", "events_url": "https://api.github.com/users/BusyJay/events{/privacy}", "received_events_url": "https://api.github.com/users/BusyJay/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "When will be next release?\n", "I'll create one soon.\n" ]
2015-01-08T19:17:42
2015-01-21T16:03:41
2015-01-08T20:22:10
NONE
null
Hi, I have a custom field definition like: ``` class CustomField(peewee.Field): def coerce(self, value): return "parsed" class A(peewee.Model): f = CustomField() ``` When I parse custom value to Models directly, it works fine. ``` >>> A.select().where(A.f == 20) <class '__main__.A'> SELECT "t1"."id", "t1"."f" FROM "a" AS t1 WHERE ("t1"."f" = ?) ['parsed'] ``` But, when I use alias, it won't parse the value for me. ``` >>> a = A.alias() >>> A.select().join(a, on=(A.f == a.f)).where(a.f == 20) <class '__main__.A'> SELECT "t1"."id", "t1"."f" FROM "a" AS t1 INNER JOIN "a" AS t2 ON ("t1"."f" = "t2"."f") WHERE ("t2"."f" = ?) [20] ``` What I am expecting is: ``` <class '__main__.A'> SELECT "t1"."id", "t1"."f" FROM "a" AS t1 INNER JOIN "a" AS t2 ON ("t1"."f" = "t2"."f") WHERE ("t2"."f" = ?) ['parsed'] ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/498/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/498/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/497
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/497/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/497/comments
https://api.github.com/repos/coleifer/peewee/issues/497/events
https://github.com/coleifer/peewee/issues/497
53,671,314
MDU6SXNzdWU1MzY3MTMxNA==
497
How to use the read and write with multithreading?
{ "login": "ismkv", "id": 6520418, "node_id": "MDQ6VXNlcjY1MjA0MTg=", "avatar_url": "https://avatars.githubusercontent.com/u/6520418?v=4", "gravatar_id": "", "url": "https://api.github.com/users/ismkv", "html_url": "https://github.com/ismkv", "followers_url": "https://api.github.com/users/ismkv/followers", "following_url": "https://api.github.com/users/ismkv/following{/other_user}", "gists_url": "https://api.github.com/users/ismkv/gists{/gist_id}", "starred_url": "https://api.github.com/users/ismkv/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/ismkv/subscriptions", "organizations_url": "https://api.github.com/users/ismkv/orgs", "repos_url": "https://api.github.com/users/ismkv/repos", "events_url": "https://api.github.com/users/ismkv/events{/privacy}", "received_events_url": "https://api.github.com/users/ismkv/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I'm not exactly sure I understand what problem, specifically, you are encountering.\n", "@coleifer, I made an example for you to understand:\n\n``` python\nfrom peewee import *\nfrom threading import Thread\nfrom random import random, randint\n\nimport os\n\nDB_FILE = 'db.sqlite'\n\nif os.path.isfile(DB_FILE):\n os.remove(DB_FILE)\n\ndb = SqliteDatabase(DB_FILE, threadlocals=True)\n\n\n# Next comes the creation of tables and filling.\nclass Products(Model):\n id = IntegerField(index=True, primary_key=True)\n count_sales = IntegerField()\n updated = IntegerField() # default to zero\n\n class Meta:\n database = db\n\ndb.connect()\ndb.create_tables([Products]) # I have several tables\n\ndata = []\nfor _ in range(0, 40):\n data.append({'count_sales': randint(2, 9), 'updated': 0})\n\nwith db.transaction():\n for data_dict in data:\n Products.create(**data_dict)\n\nprint('Count products: {}\\n'.format(Products.select().count()))\n\n\ndef products_update(n, tables, db):\n Products, = tables\n\n count = Products.select().where(Products.count_sales < 10, Products.updated == 0).count()\n print('Thread #{}, {} records found'.format(n, count))\n if count:\n row = Products.select().where(Products.count_sales < 10, Products.updated == 0).order_by(random()).limit(1).get()\n\n Products.update(updated=1).where(Products.id == row.id).execute()\n\n\nclass MyThread(Thread):\n n = None\n tables = None\n db = None\n\n def run(self):\n products_update(self.n, self.tables, self.db)\n\nfor n in range(1, 5):\n t = MyThread()\n t.tables = (Products,)\n t.db = db\n t.n = n\n t.start()\n\n# Result:\n# --------------------\n# Count products: 40\n#\n# Thread #1, 40 records found\n# Thread #2, 40 records found\n# Thread #3, 40 records found\n# Thread #4, 39 records found\n```\n", "And I need the result to be consistent:\n\n```\n# Thread #1, 40 records found\n# Thread #2, 39 records found\n# Thread #3, 38 records found\n# Thread #4, 37 records found\n```\n", "I appreciate you're spending the time creating this issue, but this isn't the appropriate place for this type of question. Try StackOverflow?\n", "@coleifer Tried, they could not help. Can you tell me where to dig?\n", "I'm failing to see how this is a peewee issue and not an issue of incorrect use of locks or incorrect assumptions about concurrent behavior.\n" ]
2015-01-07T19:29:06
2015-01-08T03:54:01
2015-01-08T00:31:58
NONE
null
Good day. Please help me with a problem. I'm having trouble updating / reading data in a thread when using ORM. I've been using peewee for Python. After reading the documentation starting to initialize the object to work with the database. ``` python db = SqliteDatabase('db.sqlite', threadlocals=True) # Next comes the creation of tables and filling. class Products(Model): id = IntegerField(index=True, primary_key=True) count_sales = IntegerField() updated = IntegerField() # default to zero class Meta: database = db db.connect() db.create_tables([Products, ...]) # I have several tables # I continue to fill the table with data from a file ``` I then create a predetermined amount of threads as follows: ``` python class MyThread(Thread): tables = None db = None def run(self): products_update(self.tables, self.db) for _ in range(1, 20): t = MyThread() t.tables = (Products, ...) t.db = db t.start() ``` The function counts the number of records in the field `count_sales`, and there they are, it changes randomly one of them. ``` python def products_update(tables, db): Products, ... = tables count = Products.select().where(Products.count_sales < 10, Products.updated == 0).limit(1).count() if count: row = Products.select().where(Products.count_sales < 10, Products.updated == 0).order_by(random()).limit(1).get() Products.update(updated=1).where(Products.id == row.id).execute() ``` I need to make the process of finding and updating was linear. **Thank you for your attention. I apologize for the language I used a translator.**
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/497/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/497/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/496
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/496/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/496/comments
https://api.github.com/repos/coleifer/peewee/issues/496/events
https://github.com/coleifer/peewee/issues/496
53,652,235
MDU6SXNzdWU1MzY1MjIzNQ==
496
Add jsonb field support for postgres
{ "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
[ "Yes! I'm very interested in adding this. I currently have 9.3.5 installed so I'll need to get 9.4 running in order to start working on this.\n", "0f48020cf2604966aa77dcd57044b738cc7f44de\n", "I've made a start at implementing this. I'll put together some docs shortly.\n", ":thumbsup:\n", "Any update on this issue @coleifer ???\n", "Support was merged in.\n" ]
2015-01-07T16:39:18
2015-04-01T14:32:54
2015-01-24T23:41:10
NONE
null
PostgreSQL 9.4 now supports binary json field (jsonb), the documentation is here: http://www.postgresql.org/docs/9.4/static/datatype-json.html
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/496/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/496/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/495
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/495/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/495/comments
https://api.github.com/repos/coleifer/peewee/issues/495/events
https://github.com/coleifer/peewee/issues/495
53,458,868
MDU6SXNzdWU1MzQ1ODg2OA==
495
Union with Meta "order_by" clause produces incorrect SQL query
{ "login": "albatros69", "id": 5740149, "node_id": "MDQ6VXNlcjU3NDAxNDk=", "avatar_url": "https://avatars.githubusercontent.com/u/5740149?v=4", "gravatar_id": "", "url": "https://api.github.com/users/albatros69", "html_url": "https://github.com/albatros69", "followers_url": "https://api.github.com/users/albatros69/followers", "following_url": "https://api.github.com/users/albatros69/following{/other_user}", "gists_url": "https://api.github.com/users/albatros69/gists{/gist_id}", "starred_url": "https://api.github.com/users/albatros69/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/albatros69/subscriptions", "organizations_url": "https://api.github.com/users/albatros69/orgs", "repos_url": "https://api.github.com/users/albatros69/repos", "events_url": "https://api.github.com/users/albatros69/events{/privacy}", "received_events_url": "https://api.github.com/users/albatros69/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "This is one of many reasons why default ordering is a bad idea. I regret adding this functionality, but it's too late to remove it now.\n\nAt any rate, you can clear the existing order by clauses on your sub-queries. That should fix the problem:\n\n``` python\nq_orders = cls.select(Type, Order.quantity).join(Wine).join(Order).\\\n where(Type.owner == login.current_user.id).group_by(Type.id).\\\n order_by()\nq_changes = cls.select(Type, fn.sum(ChangeLog.change).alias('quantity')).\\\n join(Wine).join(Order).join(ChangeLog).\\\n where(Type.owner == login.current_user.id).group_by(Type.id).\\\n order_by()\n```\n" ]
2015-01-05T22:55:36
2015-01-06T00:16:06
2015-01-06T00:15:41
NONE
null
Hello, I've tried the following (rather complex I admit) but ended up to an incorrect SQL statement (at least with SQLite). Commenting the "order_by" in the Meta class is a workaround. ``` class Type(Model): [...] class Meta: db_table = 'types' order_by = ('name', ) q_orders = cls.select(Type, Order.quantity).join(Wine).join(Order).\ where(Type.owner == login.current_user.id).group_by(Type.id) q_changes = cls.select(Type, fn.sum(ChangeLog.change).alias('quantity')).\ join(Wine).join(Order).join(ChangeLog).\ where(Type.owner == login.current_user.id).group_by(Type.id) print (q_orders | q_changes) ``` Result: ``` sql SELECT "t2"."id", "t2"."html_color", "t2"."name", "t2"."owner_id", "t4"."quantity" FROM "types" AS t2 INNER JOIN "wines" AS t3 ON ("t2"."id" = "t3"."type_id") INNER JOIN "orders" AS t4 ON ("t3"."id" = "t4"."wine_id") WHERE ("t2"."owner_id" = ?) GROUP BY "t2"."id" ORDER BY "t2"."name" ASC UNION SELECT "t2"."id", "t2"."html_color", "t2"."name", "t2"."owner_id", sum("t5"."change") AS quantity FROM "types" AS t2 INNER JOIN "wines" AS t3 ON ("t2"."id" = "t3"."type_id") INNER JOIN "orders" AS t4 ON ("t3"."id" = "t4"."wine_id") INNER JOIN "changelog" AS t5 ON ("t4"."id" = "t5"."order_id") WHERE ("t2"."owner_id" = ?) GROUP BY "t2"."id" ORDER BY "t2"."name" ASC ``` Which leads to the following SQL error: `Error: ORDER BY clause should come after UNION not before`
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/495/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/495/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/494
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/494/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/494/comments
https://api.github.com/repos/coleifer/peewee/issues/494/events
https://github.com/coleifer/peewee/pull/494
53,387,448
MDExOlB1bGxSZXF1ZXN0MjY4MTg1NjA=
494
[fix] TypeError: host is an invalid keyword argument for this function
{ "login": "ekatsah", "id": 1141204, "node_id": "MDQ6VXNlcjExNDEyMDQ=", "avatar_url": "https://avatars.githubusercontent.com/u/1141204?v=4", "gravatar_id": "", "url": "https://api.github.com/users/ekatsah", "html_url": "https://github.com/ekatsah", "followers_url": "https://api.github.com/users/ekatsah/followers", "following_url": "https://api.github.com/users/ekatsah/following{/other_user}", "gists_url": "https://api.github.com/users/ekatsah/gists{/gist_id}", "starred_url": "https://api.github.com/users/ekatsah/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/ekatsah/subscriptions", "organizations_url": "https://api.github.com/users/ekatsah/orgs", "repos_url": "https://api.github.com/users/ekatsah/repos", "events_url": "https://api.github.com/users/ekatsah/events{/privacy}", "received_events_url": "https://api.github.com/users/ekatsah/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I'm confused -- why is `host` getting used?\n", "Hum i read the doc too rapidly and confused relatif/absolute path. please discard this PR. sorry for the noise.\n\nWas trying to fix this kind of error\n\n```\nself = <peewee.SqliteDatabase object at 0x7fc15db82c90>\ndatabase = 'tmp/file.db', kwargs = {}\n\ndef _connect(self, database, **kwargs):\n> conn = sqlite3.connect(database, **kwargs)\nE OperationalError: unable to open database file\n```\n\nbut the doc is right. furthermore, this fix doesnt cover the use case (absolute path...)\n" ]
2015-01-05T11:33:13
2015-01-05T16:10:06
2015-01-05T16:10:06
NONE
null
Try to fix this: ``` self = <peewee.SqliteDatabase object at 0x7f79bbfcf950>, database = ':memory:' kwargs = {'host': file.db'} def _connect(self, database, **kwargs): > conn = sqlite3.connect(database, **kwargs) E TypeError: 'host' is an invalid keyword argument for this function ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/494/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/494/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/494", "html_url": "https://github.com/coleifer/peewee/pull/494", "diff_url": "https://github.com/coleifer/peewee/pull/494.diff", "patch_url": "https://github.com/coleifer/peewee/pull/494.patch", "merged_at": null }
https://api.github.com/repos/coleifer/peewee/issues/493
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/493/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/493/comments
https://api.github.com/repos/coleifer/peewee/issues/493/events
https://github.com/coleifer/peewee/issues/493
53,263,386
MDU6SXNzdWU1MzI2MzM4Ng==
493
Foreign Key Issue
{ "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
[ "What database engine are you using? That's definitely a bit odd.\n", "If you're using SQLite, you will need to execute `PRAGMA foreign_keys=on;` when you open a connection in order for this to work correctly.\n", "Thank you. I am using SQLite, and this seems to be the solution. :+1:\n", "The problem persists.\n\nTried executing `PRAGMA foreign_keys=on;` using Flasks `before_request` decorator like this\n\n```\[email protected]_request\ndef before_request():\n g.db = db\n g.db.execute_sql('PRAGMA foreign_keys=on')\n g.db.connect()\n```\n\nThe problem still persists.\n", "You just need to swap so you execute the pragma statement **on** the new connection.\n\n``` python\n g.db = db\n g.db.connect()\n g.db.execute_sql('PRAGMA foreign_keys=on')\n```\n\nAlternatively you could subclass `SqliteDatabase`:\n\n``` python\n\nclass SqliteFKDatabase(SqliteDatabase):\n def _add_conn_hooks(self, conn):\n super(SqliteFKDatabase, self)._add_conn_hooks(conn)\n self.execute_sql('PRAGMA foreign_keys=on;')\n```\n", "This seems not like a SQLite specific issue. Tried using MySQL too. The problem still persists. \nWondering wether my model is right. Also `delete_instance()` is enough right?\n", "``` python\nfrom peewee import *\n\ndb = SqliteDatabase(':memory:')\ndb.execute_sql('pragma foreign_keys=on;')\n\nclass Base(Model):\n class Meta:\n database = db\n\nclass A(Base):\n data = IntegerField(default=0)\n\nclass B(Base):\n a = ForeignKeyField(A, on_delete='CASCADE')\n\ndb.create_tables([A, B])\n\na1 = A.create()\na2 = A.create()\nfor a in [a1, a2]:\n for i in range(3):\n B.create(a=a)\n\nprint B.select().count()\na1.delete_instance()\nprint B.select().count()\n```\n\nPrints:\n\n```\n6\n3\n```\n", "Thank you. I had got the concept wrong. \nEvery thing is fine now :+1:\n" ]
2015-01-02T16:59:35
2015-01-05T01:28:35
2015-01-02T19:39:53
NONE
null
I just encountered this issue. Not sure if it had already been reported. I have my models defined as follows ``` class BaseModel(Model): class Meta: database = db class Login(BaseModel): username = TextField(unique=True) password = TextField() class Profile(BaseModel): dname = TextField() about = TextField() photo = TextField() class User(BaseModel): login = ForeignKeyField(Login, on_delete='CASCADE') profile = ForeignKeyField(Profile, null=True, on_delete='CASCADE') ``` When I call `user.delete_instance()` the record from user table is deleted, but record from login table persists. It is wrong right?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/493/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/493/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/492
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/492/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/492/comments
https://api.github.com/repos/coleifer/peewee/issues/492/events
https://github.com/coleifer/peewee/issues/492
53,178,986
MDU6SXNzdWU1MzE3ODk4Ng==
492
pwiz issue with composite primary keys
{ "login": "dkorduban", "id": 340771, "node_id": "MDQ6VXNlcjM0MDc3MQ==", "avatar_url": "https://avatars.githubusercontent.com/u/340771?v=4", "gravatar_id": "", "url": "https://api.github.com/users/dkorduban", "html_url": "https://github.com/dkorduban", "followers_url": "https://api.github.com/users/dkorduban/followers", "following_url": "https://api.github.com/users/dkorduban/following{/other_user}", "gists_url": "https://api.github.com/users/dkorduban/gists{/gist_id}", "starred_url": "https://api.github.com/users/dkorduban/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/dkorduban/subscriptions", "organizations_url": "https://api.github.com/users/dkorduban/orgs", "repos_url": "https://api.github.com/users/dkorduban/repos", "events_url": "https://api.github.com/users/dkorduban/events{/privacy}", "received_events_url": "https://api.github.com/users/dkorduban/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "You should not specify `primary_key=True` if you are specifying a `CompositeKey`. Instead write:\n\n``` python\nclass A(BaseModel):\n id1 = IntegerField()\n id2 = IntegerField()\n\n class Meta:\n db_table = 'a'\n primary_key = CompositeKey('id1', 'id2')\n```\n", "Oh shit, should have read this more closely. You're right.\n" ]
2014-12-31T11:06:45
2014-12-31T17:16:50
2014-12-31T17:16:50
CONTRIBUTOR
null
It generates something like ``` class A(BaseModel): id1 = IntegerField(primary_key=True) id2 = IntegerField(primary_key=True) class Meta: db_table = 'a' primary_key = CompositeKey('id1', 'id2') ``` which in turn leads to ``` ValueError: primary key is overdetermined. ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/492/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/492/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/491
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/491/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/491/comments
https://api.github.com/repos/coleifer/peewee/issues/491/events
https://github.com/coleifer/peewee/pull/491
53,178,577
MDExOlB1bGxSZXF1ZXN0MjY3MjEyMTI=
491
Fix Model.create_table(fail_silently=True) if schema is used.
{ "login": "dkorduban", "id": 340771, "node_id": "MDQ6VXNlcjM0MDc3MQ==", "avatar_url": "https://avatars.githubusercontent.com/u/340771?v=4", "gravatar_id": "", "url": "https://api.github.com/users/dkorduban", "html_url": "https://github.com/dkorduban", "followers_url": "https://api.github.com/users/dkorduban/followers", "following_url": "https://api.github.com/users/dkorduban/following{/other_user}", "gists_url": "https://api.github.com/users/dkorduban/gists{/gist_id}", "starred_url": "https://api.github.com/users/dkorduban/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/dkorduban/subscriptions", "organizations_url": "https://api.github.com/users/dkorduban/orgs", "repos_url": "https://api.github.com/users/dkorduban/repos", "events_url": "https://api.github.com/users/dkorduban/events{/privacy}", "received_events_url": "https://api.github.com/users/dkorduban/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Thank you!\n" ]
2014-12-31T10:55:37
2014-12-31T16:10:05
2014-12-31T16:09:46
CONTRIBUTOR
null
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/491/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/491/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/491", "html_url": "https://github.com/coleifer/peewee/pull/491", "diff_url": "https://github.com/coleifer/peewee/pull/491.diff", "patch_url": "https://github.com/coleifer/peewee/pull/491.patch", "merged_at": "2014-12-31T16:09:46" }
https://api.github.com/repos/coleifer/peewee/issues/490
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/490/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/490/comments
https://api.github.com/repos/coleifer/peewee/issues/490/events
https://github.com/coleifer/peewee/issues/490
53,039,883
MDU6SXNzdWU1MzAzOTg4Mw==
490
PyPy count issue
{ "login": "stas", "id": 112147, "node_id": "MDQ6VXNlcjExMjE0Nw==", "avatar_url": "https://avatars.githubusercontent.com/u/112147?v=4", "gravatar_id": "", "url": "https://api.github.com/users/stas", "html_url": "https://github.com/stas", "followers_url": "https://api.github.com/users/stas/followers", "following_url": "https://api.github.com/users/stas/following{/other_user}", "gists_url": "https://api.github.com/users/stas/gists{/gist_id}", "starred_url": "https://api.github.com/users/stas/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/stas/subscriptions", "organizations_url": "https://api.github.com/users/stas/orgs", "repos_url": "https://api.github.com/users/stas/repos", "events_url": "https://api.github.com/users/stas/events{/privacy}", "received_events_url": "https://api.github.com/users/stas/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Closing this, looks like a https://github.com/spulec/freezegun issue with PyPy.\n" ]
2014-12-29T13:04:25
2014-12-29T14:04:35
2014-12-29T14:04:35
NONE
null
I was upgrading a package and some of our tests on PyPy failed. The backtrace goes down to: ``` peewee-2.4.5-py2.7.egg/peewee.py", line 2433, in _aggregate aggregation = fn.Count(SQL('*')) AttributeError: 'builtin_function' object has no attribute 'Count' ``` Interesting fact, that running the same tests separately works. Only running it with the whole suite, at some point starts failing. Any ideas what could cause this? Thanks in advance.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/490/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/490/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/489
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/489/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/489/comments
https://api.github.com/repos/coleifer/peewee/issues/489/events
https://github.com/coleifer/peewee/issues/489
53,006,273
MDU6SXNzdWU1MzAwNjI3Mw==
489
Database connection not refreshed after wait_timeout
{ "login": "arunisaac", "id": 6452653, "node_id": "MDQ6VXNlcjY0NTI2NTM=", "avatar_url": "https://avatars.githubusercontent.com/u/6452653?v=4", "gravatar_id": "", "url": "https://api.github.com/users/arunisaac", "html_url": "https://github.com/arunisaac", "followers_url": "https://api.github.com/users/arunisaac/followers", "following_url": "https://api.github.com/users/arunisaac/following{/other_user}", "gists_url": "https://api.github.com/users/arunisaac/gists{/gist_id}", "starred_url": "https://api.github.com/users/arunisaac/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/arunisaac/subscriptions", "organizations_url": "https://api.github.com/users/arunisaac/orgs", "repos_url": "https://api.github.com/users/arunisaac/repos", "events_url": "https://api.github.com/users/arunisaac/events{/privacy}", "received_events_url": "https://api.github.com/users/arunisaac/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "You need to close connections when you're done with them. Neither pymysql nor peewee will detect the 2013/2006 error and re-connect automatically.\n", "If you're using the connection pool, then when you close a connection it will be returned to the pool and recycled until it reaches it's stale timeout (specified when initializing the pool).\n\n``` python\n\ndb = PooledMySQLDatabase('my_db', stale_timeout=300) # Consider a conn stale after 5 mins.\n\ndb.connect()\n# do some stuff.\ndb.close() # Return connection to the pool.\n```\n", "Ok. I didn't realize I had to manually connect and close database connections. That makes sense. Thanks a lot!\n\nI do realize this is a very newbie kind of problem, but maybe you could put some more emphasis on this in the documentation - possibly in the quickstart section.\n\nAnyways, thanks for the great ORM! Your work is very much appreciated!\n", "Yeah, while I have added some documentation to this effect, it could certainly stand to be improved. You're not the first person to find this confusing, so I'll make a point to clean up the docs.\n", "![s1419837109 48](https://cloud.githubusercontent.com/assets/119974/5566767/fd8aa9a2-8ef7-11e4-96e3-e1e505e3dde8.png)\n", "Explicitly putting the db.connect() and db.close() statements in some example code might help make the point clear. I noticed that this is shown in the \"Example app\" page in the documentation. But, I hadn't read it until now, because I use cherrypy and I thought the \"Example app\" page was flask specific and not relevant to me. I was mostly going through the \"API Reference\", \"Managing your Database\" and \"Quickstart\" sections of the documentation to try and figure out what had happened.\n", "good idea\n" ]
2014-12-28T18:19:11
2015-01-06T00:10:50
2015-01-06T00:10:50
NONE
null
I'm using peewee with a MySQL database with pymysql being the database driver. The wait_timeout of my mysql database is set to the default value of 8 hours. When my application remains idle for 8 hours, the database connection times out, and any further requests throw MySQL errors 2013 (Lost connection to MySQL server during query) and 2006 (MySQL server has gone away). Similar behaviour also happens with PooledMySQLDatabase connections. Is this behaviour normal? Should I do something to make peewee to reconnect timed out connections, or is pymysql supposed to take care of this?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/489/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/489/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/488
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/488/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/488/comments
https://api.github.com/repos/coleifer/peewee/issues/488/events
https://github.com/coleifer/peewee/issues/488
53,004,974
MDU6SXNzdWU1MzAwNDk3NA==
488
indexes not working: ValueError: too many values to unpack (expected 2)
{ "login": "kshade", "id": 749398, "node_id": "MDQ6VXNlcjc0OTM5OA==", "avatar_url": "https://avatars.githubusercontent.com/u/749398?v=4", "gravatar_id": "", "url": "https://api.github.com/users/kshade", "html_url": "https://github.com/kshade", "followers_url": "https://api.github.com/users/kshade/followers", "following_url": "https://api.github.com/users/kshade/following{/other_user}", "gists_url": "https://api.github.com/users/kshade/gists{/gist_id}", "starred_url": "https://api.github.com/users/kshade/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/kshade/subscriptions", "organizations_url": "https://api.github.com/users/kshade/orgs", "repos_url": "https://api.github.com/users/kshade/repos", "events_url": "https://api.github.com/users/kshade/events{/privacy}", "received_events_url": "https://api.github.com/users/kshade/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "``` python\n class Meta:\n indexes = (\n (('vorname', 'nachname', 'gesamtbrutto'), True), # Add trailing comma.\n )\n```\n" ]
2014-12-28T17:15:33
2014-12-28T17:25:29
2014-12-28T17:25:29
NONE
null
I'm writing a small SQLite-based application with peewee 2.4.5 for which I need to import data from another souce that, sadly, doesn't supply unique IDs. Therefore I want to have my own, internal primary keys and a constraint that makes sure I don't import the same row multiple times. I'm trying to use an unique index to do so: ``` python #!/bin/env python3 # -*- coding: utf-8 -*- import peewee as pw DATABASE = pw.SqliteDatabase('testcase.sqlite3') class BaseModel(pw.Model): class Meta: database = DATABASE class Employee(BaseModel): eid = pw.PrimaryKeyField() gesamtbrutto = pw.IntegerField(null=True) vorname = pw.TextField(null=True) nachname = pw.TextField(null=True) class Meta: indexes = ((('vorname', 'nachname', 'gesamtbrutto'), True)) if __name__ == "__main__": DATABASE.connect() DATABASE.create_tables([Employee], safe=True) ``` Sadly this doesn't work: ``` $ rm testcase.sqlite3 $ ./testcase.py Traceback (most recent call last): File "./testcase.py", line 23, in <module> DATABASE.create_tables([Employee], safe=True) File "/usr/lib64/python3.3/site-packages/peewee.py", line 2915, in create_tables create_model_tables(models, fail_silently=safe) File "/usr/lib64/python3.3/site-packages/peewee.py", line 3983, in create_model_tables m.create_table(**create_table_kwargs) File "/usr/lib64/python3.3/site-packages/peewee.py", line 3740, in create_table cls._create_indexes() File "/usr/lib64/python3.3/site-packages/peewee.py", line 3763, in _create_indexes for fields, unique in cls._meta.indexes: ValueError: too many values to unpack (expected 2) $ sqlite3 testcase.sqlite3 SQLite version 3.8.7.4 2014-12-09 01:34:36 Enter ".help" for usage hints. sqlite> .dump employee PRAGMA foreign_keys=OFF; BEGIN TRANSACTION; CREATE TABLE "employee" ("eid" INTEGER NOT NULL PRIMARY KEY, "gesamtbrutto" INTEGER, "vorname" TEXT, "nachname" TEXT); COMMIT; ``` Am I missing something here? Is this feature not available in SQLite?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/488/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/488/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/487
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/487/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/487/comments
https://api.github.com/repos/coleifer/peewee/issues/487/events
https://github.com/coleifer/peewee/pull/487
52,983,407
MDExOlB1bGxSZXF1ZXN0MjY2MjQ5NjI=
487
Fix Introspector schema handling.
{ "login": "dkorduban", "id": 340771, "node_id": "MDQ6VXNlcjM0MDc3MQ==", "avatar_url": "https://avatars.githubusercontent.com/u/340771?v=4", "gravatar_id": "", "url": "https://api.github.com/users/dkorduban", "html_url": "https://github.com/dkorduban", "followers_url": "https://api.github.com/users/dkorduban/followers", "following_url": "https://api.github.com/users/dkorduban/following{/other_user}", "gists_url": "https://api.github.com/users/dkorduban/gists{/gist_id}", "starred_url": "https://api.github.com/users/dkorduban/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/dkorduban/subscriptions", "organizations_url": "https://api.github.com/users/dkorduban/orgs", "repos_url": "https://api.github.com/users/dkorduban/repos", "events_url": "https://api.github.com/users/dkorduban/events{/privacy}", "received_events_url": "https://api.github.com/users/dkorduban/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[]
2014-12-28T15:20:41
2014-12-29T03:21:17
2014-12-29T03:21:17
CONTRIBUTOR
null
Partially fixes #486.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/487/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/487/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/487", "html_url": "https://github.com/coleifer/peewee/pull/487", "diff_url": "https://github.com/coleifer/peewee/pull/487.diff", "patch_url": "https://github.com/coleifer/peewee/pull/487.patch", "merged_at": null }
https://api.github.com/repos/coleifer/peewee/issues/486
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/486/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/486/comments
https://api.github.com/repos/coleifer/peewee/issues/486/events
https://github.com/coleifer/peewee/issues/486
52,983,378
MDU6SXNzdWU1Mjk4MzM3OA==
486
pwiz doesn't work well with schemas.
{ "login": "dkorduban", "id": 340771, "node_id": "MDQ6VXNlcjM0MDc3MQ==", "avatar_url": "https://avatars.githubusercontent.com/u/340771?v=4", "gravatar_id": "", "url": "https://api.github.com/users/dkorduban", "html_url": "https://github.com/dkorduban", "followers_url": "https://api.github.com/users/dkorduban/followers", "following_url": "https://api.github.com/users/dkorduban/following{/other_user}", "gists_url": "https://api.github.com/users/dkorduban/gists{/gist_id}", "starred_url": "https://api.github.com/users/dkorduban/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/dkorduban/subscriptions", "organizations_url": "https://api.github.com/users/dkorduban/orgs", "repos_url": "https://api.github.com/users/dkorduban/repos", "events_url": "https://api.github.com/users/dkorduban/events{/privacy}", "received_events_url": "https://api.github.com/users/dkorduban/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[]
2014-12-28T15:19:32
2014-12-28T17:24:00
2014-12-28T17:24:00
CONTRIBUTOR
null
When you run `python -m pwiz -e postgresql -u postgres -s schemaname dbname` it creates an empty model stub.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/486/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/486/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/485
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/485/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/485/comments
https://api.github.com/repos/coleifer/peewee/issues/485/events
https://github.com/coleifer/peewee/issues/485
52,825,165
MDU6SXNzdWU1MjgyNTE2NQ==
485
Docs are generated from master instead of latest stable
{ "login": "timovwb", "id": 893402, "node_id": "MDQ6VXNlcjg5MzQwMg==", "avatar_url": "https://avatars.githubusercontent.com/u/893402?v=4", "gravatar_id": "", "url": "https://api.github.com/users/timovwb", "html_url": "https://github.com/timovwb", "followers_url": "https://api.github.com/users/timovwb/followers", "following_url": "https://api.github.com/users/timovwb/following{/other_user}", "gists_url": "https://api.github.com/users/timovwb/gists{/gist_id}", "starred_url": "https://api.github.com/users/timovwb/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/timovwb/subscriptions", "organizations_url": "https://api.github.com/users/timovwb/orgs", "repos_url": "https://api.github.com/users/timovwb/repos", "events_url": "https://api.github.com/users/timovwb/events{/privacy}", "received_events_url": "https://api.github.com/users/timovwb/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "There's now a `stable` branch with corresponding docs. I will keep the `stable` branch pinned to the latest tag:\n\nhttp://docs.peewee-orm.com/en/stable/\n" ]
2014-12-24T15:46:46
2014-12-24T20:49:41
2014-12-24T20:49:41
NONE
null
It looks like the documentation is generated against master instead of the latest stable release. I was looking at implementing ManyToMany and noticed I couldn't import the `ManyToManyField` which is mentioned in the docs. A quick look at the latest commits show that this is added after the 2.4.5 release. It's a bit confusing as the page title of the documentation mentions that 2.4.5 version. Mentioned at these two pages: http://peewee.readthedocs.org/en/latest/peewee/querying.html#manytomanyfield http://peewee.readthedocs.org/en/latest/peewee/playhouse.html#ManyToManyField
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/485/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/485/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/484
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/484/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/484/comments
https://api.github.com/repos/coleifer/peewee/issues/484/events
https://github.com/coleifer/peewee/pull/484
52,577,033
MDExOlB1bGxSZXF1ZXN0MjY0MjEwMTc=
484
Support for Expression-based joins when using aggregate_rows()
{ "login": "arrowgamer", "id": 779694, "node_id": "MDQ6VXNlcjc3OTY5NA==", "avatar_url": "https://avatars.githubusercontent.com/u/779694?v=4", "gravatar_id": "", "url": "https://api.github.com/users/arrowgamer", "html_url": "https://github.com/arrowgamer", "followers_url": "https://api.github.com/users/arrowgamer/followers", "following_url": "https://api.github.com/users/arrowgamer/following{/other_user}", "gists_url": "https://api.github.com/users/arrowgamer/gists{/gist_id}", "starred_url": "https://api.github.com/users/arrowgamer/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/arrowgamer/subscriptions", "organizations_url": "https://api.github.com/users/arrowgamer/orgs", "repos_url": "https://api.github.com/users/arrowgamer/repos", "events_url": "https://api.github.com/users/arrowgamer/events{/privacy}", "received_events_url": "https://api.github.com/users/arrowgamer/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Thanks a lot. I'm sorry for all the pull requests and stuff. These are just the issues I've found thus far in using your ORM in a personal project of mine, and I thought it'd be nice to share them so others don't run into the same =)\n", "No, I appreciate it! Thanks for your help!\n", "Sure! =)\n" ]
2014-12-20T21:21:35
2014-12-20T23:52:46
2014-12-20T23:24:32
CONTRIBUTOR
null
Joining on an Expression when using aggregate_rows() would cause an error because rel_for_model only handles Fields. Consider the following data models: ``` python class Organization(BaseModel): name = CharField() class Review(BaseModel): rating = IntegerField() organization = ForeignKeyField(Organization, related_name='reviews') ``` I want to query for an organization by ID and eagerly load its reviews that are higher than 3. ``` python (Organization .select(Organization, Review) .join(Review, JOIN_LEFT_OUTER, on=((Review.organization == Organization.id) & (Review.rating > 3)).alias('organization')) .where(Organization.id == 1) .aggregate_rows())[0] ``` Note the usage of [0] because of #483. The above would fail because rel_for_model does not support Expressions. I am doing the filter on the join instead of the where, because the query should still pull organization data even if there are no reviews above the rating of 3.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/484/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/484/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/484", "html_url": "https://github.com/coleifer/peewee/pull/484", "diff_url": "https://github.com/coleifer/peewee/pull/484.diff", "patch_url": "https://github.com/coleifer/peewee/pull/484.patch", "merged_at": null }
https://api.github.com/repos/coleifer/peewee/issues/483
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/483/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/483/comments
https://api.github.com/repos/coleifer/peewee/issues/483/events
https://github.com/coleifer/peewee/issues/483
52,576,702
MDU6SXNzdWU1MjU3NjcwMg==
483
Using .get() with .aggregate_rows()
{ "login": "arrowgamer", "id": 779694, "node_id": "MDQ6VXNlcjc3OTY5NA==", "avatar_url": "https://avatars.githubusercontent.com/u/779694?v=4", "gravatar_id": "", "url": "https://api.github.com/users/arrowgamer", "html_url": "https://github.com/arrowgamer", "followers_url": "https://api.github.com/users/arrowgamer/followers", "following_url": "https://api.github.com/users/arrowgamer/following{/other_user}", "gists_url": "https://api.github.com/users/arrowgamer/gists{/gist_id}", "starred_url": "https://api.github.com/users/arrowgamer/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/arrowgamer/subscriptions", "organizations_url": "https://api.github.com/users/arrowgamer/orgs", "repos_url": "https://api.github.com/users/arrowgamer/repos", "events_url": "https://api.github.com/users/arrowgamer/events{/privacy}", "received_events_url": "https://api.github.com/users/arrowgamer/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Refs #480\n", "Your options proposed there do make sense! Performing a separate query isn't that big of an issue given that the usage of get() implies there will only be one parent object. However, in the case that you're joining on many different tables, I suppose you'd need a separate query for each of them, or use the [0] option as I did in #484.\n\nPlease note that #484 is not dependent on single row selects, however, as it can apply to selecting all rows with an Expression-based join.\n" ]
2014-12-20T21:08:30
2014-12-20T23:29:52
2014-12-20T23:29:52
CONTRIBUTOR
null
Consider the following data models: ``` python class Organization(BaseModel): name = CharField() class Review(BaseModel): rating = IntegerField() organization = ForeignKeyField(Organization, related_name='reviews') ``` If I wanted to get an organization by its ID and eagerly load its reviews, the LIMIT 1 that gets applied to the query due to .get() prevents it from getting any more than the first review. ``` python (Organization .select(Organization, Review) .join(Review, JOIN_LEFT_OUTER) .where(Organization.id == 1) .aggregate_rows()).get() ``` Is this expected functionality? Would this need to be done using prefetch()? Or is there a different way of structuring this query?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/483/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/483/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/482
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/482/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/482/comments
https://api.github.com/repos/coleifer/peewee/issues/482/events
https://github.com/coleifer/peewee/pull/482
52,558,616
MDExOlB1bGxSZXF1ZXN0MjY0MTQ1MTA=
482
Support for filtering by joined table outside of select
{ "login": "arrowgamer", "id": 779694, "node_id": "MDQ6VXNlcjc3OTY5NA==", "avatar_url": "https://avatars.githubusercontent.com/u/779694?v=4", "gravatar_id": "", "url": "https://api.github.com/users/arrowgamer", "html_url": "https://github.com/arrowgamer", "followers_url": "https://api.github.com/users/arrowgamer/followers", "following_url": "https://api.github.com/users/arrowgamer/following{/other_user}", "gists_url": "https://api.github.com/users/arrowgamer/gists{/gist_id}", "starred_url": "https://api.github.com/users/arrowgamer/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/arrowgamer/subscriptions", "organizations_url": "https://api.github.com/users/arrowgamer/orgs", "repos_url": "https://api.github.com/users/arrowgamer/repos", "events_url": "https://api.github.com/users/arrowgamer/events{/privacy}", "received_events_url": "https://api.github.com/users/arrowgamer/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I fixed this with a slightly smaller change: 4c38abd5ea1c0d05226e181fced3895ada8ee73d\n", "I took a look. Awesome!\n" ]
2014-12-20T09:35:34
2014-12-20T19:56:30
2014-12-20T18:49:47
CONTRIBUTOR
null
Filtering by a joined table that is not part of the select would cause a KeyError when using aggregate_rows. Consider the following example models: ``` python class Organization(Model): name = CharField() class Job(Model): name = CharField() organization = ForeignKeyField(Organization) class Employee(Model): name = CharField() organization = ForeignKeyField(Organization) job = ForeignKeyField(Job) ``` Setup some basic records like so: ``` python testing = Organization.create(name='Testing Co.') tester = Job.create(name='Tester', organization=testing) Employee.create(name='Tester Guy', organization=testing, job=tester) ``` The below throws an unhandled KeyError because the second join that is used to filter is not included in the select. The intent of the query below is to eagerly load an organization and all its jobs based on an employee's name, but not to load the employee's data. ``` python (Organization .select(Organization, Job) .join(Job) .switch(Organization) .join(Employee) .where(Employee.name == 'Tester Guy') .aggregate_rows() .get()) ``` Adding the try/except after line 2036 fixes this. The below throws an unhandled KeyError because the second join that is used to filter is not included in the select. The intent of the query below is to eagerly load an employee and all its jobs based on an organization's name, but not to load the organization's data. ``` python (Employee .select(Employee, Job) .join(Job) .switch(Employee) .join(Organization) .where(Organization.name == 'Testing Co.') .aggregate_rows() .get()) ``` Adding the try/except after line 2020 fixes this.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/482/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/482/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/482", "html_url": "https://github.com/coleifer/peewee/pull/482", "diff_url": "https://github.com/coleifer/peewee/pull/482.diff", "patch_url": "https://github.com/coleifer/peewee/pull/482.patch", "merged_at": null }
https://api.github.com/repos/coleifer/peewee/issues/481
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/481/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/481/comments
https://api.github.com/repos/coleifer/peewee/issues/481/events
https://github.com/coleifer/peewee/issues/481
52,533,780
MDU6SXNzdWU1MjUzMzc4MA==
481
ForeignKey related_name problem
{ "login": "tigrus", "id": 804424, "node_id": "MDQ6VXNlcjgwNDQyNA==", "avatar_url": "https://avatars.githubusercontent.com/u/804424?v=4", "gravatar_id": "", "url": "https://api.github.com/users/tigrus", "html_url": "https://github.com/tigrus", "followers_url": "https://api.github.com/users/tigrus/followers", "following_url": "https://api.github.com/users/tigrus/following{/other_user}", "gists_url": "https://api.github.com/users/tigrus/gists{/gist_id}", "starred_url": "https://api.github.com/users/tigrus/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/tigrus/subscriptions", "organizations_url": "https://api.github.com/users/tigrus/orgs", "repos_url": "https://api.github.com/users/tigrus/repos", "events_url": "https://api.github.com/users/tigrus/events{/privacy}", "received_events_url": "https://api.github.com/users/tigrus/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Related names are \"back references\", a handy way of accessing a collection of objects relating _to_ the given instance. For example say you have user and tweet models. You would say a tweet has one user, while a user has many tweets. That gives you a foreign key named user and a related name of tweets:\n\n``` python\nclass User(Model):\n username = CharField()\n\nclass Tweet(Model):\n user = ForeignKeyField(User, related_name='tweets')\n content = TextField()\n```\n\nThis will patch a new attribute onto the user model named `tweets`. If the `User` already had a field named `tweets`, though, then peewee would not like it because the related name attribute it's trying to add is taken.\n\nThat's one part of the issue. To fix this, I would suggest calling your related_name \"res_users\":\n\n``` python\nclass ResUsers(BaseModel):\n #gave up here... it reference to self, but have same error\n create_uid = peewee.IntegerField()\n\nclass ProductPriceType(BaseModel):\n class Meta:\n managed = False\n db_table = 'product_price_type'\n\n create_uid = peewee.ForeignKeyField(ResUsers, null=True, related_name=\"res_users\")\n```\n\nTo create a self-referential foreign key, you can do:\n\n``` python\nclass ResUsers(BaseModel):\n create_uid = peewee.ForeignKeyField('self', related_name='users_created')\n```\n\nDocumentation:\n- http://docs.peewee-orm.com/en/latest/peewee/models.html#self-referential-foreign-keys\n- http://docs.peewee-orm.com/en/latest/peewee/api.html#ForeignKeyField\n\nPlease let me know if this does not address your question.\n", "Looks like I've understood difference between django ORM and Peewee in this part. \nWill update ticket, if something will go wrong. Thanks. \n" ]
2014-12-19T22:02:54
2014-12-19T22:36:26
2014-12-19T22:14:18
NONE
null
We have following models: ``` class ResUsers(BaseModel): #gave up here... it reference to self, but have same error create_uid = peewee.IntegerField() class ProductPriceType(BaseModel): class Meta: managed = False db_table = 'product_price_type' create_uid = peewee.ForeignKeyField(ResUsers, null=True, related_name="create_uid") ``` When I'm using this models, I have following error: AttributeError: Foreign key: productpricetype.create_uid related name "create_uid" collision with model field of the same name. Temporary solution - usage of IntegerFields. How this part of code should be designed with ForeignKeys? We use existing legacy db scheme.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/481/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/481/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/480
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/480/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/480/comments
https://api.github.com/repos/coleifer/peewee/issues/480/events
https://github.com/coleifer/peewee/issues/480
52,261,553
MDU6SXNzdWU1MjI2MTU1Mw==
480
Using .aggregate_rows() with .get() doesn't work correctly
{ "login": "jturmel", "id": 37833, "node_id": "MDQ6VXNlcjM3ODMz", "avatar_url": "https://avatars.githubusercontent.com/u/37833?v=4", "gravatar_id": "", "url": "https://api.github.com/users/jturmel", "html_url": "https://github.com/jturmel", "followers_url": "https://api.github.com/users/jturmel/followers", "following_url": "https://api.github.com/users/jturmel/following{/other_user}", "gists_url": "https://api.github.com/users/jturmel/gists{/gist_id}", "starred_url": "https://api.github.com/users/jturmel/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/jturmel/subscriptions", "organizations_url": "https://api.github.com/users/jturmel/orgs", "repos_url": "https://api.github.com/users/jturmel/repos", "events_url": "https://api.github.com/users/jturmel/events{/privacy}", "received_events_url": "https://api.github.com/users/jturmel/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "`aggregate_rows()` was not really intended, when I wrote it, for fetching single instances via `.get()`. Can you explain your specific use case? I might be able to suggest some equally viable alternatives.\n", "We have an alternative, we just don't use .get(), we just run the normal \"list\" query, check to see if there are any results, and pick off the first result, it's just not as elegant as using .get() and catching the peewee.DoesNotExist exception\n\nUsing an example from the docs: http://peewee.readthedocs.org/en/latest/peewee/quickstart.html\n\n``` python\n>>> subquery = Pet.select(fn.COUNT(Pet.id)).where(Pet.owner == Person.id).\n>>> person = (Person\n... .select(Person, Pet, subquery.alias('pet_count'))\n... .join(Pet, JOIN_LEFT_OUTER)\n... .order_by(Person.name)\n... .where(Person.id == 1)\n... .aggregate_rows()\n... .get())\n\n... print person.name, person.pet_count, 'pets'\n... for pet in person.pets:\n... print ' ', pet.name, pet.animal_type\n```\n", "So the `.get()` helper works efficiently by calling `LIMIT 1`. `aggregate_rows()` does not work well with `LIMIT` because the data is de-duped and aggregated (hence aggregate_rows) on the python side. Also note the row**s** -- it is intended to work with multiple rows of data.\n\nYou can still achieve what you're going for in O(1) queries, you'll just need to make 2 instead of 1:\n\n``` python\nperson = Person.get(Person.id == 1)\npets = Pet.select().where(Pet.owner == person)\n# or\npets = person.pets\n```\n\nIn addition to being roughly equivalent in terms of performance, this is probably quite a bit more efficient than `aggregate_rows()`.\n\nNote: I edited your comment to fix the syntax highlighting.\n", "Do you have any additional questions or thoughts? If not, I will go ahead and close the issue.\n", "Definitely understand, that's fine on closing it.\n\nIt does seem like .get() could just be intelligent enough that if .aggregate_rows() is set on the query that it drops the LIMIT 1, that way aggregate rows still collects the records under the single record but the case where they don't use aggregate_rows() is still optimal.\n", "Yeah, it would be possible, but I'm loth to introduce special-cases. Particularly because, in my mind, the use-cases for `.get()` and `.aggregate_rows()` are quite different. With `.get()` you have some piece of information to uniquely identify a row, so you're already looking at O(1). Whereas with `.aggregate_rows()` you're looking to grab multiple rows and avoiding the dreaded N+1 query problem. Since `.get()` already implies you don't have N+1, I think it's acceptable to avoid special-casing.\n\nThat said, I will update the docs to make this clear. Thanks for reporting the issue!\n" ]
2014-12-17T16:38:01
2014-12-17T19:25:39
2014-12-17T19:25:39
NONE
null
It only returns one item on the back reference lists even if the item had more in the tables that were joined in.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/480/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/480/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/479
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/479/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/479/comments
https://api.github.com/repos/coleifer/peewee/issues/479/events
https://github.com/coleifer/peewee/issues/479
51,988,552
MDU6SXNzdWU1MTk4ODU1Mg==
479
Issue with aggregate functions and mathematical operations
{ "login": "goir", "id": 586209, "node_id": "MDQ6VXNlcjU4NjIwOQ==", "avatar_url": "https://avatars.githubusercontent.com/u/586209?v=4", "gravatar_id": "", "url": "https://api.github.com/users/goir", "html_url": "https://github.com/goir", "followers_url": "https://api.github.com/users/goir/followers", "following_url": "https://api.github.com/users/goir/following{/other_user}", "gists_url": "https://api.github.com/users/goir/gists{/gist_id}", "starred_url": "https://api.github.com/users/goir/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/goir/subscriptions", "organizations_url": "https://api.github.com/users/goir/orgs", "repos_url": "https://api.github.com/users/goir/repos", "events_url": "https://api.github.com/users/goir/events{/privacy}", "received_events_url": "https://api.github.com/users/goir/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "> Is this an issue or are we just using it wrong ? :)\n\nYes, it appears to be! Thanks for bringing this to my attention. I'll look into fixing this tonight after work.\n" ]
2014-12-15T13:58:50
2014-12-16T01:44:14
2014-12-16T01:44:14
NONE
null
Hi, We're having an issue with aggregate functions and mathematical calculations, this simple Test shows the issue: ``` from peewee import fn, Model query = Model.select( fn.MAX( fn.IFNULL(1, 10) * 151, fn.IFNULL(None, 10) ) ) print query ``` This gives us: <class 'peewee.Model'> SELECT MAX(IFNULL(?, ?) \* ?), IFNULL(?, ?) FROM "model" AS t1 [1, 10, 151, None, 10] But it should be SELECT MAX**(**(IFNULL(?, ?) \* ?), IFNULL(?, ?)**)** FROM "model" AS t1 [1, 10, 151, None, 10] There is a bracket missing. If you remove the `* 151` everything is fine. You can put in as many brackets as you like, they are getting ignored. I couldnt find a way to get this working. Is this an issue or are we just using it wrong ? :)
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/479/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/479/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/478
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/478/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/478/comments
https://api.github.com/repos/coleifer/peewee/issues/478/events
https://github.com/coleifer/peewee/issues/478
51,969,824
MDU6SXNzdWU1MTk2OTgyNA==
478
Would thread pool be useful for single thread application?
{ "login": "kamelzcs", "id": 3021531, "node_id": "MDQ6VXNlcjMwMjE1MzE=", "avatar_url": "https://avatars.githubusercontent.com/u/3021531?v=4", "gravatar_id": "", "url": "https://api.github.com/users/kamelzcs", "html_url": "https://github.com/kamelzcs", "followers_url": "https://api.github.com/users/kamelzcs/followers", "following_url": "https://api.github.com/users/kamelzcs/following{/other_user}", "gists_url": "https://api.github.com/users/kamelzcs/gists{/gist_id}", "starred_url": "https://api.github.com/users/kamelzcs/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/kamelzcs/subscriptions", "organizations_url": "https://api.github.com/users/kamelzcs/orgs", "repos_url": "https://api.github.com/users/kamelzcs/repos", "events_url": "https://api.github.com/users/kamelzcs/events{/privacy}", "received_events_url": "https://api.github.com/users/kamelzcs/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I didn't think about Tornado when writing that, to be honest. The connections are stored in a heap on the pooled database instance, so there's no reason why a single-threaded app could not check out multiple connections. There's a catch, though...\n\nThe database stores the connection on a threadlocal. So if you had a multi-threaded app, each thread would have it's own connection (which would be managed by the pool). In a single-threaded app using an event-loop, how would peewee know which connection belongs with which callback?\n", "I checked again, and found single-threaded app could check out multiple connections.\n\nBut for things like `transaction`, which stores the info in `threadlocal` variable.\nFor single thread app, this kind of `transaction` would not work, as all the transactions are within the same `threadlocal`.\n\nIs this one the catch which should be taken care?\n", "> I checked again, and found single-threaded app could check out multiple connections.\n\nOh really? I would have thought that calling `db.get_conn()` in a single-threaded app would always yield the same connection. Were you using a different API than `get_conn()`?\n", "I just thought the `PooledDatabase _connect()` could create multi connections.\nBut the `get_conn()` could only get the same connection, I think.\n\nBTW: The transaction part will not work in single-thread app, isn't it?\n", "> I just thought the PooledDatabase _connect() could create multi connections.\n> But the get_conn() could only get the same connection, I think.\n\nRight, the `_connect()` method will create new connections, but that is a private API and will not actually work how you think it will.\n\nThe database instance your app uses has a threadlocal (`__local`) that stores the currently active connection (or None if no conn is open yet). Whenever you use a model or the db to execute a query, the db will call `self.get_conn()` to get the connection stored on the threadlocal, creating one if one does not exist.\n\nSo while you can open as many connections as you want, the database will only use the one stored on the threadlocal.\n", "I'm closing the issue as this is not really a bug, but if you have more questions or would like to discuss, feel free to continue commenting.\n", "But for single-thread app, this `__local` actually becomes a shared variable.\nThen does it mean, things like `transaction(object)`and `get_conn()` which assume the `__local` is private to each client thread, would not work as desired?\n", "> But for single-thread app, this __local actually becomes a shared variable. Then does it mean, things like transaction(object)and get_conn() which assume the __local is private to each client thread, would not work as desired?\n\nExactly. For a single-threaded application, it acts like an instance attribute, and since there is only a single database instance, there will only be a single connection.\n", "Thanks for your time and great classification.\n", "My pleasure! I hope I've helped, or at least explained the limitations of the code.\n" ]
2014-12-15T10:25:02
2014-12-16T08:38:49
2014-12-16T06:36:36
NONE
null
The docs said, `If your application is single-threaded, only one connection will be opened.` In frameworks like `Tornado`, there is only one thread. Does it mean, no matter how many requests from the client, there would be ONLY ONE connection to deal with the requests?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/478/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/478/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/477
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/477/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/477/comments
https://api.github.com/repos/coleifer/peewee/issues/477/events
https://github.com/coleifer/peewee/pull/477
51,654,368
MDExOlB1bGxSZXF1ZXN0MjU4ODA4OTE=
477
Fix error when aggregating results that JOIN many-to-many tables
{ "login": "jturmel", "id": 37833, "node_id": "MDQ6VXNlcjM3ODMz", "avatar_url": "https://avatars.githubusercontent.com/u/37833?v=4", "gravatar_id": "", "url": "https://api.github.com/users/jturmel", "html_url": "https://github.com/jturmel", "followers_url": "https://api.github.com/users/jturmel/followers", "following_url": "https://api.github.com/users/jturmel/following{/other_user}", "gists_url": "https://api.github.com/users/jturmel/gists{/gist_id}", "starred_url": "https://api.github.com/users/jturmel/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/jturmel/subscriptions", "organizations_url": "https://api.github.com/users/jturmel/orgs", "repos_url": "https://api.github.com/users/jturmel/repos", "events_url": "https://api.github.com/users/jturmel/events{/privacy}", "received_events_url": "https://api.github.com/users/jturmel/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[]
2014-12-11T07:14:54
2014-12-11T18:21:34
2014-12-11T18:21:34
NONE
null
Composite key is a list of primary keys in how the pk_value was being generated causing a crash when trying to be used as a dictionary key since a list isn't hashable. Now it looks to see if it's a list, if it is, it casts the values to strings and concatenates them together with a dash.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/477/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/477/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/477", "html_url": "https://github.com/coleifer/peewee/pull/477", "diff_url": "https://github.com/coleifer/peewee/pull/477.diff", "patch_url": "https://github.com/coleifer/peewee/pull/477.patch", "merged_at": null }
https://api.github.com/repos/coleifer/peewee/issues/476
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/476/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/476/comments
https://api.github.com/repos/coleifer/peewee/issues/476/events
https://github.com/coleifer/peewee/issues/476
51,535,532
MDU6SXNzdWU1MTUzNTUzMg==
476
select rows not in many-to-many relation
{ "login": "exherb", "id": 65154, "node_id": "MDQ6VXNlcjY1MTU0", "avatar_url": "https://avatars.githubusercontent.com/u/65154?v=4", "gravatar_id": "", "url": "https://api.github.com/users/exherb", "html_url": "https://github.com/exherb", "followers_url": "https://api.github.com/users/exherb/followers", "following_url": "https://api.github.com/users/exherb/following{/other_user}", "gists_url": "https://api.github.com/users/exherb/gists{/gist_id}", "starred_url": "https://api.github.com/users/exherb/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/exherb/subscriptions", "organizations_url": "https://api.github.com/users/exherb/orgs", "repos_url": "https://api.github.com/users/exherb/repos", "events_url": "https://api.github.com/users/exherb/events{/privacy}", "received_events_url": "https://api.github.com/users/exherb/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "It sounds like this is more of a SQL question than an issue with peewee, so I'm going to close.\n", "@coleifer sorry, I was looking for something simple API without subquery to do this with peewee.\n" ]
2014-12-10T09:23:37
2014-12-10T15:30:29
2014-12-10T15:18:46
NONE
null
is this even possible?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/476/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/476/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/475
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/475/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/475/comments
https://api.github.com/repos/coleifer/peewee/issues/475/events
https://github.com/coleifer/peewee/issues/475
51,447,702
MDU6SXNzdWU1MTQ0NzcwMg==
475
Regression on migrator.drop_column
{ "login": "stenci", "id": 5955495, "node_id": "MDQ6VXNlcjU5NTU0OTU=", "avatar_url": "https://avatars.githubusercontent.com/u/5955495?v=4", "gravatar_id": "", "url": "https://api.github.com/users/stenci", "html_url": "https://github.com/stenci", "followers_url": "https://api.github.com/users/stenci/followers", "following_url": "https://api.github.com/users/stenci/following{/other_user}", "gists_url": "https://api.github.com/users/stenci/gists{/gist_id}", "starred_url": "https://api.github.com/users/stenci/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/stenci/subscriptions", "organizations_url": "https://api.github.com/users/stenci/orgs", "repos_url": "https://api.github.com/users/stenci/repos", "events_url": "https://api.github.com/users/stenci/events{/privacy}", "received_events_url": "https://api.github.com/users/stenci/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "That's odd, I copy/pasted the code into a module locally and it ran without issue, although I did modify the code slightly so the call to `drop_column()` referred to `mytable` and not `mytable2`. I also explicitly checked out the 2.4.4 tag.\n\nCan you do some debugging to find out what values are being passed to `cursor.execute()`?\n", "Sorry, I didn't notice that `2`, which in my case referred to an old existing table and in your case referred to a non existing table.\n\nMy old table had a primary key and an indexed column, and it looks like that's what changes the behavior between the two versions.\n\nThe following code reproduces the problem starting from an empty database.\n\n```\nimport peewee\nimport playhouse.migrate\ndb = peewee.SqliteDatabase('test.db', threadlocals=True)\n\nclass MyTable(peewee.Model):\n pk = peewee.CharField(primary_key=True)\n mycolumn = peewee.CharField(index=True)\n class Meta:\n database = db\n\ndef create_table():\n MyTable.drop_table(True)\n MyTable.create_table()\n\nmigrator = playhouse.migrate.SqliteMigrator(db)\n\ncreate_table()\ntry: playhouse.migrate.migrate(migrator.drop_column('mytable', 'mycolumn'))\nexcept: print('1) error with good db and good column')\n\ncreate_table()\ntry: playhouse.migrate.migrate(migrator.drop_column('notable', 'mycolumn'))\nexcept: print('2) error with bad db and good column')\n\ncreate_table()\ntry: playhouse.migrate.migrate(migrator.drop_column('mytable', 'nocolumn'))\nexcept: print('3) error with good db and bad column')\n\ncreate_table()\ntry: playhouse.migrate.migrate(migrator.drop_column('notable', 'nocolumn'))\nexcept: print('4) error with bad db and bad column')\n```\n\nOutput with 2.3.3:\n\n```\n2) error with bad db and good column\n4) error with bad db and bad column\n```\n\nOutput with 2.4.4:\n\n```\n1) error with good db and good column\n2) error with bad db and good column\n3) error with good db and bad column\n4) error with bad db and bad column\n```\n\nThe traceback on the first error is:\n\n```\nTraceback (most recent call last):\n File \"F:\\eclipse\\plugins\\org.python.pydev_2.8.2.2013090511\\pysrc\\pydevd_comm.py\", line 773, in doIt\n result = pydevd_vars.evaluateExpression(self.thread_id, self.frame_id, self.expression, self.doExec)\n File \"F:\\eclipse\\plugins\\org.python.pydev_2.8.2.2013090511\\pysrc\\pydevd_vars.py\", line 376, in evaluateExpression\n result = eval(compiled, updated_globals, frame.f_locals)\n File \"<string>\", line 1, in <module>\n File \"C:\\Python34\\lib\\site-packages\\playhouse\\migrate.py\", line 535, in migrate\n operation.run()\n File \"C:\\Python34\\lib\\site-packages\\playhouse\\migrate.py\", line 144, in run\n getattr(self.migrator, self.method)(*self.args, **kwargs))\n File \"C:\\Python34\\lib\\site-packages\\playhouse\\migrate.py\", line 135, in _handle_result\n result.run()\n File \"C:\\Python34\\lib\\site-packages\\playhouse\\migrate.py\", line 144, in run\n getattr(self.migrator, self.method)(*self.args, **kwargs))\n File \"C:\\Python34\\lib\\site-packages\\playhouse\\migrate.py\", line 138, in _handle_result\n self._handle_result(item)\n File \"C:\\Python34\\lib\\site-packages\\playhouse\\migrate.py\", line 133, in _handle_result\n self.execute(result)\n File \"C:\\Python34\\lib\\site-packages\\playhouse\\migrate.py\", line 129, in execute\n self.migrator.database.execute_sql(sql, params)\n File \"C:\\Python34\\lib\\site-packages\\peewee.py\", line 2780, in execute_sql\n cursor.execute(sql, params or ())\nValueError: operation parameter must be str\n```\n\nThe `cursor.execute()` on line 2780 is executed with the following parameters:\n\n```\nsql, params\n('select name, sql from sqlite_master where type=? and LOWER(name)=?', ['table', 'mytable'])\n```\n\nthen the execution goes to the `else` block and crashes at the `self.commit()` on line 2788. (I don't understand why the 2780 is reported in the traceback)\n", "Because you have a non-integer primary key, sqlite will automatically create an index. The index is found when introspecting the db, but it has no associated SQL, so we're unable to re-create it (which is fine, because SQLite will re-create it anyways).\n", "The issue is not an issue for me. I reported because often a difference between two versions is a red flag. \nIt's up to you to close it or fix it (assuming that there is something to fix)\n\nThank you!!!!!!\n", "> It's up to you to close it or fix it (assuming that there is something to fix)\n\nI did fix it. In b0c866c\n" ]
2014-12-09T16:23:32
2014-12-10T04:32:19
2014-12-10T04:20:48
CONTRIBUTOR
null
The following code works with 2.3.3, fails with 2.4.4. ``` import peewee import playhouse.migrate db = peewee.SqliteDatabase('test.db', threadlocals=True) class MyTable(peewee.Model): mycolumn = peewee.CharField() class Meta: database = db MyTable.drop_table(True) MyTable.create_table() migrator = playhouse.migrate.SqliteMigrator(db) playhouse.migrate.migrate(migrator.drop_column('mytable2', 'mycolumn')) ``` Here is the traceback: ``` Traceback (most recent call last): File "F:\workspace\test\test.py", line 17, in <module> playhouse.migrate.migrate(migrator.drop_column('mytable2', 'mycolumn')) File "C:\Python34\lib\site-packages\playhouse\migrate.py", line 535, in migrate operation.run() File "C:\Python34\lib\site-packages\playhouse\migrate.py", line 144, in run getattr(self.migrator, self.method)(*self.args, **kwargs)) File "C:\Python34\lib\site-packages\playhouse\migrate.py", line 135, in _handle_result result.run() File "C:\Python34\lib\site-packages\playhouse\migrate.py", line 144, in run getattr(self.migrator, self.method)(*self.args, **kwargs)) File "C:\Python34\lib\site-packages\playhouse\migrate.py", line 138, in _handle_result self._handle_result(item) File "C:\Python34\lib\site-packages\playhouse\migrate.py", line 133, in _handle_result self.execute(result) File "C:\Python34\lib\site-packages\playhouse\migrate.py", line 129, in execute self.migrator.database.execute_sql(sql, params) File "C:\Python34\lib\site-packages\peewee.py", line 2780, in execute_sql cursor.execute(sql, params or ()) ValueError: operation parameter must be str ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/475/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/475/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/474
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/474/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/474/comments
https://api.github.com/repos/coleifer/peewee/issues/474/events
https://github.com/coleifer/peewee/issues/474
51,331,475
MDU6SXNzdWU1MTMzMTQ3NQ==
474
sqlite ForeignKeyField column migration errors
{ "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
[ "@coleifer Wow, thank you for super quick fix! :smiley: \n\nI've noticed adding `ForeignKeyField` produces `REFERENCES` that is inline with column definition:\n\n```\n\"network_id\" INTEGER REFERENCES \"network\" (\"id\")\n```\n\nvs what happens when you call `.create_table()`:\n\n```\n\"network_id\" INTEGER, FOREIGN KEY (\"network_id\") REFERENCES \"network\" (\"id\")\n```\n\nThese two forms seem to be equivalent. Am I right?\n\nI'm writing about it, because I didn't know about the first form. May be this thread would help people who could be confused by it :)\n", "They are equivalent and unfortunately that is the only way to do it in one shot with SQLite. The way I'd prefer is with and `ALTER/ADD COLUMN`, then `ALTER/ADD CONSTRAINT`. Since SQLite does not support this, I just inlined the foreign key definition.\n", "@coleifer Because I didn't know about inline `REFERENCES`, I've tried to implement `FOREIGN KEY` manipulation by creating a new table and copying data into it. (Reusing and extending `SqliteMigrator` `_update_column` method.) But my code quickly became ugly, I switched to other things. And on the next day you've fixed it with a much better approach :) \n" ]
2014-12-08T17:56:08
2014-12-09T18:18:42
2014-12-09T07:07:44
CONTRIBUTOR
null
- [x] ForeignKeyField add_column is incomplete - column is added, but without foreign key constraint - [x] ForeignKeyField drop_column fails: `peewee.OperationalError: unknown column "owner_id" in foreign key definition` - [x] trying to drop non-existent column doesn't give any errors: e.g. `migrate(migrator.drop_column('device', 'owner'))` Repeating the first two problems: ``` sh git clone https://gist.github.com/8fe325d798c201e8e63b.git fk-bug cd fk-bug rm -f test.sqlite && python bug_models.py create && python bug_add.py && echo '.schema' | sqlite3 test.sqlite rm -f test.sqlite && python bug_models.py create && python bug_drop.py ``` https://gist.github.com/shamrin/8fe325d798c201e8e63b
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/474/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/474/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/473
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/473/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/473/comments
https://api.github.com/repos/coleifer/peewee/issues/473/events
https://github.com/coleifer/peewee/pull/473
51,307,946
MDExOlB1bGxSZXF1ZXN0MjU2Njk0ODY=
473
fix playhouse.migrate docstring about drop_index
{ "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
[ "Thank you!\n" ]
2014-12-08T14:33:45
2014-12-08T19:02:17
2014-12-08T19:02:12
CONTRIBUTOR
null
`migrator.drop_index` seems to require table name as the first argument. But module docstring showed just `.drop_index(index_name)`.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/473/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/473/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/473", "html_url": "https://github.com/coleifer/peewee/pull/473", "diff_url": "https://github.com/coleifer/peewee/pull/473.diff", "patch_url": "https://github.com/coleifer/peewee/pull/473.patch", "merged_at": "2014-12-08T19:02:12" }
https://api.github.com/repos/coleifer/peewee/issues/472
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/472/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/472/comments
https://api.github.com/repos/coleifer/peewee/issues/472/events
https://github.com/coleifer/peewee/pull/472
50,553,948
MDExOlB1bGxSZXF1ZXN0MjUyODY0MDg=
472
Avoiding changing how Model.save() works with a composite PK
{ "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
[ "Thank you!\n" ]
2014-12-01T17:57:19
2014-12-02T01:56:36
2014-12-02T01:56:33
NONE
null
This won't fix #469, but I think it's a better way to remove the PK fields from the updating fields.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/472/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/472/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/472", "html_url": "https://github.com/coleifer/peewee/pull/472", "diff_url": "https://github.com/coleifer/peewee/pull/472.diff", "patch_url": "https://github.com/coleifer/peewee/pull/472.patch", "merged_at": "2014-12-02T01:56:33" }
https://api.github.com/repos/coleifer/peewee/issues/471
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/471/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/471/comments
https://api.github.com/repos/coleifer/peewee/issues/471/events
https://github.com/coleifer/peewee/pull/471
50,511,804
MDExOlB1bGxSZXF1ZXN0MjUyNjA3NTA=
471
Fixed issue with aggregate_rows
{ "login": "arrowgamer", "id": 779694, "node_id": "MDQ6VXNlcjc3OTY5NA==", "avatar_url": "https://avatars.githubusercontent.com/u/779694?v=4", "gravatar_id": "", "url": "https://api.github.com/users/arrowgamer", "html_url": "https://github.com/arrowgamer", "followers_url": "https://api.github.com/users/arrowgamer/followers", "following_url": "https://api.github.com/users/arrowgamer/following{/other_user}", "gists_url": "https://api.github.com/users/arrowgamer/gists{/gist_id}", "starred_url": "https://api.github.com/users/arrowgamer/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/arrowgamer/subscriptions", "organizations_url": "https://api.github.com/users/arrowgamer/orgs", "repos_url": "https://api.github.com/users/arrowgamer/repos", "events_url": "https://api.github.com/users/arrowgamer/events{/privacy}", "received_events_url": "https://api.github.com/users/arrowgamer/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Oh wow, nice catch!\n", "Thanks a lot! ^_^ When do you think this will see the light of pip? =O\n" ]
2014-12-01T11:04:37
2014-12-02T03:19:27
2014-12-02T01:49:54
CONTRIBUTOR
null
Hi there. Awesome job on this ORM! I ran into an issue while using it last night, however, and here is my proposed solution. As not the most seasoned Python developer, your code is quite difficult for me to understand, so I don't know if this implemented correctly or if the change is even warranted. Perhaps I was using Peewee incorrectly. My issue was as follows. I have ModelB with two foreign keys both to ModelA. **Example:** ``` python class ModelB(Model): manager = ForeignKeyField(ModelA, related_name='slaves') assistant = ForeignKeyField(ModelA, related_name='masters') ``` Using aggregate_rows to preload an instance of ModelA with its masters would place the results under the wrong related_field, slaves, for instance. I thought this might be because Peewee was handling this case incorrectly, and from what I understand about the code, the "rel_for_model" function accounts for this if you pass the field_obj argument, though that's not being passed through the calls to "reverse_rel_for_model", and so it's not really caring about the exact foreign key field and thus populating the wrong "related_name" field. Does that make any sense?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/471/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/471/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/471", "html_url": "https://github.com/coleifer/peewee/pull/471", "diff_url": "https://github.com/coleifer/peewee/pull/471.diff", "patch_url": "https://github.com/coleifer/peewee/pull/471.patch", "merged_at": "2014-12-02T01:49:54" }
https://api.github.com/repos/coleifer/peewee/issues/470
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/470/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/470/comments
https://api.github.com/repos/coleifer/peewee/issues/470/events
https://github.com/coleifer/peewee/issues/470
50,475,422
MDU6SXNzdWU1MDQ3NTQyMg==
470
@db.commit_on_success does not work with deferred db
{ "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
[ "> Also for unknown reasons id(self) in connect differs from id(db) in app.py.\n> Not sure why..\n\nI think this is the problem, and I'm not sure how it could be a peewee issue.\n\n``` python\nfrom peewee import *\n\ndb = SqliteDatabase(None)\n\nclass User(Model):\n username = CharField()\n\n class Meta:\n database = db\n\[email protected]_on_success\ndef create(username):\n User.create(username=username)\n\ndb.init(':memory:')\nUser.create_table()\n\ncreate('hello')\ncreate('charlie')\n\nfor user in User.select():\n print user.username\n```\n\nThis code works fine.\n", "Yes it does..\n\nI've cut everything and found minimal code for reproduce:\n\n**A. Does not work: two files.**\n\nThe first one\n\n```\n# test.py\n# -*- coding: utf-8 -*-\nfrom flask import Flask\nfrom playhouse.postgres_ext import PostgresqlExtDatabase\n\ndb = PostgresqlExtDatabase(None)\n\n\ndef create_app():\n app = Flask('calc')\n app.config[\"DEBUG\"] = True\n db.init('demo')\n print db.execute_sql(\n \"\"\"SELECT table_name FROM information_schema.tables WHERE table_schema = 'public';\"\"\"\n ).fetchall() # ok!\n from test_api import api\n\n app.register_blueprint(api, url_prefix='/api')\n return app\n\n\nif __name__ == '__main__':\n create_app().run()\n```\n\nThe second one\n\n```\n# test_api.py\n# -*- coding: utf-8 -*-\nfrom flask import Blueprint, jsonify\nfrom test import db\n\napi = Blueprint('api', __name__)\n\n\[email protected]('/log', methods=[\"GET\", \"POST\", \"PUT\", \"DELETE\", \"PATCH\", \"OPTIONS\"])\[email protected]_on_success\ndef logging_handler():\n return jsonify(hello='world from api')\n```\n\n**B. Does Work!**\n\nOne file\n\n```\n# test.py\n# -*- coding: utf-8 -*-\nfrom flask import Flask, Blueprint, jsonify\nfrom playhouse.postgres_ext import PostgresqlExtDatabase\n\ndb = PostgresqlExtDatabase(None)\napi = Blueprint('api', __name__)\n\n\[email protected]('/log', methods=[\"GET\", \"POST\", \"PUT\", \"DELETE\", \"PATCH\", \"OPTIONS\"])\[email protected]_on_success\ndef logging_handler():\n return jsonify(hello='world from api')\n\n\ndef create_app():\n app = Flask('calc')\n app.config[\"DEBUG\"] = True\n db.init('demo')\n print db.execute_sql(\n \"\"\"SELECT table_name FROM information_schema.tables WHERE table_schema = 'public';\"\"\"\n ).fetchall() # ok!\n\n app.register_blueprint(api, url_prefix='/api')\n return app\n\n\nif __name__ == '__main__':\n create_app().run()\n```\n", "this does not work either (with 2 files):\n\n```\[email protected]('/log', methods=[\"GET\", \"POST\", \"PUT\", \"DELETE\", \"PATCH\", \"OPTIONS\"])\ndef logging_handler():\n with db.transaction():\n return jsonify(hello='world from api')\n```\n", ".. and this:\n\n```\n# -*- coding: utf-8 -*-\nfrom flask import Blueprint, jsonify\nimport test\ndb = test.db\n\napi = Blueprint('api', __name__)\n\n\[email protected]('/log', methods=[\"GET\", \"POST\", \"PUT\", \"DELETE\", \"PATCH\", \"OPTIONS\"])\[email protected]_on_success\ndef logging_handler():\n return jsonify(hello='world from api')\n```\n", "The only way I found to fix that is:\n\n```\ndef create_app():\n app = Flask('calc')\n app.config[\"DEBUG\"] = True\n from test_api import api, db\n db.init('demo')\n print db.execute_sql(\n \"\"\"SELECT table_name FROM information_schema.tables WHERE table_schema = 'public';\"\"\"\n ).fetchall() # ok!\n\n app.register_blueprint(api, url_prefix='/api')\n return app\n```\n\nBut this does not looks like a solution because there could be more than 1 file which imports db from skeleton.\n", "But! If I split app skeleton into 2 files:\n\n```\n# -*- coding: utf-8 -*-\nfrom playhouse.postgres_ext import PostgresqlExtDatabase\n\ndb = PostgresqlExtDatabase(None)\n```\n\nand\n\n```\n# -*- coding: utf-8 -*-\nfrom flask import Flask\n\n\ndef create_app():\n app = Flask('calc')\n app.config[\"DEBUG\"] = True\n from test import db\n db.init('demo')\n from test_api import api\n\n print db.execute_sql(\n \"\"\"SELECT table_name FROM information_schema.tables WHERE table_schema = 'public';\"\"\"\n ).fetchall() # ok!\n\n app.register_blueprint(api, url_prefix='/api')\n return app\n\n\nif __name__ == '__main__':\n create_app().run()\n```\n\nthen it works.\n\nI really don't understand this ...\n", "I made a very simple example which is working fine for me locally:\n\n``` python\n### app.py\nfrom peewee import *\n\ndb = SqliteDatabase(None)\n\ndef initialize():\n db.init(':memory:')\n```\n\n``` python\n### db.py\nfrom peewee import *\nfrom app import db\n\nclass User(Model):\n username = CharField()\n class Meta:\n database = db\n\[email protected]_on_success\ndef test_fn(username):\n User.create(username=username)\n```\n\n``` python\n### main.py -- use python main.py to run\nfrom app import *\nfrom db import *\n\ninitialize()\nUser.create_table()\ntest_fn('asdf')\n```\n\nIt works as expected and the `id()` of the database is consistent. Throughout (verified using interactive debugger).\n", "I'm going to close this as I don't believe there is a peewee bug here.\n" ]
2014-11-30T23:31:37
2014-12-04T02:54:12
2014-12-04T02:54:12
NONE
null
The problem (simplified code): ``` # file: app.py ... db = PostgresqlExtDatabase(None) ... def create_app(config_name): app = Flask(__name__) db.init('demo') from api import api app.register_blueprint(api, url_prefix='/api') return app ... if __name__ == '__main__': create_app(config).run() # file: api.py ... from app import db ... api = Blueprint('api', __name__) @db.commit_on_success def log_request(): # do stuff @api.before_request def initialize(): log_request() ... ... ``` everything looks like ok, bur when request comes, exeption in `connect` happens ``` Exception: Error, database not properly initialized before opening connection ``` Ive spent a lot of time to understand reasons which are here: ``` def commit_on_success(self, func): @wraps(func) def inner(*args, **kwargs): with self.transaction(): return func(*args, **kwargs) return inner ``` Also for unknown reasons `id(self)` in `connect` differs from `id(db)` in app.py. Not sure why.. so .. in closure of commit_on_success db still deferred full Stacktrace ``` Traceback (most recent call last): File "/Users/a_user/a_project/py27/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__ return self.wsgi_app(environ, start_response) File "/Users/a_user/a_project/py27/lib/python2.7/site-packages/flask/app.py", line 1820, in wsgi_app response = self.make_response(self.handle_exception(e)) File "/Users/a_user/a_project/py27/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exception reraise(exc_type, exc_value, tb) File "/Users/a_user/a_project/py27/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app response = self.full_dispatch_request() File "/Users/a_user/a_project/py27/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request rv = self.handle_user_exception(e) File "/Users/a_user/a_project/py27/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception reraise(exc_type, exc_value, tb) File "/Users/a_user/a_project/py27/lib/python2.7/site-packages/flask/app.py", line 1473, in full_dispatch_request rv = self.preprocess_request() File "/Users/a_user/a_project/py27/lib/python2.7/site-packages/flask/app.py", line 1666, in preprocess_request rv = func() File "/Users/a_user/a_project/backend/blueprints/api.py", line 43, in initialize log_request() File "/Users/a_user/a_project/py27/lib/python2.7/site-packages/peewee.py", line 2829, in inner return func(*args, **kwargs) File "/Users/a_user/a_project/py27/lib/python2.7/site-packages/peewee.py", line 3233, in __exit__ self.rollback() File "/Users/a_user/a_project/py27/lib/python2.7/site-packages/peewee.py", line 3220, in rollback self.db.rollback() File "/Users/a_user/a_project/py27/lib/python2.7/site-packages/peewee.py", line 2801, in rollback self.get_conn().rollback() File "/Users/a_user/a_project/py27/lib/python2.7/site-packages/peewee.py", line 2740, in get_conn self.connect() File "/Users/a_user/a_project/py27/lib/python2.7/site-packages/peewee.py", line 2721, in connect raise Exception('Error, database not properly initialized ' Exception: Error, database not properly initialized before opening connection ``` peewee is up-to-date
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/470/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/470/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/469
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/469/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/469/comments
https://api.github.com/repos/coleifer/peewee/issues/469/events
https://github.com/coleifer/peewee/issues/469
50,372,516
MDU6SXNzdWU1MDM3MjUxNg==
469
Save only dirty fields
{ "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
[ "I can see how that code appears confusing. The `only` parameter accepts a list of fields, and `model_instance.dirty_fields` returns a list of fields that have been modified. Using the two together, you can accomplish \"save only the fields that changed\":\n\n``` python\nproject.save(only=project.dirty_fields)\n```\n", "Please let me know if this does not address your concern.\n", "Yes, It solves the problem. I just thought the presence of a composite primary key were not a good criteria to save all fields or just the dirt ones.\n", "Looking at d53415fb, I think that code is there to replace previous logic that popped the PK off the field dict when updating a model.\n" ]
2014-11-28T13:05:39
2014-11-30T03:15:49
2014-11-28T23:48:16
NONE
null
I don't use the `Model.save()` method in some of my models to avoid race conditions. Actually I overwrite it for these specific models to have a default value to the `only` argument that makes sense. Example: ``` In [1]: p1 = Project.get(id=21) In [2]: Project.get(id=21).used_credit_count Out[2]: 4669 In [3]: # Now, lets simulate another thread In [4]: Project.update(used_credit_count=Project.used_credit_count + 1).where(Project.id == 21).execute() Out[4]: 1L In [5]: Project.get(id=21).used_credit_count Out[5]: 4670 In [6]: p1.save() Out[6]: 1L In [7]: Project.get(id=21).used_credit_count Out[7]: 4669 ``` The release 2.2 introduced saving only dirty (modified) fields, what would be very useful in my application (and others, I hope). But when I took a look at the code, I noticed that the dirty fields only takes place when using CompositeKey: ``` python def save(self, force_insert=False, only=None): field_dict = dict(self._data) pk_field = self._meta.primary_key if only: field_dict = self._prune_fields(field_dict, only) if self._get_pk_value() is not None and not force_insert: # Here is # if not isinstance(pk_field, CompositeKey): field_dict.pop(pk_field.name, None) else: field_dict = self._prune_fields(field_dict, self.dirty_fields) rows = self.update(**field_dict).where(self._pk_expr()).execute() else: pk = self._get_pk_value() pk_from_cursor = self.insert(**field_dict).execute() if pk_from_cursor is not None: pk = pk_from_cursor self._set_pk_value(pk) # Do not overwrite current ID with None. rows = 1 self._dirty.clear() return rows ``` It seemed that its been used only to remove the fields that are part of the composite primary key, but IMHO its very useful on many scenarios. Sorry if my English is not clear. Please don't hesitate to ask for clarifications.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/469/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/469/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/468
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/468/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/468/comments
https://api.github.com/repos/coleifer/peewee/issues/468/events
https://github.com/coleifer/peewee/issues/468
50,340,655
MDU6SXNzdWU1MDM0MDY1NQ==
468
Why not validate the keyword before insertion?
{ "login": "kamelzcs", "id": 3021531, "node_id": "MDQ6VXNlcjMwMjE1MzE=", "avatar_url": "https://avatars.githubusercontent.com/u/3021531?v=4", "gravatar_id": "", "url": "https://api.github.com/users/kamelzcs", "html_url": "https://github.com/kamelzcs", "followers_url": "https://api.github.com/users/kamelzcs/followers", "following_url": "https://api.github.com/users/kamelzcs/following{/other_user}", "gists_url": "https://api.github.com/users/kamelzcs/gists{/gist_id}", "starred_url": "https://api.github.com/users/kamelzcs/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/kamelzcs/subscriptions", "organizations_url": "https://api.github.com/users/kamelzcs/orgs", "repos_url": "https://api.github.com/users/kamelzcs/repos", "events_url": "https://api.github.com/users/kamelzcs/events{/privacy}", "received_events_url": "https://api.github.com/users/kamelzcs/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "> It would make a big trouble if the keyword is the typo.\n\nYes, that's a valid point.\n\n> Charfield would accept all kinds of types other than basestring\n> BooleanField would accept all kinds of types other than Boolean\n\nThe `python_value` and `db_value` functions on field ensure that the correct types are passed when reading rows from the database, and vice-versa.\n", "Is it valuable to add in a keyword validation in case of typo as sqlalchemy?\n", "A `KeyError` will be raised if you try to insert data into a non-existant field, though this happens at execution time rather than the time the insert is instantiated. I think this is sufficient and will leave the logic as-is.\n", "But if birthday is optional field and when try to insert, a birthdays typo happened, this field would be ignored, but it should not be!\n\nI can't find the keyerror in this case. \n", "https://github.com/coleifer/peewee/blob/706c9d8e67f22f8610142dcaf2e37829f3f9d138/peewee.py#L2556-L2582\n\nParticularly 2560.\n", "The code in my example would work in peewee, and would not give keyerror at all.\nThis keyerror will check the insert keyword? \n" ]
2014-11-28T04:46:09
2014-11-29T02:57:42
2014-11-29T02:30:18
NONE
null
``` class Person(BaseModel): name = CharField() birthday = DateField() is_relative = BooleanField() uncle_bob = Person(name={1:2}, birthday="1910/10/11", is_relative="a", stupid="bas") uncle_bob.save() ``` It would just work. Eventhough there is no `foo` field in the Model. The insert way is to ignore any `NOT defined` keywords before insert into table. It would make a big trouble if the keyword is the typo. BTW1: sqlalchemy would give ``` TypeError: 'stupid' is an invalid keyword argument for Person ``` BTW2: `Charfield` would accept all kinds of types other than `basestring` `BooleanField` would accept all kinds of types other than `Boolean` I just wondering is there any reason? If the type checking is optional, then which interface to use?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/468/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/468/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/467
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/467/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/467/comments
https://api.github.com/repos/coleifer/peewee/issues/467/events
https://github.com/coleifer/peewee/issues/467
49,845,907
MDU6SXNzdWU0OTg0NTkwNw==
467
.save() doesn't work when primary key is manually assigned
{ "login": "scribu", "id": 225715, "node_id": "MDQ6VXNlcjIyNTcxNQ==", "avatar_url": "https://avatars.githubusercontent.com/u/225715?v=4", "gravatar_id": "", "url": "https://api.github.com/users/scribu", "html_url": "https://github.com/scribu", "followers_url": "https://api.github.com/users/scribu/followers", "following_url": "https://api.github.com/users/scribu/following{/other_user}", "gists_url": "https://api.github.com/users/scribu/gists{/gist_id}", "starred_url": "https://api.github.com/users/scribu/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/scribu/subscriptions", "organizations_url": "https://api.github.com/users/scribu/orgs", "repos_url": "https://api.github.com/users/scribu/repos", "events_url": "https://api.github.com/users/scribu/events{/privacy}", "received_events_url": "https://api.github.com/users/scribu/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "After looking at how the `save()` method is implemented, it looks like it can't tell the difference between this:\n\n```\npage = Page.get(Page.url == 'http://example.com')\n```\n\nand this:\n\n```\npage = Page(url='http://example.com')\n```\n\ni.e. between a persisted object and one that exists only in Python.\n\nAnyway, my workaround was to add an extra `if` and use `Page.create()`.\n\nI'll leave this open in case it's deemed worth fixing.\n", "As the documentation states, when using a non-auto-incrementing primary key, you must call `save()` on new instances by passing `force_insert=True`.\n\nhttp://docs.peewee-orm.com/en/latest/peewee/models.html#non-integer-primary-keys-composite-keys-and-other-tricks\n" ]
2014-11-24T00:07:25
2014-11-24T02:38:21
2014-11-24T02:38:21
NONE
null
Hello, I have a model that looks something like this: ``` python class Page(Model): class Meta: database = PostgresqlDatabase('example') url = CharField(primary_key=True) content = TextField() ``` If I manually create a Page instance, call `.save()` and then immediately query for that instance, I get a DoesntExist exception: ``` python URL = 'http://example.com' page = Page( url=URL ) page.content = 'whatever' page.save() Page.get(Page.url == URL) # raises peewee.PageDoesNotExist ``` What's going on? Here's a full test script which reproduces the problem: ``` python from peewee import * # noqa from playhouse.postgres_ext import * # noqa db = PostgresqlDatabase('example') class Page(Model): class Meta: database = db url = CharField(primary_key=True) content = TextField() def init(): try: Page.drop_table() except ProgrammingError: db.rollback() Page.create_table() init() URL = 'http://example.com' page = Page( url=URL ) page.content = 'whatever' page.save() Page.get(Page.url == URL) ``` Details: - Peewee 2.4.3 - psycopg2 2.5.4 - Python 3.4.1 - PostgreSQL 9.3.5 - OSX 10.10.1
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/467/reactions", "total_count": 3, "+1": 3, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/467/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/466
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/466/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/466/comments
https://api.github.com/repos/coleifer/peewee/issues/466/events
https://github.com/coleifer/peewee/issues/466
49,474,206
MDU6SXNzdWU0OTQ3NDIwNg==
466
The table name on playhouse.migrate.migrate is partially case sensitive
{ "login": "stenci", "id": 5955495, "node_id": "MDQ6VXNlcjU5NTU0OTU=", "avatar_url": "https://avatars.githubusercontent.com/u/5955495?v=4", "gravatar_id": "", "url": "https://api.github.com/users/stenci", "html_url": "https://github.com/stenci", "followers_url": "https://api.github.com/users/stenci/followers", "following_url": "https://api.github.com/users/stenci/following{/other_user}", "gists_url": "https://api.github.com/users/stenci/gists{/gist_id}", "starred_url": "https://api.github.com/users/stenci/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/stenci/subscriptions", "organizations_url": "https://api.github.com/users/stenci/orgs", "repos_url": "https://api.github.com/users/stenci/repos", "events_url": "https://api.github.com/users/stenci/events{/privacy}", "received_events_url": "https://api.github.com/users/stenci/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[]
2014-11-20T00:36:41
2014-11-20T07:13:39
2014-11-20T07:13:39
CONTRIBUTOR
null
After executing the code below mytable2 misses one index. The difference between the two migrate() lines is that one uses the case of the class and the other uses the case of the table name. The function should be either case sensitive and fail when the case does not match (the class name or the column name?) or (better) not case sensitive and always work. `````` Python import peewee import playhouse.migrate db = peewee.SqliteDatabase('test.db', threadlocals=True) class PeeweeModel(peewee.Model): class Meta: database = db migrator = playhouse.migrate.SqliteMigrator(db) class MyTable1(PeeweeModel): pk = peewee.CharField(primary_key=True) indexed = peewee.CharField(index=True) class MyTable2(PeeweeModel): pk = peewee.CharField(primary_key=True) indexed = peewee.CharField(index=True) MyTable1.drop_table(True) MyTable2.drop_table(True) MyTable1.create_table() MyTable2.create_table() try: playhouse.migrate.migrate(migrator.drop_column('MyTable1', 'missing_column')) except: pass try: playhouse.migrate.migrate(migrator.drop_column('mytable2', 'missing_column')) except: pass``` ``````
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/466/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/466/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/465
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/465/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/465/comments
https://api.github.com/repos/coleifer/peewee/issues/465/events
https://github.com/coleifer/peewee/issues/465
49,308,229
MDU6SXNzdWU0OTMwODIyOQ==
465
Disable backref validation
{ "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
[ "I noticed an indentation error in the minimal example above: `return DynamicTable` is indented one level to deep.\n\nI must confess that I have not read the peewee source in detail. But could it be, that even after the deletion of `dyntable`, the class `StaticTable` still has some sort of reference to it?\n", "I was able to make it work by defining destructors on the ForeingKeyField and the BaseModel classes:\nhttps://github.com/hitzg/peewee/commit/3cb1feb4f477d540d6ff1ad951c04304eee176a7 \nI did not define a new test, but all the old ones seem to run ok. I can create a pull request, but I'm not sure if my solution is safe / not introducing other problems.\n\nEDIT: haha, I haven't seen your commit.... sorry\n", "Actually I think I made the indentation error when copying the code from StackOverflow.\n\nEven after the deleteion of `dyntable`, yes, `Statictable` will retain a back-reference. Maybe I need to find a way to hook into the deletion of a Model class from memory.\n", "Ah, you added `__del__` to the model metaclass, perfect! I wlil definitely take your changes, they look great.\n", "Actually quick question -- in your code on `BaseModel.__del__` your override accepts the `self` argument, yet it accesses `cls` inside. I'm curious how this worked, since I would think that would be a `NameError`.\n", "Sorry, I really was too quick on that. you are quite right, using `cls` raises a `NameError`. Not sure what I have tested before, but somehow I tricked myself.\nI figured out two things:\n1. The approach works (at least with these corrections: https://github.com/hitzg/peewee/commit/f6cafe05ecbd43b48b9acf23c4f4ad400e00c72d), as far as I can tell (Its +3000 lines of code and I haven't spent a lot of time looking at it ;)\n2. The destructors need to be called explicitly (in the minimal example above you have to call do `dyntable.__del__()`, which means that somewhere there are further references to the objects. I'm not sure where though. So it might make more sense to put the code in some sort of `release_backrefs` function.\n", "> The destructors need to be called explicitly (in the minimal example above you have to call do `dyntable.__del__()`, which means that somewhere there are further references to the objects. I'm not sure where though. So it might make more sense to put the code in some sort of release_backrefs function.\n\nAhh, that makes sense. I was testing locally and there were still references hanging around. Even calling `del SomeClass` did not work. I started a SO thread which has more details: http://stackoverflow.com/questions/27018721/python-del-method-for-classes\n", "At this point I will have to use the fix you provided. Thank you for all the help!\nOne more question: Is there a downside / performance loss related to setting `validate_backrefs = True`?\n", "Not really, just that you may overwrite a pre-existing backref or attribute. In your case I think it should be fine.\n" ]
2014-11-18T23:26:46
2014-11-19T18:02:09
2014-11-19T07:27:47
OWNER
null
Via [stackoverflow](http://stackoverflow.com/questions/27000279/peewee-reusing-dynamically-created-models): > In my application I have a model for which I know the number of columns only at runtime. Using a function like Factory below to create the model solves this issue nicely. However, if I use it multiple times (with potentially varying fields), the creation of the foreign key ref throws an exception: > > ``` python > AttributeError: Foreign key: dynamictable.ref related name "dynamictable_set" > collision with foreign key using same related_name. > ``` > > The message is quite clear and when I set the related_name argument when creating the foreign key there is no error. > > Questions: > > Why can't I use the same related_name the second time? Do I need to redefine StaticTable as well? > > Is there a better approach to write to multiple databases with dynamic models? Minimal, reproducable example: ``` python import peewee database_proxy = peewee.Proxy() class BaseModel(peewee.Model): class Meta: database = database_proxy class StaticTable(BaseModel): foo = peewee.DoubleField() def Factory(fields): class DynamicTable(BaseModel): ref = peewee.ForeignKeyField(StaticTable) for field in fields: peewee.DoubleField().add_to_class(DynamicTable, field) return DynamicTable def Test(fname, fields): db = peewee.SqliteDatabase(fname) database_proxy.initialize(db) db.create_table(StaticTable) dyntable = Factory(fields) db.create_table(dyntable) db.close() Test(':memory:', ['foo', 'bar']) Test(':memory:', ['foo', 'bar', 'extra']) ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/465/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/465/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/464
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/464/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/464/comments
https://api.github.com/repos/coleifer/peewee/issues/464/events
https://github.com/coleifer/peewee/issues/464
49,271,899
MDU6SXNzdWU0OTI3MTg5OQ==
464
Losing MySQL connections even though using Pool etc.
{ "login": "cpury", "id": 1777905, "node_id": "MDQ6VXNlcjE3Nzc5MDU=", "avatar_url": "https://avatars.githubusercontent.com/u/1777905?v=4", "gravatar_id": "", "url": "https://api.github.com/users/cpury", "html_url": "https://github.com/cpury", "followers_url": "https://api.github.com/users/cpury/followers", "following_url": "https://api.github.com/users/cpury/following{/other_user}", "gists_url": "https://api.github.com/users/cpury/gists{/gist_id}", "starred_url": "https://api.github.com/users/cpury/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/cpury/subscriptions", "organizations_url": "https://api.github.com/users/cpury/orgs", "repos_url": "https://api.github.com/users/cpury/repos", "events_url": "https://api.github.com/users/cpury/events{/privacy}", "received_events_url": "https://api.github.com/users/cpury/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Thanks for sharing this. I'm sorry that you've still been experiencing errors.\n\nQuick question -- are you calling `my_db.connect()` and `my_db.close()` between requests? I ask because these calls are necessary for opening the conn and for returning it to the pool.\n\nI think some improvements could definitely be made to the mysql pool implementation -- particularly now that there's an API hook for determining if a connection is actually available.\n", "Ha! That might just be it. I wasn't aware I have to manually open/close the connections, but that seems only logical now that I think of it >.<\n\nRelated to that, I'm using the Thrift TForkedServer, which forks a new process for each request. Will the pool with threadlocals=True work fine with this?\n", "And also, what will happen if too many requests come in at once and the number of max_connections is reached? I'd like them to wait until a new connection is available, and not to fail.\n", "> Related to that, I'm using the Thrift TForkedServer, which forks a new process for each request. Will the pool with threadlocals=True work fine with this?\n\nAhh... I am not sure how that will work. The connections will be opened and maintained in the server process, then when `fork` is called they will be used in the request process... But I'm not sure what will actually happen there. If it spawned a thread for each request then `threadlocals` would work, but I'm not sure for an entire process.\n\n> And also, what will happen if too many requests come in at once and the number of max_connections is reached? I'd like them to wait until a new connection is available, and not to fail.\n\nCurrently the pool does not block, though this might be worth adding. You could always subclass and override the pool's `_connect()` method, then call it in a busy-loop?\n", "Thanks man! I'll experiment with this and report back on how it goes.\n", "Cool, I'll look into it as well this evening when I'm done with work.\n", "Where are you at with this one? Did connect/close per-request fix the issue?\n", "So I tinkered around a lot and changed a bunch of things, and it does seem to be more stable. Especially the \"MySQL server gone away\" error hasn't appeared since, and just logically I don't think it will. I haven't seen the \"Connection lost during query\" one yet, but if it happens again I guess I should also have a look at the MySQL server configuration.\n\nAs for the ForkedServer, I found out that the different forks do not share the memory for variables, which means the Pool essentially becomes useless. Thus it would be a feasible solution to combine the ForkedServer with just opening a simple connection per fork. I guess I can load test that at some point, but for now I'm going for ThreadedServer with Connection Pool.\n\nFor establishing connections, I added the busy loop as you suggested to make sure queries only fail if the server is really busy.\n\nThanks!\n", "Hmm so when posting a lot of parallel requests to my server, at some point one query and all subsequent will fail with the OperationalError: (2013, \"Lost connection to MySQL server during query (timeout('timed out',))\"). Sadly, Peewee seems unable to restart the connection then, and I have to manually restart the whole service in order for it to work again... Do you have an idea how I can have the Pool automatically kill connections that have died like this? At this point I'm not even sure the Thread/Pool combination is doing what I want. I have each request run on a separate thread, and each thread opens/closes connections from the Pool.\n", "I guess I could subclass Database and have execute_sql catch OperationalErrors and automatically reconnect if that happens? Could that cause any other issues? Would I lose my transactions?\n", "> As for the ForkedServer, I found out that the different forks do not share the memory for variables, which means the Pool essentially becomes useless.\n\nCorrect -- at this point you are going to be opening a connection-per-process.\n\n> Thus it would be a feasible solution to combine the ForkedServer with just opening a simple connection per fork. I guess I can load test that at some point, but for now I'm going for ThreadedServer with Connection Pool.\n\nThat sounds good. Make sure you are instantiating your database with `threadlocals=True` (this is the default but in older versions of peewee this was not the case).\n\n> For establishing connections, I added the busy loop as you suggested to make sure queries only fail if the server is really busy.\n\nHave you tested your implementation? Can you share any code?\n\n> Hmm so when posting a lot of parallel requests to my server, at some point one query and all subsequent will fail with the OperationalError: (2013, \"Lost connection to MySQL server during query (timeout('timed out',))\").\n\nIf you can, I'd like to see as much of your relevant code as you can share. Or perhaps an example that illustrates the problem. I'm having a hard time connecting this behavior with the implementation of the pool.\n\n> I guess I could subclass Database and have execute_sql catch OperationalErrors and automatically reconnect if that happens? Could that cause any other issues? Would I lose my transactions?\n\nI would advise against that.\n", "Sure let me see how much code I can share. However, I did not subclass the Pool as proposed, but rather just wrapped the connect calls. Maybe I'll do that now that it has proven to be useful. This is all very hacky and probably not pythonic, but here goes:\n\n```\ndef connect_to_db_with_retries(db, tries=50, pause=0.05):\n for t in xrange(tries):\n try:\n db.connect()\n return\n except ValueError:\n # no connection in pool\n if t + 1 == tries:\n raise\n time.sleep(pause)\n```\n\nThen, I have a wrapper around each handler method (each of those should be called in a subthread) that goes something like this:\n\n```\ndef connect(db):\n def connect_decorator(f):\n @wraps(f)\n def wrapper(*args, **kwargs):\n connect_to_db_with_retries(db)\n\n try:\n result = f(*args, **kwargs)\n except OperationalError:\n db.manual_close()\n\n db.close()\n\n return result\n return wrapper\n return connect_decorator\n```\n\nOh and here is how I instantiate the pool:\n\n```\ndb = PooledMySQLDatabase(charset='utf8', use_unicode=True, max_connections=1000, connect_timeout=10, stale_timeout=60, **db_credentials)\n```\n\nNote that it's actually slightly more complicated than this, since I have separate read/write connections. If you think this could be part of the issue, I can add the relevant code. Oh and the Thrift Threaded Server implementation can be found here:\nhttps://github.com/evernote/evernote-sdk-python/blob/master/lib/thrift/server/TServer.py#L92\n\nThanks again!\n", "For an example that illustrates the problem: I built a little Go-tool that sends random requests in parallel to my Python service. Here is a little table to illustrate the scale (which makes it seem like the MySQL requests are actually handled consecutively):\n\n```\nn parallel requests | avg time for request (s) | n errors\n1 | 0.1 | 0\n2 | 0.2 | 0\n4 | 0.4 | 0\n8 | 0.8 | 0\n16 | 1.6 | 0\n32 | 3.2 | 0\n64 | - | 64\n```\n\nNote that this wall where all the requests fail and return \"Connection lost during query\" is reached whenever the average time reaches the connection_timeout I set when initializing the pool (in this case it was 5). This raises two concerns for me:\na) Why is the time scaling exponentially with number of parallel requests? By the way, average here means that ALL of the requests basically need exactly that amount of time, even the very first one which shouldn't face any obstacles\nb) Why do all the connections break and need to be manually closed if this happens?\n", "It looks to me like the time is not scaling exponentially but linearly, and that might indicate that your parallel requests are running sequentially. I'm not sure what's going on -- I have very littleexperience with MySQL (I use SQLite/Postgres), so I have no idea what the db server might be doing. My best suggestion is just to add a shitload of logging and try to go from there. If you had some minimal code that reliably reproduced this problem, I'd be happy to dig further.\n", "Yeah you're right, the time per request scales linearly, but that makes the whole process explode. I'll go with your advice and log the shit out of it :) Thanks man!\n", "I've got more info! Hopefully this will help us both. So I ran my server and sent four parallel requests its way. I enabled the Pool's logging, as well as some logging by me: 1. When a request is received. 2. When we are done handling it, along with the time it took 3. Inside pool.py whenever _close or _connect are called. The results are as follows (with some comments)\n\n```\nRequest received\nConnect call:\nNo connection available in pool.\nRequest received\nConnect call:\nNo connection available in pool.\nRequest received\nConnect call:\nNo connection available in pool.\nRequest received\nConnect call:\nNo connection available in pool.\n# Up until here, no connections were available, so four connections should have been created right?\nCreated new connection 4335533392.\nCreated new connection 4335533392.\nCreated new connection 4335533392.\nCreated new connection 4335533392.\n# Wrong! They all have the same key... If that means that only one connection was opened or if they just all get mapped to the same key, I don't know\n# And now see how these are handled in a linear fashion, but each thread seems to think it \"owns\" the connection with this key\nClose call:\nReturning 4335533392 to pool.\nRequest finished: Took 2.06 sec\nClose call:\nReturning 4335533392 to pool.\nRequest finished: Took 2.14 sec\nClose call:\nReturning 4335533392 to pool.\nClose call:\nRequest finished: Took 2.15 sec\nReturning 4335533392 to pool.\nRequest finished: Took 2.16 sec\n```\n\nThis could have many implications and I will wait for your comments. But yeah apparently I'm doing something wrong or the pool is not very smart when too many new connections come at once (and there aren't enough connections in the pool). At least this explains why it seemed like my requests are sequential and not parallel. Note that the base 2 seconds is probably the time it needed to connect to the DB, as I'm behind a VPN at the moment.\n\nThanks,\nMax\n", "That certainly is strange, I think some weird things must be going on but I'm not sure what.\n\nThe key used for the connection is `id()` which should be the memory address of the database connection. If you created your `MySQLDatabase` with `threadlocals=True`, then technically a connection should be opened for each thread. I would guess this was the case, but it seems like something else is going on. What does your code look like that opens each connection? What does your database definition look like? I'm also curious what your server looks like. Anything I can implement on my end to try and replicate your setup will be good. Thanks for your help with this, I'll spend some more time looking into the unit-tests.\n", "Weird...\n\nWell, my server is pretty complicated, but the main parts are as described above:\n- Basis for my threaded server is TThreadedServer, which is provided by Thrift and should be stable and trustworthy. The logs above should also show that each request is indeed launched in it's own thread, since they handle the requests in parallel.\n- I have separate read and write connections (and for each maintain one pool), but open/close only what is needed for the request. In this case, I only need read connections so all the above applies to the read pool.\n- Each handler method (aka method ran in it's own thread) is wrapped as I explained above so that it first opens the connections it needs (here only read), then handles the request, and then closes them. In case an OperationalError occurs, I call close_manual() on the connection so it doesn't get recycled.\n- The DB is defined roughly as follows:\n \n ```\n write_database = Proxy()\n read_database = Proxy()\n \n class BaseModel(gfk.Model, read_slave.ReadSlaveModel):\n class Meta:\n database = write_database\n read_slaves = (read_database,)\n \n def __str__(self):\n return str(self.__dict__['_data'])\n \n # Model definitions etc...\n \n def initialize_db_proxy(db_credentials):\n \"\"\" Init the models with the given databases. \"\"\"\n \n write_db = PooledMySQLDatabase(charset='utf8', use_unicode=True, max_connections=1000, connect_timeout=10, stale_timeout=60, threadlocals=True, **db_credentials['write'])\n \n # Only initialize read-connection if given in config\n read_db = None\n if \"read\" in db_credentials:\n read_db = PooledMySQLDatabase(charset='utf8', use_unicode=True, max_connections=1000, connect_timeout=10, stale_timeout=60, threadlocals=True, **db_credentials['read'])\n \n write_database.initialize(write_db)\n read_database.initialize(read_db or write_db)\n ```\n\nAre there any other values I can log to help debug this?\n", "I wrote a little test script which, in my mind, shows that the pool works correctly. The idea is the program will spawn 10 threads. Each thread adds a row to the database which indicates:\n- the thread ID (each thread should have a unique id)\n- the available connections (should be empty)\n- the connections in use (should grow with each thread)\n- a piece of data unique to the thread\n\nWhen all threads are done, the program prints the number of rows in the database and the number of connections in use by the pool.\n\n``` python\nimport threading\n\nfrom peewee import *\nfrom playhouse.pool import PooledPostgresqlDatabase\n\n\ndb = PooledPostgresqlDatabase('peewee_test')\n\nclass Note(Model):\n data = TextField()\n\n class Meta:\n database = db\n\nNote.drop_table(True)\nNote.create_table()\n\nclass NoteThread(threading.Thread):\n def __init__(self, data, *args, **kwargs):\n self.data = data\n super(NoteThread, self).__init__(*args, **kwargs)\n\n def run(self):\n db.connect()\n values = [\n 'Thread ID=%s' % self.ident,\n 'Pool connections=%s' % db._connections,\n 'Pool in use=%s' % db._in_use,\n 'Data=%s' % self.data,\n ]\n Note.create(data='\\n'.join(values))\n\nthreads = [NoteThread(str(i)) for i in range(10)]\nfor t in threads:\n t.start()\nfor t in threads:\n t.join()\n\nprint 'Connections\\n=============='\nprint db._connections\nprint 'In use\\n====='\nprint len(set(db._in_use))\nprint\nprint 'Notes in database: %s' % Note.select().count()\n```\n\nOutput:\n\n```\nConnections\n==============\n[]\nIn use\n=====\n10\n\nNotes in database: 10\n```\n", "D'oh! Of course something fishy was going on... While experimenting I must have at some point switched back to TForkedServer, so all my \"threads\" were actually processes. I switched back to threads and now the behavior is at it should be!\n\nThanks a lot for your example. I notice that you don't close the connections after you're done, but that is probably for educational purposes. Trying to log these two values (db._connections and db._in_use) is what led me ultimately to debug the thread creation.\n\nAnd overall, thanks for your amazing and quick help! Peewee is awesome and I'll definitely recommend it to my friends!\n", "> I notice that you don't close the connections after you're done, but that is probably for educational purposes\n\nYes, that was just to show that there are multiple connections in use.\n\n> And overall, thanks for your amazing and quick help\n\nMy pleasure glad to help. Thanks for working with me on this issue.\n", "Hi \nI have a question that I prefer to ask here because it's relevant.\n\nwhy do we need to start/close connections? In the connectionloop case, what does that really mean? Isn't the pool responsible for taking care of connections (closing idle ones and connecting once a connection is needed)?\n", "When a connection is opened the pool will check to see if it's stale, and if so, will close it and reopen a new one, but there is no \"active\" monitoring of the connections.\n", "I have same problem:... (2006, \"MySQL server has gone away (error(32, 'Broken pipe'))\")\nanyone have a solution? tks.\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", "Awesome! Thanks\n", "Hi, \r\nI have some questions. This is my error:\r\n![error](https://user-images.githubusercontent.com/35761189/43952438-8b369964-9cc8-11e8-90e0-349afbb237d7.jpg)\r\nI used PooledMySQLDatabase . And I used the 'with db.atomic()' to process request, so I think connect will return back to pool. \r\nI think the reason for this is that MySQL closed automatic the connection, but peewee doesn't know. From the Docs, I couldn't find any about automatic-reconnect. I know RetryOperationalError can deal with, but I find it had delete from shortcuts file. I don't know why. Is there other method I don't find?\r\nWhat should I do? Thanks\r\n\r\n", "MySQL will close connections after a certain period of time. When using the connection pool, you'll want to make sure the [\"stale_timeout\"](http://docs.peewee-orm.com/en/latest/peewee/playhouse.html#PooledDatabase) is set to some value less than mysql server's timeout.\r\n\r\nAdditionally, if you're using the connection pool, you need to explicitly connect and close connections, just as if you were using the regular/non-pooled connection type. This gives peewee an opportunity to recycle/close the connection as appropriate. It sounds like you may not be doing this, though. Read the docs: http://docs.peewee-orm.com/en/latest/peewee/database.html#connection-management", "Just a quick Q&A: does `connection_context()` closes the connection properly using a pooled connection? Or do I need to close it manually as well?\r\n\r\nThe [docs](http://docs.peewee-orm.com/en/3.6.0/peewee/api.html#Database.connection_context) say:\r\n>Create a context-manager that will hold open a connection for the duration of the wrapped block.\r\n\r\nBut omits if I need to close the connection.\r\n\r\nExample:\r\n```\r\ndef run():\r\n with db.connection_context():\r\n with db.atomic() as txn:\r\n # do stuff\r\n```", "Ignore my previous comment, looking at the source code of `ConnectionContext`, it's pretty clear that it opens and closes the connection. I will leave both of my comments for documentation purposes.\r\n\r\nIt would be nice if this is explicitly stated in the docs! :)\r\n\r\n```\r\nclass ConnectionContext(_callable_context_manager):\r\n __slots__ = ('db',)\r\n def __init__(self, db): self.db = db\r\n def __enter__(self):\r\n if self.db.is_closed():\r\n self.db.connect()\r\n def __exit__(self, exc_type, exc_val, exc_tb): self.db.close()\r\n```" ]
2014-11-18T18:11:42
2019-01-15T18:48:16
2014-11-24T05:26:04
NONE
null
Hi, so I'm writing a Python Thrift service and use Peewee as my ORM. Our DB is on a MySQL server. I've had many different problems with the "MySQL server going away" and googling it I found these two tips: a) Use the playhouse connection pool b) After connecting, call database.get_conn().ping(True) (though I feel like I need to add that inside the pool code?) So right now I'm using a pool both for write-connections as well as the read-slaves. I experimented with a bunch of different values for the pool parameters, but at the moment I am at: ``` max_connections=100, connect_timeout=20, stale_timeout=60, threadlocals=True ``` Problem is, I still regularly get into the position where the connection goes away during an operation, or in between operations... Which would be fine, but in that case Peewee is failing completely to reconnect, even though that is exactly what the pool should do? E.g. this morning I got a "OperationalError: (2006, "MySQL server has gone away (error(32, 'Broken pipe'))")" when trying to run something on my service, and, alarmingly, it did not work even when sending new requests, i.e. Peewee did not even try to reconnect. The MySQL server was all up and running though and simply restarting the service fixed it. From time to time I will also get a "OperationalError: (2013, "Lost connection to MySQL server during query (timeout('timed out',))")", which is probably some server issue, but I'd really really like Peewee to reconnect automatically so that I don't have to manually "try except retry" every single Peewee command I run. Do you have any help for me how I can make definitely sure that my queries don't fail, and if they do, how to reconnect? Also, how could that "Server gone away" happen, even after resending the query? Below I attached two example stack traces for exceptions. Thanks, Max ``` File "/var/www/model.py", line 216, in find_all_general total = query.select(Resource).count() File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 2366, in count return self.wrapped_count(clear_limit=clear_limit) File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 2379, in wrapped_count return rq.scalar() or 0 File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 2135, in scalar row = self._execute().fetchone() File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 2126, in _execute return self.database.execute_sql(sql, params, self.require_commit) File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 2728, in execute_sql self.commit() File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 2597, in __exit__ reraise(new_type, new_type(*exc_value.args), traceback) File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 2720, in execute_sql cursor.execute(sql, params or ()) File "/usr/local/lib/python2.7/dist-packages/pymysql/cursors.py", line 132, in execute result = self._query(query) File "/usr/local/lib/python2.7/dist-packages/pymysql/cursors.py", line 271, in _query conn.query(q) File "/usr/local/lib/python2.7/dist-packages/pymysql/connections.py", line 725, in query self._execute_command(COM_QUERY, sql) File "/usr/local/lib/python2.7/dist-packages/pymysql/connections.py", line 888, in _execute_command self._write_bytes(prelude + sql[:chunk_size-1]) File "/usr/local/lib/python2.7/dist-packages/pymysql/connections.py", line 848, in _write_bytes raise OperationalError(2006, "MySQL server has gone away (%r)" % (e,)) OperationalError: (2006, "MySQL server has gone away (error(32, 'Broken pipe'))") File "/Users/max/code/content-service/venv-cs/lib/python2.7/site-packages/peewee.py", line 3385, in get return sq.get() File "/Users/max/code/content-service/venv-cs/lib/python2.7/site-packages/peewee.py", line 2389, in get return clone.execute().next() File "/Users/max/code/content-service/venv-cs/lib/python2.7/site-packages/peewee.py", line 2430, in execute self._qr = ResultWrapper(model_class, self._execute(), query_meta) File "/Users/max/code/content-service/venv-cs/lib/python2.7/site-packages/peewee.py", line 2126, in _execute return self.database.execute_sql(sql, params, self.require_commit) File "/Users/max/code/content-service/venv-cs/lib/python2.7/site-packages/peewee.py", line 2728, in execute_sql self.commit() File "/Users/max/code/content-service/venv-cs/lib/python2.7/site-packages/peewee.py", line 2597, in __exit__ reraise(new_type, new_type(*exc_value.args), traceback) File "/Users/max/code/content-service/venv-cs/lib/python2.7/site-packages/peewee.py", line 2720, in execute_sql cursor.execute(sql, params or ()) File "/Users/max/code/content-service/venv-cs/lib/python2.7/site-packages/pymysql/cursors.py", line 132, in execute result = self._query(query) File "/Users/max/code/content-service/venv-cs/lib/python2.7/site-packages/pymysql/cursors.py", line 271, in _query conn.query(q) File "/Users/max/code/content-service/venv-cs/lib/python2.7/site-packages/pymysql/connections.py", line 726, in query self._affected_rows = self._read_query_result(unbuffered=unbuffered) File "/Users/max/code/content-service/venv-cs/lib/python2.7/site-packages/pymysql/connections.py", line 861, in _read_query_result result.read() File "/Users/max/code/content-service/venv-cs/lib/python2.7/site-packages/pymysql/connections.py", line 1064, in read first_packet = self.connection._read_packet() File "/Users/max/code/content-service/venv-cs/lib/python2.7/site-packages/pymysql/connections.py", line 825, in _read_packet packet = packet_type(self) File "/Users/max/code/content-service/venv-cs/lib/python2.7/site-packages/pymysql/connections.py", line 242, in __init__ self._recv_packet(connection) File "/Users/max/code/content-service/venv-cs/lib/python2.7/site-packages/pymysql/connections.py", line 248, in _recv_packet packet_header = connection._read_bytes(4) File "/Users/max/code/content-service/venv-cs/lib/python2.7/site-packages/pymysql/connections.py", line 838, in _read_bytes 2013, "Lost connection to MySQL server during query (%r)" % (e,)) OperationalError: (2013, "Lost connection to MySQL server during query (timeout('timed out',))") ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/464/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/464/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/463
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/463/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/463/comments
https://api.github.com/repos/coleifer/peewee/issues/463/events
https://github.com/coleifer/peewee/issues/463
48,992,893
MDU6SXNzdWU0ODk5Mjg5Mw==
463
lastrowid not found
{ "login": "hitman249", "id": 1325326, "node_id": "MDQ6VXNlcjEzMjUzMjY=", "avatar_url": "https://avatars.githubusercontent.com/u/1325326?v=4", "gravatar_id": "", "url": "https://api.github.com/users/hitman249", "html_url": "https://github.com/hitman249", "followers_url": "https://api.github.com/users/hitman249/followers", "following_url": "https://api.github.com/users/hitman249/following{/other_user}", "gists_url": "https://api.github.com/users/hitman249/gists{/gist_id}", "starred_url": "https://api.github.com/users/hitman249/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/hitman249/subscriptions", "organizations_url": "https://api.github.com/users/hitman249/orgs", "repos_url": "https://api.github.com/users/hitman249/repos", "events_url": "https://api.github.com/users/hitman249/events{/privacy}", "received_events_url": "https://api.github.com/users/hitman249/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "The insert ID is returned on a `Model.save`. `Database.last_insert_id` takes a cursor _which was used to insert a row_ and returns the ID of the inserted row. By calling `Database.get_cursor`, your asking Peewee to open a _new_ database cursor, which will have no previously executed queries attached to it, and thus it cannot return a last-insert-id. Because this is a mostly undefined behavior, different error cases will happen for each DB-adapter.\n", "@b1naryth1ef is correct, you would need to use the cursor you executed the `INSERT` with. If you are executing an `INSERT` statement, it will return the last row id automatically, and that can give you some insight into how to do it:\n\n``` python\n def execute(self):\n if self._is_multi_row_insert and self._query is None:\n if not self.database.insert_many:\n last_id = None\n for row in self._rows:\n last_id = InsertQuery(self.model_class, row).execute()\n return last_id\n return self.database.last_insert_id(self._execute(), self.model_class)\n```\n" ]
2014-11-16T15:33:49
2014-11-17T02:59:24
2014-11-17T02:59:24
NONE
null
How to know the last added row id? ``` meta = self.table.database cur = meta.get_cursor() last_insert_id = meta.last_insert_id(cursor=cur, model=Mt_files) print(last_insert_id) ``` AttributeError: 'Cursor' object has no attribute 'lastrowid'
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/463/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/463/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/462
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/462/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/462/comments
https://api.github.com/repos/coleifer/peewee/issues/462/events
https://github.com/coleifer/peewee/issues/462
48,606,642
MDU6SXNzdWU0ODYwNjY0Mg==
462
introspection fails in postgres when database contains table with same name in two different schemas
{ "login": "Jokipii", "id": 1269218, "node_id": "MDQ6VXNlcjEyNjkyMTg=", "avatar_url": "https://avatars.githubusercontent.com/u/1269218?v=4", "gravatar_id": "", "url": "https://api.github.com/users/Jokipii", "html_url": "https://github.com/Jokipii", "followers_url": "https://api.github.com/users/Jokipii/followers", "following_url": "https://api.github.com/users/Jokipii/following{/other_user}", "gists_url": "https://api.github.com/users/Jokipii/gists{/gist_id}", "starred_url": "https://api.github.com/users/Jokipii/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/Jokipii/subscriptions", "organizations_url": "https://api.github.com/users/Jokipii/orgs", "repos_url": "https://api.github.com/users/Jokipii/repos", "events_url": "https://api.github.com/users/Jokipii/events{/privacy}", "received_events_url": "https://api.github.com/users/Jokipii/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Thank you for this issue, looking into it now.\n" ]
2014-11-13T07:42:22
2014-11-13T16:13:36
2014-11-13T16:13:36
NONE
null
I tried to introspector.metadata.get_columns('isrc') and got following error: ``` C:\Python27\lib\site-packages\playhouse\reflection.pyc in get_columns(self, table) 230 columns[name] = Column( 231 name, --> 232 field_class=column_info['field_class'], 233 raw_column_type=column_info['raw_column_type'], 234 nullable=column_info['nullable'], KeyError: 'field_class' ``` To duplicate error create PostgreSQL database 'testdatabase' with two schemas 'public' and 'music' and table 'isrc' with different columns in both schemas. Then run: ``` python from peewee import * from playhouse.reflection import Introspector db = PostgresqlDatabase('testdatabase') introspector = Introspector.from_database(db) introspector.metadata.get_columns('isrc') ``` Reson for failure seems to be query from lines 192-198 ``` python def get_columns(self, table): # Get basic metadata about columns. cursor = self.execute(""" SELECT column_name, is_nullable, data_type, character_maximum_length FROM information_schema.columns WHERE table_name=%s""", table) ``` It returns table columns from all schemas. I think that It should return only columns related on current schema...
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/462/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/462/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/461
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/461/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/461/comments
https://api.github.com/repos/coleifer/peewee/issues/461/events
https://github.com/coleifer/peewee/issues/461
48,420,836
MDU6SXNzdWU0ODQyMDgzNg==
461
Join doesn't work when a composite key is used
{ "login": "bastula", "id": 61406, "node_id": "MDQ6VXNlcjYxNDA2", "avatar_url": "https://avatars.githubusercontent.com/u/61406?v=4", "gravatar_id": "", "url": "https://api.github.com/users/bastula", "html_url": "https://github.com/bastula", "followers_url": "https://api.github.com/users/bastula/followers", "following_url": "https://api.github.com/users/bastula/following{/other_user}", "gists_url": "https://api.github.com/users/bastula/gists{/gist_id}", "starred_url": "https://api.github.com/users/bastula/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/bastula/subscriptions", "organizations_url": "https://api.github.com/users/bastula/orgs", "repos_url": "https://api.github.com/users/bastula/repos", "events_url": "https://api.github.com/users/bastula/events{/privacy}", "received_events_url": "https://api.github.com/users/bastula/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I tried a raw SQL query and it works fine:\n\n``` SQL\nSELECT * FROM image JOIN treatment WHERE image.date == treatment.date\n```\n\nThe database backend is SQLite.\n", "Have you tried explicitly setting the join condition?\n\n``` python\npredicate = (Image.date == Treatment.date) & (Image.time == Treatment.time)\n query = Image.select().join(\n Treatment,\n on=predicate)\n```\n", "That works by setting the join condition. I thought I could set it using where, but that's not the right place.\n\nThanks!\n" ]
2014-11-11T19:07:52
2014-11-19T17:48:15
2014-11-13T15:49:38
NONE
null
Hello, I have a table that has a primary key set as a Composite Key and I am unable to complete a join. Here is the traceback: ``` Python Traceback (most recent call last): File "localsync.py", line 79, in get_dates query = Image.select().join(Treatment).where(Image.date == Treatment.date) File "C:\Python27\lib\site-packages\peewee.py", line 257, in inner func(clone, *args, **kwargs) File "C:\Python27\lib\site-packages\peewee.py", line 2077, in join raise ValueError('A join condition must be specified.') ValueError: A join condition must be specified. ``` and here are the models: ``` Python class Image(Model): pid = CharField() date = DateField() time = TimeField() panel = CharField() class Meta: database = db primary_key = CompositeKey('date', 'time') class Treatment(Model): id = PrimaryKeyField() pid = CharField() date = DateField() time = TimeField() field = CharField() class Meta: database = db ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/461/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/461/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/460
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/460/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/460/comments
https://api.github.com/repos/coleifer/peewee/issues/460/events
https://github.com/coleifer/peewee/pull/460
47,815,151
MDExOlB1bGxSZXF1ZXN0MjM4OTI5NzA=
460
Added terminal colors and changed string formmating following the PEP 3101
{ "login": "manipuladordedados", "id": 1189862, "node_id": "MDQ6VXNlcjExODk4NjI=", "avatar_url": "https://avatars.githubusercontent.com/u/1189862?v=4", "gravatar_id": "", "url": "https://api.github.com/users/manipuladordedados", "html_url": "https://github.com/manipuladordedados", "followers_url": "https://api.github.com/users/manipuladordedados/followers", "following_url": "https://api.github.com/users/manipuladordedados/following{/other_user}", "gists_url": "https://api.github.com/users/manipuladordedados/gists{/gist_id}", "starred_url": "https://api.github.com/users/manipuladordedados/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/manipuladordedados/subscriptions", "organizations_url": "https://api.github.com/users/manipuladordedados/orgs", "repos_url": "https://api.github.com/users/manipuladordedados/repos", "events_url": "https://api.github.com/users/manipuladordedados/events{/privacy}", "received_events_url": "https://api.github.com/users/manipuladordedados/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Thank you, but I will pass on this in order to keep the example simple.\n" ]
2014-11-05T09:22:17
2014-11-05T14:17:19
2014-11-05T14:17:19
NONE
null
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/460/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/460/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/460", "html_url": "https://github.com/coleifer/peewee/pull/460", "diff_url": "https://github.com/coleifer/peewee/pull/460.diff", "patch_url": "https://github.com/coleifer/peewee/pull/460.patch", "merged_at": null }
https://api.github.com/repos/coleifer/peewee/issues/459
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/459/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/459/comments
https://api.github.com/repos/coleifer/peewee/issues/459/events
https://github.com/coleifer/peewee/issues/459
47,814,477
MDU6SXNzdWU0NzgxNDQ3Nw==
459
Feature request: Automatically generate table and column comments from Model and Field docstrings
{ "login": "conqp", "id": 3766192, "node_id": "MDQ6VXNlcjM3NjYxOTI=", "avatar_url": "https://avatars.githubusercontent.com/u/3766192?v=4", "gravatar_id": "", "url": "https://api.github.com/users/conqp", "html_url": "https://github.com/conqp", "followers_url": "https://api.github.com/users/conqp/followers", "following_url": "https://api.github.com/users/conqp/following{/other_user}", "gists_url": "https://api.github.com/users/conqp/gists{/gist_id}", "starred_url": "https://api.github.com/users/conqp/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/conqp/subscriptions", "organizations_url": "https://api.github.com/users/conqp/orgs", "repos_url": "https://api.github.com/users/conqp/repos", "events_url": "https://api.github.com/users/conqp/events{/privacy}", "received_events_url": "https://api.github.com/users/conqp/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Thanks for the suggestion. I think I'm going to pass on this, but if you would like to submit a pull-request with an implementation, I'd help review it.\n" ]
2014-11-05T09:13:03
2014-11-05T14:08:45
2014-11-05T14:08:45
CONTRIBUTOR
null
I wondered, whether it would be possible to implement the feature of generating table and column comments from the respective models' and fields' docstrings on table creation. Thanks for considering it. OT: The "schema" option for the cross-DB FK worked. Thanks for the hint.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/459/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/459/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/458
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/458/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/458/comments
https://api.github.com/repos/coleifer/peewee/issues/458/events
https://github.com/coleifer/peewee/issues/458
47,589,169
MDU6SXNzdWU0NzU4OTE2OQ==
458
Docs issue: Example with bad practices
{ "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
[]
2014-11-03T12:36:01
2014-11-03T15:32:50
2014-11-03T15:32:50
NONE
null
http://peewee.readthedocs.org/en/unstable-2.0/peewee/models.html#Model.delete_instance there is an example ``` >>> user = User.get(User.username == username, User.password == password) ``` One could think that it's ok to store plain password in db.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/458/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/458/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/457
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/457/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/457/comments
https://api.github.com/repos/coleifer/peewee/issues/457/events
https://github.com/coleifer/peewee/issues/457
47,588,627
MDU6SXNzdWU0NzU4ODYyNw==
457
improvement : Peewee Cookbook
{ "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
[]
2014-11-03T12:28:35
2014-11-03T15:15:52
2014-11-03T15:15:52
NONE
null
http://peewee.readthedocs.org/en/unstable-2.0/peewee/cookbook.html there is example on use pwiz.py ``` python pwiz.py my_postgresql_database ``` I suggest to replace such things with ``` python -m pwiz my_postgresql_database ``` It's better to explicitly search for python module in python libs than "some script" in system paths. Also in my case it said evident thing: ``` $ python pwiz.py python: can't open file 'pwiz.py': [Errno 2] No such file or directory ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/457/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/457/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/456
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/456/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/456/comments
https://api.github.com/repos/coleifer/peewee/issues/456/events
https://github.com/coleifer/peewee/issues/456
47,517,203
MDU6SXNzdWU0NzUxNzIwMw==
456
Filtering by Count() in SQlite raises an error
{ "login": "arski", "id": 904818, "node_id": "MDQ6VXNlcjkwNDgxOA==", "avatar_url": "https://avatars.githubusercontent.com/u/904818?v=4", "gravatar_id": "", "url": "https://api.github.com/users/arski", "html_url": "https://github.com/arski", "followers_url": "https://api.github.com/users/arski/followers", "following_url": "https://api.github.com/users/arski/following{/other_user}", "gists_url": "https://api.github.com/users/arski/gists{/gist_id}", "starred_url": "https://api.github.com/users/arski/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/arski/subscriptions", "organizations_url": "https://api.github.com/users/arski/orgs", "repos_url": "https://api.github.com/users/arski/repos", "events_url": "https://api.github.com/users/arski/events{/privacy}", "received_events_url": "https://api.github.com/users/arski/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Your query is incorrect.\n\n``` python\n(User\n .select(User, fn.COUNT(Tweet.id).alias('count'))\n .join(Tweet)\n .group_by(User)\n .having(fn.COUNT(Tweet.id) > 0))\n```\n", "When aggregating, you can only filter on aggregates in the `HAVING` clause. Additionally, you need to tell the database how to group the rows -- in this case, by user.\n", "My bad, I thought I had filtered by SUM or COUNT in a WHERE clause in MySQL before.. but maybe that was an erroneous recollection. thanks for the help!\n" ]
2014-11-01T21:11:10
2014-11-02T13:44:30
2014-11-01T21:22:56
NONE
null
What I'm trying to do is something like: ``` User.select(User, fn.Count(Tweet)).join(Tweet).where(fn.Count(Tweet) > 0) ``` Sadly, in SQlite, this throws an `OperationalError: misuse of aggregate: Count()` - which upon further investigation on SO turns out to be a specific SQlite issue where filtering by aggregates has to be done inside `HAVING` clause instead of `WHERE` - http://stackoverflow.com/questions/648083/sql-error-misuse-of-aggregate - any chance you could look into this please
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/456/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/456/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/455
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/455/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/455/comments
https://api.github.com/repos/coleifer/peewee/issues/455/events
https://github.com/coleifer/peewee/issues/455
47,516,731
MDU6SXNzdWU0NzUxNjczMQ==
455
How to use functions like POSTGRES EXTRACT(YEAR FROM table.field)
{ "login": "demongoo", "id": 941459, "node_id": "MDQ6VXNlcjk0MTQ1OQ==", "avatar_url": "https://avatars.githubusercontent.com/u/941459?v=4", "gravatar_id": "", "url": "https://api.github.com/users/demongoo", "html_url": "https://github.com/demongoo", "followers_url": "https://api.github.com/users/demongoo/followers", "following_url": "https://api.github.com/users/demongoo/following{/other_user}", "gists_url": "https://api.github.com/users/demongoo/gists{/gist_id}", "starred_url": "https://api.github.com/users/demongoo/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/demongoo/subscriptions", "organizations_url": "https://api.github.com/users/demongoo/orgs", "repos_url": "https://api.github.com/users/demongoo/repos", "events_url": "https://api.github.com/users/demongoo/events{/privacy}", "received_events_url": "https://api.github.com/users/demongoo/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "You might try:\n\n``` python\nfn.EXTRACT(Clause(SQL('EPOCH FROM'), SomeModel.field))\n\n# or\n(fn.EXTRACT(Clause(SQL('EPOCH FROM'), SomeModel.field)) * 1000).alias('session_id)\n```\n", "For future reference it looks like you want to use `NodeList` now instead of Clause", "This is built-in to the database object as of Peewee 3. You can use `db.extract_date('epoch', M.field)`." ]
2014-11-01T20:52:48
2019-11-11T18:25:21
2014-11-01T21:20:17
NONE
null
This thing still doesn't let me sleep tight. Can I somehow write the select field like: ``` EXTRACT(EPOCH FROM field) ``` Now I'm using `(fn.EXTRACT(SQL("EPOCH FROM \"t5\".\"ts\"")) * 1000).alias('session_id')` and the worst part is "t5". Is there any other solution? Or maybe some ideas how to let such constructions to be written?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/455/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/455/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/454
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/454/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/454/comments
https://api.github.com/repos/coleifer/peewee/issues/454/events
https://github.com/coleifer/peewee/issues/454
47,510,108
MDU6SXNzdWU0NzUxMDEwOA==
454
Parenthesis for CompoundQueries in FROM clause
{ "login": "demongoo", "id": 941459, "node_id": "MDQ6VXNlcjk0MTQ1OQ==", "avatar_url": "https://avatars.githubusercontent.com/u/941459?v=4", "gravatar_id": "", "url": "https://api.github.com/users/demongoo", "html_url": "https://github.com/demongoo", "followers_url": "https://api.github.com/users/demongoo/followers", "following_url": "https://api.github.com/users/demongoo/following{/other_user}", "gists_url": "https://api.github.com/users/demongoo/gists{/gist_id}", "starred_url": "https://api.github.com/users/demongoo/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/demongoo/subscriptions", "organizations_url": "https://api.github.com/users/demongoo/orgs", "repos_url": "https://api.github.com/users/demongoo/repos", "events_url": "https://api.github.com/users/demongoo/events{/privacy}", "received_events_url": "https://api.github.com/users/demongoo/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "What version of peewee are you using? In my testing locally it appears the parentheses are correct:\n\n``` python\nuq = User.select(User.username).where(User.username << ['a', 'b', 'd'])\n oq = (OrderedModel\n .select(OrderedModel.title)\n .where(OrderedModel.title << ['a', 'b'])\n .order_by())\n union = uq | oq\n print union.sql()\n```\n\nPrints:\n\n``` sql\nSELECT 1 FROM (\n SELECT \"t2\".\"username\" FROM \"users\" AS t2 WHERE (\"t2\".\"username\" IN (?, ?, ?)) \n UNION \n SELECT \"t2\".\"title\" FROM \"orderedmodel\" AS t2 WHERE (\"t2\".\"title\" IN (?, ?))\n)\n```\n", "I use `peewee (2.4.0)`.\nAnd just found that there's 2.4.1 available. Please, don't close the issue for a couple of days, ok? I'll check with 2.4.1 tomorrow and will write here.\n", "Sure thing, I added a unittest which shows that the parentheses are present.\n", "Indeed, seems it had been fixed recently. After upgrading it has parenthesis. Sorry for bothering. peewee is really cool piece of software. :)\n", "No problem at all! Thanks for opening the issue, glad it's fixed for you.\n" ]
2014-11-01T16:36:35
2014-11-01T21:02:31
2014-11-01T20:42:25
NONE
null
I made union query using `|` and was hoping to put it into `from_` of another query, but compiled query contains no parenthesis and results in error: `ProgrammingError at or near "SELECT`. Because inner query is not surrounded by parenthesis. Compiled output something like that: ``` inner = q1 | q2 | q3 q = Model.select(SQL('f1'), SQL('f2')).from(inner.alias('q')... results in: SELECT f1, f2 FROM q1 UNION q2 UNION q3 AS q ``` And fails. But if I try to do it manually like: `SELECT f1, f2 FROM (q1 UNION q2 UNION q3) AS q it is ok. (q1-q3 is just substitues for actual queries, to simplify example). Database is postgresql. Can we somehow fix it or am I missing some functionality for that?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/454/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/454/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/453
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/453/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/453/comments
https://api.github.com/repos/coleifer/peewee/issues/453/events
https://github.com/coleifer/peewee/issues/453
47,327,576
MDU6SXNzdWU0NzMyNzU3Ng==
453
Just and idea / discussion. Extensions support?
{ "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
[ "Technically all is necessary is to add some reference to docs and add \"peewee_ext\" package from that sample to distribution.\n", "> Just an idea, what do you think of \"standard\" extensions support for peewee like in Flask?\n\nI thought that Flask had moved away from that type of packaging.\n\nPython packaging is already confusing enough, I say let's just have peewee plugins be normal python packages.\n", "> I thought that Flask had moved away from that type of packaging.\n\nThey moved away from \"namespace packages\" and now Flask packages are normal packages, but there's a \"import redirect\" for \"flask.ext.name\" to \"flask_name\", so extension just define regular Python package \"flask_name\" and Flask is aware of the rest.\n\n> Python packaging is already confusing enough, I say let's just have peewee plugins be normal python packages.\n\nWell, I agree with that! :)\n\nI just like that Flask extensions are well organised, so I've explored their approach.\n", "This redirect rule was designed as a workaround for moving from old-style namespace packages to new style packages. So, it's more necessary step than initial intention. But ironically this workaround due to tight restriction has lead to common naming convention, which Django doesn't have for example :)\n", "Interesting about the import redirection... At any rate, I think I prefer the default style, even at the loss of a little consistency in naming.\n" ]
2014-10-30T21:05:50
2014-10-31T14:41:29
2014-10-31T05:47:09
NONE
null
Hello Charles! Just an idea, what do you think of "standard" extensions support for peewee like in Flask? So everyone who wants to write extension for peewee creates package like "peewee_foobar" and peewee has special hook for importing these package with: ``` import peewee_ext.foobar ``` So we can put "stable" extensions to that namespace and provide a simple convention for creating extensions via simple package naming. This is not about less verbosity. Just about a bit cleaner standard. I've played with it and it worked: https://github.com/rudyryk/peewee-ext
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/453/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/453/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/452
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/452/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/452/comments
https://api.github.com/repos/coleifer/peewee/issues/452/events
https://github.com/coleifer/peewee/pull/452
47,192,445
MDExOlB1bGxSZXF1ZXN0MjM1NTc1NTM=
452
PyPy support
{ "login": "stas", "id": 112147, "node_id": "MDQ6VXNlcjExMjE0Nw==", "avatar_url": "https://avatars.githubusercontent.com/u/112147?v=4", "gravatar_id": "", "url": "https://api.github.com/users/stas", "html_url": "https://github.com/stas", "followers_url": "https://api.github.com/users/stas/followers", "following_url": "https://api.github.com/users/stas/following{/other_user}", "gists_url": "https://api.github.com/users/stas/gists{/gist_id}", "starred_url": "https://api.github.com/users/stas/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/stas/subscriptions", "organizations_url": "https://api.github.com/users/stas/orgs", "repos_url": "https://api.github.com/users/stas/repos", "events_url": "https://api.github.com/users/stas/events{/privacy}", "received_events_url": "https://api.github.com/users/stas/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Interesting! Fwiw peewee had fallback code in place to use pymysql, the pure python lib.\n", "@coleifer please take a look at the latest changes. Thanks.\n", "Looks good -- can you explain a little bit the changes in c92510a? I see 2 instances of manually closing a cursor and was just wondering about it.\n", "Honestly I can't. It looks like this is an issue only when testing sqlite engine on pypy. My best guess is that this is related to the way gc works on pypy. If you think this is an important aspect, let me have some more time before merging this.\n", "> If you think this is an important aspect, let me have some more time before merging this.\n\nI'm not sure how important it is. Peewee uses cursors quite a bit and I don't believe I've ever added a call to close one, so my concern is just that there may be lurking problems.\n\nI'd definitely like to get to the bottom of it, though. Can you share the errors that occurred when the calls to `close` weren't present?\n", "Sure, here's the travis build without that call:\nhttps://travis-ci.org/coleifer/peewee/jobs/39418500\n\nIgnore the non-pypy failed builds.\n", "Ah, interesting, ok! I wonder if there's a pattern to those errors, or if they just pop up now and then.\n", "Well, its for sure that the failures depend on the test I patched to close the cursor, without that test, the suite passes.\n", "> Well, its for sure that the failures depend on the test I patched to close the cursor, without that test, the suite passes.\n\nAnd the failures were repeatable and occurred every time the suite ran?\n", "Yep, I was able to reproduce the failures locally and isolate this to that single test. Weird, I know...\n", "Hey @coleifer I'm a bit confused.\nWhy this was not merged? I don't see how df64a0e covers all the changes I suggested in the PR.\nAlso it looks like you just hand-picked some of the changes, why?\n", "> I don't see how df64a0e covers all the changes I suggested in the PR.\n\nWhat's missing?\n", "I'm on master and sqlite tests fail for me, postgres engine migrations tests fail too.\nI also suggested to include the pypy builds on travis.\n\nI'm really curious what was wrong with this PR...\n", "Well, I wasn't sure I wanted to include it on travis, and I also wasn't sure about the manual closing of cursors in places. I thought I'd try it out with what I thought were the minimal code changes and not worry about test behavior at first.\n", "I'm sorry if you are upset that I didn't merge your contributions, I will definitely give you a shout-out in the release notes.\n", "Ok, this sounds good, though I would be happier if we had the travis running those builds.\nCarry on, this is really great that we can now use peewee on PyPy :tada: \n", "Thanks for your contribution, I really appreciate it and am glad to have things working on PyPy as well.\n" ]
2014-10-29T19:26:08
2014-11-19T14:41:25
2014-11-19T06:03:25
NONE
null
This is a tentative to make peewee work on PyPy. So far most of the issues I could find are related to the database packages that are compatible on PyPy/CPython. This is still a WIP, I didn't make time to look at the MySQL support yet. I will try to have an update on that asap. Please let me know if there are any questions so far, or there are better ways to handle the compatibility aspects. Thanks in advance for reviewing this.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/452/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/452/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/452", "html_url": "https://github.com/coleifer/peewee/pull/452", "diff_url": "https://github.com/coleifer/peewee/pull/452.diff", "patch_url": "https://github.com/coleifer/peewee/pull/452.patch", "merged_at": null }
https://api.github.com/repos/coleifer/peewee/issues/451
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/451/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/451/comments
https://api.github.com/repos/coleifer/peewee/issues/451/events
https://github.com/coleifer/peewee/issues/451
47,103,819
MDU6SXNzdWU0NzEwMzgxOQ==
451
python_value not being called on create()
{ "login": "alexlatchford", "id": 628146, "node_id": "MDQ6VXNlcjYyODE0Ng==", "avatar_url": "https://avatars.githubusercontent.com/u/628146?v=4", "gravatar_id": "", "url": "https://api.github.com/users/alexlatchford", "html_url": "https://github.com/alexlatchford", "followers_url": "https://api.github.com/users/alexlatchford/followers", "following_url": "https://api.github.com/users/alexlatchford/following{/other_user}", "gists_url": "https://api.github.com/users/alexlatchford/gists{/gist_id}", "starred_url": "https://api.github.com/users/alexlatchford/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/alexlatchford/subscriptions", "organizations_url": "https://api.github.com/users/alexlatchford/orgs", "repos_url": "https://api.github.com/users/alexlatchford/repos", "events_url": "https://api.github.com/users/alexlatchford/events{/privacy}", "received_events_url": "https://api.github.com/users/alexlatchford/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I don't think this is a bug, since you are creating the objects from Python, but I appreciate you opening the issue.\n", "Yeah figured that might the response, I'll fix it on my end then. Cheers :)\n" ]
2014-10-29T02:09:11
2014-10-29T22:21:37
2014-10-29T22:21:37
CONTRIBUTOR
null
Hi Charles, Just found another minor issue, this set of tests should demonstrate the problem. ``` import unittest from datetime import datetime from peewee import SqliteDatabase, Model, PrimaryKeyField, DateTimeField db = SqliteDatabase(':memory:') class MyModel(Model): id = PrimaryKeyField() my_field = DateTimeField() class Meta: database = db class DatetimeConversionTest(unittest.TestCase): def setUp(self): db.connect() MyModel.create_table() def tearDown(self): MyModel.drop_table() db.close() def test_create(self): my_model = MyModel.create(my_field="2014-01-01 00:00:00") # Throws, actually returns "2014-01-01 00:00:00" self.assertEqual(my_model.my_field, datetime(2014, 1, 1, 0, 0, 0)) def test_get(self): my_model = MyModel.create(my_field="2014-01-01 00:00:00") my_model2 = MyModel.get(MyModel.id == my_model.id) self.assertEqual(my_model2.my_field, datetime(2014, 1, 1, 0, 0, 0)) # Passes fine if __name__ == "__main__": unittest.main() ``` I think it's just a case of running the python_value function over any arguments passed into the model. Not sure if this is something you this is something you'd consider a bug or not. Cheers, Alex
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/451/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/451/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/450
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/450/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/450/comments
https://api.github.com/repos/coleifer/peewee/issues/450/events
https://github.com/coleifer/peewee/issues/450
47,050,456
MDU6SXNzdWU0NzA1MDQ1Ng==
450
Why does saving a model in a loop over a query go twice over the first two items?
{ "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
[ "Just to add to the confusion. If I run the loop one time before I run it while saving, it doesn't loop 3 times:\n\n```\nusers = User.select()\nfor user in users: pass\n\nfor user in users:\n print 'We\\'re now storing a pm for user: ', user.name\n pm = PM()\n pm.user = user\n pm.text = ''.join([random.choice(string.ascii_letters) for n in xrange(25)])\n pm.save()\n```\n\nThis also correctly prints out:\n\n```\nWe've got so many users: 3\nWe're now storing a pm for user: A\nWe're now storing a pm for user: B\nWe're now storing a pm for user: C\n```\n\nbut when I remove the line `for user in users: pass` it does this again:\n\n```\nWe've got so many users: 3\nWe're now storing a pm for user: A\nWe're now storing a pm for user: B\nWe're now storing a pm for user: A\nWe're now storing a pm for user: B\nWe're now storing a pm for user: C\n```\n\nAny idea why a loop before the second loop would influence the behaviour?\n", "http://docs.peewee-orm.com/en/latest/peewee/database.html#common-pitfalls-with-sqlite\n" ]
2014-10-28T16:46:54
2014-10-28T17:18:32
2014-10-28T17:18:32
NONE
null
I'm trying to save something for every user in a db, but to my surprise the loop goes double over the first two items. ``` #!/usr/bin/env python import os, random, string from peewee import * DB_NAME = 'people.db' db = SqliteDatabase(DB_NAME) class User(Model): name = CharField() class Meta: database = db class PM(Model): user = ForeignKeyField(User) text = TextField() class Meta: database = db try: os.remove(DB_NAME) print 'Deleted the existing DB' except OSError: print 'No db present. Creating one.' db.create_tables([User, PM]) for name in ['A', 'B', 'C']: u = User() u.name = name u.save() print 'We\'ve got so many users: ', User.select().count() for user in User.select(): print 'We\'re now storing a pm for user: ', user.name pm = PM() pm.user = user pm.text = ''.join([random.choice(string.ascii_letters) for n in xrange(25)]) pm.save() # comment this line out and see what happens. ``` This prints out: ``` We've got so many users: 3 We're now storing a pm for user: A We're now storing a pm for user: B We're now storing a pm for user: A We're now storing a pm for user: B We're now storing a pm for user: C ``` When you comment out the last line, it correctly prints out: ``` We've got so many users: 3 We're now storing a pm for user: A We're now storing a pm for user: B We're now storing a pm for user: C ``` I tried whether this is caused by the ForeignKeyField, but if I do the same with an unrelated table ([code here](http://pastebin.com/ayWGbqkT)) I see the same behaviour. Does anybody know what's wrong here? ps. I have the feeling that I've encountered this before, but I can't remember how I dealt with it back then and I can't find any issues from myself about this.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/450/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/450/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/449
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/449/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/449/comments
https://api.github.com/repos/coleifer/peewee/issues/449/events
https://github.com/coleifer/peewee/pull/449
46,863,011
MDExOlB1bGxSZXF1ZXN0MjMzNTk4NjM=
449
Fix typo in db_url.py
{ "login": "malea", "id": 4734824, "node_id": "MDQ6VXNlcjQ3MzQ4MjQ=", "avatar_url": "https://avatars.githubusercontent.com/u/4734824?v=4", "gravatar_id": "", "url": "https://api.github.com/users/malea", "html_url": "https://github.com/malea", "followers_url": "https://api.github.com/users/malea/followers", "following_url": "https://api.github.com/users/malea/following{/other_user}", "gists_url": "https://api.github.com/users/malea/gists{/gist_id}", "starred_url": "https://api.github.com/users/malea/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/malea/subscriptions", "organizations_url": "https://api.github.com/users/malea/orgs", "repos_url": "https://api.github.com/users/malea/repos", "events_url": "https://api.github.com/users/malea/events{/privacy}", "received_events_url": "https://api.github.com/users/malea/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Wow, that's embarrassing! Thanks for the fix!\n" ]
2014-10-27T01:48:14
2014-10-27T01:49:32
2014-10-27T01:49:32
CONTRIBUTOR
null
This was breaking on Heroku with the following error: ``` peewee.OperationalError: invalid connection option "post" ``` I checked the source code to see where this `"post"` was coming from, and here it was!
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/449/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/449/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/449", "html_url": "https://github.com/coleifer/peewee/pull/449", "diff_url": "https://github.com/coleifer/peewee/pull/449.diff", "patch_url": "https://github.com/coleifer/peewee/pull/449.patch", "merged_at": "2014-10-27T01:49:32" }
https://api.github.com/repos/coleifer/peewee/issues/448
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/448/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/448/comments
https://api.github.com/repos/coleifer/peewee/issues/448/events
https://github.com/coleifer/peewee/pull/448
46,692,791
MDExOlB1bGxSZXF1ZXN0MjMyNjk0NTI=
448
Add in support for detecting server closed connections in postgres
{ "login": "alexlatchford", "id": 628146, "node_id": "MDQ6VXNlcjYyODE0Ng==", "avatar_url": "https://avatars.githubusercontent.com/u/628146?v=4", "gravatar_id": "", "url": "https://api.github.com/users/alexlatchford", "html_url": "https://github.com/alexlatchford", "followers_url": "https://api.github.com/users/alexlatchford/followers", "following_url": "https://api.github.com/users/alexlatchford/following{/other_user}", "gists_url": "https://api.github.com/users/alexlatchford/gists{/gist_id}", "starred_url": "https://api.github.com/users/alexlatchford/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/alexlatchford/subscriptions", "organizations_url": "https://api.github.com/users/alexlatchford/orgs", "repos_url": "https://api.github.com/users/alexlatchford/repos", "events_url": "https://api.github.com/users/alexlatchford/events{/privacy}", "received_events_url": "https://api.github.com/users/alexlatchford/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Thank you for your help with this issue!\n" ]
2014-10-24T00:22:17
2014-10-24T03:00:21
2014-10-24T03:00:15
CONTRIBUTOR
null
How about this implementation? Making use of your approach but still including it in the main repo, as much as I'd like to I'd like to contribute back to the main repo for things like this :)
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/448/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/448/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/448", "html_url": "https://github.com/coleifer/peewee/pull/448", "diff_url": "https://github.com/coleifer/peewee/pull/448.diff", "patch_url": "https://github.com/coleifer/peewee/pull/448.patch", "merged_at": "2014-10-24T03:00:15" }
https://api.github.com/repos/coleifer/peewee/issues/447
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/447/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/447/comments
https://api.github.com/repos/coleifer/peewee/issues/447/events
https://github.com/coleifer/peewee/pull/447
46,478,137
MDExOlB1bGxSZXF1ZXN0MjMxMzgwNTk=
447
Fix typo.
{ "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
[ "Thanks!\n" ]
2014-10-22T06:53:15
2014-10-22T16:39:40
2014-10-22T16:39:38
CONTRIBUTOR
null
``` > query.update() E AttributeError: 'UpdateQuery' object has no attribute 'update' 1 failed, 27 passed in 3.69 seconds ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/447/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/447/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/447", "html_url": "https://github.com/coleifer/peewee/pull/447", "diff_url": "https://github.com/coleifer/peewee/pull/447.diff", "patch_url": "https://github.com/coleifer/peewee/pull/447.patch", "merged_at": "2014-10-22T16:39:38" }
https://api.github.com/repos/coleifer/peewee/issues/446
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/446/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/446/comments
https://api.github.com/repos/coleifer/peewee/issues/446/events
https://github.com/coleifer/peewee/issues/446
46,418,499
MDU6SXNzdWU0NjQxODQ5OQ==
446
How to enter the admin interface?
{ "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
[ "```\n File \"/Library/Python/2.7/site-packages/flask_peewee/auth.py\", line 142, in authenticate\n user = active.where(self.User.username==username).get()\n```\n\nYou may need to implement your own `Auth` class providing an `authenticate()` method which will ensure that the requesting user is authenticated. This is not really a peewee question, so I am closing. Feel free to reopen in `flask-peewee`.\n" ]
2014-10-21T17:05:05
2014-10-21T18:08:35
2014-10-21T18:08:35
NONE
null
I'm trying to get the peewee admin up and running. For this I followed the simple four step getting started guide here: http://flask-peewee.readthedocs.org/en/latest/admin.html And after implementing the four steps and having my flask app up and running I'm kinda lost. I managed to figure out that I had to go to mydomain.com/admin (could have been mentioned there .. :) ), but I now need to insert a username and password. Since I never defined a username and password anywhere I wouldn't know what to use. I do have user logins on my website using flask-login and flask-oauthlib to authenticate with LinkedIn, but I figured that the Peewee admin doesn't assume any User model to be defined or login system incorporated in the app. So in the end I just tried something random and hit "Log In", which caused it to end in an error: ``` Traceback (most recent call last): File "/Library/Python/2.7/site-packages/flask/app.py", line 1836, in __call__ return self.wsgi_app(environ, start_response) File "/Library/Python/2.7/site-packages/flask/app.py", line 1820, in wsgi_app response = self.make_response(self.handle_exception(e)) File "/Library/Python/2.7/site-packages/flask/app.py", line 1403, in handle_exception reraise(exc_type, exc_value, tb) File "/Library/Python/2.7/site-packages/flask/app.py", line 1817, in wsgi_app response = self.full_dispatch_request() File "/Library/Python/2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request rv = self.handle_user_exception(e) File "/Library/Python/2.7/site-packages/flask/app.py", line 1381, in handle_user_exception reraise(exc_type, exc_value, tb) File "/Library/Python/2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request rv = self.dispatch_request() File "/Library/Python/2.7/site-packages/flask/app.py", line 1461, in dispatch_request return self.view_functions[rule.endpoint](**req.view_args) File "/Library/Python/2.7/site-packages/flask_peewee/auth.py", line 189, in login form.password.data, File "/Library/Python/2.7/site-packages/flask_peewee/auth.py", line 142, in authenticate user = active.where(self.User.username==username).get() File "build/bdist.macosx-10.9-intel/egg/peewee.py", line 2390, in get return clone.execute().next() File "build/bdist.macosx-10.9-intel/egg/peewee.py", line 2431, in execute self._qr = ResultWrapper(model_class, self._execute(), query_meta) File "build/bdist.macosx-10.9-intel/egg/peewee.py", line 2127, in _execute return self.database.execute_sql(sql, params, self.require_commit) File "build/bdist.macosx-10.9-intel/egg/peewee.py", line 2732, in execute_sql self.commit() File "build/bdist.macosx-10.9-intel/egg/peewee.py", line 2601, in __exit__ reraise(new_type, new_type(*exc_value.args), traceback) File "build/bdist.macosx-10.9-intel/egg/peewee.py", line 2724, in execute_sql cursor.execute(sql, params or ()) OperationalError: no such column: t1.username ``` So from this I think that it does actually try to use my User class (which doesn't have a username defined because it uses LinkedIn authentication). Does anybody know how I can get the peewee admin working? All tips are welcome!
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/446/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/446/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/445
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/445/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/445/comments
https://api.github.com/repos/coleifer/peewee/issues/445/events
https://github.com/coleifer/peewee/issues/445
46,268,272
MDU6SXNzdWU0NjI2ODI3Mg==
445
Cross-database foreign keys do not work
{ "login": "conqp", "id": 3766192, "node_id": "MDQ6VXNlcjM3NjYxOTI=", "avatar_url": "https://avatars.githubusercontent.com/u/3766192?v=4", "gravatar_id": "", "url": "https://api.github.com/users/conqp", "html_url": "https://github.com/conqp", "followers_url": "https://api.github.com/users/conqp/followers", "following_url": "https://api.github.com/users/conqp/following{/other_user}", "gists_url": "https://api.github.com/users/conqp/gists{/gist_id}", "starred_url": "https://api.github.com/users/conqp/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/conqp/subscriptions", "organizations_url": "https://api.github.com/users/conqp/orgs", "repos_url": "https://api.github.com/users/conqp/repos", "events_url": "https://api.github.com/users/conqp/events{/privacy}", "received_events_url": "https://api.github.com/users/conqp/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "What is the correct syntax for using cross-database relationships? I'm not familiar with them. Can you share some example SQL queries that work, so I can compare against the ones that don't?\n", "On MySQL-level it works like that:\n\n``` MySQL\ncreate database db1;\n\nuse db1;\n\nCREATE TABLE `historial` (\n`codh` smallint(5) unsigned NOT NULL auto_increment,\nPRIMARY KEY (`codh`)\n) ENGINE=InnoDB DEFAULT CHARSET=latin1;\n\ncreate database db2;\n\nuse db2;\n\nCREATE TABLE t1 (\nid tinyint(3) unsigned NOT NULL auto_increment,\nmicod smallint(5) unsigned default NULL,\nPRIMARY KEY (id),\nKEY micod (micod),\nCONSTRAINT t1_ibfk_1 FOREIGN KEY (micod) REFERENCES db1.historial (codh) ON DELETE CASCADE ON UPDATE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=latin1;\n\nCREATE TABLE t2 (\nid tinyint(3) unsigned NOT NULL auto_increment,\nmicod2 smallint(5) unsigned default NULL,\nPRIMARY KEY (id),\nKEY micod2 (micod2)\n) ENGINE=InnoDB DEFAULT CHARSET=latin1;\n\nalter table t2 add foreign key FK_t2(micod2) references db1.historial(codh) on delete cascade on update cascade; \n```\n\nTaken from: http://forums.mysql.com/read.php?22,150829,200251#msg-200251\n", "Sorry, I should have clarified my question -- what are some example SQL queries you want to execute but are currently not able to?\n", "Oh, sorry. I obviously misunserstood you then.\nI am trying to map real estates from our real estate database to our customers in our CRM database.\n1) CRM database\nDB definition: _homeinfodb.config_\n\n``` python\nDB = 'homeinfodb'\nHOST = 'myusername'\nUSER = 'myuser'\nPASSWD = 'mypasswd'\n\ndatabase = MySQLDatabase(DB, host=HOST, user=USER, passwd=PASSWD)\n```\n\nBase model: _homeinfodb.models.abc_\n\n``` python\nfrom peewee import Model\nfrom ..config import database\n\nclass CRMModel(Model):\n \"\"\"\n Generic HOMEINFO-DB Model\n \"\"\"\n class Meta:\n database = database\n```\n\nThe actual customer model: _homeinfodb.models.customer_\n\n``` python\nfrom .abc import CRMModel\nfrom .company import Company\nfrom peewee import ForeignKeyField, IntegerField\n\nclass Customer(CRMModel):\n \"\"\"\n CRM's customer(s)\n \"\"\"\n cid = IntegerField()\n \"\"\"A unique customer ID\"\"\"\n company = ForeignKeyField(Company, related_name='customers')\n \"\"\"A related company\"\"\"\n # TODO: Add other stuff like merchants etc.\n```\n\n(The foreign key field in customer is not the issue here!) \n\n2) The real estate database\nDefinition: _realestatedb.config_\n\n``` python\nfrom peewee import MySQLDatabase\n\nDB = 'realestatedb'\nHOST = 'myusername'\nUSER = 'myuser'\nPASSWD = 'mypasswd'\n\ndatabase = MySQLDatabase(DB, host=HOST, user=USER, passwd=PASSWD)\n```\n\nBase model: _realestatedb.models.abc_\n\n``` python\nfrom ..config import database\nfrom peewee import Model\n\nclass REDBModel(Model):\n class Meta:\n database = database\n```\n\nRealestate definition: _realestatedb.models.realestate_\n\n``` python\nfrom .abc import OIDBModel\nfrom .log import ImportLog\nfrom homeinfodb.models import Customer\nfrom peewee import ForeignKeyField, TextField\n# XXX: Rename import to avoid collision with property\nimport openimmo as openimmo_classbinding\n\nclass RealEstate(OIDBModel):\n \"\"\"\n A table for real estate lists\n \"\"\"\n customer = ForeignKeyField(Customer, related_name='realestates')\n \"\"\"Foreign key mapping to the owning customer\"\"\"\n xml = TextField()\n \"\"\"The OpenImmo XML text\n XXX: Must be of type 'VOLL'!\"\"\"\n last_import = ForeignKeyField(ImportLog)\n \"\"\"Link to the last import\"\"\"\n\n @property\n def openimmo(self):\n \"\"\"Returns an OpenImmo class binding\"\"\"\n return openimmo_classbinding.CreateFromDocument(self.xml)\n```\n\nOnly the foreign key to the Customer (of the _homeinfodb_ package and in the other database) triggers an error here, when I try to create the latter database tables or try any type of selection after I created them manually. The stack traces are those of my initial post. If I don't use foreign keys on models within other databases, there is no problem whatsoever.\n\nIf you need more information, just let me know.\n", "You might try using the `schema` model option. This is typically reserved for referencing tables that belong to a schema, but it might work for your use-case as well.\n\n``` python\nclass CRMModel(Model):\n \"\"\"\n Generic HOMEINFO-DB Model\n \"\"\"\n class Meta:\n database = database\n schema = 'homeinfodb'\n\n# ...\n\n\nclass REDBModel(Model):\n class Meta:\n database = database\n schema = 'realestatedb'\n```\n", "Please re-open if using `schema` does not resolve the issue.\n" ]
2014-10-20T12:55:23
2014-10-30T18:20:01
2014-10-30T18:20:01
CONTRIBUTOR
null
Using the _ForeignKeyField_ inside a model with a _rel_model_ that's located inside another database than the aforementioned model peewee won't resolve the related model to its correct database. As a result, tables containing foreign keys with related models of other databases cannot be created: ``` Traceback (most recent call last): File "/usr/lib/python3.4/site-packages/peewee-2.2.4-py3.4.egg/peewee.py", line 2406, in execute_sql File "/usr/lib/python3.4/site-packages/PyMySQL-0.6.2-py3.4.egg/pymysql/cursors.py", line 132, in execute result = self._query(query) File "/usr/lib/python3.4/site-packages/PyMySQL-0.6.2-py3.4.egg/pymysql/cursors.py", line 271, in _query conn.query(q) File "/usr/lib/python3.4/site-packages/PyMySQL-0.6.2-py3.4.egg/pymysql/connections.py", line 744, in query self._affected_rows = self._read_query_result(unbuffered=unbuffered) File "/usr/lib/python3.4/site-packages/PyMySQL-0.6.2-py3.4.egg/pymysql/connections.py", line 879, in _read_query_result result.read() File "/usr/lib/python3.4/site-packages/PyMySQL-0.6.2-py3.4.egg/pymysql/connections.py", line 1082, in read first_packet = self.connection._read_packet() File "/usr/lib/python3.4/site-packages/PyMySQL-0.6.2-py3.4.egg/pymysql/connections.py", line 844, in _read_packet packet.check_error() File "/usr/lib/python3.4/site-packages/PyMySQL-0.6.2-py3.4.egg/pymysql/connections.py", line 370, in check_error raise_mysql_exception(self._data) File "/usr/lib/python3.4/site-packages/PyMySQL-0.6.2-py3.4.egg/pymysql/err.py", line 116, in raise_mysql_exception _check_mysql_exception(errinfo) File "/usr/lib/python3.4/site-packages/PyMySQL-0.6.2-py3.4.egg/pymysql/err.py", line 112, in _check_mysql_exception raise InternalError(errno, errorvalue) pymysql.err.InternalError: (1005, "Can't create table 'realestatedb.realestate' (errno: 150)") During handling of the above exception, another exception occurred: Traceback (most recent call last): File "./setup.py", line 22, in <module> table.create_table(fail_silently=True) File "/usr/lib/python3.4/site-packages/peewee-2.2.4-py3.4.egg/peewee.py", line 3078, in create_table File "/usr/lib/python3.4/site-packages/peewee-2.2.4-py3.4.egg/peewee.py", line 2471, in create_table File "/usr/lib/python3.4/site-packages/peewee-2.2.4-py3.4.egg/peewee.py", line 2414, in execute_sql File "/usr/lib/python3.4/site-packages/peewee-2.2.4-py3.4.egg/peewee.py", line 2283, in __exit__ File "/usr/lib/python3.4/site-packages/peewee-2.2.4-py3.4.egg/peewee.py", line 105, in reraise File "/usr/lib/python3.4/site-packages/peewee-2.2.4-py3.4.egg/peewee.py", line 2406, in execute_sql File "/usr/lib/python3.4/site-packages/PyMySQL-0.6.2-py3.4.egg/pymysql/cursors.py", line 132, in execute result = self._query(query) File "/usr/lib/python3.4/site-packages/PyMySQL-0.6.2-py3.4.egg/pymysql/cursors.py", line 271, in _query conn.query(q) File "/usr/lib/python3.4/site-packages/PyMySQL-0.6.2-py3.4.egg/pymysql/connections.py", line 744, in query self._affected_rows = self._read_query_result(unbuffered=unbuffered) File "/usr/lib/python3.4/site-packages/PyMySQL-0.6.2-py3.4.egg/pymysql/connections.py", line 879, in _read_query_result result.read() File "/usr/lib/python3.4/site-packages/PyMySQL-0.6.2-py3.4.egg/pymysql/connections.py", line 1082, in read first_packet = self.connection._read_packet() File "/usr/lib/python3.4/site-packages/PyMySQL-0.6.2-py3.4.egg/pymysql/connections.py", line 844, in _read_packet packet.check_error() File "/usr/lib/python3.4/site-packages/PyMySQL-0.6.2-py3.4.egg/pymysql/connections.py", line 370, in check_error raise_mysql_exception(self._data) File "/usr/lib/python3.4/site-packages/PyMySQL-0.6.2-py3.4.egg/pymysql/err.py", line 116, in raise_mysql_exception _check_mysql_exception(errinfo) File "/usr/lib/python3.4/site-packages/PyMySQL-0.6.2-py3.4.egg/pymysql/err.py", line 112, in _check_mysql_exception raise InternalError(errno, errorvalue) peewee.InternalError: (1005, "Can't create table 'realestatedb.realestate' (errno: 150)") ``` And, if the databases were then manually created, it cannot assign the correct foreign key fields: ``` Traceback (most recent call last): File "/usr/lib/python3.4/site-packages/peewee-2.2.4-py3.4.egg/peewee.py", line 2406, in execute_sql File "/usr/lib/python3.4/site-packages/PyMySQL-0.6.2-py3.4.egg/pymysql/cursors.py", line 132, in execute result = self._query(query) File "/usr/lib/python3.4/site-packages/PyMySQL-0.6.2-py3.4.egg/pymysql/cursors.py", line 271, in _query conn.query(q) File "/usr/lib/python3.4/site-packages/PyMySQL-0.6.2-py3.4.egg/pymysql/connections.py", line 744, in query self._affected_rows = self._read_query_result(unbuffered=unbuffered) File "/usr/lib/python3.4/site-packages/PyMySQL-0.6.2-py3.4.egg/pymysql/connections.py", line 879, in _read_query_result result.read() File "/usr/lib/python3.4/site-packages/PyMySQL-0.6.2-py3.4.egg/pymysql/connections.py", line 1082, in read first_packet = self.connection._read_packet() File "/usr/lib/python3.4/site-packages/PyMySQL-0.6.2-py3.4.egg/pymysql/connections.py", line 844, in _read_packet packet.check_error() File "/usr/lib/python3.4/site-packages/PyMySQL-0.6.2-py3.4.egg/pymysql/connections.py", line 370, in check_error raise_mysql_exception(self._data) File "/usr/lib/python3.4/site-packages/PyMySQL-0.6.2-py3.4.egg/pymysql/err.py", line 116, in raise_mysql_exception _check_mysql_exception(errinfo) File "/usr/lib/python3.4/site-packages/PyMySQL-0.6.2-py3.4.egg/pymysql/err.py", line 112, in _check_mysql_exception raise InternalError(errno, errorvalue) pymysql.err.InternalError: (1054, "Unknown column 't1.customer_id' in 'field list'") During handling of the above exception, another exception occurred: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python3.4/site-packages/peewee-2.2.4-py3.4.egg/peewee.py", line 2139, in __iter__ File "/usr/lib/python3.4/site-packages/peewee-2.2.4-py3.4.egg/peewee.py", line 2132, in execute File "/usr/lib/python3.4/site-packages/peewee-2.2.4-py3.4.egg/peewee.py", line 1838, in _execute File "/usr/lib/python3.4/site-packages/peewee-2.2.4-py3.4.egg/peewee.py", line 2414, in execute_sql File "/usr/lib/python3.4/site-packages/peewee-2.2.4-py3.4.egg/peewee.py", line 2283, in __exit__ File "/usr/lib/python3.4/site-packages/peewee-2.2.4-py3.4.egg/peewee.py", line 105, in reraise File "/usr/lib/python3.4/site-packages/peewee-2.2.4-py3.4.egg/peewee.py", line 2406, in execute_sql File "/usr/lib/python3.4/site-packages/PyMySQL-0.6.2-py3.4.egg/pymysql/cursors.py", line 132, in execute result = self._query(query) File "/usr/lib/python3.4/site-packages/PyMySQL-0.6.2-py3.4.egg/pymysql/cursors.py", line 271, in _query conn.query(q) File "/usr/lib/python3.4/site-packages/PyMySQL-0.6.2-py3.4.egg/pymysql/connections.py", line 744, in query self._affected_rows = self._read_query_result(unbuffered=unbuffered) File "/usr/lib/python3.4/site-packages/PyMySQL-0.6.2-py3.4.egg/pymysql/connections.py", line 879, in _read_query_result result.read() File "/usr/lib/python3.4/site-packages/PyMySQL-0.6.2-py3.4.egg/pymysql/connections.py", line 1082, in read first_packet = self.connection._read_packet() File "/usr/lib/python3.4/site-packages/PyMySQL-0.6.2-py3.4.egg/pymysql/connections.py", line 844, in _read_packet packet.check_error() File "/usr/lib/python3.4/site-packages/PyMySQL-0.6.2-py3.4.egg/pymysql/connections.py", line 370, in check_error raise_mysql_exception(self._data) File "/usr/lib/python3.4/site-packages/PyMySQL-0.6.2-py3.4.egg/pymysql/err.py", line 116, in raise_mysql_exception _check_mysql_exception(errinfo) File "/usr/lib/python3.4/site-packages/PyMySQL-0.6.2-py3.4.egg/pymysql/err.py", line 112, in _check_mysql_exception raise InternalError(errno, errorvalue) peewee.InternalError: (1054, "Unknown column 't1.customer_id' in 'field list'") ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/445/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/445/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/444
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/444/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/444/comments
https://api.github.com/repos/coleifer/peewee/issues/444/events
https://github.com/coleifer/peewee/pull/444
45,199,411
MDExOlB1bGxSZXF1ZXN0MjIzOTg3Nzg=
444
Add in detection of closed connections in the pool
{ "login": "alexlatchford", "id": 628146, "node_id": "MDQ6VXNlcjYyODE0Ng==", "avatar_url": "https://avatars.githubusercontent.com/u/628146?v=4", "gravatar_id": "", "url": "https://api.github.com/users/alexlatchford", "html_url": "https://github.com/alexlatchford", "followers_url": "https://api.github.com/users/alexlatchford/followers", "following_url": "https://api.github.com/users/alexlatchford/following{/other_user}", "gists_url": "https://api.github.com/users/alexlatchford/gists{/gist_id}", "starred_url": "https://api.github.com/users/alexlatchford/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/alexlatchford/subscriptions", "organizations_url": "https://api.github.com/users/alexlatchford/orgs", "repos_url": "https://api.github.com/users/alexlatchford/repos", "events_url": "https://api.github.com/users/alexlatchford/events{/privacy}", "received_events_url": "https://api.github.com/users/alexlatchford/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Since this is not implemented for MySQL I will pass on merging it as-is, but I'll think about how this might work as it seems like a valid issue.\n", "Awesome, cheers Charles. I'll take another look into MySQL tomorrow to see what I can do from my end. Would be great to close this bug from my perspective :)\n", "Did you have any thoughts about how to develop this? I'm willing to lend a hand but don't want to go in the wrong direction if this approach isn't what you're thinking.\n", "I added a hook method which I believe should make it easy for you to implement your changes: ad50a51f9fa8669b8611964878d1ad0d87aa710e\n\nJust subclass and override the `_is_closed()` method.\n", "Awesome that works for me, one problem is that I need to use the `conn` itself within _is_closed, can you add that as a param to the definition please. I just checked and there is no sane way of going from the `id()` of an object to the object itself in python :)\n", "Fixed in d442a92309c0ec437c18aa92293fe256933b4cf8\n" ]
2014-10-08T03:27:15
2014-10-22T16:39:23
2014-10-22T03:38:33
CONTRIBUTOR
null
Hi Charles, I've got a little problem with connection pooling, it works great up until the point I have to kill a hanging postgres query or stop the database service. Any requests on that same connection get an `InterfaceError: connection already closed` from the psycopg2 library because it successfully retrieves a connection from `_connect`. The problem is that the connection pool is only aware of connections killed by the application and not the database server itself. This pull is my attempt to monkey patch a solution for postgres, I had a brief look into the MySQLdb and pymysql docs to try to also get a good solution for that but fell short so thought I'd pass it over to you to see what you thought. Other than this minor problem, (which can be fixed by restarting the webserver, thus flushing the connection pool), this module has been running really well for me in testing, thanks again :) Cheers, Alex
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/444/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/444/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/444", "html_url": "https://github.com/coleifer/peewee/pull/444", "diff_url": "https://github.com/coleifer/peewee/pull/444.diff", "patch_url": "https://github.com/coleifer/peewee/pull/444.patch", "merged_at": null }
https://api.github.com/repos/coleifer/peewee/issues/443
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/443/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/443/comments
https://api.github.com/repos/coleifer/peewee/issues/443/events
https://github.com/coleifer/peewee/issues/443
45,177,715
MDU6SXNzdWU0NTE3NzcxNQ==
443
Model without auto increment primary key is not saved without force_insert=True
{ "login": "ElvisTheKing", "id": 384889, "node_id": "MDQ6VXNlcjM4NDg4OQ==", "avatar_url": "https://avatars.githubusercontent.com/u/384889?v=4", "gravatar_id": "", "url": "https://api.github.com/users/ElvisTheKing", "html_url": "https://github.com/ElvisTheKing", "followers_url": "https://api.github.com/users/ElvisTheKing/followers", "following_url": "https://api.github.com/users/ElvisTheKing/following{/other_user}", "gists_url": "https://api.github.com/users/ElvisTheKing/gists{/gist_id}", "starred_url": "https://api.github.com/users/ElvisTheKing/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/ElvisTheKing/subscriptions", "organizations_url": "https://api.github.com/users/ElvisTheKing/orgs", "repos_url": "https://api.github.com/users/ElvisTheKing/repos", "events_url": "https://api.github.com/users/ElvisTheKing/events{/privacy}", "received_events_url": "https://api.github.com/users/ElvisTheKing/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "This is known and documented behavior: http://docs.peewee-orm.com/en/latest/peewee/models.html#id3\n\nYou can always implement a custom method to perform this query if you are using MySQL (or create a mysql_ext module for the playhouse).\n\nIn the events where I've needed \"get object or create if it does not exist\" I've used something like this: http://docs.peewee-orm.com/en/latest/peewee/querying.html#get-or-create\n\nI believe you could repurpose that code to attempt to INSERT then UPDATE on IntegrityError:\n\n``` python\ntry:\n with db.transaction():\n SomeModel.insert(pk_val=primary_key, other_val=something_else).execute()\nexcept peewee.IntegrityError:\n with db.transaction():\n SomeModel.update(other_val=something_else).where(\n SomeModel.pk_val == primary_key).execute()\n```\n", "While not being exactly what you asked for, hopefully the helpers in 073364a prove useful to you as building blocks.\n", "@coleifer Could you explain why this commit was reverted shortly after? The docs state that \"create or get\" should be used instead of `create_or_get`, but only the latter seems to be supported in code.\n\nOne small issue I did notice with the code example, it relies on `IntegrityError` but doesn't check if the error was caused by a unique constraint, potentially causing `get` fallback on the wrong condition.\n", "Ugh, I wish I can remember... I think I decided maybe just to keep stuff like that for the application layer developers rather than library code.\n", "I think `create_or_get()` functionality still has a place within the core, but could be difficult to implement properly due to #639, and would require string comparison (due to missing error code on py3.4), which is a bit dirty.\n\nThe documentation recommends that \"create or get\" is better than `get_or_create`, but doesn't offer any ability to implement it in a clean fashion (due to missing error code), or any out of the box solution since this commit was reversed. The examples show that catching `IntegrityError` is enough, but this could lead to surprising results (e.g. an error occurs which is unrelated to unique constraints, but still raises `IntegrityError`, the except block then tries to fetch a row that doesn't exist).\n\nAlthough I concur that `create_or_get` is far superior to `get_or_create`, we're perhaps not making it easy for people to adopt this correct approach, and the recommended documentation could lead to surprising behaviour if error codes are not checked. Or perhaps I'm thinking into it too much :)\n\nDo you think it's worth re-visiting or should be left as is?\n", "Yeah, reopening. Good points for sure.\n", "Just FYI, my wife and I had our first baby a few days ago so I'm going to be kinda AWOL for a while.\n", "Congratulations! I'll do some testing and submit an updated proposal, might be a few weeks though as I'll have to test each database etc.\n", "Added create/get in\n- be32fac431e75a1d9e5e0d06bcd0c9ff85a76b51 \n- 4566c0d494d54a1a2d5e8b3a16ea2673b236f5af\n", "LGTM. How would you feel about adding an additional check against the error code of `exc.args[0]` (to ensure it got a unique constraint error) of supported databases? I'm happy to submit a fully tested PR for this if needed.\n", "I think I will pass on that for now, seems like a bit of a can of worms. If you do want your app to check for a specific error, you may just add your own implementation of `create_or_get`. FWIW, the semantics here are similar to Django, so that's why I'm OK with it.\n", "This is really a weird behavior, comparing with all other ORM I have used." ]
2014-10-07T22:19:00
2018-05-17T05:04:30
2015-06-27T23:08:28
NONE
null
Model save() method is implemented in such a way that it only use insert statement if primary key is null, which is correct only if primary key is auto increment or sequence field. for example ``` class Object(BaseModel): uuid = CharField(primary_key=True) object = Object(uuid="some-text-uuid") object.save() #returns 0 ``` save issues an update statement, which obviously updates zero rows I think insert should be implemented using "INSERT ... ON DUPLICATE KEY UPDATE" for mysql and sequential UPDATE-INSERT for sqlite and postgress (not really sure about these two)
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/443/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/443/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/442
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/442/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/442/comments
https://api.github.com/repos/coleifer/peewee/issues/442/events
https://github.com/coleifer/peewee/issues/442
44,967,547
MDU6SXNzdWU0NDk2NzU0Nw==
442
Cross database join
{ "login": "RealJTG", "id": 930399, "node_id": "MDQ6VXNlcjkzMDM5OQ==", "avatar_url": "https://avatars.githubusercontent.com/u/930399?v=4", "gravatar_id": "", "url": "https://api.github.com/users/RealJTG", "html_url": "https://github.com/RealJTG", "followers_url": "https://api.github.com/users/RealJTG/followers", "following_url": "https://api.github.com/users/RealJTG/following{/other_user}", "gists_url": "https://api.github.com/users/RealJTG/gists{/gist_id}", "starred_url": "https://api.github.com/users/RealJTG/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/RealJTG/subscriptions", "organizations_url": "https://api.github.com/users/RealJTG/orgs", "repos_url": "https://api.github.com/users/RealJTG/repos", "events_url": "https://api.github.com/users/RealJTG/events{/privacy}", "received_events_url": "https://api.github.com/users/RealJTG/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Interesting. Peewee does not support this out of the box, so your best option right now is to probably use the `RawQuery` helper ([docs](http://docs.peewee-orm.com/en/latest/peewee/api.html#RawQuery)).\n\nAnother option is to take a look at how the `PostgresqlDatabase` supports a \"schema\" argument. The schema is only used to prefix table and column names, so maybe it could be repurposed to prefix with the database name instead?\n", "`schema` seems to work fine. I'm using flask-peewee and my DB class now looks like this (with delayed initialization https://github.com/coleifer/flask-peewee/pull/154 and multiple configurations support)\n\n``` python\nclass SchemaProxy(object):\n __slots__ = ['obj']\n\n def __init__(self):\n self.initialize(None)\n\n def initialize(self, obj):\n self.obj = obj\n\n def __str__(self):\n return self.obj or None\n\n\nclass ConfigurableDatabase(Database):\n\n def __init__(self, app=None, config_key='DATABASE'):\n self.config_key = config_key\n self.schema = SchemaProxy()\n super(ConfigurableDatabase, self).__init__(app)\n\n def load_database(self):\n self.database_config = dict(self.app.config[self.config_key])\n try:\n self.database_name = self.database_config.pop('name')\n self.database_engine = self.database_config.pop('engine')\n self.schema.initialize(self.database_name)\n except KeyError:\n raise ImproperlyConfigured('Please specify a \"name\" and \"engine\" for your database')\n\n try:\n self.database_class = load_class(self.database_engine)\n assert issubclass(self.database_class, PeeweeDatabase)\n except ImportError:\n raise ImproperlyConfigured('Unable to import: \"%s\"' % self.database_engine)\n except AttributeError:\n raise ImproperlyConfigured('Database engine not found: \"%s\"' % self.database_engine)\n except AssertionError:\n raise ImproperlyConfigured('Database engine not a subclass of peewee.Database: \"%s\"' % self.database_engine)\n\n self.database = self.database_class(self.database_name, **self.database_config)\n\n def get_model_class(self):\n class BaseModel(Model):\n class Meta:\n database = self.proxy\n schema = self.schema\n\n return BaseModel\n```\n\nWith `werkzeug.local.LocalProxy` even cleaner, but not sure about side effects\n\n``` python\n\nclass ConfigurableDatabase(Database):\n\n def get_model_class(self):\n class BaseModel(Model):\n class Meta:\n database = self.proxy\n schema = LocalProxy(lambda: self.database_name)\n\n return BaseModel\n```\n", "Neat. I'm going to close as it sounds like your immediate issue is resolved. Please comment if this is not the case.\n" ]
2014-10-06T10:13:43
2014-10-07T14:21:13
2014-10-07T14:21:13
NONE
null
Is it possible to perform cross database join somehow on the same MySQL instance? For example: ``` SQL SELECT A.value, B.value FROM db1.foo A JOIN db2.bar B ON A.id = B.id ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/442/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/442/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/441
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/441/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/441/comments
https://api.github.com/repos/coleifer/peewee/issues/441/events
https://github.com/coleifer/peewee/pull/441
44,760,939
MDExOlB1bGxSZXF1ZXN0MjIxODMyMDQ=
441
Update README.rst
{ "login": "wwj718", "id": 3153878, "node_id": "MDQ6VXNlcjMxNTM4Nzg=", "avatar_url": "https://avatars.githubusercontent.com/u/3153878?v=4", "gravatar_id": "", "url": "https://api.github.com/users/wwj718", "html_url": "https://github.com/wwj718", "followers_url": "https://api.github.com/users/wwj718/followers", "following_url": "https://api.github.com/users/wwj718/following{/other_user}", "gists_url": "https://api.github.com/users/wwj718/gists{/gist_id}", "starred_url": "https://api.github.com/users/wwj718/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/wwj718/subscriptions", "organizations_url": "https://api.github.com/users/wwj718/orgs", "repos_url": "https://api.github.com/users/wwj718/repos", "events_url": "https://api.github.com/users/wwj718/events{/privacy}", "received_events_url": "https://api.github.com/users/wwj718/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Nice catch, thank you!\n", ":smile: \n" ]
2014-10-03T02:30:48
2014-10-03T12:15:15
2014-10-03T02:52:01
CONTRIBUTOR
null
import datetime
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/441/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/441/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/441", "html_url": "https://github.com/coleifer/peewee/pull/441", "diff_url": "https://github.com/coleifer/peewee/pull/441.diff", "patch_url": "https://github.com/coleifer/peewee/pull/441.patch", "merged_at": "2014-10-03T02:52:01" }
https://api.github.com/repos/coleifer/peewee/issues/440
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/440/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/440/comments
https://api.github.com/repos/coleifer/peewee/issues/440/events
https://github.com/coleifer/peewee/issues/440
44,759,584
MDU6SXNzdWU0NDc1OTU4NA==
440
What is the meaning of Model.dirty_fields?
{ "login": "ak4nv", "id": 73960, "node_id": "MDQ6VXNlcjczOTYw", "avatar_url": "https://avatars.githubusercontent.com/u/73960?v=4", "gravatar_id": "", "url": "https://api.github.com/users/ak4nv", "html_url": "https://github.com/ak4nv", "followers_url": "https://api.github.com/users/ak4nv/followers", "following_url": "https://api.github.com/users/ak4nv/following{/other_user}", "gists_url": "https://api.github.com/users/ak4nv/gists{/gist_id}", "starred_url": "https://api.github.com/users/ak4nv/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/ak4nv/subscriptions", "organizations_url": "https://api.github.com/users/ak4nv/orgs", "repos_url": "https://api.github.com/users/ak4nv/repos", "events_url": "https://api.github.com/users/ak4nv/events{/privacy}", "received_events_url": "https://api.github.com/users/ak4nv/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Looks like a bug -- the `dirty_fields` property should return an empty list for instances that are fetched from the database. Thanks for letting me know!\n", "Yeah, I read it in docs.\nI'll wait a bugfix. I need this functionality in my small project. :)\n" ]
2014-10-03T01:59:27
2014-10-03T15:54:57
2014-10-03T15:54:57
NONE
null
Just a code: ``` python >>> from blueprints.auth.models import User >>> user = User.get(User.id == 1) >>> user.dirty_fields [<peewee.PrimaryKeyField object at 0x7f8d2e948da0>, <peewee.CharField object at 0x7f8d2e9487b8>, <peewee.CharField object at 0x7f8d2e948a58>, <peewee.CharField object at 0x7f8d2e948898>, <peewee.CharField object at 0x7f8d2e948b00>, <peewee.CharField object at 0x7f8d2e948b38>, <peewee.CharField object at 0x7f8d2e948b70>, <peewee.ForeignKeyField object at 0x7f8d2e948ba8>, <peewee.DateTimeField object at 0x7f8d2e948be0>, <peewee.CharField object at 0x7f8d2e948c18>, <peewee.BooleanField object at 0x7f8d2e948c50>, <peewee.BooleanField object at 0x7f8d2e948c88>, <peewee.BooleanField object at 0x7f8d2e948cc0>] >>> ``` I expected to get an empty list. Am I wrong?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/440/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/440/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/439
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/439/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/439/comments
https://api.github.com/repos/coleifer/peewee/issues/439/events
https://github.com/coleifer/peewee/issues/439
44,606,553
MDU6SXNzdWU0NDYwNjU1Mw==
439
Writing under a select query iterator results in unexpected behavior
{ "login": "josephschorr", "id": 4073002, "node_id": "MDQ6VXNlcjQwNzMwMDI=", "avatar_url": "https://avatars.githubusercontent.com/u/4073002?v=4", "gravatar_id": "", "url": "https://api.github.com/users/josephschorr", "html_url": "https://github.com/josephschorr", "followers_url": "https://api.github.com/users/josephschorr/followers", "following_url": "https://api.github.com/users/josephschorr/following{/other_user}", "gists_url": "https://api.github.com/users/josephschorr/gists{/gist_id}", "starred_url": "https://api.github.com/users/josephschorr/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/josephschorr/subscriptions", "organizations_url": "https://api.github.com/users/josephschorr/orgs", "repos_url": "https://api.github.com/users/josephschorr/repos", "events_url": "https://api.github.com/users/josephschorr/events{/privacy}", "received_events_url": "https://api.github.com/users/josephschorr/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Note: The above code works fine when executed on a MySQL database.\n", "https://github.com/coleifer/peewee/issues/12#issuecomment-5614404\n\nAnd #109 and #327 and #388 and #437.\n\nPerhaps I need to add this very clearly to the docs?\n", "Might help, but I think it would best to raise an exception if we can detect this case, since the code does work with other engines and it is non-obvious that switching engines can break it.\n\nInterestingly enough, the code did work with peewee 1.0.0.\n", "Added 613aa2025f4faa6ccfdc40c79766b24ff1cc731d which documents the behavior.\n" ]
2014-10-01T19:41:51
2014-10-02T02:35:30
2014-10-02T02:35:30
NONE
null
I'm seeing very odd behavior as a result of a loop over a select query which creates rows in another table. ``` from peewee import Model, SqliteDatabase, CharField, ForeignKeyField, create_model_tables db = SqliteDatabase(':memory:') class Person(Model): name = CharField() gender = CharField() class Meta: database = db class Creature(Model): name = CharField(default='acreature') class Meta: database = db create_model_tables([Person, Creature]) Person.create(name = 'Bob', gender = 'M') Person.create(name = 'James', gender = 'M') Person.create(name = 'Jesse', gender = 'M') Person.create(name = 'Alice', gender = 'F') Person.create(name = 'Kate', gender = 'F') Person.create(name = 'Alex', gender = 'F') print "List: %s" % list(Person.select().where(Person.gender == 'M')) print '' print "Expected (with list):" for person in list(Person.select().where(Person.gender == 'M')): print person.name Creature.create(name = person.name + "'s pet") print '' print "Broken (without list):" for person in Person.select().where(Person.gender == 'M'): print person.name Creature.create(name = person.name + "'s pet") print '' print "Causes exception:" print list(Person.select().where(Person.gender == 'M')) ``` Output: ``` List: [<__main__.Person object at 0x104ece950>, <__main__.Person object at 0x104ecec10>, <__main__.Person object at 0x104ecea50>] Expected (with list): Bob James Jesse Broken (without list): Bob James Bob James Jesse Causes exception: Traceback (most recent call last): File "repro.py", line 38, in <module> print list(Person.select().where(Person.gender == 'M')) File "/Library/Python/2.7/site-packages/peewee.py", line 2466, in __iter__ return iter(self.execute()) File "/Library/Python/2.7/site-packages/peewee.py", line 2459, in execute self._qr = ResultWrapper(model_class, self._execute(), query_meta) File "/Library/Python/2.7/site-packages/peewee.py", line 2155, in _execute return self.database.execute_sql(sql, params, self.require_commit) File "/Library/Python/2.7/site-packages/peewee.py", line 2760, in execute_sql self.commit() File "/Library/Python/2.7/site-packages/peewee.py", line 2629, in __exit__ reraise(new_type, new_type(*exc_value.args), traceback) File "/Library/Python/2.7/site-packages/peewee.py", line 2752, in execute_sql cursor.execute(sql, params or ()) peewee.InterfaceError: Error binding parameter 0 - probably unsupported type. ``` As seen above, if we loop over a `select` wrapped in a `list`, then the three rows are returned as expected. If, however, we try to loop over the `select` directly, we encounter the first two rows twice (!) and then any subsequent calls to retrieve the full list of the query results in a SQL exception.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/439/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/439/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/438
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/438/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/438/comments
https://api.github.com/repos/coleifer/peewee/issues/438/events
https://github.com/coleifer/peewee/issues/438
43,814,907
MDU6SXNzdWU0MzgxNDkwNw==
438
Order of join clause with alias join and select can lead to invalid configurations
{ "login": "jakedt", "id": 2183986, "node_id": "MDQ6VXNlcjIxODM5ODY=", "avatar_url": "https://avatars.githubusercontent.com/u/2183986?v=4", "gravatar_id": "", "url": "https://api.github.com/users/jakedt", "html_url": "https://github.com/jakedt", "followers_url": "https://api.github.com/users/jakedt/followers", "following_url": "https://api.github.com/users/jakedt/following{/other_user}", "gists_url": "https://api.github.com/users/jakedt/gists{/gist_id}", "starred_url": "https://api.github.com/users/jakedt/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/jakedt/subscriptions", "organizations_url": "https://api.github.com/users/jakedt/orgs", "repos_url": "https://api.github.com/users/jakedt/repos", "events_url": "https://api.github.com/users/jakedt/events{/privacy}", "received_events_url": "https://api.github.com/users/jakedt/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Thanks for sharing some code to reproduce this!\n", "Basically what peewee is trying to figure out is how to patch the joined instance (`PersonAlias`, which is actually a `Person`) onto `RelatesToPerson` given the join predicate. There's some special-casing around aliases and expressions -- I think there are some undiscovered bugs in the relevant block of code. I'm working on a complete refactor to hopefully clean this up and make the behavior more predictable.\n", "I've got things partially fixed in 55373892a7454052c54a5b8bc9ba7d9da72aeeb2\n", "I believe this is now fixed.\n" ]
2014-09-24T21:04:31
2014-09-27T09:34:07
2014-09-27T09:34:07
NONE
null
I'm not sure how to describe the problem accurately, so here is a repro case: ``` python from peewee import Model, SqliteDatabase, CharField, ForeignKeyField, create_model_tables db = SqliteDatabase(':memory:') class Person(Model): name = CharField(default='aperson') class Meta: database = db class RelatesToPerson(Model): name = CharField(default='arelationship') person = ForeignKeyField(Person) class Meta: database = db create_model_tables([Person, RelatesToPerson]) PersonAlias = Person.alias() a_person = Person.create() RelatesToPerson.create(person=a_person) print str(RelatesToPerson .select(RelatesToPerson, PersonAlias) .join(PersonAlias, on=(PersonAlias.id == RelatesToPerson.person)) .get().id) + " <- an instance!" print (RelatesToPerson .select(RelatesToPerson, PersonAlias) .join(PersonAlias, on=(RelatesToPerson.person == PersonAlias.id)) .get().id) ``` output ``` bash $ python repro.py <__main__.Person object at 0x10b201c50> <- an instance! 1 ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/438/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/438/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/437
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/437/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/437/comments
https://api.github.com/repos/coleifer/peewee/issues/437/events
https://github.com/coleifer/peewee/issues/437
43,270,829
MDU6SXNzdWU0MzI3MDgyOQ==
437
Query iteration bug?
{ "login": "frdfsnlght", "id": 417767, "node_id": "MDQ6VXNlcjQxNzc2Nw==", "avatar_url": "https://avatars.githubusercontent.com/u/417767?v=4", "gravatar_id": "", "url": "https://api.github.com/users/frdfsnlght", "html_url": "https://github.com/frdfsnlght", "followers_url": "https://api.github.com/users/frdfsnlght/followers", "following_url": "https://api.github.com/users/frdfsnlght/following{/other_user}", "gists_url": "https://api.github.com/users/frdfsnlght/gists{/gist_id}", "starred_url": "https://api.github.com/users/frdfsnlght/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/frdfsnlght/subscriptions", "organizations_url": "https://api.github.com/users/frdfsnlght/orgs", "repos_url": "https://api.github.com/users/frdfsnlght/repos", "events_url": "https://api.github.com/users/frdfsnlght/events{/privacy}", "received_events_url": "https://api.github.com/users/frdfsnlght/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Check out:\n- https://github.com/coleifer/peewee/issues/12#issuecomment-5614404\n- https://github.com/coleifer/peewee/issues/81\n" ]
2014-09-19T18:57:40
2014-10-01T20:16:47
2014-09-19T19:00:31
NONE
null
``` python from peewee import * from datetime import datetime db = SqliteDatabase('test.db') class A(Model): id = PrimaryKeyField() date = DateTimeField() class Meta: database = db A.create_table(fail_silently = True); if not A.select().count(): A(date = datetime.now()).save() A(date = datetime.now()).save() print('%d records' % A.select().count()) count = 0; for a in A.select(): count += 1 print('%d: %d' % (count, a.id)) a.save() ``` Output: ``` >python test.py 2 records 1: 1 2: 2 3: 1 4: 2 ``` Python 2.7.8 (default, Jun 30 2014, 16:03:49) [MSC v.1500 32 bit (Intel)] on win32 If I comment the line "a.save()", it iterates only twice, as I would expect. Am I doing something wrong?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/437/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/437/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/436
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/436/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/436/comments
https://api.github.com/repos/coleifer/peewee/issues/436/events
https://github.com/coleifer/peewee/issues/436
43,212,512
MDU6SXNzdWU0MzIxMjUxMg==
436
Query bug
{ "login": "ak4nv", "id": 73960, "node_id": "MDQ6VXNlcjczOTYw", "avatar_url": "https://avatars.githubusercontent.com/u/73960?v=4", "gravatar_id": "", "url": "https://api.github.com/users/ak4nv", "html_url": "https://github.com/ak4nv", "followers_url": "https://api.github.com/users/ak4nv/followers", "following_url": "https://api.github.com/users/ak4nv/following{/other_user}", "gists_url": "https://api.github.com/users/ak4nv/gists{/gist_id}", "starred_url": "https://api.github.com/users/ak4nv/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/ak4nv/subscriptions", "organizations_url": "https://api.github.com/users/ak4nv/orgs", "repos_url": "https://api.github.com/users/ak4nv/repos", "events_url": "https://api.github.com/users/ak4nv/events{/privacy}", "received_events_url": "https://api.github.com/users/ak4nv/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "First of all, your use of the python `and` keyword is incorrect -- see [query operators table](http://docs.peewee-orm.com/en/latest/peewee/querying.html#query-operators), particularly the section on logical operators.\n\nAs to the other examples, I will take a look. Your final query (using `&`) looks like it should work but I'm surprised the chained calls to .where do not since those should be equivalent.\n", "> > peewee.OperationalError: user-defined function raised exception\n\nIs it possible that in the first query you have a `None` value in the `deadline` column? I wonder if SQLite is running that filter first in the query that's failing, and it succeeds in the other examples because the result-set has already been filtered.\n", "> Is it possible that in the first query you have a None value in the deadline column? \n\nBingo!\nMy apologies. :)\n", "Fixed in ffbfb9c024d5a63e895888b7f6eee46ad7f39b4b\n" ]
2014-09-19T07:36:16
2014-09-24T11:39:15
2014-09-24T11:39:15
NONE
null
``` python tasks = Task.select()\ .where(Task.deadline.year == year)\ .where(Task.performer << performers)\ .where(Task.state << (States.ACCEPTED, States.CLOSED)) ``` peewee.OperationalError: user-defined function raised exception ``` python tasks = Task.select()\ .where(Task.performer << performers)\ .where(Task.state << (States.ACCEPTED, States.CLOSED))\ .where(Task.deadline.year == year) ``` works fine Also ``` python tasks = Task.select().where( (Task.performer << performers) and (Task.state << (States.ACCEPTED, States.CLOSED)) and (Task.deadline == year) ) print(tasks) ``` result ``` <class 'tm.tasks.models.Task'> SELECT "t1"."id", "t1"."title", "t1"."task_type", "t1"."desc", "t1"."deadline", "t1"."customer_id", "t1"."performer_id", "t1"."related_proj_id", "t1"."related_task_id", "t1"."state" FROM "tasks" AS t1 WHERE ("t1"."deadline" = ?) ORDER BY "t1"."id" DESC [2014] ``` and ``` python tasks = Task.select().where( (Task.performer << performers) & (Task.state << (States.ACCEPTED, States.CLOSED)) & (Task.deadline == year) ) print(tasks) ``` result ``` <class 'tm.tasks.models.Task'> SELECT "t1"."id", "t1"."title", "t1"."task_type", "t1"."desc", "t1"."deadline", "t1"."customer_id", "t1"."performer_id", "t1"."related_proj_id", "t1"."related_task_id", "t1"."state" FROM "tasks" AS t1 WHERE ((("t1"."performer_id" IN (SELECT "t2"."id" FROM "users" AS t2 WHERE ("t2"."group_id" = ?))) AND ("t1"."state" IN (?, ?))) AND ("t1"."deadline" = ?)) ORDER BY "t1"."id" DESC [1, 'accepted', 'closed', 2014] ``` Python 3.4 Flask 0.10.1 peewee 2.3.2 psycopg2 2.5.4
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/436/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/436/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/435
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/435/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/435/comments
https://api.github.com/repos/coleifer/peewee/issues/435/events
https://github.com/coleifer/peewee/issues/435
43,134,965
MDU6SXNzdWU0MzEzNDk2NQ==
435
Peewee gives error in combination with Flask-login
{ "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
[ "Peewee models implement a `get_id()` method, which is used by the `pk_expr()` method. I am guessing that is the source of the issue.\n" ]
2014-09-18T13:52:20
2014-09-18T18:15:18
2014-09-18T18:15:18
NONE
null
I'm trying to use peewee in combination with Flask-login, and I now get into trouble when implementing the `get_id()` method. The User class I have is as follows: ``` class User(db.Model, BaseUser): username = CharField() password = CharField() def is_authenticated(self): return True def is_active(self): return True def is_anonymous(self): return False def get_id(self): return unicode(self.id) ``` When trying to save a user to the (sqlite) DB, I get the following error: ``` >>> from app.models import User >>> u = User() >>> u.username = 'lala' >>> u.password = 'blabla' >>> u.save() Traceback (most recent call last): File "<input>", line 1, in <module> File "/Library/Python/2.7/site-packages/peewee.py", line 3488, in save rows = self.update(**field_dict).where(self.pk_expr()).execute() File "/Library/Python/2.7/site-packages/peewee.py", line 2487, in execute return self.database.rows_affected(self._execute()) File "/Library/Python/2.7/site-packages/peewee.py", line 2119, in _execute sql, params = self.sql() File "/Library/Python/2.7/site-packages/peewee.py", line 2484, in sql return self.compiler().generate_update(self) File "/Library/Python/2.7/site-packages/peewee.py", line 1482, in generate_update return self.build_query(clauses, alias_map) File "/Library/Python/2.7/site-packages/peewee.py", line 1357, in build_query return self.parse_node(Clause(*clauses), alias_map) File "/Library/Python/2.7/site-packages/peewee.py", line 1318, in parse_node sql, params, unknown = self._parse(node, alias_map, conv) File "/Library/Python/2.7/site-packages/peewee.py", line 1293, in _parse sql, params = self._parse_map[node_type](node, alias_map, conv) File "/Library/Python/2.7/site-packages/peewee.py", line 1246, in _parse_clause node.nodes, alias_map, conv, node.glue) File "/Library/Python/2.7/site-packages/peewee.py", line 1335, in parse_node_list node_sql, node_params = self.parse_node(node, alias_map, conv) File "/Library/Python/2.7/site-packages/peewee.py", line 1318, in parse_node sql, params, unknown = self._parse(node, alias_map, conv) File "/Library/Python/2.7/site-packages/peewee.py", line 1293, in _parse sql, params = self._parse_map[node_type](node, alias_map, conv) File "/Library/Python/2.7/site-packages/peewee.py", line 1227, in _parse_expression rhs, rparams = self.parse_node(node.rhs, alias_map, conv) File "/Library/Python/2.7/site-packages/peewee.py", line 1320, in parse_node params = [conv.db_value(i) for i in params] File "/Library/Python/2.7/site-packages/peewee.py", line 674, in db_value return value if value is None else self.coerce(value) ValueError: invalid literal for int() with base 10: 'None' ``` If I remove the `get_id()` method I get no error, so that method seems to be the source of evil. Would anybody know whats wrong with it? All tips are welcome!
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/435/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/435/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/434
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/434/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/434/comments
https://api.github.com/repos/coleifer/peewee/issues/434/events
https://github.com/coleifer/peewee/issues/434
43,124,600
MDU6SXNzdWU0MzEyNDYwMA==
434
Integration with mongodb?
{ "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 you'll find that its better to use an existing library. Or be prepared to do a really close reading of the source code!\n", "Basically you're going to be dealing with replacing the database classes and the query compiler. The model and field semantics are probably different as well. Please comment if you'd like to discuss more, but frankly I think you're barking up the wrong tree.\n" ]
2014-09-18T11:59:29
2014-09-18T21:14:43
2014-09-18T21:14:43
NONE
null
I'm using Peewee in more and more projects now, but I'm currently working on a project in which we need to use MongoDB. Is there a way that I can make Peewee work with MongoDB? All tips are welcome!
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/434/reactions", "total_count": 2, "+1": 2, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/434/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/433
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/433/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/433/comments
https://api.github.com/repos/coleifer/peewee/issues/433/events
https://github.com/coleifer/peewee/issues/433
43,117,972
MDU6SXNzdWU0MzExNzk3Mg==
433
Using Peewee with Twisted
{ "login": "fikisipi", "id": 8115972, "node_id": "MDQ6VXNlcjgxMTU5NzI=", "avatar_url": "https://avatars.githubusercontent.com/u/8115972?v=4", "gravatar_id": "", "url": "https://api.github.com/users/fikisipi", "html_url": "https://github.com/fikisipi", "followers_url": "https://api.github.com/users/fikisipi/followers", "following_url": "https://api.github.com/users/fikisipi/following{/other_user}", "gists_url": "https://api.github.com/users/fikisipi/gists{/gist_id}", "starred_url": "https://api.github.com/users/fikisipi/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/fikisipi/subscriptions", "organizations_url": "https://api.github.com/users/fikisipi/orgs", "repos_url": "https://api.github.com/users/fikisipi/repos", "events_url": "https://api.github.com/users/fikisipi/events{/privacy}", "received_events_url": "https://api.github.com/users/fikisipi/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I have no plans to support twisted but I'd accept s pull request for a playhouse module. If you're interested, I'd start here: \n\nhttp://docs.peewee-orm.com/en/latest/peewee/database.html#adding-a-new-database-driver\n" ]
2014-09-18T10:27:06
2014-09-18T21:07:50
2014-09-18T21:07:50
NONE
null
At the moment, there is no way to use peewee with async Twisted. Twisted handles database connections using [ConnectionPool](https://twistedmatrix.com/documents/14.0.0/api/twisted.enterprise.adbapi.ConnectionPool.html) ``` from twisted.enterprise import adbapi db= adbapi.ConnectionPool("MySQLdb", host = "", user = "", passwd = "", db = "") q = db.runQuery("CREATE TABLE test(msg VARCHAR(100))") q.addCallBack(asyncCallBackFunctionHere) ``` Would it be possible to have support for ConnectionPool? It has about 4 methods that are used to execute and return data.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/433/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/433/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/432
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/432/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/432/comments
https://api.github.com/repos/coleifer/peewee/issues/432/events
https://github.com/coleifer/peewee/issues/432
42,946,454
MDU6SXNzdWU0Mjk0NjQ1NA==
432
hstore extension is required to initialise a postgresql database
{ "login": "alexlatchford", "id": 628146, "node_id": "MDQ6VXNlcjYyODE0Ng==", "avatar_url": "https://avatars.githubusercontent.com/u/628146?v=4", "gravatar_id": "", "url": "https://api.github.com/users/alexlatchford", "html_url": "https://github.com/alexlatchford", "followers_url": "https://api.github.com/users/alexlatchford/followers", "following_url": "https://api.github.com/users/alexlatchford/following{/other_user}", "gists_url": "https://api.github.com/users/alexlatchford/gists{/gist_id}", "starred_url": "https://api.github.com/users/alexlatchford/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/alexlatchford/subscriptions", "organizations_url": "https://api.github.com/users/alexlatchford/orgs", "repos_url": "https://api.github.com/users/alexlatchford/repos", "events_url": "https://api.github.com/users/alexlatchford/events{/privacy}", "received_events_url": "https://api.github.com/users/alexlatchford/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I'm not really sure what to do here -- it's kind of on the database user to install the extension if they want to use it.\n", "The point is I don't want to use it, it's forcing me to install it to use peewee.\n", "Oh, I see.\n", "I've added a `register_hstore` parameter to `PostgresqlExtDatabase`. The default is `True` to avoid breaking backwards compatibility.\n" ]
2014-09-16T23:35:13
2019-06-18T19:51:15
2014-09-17T03:54:14
CONTRIBUTOR
null
I've been meaning to write this one up for a while.. I've just installed the extension every time to avoid this one :) ``` Traceback (most recent call last): File "peewee_bug.py", line 22, in <module> MyModel.create_table() File "/Users/alexlatchford/Code/peewee/peewee.py", line 3423, in create_table db.create_table(cls) File "/Users/alexlatchford/Code/peewee/peewee.py", line 2788, in create_table return self.execute_sql(*qc.create_table(model_class, safe)) File "/Users/alexlatchford/Code/peewee/playhouse/postgres_ext.py", line 288, in execute_sql self.commit() File "/Users/alexlatchford/Code/peewee/peewee.py", line 2600, in __exit__ reraise(new_type, new_type(*exc_value.args), traceback) File "/Users/alexlatchford/Code/peewee/playhouse/postgres_ext.py", line 279, in execute_sql cursor = self.get_cursor() File "/Users/alexlatchford/Code/peewee/playhouse/postgres_ext.py", line 266, in get_cursor return self.get_conn().cursor(name=name) File "/Users/alexlatchford/Code/peewee/peewee.py", line 2680, in get_conn self.connect() File "/Users/alexlatchford/Code/peewee/peewee.py", line 2667, in connect self.__local.closed = False File "/Users/alexlatchford/Code/peewee/peewee.py", line 2600, in __exit__ reraise(new_type, new_type(*exc_value.args), traceback) File "/Users/alexlatchford/Code/peewee/peewee.py", line 2666, in connect **self.connect_kwargs) File "/Users/alexlatchford/Code/peewee/playhouse/postgres_ext.py", line 293, in _connect register_hstore(conn, globally=True) File "/Library/Python/2.7/site-packages/psycopg2/extras.py", line 775, in register_hstore "hstore type not found in the database. " peewee.ProgrammingError: hstore type not found in the database. please install it from your 'contrib/hstore.sql' file ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/432/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/432/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/431
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/431/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/431/comments
https://api.github.com/repos/coleifer/peewee/issues/431/events
https://github.com/coleifer/peewee/issues/431
42,886,748
MDU6SXNzdWU0Mjg4Njc0OA==
431
Iterating over big dataset
{ "login": "demongoo", "id": 941459, "node_id": "MDQ6VXNlcjk0MTQ1OQ==", "avatar_url": "https://avatars.githubusercontent.com/u/941459?v=4", "gravatar_id": "", "url": "https://api.github.com/users/demongoo", "html_url": "https://github.com/demongoo", "followers_url": "https://api.github.com/users/demongoo/followers", "following_url": "https://api.github.com/users/demongoo/following{/other_user}", "gists_url": "https://api.github.com/users/demongoo/gists{/gist_id}", "starred_url": "https://api.github.com/users/demongoo/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/demongoo/subscriptions", "organizations_url": "https://api.github.com/users/demongoo/orgs", "repos_url": "https://api.github.com/users/demongoo/repos", "events_url": "https://api.github.com/users/demongoo/events{/privacy}", "received_events_url": "https://api.github.com/users/demongoo/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Normally peewee will cache result rows so that if you iterate, slice or index the result set multiple times you will not incur multiple queries. When you use `iterator()`, rows will not be cached.\n\nIt's still possible to run out of memory, depending on your database, because the rows are not streamed to the cursor but loaded all at once. What database are you using?\n", "I use mysql.\nBut why are rows loaded at once?\n", "> But why are rows loaded at once?\n\nYou'll have to look into the implementation of the python driver. My understanding is that the database loads the rows into memory and passes them to the cursor, rather than streaming them to the cursor.\n\nPeewee's `iterator()` behavior is covered by unit tests and I believe it to be working, so I am going to close this.\n", "> You'll have to look into the implementation of the python driver \r\n\r\nBy looking up the pymysql driver, is it possible to use the `fetchall_unbuffered()` when iterating large results?\r\n\r\n\r\nhttps://pymysql.readthedocs.io/en/latest/modules/cursors.html#pymysql.cursors.SSCursor.fetchall_unbuffered" ]
2014-09-16T14:16:31
2022-03-02T06:57:45
2014-09-16T16:40:40
NONE
null
I try to iterate result set: ``` for field1, field2 in query.tuples().iterator(): print .... ``` But it failes with 'out of memory' (script just gets killed by kernel), so, I see no difference in my case - either with iterator or without. I have there python 2.6 and peewee 2.3.2. I'm not familiar much with lazy loading in python, except generators, but how this supposed to work: https://github.com/coleifer/peewee/blob/master/peewee.py#L2439 ? In `execute` `self._qr` gets constructed anyway - so how can this save memory to allow coping with big dataset? Is it me missing something, or maybe obsolete python version or ...?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/431/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/431/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/430
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/430/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/430/comments
https://api.github.com/repos/coleifer/peewee/issues/430/events
https://github.com/coleifer/peewee/pull/430
42,834,293
MDExOlB1bGxSZXF1ZXN0MjEyNzA1NjA=
430
Cast to db_value for insert queries
{ "login": "alexlatchford", "id": 628146, "node_id": "MDQ6VXNlcjYyODE0Ng==", "avatar_url": "https://avatars.githubusercontent.com/u/628146?v=4", "gravatar_id": "", "url": "https://api.github.com/users/alexlatchford", "html_url": "https://github.com/alexlatchford", "followers_url": "https://api.github.com/users/alexlatchford/followers", "following_url": "https://api.github.com/users/alexlatchford/following{/other_user}", "gists_url": "https://api.github.com/users/alexlatchford/gists{/gist_id}", "starred_url": "https://api.github.com/users/alexlatchford/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/alexlatchford/subscriptions", "organizations_url": "https://api.github.com/users/alexlatchford/orgs", "repos_url": "https://api.github.com/users/alexlatchford/repos", "events_url": "https://api.github.com/users/alexlatchford/events{/privacy}", "received_events_url": "https://api.github.com/users/alexlatchford/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I thought I had commented on this, but looks like it did not get saved. At any rate, I believe that peewee should already be converting values using the associated field's `db_value`. If you take a look at `QueryCompiler.generate_insert`, you'll see this code:\n\n``` python\n for row_dict in query._iter_rows():\n if not have_fields:\n fields = sorted(\n row_dict.keys(), key=operator.attrgetter('_sort_key'))\n have_fields = True\n\n values = []\n for field in fields:\n value = row_dict[field]\n if not isinstance(value, (Node, Model)):\n value = Param(value, conv=field.db_value)\n values.append(value)\n\n value_clauses.append(EnclosedClause(*values))\n```\n\nEssentially, any values that are not `Node` or `Model` instances, will be parameterized. Additionally, the field's db_value method will be used to convert to the `Param`. In `QueryCompiler._parse_param`:\n\n``` python\n def _parse_param(self, node, alias_map, conv):\n if node.conv:\n params = [node.conv(node.value)]\n else:\n params = [node.value]\n return self.interpolation, params\n```\n\nCan you explain a bit more what problem you encountered?\n", "Whoops I think I wrote the example for another bug instead of this one. This was my initial attempt at monkey patching the other issue I reported yesterday (that you fixed properly!).\n\nI'll close this one and open a separate issue, sorry for time wasting, had a lot on my mind yesterday I guess.\n", "Good news is I just updated to the latest copy of master and played around with the example code above and cannot reproduce the bug so either my code is wrong or it's fixed already. Either way thanks a lot for investigating, great to get problems fixed so quickly!!\n" ]
2014-09-16T00:46:27
2014-09-16T23:38:53
2014-09-16T23:26:52
CONTRIBUTOR
null
I was getting problems with foreign key fields not being cast properly, looks like this is the solution. It's not well tested so you might want to have a play yourself before accepting. ``` python class MyModel(Model): uuid = UUIDField(primary_key=True) class MyRelatedModel(Model): name = CharField() my_model = ForeignKeyField(MyModel) my_model = MyModel.get(...) MyRelatedModel.select(MyRelatedModel.my_model == my_model) ``` Should output something similar to: ``` HTTP Traceback (most recent call last): File "/Library/Python/2.7/site-packages/cherrypy/_cprequest.py", line 656, in respond response.body = self.handler() File "/Library/Python/2.7/site-packages/cherrypy/lib/encoding.py", line 188, in __call__ self.body = self.oldhandler(*args, **kwargs) File "/Library/Python/2.7/site-packages/cherrypy/_cpdispatch.py", line 34, in __call__ return self.callable(*self.args, **self.kwargs) File "/Users/alexlatchford/Code/abbreviate/a8-product/a8_product/../a8_product/lib/auth_tools.py", line 11, in __ca return f(*args, **kwargs) File "/Users/alexlatchford/Code/abbreviate/a8-product/a8_product/../a8_product/routes/auth/signup.py", line 95, in POST NewsFilterKeyword.insert_many(news_filter_keywords).execute() File "/Users/alexlatchford/Code/peewee/peewee.py", line 2564, in execute return self.database.last_insert_id(self._execute(), self.model_class) File "/Users/alexlatchford/Code/peewee/peewee.py", line 2126, in _execute return self.database.execute_sql(sql, params, self.require_commit) File "/Users/alexlatchford/Code/peewee/playhouse/postgres_ext.py", line 289, in execute_sql self.commit() File "/Users/alexlatchford/Code/peewee/peewee.py", line 2600, in __exit__ reraise(new_type, new_type(*exc_value.args), traceback) File "/Users/alexlatchford/Code/peewee/playhouse/postgres_ext.py", line 282, in execute_sql res = cursor.execute(sql, params or ()) ProgrammingError: can't adapt type 'UUID' ``` Thanks, Alex
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/430/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/430/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/430", "html_url": "https://github.com/coleifer/peewee/pull/430", "diff_url": "https://github.com/coleifer/peewee/pull/430.diff", "patch_url": "https://github.com/coleifer/peewee/pull/430.patch", "merged_at": null }
https://api.github.com/repos/coleifer/peewee/issues/429
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/429/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/429/comments
https://api.github.com/repos/coleifer/peewee/issues/429/events
https://github.com/coleifer/peewee/issues/429
42,832,945
MDU6SXNzdWU0MjgzMjk0NQ==
429
UUID field is not instantiated multiple times for insert_many fields
{ "login": "alexlatchford", "id": 628146, "node_id": "MDQ6VXNlcjYyODE0Ng==", "avatar_url": "https://avatars.githubusercontent.com/u/628146?v=4", "gravatar_id": "", "url": "https://api.github.com/users/alexlatchford", "html_url": "https://github.com/alexlatchford", "followers_url": "https://api.github.com/users/alexlatchford/followers", "following_url": "https://api.github.com/users/alexlatchford/following{/other_user}", "gists_url": "https://api.github.com/users/alexlatchford/gists{/gist_id}", "starred_url": "https://api.github.com/users/alexlatchford/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/alexlatchford/subscriptions", "organizations_url": "https://api.github.com/users/alexlatchford/orgs", "repos_url": "https://api.github.com/users/alexlatchford/repos", "events_url": "https://api.github.com/users/alexlatchford/events{/privacy}", "received_events_url": "https://api.github.com/users/alexlatchford/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Well, I would think that in those examples you would get an error because the first row's UUID would be `None`. But if you specified `default=uuid.uuid4` or something, I think your error would be replicated.\n", "Ah yes, sorry I knew I'd forgotten something in the example! I've updated my original post\n", "Should be fixed in 5c59f44915f7418b031e27ec8bc4806e562dd5d4 thanks for reporting!\n" ]
2014-09-16T00:19:06
2014-09-16T03:07:37
2014-09-16T03:07:37
CONTRIBUTOR
null
Hi Charles, ``` python class MyModel(Model): uuid = UUIDField(primary_key=True, default=uuid.uuid4) name = CharField() my_models = [{"name": "foo"}, {"name": "bar"}] MyModel.insert_many(my_models).execute() ``` You'll get the same uuid in `InsertQuery._defaults` applied to both rows and it'll result in an error similar to the one found below. ``` Traceback (most recent call last): File "/Library/Python/2.7/site-packages/cherrypy/_cprequest.py", line 656, in respond response.body = self.handler() File "/Library/Python/2.7/site-packages/cherrypy/lib/encoding.py", line 188, in __call__ self.body = self.oldhandler(*args, **kwargs) File "/Library/Python/2.7/site-packages/cherrypy/_cpdispatch.py", line 34, in __call__ return self.callable(*self.args, **self.kwargs) File "/Users/alexlatchford/Code/abbreviate/a8-product/a8_product/../a8_product/lib/auth_tools.py", line 11, in __ca return f(*args, **kwargs) File "/Users/alexlatchford/Code/abbreviate/a8-product/a8_product/../a8_product/routes/auth/signup.py", line 80, in POST NewsFilter.insert_many(filters).execute() File "/Users/alexlatchford/Code/peewee/peewee.py", line 2555, in execute return self.database.last_insert_id(self._execute(), self.model_class) File "/Users/alexlatchford/Code/peewee/peewee.py", line 2120, in _execute return self.database.execute_sql(sql, params, self.require_commit) File "/Users/alexlatchford/Code/peewee/playhouse/postgres_ext.py", line 250, in execute_sql logger.exception('%s %s', sql, params) File "/Users/alexlatchford/Code/peewee/peewee.py", line 2591, in __exit__ reraise(new_type, new_type(*exc_value.args), traceback) File "/Users/alexlatchford/Code/peewee/playhouse/postgres_ext.py", line 250, in execute_sql logger.exception('%s %s', sql, params) IntegrityError: duplicate key value violates unique constraint "news_filter_pkey" DETAIL: Key (uuid)=(1116e6d9-dfaa-4709-be2d-95ef5cfc4983) already exists. ``` I've fixed it for myself at the moment by simply generating the UUID's outside of peewee :) Many thanks, Alex
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/429/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/429/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/428
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/428/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/428/comments
https://api.github.com/repos/coleifer/peewee/issues/428/events
https://github.com/coleifer/peewee/issues/428
42,820,696
MDU6SXNzdWU0MjgyMDY5Ng==
428
Docs build error for peewee-2.3.2
{ "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
[]
2014-09-15T21:24:28
2014-09-15T21:27:21
2014-09-15T21:27:21
NONE
null
Getting this while running Sphinx v1.2.1 to build the docs ``` peewee-2.3.2/docs/peewee/playhouse.rst:2346: ERROR: Malformed table. Text in column margin in table line 6. ================ ============= ======================================= Option Default Description ================ ============= ======================================= ``-l,--logging`` False Log all queries to stdout. ``-e,--engine`` sqlite Database driver to use. ``-d,--database`` ``:memory:`` Database to connect to. ================ ============= ======================================= ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/428/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/428/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/427
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/427/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/427/comments
https://api.github.com/repos/coleifer/peewee/issues/427/events
https://github.com/coleifer/peewee/issues/427
42,732,661
MDU6SXNzdWU0MjczMjY2MQ==
427
caniusepython3 thinks peewee does not support python3
{ "login": "Amleto", "id": 2996796, "node_id": "MDQ6VXNlcjI5OTY3OTY=", "avatar_url": "https://avatars.githubusercontent.com/u/2996796?v=4", "gravatar_id": "", "url": "https://api.github.com/users/Amleto", "html_url": "https://github.com/Amleto", "followers_url": "https://api.github.com/users/Amleto/followers", "following_url": "https://api.github.com/users/Amleto/following{/other_user}", "gists_url": "https://api.github.com/users/Amleto/gists{/gist_id}", "starred_url": "https://api.github.com/users/Amleto/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/Amleto/subscriptions", "organizations_url": "https://api.github.com/users/Amleto/orgs", "repos_url": "https://api.github.com/users/Amleto/repos", "events_url": "https://api.github.com/users/Amleto/events{/privacy}", "received_events_url": "https://api.github.com/users/Amleto/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I'm not positive, I tried to find the reason or code in caniusepython3.com's codebase but didn't seem to see it.\n", "Appears to be fixed with the latest release. Thanks for mentioning this.\n" ]
2014-09-14T22:42:52
2014-09-15T18:32:09
2014-09-15T18:32:09
NONE
null
Is this down to the tags used on pypi?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/427/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/427/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/426
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/426/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/426/comments
https://api.github.com/repos/coleifer/peewee/issues/426/events
https://github.com/coleifer/peewee/issues/426
42,641,325
MDU6SXNzdWU0MjY0MTMyNQ==
426
pwiz.py SqliteIntrospector.get_foreign_keys
{ "login": "mattjvincent", "id": 1842565, "node_id": "MDQ6VXNlcjE4NDI1NjU=", "avatar_url": "https://avatars.githubusercontent.com/u/1842565?v=4", "gravatar_id": "", "url": "https://api.github.com/users/mattjvincent", "html_url": "https://github.com/mattjvincent", "followers_url": "https://api.github.com/users/mattjvincent/followers", "following_url": "https://api.github.com/users/mattjvincent/following{/other_user}", "gists_url": "https://api.github.com/users/mattjvincent/gists{/gist_id}", "starred_url": "https://api.github.com/users/mattjvincent/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/mattjvincent/subscriptions", "organizations_url": "https://api.github.com/users/mattjvincent/orgs", "repos_url": "https://api.github.com/users/mattjvincent/repos", "events_url": "https://api.github.com/users/mattjvincent/events{/privacy}", "received_events_url": "https://api.github.com/users/mattjvincent/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Hmmm... it seems also that ForeignKeyField have to be integers? I usually design my databases with keys being integers, but that's not always going to be the case. See above example. When populated and trying to use, errors occur trying to coerce to be ints.\n\n```\n/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/peewee.pyc in get(self)\n 2381 clone = self.paginate(1, 1)\n 2382 try:\n-> 2383 return clone.execute().next()\n 2384 except StopIteration:\n 2385 raise self.model_class.DoesNotExist(\n\n/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/peewee.pyc in next(self)\n 1684 return inst\n 1685 \n-> 1686 obj = self.iterate()\n 1687 self._result_cache.append(obj)\n 1688 self.__ct += 1\n\n/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/peewee.pyc in iterate(self)\n 1672 self.initialize(self.cursor.description)\n 1673 self._initialized = True\n-> 1674 return self.process_row(row)\n 1675 \n 1676 def iterator(self):\n\n/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/peewee.pyc in process_row(self, row)\n 1744 instance = self.model()\n 1745 for i, column, func in self.conv:\n-> 1746 setattr(instance, column, func(row[i]))\n 1747 instance.prepared()\n 1748 return instance\n\n/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/peewee.pyc in python_value(self, value)\n 676 def python_value(self, value):\n 677 \"\"\"Convert the database value to a pythonic value.\"\"\"\n--> 678 return value if value is None else self.coerce(value)\n 679 \n 680 def _as_entity(self, with_table=False):\n\n/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/peewee.pyc in coerce(self, value)\n 1045 \n 1046 def coerce(self, value):\n-> 1047 return self.to_field.coerce(value)\n 1048 \n 1049 def db_value(self, value):\n\nValueError: invalid literal for int() with base 10: 'example_player_1'\n```\n", "> it seems also that ForeignKeyField have to be integers?\n\nNo, but if your foreign key references a column other than the primary key, you need to specify it using `to_field`: http://peewee.readthedocs.org/en/latest/peewee/api.html#ForeignKeyField\n", "Yes, but doesn't ForeignKeyField inherit from IntegerField?\n", "It does, but it will derive its behavior (and column definition) from the column it relates to. So if it points to a `TEXT` column, it will behave like one.\n", "Ok, but pwiz.py should still be changed to use the `to_field`...\n\n```\nsqlite3 player.db \"insert into player values (1, 'matt', 'matt v');\"\nsqlite3 player.db \"insert into player values (2, 'zach', 'zach v');\"\nsqlite3 player.db \"insert into player options(1, 'matt', 'foo', 'bar');\"\nsqlite3 player.db \"insert into player options(1, 'matt', 'foo2', 'bar2');\"\nsqlite3 player.db \"insert into player options(3, 'matt', 'foo3', 'bar3');\"\nsqlite3 player.db \"insert into player options(4, 'zach', 'foo', 'bar');\"\n```\n\npwiz.py -e sqlite player.db >player.py\n\n```\nfrom peewee import *\n\ndatabase = SqliteDatabase('player.db3', **{})\n\nclass UnknownField(object):\n pass\n\nclass BaseModel(Model):\n class Meta:\n database = database\n\nclass Player(BaseModel):\n _key = PrimaryKeyField(null=True)\n name = TextField()\n player = TextField(db_column='player_id')\n\n class Meta:\n db_table = 'player'\n\nclass PlayerOptions(BaseModel):\n _key = PrimaryKeyField(null=True)\n option_key = TextField()\n option_value = TextField()\n player = ForeignKeyField(db_column='player_id', rel_model=Player)\n\n class Meta:\n db_table = 'player_options'\n```\n\nThan ipython:\n\n```\n\nIn [1]: import player\n\nIn [2]: player.PlayerOptions.select().where((player.PlayerOptions.player == 'matt')).get()\n---------------------------------------------------------------------------\nValueError Traceback (most recent call last)\n<ipython-input-2-54331d4f3326> in <module>()\n----> 1 player.PlayerOptions.select().where((player.PlayerOptions.player == 'matt')).get()\n\n/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/peewee.pyc in get(self)\n 2381 clone = self.paginate(1, 1)\n 2382 try:\n-> 2383 return clone.execute().next()\n 2384 except StopIteration:\n 2385 raise self.model_class.DoesNotExist(\n\n/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/peewee.pyc in execute(self)\n 2422 else:\n 2423 ResultWrapper = ModelQueryResultWrapper\n-> 2424 self._qr = ResultWrapper(model_class, self._execute(), query_meta)\n 2425 self._dirty = False\n 2426 return self._qr\n\n/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/peewee.pyc in _execute(self)\n 2117 \n 2118 def _execute(self):\n-> 2119 sql, params = self.sql()\n 2120 return self.database.execute_sql(sql, params, self.require_commit)\n 2121 \n\n/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/peewee.pyc in sql(self)\n 2396 \n 2397 def sql(self):\n-> 2398 return self.compiler().generate_select(self)\n 2399 \n 2400 def verify_naive(self):\n\n/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/peewee.pyc in generate_select(self, query, alias_map)\n 1458 clauses.append(SQL(stmt))\n 1459 \n-> 1460 return self.build_query(clauses, alias_map)\n 1461 \n 1462 def generate_update(self, query):\n\n/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/peewee.pyc in build_query(self, clauses, alias_map)\n 1355 \n 1356 def build_query(self, clauses, alias_map=None):\n-> 1357 return self.parse_node(Clause(*clauses), alias_map)\n 1358 \n 1359 def generate_joins(self, joins, model_class, alias_map):\n\n/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/peewee.pyc in parse_node(self, node, alias_map, conv)\n 1316 \n 1317 def parse_node(self, node, alias_map=None, conv=None):\n-> 1318 sql, params, unknown = self._parse(node, alias_map, conv)\n 1319 if unknown and conv and params:\n 1320 params = [conv.db_value(i) for i in params]\n\n/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/peewee.pyc in _parse(self, node, alias_map, conv)\n 1291 unknown = False\n 1292 if node_type in self._parse_map:\n-> 1293 sql, params = self._parse_map[node_type](node, alias_map, conv)\n 1294 unknown = node_type in self._unknown_types\n 1295 elif isinstance(node, (list, tuple)):\n\n/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/peewee.pyc in _parse_clause(self, node, alias_map, conv)\n 1244 def _parse_clause(self, node, alias_map, conv):\n 1245 sql, params = self.parse_node_list(\n-> 1246 node.nodes, alias_map, conv, node.glue)\n 1247 if node.parens:\n 1248 sql = '(%s)' % self._clean_extra_parens(sql)\n\n/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/peewee.pyc in parse_node_list(self, nodes, alias_map, conv, glue)\n 1333 params = []\n 1334 for node in nodes:\n-> 1335 node_sql, node_params = self.parse_node(node, alias_map, conv)\n 1336 sql.append(node_sql)\n 1337 params.extend(node_params)\n\n/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/peewee.pyc in parse_node(self, node, alias_map, conv)\n 1316 \n 1317 def parse_node(self, node, alias_map=None, conv=None):\n-> 1318 sql, params, unknown = self._parse(node, alias_map, conv)\n 1319 if unknown and conv and params:\n 1320 params = [conv.db_value(i) for i in params]\n\n/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/peewee.pyc in _parse(self, node, alias_map, conv)\n 1291 unknown = False\n 1292 if node_type in self._parse_map:\n-> 1293 sql, params = self._parse_map[node_type](node, alias_map, conv)\n 1294 unknown = node_type in self._unknown_types\n 1295 elif isinstance(node, (list, tuple)):\n\n/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/peewee.pyc in _parse_expression(self, node, alias_map, conv)\n 1225 conv = node.lhs\n 1226 lhs, lparams = self.parse_node(node.lhs, alias_map, conv)\n-> 1227 rhs, rparams = self.parse_node(node.rhs, alias_map, conv)\n 1228 template = '%s %s %s' if node.flat else '(%s %s %s)'\n 1229 sql = template % (lhs, self.get_op(node.op), rhs)\n\n/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/peewee.pyc in parse_node(self, node, alias_map, conv)\n 1318 sql, params, unknown = self._parse(node, alias_map, conv)\n 1319 if unknown and conv and params:\n-> 1320 params = [conv.db_value(i) for i in params]\n 1321 \n 1322 if isinstance(node, Node):\n\n/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/peewee.pyc in db_value(self, value)\n 1050 if isinstance(value, self.rel_model):\n 1051 value = value.get_id()\n-> 1052 return self.to_field.db_value(value)\n 1053 \n 1054 \n\n/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/peewee.pyc in db_value(self, value)\n 672 def db_value(self, value):\n 673 \"\"\"Convert the python value for storage in the database.\"\"\"\n--> 674 return value if value is None else self.coerce(value)\n 675 \n 676 def python_value(self, value):\n\nValueError: invalid literal for int() with base 10: 'matt'\n\nIn [3]: \n```\n\nSo coercing takes place since pwiz.py does not use the fact that Player.player is a `TEXT` field when creating the \"model\".\n\nDoes that make sense?\n\nDid the change on line 442 also make sense?\n\nThanks! Love the library thus far!\n", "Seems like adding a `to_field` key and value where the if condition on line would work.\n\n```\nif self.field_class is ForeignKeyField:\n params['rel_model'] = self.rel_model\n```\n\nJust have to run and don't have time to see what's available to grab from right now. I'm sure you know how better than I.\n", "75981c4 fixes both the multi-line issue and the `to_field` issue.\n", "What's the rationale for removing the '_id' in the column_names? I'm having breakage with the following...\n\ngame.sql\n\n```\nCREATE TABLE ball_player (\n _key INTEGER PRIMARY KEY,\n ball_player_id TEXT NOT NULL,\n name TEXT NOT NULL\n);\nCREATE UNIQUE INDEX ball_player_idx ON ball_player (ball_player_id ASC);\n\nCREATE TABLE game_option (\n _key INTEGER PRIMARY KEY,\n game_option_id TEXT NOT NULL,\n name TEXT NOT NULL\n);\nCREATE UNIQUE INDEX game_option_idx ON game_option (game_option_id ASC);\n\nCREATE TABLE ball_player_game_options (\n _key INTEGER PRIMARY KEY,\n ball_player_id TEXT NOT NULL,\n game_option_id TEXT NOT NULL,\n value TEXT NOT NULL,\n FOREIGN KEY (ball_player_id) REFERENCES ball_player (ball_player_id),\n FOREIGN KEY (game_option_id) REFERENCES game_option (game_option_id)\n);\nCREATE UNIQUE INDEX ball_player_game_options_idx ON ball_player_game_options (ball_player_id, game_option_id ASC);\n```\n\nNext:\n\n```\nsqlite3 game.db3 < game.sql\n```\n\nThan\n\n```\nipython\n\nPython 2.7.6 (v2.7.6:3a1db0d2747e, Nov 10 2013, 00:42:54) \nType \"copyright\", \"credits\" or \"license\" for more information.\n\nIPython 2.1.0 -- An enhanced Interactive Python.\n? -> Introduction and overview of IPython's features.\n%quickref -> Quick reference.\nhelp -> Python's own help system.\nobject? -> Details about 'object', use 'object??' for extra details.\n\nIn [1]: import game.py\n\nAttributeError: type object 'GameOption' has no attribute 'game_option_id'\n```\n", "This appears to be a bug.\n\nOn Mon, Sep 22, 2014 at 11:12 AM, Matt Vincent [email protected]\nwrote:\n\n> What's the rational for removing the '_id' in the column_names? I'm having\n> breakage with the following...\n> \n> game.sql\n> \n> CREATE TABLE ball_player (\n> _key INTEGER PRIMARY KEY,\n> ball_player_id TEXT NOT NULL,\n> name TEXT NOT NULL\n> );\n> CREATE UNIQUE INDEX ball_player_idx ON ball_player (ball_player_id ASC);\n> \n> CREATE TABLE game_option (\n> _key INTEGER PRIMARY KEY,\n> game_option_id TEXT NOT NULL,\n> name TEXT NOT NULL\n> );\n> CREATE UNIQUE INDEX game_option_idx ON game_option (game_option_id ASC);\n> \n> CREATE TABLE ball_player_game_options (\n> _key INTEGER PRIMARY KEY,\n> ball_player_id TEXT NOT NULL,\n> game_option_id TEXT NOT NULL,\n> value TEXT NOT NULL,\n> FOREIGN KEY (ball_player_id) REFERENCES ball_player (ball_player_id),\n> FOREIGN KEY (game_option_id) REFERENCES game_option (game_option_id)\n> );\n> CREATE UNIQUE INDEX ball_player_game_options_idx ON ball_player_game_options (ball_player_id, game_option_id ASC);\n> \n> Next:\n> \n> sqlite3 game.db3 < game.sql\n> \n> Than\n> \n> ipython\n> \n> Python 2.7.6 (v2.7.6:3a1db0d2747e, Nov 10 2013, 00:42:54)\n> Type \"copyright\", \"credits\" or \"license\" for more information.\n> \n> IPython 2.1.0 -- An enhanced Interactive Python.\n> ? -> Introduction and overview of IPython's features.\n> %quickref -> Quick reference.\n> help -> Python's own help system.\n> object? -> Details about 'object', use 'object??' for extra details.\n> \n> In [1]: import game.py\n> \n> AttributeError: type object 'GameOption' has no attribute 'game_option_id'\n> \n> —\n> Reply to this email directly or view it on GitHub\n> https://github.com/coleifer/peewee/issues/426#issuecomment-56397634.\n", "Fixed for real in c7d538e216c4c896c95a8cfed9fbd5454506dacc\n" ]
2014-09-12T15:34:16
2014-09-24T11:44:55
2014-09-12T23:14:47
NONE
null
Some SQLite databases will return EOL characters in the following query: ``` SELECT sql FROM sqlite_master WHERE (tbl_name = ? AND type = ?) ``` This makes it so foreign keys don't work. To fix change line **442 in pwiz.py**. ``` def get_foreign_keys(self, table, schema=None): query = """ SELECT sql FROM sqlite_master WHERE (tbl_name = ? AND type = ?)""" cursor = self.execute(query, table, 'table') #LINE 442 table_definition = cursor.fetchone()[0].strip() table_definition = ''.join(map(lambda x: str(x[0]).replace('\r\n', ' ').replace('\n', ' ').strip(), cursor.fetchall())) ``` My test was: File: player.sql ``` DROP TABLE IF EXISTS player; CREATE TABLE player ( _key INTEGER PRIMARY KEY, player_id TEXT NOT NULL, name TEXT NOT NULL ); CREATE UNIQUE INDEX player_idx_id ON player (player_id ASC); DROP TABLE IF EXISTS player_options; CREATE TABLE player_options ( _key INTEGER PRIMARY KEY, player_id TEXT NOT NULL, option_key TEXT NOT NULL, option_value TEXT NOT NULL, FOREIGN KEY (player_id) REFERENCES player (player_id) ); CREATE INDEX player_options_idx_player ON player_options (player_id ASC); ``` Than from the command line: ``` sqlite3 player.db3 < player.sql pwiz.py -e sqlite player.db3 > PlayerModels.py ``` Using the old version of line 442 gives the following output: **Unable to read table definition for "player"** ``` from peewee import * database = SqliteDatabase('player.db3', **{}) class UnknownFieldType(object): pass class BaseModel(Model): class Meta: database = database class Player(BaseModel): _key = PrimaryKeyField(null=True) name = TextField() player = TextField(db_column='player_id') class Meta: db_table = 'player' class Player_Options(BaseModel): _key = PrimaryKeyField(null=True) option_key = TextField() option_value = TextField() player = TextField(db_column='player_id') class Meta: db_table = 'player_options' ``` However, the new version gives: ``` from peewee import * database = SqliteDatabase('player.db3', **{}) class UnknownField(object): pass class BaseModel(Model): class Meta: database = database class Player(BaseModel): _key = PrimaryKeyField(null=True) name = TextField() player = TextField(db_column='player_id') class Meta: db_table = 'player' class PlayerOptions(BaseModel): _key = PrimaryKeyField(null=True) option_key = TextField() option_value = TextField() player = ForeignKeyField(db_column='player_id', rel_model=Player) class Meta: db_table = 'player_options' ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/426/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/426/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/425
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/425/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/425/comments
https://api.github.com/repos/coleifer/peewee/issues/425/events
https://github.com/coleifer/peewee/issues/425
42,635,767
MDU6SXNzdWU0MjYzNTc2Nw==
425
ExtQueryWrapper raises exception when selecting fn.NOW()
{ "login": "demongoo", "id": 941459, "node_id": "MDQ6VXNlcjk0MTQ1OQ==", "avatar_url": "https://avatars.githubusercontent.com/u/941459?v=4", "gravatar_id": "", "url": "https://api.github.com/users/demongoo", "html_url": "https://github.com/demongoo", "followers_url": "https://api.github.com/users/demongoo/followers", "following_url": "https://api.github.com/users/demongoo/following{/other_user}", "gists_url": "https://api.github.com/users/demongoo/gists{/gist_id}", "starred_url": "https://api.github.com/users/demongoo/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/demongoo/subscriptions", "organizations_url": "https://api.github.com/users/demongoo/orgs", "repos_url": "https://api.github.com/users/demongoo/repos", "events_url": "https://api.github.com/users/demongoo/events{/privacy}", "received_events_url": "https://api.github.com/users/demongoo/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Nice catch, you're right.\n" ]
2014-09-12T14:40:34
2014-09-12T14:46:20
2014-09-12T14:46:20
NONE
null
When using something like this: `Record.select(Record.datetime, fn.NOW()).tuples()`, on iteration exception gets thrown: ``` File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 1686, in next obj = self.iterate() File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 1672, in iterate self.initialize(self.cursor.description) File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 1724, in initialize isinstance(select_column.arguments[0], Field)): IndexError: tuple index out of range ``` The place in current master is: https://github.com/coleifer/peewee/blob/master/peewee.py#L1729 Should be checked that `len(select_column.arguments) > 0`
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/425/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/425/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/424
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/424/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/424/comments
https://api.github.com/repos/coleifer/peewee/issues/424/events
https://github.com/coleifer/peewee/issues/424
42,551,982
MDU6SXNzdWU0MjU1MTk4Mg==
424
`Expression.__bool__` should raise an exception
{ "login": "abarnert", "id": 1808250, "node_id": "MDQ6VXNlcjE4MDgyNTA=", "avatar_url": "https://avatars.githubusercontent.com/u/1808250?v=4", "gravatar_id": "", "url": "https://api.github.com/users/abarnert", "html_url": "https://github.com/abarnert", "followers_url": "https://api.github.com/users/abarnert/followers", "following_url": "https://api.github.com/users/abarnert/following{/other_user}", "gists_url": "https://api.github.com/users/abarnert/gists{/gist_id}", "starred_url": "https://api.github.com/users/abarnert/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/abarnert/subscriptions", "organizations_url": "https://api.github.com/users/abarnert/orgs", "repos_url": "https://api.github.com/users/abarnert/repos", "events_url": "https://api.github.com/users/abarnert/events{/privacy}", "received_events_url": "https://api.github.com/users/abarnert/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I think raising an exception will prevent a lot of hard-to-diagnose bugs...great suggestion.\n", "Unfortunately, this will mean overriding the `__nonzero__` method and there are just too many places where the truthiness of a node object is checked. Maybe I could override it only for `Expression`...\n", "One thing I just realized, from looking over SQLAlchemy:\n\nIf you make `__eq__` return an `Expression`, and you make `Expression.__bool__` raise an exception, then you can't use nodes as set elements or dict keys. And I can see wanting to be able to, e.g., build a set of column nodes, or map expressions to result sets (which works in Peewee today).\n\nSQLAlchemy solves this by making any node _except_ for a `!=` or `==` `BinaryExpression` raise an exception in boolean context, but have those two expressions compare hash values. So a column is equal to itself and nothing else. Like this:\n\n```\ndef __bool__(self):\n if self.operator in (operator.eq, operator.ne):\n return self.operator(hash(self._orig[0]), hash(self._orig[1]))\n else:\n raise TypeError(\"Boolean value of this clause is not defined\")\n```\n\nI'm actually not sure this is why they've added the special case, but I can't see any other reason to do it.\n\nThat just seems wrong to me. `==` and `!=` are the two most commonly-used operators. All of the relevant questions I've seen on StackOverflow were of the form \"I wrote `where(Person.name != 'Guido' and Person.commits > 1000)` but I still get Guido back\". So SQLAlchemy protects people from this bug everywhere except the place they're most likely to see it. I think that may actually be worse than not protecting them and just trying to explain it in the docs.\n\nAlso, the only time a set or dict will ever ask you for a `==` comparison is if it already knows the hashes are equal and needs to check for a hash collision; if you do this, you need to ensure that no two live nodes ever have the same hash value as each other or as anything else they can be in a dict with, or you're going to have either those fun one-in-a-trillion bugs that are so much fun to reproduce or someone taking over a server using a collision attack…\n", "> Also, the only time a set or dict will ever ask you for a == comparison is if it already knows the hashes are equal and needs to check for a hash collision\n\nVery interesting!\n", "Thanks for your insight and for sharing the behavior of SQA. I've thought about it some and I don't really think there's a great way to prevent people from accidentally using `not`, `or`, and `and`. Overriding `__nonzero__` seems like it might have too many unintended/unpredictable side-effects. Perhaps the solution is just to add better documentation.\n" ]
2014-09-11T17:52:09
2014-09-13T00:35:45
2014-09-13T00:35:45
NONE
null
I haven't looked carefully enough to know if this is a plausible idea or not, but… I've seen multiple people getting confused because `where(Meal.spam==2 and Meal.eggs==3)` ignores the `Meal.spam=2` part. To anyone who understands how Python's `and` operator works, this is pretty obvious, but Peewee is very useful to a lot of people who aren't experienced Python users. One obvious solution is: ``` def __bool__(self): raise ValueError("The truth value of an expression is ambiguous until " "executed in a query. Use x&y, x|y, ~x, x.bin_and(y), etc.") ``` Now, instead of silently getting a query they didn't want and having no idea how to debug it, they immediately get an error that tells them what's wrong and what to do about it. Numpy and Pandas do effectively the same thing; if you try to use an array/matrix/series/dataframe in a boolean context (except a scalar or an array whose dimensions are all 1), you get: ``` ValueError('The truth value of an array with more than one element is ambiguous. ' 'Use a.any() or a.all()') ``` Of course if there's a good use case for using `Expression`s as truthy in a boolean context, this would be a bad change; just because I can't think of one off the top of my head doesn't mean it doesn't exist.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/424/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/424/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/423
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/423/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/423/comments
https://api.github.com/repos/coleifer/peewee/issues/423/events
https://github.com/coleifer/peewee/issues/423
41,623,988
MDU6SXNzdWU0MTYyMzk4OA==
423
Accessing column values using magic .c lookup with Subqueries
{ "login": "oneleaftea", "id": 8613451, "node_id": "MDQ6VXNlcjg2MTM0NTE=", "avatar_url": "https://avatars.githubusercontent.com/u/8613451?v=4", "gravatar_id": "", "url": "https://api.github.com/users/oneleaftea", "html_url": "https://github.com/oneleaftea", "followers_url": "https://api.github.com/users/oneleaftea/followers", "following_url": "https://api.github.com/users/oneleaftea/following{/other_user}", "gists_url": "https://api.github.com/users/oneleaftea/gists{/gist_id}", "starred_url": "https://api.github.com/users/oneleaftea/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/oneleaftea/subscriptions", "organizations_url": "https://api.github.com/users/oneleaftea/orgs", "repos_url": "https://api.github.com/users/oneleaftea/repos", "events_url": "https://api.github.com/users/oneleaftea/events{/privacy}", "received_events_url": "https://api.github.com/users/oneleaftea/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Can you share the generated SQL for the query that is failing?\n", "Hello,\nI think I figured out what the issue was:\n\nHere is the python code as originally written:\n\n``` python\njoinquery = Salaries.select().order_by(Salaries.salary.desc()).limit(howmany)\njoinquery = joinquery.alias('jq')\nquery = Employees.select(Employees, joinquery.c.salary).join(joinquery, \\\n on=(Employees.emp_no == joinquery.c.emp_no)).order_by(joinquery.c.salary.desc()).naive()\n```\n\nwhich generates this sql code:\n\n``` sql\nSELECT `t1`.`emp_no`, `t1`.`birth_date`, `t1`.`first_name`, \n `t1`.`gender`, `t1`.`hire_date`, `t1`.`last_name`, `jq`.`salary` \nFROM `employees` AS t1 \nINNER JOIN (\n SELECT `t3`.`emp_no` \n FROM `salaries` AS t3 \n ORDER BY `t3`.`salary` DESC LIMIT 20\n) AS jq ON (`t1`.`emp_no` = `jq`.`emp_no`) \nORDER BY `jq`.`salary` DESC []\n```\n\nFrom the sql code, it is shown that joinquery only makes t3.emp_no available, despite calling select() when assigning joinquery, which I thought would make all columns available.\n\nIn fact, if you do print(joinquery), it shows that all columns of the Salaries model/table selected:\n\n``` sql\nSELECT `t1`.`emp_no`, `t1`.`from_date`, `t1`.`salary`, `t1`.`to_date` \nFROM `salaries` AS t1 \nORDER BY `t1`.`salary` DESC LIMIT 20 []\n```\n\nBut when joining it later on, the only column that is available is the one used by the join condition, which is t1.emp_no.\n\nA solution:\n\nBy explicitly doing this:\n\n``` python\njoinquery = Salaries.select(Salaries.emp_no, Salaries.salary).order_by(Salaries.salary.desc()).limit(howmany)\n```\n\nThe needed columns are thus available:\n\n``` sql\nSELECT `t1`.`emp_no`, `t1`.`birth_date`, `t1`.`first_name`, \n `t1`.`gender`, `t1`.`hire_date`, `t1`.`last_name`, `jq`.`salary` \nFROM `employees` AS t1 \nINNER JOIN (\n SELECT `t3`.`emp_no`, `t3`.`salary` \n FROM `salaries` AS t3 \n ORDER BY `t3`.`salary` DESC LIMIT 20\n) AS jq ON (`t1`.`emp_no` = `jq`.`emp_no`) \nORDER BY `jq`.`salary` DESC []\n```\n\nThis then makes ordering by salary possible as well as making possible subsequent print command of:\n\n``` python\nfor empvar in query:\n print(' '+empvar.first_name, empvar.last_name, 'making $'+str(empvar.salary))\n```\n\nNot sure if this is per design? It seems the original subquery should stay intact when used in the join, to better represent what one would expect when doing raw SQL. That said, being more explicit is never a bad thing and I consider the solution to be an adequate one. \n\nThanks!\n", "> Not sure if this is per design? It seems the original subquery should stay intact when used in the join, to better represent what one would expect when doing raw SQL.\n\nYes, if you are performing a subquery with no explicit selection, peewee will default to only grabbing the primary key.\n", "Ahhh ok, that makes sense. Thanks for the response! \n" ]
2014-09-01T10:03:39
2014-09-04T22:28:28
2014-09-04T22:28:28
NONE
null
I ran into a behavior with peewee where it seems the .c lookup for a subquery only works for the **on clause**, but not for the **select()** and **order_by** clauses, as well as subsequent access in a **print** command. For instance, this works ``` python joinquery = Salaries.select().order_by(Salaries.salary.desc()).limit('4') joinquery = joinquery.alias('jq') query = Employees.select().join(joinquery, on=(Employees.emp_no == joinquery.c.emp_no)) ``` But let's say I want access to not only the **emp_no** column in the joinquery, but also a **salary** column, so that I can **order by salary**. I cannot do: ``` python **same joinquery and joinquery alias as above*** query = Employees.select(Employees, joinquery.c.salary).join(joinquery, on=\ (Employees.emp_no == joinquery.c.emp_no)).order_by(joinquery.c.salary.desc()).naive() ``` It returns an error: (1054, "Unknown column 'jq.salary' in 'field list'") This makes it unavailable for ordering as well as unavailable for passing on the salary column in a print command such as: ``` python for empvar in query: print(' '+empvar.first_name, empvar.last_name, 'making $'+str(empvar.salary)) ``` I have tested the above syntax for a situation without a subquery and it worked. But for performance reasons, I wanted to try doing the subquery first, and then joining to make it more flexible to get around MySQL's default query plan which is often slow. But I ran into issues accessing the salary column. Is there something I am missing with the syntax? Thanks so much!
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/423/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/423/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/422
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/422/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/422/comments
https://api.github.com/repos/coleifer/peewee/issues/422/events
https://github.com/coleifer/peewee/issues/422
40,966,006
MDU6SXNzdWU0MDk2NjAwNg==
422
Sub-queries using union
{ "login": "awahlig", "id": 1263649, "node_id": "MDQ6VXNlcjEyNjM2NDk=", "avatar_url": "https://avatars.githubusercontent.com/u/1263649?v=4", "gravatar_id": "", "url": "https://api.github.com/users/awahlig", "html_url": "https://github.com/awahlig", "followers_url": "https://api.github.com/users/awahlig/followers", "following_url": "https://api.github.com/users/awahlig/following{/other_user}", "gists_url": "https://api.github.com/users/awahlig/gists{/gist_id}", "starred_url": "https://api.github.com/users/awahlig/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/awahlig/subscriptions", "organizations_url": "https://api.github.com/users/awahlig/orgs", "repos_url": "https://api.github.com/users/awahlig/repos", "events_url": "https://api.github.com/users/awahlig/events{/privacy}", "received_events_url": "https://api.github.com/users/awahlig/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Ahh, good catch. I had to be explicit about removing parentheses from union queries because one of the dbs (I think SQLite?) didn't like them, but I did not think about subqueries. I'll look into a fix, thanks for the great bug report.\n", "Fixed in b13ff6c131d0722f6a3cfb54c8280bc99ea0\n" ]
2014-08-23T03:22:45
2014-09-04T20:14:13
2014-09-04T20:13:53
NONE
null
First of all, thanks for your continued great work! I've been using peewee successfully for quite some time now. Today I hit a small issue though. If you build a union query and try to use it in WHERE of another query using << (IN), the union in the resulting SQL will not have parentheses around it which causes a syntax error. ``` python from peewee import * db = SqliteDatabase('test.db') class A(Model): foo = IntegerField() class Meta: database = db class B(Model): bar = IntegerField() class Meta: database = db class C(Model): baz = IntegerField() class Meta: database = db print A.select().where(A.foo << (B.select(B.bar) | C.select(C.baz))) ``` ``` <class '__main__.A'> SELECT t1."id", t1."foo" FROM "a" AS t1 WHERE (t1."foo" IN SELECT t2."bar" FROM "b" AS t2 UNION SELECT t3."baz" FROM "c" AS t3) [] ``` Using version 2.2.5.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/422/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/422/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/421
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/421/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/421/comments
https://api.github.com/repos/coleifer/peewee/issues/421/events
https://github.com/coleifer/peewee/issues/421
40,962,884
MDU6SXNzdWU0MDk2Mjg4NA==
421
Python 3 problem with division
{ "login": "NJDFan", "id": 8527880, "node_id": "MDQ6VXNlcjg1Mjc4ODA=", "avatar_url": "https://avatars.githubusercontent.com/u/8527880?v=4", "gravatar_id": "", "url": "https://api.github.com/users/NJDFan", "html_url": "https://github.com/NJDFan", "followers_url": "https://api.github.com/users/NJDFan/followers", "following_url": "https://api.github.com/users/NJDFan/following{/other_user}", "gists_url": "https://api.github.com/users/NJDFan/gists{/gist_id}", "starred_url": "https://api.github.com/users/NJDFan/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/NJDFan/subscriptions", "organizations_url": "https://api.github.com/users/NJDFan/orgs", "repos_url": "https://api.github.com/users/NJDFan/repos", "events_url": "https://api.github.com/users/NJDFan/events{/privacy}", "received_events_url": "https://api.github.com/users/NJDFan/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Thanks, good catch.\n" ]
2014-08-23T00:42:18
2014-08-25T01:09:33
2014-08-25T01:09:33
NONE
null
All the other mathematical operators work fine in queries, but division doesn't. This is most likely because Python3 killed `__div__` in favor of `__truediv__` and `__floordiv__`. After the line that reads:: ``` __div__ = _e(OP_DIV) ``` I put:: ``` __truediv__ = _e(OP_DIV) ``` And that seemed to fix it, but I'm not set up to run full regression tests on things.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/421/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/421/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/420
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/420/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/420/comments
https://api.github.com/repos/coleifer/peewee/issues/420/events
https://github.com/coleifer/peewee/issues/420
40,622,050
MDU6SXNzdWU0MDYyMjA1MA==
420
Table name not quoted as of 2.3.0
{ "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
[ "See #414 -- I'll push a new release soon.\n", "Oh, sorry, didn't see it was already filed.\n" ]
2014-08-19T18:32:33
2014-08-19T20:18:33
2014-08-19T20:17:39
CONTRIBUTOR
null
I accidentally upgraded to 2.3.0 on a staging environment, and /admin started throwing errors. I have a table called `user` (I regret this, it is a keyword), and in 2.2.5 everything is ok. In 2.3.0, `user` is no longer quoted properly when attempting to update a record in /admin, possibly everywhere. I end up with ``` WHERE (user."id" = 79) ``` Actually, the difference might be that in 2.2.5, `user` isn't even in the WHERE.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/420/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/420/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/419
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/419/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/419/comments
https://api.github.com/repos/coleifer/peewee/issues/419/events
https://github.com/coleifer/peewee/issues/419
40,429,077
MDU6SXNzdWU0MDQyOTA3Nw==
419
python_value not returning as expected
{ "login": "sojourning", "id": 537668, "node_id": "MDQ6VXNlcjUzNzY2OA==", "avatar_url": "https://avatars.githubusercontent.com/u/537668?v=4", "gravatar_id": "", "url": "https://api.github.com/users/sojourning", "html_url": "https://github.com/sojourning", "followers_url": "https://api.github.com/users/sojourning/followers", "following_url": "https://api.github.com/users/sojourning/following{/other_user}", "gists_url": "https://api.github.com/users/sojourning/gists{/gist_id}", "starred_url": "https://api.github.com/users/sojourning/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/sojourning/subscriptions", "organizations_url": "https://api.github.com/users/sojourning/orgs", "repos_url": "https://api.github.com/users/sojourning/repos", "events_url": "https://api.github.com/users/sojourning/events{/privacy}", "received_events_url": "https://api.github.com/users/sojourning/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[]
2014-08-17T07:52:36
2014-08-18T23:11:14
2014-08-18T23:11:14
NONE
null
Never mind. Figured it out. Thanks
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/419/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/419/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/418
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/418/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/418/comments
https://api.github.com/repos/coleifer/peewee/issues/418/events
https://github.com/coleifer/peewee/issues/418
40,403,054
MDU6SXNzdWU0MDQwMzA1NA==
418
“exc_value.args” at line 2591 may caused the error " AttributeError: 'str' object has no attribute 'args' " sometime
{ "login": "JoneXiong", "id": 2276625, "node_id": "MDQ6VXNlcjIyNzY2MjU=", "avatar_url": "https://avatars.githubusercontent.com/u/2276625?v=4", "gravatar_id": "", "url": "https://api.github.com/users/JoneXiong", "html_url": "https://github.com/JoneXiong", "followers_url": "https://api.github.com/users/JoneXiong/followers", "following_url": "https://api.github.com/users/JoneXiong/following{/other_user}", "gists_url": "https://api.github.com/users/JoneXiong/gists{/gist_id}", "starred_url": "https://api.github.com/users/JoneXiong/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/JoneXiong/subscriptions", "organizations_url": "https://api.github.com/users/JoneXiong/orgs", "repos_url": "https://api.github.com/users/JoneXiong/repos", "events_url": "https://api.github.com/users/JoneXiong/events{/privacy}", "received_events_url": "https://api.github.com/users/JoneXiong/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "On python 2, I get:\n\n```\nProgrammingError: SQLite objects created in a thread can only be used in that same thread.The object was created in thread id 140311384954624 and this is thread id 140311230535424\n```\n\nWhich I believe is the correct traceback. What python version are you using?\n", "Actually, on python 3, I get:\n\n```\npeewee.ProgrammingError: SQLite objects created in a thread can only be used in that same thread.The object was created in thread id 140570851063552 and this is thread id 140570760951552\n```\n\nSo I believe this is working as I expect.\n", "Thanks for you reply! I used Python 2.6.6 on CentOs 6.5 x86_64 and got the error.\n", "Cool, I don't currently have access to a Python 2.6 interpreter -- I'll see what I can do about compiling one. I wonder if the difference in exceptions is documented anywhere..I looked at the Python 2.7 changelog but nothing jumped out at me.\n", "I'm confused why `exc_value` is a string, according to the python 2.6 docs, `exc_value` should be an instance of the `exc_type` being raised:\n\nhttps://docs.python.org/2.6/library/sys.html#sys.exc_info\n\n> value gets the exception parameter (its associated value or the second argument to raise, which is always a class instance if the exception type is a class object)\n", "I am unable to replicate the error. Here is a script I am using:\n\n``` python\nimport sqlite3\nimport sys\nimport threading\n\nconn = sqlite3.connect('/tmp/my.db')\n\ndef foo():\n try:\n curs = conn.cursor()\n curs.execute('select 1')\n except Exception as exc:\n print exc\n et, ev, tb = sys.exc_info()\n print et\n print ev\n print type(ev)\n print ev.args\n\nt = threading.Thread(target=foo)\nt.start()\nt.join()\n```\n\nOutput:\n\n```\npython2.6 x.py\nSQLite objects created in a thread can only be used in that same thread.The object was created in thread id 140622844954368 and this is thread id 140622810523392\n<class 'sqlite3.ProgrammingError'>\nSQLite objects created in a thread can only be used in that same thread.The object was created in thread id 140622844954368 and this is thread id 140622810523392\n<class 'sqlite3.ProgrammingError'>\n('SQLite objects created in a thread can only be used in that same thread.The object was created in thread id 140622844954368 and this is thread id 140622810523392',)\n```\n\nWhat do you think? What output do you get with that script?\n", "I'm going to close this out, please reopen if you would like to add anything.\n", "It seems like MySQLdb python module affects on `exc_value` behavior. Workaround: use PyMySQL module instead.\n" ]
2014-08-16T04:12:51
2015-05-18T18:54:02
2014-08-28T14:18:19
NONE
null
eg: if you haven't seted "check_same_thread=False" may lead to: exc_value = “SQLite objects created in a thread can only be used in that same thread.The object was created in thread id.....” and then: reraise(new_type, new_type(*exc_value.args), traceback) AttributeError: 'str' object has no attribute 'args'
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/418/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/418/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/417
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/417/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/417/comments
https://api.github.com/repos/coleifer/peewee/issues/417/events
https://github.com/coleifer/peewee/issues/417
40,303,486
MDU6SXNzdWU0MDMwMzQ4Ng==
417
peewee regexp works only the first time
{ "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
[ "The `regexp` function is covered by unit tests and I can verify from local testing that it works. Can you share your code that is causing the problem? I wonder if at some point in between you are assigning a value to `Table.column` (maybe using single `=` sign instead of 2)?\n", "Hello. This is usually what I run:\nquery = Table.select().where(Table.column.regexp('string'))\n\nI've also tried doing to see if I need to execute the query at least once to \"release\" it from memory -\nfor column in Table.select().where(Table.column.regexp('string')):\n print Table.column\n\nNeither of those seems to work once I've done this the first time (by either method). Somehow it seems to be converting Table.column to unicode so that the next time I run it, it thinks I'm calling .regexp() on the unicode and not on the Table.column object. How do I release it so that it thinks of Table.column as the database object rather than whatever it pulled the first time?\n\nThanks!\n", "> Somehow it seems to be converting Table.column to unicode so that the next time I run it, it thinks I'm calling .regexp() on the unicode and not on the Table.column object.\n\nRight, which is why I asked if you were assigning a value to `Table.column` elsewhere. Can you share some code that I can use to try and reproduce the issue? Or share the actual code you're running? Also, what database engine are you using?\n", "Oh I see - sorry.\n\nI don't assign a value to Table.column anywhere... I literally just try to call this twice in a row.\n\nMy code is really this simple, actually... I just started using peewee last night. :)\n\nThe flow is as follows:\nquery = Table.select().where(Table.column.regexp('string'))\nquery = Table.select().where(Table.column.regexp('string2'))\n\nor \nquery = Table.select().where(Table.column.regexp('string'))\nfor column in Table.select().where(Table.column.regexp('string2')):\n print Table.column\n\nThe second of each results in the unicode error above.\n\nThe database itself is a MySQL db.\n\n(I'm about to go catch a plane - will check back as I find wifi. Thx in advance!!)\n", "Hmm, I'm confused why you're doing the first query if you don't do anything with the result. Is this literally the exact code you're using? If not I'd appreciate you sharing some code to reproduce the bug.\n", "I do use the result... I look to see what it returns and then fine tune my regex. I don't know how specific of a lookup I want to use, so I have to try it a few times. \n", "Since the consecutive queries with regexp haven't been working, I've been using MySQL for queries and using peewee just for data pulls. I guess I could go straight from MySQL as well to cut out some extra steps.\n", "Sorry you had trouble with this. I think that after your first query you were possibly overwriting the value of `Table.column`, which is why I asked you to share your code. At any rate, let me know if you want some help.\n" ]
2014-08-14T21:50:49
2014-08-18T23:13:15
2014-08-16T14:08:51
NONE
null
I'm running into an issue with the peewee regexp function. Queries like this work the first time I run it: query = Table.select().where(Table.column.regexp('string')) However, if I try to run it with a different string, I get this error: 'unicode' object has no attribute 'regexp': query = Table.select().where(Table.column.regexp('string2')) I usually run it twice because I need to see how specific to make the regexp string. I've tried disconnecting/reconnecting to the db, but that doesn't help. The only thing that works is if I close ipython and restart it. Is this a memory/buffer issue? Is there a good way to get this to work? Thanks in advance.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/417/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/417/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/416
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/416/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/416/comments
https://api.github.com/repos/coleifer/peewee/issues/416/events
https://github.com/coleifer/peewee/issues/416
40,274,720
MDU6SXNzdWU0MDI3NDcyMA==
416
Database.drop_tables hide warning when a table doesn't exist
{ "login": "rvindas-gap", "id": 8330613, "node_id": "MDQ6VXNlcjgzMzA2MTM=", "avatar_url": "https://avatars.githubusercontent.com/u/8330613?v=4", "gravatar_id": "", "url": "https://api.github.com/users/rvindas-gap", "html_url": "https://github.com/rvindas-gap", "followers_url": "https://api.github.com/users/rvindas-gap/followers", "following_url": "https://api.github.com/users/rvindas-gap/following{/other_user}", "gists_url": "https://api.github.com/users/rvindas-gap/gists{/gist_id}", "starred_url": "https://api.github.com/users/rvindas-gap/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/rvindas-gap/subscriptions", "organizations_url": "https://api.github.com/users/rvindas-gap/orgs", "repos_url": "https://api.github.com/users/rvindas-gap/repos", "events_url": "https://api.github.com/users/rvindas-gap/events{/privacy}", "received_events_url": "https://api.github.com/users/rvindas-gap/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "When I test this locally it appears to be working correctly:\n\n``` python\nIn [4]: db.drop_tables([User])\n\n.... traceback ....\n\n/home/charles/pypath/peewee.pyc in execute_sql(self, sql, params, require_commit)\n 2711 cursor = self.get_cursor()\n 2712 try:\n-> 2713 cursor.execute(sql, params or ())\n 2714 except Exception as exc:\n 2715 if self.get_autocommit() and self.autorollback:\n\nOperationalError: no such table: user\n\nIn [5]: db.drop_tables([User], safe=True)\n\nIn [6]: db.drop_tables([User], safe=True)\n```\n\nI believe you can just ignore the warnings.\n" ]
2014-08-14T16:51:21
2016-12-02T12:09:44
2014-08-14T21:05:28
NONE
null
Just ugraded to version 2.3.0 and I was trying the `drop_tables` function. If a table doesn't exist then I get a warning like the following (even specifying the `safe=True` parameter) ``` /mypathto/env/site-packages/peewee.py:2702: Warning: Unknown table 'variables' cursor.execute(sql, params or ()) /mypathto/env/site-packages/peewee.py:2702: Warning: Unknown table 'companies' cursor.execute(sql, params or ()) /mypathto/env/site-packages/peewee.py:2702: Warning: Unknown table 'users' cursor.execute(sql, params or ()) ``` Is there a way to turn off the warnings when trying to drop a table that doesn't exist and when specifying the `safe=True` parameter?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/416/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/416/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/415
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/415/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/415/comments
https://api.github.com/repos/coleifer/peewee/issues/415/events
https://github.com/coleifer/peewee/issues/415
40,255,541
MDU6SXNzdWU0MDI1NTU0MQ==
415
Regexp only works 1st time
{ "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-08-14T13:48:38
2014-08-14T14:01:31
2014-08-14T14:01:31
OWNER
null
I'm running into an issue with the peewee regexp function. Queries like this work the first time I run it: ``` query = Table.select().where(Table.column.regexp('string')) ``` However, if I try to run it with a different string, I get this error: 'unicode' object has no attribute 'regexp': ``` query = Table.select().where(Table.column.regexp('string2')) ``` I usually run it twice because I need to see how specific to make the regexp string. I've tried disconnecting/reconnecting to the db, but that doesn't help. The only thing that works is if I close ipython and restart it. Is this a memory/buffer issue? Is there a good way to get this to work? Thanks in advance.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/415/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/415/timeline
null
completed
null
null