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/114 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/114/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/114/comments | https://api.github.com/repos/coleifer/peewee/issues/114/events | https://github.com/coleifer/peewee/issues/114 | 7,499,691 | MDU6SXNzdWU3NDk5Njkx | 114 | Print SQL queries | {
"login": "ripperdoc",
"id": 1027509,
"node_id": "MDQ6VXNlcjEwMjc1MDk=",
"avatar_url": "https://avatars.githubusercontent.com/u/1027509?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/ripperdoc",
"html_url": "https://github.com/ripperdoc",
"followers_url": "https://api.github.com/users/ripperdoc/followers",
"following_url": "https://api.github.com/users/ripperdoc/following{/other_user}",
"gists_url": "https://api.github.com/users/ripperdoc/gists{/gist_id}",
"starred_url": "https://api.github.com/users/ripperdoc/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/ripperdoc/subscriptions",
"organizations_url": "https://api.github.com/users/ripperdoc/orgs",
"repos_url": "https://api.github.com/users/ripperdoc/repos",
"events_url": "https://api.github.com/users/ripperdoc/events{/privacy}",
"received_events_url": "https://api.github.com/users/ripperdoc/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I added a little helper here:\nhttps://github.com/coleifer/peewee/commit/a5ec7bb90b1882db95c6f4eae94ea373f7f6a50f\n",
"Great, thanks!\n",
"@coleifer Can you please give an example of how to use that helper function?\n",
"That function actually went away. Now you can just call:\n\n``` python\nq = MyModel.select().where(MyModel.id == 3)\nprint q.sql()\nsql, params = q.sql()\n```\n",
"@coleifer What if the result of `q = MyModel.select().where(MyModel.id == 3)` fails and caused an error? Is it possible to get the query that was sent to the DB and failed?",
"You can log all queries.\r\n\r\n```python\r\nimport logging\r\nlogger = logging.getLogger('peewee')\r\nlogger.addHandler(logging.StreamHandler())\r\nlogger.setLevel(logging.DEBUG)\r\n```\r\n\r\nOr you can add try/except or use an interactive debugger...it's just Python, remember!",
"http://docs.peewee-orm.com/en/latest/peewee/database.html#logging-queries",
"@TimothyBramlett you can use the logging package:\r\n\r\n```\r\nimport logging\r\nlogging.basicConfig(level=logging.DEBUG)\r\n```\r\n\r\nPeewee will print all queries that it sends to the DB.",
"As per peewee `3.13`, if you are connecting to a postgres database with peewee's underlying `psycopg2` (thanks @coleifer), you can print SQL queries by first getting the cursor, then calling the `mogrify()` method for your query.\r\n\r\n```python\r\nquery = <YOUR PEEWEE QUERY>\r\n\r\ncur = database.cursor()\r\nprint(cur.mogrify(*query.sql()))\r\n```\r\nWhere `database` is the Peewee Database object representing the connection to your database.",
"`mogrify` may be a psycopg2-only thing, and no supported by other drivers. For example, the standard lib sqlite3 does not provide this method."
] | 2012-10-10T23:47:16 | 2020-02-09T19:20:42 | 2012-10-12T00:47:38 | NONE | null | I updated from 1.0 to 2.0 and got into a bit of a mess - which has mostly cleared up now. One thing though - how do I print sql queries? I used to be able to do SelectQuery.sql() but not it requires a compiler argument, but what should I put into that? I cannot find any mention in the docs...
Thanks!
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/114/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/114/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/113 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/113/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/113/comments | https://api.github.com/repos/coleifer/peewee/issues/113/events | https://github.com/coleifer/peewee/pull/113 | 7,431,054 | MDExOlB1bGxSZXF1ZXN0MjU3ODY5NQ== | 113 | Add support for primary foreign keys | {
"login": "tmoertel",
"id": 21773,
"node_id": "MDQ6VXNlcjIxNzcz",
"avatar_url": "https://avatars.githubusercontent.com/u/21773?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/tmoertel",
"html_url": "https://github.com/tmoertel",
"followers_url": "https://api.github.com/users/tmoertel/followers",
"following_url": "https://api.github.com/users/tmoertel/following{/other_user}",
"gists_url": "https://api.github.com/users/tmoertel/gists{/gist_id}",
"starred_url": "https://api.github.com/users/tmoertel/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/tmoertel/subscriptions",
"organizations_url": "https://api.github.com/users/tmoertel/orgs",
"repos_url": "https://api.github.com/users/tmoertel/repos",
"events_url": "https://api.github.com/users/tmoertel/events{/privacy}",
"received_events_url": "https://api.github.com/users/tmoertel/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2012-10-08T20:53:27 | 2014-07-06T01:51:38 | 2012-10-08T21:39:00 | CONTRIBUTOR | null | This commit adds support for foreign keys that are also primary keys, the preferred means of representing one-to-zero-or-one relationships between model classes. (The alternative representation wastes a column and an index.) This kind relationship is common in modeling schemes for inheritance or extension semantics.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/113/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/113/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/113",
"html_url": "https://github.com/coleifer/peewee/pull/113",
"diff_url": "https://github.com/coleifer/peewee/pull/113.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/113.patch",
"merged_at": "2012-10-08T21:39:00"
} |
https://api.github.com/repos/coleifer/peewee/issues/112 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/112/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/112/comments | https://api.github.com/repos/coleifer/peewee/issues/112/events | https://github.com/coleifer/peewee/issues/112 | 7,340,735 | MDU6SXNzdWU3MzQwNzM1 | 112 | Support SelectQuery on a view | {
"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 | [
"I wonder if it would work just to create a model and have it specify its db_table attribute as the view. If the view \"looks\" like one of your existing models, you should also be able to subclass the exisitng model, e.g.:\n\n``` python\n\nclass MyModel(Model):\n # fields ...\n\nclass MyViewModel(MyModel):\n class Meta:\n db_table = 'this_is_actually_the_view'\n```\n\nIf I'm missing something essential to the issue please let me know but I belive the above should work.\n\nMore to the point, you have raised some excellent points about places where the API is brittle. I've rewritten peewee from the ground up and am finishing the work before merging it into master, but you can check the branch:\nhttps://github.com/coleifer/peewee/tree/unstable/2.0\n\nIt provides better hooks with a lot less insanity :)\n",
"In this case I am using different views for different queries. I have a \"Video\" object, and I have 3 different views for pulling out videos based on some complicated rules. I forgot to mention that I was going to use RawQuery, which would have almost worked, except RawQuery and flask-peewee don't work well together. flask-peewee assumes a SelectQuery in a few places (like PaginatedQuery).\n\nI will check out the branch in the meantime too though.\n",
"Cool, so just to clarify it won't work to do something like:\n\n``` python\n\nclass VideoViewOne(Video):\n class Meta:\n db_table = 'video_view_one'\n\nclass VideoViewTwo(Video):\n class Meta:\n db_table = 'video_view_two'\n```\n\nAnd then:\n\n``` python\n\nVideoViewOne.select() # <--- pull video objects out of the view \"video_view_one\"\n```\n",
"Oh... um.... yeah that might work. I think I will need to see how that plays with my flask-peewee setup. Thanks for the tip.\n",
"Just wanted to say I finally made the jump to your 2.0 release. Really nice. I really like the changes to the query language. I also was able to kill my fork and extend flask-peewee with my JSONField stuff pretty easily.\n\nThanks for a nice set of frameworks.\n"
] | 2012-10-04T03:16:00 | 2012-11-10T04:09:48 | 2012-10-05T19:51:54 | CONTRIBUTOR | null | I am writing some queries that are beyond what peewee can/should do. Specifically I need to be able to union together a result set. I figured I would just create a view, and then somehow set that view into the SelectQuery. I think that would be a really nice simple option, where you just use the view name in place of
```
self.model._meta.db_table
```
I ended up subclassing, but it isn't easy since the clone method always creates a new instance of SelectQuery, so each call to .where, etc, ends up getting rid of my subclass. Would also be nice if clone could use the current class name to create the instance, so I could just override clone, call super, and then copy the viewname as well.
It also isn't easy b/c sql_meta uses db_table directly
```
table = self.qn(self.model._meta.db_table)
```
vs calling a method like get_table or something that could be overridden.
I think it makes more sense though just to support an optional "view" parameter?
Thanks for any feedback.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/112/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/112/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/111 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/111/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/111/comments | https://api.github.com/repos/coleifer/peewee/issues/111/events | https://github.com/coleifer/peewee/issues/111 | 7,334,558 | MDU6SXNzdWU3MzM0NTU4 | 111 | Use database column defaults | {
"login": "obensonne",
"id": 121881,
"node_id": "MDQ6VXNlcjEyMTg4MQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/121881?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/obensonne",
"html_url": "https://github.com/obensonne",
"followers_url": "https://api.github.com/users/obensonne/followers",
"following_url": "https://api.github.com/users/obensonne/following{/other_user}",
"gists_url": "https://api.github.com/users/obensonne/gists{/gist_id}",
"starred_url": "https://api.github.com/users/obensonne/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/obensonne/subscriptions",
"organizations_url": "https://api.github.com/users/obensonne/orgs",
"repos_url": "https://api.github.com/users/obensonne/repos",
"events_url": "https://api.github.com/users/obensonne/events{/privacy}",
"received_events_url": "https://api.github.com/users/obensonne/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I am aware of the DRY issues, which is why I doc'd it and mentioned my reasons for defining defaults in python.\n\nAs to your question, the InsertQuery behaves correctly but `create` is apparently adding everyting regardless of whether you specify it or not. I will take a look into making create behave more like insert, as I think you're right about letting the db handle it where possible.\n\n``` python\n\nIn [1]: from peewee import *\n\nIn [2]: class Example(Model):\n ...: f1 = IntegerField(default=1)\n ...: f2 = CharField(default='hello')\n ...: f3 = CharField()\n ...: f4 = IntegerField()\n ...: \n\nIn [3]: Example.insert().sql()\nOut[3]: ('INSERT INTO \"example\" (\"f1\",\"f2\") VALUES (?,?)', [1, u'hello'])\n\nIn [4]: Example.insert(f3='bar').sql()\nOut[4]: \n('INSERT INTO \"example\" (\"f1\",\"f2\",\"f3\") VALUES (?,?,?)',\n [1, u'hello', u'bar'])\n```\n",
"Thanks for the quick response.\n\nIndeed the query returned by `insert()` is what I'd expect. Would be great if `create()` has a similar behavior.\n\nDo you plan to work on this on your own or do you prefer a patch/pull request.\n",
"Unfortunately this issue is not resolved yet.\n\nWhile `Model.create()` now works as exepected, `Model.save()` still creates an update query with all defined fields. Here it would be useful if only fields actually set are be included in the query. I can think of 2 solutions:\n1. Either use a special `unset` value (next to `None`) to distinguish not specified and `NULL` values, or\n2. Implement a `Model.__setattr__()` method which keeps track of set fields. Then, only these set fields plus the ones passed to the model constructor plus fields with defined defaults are used for the corresponding update query.\n\nOf course this is only needed for model instances created by `Model(**query)`, not for instances retrieved from database queries.\n\nI guess this is a bit more tricky. I know I could use `Model.update(...).execute()`, but setting fields with attribute-style access is much more convinient.\n",
"This is all working in branch unstable/2.0 for what its worth.\n\nFixing in current will require using sentinel values most likely. If you want to patch it I can merge something, but since its working in the latest branch I'll probably pass for now on writing it myself.\n",
"Great to hear that this already works in 2.0. I did not test it yet but I guess the unstable branch is just fine for me (instead of patchng 1.0). How _experimental_ is the unstable branch?\n",
"Weeelllll, pretty. The API is not too different, but i haven't yet upgraded flask-peewee or wtf-peewee to work with it. Soon i'm going to merge it into master, just need to get everything documented.\n"
] | 2012-10-03T21:01:48 | 2012-10-08T14:12:42 | 2012-10-08T14:12:42 | NONE | null | The [peewee documentation says](https://peewee.readthedocs.org/en/latest/peewee/fields.html?highlight=default#a-note-on-validation):
_Both default and choices could be implemented at the database level as DEFAULT and CHECK CONSTRAINT respectively, but any application change would require a schema change. Because of this, default is implemented purely in python and choices are not validated but exist for metadata purposes only._
I understand this is useful when peewee is used as the main place to define a DB schema. However, in some cases it perfectly makes sense to define certain logic (like default values) on the DB level. Especially when a database is used by multiple applications, not only by an application which uses peewee for DB interaction. In such a case the schema definition usually is done outside of peewee. Here is a conflict with the DRY principle: default values have to be specified when a schema is defined _and_ in peewee models.
For instance, when I create and save a model with peewee, I would expect it to construct insert statements which only use columns explicitly specified in `Model.create(...)` or which have explicit default values in the model definition (e.g. `foo = IntegerField(default=1)`). All other, not specified attributes (i.e. columns) simply should not be used in insert statements, which practically lets the DB check for integrity errors and/or use default values defined by the schema.
Am I right that peewee does not support such partial insert statements? If yes, what about adding such a functionality?
Regards,
Oben
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/111/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/111/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/110 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/110/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/110/comments | https://api.github.com/repos/coleifer/peewee/issues/110/events | https://github.com/coleifer/peewee/issues/110 | 7,268,077 | MDU6SXNzdWU3MjY4MDc3 | 110 | Support for group_by and count aggregate on two or more different table cloumns. | {
"login": "zffl",
"id": 186776,
"node_id": "MDQ6VXNlcjE4Njc3Ng==",
"avatar_url": "https://avatars.githubusercontent.com/u/186776?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/zffl",
"html_url": "https://github.com/zffl",
"followers_url": "https://api.github.com/users/zffl/followers",
"following_url": "https://api.github.com/users/zffl/following{/other_user}",
"gists_url": "https://api.github.com/users/zffl/gists{/gist_id}",
"starred_url": "https://api.github.com/users/zffl/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/zffl/subscriptions",
"organizations_url": "https://api.github.com/users/zffl/orgs",
"repos_url": "https://api.github.com/users/zffl/repos",
"events_url": "https://api.github.com/users/zffl/events{/privacy}",
"received_events_url": "https://api.github.com/users/zffl/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Yeah...its weird, i'm not in love with the api...but here's how you do it:\n\n``` python\n\nC.select({A: ['c1'], C: ['c4', Count('id')]}).group_by('c4').join(B).join(A).group_by('c1')\n```\n1. First we select the columns -- you had that part right except you were just missing the Count('id') in the list of \"C\" columns. `from peewee import Count`\n2. Then while the \"query context\" is \"C\", we'll group by `c4`\n3. Then join from c -> b, b -> a\n4. Now the query context is \"A\", we'll group by `c1`\n\nThis yields:\n\n``` sql\n\nSELECT t1.\"c4\", COUNT(t1.\"id\") AS count, t3.\"c1\"\nFROM \"c\" AS t1 \nINNER JOIN \"b\" AS t2 ON t1.\"c3_id\" = t2.\"id\"\nINNER JOIN \"a\" AS t3 ON t2.\"c2_id\" = t3.\"id\" \nGROUP BY t1.\"c4\", t3.\"c1\"\n```\n\nI'm working on a rewrite of peewee in branch unstable/2.0 -- it will improve on some of these inconsistencies.\n"
] | 2012-10-01T16:12:48 | 2012-10-02T13:37:44 | 2012-10-02T13:37:44 | NONE | null | I have this:
``` python
class A(Model):
c1 = CharField()
class B(Model):
c2 = ForeignKeyField(A)
class C(Model):
c3 = ForeignKeyField(B)
c4 = CharField()
```
I want to group by A.c1 and C.c4, and count C.id
and my query like this:
``` python
C.select({A:['c1'], C:['c4']}).filter(c3__c2__c1__in=[]).group_by('t1.c4, t3.c1')
```
Two problems here:
1.I don't know where to put the count aggregate? I try the select dict, count() function, but failed.
2.The group clause is weird. I can only use the alias. Any other solution?
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/110/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/110/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/109 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/109/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/109/comments | https://api.github.com/repos/coleifer/peewee/issues/109/events | https://github.com/coleifer/peewee/issues/109 | 7,186,934 | MDU6SXNzdWU3MTg2OTM0 | 109 | Access to ForeignKeyField's related_name attribute from another process? | {
"login": "davidthewatson",
"id": 150892,
"node_id": "MDQ6VXNlcjE1MDg5Mg==",
"avatar_url": "https://avatars.githubusercontent.com/u/150892?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/davidthewatson",
"html_url": "https://github.com/davidthewatson",
"followers_url": "https://api.github.com/users/davidthewatson/followers",
"following_url": "https://api.github.com/users/davidthewatson/following{/other_user}",
"gists_url": "https://api.github.com/users/davidthewatson/gists{/gist_id}",
"starred_url": "https://api.github.com/users/davidthewatson/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/davidthewatson/subscriptions",
"organizations_url": "https://api.github.com/users/davidthewatson/orgs",
"repos_url": "https://api.github.com/users/davidthewatson/repos",
"events_url": "https://api.github.com/users/davidthewatson/events{/privacy}",
"received_events_url": "https://api.github.com/users/davidthewatson/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"This sounds very evil.\n",
"Without sounding pedantic, could you elaborate on the ambiguous pronoun \"this\"? That is, are you saying that model sharing across processes is evil or that attribute level model accessor affordances existing across processes is evil? If so, why? This seemed like a perfectly reasonable use of peewee to me.\n",
"a peewee model is just a class...changes made in one python interpreter will not affect another interpreter process. if you need to, shuffle messages around via IPC that do the attribute manipulation.\n\ni said it was evil because a related_name is really an internal API used by code, so i was confused why code would need to change it.\n",
"when you get a chance, please update me with the status of this or provide more info so i can help resolve\n",
"In the example below, D is the model class representing the related_name d which was being used to access the values from the downstream process. This is, of course, broken, as you pointed out, because the downstream process hasn't manifested the attributes like the upstream process. Thus, this breaks because the related_name attribute d doesn't exist:\n\na.b.c.d[0].e\n\nThe solution is to use a get query in place of the missing related_name attribute:\n\nD.get(c=self.a.b.c).e\n\nwhich works fine.\n\nThis is, of course, writ large to show the relationships. The actual code uses functional shorthand to flatten the joins. \n\nI thought this might be a useful piece of documentation. Perhaps obvious, but wasn't immediately apparent to me until I thought through the related_name issue. It seemed from your earlier answer that related_name may be intended for internal use only. Should I never be using related_name attributes outside the model they're defined in?\n\nI wanted to point this out, because, while my use of peewee maybe somewhat beyond its intended usage, these things can and do work. And I love peewee!\n",
"Hmm... I suppose I'm still not 100% sure what the related name issue is. Can we talk about two of my favorite models, User and tweet (which Fks to user)?\n\n``` python\n\nclass User(Model):\n username = CharField()\n\nclass Tweet(Model):\n user = ForeignKeyField(User, related_name='tweets')\n message = CharField()\n```\n\nCan you show me, using those two models, the issue?\n",
"Yeah, no problem.\n\nThe first process creates a user which has associated tweets. The second process needs to act on a user's associated tweets but the tweets related_name doesn't exist:\n\nProcess #1: \n\nuser.tweets\n\nProcess #2:\nuser = User.get(username=\"charlie\")\nTweet.get(user=user)\n",
"closing for now\n"
] | 2012-09-27T14:50:24 | 2014-10-01T20:16:47 | 2012-10-11T23:39:39 | NONE | null | I have several processes that share the same peewee models. One of those processes manipulates data which effects a ForeignKeyField's related_name attribute which is then later accessed by another process. However, accessing the attribute throws a missing attribute exception from the downstream process. Is it possible to instantiate this attribute in the second process? If so, how?
Thanks.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/109/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/109/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/108 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/108/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/108/comments | https://api.github.com/repos/coleifer/peewee/issues/108/events | https://github.com/coleifer/peewee/issues/108 | 6,910,029 | MDU6SXNzdWU2OTEwMDI5 | 108 | Postgresql with pk_col='ID' reported "doesn't exist" | {
"login": "widoyo",
"id": 43075,
"node_id": "MDQ6VXNlcjQzMDc1",
"avatar_url": "https://avatars.githubusercontent.com/u/43075?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/widoyo",
"html_url": "https://github.com/widoyo",
"followers_url": "https://api.github.com/users/widoyo/followers",
"following_url": "https://api.github.com/users/widoyo/following{/other_user}",
"gists_url": "https://api.github.com/users/widoyo/gists{/gist_id}",
"starred_url": "https://api.github.com/users/widoyo/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/widoyo/subscriptions",
"organizations_url": "https://api.github.com/users/widoyo/orgs",
"repos_url": "https://api.github.com/users/widoyo/repos",
"events_url": "https://api.github.com/users/widoyo/events{/privacy}",
"received_events_url": "https://api.github.com/users/widoyo/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Can you share your model code with me? Just the class definition should be fine. If you can get me the SQL create table query as well that you ran that'd be great (ModelClass.create_table_query() i think). Were these models autogenerated by peewee or were they pre-existing?\n",
"I'm not sure if you have tried this, but you might write:\n\n``` python\nclass MyModel(db.Model):\n ID = PrimaryKeyField()\n some_field = CharField()\n```\n\nThat should work correctly, and in my testing locally appears to do the right thing.\n",
"I use pre existing database, I use Gammu with postgresql database.\n\n...sql\n-- Table: sentitems\n\n-- DROP TABLE sentitems;\n\nCREATE TABLE sentitems\n(\n \"ID\" serial NOT NULL,\n \"UDH\" text NOT NULL,\n \"SMSCNumber\" character varying(20) NOT NULL DEFAULT ''::character varying,\n \"Class\" integer NOT NULL DEFAULT (-1),\n \"TextDecoded\" text NOT NULL DEFAULT ''::text,\n \"SenderID\" character varying(255) NOT NULL,\n \"SequencePosition\" integer NOT NULL DEFAULT 1,\n \"Status\" character varying(255) NOT NULL DEFAULT 'SendingOK'::character\nvarying,\n \"StatusError\" integer NOT NULL DEFAULT (-1),\n \"TPMR\" integer NOT NULL DEFAULT (-1),\n \"RelativeValidity\" integer NOT NULL DEFAULT (-1),\n \"CreatorID\" text NOT NULL,\n id_folder integer NOT NULL DEFAULT 3,\n)\n...\n\nAnd my model is\n\n...python\nclass Sent(db.Model, PgModel):\n ID = pw.PrimaryKeyField()\n body = pw.TextField(db_column='TextDecoded')\n destination = pw.CharField(max_length=20, db_column='DestinationNumber')\n\n```\nclass Meta:\n db_table = 'sentitems'\n```\n\n...\n\nand the error is:\n\n```\npsycopg2.ProgrammingError\n\nProgrammingError: column \"id\" does not exist LINE 1: SELECT COUNT(ID) FROM\n\"sentitems\" ^\n```\n\nWhen I rename column 'ID' into 'id' there is no \"programming error\".\nThe programming error is because of \"SELECT COUNT(ID) FROM ...\", it is not\nerror when \"SELECT COUNT('ID') FROM ...\", I have tried from SQL command on\nPostgresql.\n\nOn Mon, Sep 17, 2012 at 11:35 PM, Charles Leifer\[email protected]:\n\n> Can you share your model code with me? Just the class definition should be\n> fine. If you can get me the SQL create table query as well that you ran\n> that'd be great (ModelClass.create_table_query() i think). Were these\n> models autogenerated by peewee or were they pre-existing?\n\n## \n\nWidoyo\n",
"Hmm -- something strange is going on. Is it only SELECT COUNT() queries that don't work? Is the SQL you pasted generated by dumping your existing database, or is it something else? I'm curious to see exactly what your _current_ database schema looks like\n",
"The problem could be on the postgresql with column named ID. Sql generated\nfrom pgadminIII\n"
] | 2012-09-17T04:22:31 | 2012-09-18T17:25:04 | 2012-09-17T19:15:09 | NONE | null | I have a primary column named 'ID' (UPPERCASE). Executing SQL into Postgresql "SELECT COUNT(ID) FROM inbox" postgresql reported "column doesn't exist". But it is return as expected when my SQL "SELECT COUNT('id') FROM inbox".
I found the problem when using flask-peewee that the error ofound at peewee.py line 1410.
The problem doesn't occur when I change column name from 'ID' into 'id'.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/108/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/108/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/107 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/107/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/107/comments | https://api.github.com/repos/coleifer/peewee/issues/107/events | https://github.com/coleifer/peewee/issues/107 | 6,740,806 | MDU6SXNzdWU2NzQwODA2 | 107 | Default value no work in Model.insert().execute() | {
"login": "zffl",
"id": 186776,
"node_id": "MDQ6VXNlcjE4Njc3Ng==",
"avatar_url": "https://avatars.githubusercontent.com/u/186776?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/zffl",
"html_url": "https://github.com/zffl",
"followers_url": "https://api.github.com/users/zffl/followers",
"following_url": "https://api.github.com/users/zffl/following{/other_user}",
"gists_url": "https://api.github.com/users/zffl/gists{/gist_id}",
"starred_url": "https://api.github.com/users/zffl/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/zffl/subscriptions",
"organizations_url": "https://api.github.com/users/zffl/orgs",
"repos_url": "https://api.github.com/users/zffl/repos",
"events_url": "https://api.github.com/users/zffl/events{/privacy}",
"received_events_url": "https://api.github.com/users/zffl/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"When you initialize a model instance, it will initialize fields to their default values, e.g.:\n\n``` python\n\n>>> from tests import *\n>>> dv = DefaultVals() # <-- pub date defaults to datetime.datetime.now\n>>> dv.pub_date\ndatetime.datetime(2012, 9, 9, 11, 31, 37, 797693)\n```\n\nWhen you call `save()` it rounds up all the field values on the instance and passes them along to the insert query.\n\nHowever when using `insert` directly it will only use the values you pass in explicitly. This is not explicitly by design. I'll have to think on whether to keep the current behavior (insert is explicit and ignores defaults) or whether it will implicitly fill in missing values with the field defaults.\n",
"Insert will now respect defaults when they are not specified\n",
"I think this fix might have been un-fixed.\n\n```\nm = DatModel()\nm.foo = None\nm.save()\n```\n\nThis results in an Integrity error (NOT NULL constraint failed) if `DatModel.foo` has `null=False`.\n\nI already found out that in the current version in pip, nothing besides `Model.__init__` calls `ModelOptions.get_default_dict` (The fix introduced a call to it in `InsertQuery.__init__`).\n",
"I'm not sure I'm understanding correctly, because if you explicitly set foo to None, peewee will not override it. Given that, makes sense to me there would follow an exception if foo was not null.\n",
"Oh, but I see your point in reference to this particular issue and the way it was resolved.\n\nSo, to clarify, the fix should still be in place. Check out InsertQuery._iter_rows(). Basically it's applying defaults there. But when you are working with a model and explicitly set a field to a value, that takes precedence over a default.\n",
"Thanks for the clarification. But now I'm wondering what the correct way of setting the value of a field (of a previously existing instance, so UPDATE) back to its default. Do I have to manually evaluate `DatModel.datfield._meta.default` or is there a way to make peewee do it?\n",
"Just do: obj.field = ModelClass.field.default (add parentheses if it's a callable).\n"
] | 2012-09-09T07:40:16 | 2016-09-07T02:32:42 | 2012-09-09T16:51:04 | NONE | null | I add default value for datetime field, but not work in this case, but It work by writing m =Model(..); m.save(). Is this a problem or by design?
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/107/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/107/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/106 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/106/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/106/comments | https://api.github.com/repos/coleifer/peewee/issues/106/events | https://github.com/coleifer/peewee/issues/106 | 6,457,197 | MDU6SXNzdWU2NDU3MTk3 | 106 | Problem with flask debug mode and automatic restart | {
"login": "mrjoes",
"id": 179880,
"node_id": "MDQ6VXNlcjE3OTg4MA==",
"avatar_url": "https://avatars.githubusercontent.com/u/179880?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/mrjoes",
"html_url": "https://github.com/mrjoes",
"followers_url": "https://api.github.com/users/mrjoes/followers",
"following_url": "https://api.github.com/users/mrjoes/following{/other_user}",
"gists_url": "https://api.github.com/users/mrjoes/gists{/gist_id}",
"starred_url": "https://api.github.com/users/mrjoes/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/mrjoes/subscriptions",
"organizations_url": "https://api.github.com/users/mrjoes/orgs",
"repos_url": "https://api.github.com/users/mrjoes/repos",
"events_url": "https://api.github.com/users/mrjoes/events{/privacy}",
"received_events_url": "https://api.github.com/users/mrjoes/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I found this in documentation: http://peewee.readthedocs.org/en/latest/peewee/cookbook.html#multi-threaded-applications but in Flask autoreload case, I'm not using threads. Can use these options to work around it though.\n",
"Looks like the werkzeug debugger uses multiple threads:\n\nhttps://github.com/mitsuhiko/werkzeug/blob/master/werkzeug/serving.py#L585\n\nTo suppress these errors you can configure your database `threadlocals=True` or use the sqlite driver's `check_same_thread=False`\n",
"`check_same_thread=False` is useful.\n"
] | 2012-08-26T08:01:34 | 2016-08-31T05:23:04 | 2012-08-26T14:45:22 | NONE | null | Hi,
I have following code:
``` python
from flask import Flask
import peewee
app = Flask(__name__)
app.config['SECRET_KEY'] = '123456790'
db = peewee.SqliteDatabase('test.sqlite')
class BaseModel(peewee.Model):
class Meta:
database = db
class User(BaseModel):
username = peewee.CharField(max_length=80)
email = peewee.CharField(max_length=120)
def __unicode__(self):
return self.username
class Post(BaseModel):
title = peewee.CharField(max_length=120)
text = peewee.TextField(null=False)
date = peewee.DateTimeField()
user = peewee.ForeignKeyField(User)
def __unicode__(self):
return self.title
@app.route('/')
def index():
for p in Post.select():
print p
return '<a href="/admin/">Click me to get to Admin!</a>'
if __name__ == '__main__':
try:
User.create_table()
Post.create_table()
except:
pass
app.debug = True
app.run('0.0.0.0', 8000)
```
and whenever I try to open index view, I get following exception: SQLite objects created in a thread can only be used in that same thread.The object was created in thread id 7052 and this is thread id 884.
This issue happens only when debug set to True and at least one restart happened.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/106/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/106/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/105 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/105/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/105/comments | https://api.github.com/repos/coleifer/peewee/issues/105/events | https://github.com/coleifer/peewee/issues/105 | 6,345,172 | MDU6SXNzdWU2MzQ1MTcy | 105 | Migrations | {
"login": "jamorton",
"id": 18852,
"node_id": "MDQ6VXNlcjE4ODUy",
"avatar_url": "https://avatars.githubusercontent.com/u/18852?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/jamorton",
"html_url": "https://github.com/jamorton",
"followers_url": "https://api.github.com/users/jamorton/followers",
"following_url": "https://api.github.com/users/jamorton/following{/other_user}",
"gists_url": "https://api.github.com/users/jamorton/gists{/gist_id}",
"starred_url": "https://api.github.com/users/jamorton/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/jamorton/subscriptions",
"organizations_url": "https://api.github.com/users/jamorton/orgs",
"repos_url": "https://api.github.com/users/jamorton/repos",
"events_url": "https://api.github.com/users/jamorton/events{/privacy}",
"received_events_url": "https://api.github.com/users/jamorton/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"If you take a look at the Database class, there are some undocumented methods that may be of help:\n\nhttps://github.com/coleifer/peewee/blob/master/peewee.py#L456\n\nSay you're renaming a field... from 'foo' to 'bar':\n\n`database.execute(database.rename_column_sql(FooModel, 'foo', 'bar'))`\n\nI'll see about getting this into the docs.\n"
] | 2012-08-21T08:40:33 | 2013-05-28T01:11:05 | 2012-08-21T14:47:44 | NONE | null | Just curious if you have thought about migrations in peewee. If not an automated way, is there an idiomatic way to do it with peewee besides changing fields and guessing the needed SQL statements to reflect them?
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/105/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/105/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/104 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/104/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/104/comments | https://api.github.com/repos/coleifer/peewee/issues/104/events | https://github.com/coleifer/peewee/issues/104 | 6,250,764 | MDU6SXNzdWU2MjUwNzY0 | 104 | PeeWee doesn't play nice with pylint (or vice-versa) | {
"login": "diwakergupta",
"id": 15990,
"node_id": "MDQ6VXNlcjE1OTkw",
"avatar_url": "https://avatars.githubusercontent.com/u/15990?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/diwakergupta",
"html_url": "https://github.com/diwakergupta",
"followers_url": "https://api.github.com/users/diwakergupta/followers",
"following_url": "https://api.github.com/users/diwakergupta/following{/other_user}",
"gists_url": "https://api.github.com/users/diwakergupta/gists{/gist_id}",
"starred_url": "https://api.github.com/users/diwakergupta/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/diwakergupta/subscriptions",
"organizations_url": "https://api.github.com/users/diwakergupta/orgs",
"repos_url": "https://api.github.com/users/diwakergupta/repos",
"events_url": "https://api.github.com/users/diwakergupta/events{/privacy}",
"received_events_url": "https://api.github.com/users/diwakergupta/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Peewee uses metaclasses to give you \"declarative\" models. Your models and the fields you define as class attributes are valuable metadata and I cribbed the notion of using a metaclass to introspect these. It would be arguably more pythonic to do it differently, but this is the API I have chosen. You can see the details:\n\nhttps://github.com/coleifer/peewee/blob/master/peewee.py#L2566\n",
"I'm not contesting the way Peewee does things. I'm merely asking if there's\nany way to make pylint + peewee happy short of disabling that error (which\ncan mask legit bugs in other code)\n\nOn Fri, Aug 17, 2012 at 6:42 AM, Charles Leifer [email protected]:\n\n> Peewee uses metaclasses to give you \"declarative\" models. Your models and\n> the fields you define as class attributes are valuable metadata and I\n> cribbed the notion of using a metaclass to introspect these. It would be\n> arguably more pythonic to do it differently, but this is the API I have\n> chosen. You can see the details:\n> \n> https://github.com/coleifer/peewee/blob/master/peewee.py#L2566\n> \n> —\n> Reply to this email directly or view it on GitHubhttps://github.com/coleifer/peewee/issues/104#issuecomment-7818122.\n\n## \n\nhttp://floatingsun.net\n",
"Ahh, totally -- I am not very familiar with pylint so I'm not sure what hooks it provides to say \"i know what i'm doing here\". If you come up with a patch I'd consider merging.\n",
"This may be helpful http://stackoverflow.com/questions/115977/using-pylint-with-django\n"
] | 2012-08-15T20:56:17 | 2012-08-18T13:03:58 | 2012-08-17T13:42:47 | NONE | null | PeeWee modifies the model classes at RunTime. pylint doesn't like this and I get errors like:
```
E:123,15:Benchmark.add_run_data: Class 'RunData' has no 'DoesNotExist' member
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/104/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/104/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/103 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/103/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/103/comments | https://api.github.com/repos/coleifer/peewee/issues/103/events | https://github.com/coleifer/peewee/issues/103 | 6,035,334 | MDU6SXNzdWU2MDM1MzM0 | 103 | if a table join another table twice, the query cannot be done. | {
"login": "zffl",
"id": 186776,
"node_id": "MDQ6VXNlcjE4Njc3Ng==",
"avatar_url": "https://avatars.githubusercontent.com/u/186776?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/zffl",
"html_url": "https://github.com/zffl",
"followers_url": "https://api.github.com/users/zffl/followers",
"following_url": "https://api.github.com/users/zffl/following{/other_user}",
"gists_url": "https://api.github.com/users/zffl/gists{/gist_id}",
"starred_url": "https://api.github.com/users/zffl/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/zffl/subscriptions",
"organizations_url": "https://api.github.com/users/zffl/orgs",
"repos_url": "https://api.github.com/users/zffl/repos",
"events_url": "https://api.github.com/users/zffl/events{/privacy}",
"received_events_url": "https://api.github.com/users/zffl/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"This issue goes more-or-less to some of the core assumptions I made -- many things are simpler if multiple joins to the same table aren't allowed -- for example:\n- in a complex query, the columns you select are represented as a dictionary keyed by model. if a model appears twice (i.e. is joined on twice) how do you represent which to select from?\n- when multiple models are joined on how do you express which you are querying in the where clause?\n\nI don't think I'll be able to fix this anytime soon, in other words. Sorry! Looks like sqa can do this but is kinda hacky: http://stackoverflow.com/questions/5780516/how-to-join-detail-twice-on-a-master-in-sqlalchemy\n",
"One year on, it this still the case? I thought the Alias capability which allows for self joins would cause a new table alias to be created, but it doesn't appear to be the case.\n",
"I see now that it works if you use the aliased model in a join, but it can't be used as the root of a select query.\n",
"Correct -- you should be able to construct joins with aliased models, but not actually select them. OK to close this out?\n"
] | 2012-08-05T07:48:52 | 2013-11-02T03:31:54 | 2013-11-02T03:31:54 | NONE | null | Code as follow:
``` python
class A(db.Model):
f1 = CharField()
f2 = CharField()
f3 = CharField()
class B(db.Model):
f1 = ForeignKeyField(A)
f2 = ForeignKeyField(A)
f3 = CharField()
q = {A:['*'],
B:['f1'],
B:['f1'],
}
SelectQuery(B,q).join(A, on='f1').switch(B).join(A, on='f2')
```
I also try alias , not work either.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/103/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/103/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/102 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/102/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/102/comments | https://api.github.com/repos/coleifer/peewee/issues/102/events | https://github.com/coleifer/peewee/pull/102 | 5,956,022 | MDExOlB1bGxSZXF1ZXN0MTkzOTc4Ng== | 102 | Add support for querying models by primary-key value | {
"login": "tmoertel",
"id": 21773,
"node_id": "MDQ6VXNlcjIxNzcz",
"avatar_url": "https://avatars.githubusercontent.com/u/21773?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/tmoertel",
"html_url": "https://github.com/tmoertel",
"followers_url": "https://api.github.com/users/tmoertel/followers",
"following_url": "https://api.github.com/users/tmoertel/following{/other_user}",
"gists_url": "https://api.github.com/users/tmoertel/gists{/gist_id}",
"starred_url": "https://api.github.com/users/tmoertel/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/tmoertel/subscriptions",
"organizations_url": "https://api.github.com/users/tmoertel/orgs",
"repos_url": "https://api.github.com/users/tmoertel/repos",
"events_url": "https://api.github.com/users/tmoertel/events{/privacy}",
"received_events_url": "https://api.github.com/users/tmoertel/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"There is a small problem in the implementation, which is that it does not take into account non-integer primary keys. That could be worked around though. I agree with this patch from the point-of-view that it simplifies the API but am not sure if it is worth changing the behavior of the entire `where` method (which calls `parseq`) to allow \"naked\" values to be passed in and implicitly taken to express `== <pk>`. I would suggest, if you want this, to implement a `get_pk` method on `Model`.\n",
"Thanks for your feedback.\n\nLeaving aside for the moment non-integer primary keys, which I'll be happy to fix, let's assume that we add `get_pk`. Even if we have this method, won't we still need the equivalent for `where` filtering and the like?\n\nFor example, consider the following code, in which we want to get a blog entry given by an entry identifier, provided that the entry is owned by the blog that matches a given blog identifier and that the blog is owned by the currently logged in user:\n\n``` python\nclass User(Model):\n \"\"\"A person who can own blogs.\"\"\"\n # more fields here\n\nclass Blog(Model):\n \"\"\"A blog, which can own entries.\"\"\"\n owner = ForeignKeyField(User)\n # more fields here\n\nclass Entry(Model):\n \"\"\"A post to a blog.\"\"\"\n blog = ForeignKeyField(Blog)\n # more fields here\n\n\ndef read_entry(user, blog_id, entry_id):\n \"\"\"Handle request for /blog/<blog_id>/entry/<entry_id>.\n\n Args:\n user: Authenticated User-model instance for the logged-in user.\n blog_id: Blog identifier from URL.\n entry_id: Entry identifier from URL.\n\n Returns:\n Rendered HTML.\n\n Raises:\n Abort(404): if no such blog entry is visible to the user.\n\n \"\"\"\n query = (Entry.select().where(id=entry_id)\n .join(Blog).where(id=blog_id, owner=user))\n try:\n entry = query.get()\n except Entry.DoesNotExist:\n raise Abort(404)\n return render(\"entry\", entry=entry)\n```\n\nIt's easy to write this kind of code for specific model instances, where you know the names of all the primary keys in advance. But for generic code that gets passed Entry-like models and Blog-like models and their respective instance identifiers at run time, you can't write the code (reliably) without having it pry into peewee's internals to find what the models' primary keys are called:\n\n``` python\ndef read_general_entry(user, blog_model, blog_id, entry_model, entry_id):\n blog_pkname = blog_model._meta.pk_name\n entry_pkname = entry_model._meta.pk_name\n query = (Entry.select().where(**{entry_pkname: entry_id})\n .join(Blog).where(owner=user, **{blog_pkname: blog_id}))\n # the rest as before\n```\n\nWithout something like the change I'm proposing, is there any clean way to solve problems like the above from user code?\n\nAs an alternative to \"naked\" identifier values, would you be more agreeable to adding a PK class that could be used wherever Q could? So you could write\n\n``` python\nentry = entry_model.get(PK(entry_id))\nentry = entry_model.select().where(PK(entry_id).join(blog_model).where(PK(blog_id), user=user)\n```\n\nThoughts?\n",
"While all of your suggestions have merit, I think I'm going to pass for now on adding something like this. Adding yet another method of querying to the (already large) available methods seems like a bad plan. _\"Syntactic sugar causes cancer of the semicolon\"_.\n",
"Thanks for your response.\n\nCan I ask a favor? Given the current API, how would you recommend that I write model-generic code? (I can't figure out how to do it without prying into peewee's implementation internals (or requiring that all models use the same primary-key name). Am I missing something?)\n",
"If you take a look here, https://github.com/coleifer/flask-peewee/blob/master/flask_peewee/admin.py#L142\n\nBasically, you're right:\n\n``` python\n\ndef get_pk(klass, pk):\n return klass.get(**{klass._meta.pk_name: pk})\n```\n",
"What do you think about adding a public `get_pk_name()` method to models? It won't be super-convenient to use (`**{klass.get_pk_name(): pk}` doesn't exactly flow off the keyboard), but at least people won't have to make their code dependent upon peewee's internal implementation when they need knowledge of the primary key. That's the kind of thing that gets flagged at code reviews.\n\nBut maybe such a change would go against the grain of peewee's design? (My hunch about why there's not already something like `get_pk_name()` is that you wanted peewee to be smart enough that people wouldn't _have_ to know the names of keys: during joins and other common operations, peewee would just take care of that stuff. I figured that leaving the method off was your way of ensuring that users would come to you with those cases where peewee's current design wasn't able to be fully transparent about keys, so you could consider ways of making it transparent for those cases. All of this is to say: I'll understand if you don't want to add such a method. I wouldn't.)\n",
"i've gone ahead and added `get_pk_dict` and `get_pk_name` methods to `Model` -- added in 04dace3bc9f71d93bbbfd7ab27e74bb81b59875b and 023d481199d6cea7d1ca223e3e46535496a81368\n\nHope this helps!\n",
"Works for me :-)\n\nThanks.\n"
] | 2012-07-31T23:07:03 | 2014-07-06T01:51:40 | 2012-08-01T15:47:29 | CONTRIBUTOR | null | This (tiny!) patch allows you to query for a model instance by simply
providing its primary-key value as a query argument. You can use this
new convention anywhere Q objects are allowed, but the most-common
expected use case is this:
```
blog = Blog.get(1) # get blog w/ primary key of 1
```
Rationale.
Why this patch? In short, because it simplifies one common use-case
and eliminates the need to break encapsulation for another.
Currently, to fetch a model instance when you know its primary-key
value, you must also know its primary-key name:
```
blog = Blog.get(id=1) # relies on knowledge that Blog's pkey is "id"
```
Since the model already has this knowledge, why not just let the model
take care of it?
```
blog = Blog.get(1)
```
Moreover, when writing generic code that takes a model as a parameter,
you must pry into peewee's internals to learn what the model's primary
key is called. For example:
```
def get_required_web_model_instance(model, id):
try:
return model.get(**{model._meta.pk_name: id}) # naughty!
except model.DoesNotExist:
raise flask.abort(404)
```
If we let the model take care of the details, however, we need not
breach peewee's encapsulation barriers to write model-generic code:
```
def get_required_web_model_instance(model, id):
try:
return model.get(id) # nice!
except model.DoesNotExist:
raise flask.abort(404)
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/102/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/102/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/102",
"html_url": "https://github.com/coleifer/peewee/pull/102",
"diff_url": "https://github.com/coleifer/peewee/pull/102.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/102.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/101 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/101/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/101/comments | https://api.github.com/repos/coleifer/peewee/issues/101/events | https://github.com/coleifer/peewee/pull/101 | 5,616,326 | MDExOlB1bGxSZXF1ZXN0MTc5NTAyNA== | 101 | Support multiple annotation using different aggregates | {
"login": "ternus",
"id": 77170,
"node_id": "MDQ6VXNlcjc3MTcw",
"avatar_url": "https://avatars.githubusercontent.com/u/77170?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/ternus",
"html_url": "https://github.com/ternus",
"followers_url": "https://api.github.com/users/ternus/followers",
"following_url": "https://api.github.com/users/ternus/following{/other_user}",
"gists_url": "https://api.github.com/users/ternus/gists{/gist_id}",
"starred_url": "https://api.github.com/users/ternus/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/ternus/subscriptions",
"organizations_url": "https://api.github.com/users/ternus/orgs",
"repos_url": "https://api.github.com/users/ternus/repos",
"events_url": "https://api.github.com/users/ternus/events{/privacy}",
"received_events_url": "https://api.github.com/users/ternus/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Hi @ternus sorry I missed your messages in IRC. Will look into this today, thnx for the excellent report :)\n"
] | 2012-07-13T23:33:13 | 2014-07-06T01:51:43 | 2012-07-14T16:17:03 | CONTRIBUTOR | null | Using .annotate() multiple times on the same query fails:
``` python
annotated = Blog.select().annotate(Entry).annotate(Entry, Max('pub_date', 'max_pub'))
```
generates the SQL:
``` sql
SELECT t1."id", t1."title", MAX(t2."pub_date") AS max_pub FROM "blog" AS t1 INNER JOIN "entry" AS t2 ON t1."id" = t2."blog_id" GROUP BY t1."id", t1."title", *
```
which is a syntax error (stray \* near the end) in addition to being wrong. The SQL generated should be something like:
``` sql
SELECT t1."id", t1."title", COUNT(t2.`pk`) AS count, MAX(t2."pub_date") AS max_pub FROM "blog" AS t1 INNER JOIN "entry" AS t2 ON t1."id" = t2."blog_id" GROUP BY t1."id", t1."title"
```
I've added a test case and a fix.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/101/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/101/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/101",
"html_url": "https://github.com/coleifer/peewee/pull/101",
"diff_url": "https://github.com/coleifer/peewee/pull/101.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/101.patch",
"merged_at": "2012-07-14T16:17:03"
} |
https://api.github.com/repos/coleifer/peewee/issues/100 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/100/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/100/comments | https://api.github.com/repos/coleifer/peewee/issues/100/events | https://github.com/coleifer/peewee/issues/100 | 5,515,430 | MDU6SXNzdWU1NTE1NDMw | 100 | Required attribute for Fields | {
"login": "mkosler",
"id": 1159095,
"node_id": "MDQ6VXNlcjExNTkwOTU=",
"avatar_url": "https://avatars.githubusercontent.com/u/1159095?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/mkosler",
"html_url": "https://github.com/mkosler",
"followers_url": "https://api.github.com/users/mkosler/followers",
"following_url": "https://api.github.com/users/mkosler/following{/other_user}",
"gists_url": "https://api.github.com/users/mkosler/gists{/gist_id}",
"starred_url": "https://api.github.com/users/mkosler/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/mkosler/subscriptions",
"organizations_url": "https://api.github.com/users/mkosler/orgs",
"repos_url": "https://api.github.com/users/mkosler/repos",
"events_url": "https://api.github.com/users/mkosler/events{/privacy}",
"received_events_url": "https://api.github.com/users/mkosler/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Yes, non-nullable is the same as required. Not null means if you do not store something there, the database will complain. Adding a required would be redundant.\n",
"Well, then I think there must be a bug, because like I said, when I do this in the python shell, it doesn't yell at me. This is the model I am using for this:\n\n```\nclass User(BaseModel):\n username = CharField(unique = True)\n password = CharField(max_length = 40)\n email = CharField(unique = True)\n date_joined = DateField(default = datetime.date.today())\n website = CharField(null = True)\n logged_in = BooleanField()\n is_mod = BooleanField()\n is_admin = BooleanField()\n```\n\nBaseModel just sets the Meta class to the correct database. Here is what I run in the shell to show the issue:\n\n```\n>>> from models import *\n>>> user = User.create(username = 'test')\n>>> user.save() # redundant, but whatever\n>>> print user.password\nNone\n>>> user2 = User.get()\n>>> print user2.username\ntest\n>>> print user2.password\n\n>>> \n```\n\nFrom my understanding, the only field that should be allowed to be left blank is `website`, but I've clearly left every field besides username blank.\n\nI am using flask-script to get shell access, via `python manage.py shell`. Here's all the other libraries I am using:\n\n```\nFlask==0.9\nFlask-Script==0.3.3\nJinja2==2.6\nWTForms==1.0.1\nWerkzeug==0.8.3\nargparse==1.2.1\npasslib==1.6\npeewee==0.9.9\nwsgiref==0.1.2\n```\n",
"It appears peewee is setting it to an empty string when no value is present (as opposed to letting it fall through to the database and raising an integrity error). This is probably a bug...working on a test case\n",
"Hrm... I'm torn on this one. Looking a little closer, it appears that Field() is wrapping up the value passed to the db. It has the following check:\n\n``` python\n\n def db_value(self, value):\n if (self.null and value is None):\n return None\n return self.column.db_value(value)\n```\n\nThe column converts the value to a suitable type, e.g. VarCharColumn does `unicode(value or '')`.\n\nI'm thinking that this behavior is acceptable. The best I can say is its a gray area. If you want to store NULLs then make the field nullable, otherwise an empty string (or \"0\", etc) will be put in to avoid the integrity error.\n",
"Then could we get a required attribute at some point? If I'm using the shell as my admin interface during development, I could easily pollute my DB with inconsistent data.\n",
"Grr... i keep waffling on this.\n\nI think that the only acceptable answer is to allow NULL values to get sent back regardless, and let the integrity error happen if the field isn't null. Working on a testcase and a patch.\n"
] | 2012-07-10T04:26:04 | 2012-07-11T01:56:11 | 2012-07-11T01:56:11 | NONE | null | Newish to SQL so feel free to correct me if I can do this in some way already.
Is a field being not nullable the same as making the field required? I would figure this would be true, but doing some python shell experimenting, it seems that this is not true. I think adding a 'required' attribute to the base Field class would be nice. Throw an exception you attempt to use either `Model.create()` or `Model.save()` with an uninitialized required variable.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/100/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/100/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/99 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/99/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/99/comments | https://api.github.com/repos/coleifer/peewee/issues/99/events | https://github.com/coleifer/peewee/issues/99 | 5,410,030 | MDU6SXNzdWU1NDEwMDMw | 99 | Escaping mysql reserved words when creating foreign keys | {
"login": "jonatanfan",
"id": 1277652,
"node_id": "MDQ6VXNlcjEyNzc2NTI=",
"avatar_url": "https://avatars.githubusercontent.com/u/1277652?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/jonatanfan",
"html_url": "https://github.com/jonatanfan",
"followers_url": "https://api.github.com/users/jonatanfan/followers",
"following_url": "https://api.github.com/users/jonatanfan/following{/other_user}",
"gists_url": "https://api.github.com/users/jonatanfan/gists{/gist_id}",
"starred_url": "https://api.github.com/users/jonatanfan/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/jonatanfan/subscriptions",
"organizations_url": "https://api.github.com/users/jonatanfan/orgs",
"repos_url": "https://api.github.com/users/jonatanfan/repos",
"events_url": "https://api.github.com/users/jonatanfan/events{/privacy}",
"received_events_url": "https://api.github.com/users/jonatanfan/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"dupe of #98\n"
] | 2012-07-03T15:51:16 | 2012-07-03T16:15:10 | 2012-07-03T16:15:10 | NONE | null | Hi
Seems like reserved mysql words are not escaped when creating references for a table. Kind of a problem when a column is named `order`
Like so:
OrderProduct.create_table()
CREATE TABLE `orderproduct` (`id` INTEGER AUTO_INCREMENT NOT NULL PRIMARY KEY, `product_id` INTEGER NOT NULL REFERENCES product (id), `order_id` INTEGER NOT NULL REFERENCES order (id));
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/99/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/99/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/98 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/98/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/98/comments | https://api.github.com/repos/coleifer/peewee/issues/98/events | https://github.com/coleifer/peewee/issues/98 | 5,410,028 | MDU6SXNzdWU1NDEwMDI4 | 98 | Escaping mysql reserved words when creating foreign keys | {
"login": "jonatanfan",
"id": 1277652,
"node_id": "MDQ6VXNlcjEyNzc2NTI=",
"avatar_url": "https://avatars.githubusercontent.com/u/1277652?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/jonatanfan",
"html_url": "https://github.com/jonatanfan",
"followers_url": "https://api.github.com/users/jonatanfan/followers",
"following_url": "https://api.github.com/users/jonatanfan/following{/other_user}",
"gists_url": "https://api.github.com/users/jonatanfan/gists{/gist_id}",
"starred_url": "https://api.github.com/users/jonatanfan/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/jonatanfan/subscriptions",
"organizations_url": "https://api.github.com/users/jonatanfan/orgs",
"repos_url": "https://api.github.com/users/jonatanfan/repos",
"events_url": "https://api.github.com/users/jonatanfan/events{/privacy}",
"received_events_url": "https://api.github.com/users/jonatanfan/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2012-07-03T15:51:16 | 2012-07-03T19:03:21 | 2012-07-03T19:03:21 | NONE | null | Hi
Seems like reserved mysql words are not escaped when creating references for a table. Kind of a problem when a column is named `order`
Like so:
OrderProduct.create_table()
CREATE TABLE `orderproduct` (`id` INTEGER AUTO_INCREMENT NOT NULL PRIMARY KEY, `product_id` INTEGER NOT NULL REFERENCES product (id), `order_id` INTEGER NOT NULL REFERENCES order (id));
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/98/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/98/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/97 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/97/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/97/comments | https://api.github.com/repos/coleifer/peewee/issues/97/events | https://github.com/coleifer/peewee/pull/97 | 5,379,099 | MDExOlB1bGxSZXF1ZXN0MTY5MzE1NQ== | 97 | Fix Postgresql docstring in cookbook.rst | {
"login": "edavis",
"id": 622509,
"node_id": "MDQ6VXNlcjYyMjUwOQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/622509?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/edavis",
"html_url": "https://github.com/edavis",
"followers_url": "https://api.github.com/users/edavis/followers",
"following_url": "https://api.github.com/users/edavis/following{/other_user}",
"gists_url": "https://api.github.com/users/edavis/gists{/gist_id}",
"starred_url": "https://api.github.com/users/edavis/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/edavis/subscriptions",
"organizations_url": "https://api.github.com/users/edavis/orgs",
"repos_url": "https://api.github.com/users/edavis/repos",
"events_url": "https://api.github.com/users/edavis/events{/privacy}",
"received_events_url": "https://api.github.com/users/edavis/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Good looking out!\n"
] | 2012-07-02T03:13:34 | 2014-07-06T01:51:44 | 2012-07-02T03:29:09 | CONTRIBUTOR | null | Very minor, but thought you'd like to know.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/97/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/97/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/97",
"html_url": "https://github.com/coleifer/peewee/pull/97",
"diff_url": "https://github.com/coleifer/peewee/pull/97.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/97.patch",
"merged_at": "2012-07-02T03:29:09"
} |
https://api.github.com/repos/coleifer/peewee/issues/96 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/96/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/96/comments | https://api.github.com/repos/coleifer/peewee/issues/96/events | https://github.com/coleifer/peewee/issues/96 | 5,298,272 | MDU6SXNzdWU1Mjk4Mjcy | 96 | Database.executemany is not available | {
"login": "karlb",
"id": 144773,
"node_id": "MDQ6VXNlcjE0NDc3Mw==",
"avatar_url": "https://avatars.githubusercontent.com/u/144773?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/karlb",
"html_url": "https://github.com/karlb",
"followers_url": "https://api.github.com/users/karlb/followers",
"following_url": "https://api.github.com/users/karlb/following{/other_user}",
"gists_url": "https://api.github.com/users/karlb/gists{/gist_id}",
"starred_url": "https://api.github.com/users/karlb/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/karlb/subscriptions",
"organizations_url": "https://api.github.com/users/karlb/orgs",
"repos_url": "https://api.github.com/users/karlb/repos",
"events_url": "https://api.github.com/users/karlb/events{/privacy}",
"received_events_url": "https://api.github.com/users/karlb/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I can call db.get_cursor().executemany, of course. It just expected executemany to be usable whereever execute can be used. So this is not important at all.\n",
"Yeah, I have not implemented executemany or executescript. Many of the db-api 2.0 methods, while used internally, are not exposed -- this is intentional. If you do need them, you can do like you've suggested, get a cursor.\n"
] | 2012-06-27T14:32:33 | 2012-06-27T16:10:53 | 2012-06-27T16:10:53 | NONE | null | In some cases I like to work directly with SQL by using Database.execute. However, I don't see a way to do what the DB-API executemany method does. In this specific case I'm trying to do multiple inserts this way.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/96/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/96/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/95 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/95/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/95/comments | https://api.github.com/repos/coleifer/peewee/issues/95/events | https://github.com/coleifer/peewee/issues/95 | 5,248,654 | MDU6SXNzdWU1MjQ4NjU0 | 95 | Database Support | {
"login": "cevarief",
"id": 850737,
"node_id": "MDQ6VXNlcjg1MDczNw==",
"avatar_url": "https://avatars.githubusercontent.com/u/850737?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/cevarief",
"html_url": "https://github.com/cevarief",
"followers_url": "https://api.github.com/users/cevarief/followers",
"following_url": "https://api.github.com/users/cevarief/following{/other_user}",
"gists_url": "https://api.github.com/users/cevarief/gists{/gist_id}",
"starred_url": "https://api.github.com/users/cevarief/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/cevarief/subscriptions",
"organizations_url": "https://api.github.com/users/cevarief/orgs",
"repos_url": "https://api.github.com/users/cevarief/repos",
"events_url": "https://api.github.com/users/cevarief/events{/privacy}",
"received_events_url": "https://api.github.com/users/cevarief/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I don't know much about firebird -- will have to look into it. Currently, peewee's internal db calls rely on the driver supporting the python db-api 2.0. It looks like kinterbasdb supports this, so integration should be really easy. I was thinking personally that the next driver i'd like to look at is [apsw](http://apidoc.apsw.googlecode.com/hg/index.html), which provides much richer support for sqlite than the sqlite3 driver (virtual tables, etc). If you want to see firebird, i'd suggest taking a crack at it yourself, the implementation should be simple - take a look at the code.\n\nYou will need to implement at the very least:\n- an adapter class, which handles connecting to the database (here is [mysql](https://github.com/coleifer/peewee/blob/master/peewee.py#L224))\n- a database class that uses the given adapter (here is [mysql](https://github.com/coleifer/peewee/blob/master/peewee.py#L537))\n\nIt is unlikely i'll be adding firebird support any time soon without learning a bit more about it and its advantages over, say, postgres mysql or sqlite which seem to run the gamut from prototype to large-scale production, but if you're inclined i'd be happy to merge in your changes if you write an implementation.\n",
"I've written some docs on writing a database backend:\n\nhttp://peewee.readthedocs.org/en/latest/peewee/database.html#writing-a-database-driver\n"
] | 2012-06-25T13:32:59 | 2012-06-26T01:32:26 | 2012-06-26T01:32:26 | NONE | null | What is next database that will be supported by peewe? Any plan for firebird?
For prototyping sqlite is enough, but for portable database in production embedded firebird could give more power...
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/95/reactions",
"total_count": 1,
"+1": 1,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/95/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/94 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/94/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/94/comments | https://api.github.com/repos/coleifer/peewee/issues/94/events | https://github.com/coleifer/peewee/pull/94 | 5,219,779 | MDExOlB1bGxSZXF1ZXN0MTYzMDAyNQ== | 94 | Fixed thread_locals not actually working. | {
"login": "b1naryth1ef",
"id": 599433,
"node_id": "MDQ6VXNlcjU5OTQzMw==",
"avatar_url": "https://avatars.githubusercontent.com/u/599433?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/b1naryth1ef",
"html_url": "https://github.com/b1naryth1ef",
"followers_url": "https://api.github.com/users/b1naryth1ef/followers",
"following_url": "https://api.github.com/users/b1naryth1ef/following{/other_user}",
"gists_url": "https://api.github.com/users/b1naryth1ef/gists{/gist_id}",
"starred_url": "https://api.github.com/users/b1naryth1ef/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/b1naryth1ef/subscriptions",
"organizations_url": "https://api.github.com/users/b1naryth1ef/orgs",
"repos_url": "https://api.github.com/users/b1naryth1ef/repos",
"events_url": "https://api.github.com/users/b1naryth1ef/events{/privacy}",
"received_events_url": "https://api.github.com/users/b1naryth1ef/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"How does this come about? How is it being passed in via connect_kwargs?\n",
"Hmm, i'm kind of baffled -- where is \"self.threadlocals\" referenced? In my code it appears that it is just used in the scope of the init method, where the `__local` is instantiated. Can you explain more the rationale?\n",
"I was consistently having problems with starting an sqlite instance, and giving it the threadlocals var. Tested on both 2.6/2.7 and few os's. Looked into it, and it seems threadlocals wasnt actually being passed in under the threadlocals kwarg, but rather inside the *\\* catch all. Again, this isnt really a proper fix to it. \n",
"Ahhh never mind, I see. The `self.` isnt required. This was more of a fix of threadlocals not being passed correctly.\n",
"can you please send me your code that was not working properly so i can test it here? i've not encountered this problem myself.\n",
"```\nfrom peewee import *\nimport thread\n\ndb = SqliteDatabase('test', threadlocals=True)\ndb.connect()\n\nclass Test():\n uid = IntegerField()\n\nTest.create_table()\n\nt = Test(1)\nt.save()\n\nq = lambda: [i for i in Test.select().where(uid=1)\n\nthread.start_new_thread(q, ())\n```\n\nSomething like that.\n",
"Sorry but that code has a number of problems. you're not specifying your database when you define your model. your model doesn't subclass Model. I'm also not clear on how that demonstrates the actual issue.\n",
"Sorry wrote that on the fly. This code gives the error:\n\n```\nfrom peewee import *\nimport thread\n\ndb = SqliteDatabase('test.db', threadlocals=True)\ndb.connect()\n\nclass Test(model):\n uid = IntegerField()\n\nTest.create_table()\n\nt = Test(uid=1)\nt.save()\n\ndef testQuery():\n print [i for i in Test.select().where(uid=1)]\n\nthread.start_new_thread(testQuery, ())\n```\n\nThe example outputs this on both a Mac laptop and Linux box:\n\n```\n-1214440592\nUnhandled exception in thread started by <function testing at 0xb7bffbfc>\nTraceback (most recent call last):\n File \"<stdin>\", line 2, in testing\n File \"/usr/local/lib/python2.6/dist-packages/peewee-0.9.7-py2.6.egg/peewee.py\", line 1646, in __iter__\n return iter(self.execute())\n File \"/usr/local/lib/python2.6/dist-packages/peewee-0.9.7-py2.6.egg/peewee.py\", line 1638, in execute\n self._qr = QueryResultWrapper(self.model, self.raw_execute(sql, params), meta)\n File \"/usr/local/lib/python2.6/dist-packages/peewee-0.9.7-py2.6.egg/peewee.py\", line 1287, in raw_execute\n return self.database.execute(query, params, self.require_commit)\n File \"/usr/local/lib/python2.6/dist-packages/peewee-0.9.7-py2.6.egg/peewee.py\", line 322, in execute\n cursor = self.get_cursor()\n File \"/usr/local/lib/python2.6/dist-packages/peewee-0.9.7-py2.6.egg/peewee.py\", line 319, in get_cursor\n return self.get_conn().cursor()\nsqlite3.ProgrammingError: SQLite objects created in a thread can only be used in that same thread.The object was created in thread id -1211824448 and this is thread id -1214440592\n```\n\nThe problem is passing threadlocals into peewees Database class, as I mentioned a few comments above.\n",
"You need to tell peewee to use the database you instantiated:\n\n``` python\n\nclass Test(model):\n uid = IntegerField()\n\n class Meta:\n database = db\n```\n",
"And now I fell silly! My only note is that this is a just little unclear/ambiguous in the docs. Might consider moving the `Best Practices` up a bit, or make it more clear that its important/required. Thanks much for your help!\n",
"No sweat, mane -- i'll spruce up the docs. This works fine for me, btw:\n\n``` python\n\nfrom peewee import *\nimport threading\n\ndb = SqliteDatabase('test.db', threadlocals=True)\ndb.connect()\n\nclass Test(Model):\n uid = IntegerField()\n class Meta:\n database=db\n\nTest.create_table(True)\n\nt = Test(uid=1)\nt.save()\n\ndef testQuery():\n print [i for i in Test.select().where(uid=1)]\n\nt = threading.Thread(target=testQuery)\nt.start()\nt.join()\n```\n"
] | 2012-06-22T17:18:46 | 2014-06-12T17:04:18 | 2012-06-22T20:15:59 | NONE | null | Cheap fix that you may feel like rewriting to actually trace back to the problem. The thread_locals var was being passed in as connect_kwargs as opposed to the keyword.
Again, this is probably just a temporary fix.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/94/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/94/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/94",
"html_url": "https://github.com/coleifer/peewee/pull/94",
"diff_url": "https://github.com/coleifer/peewee/pull/94.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/94.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/93 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/93/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/93/comments | https://api.github.com/repos/coleifer/peewee/issues/93/events | https://github.com/coleifer/peewee/issues/93 | 4,961,548 | MDU6SXNzdWU0OTYxNTQ4 | 93 | choices just like django or mongoengine | {
"login": "ddorian",
"id": 1592898,
"node_id": "MDQ6VXNlcjE1OTI4OTg=",
"avatar_url": "https://avatars.githubusercontent.com/u/1592898?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/ddorian",
"html_url": "https://github.com/ddorian",
"followers_url": "https://api.github.com/users/ddorian/followers",
"following_url": "https://api.github.com/users/ddorian/following{/other_user}",
"gists_url": "https://api.github.com/users/ddorian/gists{/gist_id}",
"starred_url": "https://api.github.com/users/ddorian/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/ddorian/subscriptions",
"organizations_url": "https://api.github.com/users/ddorian/orgs",
"repos_url": "https://api.github.com/users/ddorian/repos",
"events_url": "https://api.github.com/users/ddorian/events{/privacy}",
"received_events_url": "https://api.github.com/users/ddorian/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"i'm on the fence about this, should they be implemented as a check constraint or solely in python? if you assign something that is an invalid choice, should it error out? if so, what type of error?\n",
"i checked django, it seems you can assign invalid values to a field that specifies `choices`. you can also save these invalid choices. probably just for modelform validation. so, options:\n- db-level check constraint -- bad because if you want to change your choices that means schema change\n- python-level on save\n- python-level on assignment\n- none at all, just for metadata and other libraries (flask-peewee, wtf-peewee)\n\nI'm leaning towards none at all, same as django.\n",
"Maybe it should output a warning in DEBUG mode\n",
"I've added this in commit 2d076f069baf715d6dfd0070df861f0b3f417724\n\nI've also added integration in the wtf-peewee bindings (wtforms form library integration)\nhttps://github.com/coleifer/wtf-peewee/commits/master\n\nI've also added a small example to the flask-peewee app:\nhttps://github.com/coleifer/flask-peewee/commit/225f85d68fe39c0271b7a1a00b55ede1ede7f41f\n\nFinally, there's no debug mode per se with peewee, so there's no warning\n"
] | 2012-06-07T23:17:47 | 2012-06-08T22:58:06 | 2012-06-08T22:58:06 | NONE | null | Add choices to fields like django and mongoengine.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/93/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/93/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/92 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/92/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/92/comments | https://api.github.com/repos/coleifer/peewee/issues/92/events | https://github.com/coleifer/peewee/issues/92 | 4,877,961 | MDU6SXNzdWU0ODc3OTYx | 92 | peewee 0.9.6 docs show transaction context manager, which isn't in 0.9.6 | {
"login": "rouge8",
"id": 237005,
"node_id": "MDQ6VXNlcjIzNzAwNQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/237005?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/rouge8",
"html_url": "https://github.com/rouge8",
"followers_url": "https://api.github.com/users/rouge8/followers",
"following_url": "https://api.github.com/users/rouge8/following{/other_user}",
"gists_url": "https://api.github.com/users/rouge8/gists{/gist_id}",
"starred_url": "https://api.github.com/users/rouge8/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/rouge8/subscriptions",
"organizations_url": "https://api.github.com/users/rouge8/orgs",
"repos_url": "https://api.github.com/users/rouge8/repos",
"events_url": "https://api.github.com/users/rouge8/events{/privacy}",
"received_events_url": "https://api.github.com/users/rouge8/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"thanks for catching this, i pushed a new version 0.9.7 and a new git tag.\n"
] | 2012-06-03T16:52:20 | 2012-06-04T17:04:01 | 2012-06-04T17:04:01 | CONTRIBUTOR | null | The [docs for 0.9.6](http://peewee.readthedocs.org/en/latest/peewee/cookbook.html?highlight=transaction#context-manager) show the context manager for transactions, but after installing 0.9.6 this wasn't supported.
Installing from `git:master` fixed it. Maybe time for 0.9.7?
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/92/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/92/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/91 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/91/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/91/comments | https://api.github.com/repos/coleifer/peewee/issues/91/events | https://github.com/coleifer/peewee/pull/91 | 4,873,218 | MDExOlB1bGxSZXF1ZXN0MTQ4MDUyNg== | 91 | Added auto_round and always_float attributes to DecimalField | {
"login": "applegrew",
"id": 434574,
"node_id": "MDQ6VXNlcjQzNDU3NA==",
"avatar_url": "https://avatars.githubusercontent.com/u/434574?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/applegrew",
"html_url": "https://github.com/applegrew",
"followers_url": "https://api.github.com/users/applegrew/followers",
"following_url": "https://api.github.com/users/applegrew/following{/other_user}",
"gists_url": "https://api.github.com/users/applegrew/gists{/gist_id}",
"starred_url": "https://api.github.com/users/applegrew/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/applegrew/subscriptions",
"organizations_url": "https://api.github.com/users/applegrew/orgs",
"repos_url": "https://api.github.com/users/applegrew/repos",
"events_url": "https://api.github.com/users/applegrew/events{/privacy}",
"received_events_url": "https://api.github.com/users/applegrew/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Not sure on the application of the float option, since there's a floatfield already. As far as rounding, I suppose that would be handled by the DB when you specify a precision on the column, but this might need to be looked into a little more.\n",
"- Yes there is `FloatField` but it does not allow us to define number of decimals I need, (e.g. only two for currencies). Because of dynamic nature of Python it is difficult to work with codes where there is a possibility of mixing `float` data with the `Decimal` ones. So, it is important to normalize them to one type - maybe float. Well now I agree that in such a scenario it would indicate a design issue or there should be central point where the code should convert the `Decimal` returned to `float`, but then again I don't see anyway to implement custom getters and setters in Peewee `Model` to do it centrally. I will leave this open to your good judgement.\n- DBs are responsible to accurately store the data, so if any data passed to it needs to be rounded which will result in loss of precision then it is going to throw a warning. This can happen when our `Decimal` has more decimals, or if we pass a `float`. Storing `23.221` in a `Decimal(5,2)` column in MySql throws 'Error 1265: Data truncation' warning, and I don't see any way to turn this off in DB. Even this warning is treated as error in Peewee, disrupting normal flow. By specifying `decimal_places` user has already consented with fact that he wants only that many decimals. Peewee already has enough information to lend user this helping hand. I really do not like warnings in my code. Now it can be argued that some users might want to warned about this loss. That is why I have added the `auto_round` flag to let user turn this behavior on or off. In fact it is off by default so that Peewee's current behavior do not change.\n",
"Added in 4c3af4ccc83dad38a369a1b8e3121de1d6838a7b -- thanks for the help!\n"
] | 2012-06-02T20:59:55 | 2014-07-06T01:51:53 | 2012-06-05T00:27:29 | NONE | null | - auto_round makes sure that if the value has higher precision than the
number of decimal_places then it round it to that value before send
that to db. This will save from some unexpected "Data truncation"
warnings from MySQL (http://bit.ly/bWr1mn).
- always_float makes sure that in Python code always gets the value as
float instead of Decimal. This way the return value can be easily
intermixed with other floats. Also float can be faster than Decimal.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/91/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/91/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/91",
"html_url": "https://github.com/coleifer/peewee/pull/91",
"diff_url": "https://github.com/coleifer/peewee/pull/91.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/91.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/90 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/90/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/90/comments | https://api.github.com/repos/coleifer/peewee/issues/90/events | https://github.com/coleifer/peewee/issues/90 | 4,790,001 | MDU6SXNzdWU0NzkwMDAx | 90 | follow_joins - assigns duplicate aliases during complex joins | {
"login": "sdobz",
"id": 948178,
"node_id": "MDQ6VXNlcjk0ODE3OA==",
"avatar_url": "https://avatars.githubusercontent.com/u/948178?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/sdobz",
"html_url": "https://github.com/sdobz",
"followers_url": "https://api.github.com/users/sdobz/followers",
"following_url": "https://api.github.com/users/sdobz/following{/other_user}",
"gists_url": "https://api.github.com/users/sdobz/gists{/gist_id}",
"starred_url": "https://api.github.com/users/sdobz/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/sdobz/subscriptions",
"organizations_url": "https://api.github.com/users/sdobz/orgs",
"repos_url": "https://api.github.com/users/sdobz/repos",
"events_url": "https://api.github.com/users/sdobz/events{/privacy}",
"received_events_url": "https://api.github.com/users/sdobz/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Thanks so much for the excellent bug report, I've added a fix and a testcase.\n"
] | 2012-05-29T07:32:49 | 2012-05-29T15:13:37 | 2012-05-29T15:13:17 | NONE | null | I am doing something ugly (view support) and in the process of building some automated joins I discovered that certain queries create duplicate aliases in a sql select.
``` python
from peewee import *
class Artist(Model):
artistid = CharField(size=36,unique=True)
name = CharField()
sortname = CharField()
disambiguation = CharField()
class Track(Model):
trackid = CharField(size=36,unique=True)
title = CharField()
artist = ForeignKeyField(Artist)
class Release(Model):
releaseid = CharField(db_index=True, size=36)
title = CharField()
artist = ForeignKeyField(Artist)
class ReleaseTrack(Model):
track = ForeignKeyField(Track)
release = ForeignKeyField(Release)
tracknumber = IntegerField(size=2)
print("Multiple joins before a single join cause errors")
print(Track.select().join(ReleaseTrack).join(Release).switch(Track).join(Artist).sql())
print("Single join before multiple is OK")
print(Track.select().join(Artist).switch(Track).join(ReleaseTrack).join(Release).sql())
```
Outputs:
```
Multiple joins before a single join cause errors
('SELECT t1."id", t1."trackid", t1."title", t1."artist_id" FROM "track" AS t1 INNER JOIN "releasetrack" AS t2 ON t1."id" = t2."track_id"\nINNER JOIN "release" AS t3 ON t2."release_id" = t3."id"\nINNER JOIN "artist" AS t3 ON t1."artist_id" = t3."id"', [])
Single join before multiple is OK
('SELECT t1."id", t1."trackid", t1."title", t1."artist_id" FROM "track" AS t1 INNER JOIN "artist" AS t2 ON t1."artist_id" = t2."id"\nINNER JOIN "releasetrack" AS t3 ON t1."id" = t3."track_id"\nINNER JOIN "release" AS t4 ON t3."release_id" = t4."id"', [])
```
Notice that on the first both artist and release are aliased to t3, but on the second it goes up to t4.
I've tracked down a cause. In the function follow_joins (~line 1114) you recurse and call the function again (~line 1159), passing in alias_count. This function call may in fact increment alias_count, but though alias_map may be modified, once it pops back out and run the for loop again alias_count does not reflect the change.
In order to work around this I've implemented a truly hacky fix and instead of starting with alias_count = 0 I use alias_count = [0] and always reference alias_count[0], but this is ugly and horrible.
``` diff
--- peewee_fresh.py 2012-05-29 00:29:16.997304000 -0700
+++ library/peewee.py 2012-05-29 00:25:09.429190000 -0700
@@ -1125,8 +1125,8 @@
if model in self._table_alias:
alias_map[model] = self._table_alias[model]
else:
- alias_count += 1
- alias_map[model] = 't%d' % alias_count
+ alias_count[0] += 1
+ alias_map[model] = 't%d' % alias_count[0]
else:
alias_map[model] = ''
@@ -1161,7 +1161,7 @@
return computed
def compile_where(self):
- alias_count = 0
+ alias_count = [0]
alias_map = {}
alias_required = self.use_aliases()
@@ -1169,8 +1169,8 @@
if self.model in self._table_alias:
alias_map[self.model] = self._table_alias[self.model]
else:
- alias_count += 1
- alias_map[self.model] = 't%d' % alias_count
+ alias_count[0] += 1
+ alias_map[self.model] = 't%d' % alias_count[0]
else:
alias_map[self.model] = ''
```
After the fix:
```
Multiple joins before a single join cause errors
('SELECT t1."id", t1."trackid", t1."title", t1."artist_id" FROM "track" AS t1 INNER JOIN "releasetrack" AS t2 ON t1."id" = t2."track_id"\nINNER JOIN "release" AS t3 ON t2."release_id" = t3."id"\nINNER JOIN "artist" AS t4 ON t1."artist_id" = t4."id"', [])
Single join before multiple is OK
('SELECT t1."id", t1."trackid", t1."title", t1."artist_id" FROM "track" AS t1 INNER JOIN "artist" AS t2 ON t1."artist_id" = t2."id"\nINNER JOIN "releasetrack" AS t3 ON t1."id" = t3."track_id"\nINNER JOIN "release" AS t4 ON t3."release_id" = t4."id"', [])
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/90/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/90/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/89 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/89/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/89/comments | https://api.github.com/repos/coleifer/peewee/issues/89/events | https://github.com/coleifer/peewee/issues/89 | 4,756,938 | MDU6SXNzdWU0NzU2OTM4 | 89 | The same record different instances save() behavior | {
"login": "coderbuzz",
"id": 1284811,
"node_id": "MDQ6VXNlcjEyODQ4MTE=",
"avatar_url": "https://avatars.githubusercontent.com/u/1284811?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/coderbuzz",
"html_url": "https://github.com/coderbuzz",
"followers_url": "https://api.github.com/users/coderbuzz/followers",
"following_url": "https://api.github.com/users/coderbuzz/following{/other_user}",
"gists_url": "https://api.github.com/users/coderbuzz/gists{/gist_id}",
"starred_url": "https://api.github.com/users/coderbuzz/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/coderbuzz/subscriptions",
"organizations_url": "https://api.github.com/users/coderbuzz/orgs",
"repos_url": "https://api.github.com/users/coderbuzz/repos",
"events_url": "https://api.github.com/users/coderbuzz/events{/privacy}",
"received_events_url": "https://api.github.com/users/coderbuzz/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"This is correct, calling a model's save method will wholesale update the row in the database with the field data present on the model instance **at the time of saving**. item2 will not automatically receive changes made to item1, since they are separate instances. This is intended behavior.\n\nIf you want to only update a single column, use `update`:\n\n``` python\n\nItemModel.update(other_field=item2.other_field).where(id=item2.id).execute()\n```\n"
] | 2012-05-25T16:46:51 | 2012-05-25T16:50:23 | 2012-05-25T16:50:23 | NONE | null | **Please considering a bug:**
I'm in situation which fetching the same db record but different instance, each modified somewhere.
``` python
item1 = get_item(filter='A') # return new instance of rec A
item2 = get_item(filter='A') # also return new instance of rec A
# item1 and item2 refer to the same db record, but different instance
item1.some_field = 'some value'
item1.save()
item2.other_field = 'other value'
item2.save()
```
The **item1** data won't saved correctly after committing transaction (different field changes)
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/89/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/89/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/88 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/88/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/88/comments | https://api.github.com/repos/coleifer/peewee/issues/88/events | https://github.com/coleifer/peewee/pull/88 | 4,708,361 | MDExOlB1bGxSZXF1ZXN0MTQwOTc0Ng== | 88 | Pull request to fix issue #87 | {
"login": "maiksprenger",
"id": 509427,
"node_id": "MDQ6VXNlcjUwOTQyNw==",
"avatar_url": "https://avatars.githubusercontent.com/u/509427?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/maiksprenger",
"html_url": "https://github.com/maiksprenger",
"followers_url": "https://api.github.com/users/maiksprenger/followers",
"following_url": "https://api.github.com/users/maiksprenger/following{/other_user}",
"gists_url": "https://api.github.com/users/maiksprenger/gists{/gist_id}",
"starred_url": "https://api.github.com/users/maiksprenger/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/maiksprenger/subscriptions",
"organizations_url": "https://api.github.com/users/maiksprenger/orgs",
"repos_url": "https://api.github.com/users/maiksprenger/repos",
"events_url": "https://api.github.com/users/maiksprenger/events{/privacy}",
"received_events_url": "https://api.github.com/users/maiksprenger/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2012-05-23T10:07:18 | 2014-07-06T01:51:54 | 2012-05-23T14:26:25 | NONE | null | Hello Charles,
I suggest the following fix to resolve the problem described by me here: https://github.com/coleifer/peewee/issues/87
With regards,
Maik Hoepfel
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/88/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/88/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/88",
"html_url": "https://github.com/coleifer/peewee/pull/88",
"diff_url": "https://github.com/coleifer/peewee/pull/88.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/88.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/87 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/87/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/87/comments | https://api.github.com/repos/coleifer/peewee/issues/87/events | https://github.com/coleifer/peewee/issues/87 | 4,708,010 | MDU6SXNzdWU0NzA4MDEw | 87 | NULL value for BooleanField returns False instead of None | {
"login": "maiksprenger",
"id": 509427,
"node_id": "MDQ6VXNlcjUwOTQyNw==",
"avatar_url": "https://avatars.githubusercontent.com/u/509427?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/maiksprenger",
"html_url": "https://github.com/maiksprenger",
"followers_url": "https://api.github.com/users/maiksprenger/followers",
"following_url": "https://api.github.com/users/maiksprenger/following{/other_user}",
"gists_url": "https://api.github.com/users/maiksprenger/gists{/gist_id}",
"starred_url": "https://api.github.com/users/maiksprenger/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/maiksprenger/subscriptions",
"organizations_url": "https://api.github.com/users/maiksprenger/orgs",
"repos_url": "https://api.github.com/users/maiksprenger/repos",
"events_url": "https://api.github.com/users/maiksprenger/events{/privacy}",
"received_events_url": "https://api.github.com/users/maiksprenger/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2012-05-23T09:46:09 | 2012-05-23T14:26:04 | 2012-05-23T14:26:04 | NONE | null | I have a User object that can has, among others, the following fields.
```
class User(BaseModel):
class Meta:
db_table = 'users'
user_id = peewee.PrimaryKeyField()
crm_id = peewee.CharField(null=True)
username = peewee.CharField()
password = peewee.CharField()
lost_pw_key = peewee.CharField(null=True)
lost_pw_key_creation = UnixtimeField(null=True)
lat = peewee.FloatField(null=True)
lat = peewee.FloatField(null=True)
birthday = UnixdateField(null=True)
responds_quickly = peewee.BooleanField(null=True)
```
I use a MySQL database. The responds_quickly field is a BOOLEAN that allows NULL values. The lost_pw_key is a VARCHAR that allows NULL.
I have created a minimal user that only has required fields set. So, both responds_quickly and lost_pw_key are NULL in the database. But whereas the CharField is evaluated to be None, the BooleanField evaluates to False, which for me is unexpected (and wrong) behavior. There is alos FloatFields and IntegerFields in the model, and all of them evaluate to None as well.
```
> u.responds_quickly
False
> u.responds_quickly is None
False
> u.lost_pw_key is None
True
```
If you do not consider this a bug, how can I differentiate between a 0 and a NULL value for BooleanFields? I gladly assist if you need further info.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/87/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/87/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/86 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/86/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/86/comments | https://api.github.com/repos/coleifer/peewee/issues/86/events | https://github.com/coleifer/peewee/issues/86 | 4,707,954 | MDU6SXNzdWU0NzA3OTU0 | 86 | Support for model1 != model2 | {
"login": "wtld",
"id": 1318746,
"node_id": "MDQ6VXNlcjEzMTg3NDY=",
"avatar_url": "https://avatars.githubusercontent.com/u/1318746?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/wtld",
"html_url": "https://github.com/wtld",
"followers_url": "https://api.github.com/users/wtld/followers",
"following_url": "https://api.github.com/users/wtld/following{/other_user}",
"gists_url": "https://api.github.com/users/wtld/gists{/gist_id}",
"starred_url": "https://api.github.com/users/wtld/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/wtld/subscriptions",
"organizations_url": "https://api.github.com/users/wtld/orgs",
"repos_url": "https://api.github.com/users/wtld/repos",
"events_url": "https://api.github.com/users/wtld/events{/privacy}",
"received_events_url": "https://api.github.com/users/wtld/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2012-05-23T09:42:59 | 2012-05-23T14:18:24 | 2012-05-23T14:18:24 | NONE | null | ``` python
>>> from models import Test
>>> t1 = Test.get(id=1)
>>> t2 = Test.get(id=1)
>>> t1 == t2
True
>>> t1 != t2
True
```
I think that `__ne__` method as opposite to `__eq__` should be added to the Model class.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/86/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/86/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/85 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/85/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/85/comments | https://api.github.com/repos/coleifer/peewee/issues/85/events | https://github.com/coleifer/peewee/pull/85 | 4,675,541 | MDExOlB1bGxSZXF1ZXN0MTM5NDgxNg== | 85 | Add schema support for Postgresql | {
"login": "redapple",
"id": 886296,
"node_id": "MDQ6VXNlcjg4NjI5Ng==",
"avatar_url": "https://avatars.githubusercontent.com/u/886296?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/redapple",
"html_url": "https://github.com/redapple",
"followers_url": "https://api.github.com/users/redapple/followers",
"following_url": "https://api.github.com/users/redapple/following{/other_user}",
"gists_url": "https://api.github.com/users/redapple/gists{/gist_id}",
"starred_url": "https://api.github.com/users/redapple/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/redapple/subscriptions",
"organizations_url": "https://api.github.com/users/redapple/orgs",
"repos_url": "https://api.github.com/users/redapple/repos",
"events_url": "https://api.github.com/users/redapple/events{/privacy}",
"received_events_url": "https://api.github.com/users/redapple/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I ran w/some of your ideas and have added functionality for switching search path and specifying schema when introspecting:\n\nbc465f467d0f3ccbf03c1b49ea2b2ecb04c0c765\n963cfe41c9af773be934e36fb5e3a17eaeb85ff6\n",
"Cool.\nI'll continue learning peewee.\nCheers,\nPaul.\n"
] | 2012-05-21T17:33:17 | 2014-07-06T01:51:56 | 2012-05-22T18:13:06 | NONE | null | Hi,
I've been playing a bit with peewee and had to add a few things to inspect a Postgresql database within a schema.
I haven't done much testing apart from this local Postgresql (a MusicBrainz DB mirror).
Any thoughts?
Cheers.
Paul.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/85/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/85/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/85",
"html_url": "https://github.com/coleifer/peewee/pull/85",
"diff_url": "https://github.com/coleifer/peewee/pull/85.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/85.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/84 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/84/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/84/comments | https://api.github.com/repos/coleifer/peewee/issues/84/events | https://github.com/coleifer/peewee/pull/84 | 4,663,512 | MDExOlB1bGxSZXF1ZXN0MTM4OTY2MQ== | 84 | Make common bulk operations on models and tables easier to do and harder to screw up | {
"login": "tmoertel",
"id": 21773,
"node_id": "MDQ6VXNlcjIxNzcz",
"avatar_url": "https://avatars.githubusercontent.com/u/21773?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/tmoertel",
"html_url": "https://github.com/tmoertel",
"followers_url": "https://api.github.com/users/tmoertel/followers",
"following_url": "https://api.github.com/users/tmoertel/following{/other_user}",
"gists_url": "https://api.github.com/users/tmoertel/gists{/gist_id}",
"starred_url": "https://api.github.com/users/tmoertel/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/tmoertel/subscriptions",
"organizations_url": "https://api.github.com/users/tmoertel/orgs",
"repos_url": "https://api.github.com/users/tmoertel/repos",
"events_url": "https://api.github.com/users/tmoertel/events{/privacy}",
"received_events_url": "https://api.github.com/users/tmoertel/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Wow, this is pretty interesting stuff. I'm a little bit grossed out by inspecting stack frames, I wonder if it might make sense to use the model metaclass to track subclasses or something explicit even. Not sure about merging yet, i've been playing with a branch features/extras where i've added a support for \"signals\" a-la django, and this might be a good thing to add there. Perhaps a module named 'discover.py' and a model subclass that can track subclasses somehow, then the utilities can live there.\n",
"Thanks for the feedback.\n\nYeah, the part of the code I'm least happy with is the stack-inspection stuff. Alternatives:\n1. Always require the caller to supply a module to scan, eliminating the need to detect the caller's module.\n2. Change the interface to take not a module but any collection of objects, which is then filtered to return only the models within it. That way, you can find the models in the current module by passing `globals()` and in any other module by passing `vars(the_other_module)`:\n \n models1 = find_models(globals().items()) # current module\n models2 = find_models(vars(some_other_module).items())\n\nOf course, these API designs are based on the belief that people tend to organize their models within modules. If it turns out that something other than modules makes a more natural unit of organization, I probably ought to make the discovery API ask for that thing instead. \n\nAnd maybe _base model_ is that more natural thing. If so, I can modify the discovery logic to take a base model:\n\n```\nmodels = discover_submodels(BaseModel)\n```\n\nIf peewee already tracked the subclasses derived from a base model, I could use that knowledge for the discovery process. For now, however, I could just scan the base model's module for submodels. The discovery wouldn't cross module boundaries, but maybe it doesn't need to.\n\nWhat do you think about these alternative approaches?\n\nIn any case, I put the convenience methods for creating/dropping tables into separate commits so that they can be used independently of the discovery logic. Do you have any interest in those methods?\n",
"I thought a bit more about what you wrote. Your idea of finding all the models derived from a base model seems pretty good, so I whipped up an implementation:`find_submodels`. I also renamed the module-based discovery method to `find_models_in_module` for parity and got rid of the stack-inspection logic.\n",
"Any reason not to use `__subclasses__` and call it recursively?\n",
"Nope, `__subclasses__` works just great. See most-recent commit for a revised `find_submodels` that uses it.\n\nI've made the exclusion semantics such that if you exclude a model, its descendants are also excluded. I'm not sure about this choice, however. I suspect that some people create base models in the middle of their model hierarchies for sharing purposes.\n",
"I've added a generic function to find subclasses recursively: e6b199074023237d9c1bdeef5bb2b13d3b47fd13\n\nI've added your model sorting function: a43911fee25a15e6dd47f\n\nAnd lastly, the create/drop many: f8482d0728bcc6e\n\nThanks for suggesting these improvements!\n",
"You're welcome! Thanks for peewee :-)\n"
] | 2012-05-21T00:06:42 | 2014-07-06T01:51:57 | 2012-05-22T20:56:44 | CONTRIBUTOR | null | In this branch, I've made a few small additions to peewee to make some common model and table operations easy, automatic, and hard to screw up:
- finding all your models; and
- creating/dropping their tables.
Instead of having to maintain boilerplate code to do that job, now you can just let peewee take care of it:
```
models = peewee.discover_models(exclude=[BaseModel])
peewee.create_model_tables(models, fail_silently=True)
```
That's it. Peewee will automatically gather your models, sort them topologically, and create their tables for you (in the right order).
For a real-world example of the kind of code savings this leads to, see
[how it streamlines peewee's own BaseModelTestCase](https://github.com/tmoertel/peewee/commit/753d599e90e7cb99ce05fc8b904a00bb0b683184#L1R236).
Cheers,
Tom
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/84/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/84/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/84",
"html_url": "https://github.com/coleifer/peewee/pull/84",
"diff_url": "https://github.com/coleifer/peewee/pull/84.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/84.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/83 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/83/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/83/comments | https://api.github.com/repos/coleifer/peewee/issues/83/events | https://github.com/coleifer/peewee/issues/83 | 4,561,866 | MDU6SXNzdWU0NTYxODY2 | 83 | add, create, remove, clear from ReverseForeignRelatedObject | {
"login": "maxekman",
"id": 821518,
"node_id": "MDQ6VXNlcjgyMTUxOA==",
"avatar_url": "https://avatars.githubusercontent.com/u/821518?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/maxekman",
"html_url": "https://github.com/maxekman",
"followers_url": "https://api.github.com/users/maxekman/followers",
"following_url": "https://api.github.com/users/maxekman/following{/other_user}",
"gists_url": "https://api.github.com/users/maxekman/gists{/gist_id}",
"starred_url": "https://api.github.com/users/maxekman/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/maxekman/subscriptions",
"organizations_url": "https://api.github.com/users/maxekman/orgs",
"repos_url": "https://api.github.com/users/maxekman/repos",
"events_url": "https://api.github.com/users/maxekman/events{/privacy}",
"received_events_url": "https://api.github.com/users/maxekman/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"First off, thanks for the suggestions -- I appreciate your interest in the project! This is a pretty nice API that django has, but i don't believe its something I'll add. The 'reverse relation' is exposed as a simple select query, and I think that is a good fit. The \"automatic\" filter is there on the select queyr, but i don't like adding an automatic attribute on creation or deletion. The code is not really much shorter, either:\n\n``` python\n\n# django-like api\nblog.entries.add(title='awesome post', content='lorem ipsum')\n\n# current api\nEntry.create(blog=blog, title='awesome post', content='lorem ipsum')\n```\n\nFor now, i'm going to pass on this one.\n",
"Fair enough, I was not sure about it either, just read about it in the Django docs. Pretty cool though that the Django docs works somewhat for your project as well.\n"
] | 2012-05-14T11:54:55 | 2012-05-14T17:52:02 | 2012-05-14T17:38:01 | NONE | null | Have you thought of adding some helpers to (I think) ReverseForeignRelatedObject, similar to what Django have?
Here are their docs describing it, a little bit down on the page: https://docs.djangoproject.com/en/dev/topics/db/queries/#following-relationships-backward
Sorry for spamming with ideas, I just think peewee is worth it!
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/83/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/83/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/82 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/82/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/82/comments | https://api.github.com/repos/coleifer/peewee/issues/82/events | https://github.com/coleifer/peewee/issues/82 | 4,542,935 | MDU6SXNzdWU0NTQyOTM1 | 82 | Hooks for CRUD | {
"login": "maxekman",
"id": 821518,
"node_id": "MDQ6VXNlcjgyMTUxOA==",
"avatar_url": "https://avatars.githubusercontent.com/u/821518?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/maxekman",
"html_url": "https://github.com/maxekman",
"followers_url": "https://api.github.com/users/maxekman/followers",
"following_url": "https://api.github.com/users/maxekman/following{/other_user}",
"gists_url": "https://api.github.com/users/maxekman/gists{/gist_id}",
"starred_url": "https://api.github.com/users/maxekman/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/maxekman/subscriptions",
"organizations_url": "https://api.github.com/users/maxekman/orgs",
"repos_url": "https://api.github.com/users/maxekman/repos",
"events_url": "https://api.github.com/users/maxekman/events{/privacy}",
"received_events_url": "https://api.github.com/users/maxekman/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I'm on the fence about this...feel like the signals should be able to exist at the application level as opposed to the database level.\n",
"Sure, as I see it they should be on each model, that's how I was imagining to use them.\n\nI my FSM case I would load the local in-memory FSM object after the model is loaded from the db, and I would imagine doing it on a post_init method of my actual model that have the FSM field.\n\nA naming convention would probably be the best option, for example having the above methods as abstract methods on peewee.Model and just override any of them you wish to use in your own models.\n\nAnother option is setting each callback you want to use on the class level in your model.\n",
"Since save() and delete_instance() can easily be overridden and will do the right thing, I'll leave them as-is. I have added a hook on the model instance named `prepared` which will be called when the row is ready and has received data from the db cursor. You can now write:\n\n``` python\n\nclass FSM(Model):\n state = CharField()\n\n def prepared(self):\n self.do_something_with_state()\n```\n\nThis will be called when a model is populated from the db, whether called by\n- select\n- filter\n- get\n\nIt will not be called when \"related\" models are selected, though, for instance\n\n``` python\n\nfor entry in Entry.select({Entry: '*', Blog: '*'}):\n # entry will be prepared, but entry.blog will not\n pass\n```\n",
"Cool, will try it out!\n"
] | 2012-05-11T23:24:02 | 2012-05-14T20:18:58 | 2012-05-14T19:57:28 | NONE | null | I'm trying to add this minimalistic FSM (https://github.com/oxplot/fysom) to a peewee model and just storing the state as a char field. The problem I'm having is restoring the state when selecting or creating models from elsewhere. Saving a state change is easy using the FSM callbacks. I have tried using a overloaded init, but that is called before the fields are pulled from the db. I have also tried overloaded class methods for create and and get, but that doesn't cover all cases (the filter method seems tricky to hack into from a subclass). Lastly, all my tries so far results in very un-pythonic code...
Have you though about adding hooks like the Django signals to perform custom pre/post CRUD? Some very simple callbacks would be enough to do some post init of more complex in-memory data structures (like a FSM) that depends on fields in the model.
Django uses these (https://docs.djangoproject.com/en/dev/ref/signals/):
``` python
pre_init
post_init
pre_save
post_save
pre_delete
post_delete
```
I think these hooks adds just enough to be a powerful tool without making peewee less minimalistic.
What do you think?
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/82/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/82/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/81 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/81/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/81/comments | https://api.github.com/repos/coleifer/peewee/issues/81/events | https://github.com/coleifer/peewee/issues/81 | 4,503,663 | MDU6SXNzdWU0NTAzNjYz | 81 | Iterator fails when accessing db inside loop | {
"login": "maxekman",
"id": 821518,
"node_id": "MDQ6VXNlcjgyMTUxOA==",
"avatar_url": "https://avatars.githubusercontent.com/u/821518?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/maxekman",
"html_url": "https://github.com/maxekman",
"followers_url": "https://api.github.com/users/maxekman/followers",
"following_url": "https://api.github.com/users/maxekman/following{/other_user}",
"gists_url": "https://api.github.com/users/maxekman/gists{/gist_id}",
"starred_url": "https://api.github.com/users/maxekman/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/maxekman/subscriptions",
"organizations_url": "https://api.github.com/users/maxekman/orgs",
"repos_url": "https://api.github.com/users/maxekman/repos",
"events_url": "https://api.github.com/users/maxekman/events{/privacy}",
"received_events_url": "https://api.github.com/users/maxekman/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I think I know what causes the \"running more times than there are items in the container\" problem. See [this comment from earlier today](https://github.com/coleifer/peewee/issues/12#issuecomment-5614404) on a related issue for the details.\n",
"@tmoertel nailed it in that comment. Basically, there are a couple workarounds -- you found one, which is to consume the cursor first storing the models in memory.\n\n``` python\n\nfor item in list(a_container.items):\n Other.create(name = item.name, container = a_container)\n```\n\nAnother possibility is to use transactions:\n\n``` python\n\ndb = SqliteDatabase(':memory:')\n\[email protected]_on_success\ndef create_others(a_container):\n for item in a_container.items:\n Other.create(name = item.name, container = a_container)\n```\n\nOr do it by hand...\n\n``` python\n\ndb.set_autocommit(False)\nfor item in a_container.items:\n Other.create(name = item.name, container = a_container)\ndb.commit()\ndb.set_autocommit(True)\n```\n\nOr you can turn autocommit off and do everything by hand:\n\n``` python\n\ndb = SqliteDatabase(':memory:', autocommit=False)\n\n# model definitions, etc\n\nfor item in a_container.items:\n Other.create(name = item.name, container = a_container)\ndb.commit()\n```\n",
"Thanks for all the help!\n",
"Is it possible by the way to create a transaction syntax using the \"with\" statement? That could be a really neat way to handle it, and you wouldn't need a function as with the decorator.\n\nHere is something similar: http://blog.gramant.com/2011/04/29/python-transactions-with-statement/\n\nThoughts?\n",
"Great idea, added it: https://github.com/coleifer/peewee/blob/master/tests.py#L3376\n",
"I've added some docs on working with transactions, http://peewee.readthedocs.org/en/latest/peewee/cookbook.html#working-with-transactions\n",
"That's excellent! Really quick feedback.\n",
"I have tried this now and it's a really nice syntax addition!\n"
] | 2012-05-09T23:18:33 | 2014-09-19T19:00:31 | 2012-05-10T01:48:15 | NONE | null | Accessing other db objects (moving the cursor) inside a loop with a foreign key results in this error:
"InterfaceError: Error binding parameter 0 - probably unsupported type."
Similar usage to this crashes:
``` python
class Container(Model):
name = CharField()
class Item(Model):
name = CharField()
container = ForeignKeyField(Container, related_name = 'items')
class Other(Model):
name = CharField()
container = ForeignKeyField(Container, related_name = 'others')
# stupid loop that creates a "other" for every item
for item in a_container.items:
Other.create(name = item.name, container = a_container)
```
It will run more times than there are items in the container, probably because of the cursor being disrupted.
It works by grabbing all results to a list and using that for the loop:
``` python
class Container(Model):
name = CharField()
class Item(Model):
name = CharField()
container = ForeignKeyField(Container, related_name = 'items')
class Other(Model):
name = CharField()
container = ForeignKeyField(Container, related_name = 'others')
# stupid loop that creates a "other" for every item
items = [i for i in a_container.items]
for item in items:
Other.create(name = item.name, container = a_container)
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/81/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/81/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/80 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/80/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/80/comments | https://api.github.com/repos/coleifer/peewee/issues/80/events | https://github.com/coleifer/peewee/issues/80 | 4,474,361 | MDU6SXNzdWU0NDc0MzYx | 80 | max recursion depth exceeded on admin add | {
"login": "davidthewatson",
"id": 150892,
"node_id": "MDQ6VXNlcjE1MDg5Mg==",
"avatar_url": "https://avatars.githubusercontent.com/u/150892?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/davidthewatson",
"html_url": "https://github.com/davidthewatson",
"followers_url": "https://api.github.com/users/davidthewatson/followers",
"following_url": "https://api.github.com/users/davidthewatson/following{/other_user}",
"gists_url": "https://api.github.com/users/davidthewatson/gists{/gist_id}",
"starred_url": "https://api.github.com/users/davidthewatson/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/davidthewatson/subscriptions",
"organizations_url": "https://api.github.com/users/davidthewatson/orgs",
"repos_url": "https://api.github.com/users/davidthewatson/repos",
"events_url": "https://api.github.com/users/davidthewatson/events{/privacy}",
"received_events_url": "https://api.github.com/users/davidthewatson/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"What is the db_now() function? btw, i truncated your stacktrace, there were hundreds of lines of dupe data.\n",
"I should add that I do not experience this problem locally and the test suite is passing. Have you tried running the example app that ships w/flask-peewee and do you observe the same thing?\n",
"Hmm, another consideration -- do you have another model which foreign keys to `Pool` and specifies a `related_name`? The reason I ask is that the `__get__()` is a method on the `ReverseForeignRelatedObject`...the only reason I can think that it would be called when doing the `get_field_dict()` is if its name collided with an existing field name. Can you do some interactive debugging and find out what field is causing the recursion? That might help.\n",
"Yep, that's it. I had two models that specified related_name='id' which is obviously stupid. I just didn't see how that was going to manifest at runtime and that its effect was catastrophic. Thanks for your help.\n",
"Glad it fixed it -- yes, related_name is used for the back-side of a foreign key, so 0..n related models. Typically they are expressed as a plural, i.e. `for message in user.messages:` Where Message has a Foreign key to user that looks like `user = ForeignKeyField(User, related_name='messages')`\n"
] | 2012-05-08T15:02:52 | 2012-05-08T23:24:59 | 2012-05-08T23:23:23 | NONE | null | I've got the following on fedora core 16 with postgresql:
```
Flask==0.8
Flask-DebugToolbar==0.6.3.1
Flask-OpenID==1.0.1
Flask-WTF==0.6
Jinja2==2.6
WTForms==1.0.1
Werkzeug==0.8.3
blinker==1.2
certifi==0.0.8
chardet==1.0.1
diesel==2.1.1
flask-peewee==0.5.1
greenlet==0.3.4
oauthlib==0.1.2
peewee==0.9.5
psycopg2==2.4.5
pyOpenSSL==0.13
pycrypto==2.5
pyev==0.8.1-4.04
python-openid==2.2.5
requests==0.12.0
wsgiref==0.1.2
wtf-peewee==0.1.3
```
I have a peewee model like this:
```
class Pool(db.Model):
name = CharField()
active = BooleanField(default=True)
created = DateTimeField(default=db_now())
def __unicode__(self):
return unicode(self.name)
class Meta:
db_table = 'mls'
```
When I access the generated admin at http://localhost:5000/admin/pool/add/
and type a name in the name field with the other two fields defaulting, I get the following:
Traceback (most recent call last):
File "/home/watson/git/latte/virtenv/lib/python2.7/site-packages/flask/app.py", line 1506, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/home/watson/git/latte/virtenv/lib/python2.7/site-packages/flask/app.py", line 1504, in wsgi_app
response = self.full_dispatch_request()
File "/home/watson/git/latte/virtenv/lib/python2.7/site-packages/flask/app.py", line 1264, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/watson/git/latte/virtenv/lib/python2.7/site-packages/flask/app.py", line 1262, in full_dispatch_request
rv = self.dispatch_request()
File "/home/watson/git/latte/virtenv/lib/python2.7/site-packages/flask_debugtoolbar/**init**.py", line 101, in dispatch_request
return view_func(*_req.view_args)
File "/usr/lib64/python2.7/cProfile.py", line 149, in runcall
return func(_args, *_kw)
File "/home/watson/git/latte/virtenv/lib/python2.7/site-packages/flask_peewee/admin.py", line 521, in inner
return func(_args, **kwargs)
File "/home/watson/git/latte/virtenv/lib/python2.7/site-packages/flask_peewee/admin.py", line 259, in add
instance = self.save_model(self.model(), form, True)
File "/home/watson/git/latte/virtenv/lib/python2.7/site-packages/flask_peewee/admin.py", line 200, in save_model
instance.save()
File "/home/watson/git/latte/virtenv/lib/python2.7/site-packages/peewee.py", line 2586, in save
field_dict = self.get_field_dict()
File "/home/watson/git/latte/virtenv/lib/python2.7/site-packages/peewee.py", line 2508, in get_field_dict
field_dict[field.name] = getattr(self, field.name)
File "/home/watson/git/latte/virtenv/lib/python2.7/site-packages/peewee.py", line 2249, in **get**
query = {self.field_name: instance.get_pk()}
File "/home/watson/git/latte/virtenv/lib/python2.7/site-packages/peewee.py", line 2579, in get_pk
return getattr(self, self._meta.pk_name, None)
File "/home/watson/git/latte/virtenv/lib/python2.7/site-packages/peewee.py", line 2249, in __get__
query = {self.field_name: instance.get_pk()}
File "/home/watson/git/latte/virtenv/lib/python2.7/site-packages/peewee.py", line 2579, in get_pk
return getattr(self, self._meta.pk_name, None)
File "/home/watson/git/latte/virtenv/lib/python2.7/site-packages/peewee.py", line 2249, in __get__
query = {self.field_name: instance.get_pk()}
File "/home/watson/git/latte/virtenv/lib/python2.7/site-packages/peewee.py", line 2579, in get_pk
return getattr(self, self._meta.pk_name, None)
File "/home/watson/git/latte/virtenv/lib/python2.7/site-packages/peewee.py", line 2249, in __get__
query = {self.field_name: instance.get_pk()}
File "/home/watson/git/latte/virtenv/lib/python2.7/site-packages/peewee.py", line 2579, in get_pk
return getattr(self, self._meta.pk_name, None)
File "/home/watson/git/latte/virtenv/lib/python2.7/site-packages/peewee.py", line 2249, in __get__
query = {self.field_name: instance.get_pk()}
File "/home/watson/git/latte/virtenv/lib/python2.7/site-packages/peewee.py", line 2579, in get_pk
return getattr(self, self._meta.pk_name, None)
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/80/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/80/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/79 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/79/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/79/comments | https://api.github.com/repos/coleifer/peewee/issues/79/events | https://github.com/coleifer/peewee/issues/79 | 4,435,804 | MDU6SXNzdWU0NDM1ODA0 | 79 | Database Creation | {
"login": "maxekman",
"id": 821518,
"node_id": "MDQ6VXNlcjgyMTUxOA==",
"avatar_url": "https://avatars.githubusercontent.com/u/821518?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/maxekman",
"html_url": "https://github.com/maxekman",
"followers_url": "https://api.github.com/users/maxekman/followers",
"following_url": "https://api.github.com/users/maxekman/following{/other_user}",
"gists_url": "https://api.github.com/users/maxekman/gists{/gist_id}",
"starred_url": "https://api.github.com/users/maxekman/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/maxekman/subscriptions",
"organizations_url": "https://api.github.com/users/maxekman/orgs",
"repos_url": "https://api.github.com/users/maxekman/repos",
"events_url": "https://api.github.com/users/maxekman/events{/privacy}",
"received_events_url": "https://api.github.com/users/maxekman/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I've been thinking about how to fix this... I'm going to assume that a model is \"actually used\" whenever the db connection is either explicitly or implicitly opened. If that's the case, then it really isn't a problem to structure your code such that you modify the underlying db connection on-the-fly. The most important thing is that you don't want a bunch of `Database` instances running around, since each will open its own connection to the server -- in other words, there should be only one `Database` for each database you intend to connect to.\n\nWhat I think I'll do is allow a user to set a db to \"deferred\" when initializing, then if you attempt to connect to the db (either by explicitly calling connect() or by trying to issue a query) it will raise an exception if the db hasn't been properly initialized.\n",
"If readthedocs ever updates, you can find docs here http://readthedocs.org/docs/peewee/en/latest/peewee/cookbook.html#deferring-initialization -- the basic idea is passing `None` as the db name will mark the db as deferred and an exception will be raised if you try and use it. You can then properly init the db by calling `db.init()`:\n\n``` python\n\n>>> db = SqliteDatabase(None)\n>>> db.deferred\nTrue\n\n>>> db.connect()\nException raised\n\n>>> db.init(':memory:')\n>>> db.connect()\n```\n",
"Very nice, I'll give this a try later. Is it published to pypi yet?\n",
"Just pushed a new version, 0.9.6 -- let me know how it works out!\n",
"This works perfectly!\n\nThe new best practice is probably to use a uninitialized db in the base model:\n\n``` python\nclass BaseModel(peewee.Model):\n class Meta:\n database = peewee.SqliteDatabase(None)\n```\n\nAnd later init it:\n\n``` python\nBaseModel.Meta.database.init('db.sqlite')\n```\n"
] | 2012-05-05T10:36:32 | 2012-05-09T23:27:17 | 2012-05-09T15:28:13 | NONE | null | I need to read in the db config from a file which currently does not work with the way the Meta class is used. It creates a default "peewee.db" if the database attribute is not set when parsing the model classes. Could this be delayed until a Model is actually used?
I just read this thread on the mailing list about the same issue and wondered if this patch (or similar) could be applied to the main branch?
http://groups.google.com/group/peewee-orm/browse_thread/thread/53a50c4bb63e282b
Thanks,
Max
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/79/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/79/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/78 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/78/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/78/comments | https://api.github.com/repos/coleifer/peewee/issues/78/events | https://github.com/coleifer/peewee/issues/78 | 4,302,585 | MDU6SXNzdWU0MzAyNTg1 | 78 | Peewee ignores given database name. Puts peewee.db instead. | {
"login": "DDevine",
"id": 913394,
"node_id": "MDQ6VXNlcjkxMzM5NA==",
"avatar_url": "https://avatars.githubusercontent.com/u/913394?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/DDevine",
"html_url": "https://github.com/DDevine",
"followers_url": "https://api.github.com/users/DDevine/followers",
"following_url": "https://api.github.com/users/DDevine/following{/other_user}",
"gists_url": "https://api.github.com/users/DDevine/gists{/gist_id}",
"starred_url": "https://api.github.com/users/DDevine/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/DDevine/subscriptions",
"organizations_url": "https://api.github.com/users/DDevine/orgs",
"repos_url": "https://api.github.com/users/DDevine/repos",
"events_url": "https://api.github.com/users/DDevine/events{/privacy}",
"received_events_url": "https://api.github.com/users/DDevine/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"This sounds like a configuration issue. Please refer to the docs here:\n\nhttp://peewee.readthedocs.org/en/latest/peewee/cookbook.html#creating-a-database-connection-and-tables\n\n``` python\n\ndb = SqliteDatabase('database.db')\n\nclass Entry(Model):\n # foo bar baz\n\n class Meta:\n database = db # <--- I bet you're missing this\n```\n",
"I bet you're right. Sorry!\n"
] | 2012-04-26T14:16:00 | 2012-04-27T03:48:42 | 2012-04-26T14:18:46 | NONE | null | I had a database called database.db, then I opened a python prompt and did the following:
> > > import peewee
> > > from blog import Entry
> > > db = peewee.SqliteDatabase('database.db')
> > > db.connect()
> > > Entry.create_table()
> > > entry = Entry()
> > > entry.title = "test"
> > > entry.tags = "derp blah"
> > > entry.save()
This created peewee.db and created the table inside it, while my database.db remained empty. If I do the same but with a completely new database file name (say, "test.db") then test.db is not created and when I try to do create_table() it gives me an error saying that the table already exists due to it actually using pewee.db intead.
I am using peewee-0.9.5 on Python 2.7.3
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/78/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/78/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/77 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/77/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/77/comments | https://api.github.com/repos/coleifer/peewee/issues/77/events | https://github.com/coleifer/peewee/pull/77 | 4,274,573 | MDExOlB1bGxSZXF1ZXN0MTIyNzgwNQ== | 77 | Change documentation link in README to point to RTD | {
"login": "rouge8",
"id": 237005,
"node_id": "MDQ6VXNlcjIzNzAwNQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/237005?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/rouge8",
"html_url": "https://github.com/rouge8",
"followers_url": "https://api.github.com/users/rouge8/followers",
"following_url": "https://api.github.com/users/rouge8/following{/other_user}",
"gists_url": "https://api.github.com/users/rouge8/gists{/gist_id}",
"starred_url": "https://api.github.com/users/rouge8/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/rouge8/subscriptions",
"organizations_url": "https://api.github.com/users/rouge8/orgs",
"repos_url": "https://api.github.com/users/rouge8/repos",
"events_url": "https://api.github.com/users/rouge8/events{/privacy}",
"received_events_url": "https://api.github.com/users/rouge8/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Thanks!\n"
] | 2012-04-25T04:49:33 | 2014-07-06T01:51:59 | 2012-04-25T17:11:44 | CONTRIBUTOR | null | [RTD](http://peewee.readthedocs.org/en/latest/index.html) had a newer version of the documentation, and is linked from the github description, so I assumed that's the canonical doc location.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/77/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/77/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/77",
"html_url": "https://github.com/coleifer/peewee/pull/77",
"diff_url": "https://github.com/coleifer/peewee/pull/77.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/77.patch",
"merged_at": "2012-04-25T17:11:44"
} |
https://api.github.com/repos/coleifer/peewee/issues/76 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/76/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/76/comments | https://api.github.com/repos/coleifer/peewee/issues/76/events | https://github.com/coleifer/peewee/issues/76 | 4,245,848 | MDU6SXNzdWU0MjQ1ODQ4 | 76 | on windows, peewee-0.9.4 line 1965, SyntaxError: invalid syntax | {
"login": "huaitwooos",
"id": 1182693,
"node_id": "MDQ6VXNlcjExODI2OTM=",
"avatar_url": "https://avatars.githubusercontent.com/u/1182693?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/huaitwooos",
"html_url": "https://github.com/huaitwooos",
"followers_url": "https://api.github.com/users/huaitwooos/followers",
"following_url": "https://api.github.com/users/huaitwooos/following{/other_user}",
"gists_url": "https://api.github.com/users/huaitwooos/gists{/gist_id}",
"starred_url": "https://api.github.com/users/huaitwooos/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/huaitwooos/subscriptions",
"organizations_url": "https://api.github.com/users/huaitwooos/orgs",
"repos_url": "https://api.github.com/users/huaitwooos/repos",
"events_url": "https://api.github.com/users/huaitwooos/events{/privacy}",
"received_events_url": "https://api.github.com/users/huaitwooos/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"updated formatting\n",
"I'm not quite clear on what is throwing that error, can you provide a little more information?\n",
"if i delete[ , microsecond=usec], the error will goto line 1994.\n\n<pre>\nTraceback (most recent call last):\n File \"C:\\Download\\dev\\peewee-0.9.4\\a.py\", line 1, in <module>\n import peewee\n File \"C:\\Download\\dev\\peewee-0.9.4\\peewee.py\", line 1994\n return datetime.time(*time.strptime(value, '%H:%M:%S')[3:6], microsecond=usec)\n ^\nSyntaxError: invalid syntax\n</pre>\n",
"So it sounds like windows python2.5 doesn't like microsecond? I did a quick google and didn't find anything that jumped out at me.\n",
"JUST has ERROR ON PYTHON2.5.4. it's OK on Python2.7+windows.\n\nI found two way to solve the problem on python 2.5.4:\n- put microsencond keyword before the time.time.strptime(...):\n <pre>\n return datetime.datetime(microsecond=usec,*time.strptime('2011-2-3 12:23:34', '%Y-%m-%d %H:%M:%S')[:6])\n </pre>\n- use a dict ref:\n <pre>\n return datetime.datetime(*_time.strptime('2011-2-3 12:23:34', '%Y-%m-%d %H:%M:%S')[:6], *_*{'microsecond':usec})\n </pre>\n",
"Fixed in 41de298683da7397b875597573a22a6683e19a6e -- thanks for the suggestions and for reporting the issue\n"
] | 2012-04-23T17:59:08 | 2012-04-24T14:31:02 | 2012-04-24T14:31:02 | NONE | null | C:\Download\dev\flask-peewee\coleifer-peewee-6fb13f1\example>python
Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
``` python
>>> import peewee
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\python25\lib\site-packages\peewee-0.9.4-py2.5.egg\peewee.py", line 19
65
return datetime.datetime(*time.strptime(value, '%Y-%m-%d %H:%M:%S')[:6], mic
rosecond=usec)
^
SyntaxError: invalid syntax
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/76/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/76/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/75 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/75/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/75/comments | https://api.github.com/repos/coleifer/peewee/issues/75/events | https://github.com/coleifer/peewee/pull/75 | 4,176,533 | MDExOlB1bGxSZXF1ZXN0MTE4ODE0OA== | 75 | pwiz.py: mysqldb use passwd not password as keyword argument | {
"login": "Alquimista",
"id": 185971,
"node_id": "MDQ6VXNlcjE4NTk3MQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/185971?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/Alquimista",
"html_url": "https://github.com/Alquimista",
"followers_url": "https://api.github.com/users/Alquimista/followers",
"following_url": "https://api.github.com/users/Alquimista/following{/other_user}",
"gists_url": "https://api.github.com/users/Alquimista/gists{/gist_id}",
"starred_url": "https://api.github.com/users/Alquimista/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/Alquimista/subscriptions",
"organizations_url": "https://api.github.com/users/Alquimista/orgs",
"repos_url": "https://api.github.com/users/Alquimista/repos",
"events_url": "https://api.github.com/users/Alquimista/events{/privacy}",
"received_events_url": "https://api.github.com/users/Alquimista/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"already fixed, thanks!\n"
] | 2012-04-18T17:16:06 | 2014-07-06T01:52:00 | 2012-04-18T17:16:59 | NONE | null | https://github.com/coleifer/peewee/issues/74
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/75/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/75/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/75",
"html_url": "https://github.com/coleifer/peewee/pull/75",
"diff_url": "https://github.com/coleifer/peewee/pull/75.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/75.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/74 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/74/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/74/comments | https://api.github.com/repos/coleifer/peewee/issues/74/events | https://github.com/coleifer/peewee/issues/74 | 4,176,487 | MDU6SXNzdWU0MTc2NDg3 | 74 | pwiz mysql connection | {
"login": "Alquimista",
"id": 185971,
"node_id": "MDQ6VXNlcjE4NTk3MQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/185971?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/Alquimista",
"html_url": "https://github.com/Alquimista",
"followers_url": "https://api.github.com/users/Alquimista/followers",
"following_url": "https://api.github.com/users/Alquimista/following{/other_user}",
"gists_url": "https://api.github.com/users/Alquimista/gists{/gist_id}",
"starred_url": "https://api.github.com/users/Alquimista/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/Alquimista/subscriptions",
"organizations_url": "https://api.github.com/users/Alquimista/orgs",
"repos_url": "https://api.github.com/users/Alquimista/repos",
"events_url": "https://api.github.com/users/Alquimista/events{/privacy}",
"received_events_url": "https://api.github.com/users/Alquimista/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2012-04-18T17:13:18 | 2012-04-18T17:15:34 | 2012-04-18T17:15:34 | NONE | null | mysqldb use passwd not password as keyword argument
db = MySQLdb.connect(host="localhost",user="joebob",
passwd="moonpie",db="thangs")
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/74/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/74/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/73 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/73/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/73/comments | https://api.github.com/repos/coleifer/peewee/issues/73/events | https://github.com/coleifer/peewee/issues/73 | 4,139,400 | MDU6SXNzdWU0MTM5NDAw | 73 | Memory usage Runs wild | {
"login": "prggmr",
"id": 207314,
"node_id": "MDQ6VXNlcjIwNzMxNA==",
"avatar_url": "https://avatars.githubusercontent.com/u/207314?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/prggmr",
"html_url": "https://github.com/prggmr",
"followers_url": "https://api.github.com/users/prggmr/followers",
"following_url": "https://api.github.com/users/prggmr/following{/other_user}",
"gists_url": "https://api.github.com/users/prggmr/gists{/gist_id}",
"starred_url": "https://api.github.com/users/prggmr/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/prggmr/subscriptions",
"organizations_url": "https://api.github.com/users/prggmr/orgs",
"repos_url": "https://api.github.com/users/prggmr/repos",
"events_url": "https://api.github.com/users/prggmr/events{/privacy}",
"received_events_url": "https://api.github.com/users/prggmr/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"It definitely sounds like there's a problem somewhere. I'd like to know a little bit more before I set about trying to replicate -- what database engine were you using? Did you try dropping down to the db driver and issuing raw SQL queries, and if so did this fix the problem? Were you iterating over a large number of rows from the database?\n\nThanks for reporting, I'm eager to look into this.\n",
"I was using MySQL (MySQLdb).\n\nDropping peewee and using the MySQLdb itself with plain SQL queries and no ORM interaction has solved the issue.\n\nAs for the database table size it slowly progressed regardless of table size but it ultimately failed when running on a table with ~8 million records with a total record set for the entire database being around ~12 million at the point of failure, with each record running at a minimum of 2 queries per record, a select and then an insert or update depending on if the record exists.\n\nFrom my previous experience the import would run roughly for 3 - 4 hours before consuming the servers entire memory of 4GB currently it is about to hit the 6 hour mark without using more than 0.3% of the servers memory which is the expected behavior.\n",
"Thanks for the info. I'll see about doing some profiling.\n",
"Initial results -- I am not able to replicate your issue. Using python2.7, MySQLdb, peewee 0.9.4. Wrote a little script using guppy to do memory profiling. It shows memory before starting querying after initial objects have been loaded up, then shows memory usage after every 100K iterations (it does not change). I was surprised by my results so I modified the script to add items to a dictionary in the loop and observed memory growing, so I know that its working right.\n\nHere's my script:\n\n``` python\nimport random\nfrom guppy import hpy\nfrom peewee import *\nfrom peewee import InsertQuery, UpdateQuery\n\n\ndb = MySQLDatabase('prof', user='root')\ndb.connect()\n\n\nclass TestModel(Model):\n data = CharField()\n\n class Meta:\n database = db\n\n\ndef main():\n TestModel.drop_table(True)\n TestModel.create_table()\n\n h = hpy()\n orig = num_records = 1000000\n every = 100000\n print 'Initial\\n========'\n print h.heap()\n print '\\n'\n\n while num_records:\n num_records -= 1\n data = str(random.randint(1, 100000))\n\n if TestModel.select().where(data=data).exists():\n InsertQuery(TestModel, data=data).execute()\n else:\n # this essential no-ops but we'll call update anyways\n UpdateQuery(TestModel, data=data).where(data=data).execute()\n\n if num_records % every == 0:\n print 'After %d records:\\n=================' % (orig - num_records)\n print h.heap()\n print '\\n\\n'\n #if raw_input('Continue? Yn ') == 'n':\n # break\n\nif __name__ == '__main__':\n main()\n```\n\nAnd here is a link to the output:\nhttps://gist.github.com/efadb58837aff2b64224\n\nCan you think of anything I'm missing here?\n",
"Oh shit, realized I've got a bug... that first if block needs to be \"if not\" rather than \"if\". Will update after doing somemore testing.\n",
"After changing it and about 100K records in still not seeing memory usage increasing.\n",
"This may have already been addressed in a recent version since it can be something as simple as a missed circular reference somewhere ... once I get some time I will do some more analysis of everything and provide some more concrete data on the usage and a way to easily replicate if still possible.\n\nI'm using 0.7 or 0.8 I believe ... downloaded back at the end of January.\n",
"Forgot to close this ... again thanks for looking into to it and since it seems to not exist in the current version I may just need to update ... if time allows ...\n",
"@nwhitingx yeah I am guessing there was a circular reference somewhere....never got to the number of records you were experiencing failure at, but also didn't see a steady increase in RAM usage. please update the ticket or open a new one if updating your checkout doesn't fix.\n",
"Did you have any luck with a newer version, or did you still run into memory issues?\n",
"I have not had the time to upgrade and test the newer version as I'm completely swamped with work right now once I get some time this is on my TODO list as I'm very interested in finding where this leak was occurring.\n",
"i have this problem too. I am using peewee 3.11.2 , PyMySQL 0.9.3 and python 3.6\r\ni have 20m records in my database so , to reduce ram usage, i query for 100k records each time. the problem is that records are the same and must have the same size but each query causes more ram usage than the previous one.(e.g. first query uses 100MB of ram but the 30th one uses 5GB)",
"Without code it's impossible to help. There are many ways to profile your memory usage.\r\n\r\nBest recommendation is to use the `.iterator()` method of query to get a \"one-shot\" iterator that doesn't cache rows in memory."
] | 2012-04-16T18:07:01 | 2019-10-12T14:22:44 | 2012-04-17T02:05:56 | NONE | null | Hello,
I believe to have found a problem with the library causing excessive memory usage when used with long running processes, the problem I encountered is when importing a very large XML file (80+GB) the memory usage would climb at a very steady rate, after exhausting all other options to what was consuming the memory I removed the peewee library and the memory consumption stopped.
I cannot say exactly where the consumption is taking place but I was only using the `select`, `update` and `insert` functions in the process, unfortunately I didn't have the time available to fully investigate what the problem is but it does exist somewhere.
During the import I was using the following snippet for extracting the data.
https://gist.github.com/2161849
The code for running the queries was identical to the following
```
if import.type is IMPORT_FULL Model.select().where(id = field['id']).exists():
InsertQuery(Model, **fields).execute()
else:
UpdateQuery(Model, **fields).where(id = fields['id']).execute()
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/73/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/73/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/72 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/72/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/72/comments | https://api.github.com/repos/coleifer/peewee/issues/72/events | https://github.com/coleifer/peewee/pull/72 | 4,133,991 | MDExOlB1bGxSZXF1ZXN0MTE3MDIzNw== | 72 | Avoid error when returning non-ascii characters from __unicode__ method | {
"login": "karlb",
"id": 144773,
"node_id": "MDQ6VXNlcjE0NDc3Mw==",
"avatar_url": "https://avatars.githubusercontent.com/u/144773?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/karlb",
"html_url": "https://github.com/karlb",
"followers_url": "https://api.github.com/users/karlb/followers",
"following_url": "https://api.github.com/users/karlb/following{/other_user}",
"gists_url": "https://api.github.com/users/karlb/gists{/gist_id}",
"starred_url": "https://api.github.com/users/karlb/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/karlb/subscriptions",
"organizations_url": "https://api.github.com/users/karlb/orgs",
"repos_url": "https://api.github.com/users/karlb/repos",
"events_url": "https://api.github.com/users/karlb/events{/privacy}",
"received_events_url": "https://api.github.com/users/karlb/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2012-04-16T13:10:53 | 2014-07-06T01:52:01 | 2012-04-16T14:26:41 | NONE | null | The **repr** methods just tries to cast the unicode to str, which fails when non-ascii characters are present.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/72/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/72/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/72",
"html_url": "https://github.com/coleifer/peewee/pull/72",
"diff_url": "https://github.com/coleifer/peewee/pull/72.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/72.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/71 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/71/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/71/comments | https://api.github.com/repos/coleifer/peewee/issues/71/events | https://github.com/coleifer/peewee/issues/71 | 4,080,925 | MDU6SXNzdWU0MDgwOTI1 | 71 | VarCharColumn - TypeError: 'long' object is not subscriptable | {
"login": "smokedice",
"id": 1133455,
"node_id": "MDQ6VXNlcjExMzM0NTU=",
"avatar_url": "https://avatars.githubusercontent.com/u/1133455?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/smokedice",
"html_url": "https://github.com/smokedice",
"followers_url": "https://api.github.com/users/smokedice/followers",
"following_url": "https://api.github.com/users/smokedice/following{/other_user}",
"gists_url": "https://api.github.com/users/smokedice/gists{/gist_id}",
"starred_url": "https://api.github.com/users/smokedice/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/smokedice/subscriptions",
"organizations_url": "https://api.github.com/users/smokedice/orgs",
"repos_url": "https://api.github.com/users/smokedice/repos",
"events_url": "https://api.github.com/users/smokedice/events{/privacy}",
"received_events_url": "https://api.github.com/users/smokedice/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2012-04-12T09:48:09 | 2012-04-15T20:12:10 | 2012-04-15T20:12:09 | NONE | null | Line 1944 should convert the provided value into a string:
value = str(value or '')
This should stop errors occurring when integers or such are passed in.
Traceback (most recent call last):
File "/home/smoky/Documents/Workspace/TASv3/Code/common/CommonSignals/AbstractSignal.py", line 25, in execute
action(_args, *_requiredKeywords)
File "/home/smoky/Documents/Workspace/TASv3/Code/master/MasterBusinessLogic/Results/Loggers/SQLLiteLogger.py", line 67, in __conformancePackName
tasVersion = TASBuildDetails.TASVersion)
File "/home/smoky/Documents/Workspace/TASv3/Code/libs/peewee/peewee.py", line 2567, in create
inst.save(force_insert = True)
File "/home/smoky/Documents/Workspace/TASv3/Code/libs/peewee/peewee.py", line 2601, in save
new_pk = insert.execute()
File "/home/smoky/Documents/Workspace/TASv3/Code/libs/peewee/peewee.py", line 1754, in execute
result = self.raw_execute(*self.sql())
File "/home/smoky/Documents/Workspace/TASv3/Code/libs/peewee/peewee.py", line 1737, in sql
cols, vals = self.parse_insert()
File "/home/smoky/Documents/Workspace/TASv3/Code/libs/peewee/peewee.py", line 1732, in parse_insert
vals.append(field.db_value(v))
File "/home/smoky/Documents/Workspace/TASv3/Code/libs/peewee/peewee.py", line 2130, in db_value
return self.column.db_value(value)
File "/home/smoky/Documents/Workspace/TASv3/Code/libs/peewee/peewee.py", line 1948, in db_value
return value[:x]
TypeError: 'long' object is not subscriptable
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/71/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/71/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/70 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/70/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/70/comments | https://api.github.com/repos/coleifer/peewee/issues/70/events | https://github.com/coleifer/peewee/issues/70 | 4,066,732 | MDU6SXNzdWU0MDY2NzMy | 70 | PK not respecting db column (via mailing list) | {
"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 | [
"Places to test:\n- setting up joins (follow_joins)\n- select query count()\n- parse select query special case for when just an id is selected .select(\"id\") -> .select({Model: ['id']})\n- convert_subquery\n- annotate_query\n- foreign related object lookup\n- foreign key field\n- model save\n- model collect_queries\n- delete instance\n"
] | 2012-04-11T15:13:25 | 2012-04-11T16:38:59 | 2012-04-11T16:38:59 | OWNER | null | Model:
``` python
class Peer(BaseModel):
peerId = PrimaryKeyField(db_column = 'id')
macAddress = CharField()
netAddress = CharField()
```
Error:
```
Traceback (most recent call last):
File "/home/smoky/Documents/Workspace/TASv3/Code/tests/BusinessLogic/Results/Loggers/TestSQLLiteLogger.py", line 58, in testOldDataDestroyed
assert len(Peer.select().count()) == 1
File "/usr/local/lib/python2.7/dist-packages/peewee-0.9.1-py2.7.egg/peewee.py", line 1325, in count
res = clone.database.execute(*clone.sql())
File "/usr/local/lib/python2.7/dist-packages/peewee-0.9.1-py2.7.egg/peewee.py", line 310, in execute
res = cursor.execute(sql, params or ())
OperationalError: no such column: peerId
```
It looks as if the db_column is being ignored by line 2371. Currently it is using attr.name, but surely it should use attr.db_column ?
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/70/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/70/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/69 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/69/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/69/comments | https://api.github.com/repos/coleifer/peewee/issues/69/events | https://github.com/coleifer/peewee/issues/69 | 3,994,985 | MDU6SXNzdWUzOTk0OTg1 | 69 | SelectQuery dictionary fields | {
"login": "jdearl",
"id": 1612844,
"node_id": "MDQ6VXNlcjE2MTI4NDQ=",
"avatar_url": "https://avatars.githubusercontent.com/u/1612844?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/jdearl",
"html_url": "https://github.com/jdearl",
"followers_url": "https://api.github.com/users/jdearl/followers",
"following_url": "https://api.github.com/users/jdearl/following{/other_user}",
"gists_url": "https://api.github.com/users/jdearl/gists{/gist_id}",
"starred_url": "https://api.github.com/users/jdearl/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/jdearl/subscriptions",
"organizations_url": "https://api.github.com/users/jdearl/orgs",
"repos_url": "https://api.github.com/users/jdearl/repos",
"events_url": "https://api.github.com/users/jdearl/events{/privacy}",
"received_events_url": "https://api.github.com/users/jdearl/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"First off, thank you so much for including the SQL, makes debugging so much easier :)\n\nSince a product can have multiple items, the value of the aggregate functions has meaning and that is why you get meaningful results. The big question is what you expect \"price1\" to be. By the \"?\" interpolation I gather you're using sqlite -- trying this query in postgresql would most likely not work since it is a bit stricter.\n",
"Yes, it's a bit contrived :)\n\nIn the case of the SQLite 3.7.11 it would return the same price as\nMAX(price1). Also, I'm not extremely familiar with PostgreSQL, but I\nbelieve the latest versions allow such queries also.\n\nI'm totally fine if you don't want to allow this. It was just a\nlittle confusing, because I was able to provide a list of fields to\nProduct, but not to Item. I do agree though, price1 isn't really\nuseful.\n\nSort of related, would R() work in this case? For example:\n\nR('GROUP_CONCAT(image) AS image')\n",
"Yeah, in my opinion this is one of those things that give ORMs a bad rap. For a detailed description of a possible solution, check out https://groups.google.com/forum/?fromgroups#!topic/peewee-orm/RLd2r-eKp7w\n\nYou're doing an inner join but you want, in a sense, a right join on item and peewee doesn't support this...and as you said, the value of price1 is \"indeterminate\" but should probably be a list. The way I would fix this is to query Item and group by product. I'm not familiar with the group_concat function but would be interested in learning more.\n",
"Thanks!\nBtw, I didn't realize there was a peewee forum!\n",
"If you want to try this out, its kidn of hacky but might do what you want:\nhttp://peewee.readthedocs.org/en/latest/peewee/querying.html#speeding-up-simple-select-queries\n",
"That works great, thank you! Good choice in method name :)\n"
] | 2012-04-05T20:07:26 | 2012-04-06T21:22:25 | 2012-04-06T19:14:57 | NONE | null | With the following I can access 'min' and 'max', but not 'price1'.
products = Product.select({
Product: ['*'],
Item: ['price1', Min('price1'), Max('price1')],
}).where(category_id=id).group_by('id').join(Item)
SQL:
('SELECT t1."id", t1."brand", t1."category_id", t1."name", t1."overview", t1."details", t2."price1", MIN(t2."price1") AS min, MAX(t2."price1") AS max FROM "products" AS t1 INNER JOIN "items" AS t2 ON t1."id" = t2."product_id" WHERE t1."category_id" = ? GROUP BY t1."id" ORDER BY t1."brand" ASC, t1."name" ASC', [u'29'])
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/69/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/69/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/68 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/68/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/68/comments | https://api.github.com/repos/coleifer/peewee/issues/68/events | https://github.com/coleifer/peewee/issues/68 | 3,975,858 | MDU6SXNzdWUzOTc1ODU4 | 68 | ValueError datetime | {
"login": "jdearl",
"id": 1612844,
"node_id": "MDQ6VXNlcjE2MTI4NDQ=",
"avatar_url": "https://avatars.githubusercontent.com/u/1612844?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/jdearl",
"html_url": "https://github.com/jdearl",
"followers_url": "https://api.github.com/users/jdearl/followers",
"following_url": "https://api.github.com/users/jdearl/following{/other_user}",
"gists_url": "https://api.github.com/users/jdearl/gists{/gist_id}",
"starred_url": "https://api.github.com/users/jdearl/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/jdearl/subscriptions",
"organizations_url": "https://api.github.com/users/jdearl/orgs",
"repos_url": "https://api.github.com/users/jdearl/repos",
"events_url": "https://api.github.com/users/jdearl/events{/privacy}",
"received_events_url": "https://api.github.com/users/jdearl/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I think the first 2 should probably work as expected with the existing DateTimeField, but the last should probably be given its own \"DateField\" a-la django (and maybe a TimeField as well for times). Thanks for reporting\n",
"Is it possible to cast them to a DateTime with 0's? That's sorta what I'd expect to happen. I'm coming from Ruby, and Sequel or the Ruby SQLite adapter appears to do be doing this.\n\nI also added that the field is defined as a peewee DateTimeField().\n",
"Totally, if the DateTimeField encounters something like example 3 it should zero out the times.\n",
"Great!\n",
"Thanks for fixing :)\n",
"Would be really good if we could pass in the format string into the field constructor. I have dates in a sqlite db of '9 January 2009' so I'd like to pass the format in:\n\ntransaction_date = DateField(format='%d %B %Y')\n\nI'll fork and suggest something....\n",
"Thanks for suggesting this fix, I've added it here:\n",
"here's the commit: 0d9708a0f97685144aa7a9773755832dab459b07\n\nthe way it works is you can pass in \"formats\" kwarg in the field constructor containing a list of various formats to try.\n",
"Legend Charles - you beat me to it :)\n\nLove Peewee btw - its my ORM of choice. In fact I don't choose any\nother these days - solid.\n\nThanks for the rapid help.\n\nBen\n\nOn Mon, May 14, 2012 at 5:30 PM, Charles Leifer\[email protected]\nwrote:\n\n> here's the commit: 0d9708a0f97685144aa7a9773755832dab459b07\n> \n> the way it works is you can pass in \"formats\" kwarg in the field constructor containing a list of various formats to try.\n> \n> ---\n> \n> Reply to this email directly or view it on GitHub:\n> https://github.com/coleifer/peewee/issues/68#issuecomment-5694864\n\n## \n\nBen Hughes\nChange & Innovation Lead\nBright Approach Ltd.\nTel: +447427600266\nTwitter: @bwghughes\nhttp://about.me/bwghughes\n",
"No problem, glad to hear you're liking peewee!\n"
] | 2012-04-04T18:34:14 | 2012-05-14T19:21:38 | 2012-04-06T20:00:17 | NONE | null | I have an SQLite database which has a DateTimeField() with a few different datetime formats (not on purpose). I will probably fix my datetime values, but I thought I'd post this in case you feel peewee should handle this gracefully?
2011-11-15 21:53:59.759451+0000
2011-11-28 20:12:03
2009-01-01 (error)
http://paste.pocoo.org/show/aH7tITRfn9mhczxgWq3u/
Thanks for Peewee (and Flask-Peewee)!
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/68/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/68/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/67 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/67/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/67/comments | https://api.github.com/repos/coleifer/peewee/issues/67/events | https://github.com/coleifer/peewee/issues/67 | 3,915,715 | MDU6SXNzdWUzOTE1NzE1 | 67 | Mysql error 2014 and 2006 | {
"login": "LeoDT",
"id": 685203,
"node_id": "MDQ6VXNlcjY4NTIwMw==",
"avatar_url": "https://avatars.githubusercontent.com/u/685203?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/LeoDT",
"html_url": "https://github.com/LeoDT",
"followers_url": "https://api.github.com/users/LeoDT/followers",
"following_url": "https://api.github.com/users/LeoDT/following{/other_user}",
"gists_url": "https://api.github.com/users/LeoDT/gists{/gist_id}",
"starred_url": "https://api.github.com/users/LeoDT/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/LeoDT/subscriptions",
"organizations_url": "https://api.github.com/users/LeoDT/orgs",
"repos_url": "https://api.github.com/users/LeoDT/repos",
"events_url": "https://api.github.com/users/LeoDT/events{/privacy}",
"received_events_url": "https://api.github.com/users/LeoDT/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"hey.....\n",
"Try closing your connections. Is your server multithreaded by chance?\n",
"If I close the connections, this problem seems solved.\nBut is it good to reconnect mysql every request?\n\nMultithreaded by chance? How to check this?\n",
"Yeah you should not reuse your conns across requests. Use a connection pooler if you're concerned about performance. Django opens a connection per request, fwiw.\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",
"I know its a very old post but, I cant seem to find this class in latest documentation. \r\nWas this removed for some reason? (automatic-reconnect)",
"Yes, but you can implement it yourself. Perhaps I'll add it back, since this trips up a lot of MySQL users -- particularly error 2006.\r\n\r\nThe thing is...this error indicates that you have a long-lived idle connection. MySQL closes idle connections after a certain time (which I think is configurable). So it may be a problem with the way your application is using db connections.",
"I've reimplemented it: af914ccad7d09c070000da4153f88aef69b6e44f\r\n\r\nYou can now use the `ReconnectMixin` along with your `MySQLDatabase` to get auto-reconnect logic for certain types of errors.",
"Thank you ! :) ",
"I found that you've re-added a `ReconnectMixin` in the playhouse, but no docs on that was found in the documentation site. I came across that by your answers on stackoverflow. Could you please:\r\n\r\n1. Add docs.\r\n2. Tell us when to use ReconnectMixin and when to use a connection pool?",
"It is not documented in the online docs because its use is not recommended... it is available because MySQL users seem to run into the same problem frequently but are ill-equipped to find a more correct solution.\r\n\r\nThe class itself has a docstring, though. Hopefully it is clear:\r\n\r\n```python\r\n \"\"\"\r\n Mixin class that attempts to automatically reconnect to the database under\r\n certain error conditions.\r\n\r\n For example, MySQL servers will typically close connections that are idle\r\n for 28800 seconds (\"wait_timeout\" setting). If your application makes use\r\n of long-lived connections, you may find your connections are closed after\r\n a period of no activity. This mixin will attempt to reconnect automatically\r\n when these errors occur.\r\n\r\n This mixin class probably should not be used with Postgres (unless you\r\n REALLY know what you are doing) and definitely has no business being used\r\n with Sqlite. If you wish to use with Postgres, you will need to adapt the\r\n `reconnect_errors` attribute to something appropriate for Postgres.\r\n \"\"\"\r\n```\r\n\r\nThe jist of it is that [MySQL server may terminate an idle connection after a certain timeout has elapsed](https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_wait_timeout). An idle connection typically indicates your program has failed to clean up resources. This is mentioned in the peewee docs [here](http://docs.peewee-orm.com/en/latest/peewee/database.html#error-2006-mysql-server-has-gone-away) and [here](http://docs.peewee-orm.com/en/latest/peewee/database.html#framework-integration). Automatically reconnecting and retrying the query that was rejected seems like a recipe for trouble to me.\r\n\r\nThe connection pool is used when you want to avoid the latency introduced by frequent opening/closing of connections - e.g., a web-app. That's pretty much it."
] | 2012-04-01T10:49:06 | 2019-12-06T04:27:32 | 2012-04-06T17:51:46 | NONE | null | I'm building a small site using peewee and bottle.py.
And I got Mysql error 2014 and 2006 frequently either develop env(windows) or product env(linux).
I connect mysql before every request, but don't close it. Does this matter?
Mysql error 2014 is "Commands out of sync; you can't run this command now" and 2006 is "MySQL server has gone away".
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/67/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/67/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/66 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/66/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/66/comments | https://api.github.com/repos/coleifer/peewee/issues/66/events | https://github.com/coleifer/peewee/pull/66 | 3,893,120 | MDExOlB1bGxSZXF1ZXN0MTA3NjE4NQ== | 66 | set the default charset to utf8 when create_table | {
"login": "wong2",
"id": 321947,
"node_id": "MDQ6VXNlcjMyMTk0Nw==",
"avatar_url": "https://avatars.githubusercontent.com/u/321947?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/wong2",
"html_url": "https://github.com/wong2",
"followers_url": "https://api.github.com/users/wong2/followers",
"following_url": "https://api.github.com/users/wong2/following{/other_user}",
"gists_url": "https://api.github.com/users/wong2/gists{/gist_id}",
"starred_url": "https://api.github.com/users/wong2/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/wong2/subscriptions",
"organizations_url": "https://api.github.com/users/wong2/orgs",
"repos_url": "https://api.github.com/users/wong2/repos",
"events_url": "https://api.github.com/users/wong2/events{/privacy}",
"received_events_url": "https://api.github.com/users/wong2/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Forgot to say that I just tested it in MySQL.\n",
"Does this not work? https://github.com/coleifer/peewee/blob/master/peewee.py#L244\n",
"I think that is the charset when connecting to MySQL, it doesn't specify the default charset for creating tables so when I insert Chinese words to the table, they are garbled\n"
] | 2012-03-30T06:22:30 | 2014-07-06T01:52:03 | 2012-04-02T15:56:04 | NONE | null | when create table, set the default charset to utf-8 to support more languages such as Chinese.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/66/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/66/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/66",
"html_url": "https://github.com/coleifer/peewee/pull/66",
"diff_url": "https://github.com/coleifer/peewee/pull/66.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/66.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/65 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/65/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/65/comments | https://api.github.com/repos/coleifer/peewee/issues/65/events | https://github.com/coleifer/peewee/pull/65 | 3,780,448 | MDExOlB1bGxSZXF1ZXN0MTAzNjQxOA== | 65 | Fix problems with models which have a "model" field | {
"login": "karlb",
"id": 144773,
"node_id": "MDQ6VXNlcjE0NDc3Mw==",
"avatar_url": "https://avatars.githubusercontent.com/u/144773?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/karlb",
"html_url": "https://github.com/karlb",
"followers_url": "https://api.github.com/users/karlb/followers",
"following_url": "https://api.github.com/users/karlb/following{/other_user}",
"gists_url": "https://api.github.com/users/karlb/gists{/gist_id}",
"starred_url": "https://api.github.com/users/karlb/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/karlb/subscriptions",
"organizations_url": "https://api.github.com/users/karlb/orgs",
"repos_url": "https://api.github.com/users/karlb/repos",
"events_url": "https://api.github.com/users/karlb/events{/privacy}",
"received_events_url": "https://api.github.com/users/karlb/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"this is probably an issue in more places than just this\n",
"As a workaround you could try using the db_column attribute on your field named \"model\":\n\n``` python\n\nclass MyModel(Model):\n model_alias = CharField(db_column='model')\n```\n",
"So far my project works fine with the change in the pull request (without workaround). Should I look for more places in the code with this problem and submit another pull request, or is there another plan?\n",
"I apologize for taking a while getting to this, I'll see about merging something up in the next day or two.\n"
] | 2012-03-23T14:15:49 | 2014-07-06T01:52:04 | 2012-04-10T12:57:13 | NONE | null | The same solution is already being used by the Q class.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/65/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/65/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/65",
"html_url": "https://github.com/coleifer/peewee/pull/65",
"diff_url": "https://github.com/coleifer/peewee/pull/65.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/65.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/64 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/64/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/64/comments | https://api.github.com/repos/coleifer/peewee/issues/64/events | https://github.com/coleifer/peewee/pull/64 | 3,745,004 | MDExOlB1bGxSZXF1ZXN0MTAyMDkzNQ== | 64 | Whitespace, hee-YAH! | {
"login": "medwards",
"id": 7339,
"node_id": "MDQ6VXNlcjczMzk=",
"avatar_url": "https://avatars.githubusercontent.com/u/7339?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/medwards",
"html_url": "https://github.com/medwards",
"followers_url": "https://api.github.com/users/medwards/followers",
"following_url": "https://api.github.com/users/medwards/following{/other_user}",
"gists_url": "https://api.github.com/users/medwards/gists{/gist_id}",
"starred_url": "https://api.github.com/users/medwards/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/medwards/subscriptions",
"organizations_url": "https://api.github.com/users/medwards/orgs",
"repos_url": "https://api.github.com/users/medwards/repos",
"events_url": "https://api.github.com/users/medwards/events{/privacy}",
"received_events_url": "https://api.github.com/users/medwards/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2012-03-21T12:57:17 | 2014-06-17T14:00:58 | 2012-03-21T12:59:16 | CONTRIBUTOR | null | I am such a bore, I know.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/64/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/64/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/64",
"html_url": "https://github.com/coleifer/peewee/pull/64",
"diff_url": "https://github.com/coleifer/peewee/pull/64.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/64.patch",
"merged_at": "2012-03-21T12:59:15"
} |
https://api.github.com/repos/coleifer/peewee/issues/63 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/63/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/63/comments | https://api.github.com/repos/coleifer/peewee/issues/63/events | https://github.com/coleifer/peewee/issues/63 | 3,629,824 | MDU6SXNzdWUzNjI5ODI0 | 63 | Raw Expression select with value | {
"login": "ManinTheVan",
"id": 1532983,
"node_id": "MDQ6VXNlcjE1MzI5ODM=",
"avatar_url": "https://avatars.githubusercontent.com/u/1532983?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/ManinTheVan",
"html_url": "https://github.com/ManinTheVan",
"followers_url": "https://api.github.com/users/ManinTheVan/followers",
"following_url": "https://api.github.com/users/ManinTheVan/following{/other_user}",
"gists_url": "https://api.github.com/users/ManinTheVan/gists{/gist_id}",
"starred_url": "https://api.github.com/users/ManinTheVan/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/ManinTheVan/subscriptions",
"organizations_url": "https://api.github.com/users/ManinTheVan/orgs",
"repos_url": "https://api.github.com/users/ManinTheVan/repos",
"events_url": "https://api.github.com/users/ManinTheVan/events{/privacy}",
"received_events_url": "https://api.github.com/users/ManinTheVan/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Yeah, only works like this in where clauses right now. Will look into it\n",
"I'm actually not sure whether this is a valid use-case -- in your example you are querying for the first letter of a constant (\"myFirstName\") -- what is the benefit of doing that?\n\nI'm assuming the query you're hoping to generate is something like (using sqlite style parameter interpolation):\n\n``` python\n>>> query = User.select(['id', 'username', R('LOWER(SUBSTR( %s, 1, 1))', 'myFirstName' , 'first_letter')])\n>>> query.sql()\n('SELECT \"id\", LOWER(SUBSTR(?, 1, 1)) AS first_letter FROM \"users\"', ['myFirstName'])\n```\n\nBut if you know the \"first_letter\" is always going to be 'm' why add it to the query? If you hope to use that alias as part of the where clause you could instead write:\n\n``` python\n>>> query = User.select().where(R('LOWER(SUBSTR(username, 1, 1))=%s', 'm'))\n>>> query.sql()\n('SELECT \"id\", \"username\" FROM \"users\" WHERE LOWER(SUBSTR(username, 1, 1))=?', ['m'])\n```\n\nAm I missing something? I've got this written in a branch but as I was thinking about it I had a hard time thinking of how it would be useful. Thanks!\n"
] | 2012-03-13T14:16:18 | 2012-03-20T16:29:52 | 2012-03-20T16:29:52 | NONE | null | Hello Charles,
want to use 'select' in the following way.
<< User.select(['id', 'username', R('LOWER(SUBSTR( %s, 1, 1))', 'myFirstName' , 'first_letter')]) >>
but there is no implementation using values and alias together ?
Have you any idea how to fix it?
Kind regards,
Chris
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/63/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/63/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/62 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/62/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/62/comments | https://api.github.com/repos/coleifer/peewee/issues/62/events | https://github.com/coleifer/peewee/pull/62 | 3,600,304 | MDExOlB1bGxSZXF1ZXN0OTYzNDE1 | 62 | fix typo in samples | {
"login": "kryskool",
"id": 337842,
"node_id": "MDQ6VXNlcjMzNzg0Mg==",
"avatar_url": "https://avatars.githubusercontent.com/u/337842?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/kryskool",
"html_url": "https://github.com/kryskool",
"followers_url": "https://api.github.com/users/kryskool/followers",
"following_url": "https://api.github.com/users/kryskool/following{/other_user}",
"gists_url": "https://api.github.com/users/kryskool/gists{/gist_id}",
"starred_url": "https://api.github.com/users/kryskool/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/kryskool/subscriptions",
"organizations_url": "https://api.github.com/users/kryskool/orgs",
"repos_url": "https://api.github.com/users/kryskool/repos",
"events_url": "https://api.github.com/users/kryskool/events{/privacy}",
"received_events_url": "https://api.github.com/users/kryskool/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2012-03-11T10:24:31 | 2014-07-06T01:52:07 | 2012-03-12T20:19:15 | CONTRIBUTOR | null | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/62/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/62/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/62",
"html_url": "https://github.com/coleifer/peewee/pull/62",
"diff_url": "https://github.com/coleifer/peewee/pull/62.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/62.patch",
"merged_at": "2012-03-12T20:19:15"
} |
|
https://api.github.com/repos/coleifer/peewee/issues/61 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/61/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/61/comments | https://api.github.com/repos/coleifer/peewee/issues/61/events | https://github.com/coleifer/peewee/issues/61 | 3,600,090 | MDU6SXNzdWUzNjAwMDkw | 61 | Strange models behavior | {
"login": "gnezim",
"id": 617210,
"node_id": "MDQ6VXNlcjYxNzIxMA==",
"avatar_url": "https://avatars.githubusercontent.com/u/617210?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/gnezim",
"html_url": "https://github.com/gnezim",
"followers_url": "https://api.github.com/users/gnezim/followers",
"following_url": "https://api.github.com/users/gnezim/following{/other_user}",
"gists_url": "https://api.github.com/users/gnezim/gists{/gist_id}",
"starred_url": "https://api.github.com/users/gnezim/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/gnezim/subscriptions",
"organizations_url": "https://api.github.com/users/gnezim/orgs",
"repos_url": "https://api.github.com/users/gnezim/repos",
"events_url": "https://api.github.com/users/gnezim/events{/privacy}",
"received_events_url": "https://api.github.com/users/gnezim/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Glad you like the library! Here's what I'd suggest you try -- you can pass 2-tuples into select clauses to specify aliases:\n\n``` python\n\nCC_map.select({\n CC_map: [('id', 'cc_map_id'), 'currency_id'],\n Currencies: ['currency_abbr'],\n}).order_by('country_id').where(country_id=country_id).join(Currencies, on='currency_id')\n```\n",
"In 0.9.2 that does the trick. Thanks\n"
] | 2012-03-11T09:10:48 | 2012-03-21T09:55:08 | 2012-03-17T14:53:16 | NONE | null | Problems started after Commit: 62bd00b90686aea6d6440ff129c30cf28a2a9449
Whole speak is about MySQL as backend
inside one of models I have method:
<code>
def getAbbrByCountryId(self, country_id):
return CC_map.select(
{CC_map: ['id AS cc_map_id, currency_id'],
Currencies: ['currency_abbr']}
).order_by('country_id').where(country_id=country_id
).join(Currencies, on='currency_id')
</code>
When you provided "smart select_related() behavior" I have no access to attributes created in code above.
Tried latest version and got problems with not assigning table link name to column names.
I get:
<code>SELECT id AS cc_map_id, currency_id, t2.`currency_abbr`
FROM `cc_map` AS t1
INNER JOIN `currencies` AS t2 ON t1.`currency_id` = t2.`id`
WHERE t1.`country_id` =1
ORDER BY t1.`country_id` ASC </code>
instead of
<code>SELECT t1.id AS cc_map_id, t1.currency_id, t2.`currency_abbr`
FROM `cc_map` AS t1
INNER JOIN `currencies` AS t2 ON t1.`currency_id` = t2.`id`
WHERE t1.`country_id` =1
ORDER BY t1.`country_id` ASC </code>
Tell If you need any additional info - I'll provide it.
P.S.
Thanks for your great work!
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/61/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/61/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/60 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/60/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/60/comments | https://api.github.com/repos/coleifer/peewee/issues/60/events | https://github.com/coleifer/peewee/issues/60 | 3,524,522 | MDU6SXNzdWUzNTI0NTIy | 60 | DecimalField ignores precision | {
"login": "emestee",
"id": 1101501,
"node_id": "MDQ6VXNlcjExMDE1MDE=",
"avatar_url": "https://avatars.githubusercontent.com/u/1101501?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/emestee",
"html_url": "https://github.com/emestee",
"followers_url": "https://api.github.com/users/emestee/followers",
"following_url": "https://api.github.com/users/emestee/following{/other_user}",
"gists_url": "https://api.github.com/users/emestee/gists{/gist_id}",
"starred_url": "https://api.github.com/users/emestee/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/emestee/subscriptions",
"organizations_url": "https://api.github.com/users/emestee/orgs",
"repos_url": "https://api.github.com/users/emestee/repos",
"events_url": "https://api.github.com/users/emestee/events{/privacy}",
"received_events_url": "https://api.github.com/users/emestee/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"You need to set the arguments using keywords max_digits and decimal_places:\n\n```\nclass Foo(Model):\n foo_field = DecimalField(decimal_places=2)\n```\n\n```\n+-------+---------------+------+-----+---------+----------------+\n| Field | Type | Null | Key | Default | Extra |\n+-------+---------------+------+-----+---------+----------------+\n| id | int(11) | NO | PRI | NULL | auto_increment |\n| df | decimal(10,2) | NO | | NULL | |\n+-------+---------------+------+-----+---------+----------------+\n```\n",
"Apologies, I feel pretty silly for not paying attention to the documentation.\n\nPlease do note that the docs says the decimal_places argument is simply _places_ at http://charlesleifer.com/docs/peewee/peewee/fields.html#field-types-table\n"
] | 2012-03-06T14:02:22 | 2012-03-08T08:58:01 | 2012-03-07T21:23:35 | NONE | null | At least under MySQL, DecimalField ignores the precision parameters passed to the constructor, and the created table always carries the decimal field with precision 10,5.
Example code:
``` python
class Foo(peewee.Model):
foo_field = DecimalField(15,2)
Foo.create_table()
```
Produces a table with foo_field type set to decimal(10,5)
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/60/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/60/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/59 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/59/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/59/comments | https://api.github.com/repos/coleifer/peewee/issues/59/events | https://github.com/coleifer/peewee/issues/59 | 3,388,876 | MDU6SXNzdWUzMzg4ODc2 | 59 | In memory SQLite support? | {
"login": "stodge",
"id": 95512,
"node_id": "MDQ6VXNlcjk1NTEy",
"avatar_url": "https://avatars.githubusercontent.com/u/95512?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/stodge",
"html_url": "https://github.com/stodge",
"followers_url": "https://api.github.com/users/stodge/followers",
"following_url": "https://api.github.com/users/stodge/following{/other_user}",
"gists_url": "https://api.github.com/users/stodge/gists{/gist_id}",
"starred_url": "https://api.github.com/users/stodge/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/stodge/subscriptions",
"organizations_url": "https://api.github.com/users/stodge/orgs",
"repos_url": "https://api.github.com/users/stodge/repos",
"events_url": "https://api.github.com/users/stodge/events{/privacy}",
"received_events_url": "https://api.github.com/users/stodge/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"My apologies - I got it working. :)\n",
"Yeah just set the database name to \":memory:\"\nOn Feb 25, 2012 8:57 PM, \"Mike Stoddart\" <\[email protected]>\nwrote:\n\n> I may have missed this in the docs, but does Peewee support in memory\n> SQLite databases? Thanks\n> \n> ---\n> \n> Reply to this email directly or view it on GitHub:\n> https://github.com/coleifer/peewee/issues/59\n"
] | 2012-02-26T02:57:01 | 2012-02-26T15:57:55 | 2012-02-26T02:59:37 | NONE | null | I may have missed this in the docs, but does Peewee support in memory SQLite databases? Thanks
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/59/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/59/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/58 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/58/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/58/comments | https://api.github.com/repos/coleifer/peewee/issues/58/events | https://github.com/coleifer/peewee/pull/58 | 3,320,684 | MDExOlB1bGxSZXF1ZXN0ODYyODIx | 58 | Allow foreign key select fields to be set in Meta config | {
"login": "prggmr",
"id": 207314,
"node_id": "MDQ6VXNlcjIwNzMxNA==",
"avatar_url": "https://avatars.githubusercontent.com/u/207314?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/prggmr",
"html_url": "https://github.com/prggmr",
"followers_url": "https://api.github.com/users/prggmr/followers",
"following_url": "https://api.github.com/users/prggmr/following{/other_user}",
"gists_url": "https://api.github.com/users/prggmr/gists{/gist_id}",
"starred_url": "https://api.github.com/users/prggmr/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/prggmr/subscriptions",
"organizations_url": "https://api.github.com/users/prggmr/orgs",
"repos_url": "https://api.github.com/users/prggmr/repos",
"events_url": "https://api.github.com/users/prggmr/events{/privacy}",
"received_events_url": "https://api.github.com/users/prggmr/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"See commit 7b76eca5b14211d70aa8231b2c1b65cb6a6e5b36 not sure how that other one got so messed up ... \n",
"I will pass on merging this. Traversing the FK lookup is a convenient shorthand, and not really painful if doing in small amounts. If you're following this relationship in a loop, though, then you are costing yourself N+1 queries for the size of the result set. This can be boiled down to a single quiery using the explicit select syntax:\n\n```\n# loop over all the blog entries\nEntry.select({\n Entry: ['pk', 'title', 'blog'],\n Blog: ['id', 'title'],\n User: ['username'],\n}).join(Blog).join(User)\n\n# Yields the following SQL:\nSELECT t1.\"pk\", t1.\"title\", t1.\"blog_id\", t2.\"id\", t2.\"title\", t3.\"username\" \nFROM \"entry\" AS t1 \nINNER JOIN \"blog\" AS t2 \n ON t1.\"blog_id\" = t2.\"id\"\nLEFT OUTER JOIN \"users\" AS t3\n ON t2.\"id\" = t3.\"blog_id\"\n```\n\nthen, traversing lookups will not cost you an extra query and the related models will only be populated with the field syo uexplicitly selected.\n\nAs for the other thing, the R() objects, i'd definitley be interested in seeing a diff!\n",
"Defiantly makes sense in terms of loop performance but in my case models are only queried for a single result and returned giving the cost of +1 query outweighed by the benefit of a standardized select with less overall code.\n\nAs for the R object all I simply did was put together the following.\n\nNote that this could probably be better as this was a quick fix but for my purposes of needing complex where expressions joined directly with a Q object has worked so far without problems.\n\n```\nclass R(object):\n def __init__(self, *params):\n self.params = params\n self.parent = None\n\n def sql_select(self):\n if len(self.params) == 2:\n return self.params\n else:\n raise ValueError('Incorrect number of argument provided for R() expression')\n\n def connect(self, connector):\n if self.parent is None:\n self.parent = Node(connector)\n self.parent.children.append(self)\n\n def __or__(self, rhs):\n self.connect('OR')\n return self.parent | rhs\n\n def __and__(self, rhs):\n self.connect('AND')\n return self.parent & rhs\n\n def sql_where(self):\n return self.params[0], self.params[1:]\n```\n\nDisregard last found a possible solution.\n"
] | 2012-02-21T20:44:22 | 2014-07-06T01:52:09 | 2012-02-22T15:31:09 | NONE | null | Basically as it says,
I ran into the problem that unnecessary data tied to a model was being returned during the FK selection and since most of my FK lookups are parsed and directly outputted to an API performing an inline filter for these unwanted fields on a case by case basis would be cumbersome and error prone.
So I just hacked into peewee and put it in the Models Meta config to allow for this, I am not 100% if it needed to go both in the _ForeignRelatedObject_ & _ReverseForeignRelatedObject_ so I just stuck it in _ForeignRelatedObject_.
Below is an example
```
class User(Model):
class Meta:
db_table = 'user'
fk_select = ['username', 'email', 'id']
id = PrimaryKeyField(db_index = True)
email = CharField(db_index = True, unique = True)
password = CharField()
username = CharField(unique = True, null = True)
verified = BooleanField(null = True)
verification_code = CharField(null = True)
```
Also note sure if this has gone into the latest already but I have reconstructed the "R" objects to work as "Q" objects in the sense you can join them using "&" and "|" syntax which proved very helpful to me when writing some more complex queries, this is not in my fork but if you are interested just let me know.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/58/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/58/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/58",
"html_url": "https://github.com/coleifer/peewee/pull/58",
"diff_url": "https://github.com/coleifer/peewee/pull/58.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/58.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/57 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/57/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/57/comments | https://api.github.com/repos/coleifer/peewee/issues/57/events | https://github.com/coleifer/peewee/issues/57 | 3,288,795 | MDU6SXNzdWUzMjg4Nzk1 | 57 | Define database name at runtime? | {
"login": "stodge",
"id": 95512,
"node_id": "MDQ6VXNlcjk1NTEy",
"avatar_url": "https://avatars.githubusercontent.com/u/95512?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/stodge",
"html_url": "https://github.com/stodge",
"followers_url": "https://api.github.com/users/stodge/followers",
"following_url": "https://api.github.com/users/stodge/following{/other_user}",
"gists_url": "https://api.github.com/users/stodge/gists{/gist_id}",
"starred_url": "https://api.github.com/users/stodge/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/stodge/subscriptions",
"organizations_url": "https://api.github.com/users/stodge/orgs",
"repos_url": "https://api.github.com/users/stodge/repos",
"events_url": "https://api.github.com/users/stodge/events{/privacy}",
"received_events_url": "https://api.github.com/users/stodge/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"the database name isn't needed until a connection is opened, so you _could_ manually set the name at runtime before a query gets executed or a connection opened. what is your use-case? its kind of tricky considering that your model definitions are already written, unless you are creating those dynamically as well.\n",
"I found a solution. I can create the models and database name dynamically at runtime from json descriptions. Initial testing shows it works. Thanks\n"
] | 2012-02-20T01:45:14 | 2012-02-26T01:05:18 | 2012-02-26T01:05:18 | NONE | null | I don't know the name of my database until runtime. Is there any way to support this?
Thanks
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/57/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/57/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/56 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/56/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/56/comments | https://api.github.com/repos/coleifer/peewee/issues/56/events | https://github.com/coleifer/peewee/issues/56 | 3,284,733 | MDU6SXNzdWUzMjg0NzMz | 56 | Change the lib name, I think this one is already taken | {
"login": "ksamuel",
"id": 221886,
"node_id": "MDQ6VXNlcjIyMTg4Ng==",
"avatar_url": "https://avatars.githubusercontent.com/u/221886?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/ksamuel",
"html_url": "https://github.com/ksamuel",
"followers_url": "https://api.github.com/users/ksamuel/followers",
"following_url": "https://api.github.com/users/ksamuel/following{/other_user}",
"gists_url": "https://api.github.com/users/ksamuel/gists{/gist_id}",
"starred_url": "https://api.github.com/users/ksamuel/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/ksamuel/subscriptions",
"organizations_url": "https://api.github.com/users/ksamuel/orgs",
"repos_url": "https://api.github.com/users/ksamuel/repos",
"events_url": "https://api.github.com/users/ksamuel/events{/privacy}",
"received_events_url": "https://api.github.com/users/ksamuel/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"+1\n",
"http://www.youtube.com/watch?v=FsJhfwbfMvU\n"
] | 2012-02-19T13:41:00 | 2012-02-20T22:05:20 | 2012-02-20T22:05:20 | NONE | null | http://imgur.com/r/WTF/xmydq
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/56/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/56/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/55 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/55/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/55/comments | https://api.github.com/repos/coleifer/peewee/issues/55/events | https://github.com/coleifer/peewee/issues/55 | 3,252,371 | MDU6SXNzdWUzMjUyMzcx | 55 | Invalid method signature | {
"login": "teserak",
"id": 447351,
"node_id": "MDQ6VXNlcjQ0NzM1MQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/447351?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/teserak",
"html_url": "https://github.com/teserak",
"followers_url": "https://api.github.com/users/teserak/followers",
"following_url": "https://api.github.com/users/teserak/following{/other_user}",
"gists_url": "https://api.github.com/users/teserak/gists{/gist_id}",
"starred_url": "https://api.github.com/users/teserak/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/teserak/subscriptions",
"organizations_url": "https://api.github.com/users/teserak/orgs",
"repos_url": "https://api.github.com/users/teserak/repos",
"events_url": "https://api.github.com/users/teserak/events{/privacy}",
"received_events_url": "https://api.github.com/users/teserak/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2012-02-16T14:53:03 | 2012-02-16T14:54:45 | 2012-02-16T14:54:45 | NONE | null | Invalid method signature in Database class:
Is:
```
def sequence_exists(self):
raise NotImplementedError
```
Should be:
```
def sequence_exists(self, sequence_name):
raise NotImplementedError
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/55/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/55/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/54 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/54/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/54/comments | https://api.github.com/repos/coleifer/peewee/issues/54/events | https://github.com/coleifer/peewee/issues/54 | 3,229,256 | MDU6SXNzdWUzMjI5MjU2 | 54 | sql meta information generates wrong column info in some cases | {
"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 | [] | 2012-02-15T01:56:16 | 2012-02-15T02:01:03 | 2012-02-15T02:01:03 | OWNER | null | ```
In [6]: sq.sql_meta()
Out[6]:
('SELECT t2."feature", SUM(t1."count") AS count FROM "featurecount" AS t1 INNER JOIN "feature" AS t2 ON t1."feature_id" = t2."id" GROUP BY t2."feature"',
[],
{'columns': [(models.FeatureCount, ('SUM', 'count', 'count')),
(models.Feature, 'feature')],
'graph': {models.FeatureCount: [(models.Feature, None, None)]}})
```
Should be:
```
'columns': [(models.Feature, 'feature'), (models.FeatureCount, ('SUM', 'count', 'count'))]
```
```
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/54/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/54/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/53 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/53/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/53/comments | https://api.github.com/repos/coleifer/peewee/issues/53/events | https://github.com/coleifer/peewee/issues/53 | 3,142,624 | MDU6SXNzdWUzMTQyNjI0 | 53 | Duplicated key | {
"login": "wtld",
"id": 1318746,
"node_id": "MDQ6VXNlcjEzMTg3NDY=",
"avatar_url": "https://avatars.githubusercontent.com/u/1318746?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/wtld",
"html_url": "https://github.com/wtld",
"followers_url": "https://api.github.com/users/wtld/followers",
"following_url": "https://api.github.com/users/wtld/following{/other_user}",
"gists_url": "https://api.github.com/users/wtld/gists{/gist_id}",
"starred_url": "https://api.github.com/users/wtld/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/wtld/subscriptions",
"organizations_url": "https://api.github.com/users/wtld/orgs",
"repos_url": "https://api.github.com/users/wtld/repos",
"events_url": "https://api.github.com/users/wtld/events{/privacy}",
"received_events_url": "https://api.github.com/users/wtld/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Would you mind sharing your model definiton?\n",
"``` python\nclass BaseModel(peewee.Model):\n\n class Meta:\n database = database\n\nclass Test(BaseModel):\n name = peewee.CharField()\n\nTest.create_table()\n```\n"
] | 2012-02-08T16:00:37 | 2012-02-13T15:47:49 | 2012-02-13T15:47:48 | NONE | null | Table created in MySQL by create_table method:
``` sql
CREATE TABLE `test` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `test_id` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
```
Key on 'id' column is duplicated (PRIMARY KEY and UNIQUE KEY).
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/53/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/53/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/52 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/52/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/52/comments | https://api.github.com/repos/coleifer/peewee/issues/52/events | https://github.com/coleifer/peewee/issues/52 | 3,088,968 | MDU6SXNzdWUzMDg4OTY4 | 52 | Cache? | {
"login": "23doors",
"id": 1051101,
"node_id": "MDQ6VXNlcjEwNTExMDE=",
"avatar_url": "https://avatars.githubusercontent.com/u/1051101?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/23doors",
"html_url": "https://github.com/23doors",
"followers_url": "https://api.github.com/users/23doors/followers",
"following_url": "https://api.github.com/users/23doors/following{/other_user}",
"gists_url": "https://api.github.com/users/23doors/gists{/gist_id}",
"starred_url": "https://api.github.com/users/23doors/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/23doors/subscriptions",
"organizations_url": "https://api.github.com/users/23doors/orgs",
"repos_url": "https://api.github.com/users/23doors/repos",
"events_url": "https://api.github.com/users/23doors/events{/privacy}",
"received_events_url": "https://api.github.com/users/23doors/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"If you iterate over a QueryResultWrapper, the object that wraps a db cursor when doing a select queyr, results will be cached in memory (if iterating over a large data set you can use the queryresultwrapper.iterator() which doesn't cache things).\n\nBeyond that there is no caching, nor do i think there should be. ORM level caching always seemed a little sketchy to me, probably the best place to put caching is higher up, in the application.\n"
] | 2012-02-03T21:19:00 | 2012-02-06T18:06:28 | 2012-02-06T18:06:28 | NONE | null | Is peewee caching any results?
I would love to see caching mechanisms here like in https://bitbucket.org/jmoiron/johnny-cache.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/52/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/52/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/51 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/51/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/51/comments | https://api.github.com/repos/coleifer/peewee/issues/51/events | https://github.com/coleifer/peewee/issues/51 | 3,037,596 | MDU6SXNzdWUzMDM3NTk2 | 51 | Select for update | {
"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 | [] | 2012-01-31T15:48:31 | 2012-01-31T17:25:53 | 2012-01-31T17:25:53 | OWNER | null | FROM @23doors:
There doesn't seem to be any kind of for update functionality? This is really very important for simple row-lock operations.
What I mean is a functionality like this one:
http://docs.sqlalchemy.org/en/latest/core/expression_api.html#sqlalchemy.sql.expression.select
(for_update parameter)
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/51/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/51/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/50 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/50/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/50/comments | https://api.github.com/repos/coleifer/peewee/issues/50/events | https://github.com/coleifer/peewee/issues/50 | 3,021,994 | MDU6SXNzdWUzMDIxOTk0 | 50 | Pony request, support for something akin to django orm's .extra() | {
"login": "coleifer",
"id": 119974,
"node_id": "MDQ6VXNlcjExOTk3NA==",
"avatar_url": "https://avatars.githubusercontent.com/u/119974?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/coleifer",
"html_url": "https://github.com/coleifer",
"followers_url": "https://api.github.com/users/coleifer/followers",
"following_url": "https://api.github.com/users/coleifer/following{/other_user}",
"gists_url": "https://api.github.com/users/coleifer/gists{/gist_id}",
"starred_url": "https://api.github.com/users/coleifer/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/coleifer/subscriptions",
"organizations_url": "https://api.github.com/users/coleifer/orgs",
"repos_url": "https://api.github.com/users/coleifer/repos",
"events_url": "https://api.github.com/users/coleifer/events{/privacy}",
"received_events_url": "https://api.github.com/users/coleifer/received_events",
"type": "User",
"site_admin": false
} | [
{
"id": 191751,
"node_id": "MDU6TGFiZWwxOTE3NTE=",
"url": "https://api.github.com/repos/coleifer/peewee/labels/Feature",
"name": "Feature",
"color": "02e10c",
"default": false,
"description": null
}
] | closed | false | null | [] | null | [
"Woohoo!! Added!\n\nhttp://charlesleifer.com/docs/peewee/peewee/querying.html#sql-functions-raw-expressions-and-the-r-object\n"
] | 2012-01-30T15:36:19 | 2012-01-31T06:34:25 | 2012-01-31T06:34:25 | OWNER | null | Currently you are limited, more or less, to expressing select queries using the available abstractions - simple field queries, queries against column data (F objects), aggregations (min/max/count/etc), and aliases (foo as bar). To go beyond that requires using the RawQuery, which exposes a stripped down interface. Be nice to be able to add arbitrary elements to the select query to express things like "LOWER()" or other functions. Also be nice to add it to the where() clause to express things like CASE statements and the like.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/50/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/50/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/49 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/49/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/49/comments | https://api.github.com/repos/coleifer/peewee/issues/49/events | https://github.com/coleifer/peewee/pull/49 | 3,020,133 | MDExOlB1bGxSZXF1ZXN0NzU0MTIy | 49 | Show field name in "Cannot assign, invalid type" message | {
"login": "karlb",
"id": 144773,
"node_id": "MDQ6VXNlcjE0NDc3Mw==",
"avatar_url": "https://avatars.githubusercontent.com/u/144773?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/karlb",
"html_url": "https://github.com/karlb",
"followers_url": "https://api.github.com/users/karlb/followers",
"following_url": "https://api.github.com/users/karlb/following{/other_user}",
"gists_url": "https://api.github.com/users/karlb/gists{/gist_id}",
"starred_url": "https://api.github.com/users/karlb/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/karlb/subscriptions",
"organizations_url": "https://api.github.com/users/karlb/orgs",
"repos_url": "https://api.github.com/users/karlb/repos",
"events_url": "https://api.github.com/users/karlb/events{/privacy}",
"received_events_url": "https://api.github.com/users/karlb/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"self-trolled 46f073de8f2a9760b30f7581a2c29bf563c8c066\n"
] | 2012-01-30T13:11:29 | 2014-07-06T01:52:11 | 2012-01-30T15:30:07 | NONE | null | I found this useful in two (rather simple) debugging cases.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/49/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/49/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/49",
"html_url": "https://github.com/coleifer/peewee/pull/49",
"diff_url": "https://github.com/coleifer/peewee/pull/49.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/49.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/48 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/48/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/48/comments | https://api.github.com/repos/coleifer/peewee/issues/48/events | https://github.com/coleifer/peewee/issues/48 | 3,010,155 | MDU6SXNzdWUzMDEwMTU1 | 48 | Is table name not allowed numerical value? | {
"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 | [] | 2012-01-29T07:11:37 | 2012-01-30T05:08:47 | 2012-01-30T05:08:47 | NONE | null | Hi.
I use peewee 0.8.0 and MySQL5.5.14,SQLite3.7.5 on MacOSX Lion.
Is table name not allowed like MyTable1 and My1Table?
Numerical value is replaced '_' automatically.
e.g.
MyTable1.create_table() ---> mytable_
My1Table.create_table() ---> my_table
Is this specifications?
Thank you.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/48/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/48/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/47 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/47/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/47/comments | https://api.github.com/repos/coleifer/peewee/issues/47/events | https://github.com/coleifer/peewee/issues/47 | 2,903,884 | MDU6SXNzdWUyOTAzODg0 | 47 | Complex RawQuery? | {
"login": "davidthewatson",
"id": 150892,
"node_id": "MDQ6VXNlcjE1MDg5Mg==",
"avatar_url": "https://avatars.githubusercontent.com/u/150892?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/davidthewatson",
"html_url": "https://github.com/davidthewatson",
"followers_url": "https://api.github.com/users/davidthewatson/followers",
"following_url": "https://api.github.com/users/davidthewatson/following{/other_user}",
"gists_url": "https://api.github.com/users/davidthewatson/gists{/gist_id}",
"starred_url": "https://api.github.com/users/davidthewatson/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/davidthewatson/subscriptions",
"organizations_url": "https://api.github.com/users/davidthewatson/orgs",
"repos_url": "https://api.github.com/users/davidthewatson/repos",
"events_url": "https://api.github.com/users/davidthewatson/events{/privacy}",
"received_events_url": "https://api.github.com/users/davidthewatson/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Yeah, RawQuery is best for querying against a particualr \"model\" as it willr eturn instances. To execute arbitrary queries you could look in the code and see what's happening, but basically:\n\n`database.execute(\"some sql\", (any, parameters, here))`\n"
] | 2012-01-19T21:33:55 | 2012-01-19T21:42:43 | 2012-01-19T21:42:43 | NONE | null | I'm trying to run a RawQuery that creates a view and involves several tables. Is there a way to do this in peewee? It seemed like RawQuery only accounts for simple cases tied to a single table in the data model. Is there a way to do a raw SQL query independent of the data model?
Thanks!
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/47/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/47/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/46 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/46/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/46/comments | https://api.github.com/repos/coleifer/peewee/issues/46/events | https://github.com/coleifer/peewee/pull/46 | 2,898,225 | MDExOlB1bGxSZXF1ZXN0NzEwMjIx | 46 | Unicode value and lookup tests | {
"login": "jokull",
"id": 701,
"node_id": "MDQ6VXNlcjcwMQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/701?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/jokull",
"html_url": "https://github.com/jokull",
"followers_url": "https://api.github.com/users/jokull/followers",
"following_url": "https://api.github.com/users/jokull/following{/other_user}",
"gists_url": "https://api.github.com/users/jokull/gists{/gist_id}",
"starred_url": "https://api.github.com/users/jokull/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/jokull/subscriptions",
"organizations_url": "https://api.github.com/users/jokull/orgs",
"repos_url": "https://api.github.com/users/jokull/repos",
"events_url": "https://api.github.com/users/jokull/events{/privacy}",
"received_events_url": "https://api.github.com/users/jokull/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"What's failing with the postgresql tests?\n",
"The return values from psycopg2 are `str` types, non-decoded. Rev 4a2ba5b adds encoding and decoding and the tests pass.\n\nHere's the result before the patch:\n\n# \n\n## FAIL: test_unicode_lookup (tests.UnicodeFieldTests)\n\nTraceback (most recent call last):\n File \"/Users/jokull/Code/peewee/tests.py\", line 1104, in test_unicode_lookup\n self.assertEqual(a1.title, a.title)\nAssertionError: 'L\\xc3\\xbd\\xc3\\xb0veldi\\xc3\\xb0 \\xc3\\x8dsland' != u'L\\xfd\\xf0veldi\\xf0 \\xcdsland'\n\n# \n\n## FAIL: test_unicode_value (tests.UnicodeFieldTests)\n\nTraceback (most recent call last):\n File \"/Users/jokull/Code/peewee/tests.py\", line 1097, in test_unicode_value\n self.assertEqual(a.title, u'Lýðveldið Ísland')\nAssertionError: 'L\\xc3\\xbd\\xc3\\xb0veldi\\xc3\\xb0 \\xc3\\x8dsland' != u'L\\xfd\\xf0veldi\\xf0 \\xcdsland'\n",
"I'm confused...is this working?\n",
"First commit is the test case so u can see what fails. Second commit fixes it.\n\nSent from my iPhone\n\nOn Jan 19, 2012, at 9:43 PM, Charles Leifer\[email protected]\nwrote:\n\n> I'm confused...is this working?\n> \n> ---\n> \n> Reply to this email directly or view it on GitHub:\n> https://github.com/coleifer/peewee/pull/46#issuecomment-3574890\n",
"For what it's worth the Django ORM does this too.\n",
"Thanks for all your work on this! Merged into master and verified your tests against psql & sqlite. Tested against MySQL as well and am getting failures:\n\n```\n======================================================================\nFAIL: test_unicode_lookup (tests.UnicodeFieldTests)\n----------------------------------------------------------------------\nTraceback (most recent call last):\n File \"/home/charles/code/peewee/tests.py\", line 1012, in test_unicode_lookup\n self.assertEqual(a1.title, a.title)\nAssertionError: 'L\\xfd\\xf0veldi\\xf0 \\xcdsland' != u'L\\xfd\\xf0veldi\\xf0 \\xcdsland'\n\n======================================================================\nFAIL: test_unicode_value (tests.UnicodeFieldTests)\n----------------------------------------------------------------------\nTraceback (most recent call last):\n File \"/home/charles/code/peewee/tests.py\", line 1005, in test_unicode_value\n self.assertEqual(a.title, u'Lýðveldið Ísland')\nAssertionError: 'L\\xfd\\xf0veldi\\xf0 \\xcdsland' != u'L\\xfd\\xf0veldi\\xf0 \\xcdsland'\n```\n",
"Fixed in 0c3b2ef62a83bfdd964be1739817a34d87ea4548\n"
] | 2012-01-19T15:14:54 | 2014-07-06T01:52:13 | 2012-01-20T18:08:25 | CONTRIBUTOR | null | They pass for SQLite but not for PostgreSQL.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/46/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/46/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/46",
"html_url": "https://github.com/coleifer/peewee/pull/46",
"diff_url": "https://github.com/coleifer/peewee/pull/46.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/46.patch",
"merged_at": "2012-01-20T18:08:25"
} |
https://api.github.com/repos/coleifer/peewee/issues/45 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/45/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/45/comments | https://api.github.com/repos/coleifer/peewee/issues/45/events | https://github.com/coleifer/peewee/pull/45 | 2,883,554 | MDExOlB1bGxSZXF1ZXN0NzA0NzM0 | 45 | CharField to return unicode value | {
"login": "jokull",
"id": 701,
"node_id": "MDQ6VXNlcjcwMQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/701?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/jokull",
"html_url": "https://github.com/jokull",
"followers_url": "https://api.github.com/users/jokull/followers",
"following_url": "https://api.github.com/users/jokull/following{/other_user}",
"gists_url": "https://api.github.com/users/jokull/gists{/gist_id}",
"starred_url": "https://api.github.com/users/jokull/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/jokull/subscriptions",
"organizations_url": "https://api.github.com/users/jokull/orgs",
"repos_url": "https://api.github.com/users/jokull/repos",
"events_url": "https://api.github.com/users/jokull/events{/privacy}",
"received_events_url": "https://api.github.com/users/jokull/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Testcases ought to clear that up\n",
"Do you want me to create a UnicodeCharFieldTestCase?\n"
] | 2012-01-18T15:10:59 | 2014-06-12T06:42:43 | 2012-01-19T15:14:07 | CONTRIBUTOR | null | Should CharField be utf-8 decoded? It resolves errors I had with flask-peewee.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/45/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/45/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/45",
"html_url": "https://github.com/coleifer/peewee/pull/45",
"diff_url": "https://github.com/coleifer/peewee/pull/45.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/45.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/44 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/44/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/44/comments | https://api.github.com/repos/coleifer/peewee/issues/44/events | https://github.com/coleifer/peewee/issues/44 | 2,806,299 | MDU6SXNzdWUyODA2Mjk5 | 44 | Foreign keys that do not end with "_id" | {
"login": "karlb",
"id": 144773,
"node_id": "MDQ6VXNlcjE0NDc3Mw==",
"avatar_url": "https://avatars.githubusercontent.com/u/144773?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/karlb",
"html_url": "https://github.com/karlb",
"followers_url": "https://api.github.com/users/karlb/followers",
"following_url": "https://api.github.com/users/karlb/following{/other_user}",
"gists_url": "https://api.github.com/users/karlb/gists{/gist_id}",
"starred_url": "https://api.github.com/users/karlb/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/karlb/subscriptions",
"organizations_url": "https://api.github.com/users/karlb/orgs",
"repos_url": "https://api.github.com/users/karlb/repos",
"events_url": "https://api.github.com/users/karlb/events{/privacy}",
"received_events_url": "https://api.github.com/users/karlb/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Right now the column name is closely tied to the field name -- will see about disentangling this.\n",
"To add some to this,\n\nIf you setup a ForeignKey without a \"_id\" it is created in the table with an \"_id\" appended to the name, e.g. field name blog will have a column name of \"blog_id\" in the table ( at least for MySQL ).\n\n```\nclass Comment(peewee.Model):\n id = PrimaryKeyField()\n blog = ForeignKeyField(Blog)\n```\n\nIf I then attempt to create a new record\n\n```\npeewee.InsertQuery(Comment, blog = a_blog_object)\n```\n\nYou recieve the following\n\n```\nAttributeError: Field name blog not found.\n```\n\nRunning the same with id appended\n\n```\npeewee.InsertQuery(Comment, blog_id = a_blog_object)\n```\n\nWorks as expected.\n\nAlso creating a field with \"_id\" in the name results in the column name doubling the \"_id\".\n\nE.g.\n\nblog_id results in blog_id_id\n\nI'm using version 0.8.\n",
"OK...wow, this one was a bummer to fix. I had started with the assumption that field names and columns were interchangeable, but there was a weird special case where foreign key fields would get an \"_id\" tacked onto them. The actual id would be stored on the model instance in the \"_id\" field, and the object at the fields name would be a descriptor that would lookup/cache the related object. There was a lot of disentangling to do to separate out places where we're accessing and querying fields by name versus by column, but i'm pretty confident that i've got this one fixed.\n\nThe default behavior has not changed -- in other words, \"_id\" is still added on -- but if you want you can manually specify the underlying column for any field:\n\n```\n class Blog(Model):\n name = CharField(db_column='mySweetPhpName')\n\n class Entry(Model):\n name = CharField()\n blog = ForeignKeyField(db_column='blog') # <-- actually stores it in \"blog\" in the database\n```\n\nI think i've got good test coverage for this, but if you run into any bugs with it let meknow!\n",
"Works great. Thanks a lot!\n",
"Might it be possible to adapt 'pwiz.py' to add the ',db_column=' argument for every foreign key column?\n",
"@dstruck -- Any reason this is preferable?\n",
"Expected that pwiz would use the column names from the existing tables to generate the models. As I tend to use \"id_user\", \"id_center\" instead of \"user_id\" or \"center_id\", this clashed with the default behaviour of peewee to append \"_id\" to foreign key columns.\n\nThis is an example to show the \"issue\":\n\n``` python\n'''\n-- create two test tables in postgresql\n\nCREATE TABLE list_user(\nid SERIAL PRIMARY KEY\n,name TEXT\n);\n\nINSERT INTO list_user (name) VALUES ('test');\n\nCREATE TABLE sample(\nid SERIAL PRIMARY KEY\n,id_user INT REFERENCES list_user\n,data TEXT\n);\n'''\n\n################################################################################\n# classes generated by pwiz.py\n# pwiz.py -e postgresql test > model.txt\nfrom peewee import *\n\ndatabase = PostgresqlDatabase('test', **{})\n\nclass UnknownFieldType(object):\n pass\n\nclass BaseModel(Model):\n class Meta:\n database = database\n\nclass List_User(BaseModel):\n name = TextField(null=True)\n\n class Meta:\n db_table = 'list_user'\n\nclass Sample(BaseModel):\n data = TextField(null=True)\n id_user = ForeignKeyField(null=True, rel_model=List_User)\n\n class Meta:\n db_table = 'sample'\n################################################################################\n\n# test\nentry = Sample(id_user=1,data=\"test123\")\nentry.save()\n\n'''\nerror message produced by this test:\n\npsycopg2.ProgrammingError: column \"id_user_id\" of relation \"sample\" does not exist\nLINE 1: INSERT INTO \"sample\" (\"data\", \"id_user_id\") VALUES ('test123...\n'''\n```\n",
"I will try and write some tests for this code as it is sometimes a bit buggy and difficult to verify.\n",
"Thanks for the fix. Will test it on our databases and report back if I find any other issue.\n\nps: never was a fan of orm's, always worked directly with databases, but peewee might change my opinion ;-)\n",
"would be nice to add `db_column` in api docs\n",
"It is: http://docs.peewee-orm.com/en/latest/peewee/api.html#fields\n\nAnd: http://docs.peewee-orm.com/en/latest/peewee/models.html#field-initialization-arguments\n"
] | 2012-01-11T16:17:13 | 2016-11-14T00:50:03 | 2012-01-29T16:58:25 | NONE | null | There seems to be no way to declare a foreign_key which does not end with "_id", since the expected column name is attribute_name + '_id'. Or did I miss way to declare such a key?
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/44/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/44/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/43 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/43/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/43/comments | https://api.github.com/repos/coleifer/peewee/issues/43/events | https://github.com/coleifer/peewee/pull/43 | 2,760,630 | MDExOlB1bGxSZXF1ZXN0NjY0MzQw | 43 | Proposed fix for sqlite syntax error when model field is named group | {
"login": "aflower",
"id": 1042834,
"node_id": "MDQ6VXNlcjEwNDI4MzQ=",
"avatar_url": "https://avatars.githubusercontent.com/u/1042834?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/aflower",
"html_url": "https://github.com/aflower",
"followers_url": "https://api.github.com/users/aflower/followers",
"following_url": "https://api.github.com/users/aflower/following{/other_user}",
"gists_url": "https://api.github.com/users/aflower/gists{/gist_id}",
"starred_url": "https://api.github.com/users/aflower/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/aflower/subscriptions",
"organizations_url": "https://api.github.com/users/aflower/orgs",
"repos_url": "https://api.github.com/users/aflower/repos",
"events_url": "https://api.github.com/users/aflower/events{/privacy}",
"received_events_url": "https://api.github.com/users/aflower/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Tracking on #42, closing\n"
] | 2012-01-08T12:11:25 | 2014-06-12T08:14:46 | 2012-01-08T16:33:05 | NONE | null | Just thought Id send this pull request so you dont have to edit it yourself or look up the line/method I was referencing in the issue for the operationalError/syntax error.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/43/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/43/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/43",
"html_url": "https://github.com/coleifer/peewee/pull/43",
"diff_url": "https://github.com/coleifer/peewee/pull/43.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/43.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/42 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/42/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/42/comments | https://api.github.com/repos/coleifer/peewee/issues/42/events | https://github.com/coleifer/peewee/issues/42 | 2,760,605 | MDU6SXNzdWUyNzYwNjA1 | 42 | sqlite syntax error when a field is named group | {
"login": "aflower",
"id": 1042834,
"node_id": "MDQ6VXNlcjEwNDI4MzQ=",
"avatar_url": "https://avatars.githubusercontent.com/u/1042834?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/aflower",
"html_url": "https://github.com/aflower",
"followers_url": "https://api.github.com/users/aflower/followers",
"following_url": "https://api.github.com/users/aflower/following{/other_user}",
"gists_url": "https://api.github.com/users/aflower/gists{/gist_id}",
"starred_url": "https://api.github.com/users/aflower/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/aflower/subscriptions",
"organizations_url": "https://api.github.com/users/aflower/orgs",
"repos_url": "https://api.github.com/users/aflower/repos",
"events_url": "https://api.github.com/users/aflower/events{/privacy}",
"received_events_url": "https://api.github.com/users/aflower/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Thanks for reporting, looking -- the quote thing may not work as I think mysql likes backticks, but this is definitelysomething that needs to be addressed.\n",
"Nice fix!\n",
"peewee now quotes columns and table names as well...closing\n360e55f28a606dfeabc68a5c7dcabb9e109ec0bd\n6b2a8278d9a068b71ae110f37626d053bdbcec1d\n"
] | 2012-01-08T12:03:10 | 2012-01-08T20:03:10 | 2012-01-08T18:33:03 | NONE | null | The orm generates this sql string
CREATE TABLE thethable (stat INTEGER NOT NULL, group VARCHAR(255) NOT NULL)
for a model that has stat an integerField and group a CharField.
sqlite3 then gives an operationalError: near "group" syntax error
probably since group is a keyword, but if we put quote marks around group, the statement passes.
a possible fix is to change the line 1803 (Field class, to_sql method) in peewee.py from return '%s %s' % (self.name, rendered) to
return '"%s" %s' % (self.name, rendered)
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/42/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/42/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/41 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/41/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/41/comments | https://api.github.com/repos/coleifer/peewee/issues/41/events | https://github.com/coleifer/peewee/issues/41 | 2,757,520 | MDU6SXNzdWUyNzU3NTIw | 41 | Help with alter table queries | {
"login": "coleifer",
"id": 119974,
"node_id": "MDQ6VXNlcjExOTk3NA==",
"avatar_url": "https://avatars.githubusercontent.com/u/119974?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/coleifer",
"html_url": "https://github.com/coleifer",
"followers_url": "https://api.github.com/users/coleifer/followers",
"following_url": "https://api.github.com/users/coleifer/following{/other_user}",
"gists_url": "https://api.github.com/users/coleifer/gists{/gist_id}",
"starred_url": "https://api.github.com/users/coleifer/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/coleifer/subscriptions",
"organizations_url": "https://api.github.com/users/coleifer/orgs",
"repos_url": "https://api.github.com/users/coleifer/repos",
"events_url": "https://api.github.com/users/coleifer/events{/privacy}",
"received_events_url": "https://api.github.com/users/coleifer/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Decided that the range of possible alter table queries really precludes a general purpose solution that wouldn't involve a whole lot of code. Going to leave this up to the end-user to handle if it goes beyond the most basic case (add/drop/rename col).\n"
] | 2012-01-07T19:46:19 | 2012-01-08T03:35:27 | 2012-01-08T03:34:11 | OWNER | null | Although there are no automated 'migrations' in peewee, it would be helpful to give users a way to get column sql and generate alter table queries (or with sqlite, since there's no drop column, maybe the temptable thing).
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/41/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/41/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/40 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/40/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/40/comments | https://api.github.com/repos/coleifer/peewee/issues/40/events | https://github.com/coleifer/peewee/issues/40 | 2,731,310 | MDU6SXNzdWUyNzMxMzEw | 40 | is it possible to get select query columns behavior similar to only or exclude in model converter? | {
"login": "davidthewatson",
"id": 150892,
"node_id": "MDQ6VXNlcjE1MDg5Mg==",
"avatar_url": "https://avatars.githubusercontent.com/u/150892?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/davidthewatson",
"html_url": "https://github.com/davidthewatson",
"followers_url": "https://api.github.com/users/davidthewatson/followers",
"following_url": "https://api.github.com/users/davidthewatson/following{/other_user}",
"gists_url": "https://api.github.com/users/davidthewatson/gists{/gist_id}",
"starred_url": "https://api.github.com/users/davidthewatson/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/davidthewatson/subscriptions",
"organizations_url": "https://api.github.com/users/davidthewatson/orgs",
"repos_url": "https://api.github.com/users/davidthewatson/repos",
"events_url": "https://api.github.com/users/davidthewatson/events{/privacy}",
"received_events_url": "https://api.github.com/users/davidthewatson/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"If you know which columns you are selecting in the first place, then\nyou know which columns you're iterating already! Can you just pass\nthat list into your template alongside any query? If you're looking\nfor where in the datastructures this information resides, you want to\nlook at QueryResultWrapper.query_meta and\nQueryResultWrapper.column_meta. You get a QueryResultWrapper by\ncalling SelectQuery.execute() which happens implicitly when iterating\na select query.\n\nCharlie\n\nOn Wed, Jan 4, 2012 at 9:12 PM, David Watson\[email protected]\nwrote:\n\n> I have a model where I do something simple:\n> \n> class Whatever(db.Model):\n> field1 = CharField()\n> field2 = CharField()\n> field3 = CharField()\n> \n> but in my view I'd like the query to behave like a SQL select. That is, I only get the columns back that I asked for in the select:\n> \n> whatevers = Whatever.select(Whatever: ['id', \"field2\"]}) # at this point id and field2 are populated\n> columns=whatever.model._meta.get_field_names() # this gets me all the fields, not the fields matching the previous select\n> \n> What I'm wondering is if there's a way to get the columns to match whatever's requested in the query. Obviously, I could do a list comprehension or the like to reduce the column list to the result set, but I'm looking for a more architectural solution - one that's supported within the model. It seemed like there would be something like your ModelConverter's only or exclude parameters, but I couldn't find an example where the select and the column list were matched in this way.\n> \n> The use case here is simple: I want to be able to generate tables of data in my templates like:\n> \n> <table>\n> <thead>\n> <tr>\n> {% for column in columns %}\n> <td>{{ column }}</td>\n> {% endfor %}\n> </tr>\n> </thead>\n> <tbody>\n> {% for whatever in whatevers %}\n> <tr>\n> {% for column in columns %}<td>{% if loop.index == 1: %}<a href=\"{{ url_for('detail', id=0) }}\">{{ whatever[column] }}</a>{% else %}{{ whatever[column] }}{% endif %}</td>{% endfor %}\n> </tr>\n> {% endfor %}\n> </tbody>\n> </table>\n> \n> \n> Thanks!\n> \n> ---\n> \n> Reply to this email directly or view it on GitHub:\n> https://github.com/coleifer/peewee/issues/40\n"
] | 2012-01-05T03:12:30 | 2012-01-05T05:49:40 | 2012-01-05T05:49:40 | NONE | null | I have a model where I do something simple:
```
class Whatever(db.Model):
field1 = CharField()
field2 = CharField()
field3 = CharField()
```
but in my view I'd like the query to behave like a SQL select. That is, I only get the columns back that I asked for in the select:
```
whatevers = Whatever.select(Whatever: ['id', "field2"]}) # at this point id and field2 are populated
columns=whatever.model._meta.get_field_names() # this gets me all the fields, not the fields matching the previous select
```
What I'm wondering is if there's a way to get the columns to match whatever's requested in the query. Obviously, I could do a list comprehension or the like to reduce the column list to the result set, but I'm looking for a more architectural solution - one that's supported within the model. It seemed like there would be something like your ModelConverter's only or exclude parameters, but I couldn't find an example where the select and the column list were matched in this way.
The use case here is simple: I want to be able to generate tables of data in my templates like:
```
<table>
<thead>
<tr>
{% for column in columns %}
<td>{{ column }}</td>
{% endfor %}
</tr>
</thead>
<tbody>
{% for whatever in whatevers %}
<tr>
{% for column in columns %}<td>{% if loop.index == 1: %}<a href="{{ url_for('detail', id=0) }}">{{ whatever[column] }}</a>{% else %}{{ whatever[column] }}{% endif %}</td>{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
```
Thanks!
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/40/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/40/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/39 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/39/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/39/comments | https://api.github.com/repos/coleifer/peewee/issues/39/events | https://github.com/coleifer/peewee/pull/39 | 2,699,276 | MDExOlB1bGxSZXF1ZXN0NjQzMzE1 | 39 | Added __isnull column lookup for Django-style NULL and NOT NULL value checking | {
"login": "drewyeaton",
"id": 72983,
"node_id": "MDQ6VXNlcjcyOTgz",
"avatar_url": "https://avatars.githubusercontent.com/u/72983?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/drewyeaton",
"html_url": "https://github.com/drewyeaton",
"followers_url": "https://api.github.com/users/drewyeaton/followers",
"following_url": "https://api.github.com/users/drewyeaton/following{/other_user}",
"gists_url": "https://api.github.com/users/drewyeaton/gists{/gist_id}",
"starred_url": "https://api.github.com/users/drewyeaton/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/drewyeaton/subscriptions",
"organizations_url": "https://api.github.com/users/drewyeaton/orgs",
"repos_url": "https://api.github.com/users/drewyeaton/repos",
"events_url": "https://api.github.com/users/drewyeaton/events{/privacy}",
"received_events_url": "https://api.github.com/users/drewyeaton/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Thanks mane! Looks great\n",
"No problem!\n"
] | 2012-01-02T04:41:41 | 2014-07-06T01:52:21 | 2012-01-02T21:25:20 | CONTRIBUTOR | null | I realize this can be accomplished with a Q object, but it's arguably harder to read queries using them. This also is available in the standard Django API, so it may not hurt to have more feature parity on this level.
Also, added some tests for "__isnull" and for use in conjunction with Q object (no idea why one would ever do this though).
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/39/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/39/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/39",
"html_url": "https://github.com/coleifer/peewee/pull/39",
"diff_url": "https://github.com/coleifer/peewee/pull/39.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/39.patch",
"merged_at": "2012-01-02T21:25:20"
} |
https://api.github.com/repos/coleifer/peewee/issues/38 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/38/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/38/comments | https://api.github.com/repos/coleifer/peewee/issues/38/events | https://github.com/coleifer/peewee/pull/38 | 2,694,546 | MDExOlB1bGxSZXF1ZXN0NjQyMDgy | 38 | Just a better error message | {
"login": "karlb",
"id": 144773,
"node_id": "MDQ6VXNlcjE0NDc3Mw==",
"avatar_url": "https://avatars.githubusercontent.com/u/144773?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/karlb",
"html_url": "https://github.com/karlb",
"followers_url": "https://api.github.com/users/karlb/followers",
"following_url": "https://api.github.com/users/karlb/following{/other_user}",
"gists_url": "https://api.github.com/users/karlb/gists{/gist_id}",
"starred_url": "https://api.github.com/users/karlb/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/karlb/subscriptions",
"organizations_url": "https://api.github.com/users/karlb/orgs",
"repos_url": "https://api.github.com/users/karlb/repos",
"events_url": "https://api.github.com/users/karlb/events{/privacy}",
"received_events_url": "https://api.github.com/users/karlb/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2011-12-31T13:41:26 | 2014-07-06T01:52:22 | 2011-12-31T15:11:47 | NONE | null | SelectQuery.get was missing the where-clause in the error message.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/38/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/38/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/38",
"html_url": "https://github.com/coleifer/peewee/pull/38",
"diff_url": "https://github.com/coleifer/peewee/pull/38.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/38.patch",
"merged_at": "2011-12-31T15:11:47"
} |
https://api.github.com/repos/coleifer/peewee/issues/37 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/37/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/37/comments | https://api.github.com/repos/coleifer/peewee/issues/37/events | https://github.com/coleifer/peewee/pull/37 | 2,693,586 | MDExOlB1bGxSZXF1ZXN0NjQxODE0 | 37 | Added __isnull column lookup for Django-style NULL and NOT NULL value | {
"login": "drewyeaton",
"id": 72983,
"node_id": "MDQ6VXNlcjcyOTgz",
"avatar_url": "https://avatars.githubusercontent.com/u/72983?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/drewyeaton",
"html_url": "https://github.com/drewyeaton",
"followers_url": "https://api.github.com/users/drewyeaton/followers",
"following_url": "https://api.github.com/users/drewyeaton/following{/other_user}",
"gists_url": "https://api.github.com/users/drewyeaton/gists{/gist_id}",
"starred_url": "https://api.github.com/users/drewyeaton/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/drewyeaton/subscriptions",
"organizations_url": "https://api.github.com/users/drewyeaton/orgs",
"repos_url": "https://api.github.com/users/drewyeaton/repos",
"events_url": "https://api.github.com/users/drewyeaton/events{/privacy}",
"received_events_url": "https://api.github.com/users/drewyeaton/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Add some tests and I'll be happy to merge.\n"
] | 2011-12-31T05:08:38 | 2014-07-06T01:52:24 | 2012-01-02T04:39:13 | CONTRIBUTOR | null | I realize this can be accomplished with a Q object, but it's arguably harder to read queries using them. This also is available in the standard Django API, so it may not hurt to have more feature parity on this level.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/37/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/37/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/37",
"html_url": "https://github.com/coleifer/peewee/pull/37",
"diff_url": "https://github.com/coleifer/peewee/pull/37.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/37.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/36 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/36/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/36/comments | https://api.github.com/repos/coleifer/peewee/issues/36/events | https://github.com/coleifer/peewee/issues/36 | 2,692,412 | MDU6SXNzdWUyNjkyNDEy | 36 | group_by() broken for queries without aliases | {
"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 | [] | 2011-12-30T23:03:54 | 2011-12-31T15:31:30 | 2011-12-31T15:31:30 | NONE | null | This code:
``` python
from peewee import *
class Message(Model):
author = CharField()
body = TextField()
print Message.select().group_by('author').sql()
```
Throws this exception:
```
Traceback (most recent call last):
File "test.py", line 7, in <module>
print Message.select().group_by('author').sql()
File "peewee.py", line 1216, in sql
group_by = ', '.join(group_by)
TypeError: sequence item 0: expected string, tuple found
```
This part of SelectQuery.sql() seems responsible:
``` python
if self.use_aliases():
(...)
else:
group_by = [c[1] for c in self._group_by]
```
c[1] is a sequence of field names, not a single field name, so str.join() fails. The code used when use_aliases() returns True seems to work better.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/36/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/36/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/35 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/35/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/35/comments | https://api.github.com/repos/coleifer/peewee/issues/35/events | https://github.com/coleifer/peewee/issues/35 | 2,687,878 | MDU6SXNzdWUyNjg3ODc4 | 35 | Auto save() dirty objects on commit | {
"login": "coderbuzz",
"id": 1284811,
"node_id": "MDQ6VXNlcjEyODQ4MTE=",
"avatar_url": "https://avatars.githubusercontent.com/u/1284811?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/coderbuzz",
"html_url": "https://github.com/coderbuzz",
"followers_url": "https://api.github.com/users/coderbuzz/followers",
"following_url": "https://api.github.com/users/coderbuzz/following{/other_user}",
"gists_url": "https://api.github.com/users/coderbuzz/gists{/gist_id}",
"starred_url": "https://api.github.com/users/coderbuzz/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/coderbuzz/subscriptions",
"organizations_url": "https://api.github.com/users/coderbuzz/orgs",
"repos_url": "https://api.github.com/users/coderbuzz/repos",
"events_url": "https://api.github.com/users/coderbuzz/events{/privacy}",
"received_events_url": "https://api.github.com/users/coderbuzz/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"If you take a look at the testcases it shows how things are saved:\n\nhttps://github.com/coleifer/peewee/blob/master/tests.py#L2702\n\nBasic workflow should be:\n- turn off autocommit\n- modify a bunch of models or whatever\n- call `.save()` on the models you want to save\n- call `.commit()` on the database and all the saves (update/insert) will be committed\n\nThe test is showing:\n1. turn off autocommit\n2. save two blogs\n3. open up a new connection to the same database (`new_db`)\n4. using that new connection query to see if there are any blogs\n5. assert that there are none\n6. call commit on our original connection (`test_db`)\n7. use the other connection to query again for blogs\n8. assert that they are present\n\nThere is no \"automatic\" saving of dirty models.\n"
] | 2011-12-30T10:49:18 | 2011-12-30T16:12:14 | 2011-12-30T16:12:14 | NONE | null | Hi, to speed-up my query tasks, by default I have turned-off autocommit to False in db configuration,
means we need to call db.commit() to commit the transaction
Found now behavior doesn't flush (save) dirty objects on commit.
Again, in sql-alchemy we don't need explicit call object.save() as we know there's dirty objects that need to be save() automatically on commit.
``` python
try:
othermodel.create(blablafield = 'blabla value')
mymodel = MyModel.select().first() # hehe new stuff :D
mymodel.somefield = 'edit the field value' # dirty object
# mymodel.save() # maybe explicitly required only on autocommit scheme
db.commit()
except :
db.rollback()
```
I'm playing with more than 4 models in one task, which changing the field value anywhere,
it's a bit difficult to catch which object should call save() on the end of procedure block since changes could be applied on several place of code block logic
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/35/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/35/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/34 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/34/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/34/comments | https://api.github.com/repos/coleifer/peewee/issues/34/events | https://github.com/coleifer/peewee/issues/34 | 2,671,638 | MDU6SXNzdWUyNjcxNjM4 | 34 | Column default value wont (keep) update | {
"login": "coderbuzz",
"id": 1284811,
"node_id": "MDQ6VXNlcjEyODQ4MTE=",
"avatar_url": "https://avatars.githubusercontent.com/u/1284811?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/coderbuzz",
"html_url": "https://github.com/coderbuzz",
"followers_url": "https://api.github.com/users/coderbuzz/followers",
"following_url": "https://api.github.com/users/coderbuzz/following{/other_user}",
"gists_url": "https://api.github.com/users/coderbuzz/gists{/gist_id}",
"starred_url": "https://api.github.com/users/coderbuzz/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/coderbuzz/subscriptions",
"organizations_url": "https://api.github.com/users/coderbuzz/orgs",
"repos_url": "https://api.github.com/users/coderbuzz/repos",
"events_url": "https://api.github.com/users/coderbuzz/events{/privacy}",
"received_events_url": "https://api.github.com/users/coderbuzz/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Dooh my mistake, should be:\n\n``` python\ntime = DateTimeField(default=datetime.now)\n```\n\nIn previous I pass the now() value, not passing function as arg.\n\nSorry to pollute\n"
] | 2011-12-28T14:42:47 | 2011-12-28T15:24:37 | 2011-12-28T15:24:37 | NONE | null | Hi, I have the following model which have a datetime field with default value=datetime.now()
``` python
from datetime import datetime
class ATable(BaseModel):
time = DateTimeField(default=datetime.now())
customer = CharField()
```
Surprised when I create several records say:
``` python
ATable.create(customer='A')
# some delay
ATable.create(customer='B')
# some delay
ATable.create(customer='C')
```
The time (default) filled values was all the same: 2011-12-28 21:30:38.257 on all records
The time beeween record creation surelly in different time, at least microsecond and or second value
Perhaps a caching issue?
Thanks
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/34/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/34/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/33 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/33/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/33/comments | https://api.github.com/repos/coleifer/peewee/issues/33/events | https://github.com/coleifer/peewee/issues/33 | 2,655,647 | MDU6SXNzdWUyNjU1NjQ3 | 33 | Field allow null by default | {
"login": "coderbuzz",
"id": 1284811,
"node_id": "MDQ6VXNlcjEyODQ4MTE=",
"avatar_url": "https://avatars.githubusercontent.com/u/1284811?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/coderbuzz",
"html_url": "https://github.com/coderbuzz",
"followers_url": "https://api.github.com/users/coderbuzz/followers",
"following_url": "https://api.github.com/users/coderbuzz/following{/other_user}",
"gists_url": "https://api.github.com/users/coderbuzz/gists{/gist_id}",
"starred_url": "https://api.github.com/users/coderbuzz/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/coderbuzz/subscriptions",
"organizations_url": "https://api.github.com/users/coderbuzz/orgs",
"repos_url": "https://api.github.com/users/coderbuzz/repos",
"events_url": "https://api.github.com/users/coderbuzz/events{/privacy}",
"received_events_url": "https://api.github.com/users/coderbuzz/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Thanks for the suggestion -- I am going to stick with the current behavior, though.\n"
] | 2011-12-25T18:42:12 | 2011-12-26T01:36:24 | 2011-12-26T01:36:21 | NONE | null | Hi, when initializing (create) record; sometimes; mostly we have to leave other non indexed fields with default value or null for future fill.
May I suggest you to allow null by default, it's rare of important field to be not null
``` python
class Field(object):
def __init__(self, null=True, db_index=False, unique=False, verbose_name=None,
help_text=None, *args, **kwargs):
```
null=**True**
Thanks
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/33/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/33/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/32 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/32/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/32/comments | https://api.github.com/repos/coleifer/peewee/issues/32/events | https://github.com/coleifer/peewee/issues/32 | 2,655,275 | MDU6SXNzdWUyNjU1Mjc1 | 32 | QueryResultWrapper.first() | {
"login": "coderbuzz",
"id": 1284811,
"node_id": "MDQ6VXNlcjEyODQ4MTE=",
"avatar_url": "https://avatars.githubusercontent.com/u/1284811?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/coderbuzz",
"html_url": "https://github.com/coderbuzz",
"followers_url": "https://api.github.com/users/coderbuzz/followers",
"following_url": "https://api.github.com/users/coderbuzz/following{/other_user}",
"gists_url": "https://api.github.com/users/coderbuzz/gists{/gist_id}",
"starred_url": "https://api.github.com/users/coderbuzz/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/coderbuzz/subscriptions",
"organizations_url": "https://api.github.com/users/coderbuzz/orgs",
"repos_url": "https://api.github.com/users/coderbuzz/repos",
"events_url": "https://api.github.com/users/coderbuzz/events{/privacy}",
"received_events_url": "https://api.github.com/users/coderbuzz/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Good points...I will work on adding this -- the problem w/the implementation you suggest is that a subsequent iteration will start on the 2nd result.\n",
"Thank you! :)\n"
] | 2011-12-25T15:13:08 | 2011-12-30T08:27:48 | 2011-12-28T22:30:54 | NONE | null | get() is not suitable in some cases, for example if we need get first row from complex select-where query, using join, sub-query etc (without exception)
Can you please add a first() or using get() name too method to QueryResultWrapper class?
The method should return None on empty resultset, otherwise return first row
Please check of mind:
``` python
class QueryResultWrapper(object):
# ...
#def get(self): or which suitable
def first(self):
if self._result_cache:
return self._result_cache[0]
else:
row = self.cursor.fetchone()
if row:
row_dict = self._row_to_dict(row, self.cursor)
instance = self.model_from_rowset(self.model, row_dict)
self._result_cache.append(instance)
return instance
else:
self._populated = True
return None
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/32/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/32/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/31 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/31/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/31/comments | https://api.github.com/repos/coleifer/peewee/issues/31/events | https://github.com/coleifer/peewee/issues/31 | 2,655,257 | MDU6SXNzdWUyNjU1MjU3 | 31 | BETWEEN column lookup type | {
"login": "coderbuzz",
"id": 1284811,
"node_id": "MDQ6VXNlcjEyODQ4MTE=",
"avatar_url": "https://avatars.githubusercontent.com/u/1284811?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/coderbuzz",
"html_url": "https://github.com/coderbuzz",
"followers_url": "https://api.github.com/users/coderbuzz/followers",
"following_url": "https://api.github.com/users/coderbuzz/following{/other_user}",
"gists_url": "https://api.github.com/users/coderbuzz/gists{/gist_id}",
"starred_url": "https://api.github.com/users/coderbuzz/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/coderbuzz/subscriptions",
"organizations_url": "https://api.github.com/users/coderbuzz/orgs",
"repos_url": "https://api.github.com/users/coderbuzz/repos",
"events_url": "https://api.github.com/users/coderbuzz/events{/privacy}",
"received_events_url": "https://api.github.com/users/coderbuzz/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2011-12-25T15:01:09 | 2011-12-26T01:49:41 | 2011-12-26T01:49:41 | NONE | null | Hi can you please add BETWEEN lookup type?
Thanks
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/31/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/31/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/30 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/30/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/30/comments | https://api.github.com/repos/coleifer/peewee/issues/30/events | https://github.com/coleifer/peewee/issues/30 | 2,607,864 | MDU6SXNzdWUyNjA3ODY0 | 30 | reserved word user table on postgresql? | {
"login": "davidthewatson",
"id": 150892,
"node_id": "MDQ6VXNlcjE1MDg5Mg==",
"avatar_url": "https://avatars.githubusercontent.com/u/150892?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/davidthewatson",
"html_url": "https://github.com/davidthewatson",
"followers_url": "https://api.github.com/users/davidthewatson/followers",
"following_url": "https://api.github.com/users/davidthewatson/following{/other_user}",
"gists_url": "https://api.github.com/users/davidthewatson/gists{/gist_id}",
"starred_url": "https://api.github.com/users/davidthewatson/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/davidthewatson/subscriptions",
"organizations_url": "https://api.github.com/users/davidthewatson/orgs",
"repos_url": "https://api.github.com/users/davidthewatson/repos",
"events_url": "https://api.github.com/users/davidthewatson/events{/privacy}",
"received_events_url": "https://api.github.com/users/davidthewatson/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I'd suggest trying the following:\n\n```\nclass User(db.Model, BaseUser):\n # whatever fields\n\n class Meta:\n db_table = 'users' # <-- set explicitly right here\n```\n",
"Thanks for your response.\n\nThat gets it past the creation stage, but then it dies further down in peewee. It's not clear to me that my application code is implicated here, i.e. it doesn't appear in the stack anywhere.\n\n```\nTraceback (most recent call last):\n File \"/home/watson/mine/env/lib/python2.7/site-packages/flask/app.py\", line 1518, in __call__\n return self.wsgi_app(environ, start_response)\n File \"/home/watson/mine/env/lib/python2.7/site-packages/flask/app.py\", line 1506, in wsgi_app\n response = self.make_response(self.handle_exception(e))\n File \"/home/watson/mine/env/lib/python2.7/site-packages/flask/app.py\", line 1504, in wsgi_app\n response = self.full_dispatch_request()\n File \"/home/watson/mine/env/lib/python2.7/site-packages/flask/app.py\", line 1264, in full_dispatch_request\n rv = self.handle_user_exception(e)\n File \"/home/watson/mine/env/lib/python2.7/site-packages/flask/app.py\", line 1260, in full_dispatch_request\n rv = self.preprocess_request()\n File \"/home/watson/mine/env/lib/python2.7/site-packages/flask/app.py\", line 1387, in preprocess_request\n rv = func()\n File \"/home/watson/mine/env/lib/python2.7/site-packages/flask_peewee/auth.py\", line 187, in load_user\n g.user = self.get_logged_in_user()\n File \"/home/watson/mine/env/lib/python2.7/site-packages/flask_peewee/auth.py\", line 144, in get_logged_in_user\n return self.User.select().where(active=True).get(id=session.get('user_pk'))\n File \"/home/watson/mine/env/lib/python2.7/site-packages/peewee.py\", line 978, in get\n obj = self.where(*args, **kwargs).paginate(1, 1).execute().next()\n File \"/home/watson/mine/env/lib/python2.7/site-packages/peewee.py\", line 1082, in execute\n self._qr = QueryResultWrapper(self.model, self.raw_execute())\n File \"/home/watson/mine/env/lib/python2.7/site-packages/peewee.py\", line 825, in raw_execute\n return self.database.execute(query, params, self.requires_commit)\n File \"/home/watson/mine/env/lib/python2.7/site-packages/peewee.py\", line 252, in execute\n res = cursor.execute(sql, params or ())\nProgrammingError: column \"active\" does not exist\nLINE 1: SELECT * FROM user WHERE active = 1 AND id = 1 LIMIT 1\n```\n\nMy user class now looks like:\n\n```\nclass User(db.Model, BaseUser):\n username = CharField(unique=True)\n password = CharField()\n email = CharField()\n join_date = DateTimeField(default=datetime.datetime.now)\n active = BooleanField(default=True)\n admin = BooleanField(default=False)\n\n def __unicode__(self):\n return self.username\n\n class Meta:\n db_table = 'users' # Postgres reserves user as a keyword\n```\n\nAnd the database in postgres:\n\n```\n=# select * from users;\n username | admin | id | join_date | active | password | email \n----------+-------+----+----------------------------+--------+------------------------------------------------+-------\n admin | 1 | 1 | 2011-12-20 10:55:07.186137 | 1 | 1b7e1$9112656704dad1f93fdb40727e5d5ea33bf46616 | \n(1 row)\n```\n",
"I'm going to open a new issue on flask_peewee since it doesn't honor the settings in the model - the meta users database table change on model breaks mysql also.\n"
] | 2011-12-20T00:17:02 | 2011-12-20T19:29:08 | 2011-12-20T01:40:57 | NONE | null | I have the following which I copied from some sample code:
```
from flask_peewee.auth import BaseUser
import datetime
from peewee import *
from app import db
class User(db.Model, BaseUser):
username = CharField(unique=True)
password = CharField()
email = CharField()
join_date = DateTimeField(default=datetime.datetime.now)
active = BooleanField(default=True)
admin = BooleanField(default=False)
def __unicode__(self):
return self.username
```
and the following config.py:
```
# Configuration for PostgreSQL
DATABASE = {
'name': 'whatever',
'engine': 'peewee.PostgresqlDatabase',
'user': 'me',
'password': 'mine'
}
```
but when I run this against Postgresql on Fedora Core 15, I get:
```
Traceback (most recent call last):
File "run_mine.py", line 7, in <module>
main.create_tables()
File "/home/watson/mine/main.py", line 15, in create_tables
User.create_table(fail_silently=True)
File "/home/watson/mine/env/lib/python2.7/site-packages/peewee.py", line 1770, in create_table
cls._meta.database.create_table(cls)
File "/home/watson/mine/env/lib/python2.7/site-packages/peewee.py", line 287, in create_table
self.execute(query, commit=True)
File "/home/watson/mine/env/lib/python2.7/site-packages/peewee.py", line 252, in execute
res = cursor.execute(sql, params or ())
psycopg2.ProgrammingError: syntax error at or near "user"
LINE 1: CREATE TABLE user (username VARCHAR(255) NOT NULL, admin SMA...
```
It turns out that postgresql defines a user table by default and apparently its a reserved word. It was already there with my postgresql user already created in it before I even ran my flask app.
```
mine=> select * from user;
current_user
--------------
me
(1 row)
```
I'd recommend discouraging the use of "user" in any documentation relating to postgresql tables in peewee and also perhaps catching it and throwing a warning or error before it gets to the database driver. I tried making a simple change to my code to use users in place of user, but it was still blowing up in postgresql, though I'm not sure why. I'm open to advice here if you have any - I'm still intending to use peewee but Postgresql is a requirement.
Thanks!
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/30/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/30/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/29 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/29/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/29/comments | https://api.github.com/repos/coleifer/peewee/issues/29/events | https://github.com/coleifer/peewee/issues/29 | 2,600,213 | MDU6SXNzdWUyNjAwMjEz | 29 | Feature, blob field. | {
"login": "jander",
"id": 237061,
"node_id": "MDQ6VXNlcjIzNzA2MQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/237061?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/jander",
"html_url": "https://github.com/jander",
"followers_url": "https://api.github.com/users/jander/followers",
"following_url": "https://api.github.com/users/jander/following{/other_user}",
"gists_url": "https://api.github.com/users/jander/gists{/gist_id}",
"starred_url": "https://api.github.com/users/jander/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/jander/subscriptions",
"organizations_url": "https://api.github.com/users/jander/orgs",
"repos_url": "https://api.github.com/users/jander/repos",
"events_url": "https://api.github.com/users/jander/events{/privacy}",
"received_events_url": "https://api.github.com/users/jander/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I haven't done a _ton_ of research on this issue, but it should be possible to add a custom field class with the proper column type. I've added 'blob' as a column type so you can specify `db_field = 'blob'` and it will create the right column. Looks like with sqlite3 and psycopg2 at least you'll need to wrap the incoming data using `sqlite.Binary` or `psycopg2.Binary` http://stackoverflow.com/questions/3379166/writing-blob-from-sqlite-to-file-using-python and http://initd.org/psycopg/docs/usage.html#adaptation-of-python-values-to-sql-types ... There are also questions as to the proper python type to return. Since peewee gives you the ability to create custom fields, and because of the apparent complexity, I'm going to close this issue and suggest that users who need this functionality roll their own specific to their use-case. Sqlite, for example, returns a python buffer object. Here's an example implementation for sqlite3:\n\n```\nclass BlobField(Field):\n db_field = 'blob'\n\n def db_value(self, v):\n return sqlite3.Binary(v)\n```\n\nAlternatively, you could use a TextField and just convert data from/to base64 when storing in the database.\n",
"this is not working on 2.0.9 version. I receive a:\nKeyError: 'blob'\n\nI added 'blob': 'BLOB', after line 605.\n",
"@trunet, my apologies, I should have posted an update. This is no longer included by default in peewee.\n\nIt shouldn't be difficult to add your own implementation and it might be something I will add down the road:\n\nhttp://peewee.readthedocs.org/en/latest/peewee/models.html#creating-a-custom-field\n",
"@trunet -- I added a blob field in 3cabdf3f7139cf9283d74bd27a2399ec94a84551\n",
"nice, thank you very much.\n"
] | 2011-12-19T13:49:31 | 2014-09-02T07:32:41 | 2011-12-19T19:31:56 | NONE | null | i want to save image in database by peewee.
but peewee has not BlobField yet.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/29/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/29/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/28 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/28/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/28/comments | https://api.github.com/repos/coleifer/peewee/issues/28/events | https://github.com/coleifer/peewee/issues/28 | 2,600,178 | MDU6SXNzdWUyNjAwMTc4 | 28 | UpdateQuery need more? | {
"login": "jander",
"id": 237061,
"node_id": "MDQ6VXNlcjIzNzA2MQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/237061?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/jander",
"html_url": "https://github.com/jander",
"followers_url": "https://api.github.com/users/jander/followers",
"following_url": "https://api.github.com/users/jander/following{/other_user}",
"gists_url": "https://api.github.com/users/jander/gists{/gist_id}",
"starred_url": "https://api.github.com/users/jander/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/jander/subscriptions",
"organizations_url": "https://api.github.com/users/jander/orgs",
"repos_url": "https://api.github.com/users/jander/repos",
"events_url": "https://api.github.com/users/jander/events{/privacy}",
"received_events_url": "https://api.github.com/users/jander/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Yes, totally agree this would be good. Thinking about an implementation.\n"
] | 2011-12-19T13:45:31 | 2011-12-20T21:08:49 | 2011-12-20T21:08:49 | NONE | null | A simple example:
Model class
``` python
class Entity(Model):
num = IntegerField(default=0)
```
peewee seems no way for sql:
```
update Entity set num=num+1 where num>?
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/28/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/28/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/27 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/27/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/27/comments | https://api.github.com/repos/coleifer/peewee/issues/27/events | https://github.com/coleifer/peewee/issues/27 | 2,575,353 | MDU6SXNzdWUyNTc1MzUz | 27 | SelectQuery.count() problem | {
"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 | [
"Hmm... are you using the latest version of peewee? I believe the ordering thing was fixed in ca8945a7 . I'll add your logic to handle 0 correctly: 36d5314c0f1c6b5cd01d5b15420d27f21be099e2\n\nThe try/finally isn't needed since the fix in the first commit referenced does a clone()\n",
"You're right. I was using an older version. Sorry for that.\n\nAnyway, I've noticed that count() returns weird results for queries with joins. In the current implementation of count() such queries will return one count for each joined row. Right now count() will return the first count but what we really want is the number of them.\n\nI spent some time on this and I came up with this:\n\n``` python\n def count(self):\n clone = self.order_by()\n clone._limit = clone._offset = None\n\n sql, params = clone.sql()\n res = clone.database.execute('SELECT COUNT(1) FROM (%s)' % sql, params)\n\n return res.fetchone()[0]\n```\n\nIt's a subquery that contains the original query without ordering and pagination.\n\nEarlier version of this post also changed the \"clone.query\" to \"1\". Later I found out that this breaks count() for \"DISTINCT\" queries. Any change to the \"query\" attribute of distinct queries could alter their row count. I've edited out this part because it was just an optimization anyway.\n\nAlso, it was actually a join query with no results that caused fetchone() to return None. With this subquery this is not possible anymore. The resulting outer query is always simple and always returns one result -- the count -- so there's no need for the \"or [0]\" logic.\n",
"Was able to replicate this and have added a testcase that is currently failing in both sqlite and psycopg2. Working on fixing using your suggestedi mplementation but am dealing w/numerous test failures.\n",
"Fixed in 63bdeba57dd198ba243d42aeb74d93afc0ff6001 -- basically just wrap the query if its distinct. Thanks for your help on this one!!\n",
"Hmm, there's a case where the current code still doesn't work correctly :)\n\nConsider this:\n\n``` python\nfrom peewee import *\n\nclass Blog(Model):\n dummy = IntegerField()\n\nclass Entry(Model):\n blog = ForeignKeyField(Blog)\n\nBlog.create_table()\nEntry.create_table()\n\nblog = Blog()\nblog.save()\n\nfor i in xrange(10):\n Entry(blog=blog).save()\n\nquery = Blog.select().annotate(Entry)\nprint 'count', query.count()\nprint 'wrapped-count', query.wrapped_count()\nprint 'len', len(list(query))\n```\n\nOutput:\n\n```\ncount 10\nwrapped-count 1\nlen 1\n```\n\nThe query issued by count() was:\n\n```\nSELECT COUNT(t1.id) FROM blog AS t1\n INNER JOIN entry AS t2 ON t1.id = t2.blog_id GROUP BY t1.id, t1.dummy\n```\n\nwhich returns the number of entries in each blog, not the number of blogs.\n\nThe solution that works for me is to use wrapped_count() for all queries with \"GROUP BY\":\n\n``` python\n def count(self):\n if self._distinct or self._group_by:\n return self.wrapped_count()\n```\n\nBy the way, I really appreciate your work. I used your whole toolset (peewee, flask_peewee, wtfpeewee) for my project and it works great. High quality and well documented code. Keep it up!\n"
] | 2011-12-16T01:39:51 | 2011-12-22T23:53:09 | 2011-12-19T21:35:29 | NONE | null | I was doing a query using annotate() (with the default Count aggregation) to order by the count of related models.
The query itself worked well but calling query.count() failed with:
```
OperationalError: no such column: count
```
Further investigation revealed that SelectQuery.count() replaces the query with bare COUNT(x) but doesn't remove the ORDER BY clause which in my case created an invalid statement referencing an unknown column alias.
Here's how I fixed it:
``` python
def count(self):
tmp = self.query, self._limit, self._offset, self._order_by
self._limit = self._offset = None
self._order_by = []
try:
if self.use_aliases():
self.query = 'COUNT(t1.%s)' % (self.model._meta.pk_name)
else:
self.query = 'COUNT(%s)' % (self.model._meta.pk_name)
res = self.database.execute(*self.sql())
finally:
# restore
self.query, self._limit, self._offset, self._order_by = tmp
return (res.fetchone() or [0])[0]
```
Two other things that I changed are:
- check whether fetchone() returned None (which is the case if the table is empty) and return 0 in that case
- use try..finally block to make sure the state is restored in case of an error
- replace multiple tmp variables with one
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/27/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/27/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/26 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/26/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/26/comments | https://api.github.com/repos/coleifer/peewee/issues/26/events | https://github.com/coleifer/peewee/issues/26 | 2,560,012 | MDU6SXNzdWUyNTYwMDEy | 26 | Behaviour of __in against foreign keys doesn't behave quite like one might expect | {
"login": "chadcatlett",
"id": 108175,
"node_id": "MDQ6VXNlcjEwODE3NQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/108175?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/chadcatlett",
"html_url": "https://github.com/chadcatlett",
"followers_url": "https://api.github.com/users/chadcatlett/followers",
"following_url": "https://api.github.com/users/chadcatlett/following{/other_user}",
"gists_url": "https://api.github.com/users/chadcatlett/gists{/gist_id}",
"starred_url": "https://api.github.com/users/chadcatlett/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/chadcatlett/subscriptions",
"organizations_url": "https://api.github.com/users/chadcatlett/orgs",
"repos_url": "https://api.github.com/users/chadcatlett/repos",
"events_url": "https://api.github.com/users/chadcatlett/events{/privacy}",
"received_events_url": "https://api.github.com/users/chadcatlett/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I think there are some problems with your examples -- in the first you're doing an __in on a single model instance -- modb.modela is a single model a associated with the given modb. YOu could rewrite as:\n\n```\nmoda = modb.modela\n```\n\nIn the second, you want modela records with that aren't related to some given modb... I _believe_ this should work:\n\n```\nmodas = ModelA.select().join(ModelB).where(~Q(id=modb.id))\n```\n",
"OK -- closing for now, reopen if you get more info.\n"
] | 2011-12-14T22:25:34 | 2011-12-16T19:27:58 | 2011-12-16T19:27:58 | NONE | null | Given the following models:
``` python
class ModelA(model):
blah = CharField()
class ModelB(model):
modela = ForeignKeyField(ModelA)
blah = CharField()
```
Doing a query like this, gives results not quite expected:
``` python
modb = ModelB.get(id=1)
modas = ModelA.select().where(id__in=modb.modela)
```
The second query uses ModelB's primary key, instead of the modela_id column. The above example is sort of useless, as one could just use modb.modela, but when combined with Q():
``` python
modb = ModelB.get(id=1)
modas = ModelA.select().where(~Q(id__in=modb.modela))
```
The above would allow one to fetch all ModelA records that aren't related to ModelB.
Changing this would break the current behavior, but in my opinion it would make it behave more like the code actually reads.
What do you think?
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/26/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/26/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/25 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/25/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/25/comments | https://api.github.com/repos/coleifer/peewee/issues/25/events | https://github.com/coleifer/peewee/issues/25 | 2,555,734 | MDU6SXNzdWUyNTU1NzM0 | 25 | Support for pysqlite | {
"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 | [
"sqlite3 was added in 2.5 and since peewee is 2.5+ compatible, there's really no need. If someone should want to use the alternate driver they can simply subclass the SqliteAdapter/Database and override as needed. Thanks for bringing this up, though!\n"
] | 2011-12-14T18:09:07 | 2011-12-14T18:18:54 | 2011-12-14T18:18:54 | NONE | null | To my knowledge, the sqlite3 module from the stdlib has the same API as the external pysqlite:
http://code.google.com/p/pysqlite
In case the sqlite3 module is absent, peewee could try to use pysqlite instead:
``` python
try:
import sqlite3
except ImportError:
try:
from pysqlite2 import dbapi2 as sqlite3
except ImportError:
sqlite3 = None
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/25/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/25/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/24 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/24/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/24/comments | https://api.github.com/repos/coleifer/peewee/issues/24/events | https://github.com/coleifer/peewee/issues/24 | 2,547,284 | MDU6SXNzdWUyNTQ3Mjg0 | 24 | CASCADE for mysql5.5 not work. | {
"login": "jander",
"id": 237061,
"node_id": "MDQ6VXNlcjIzNzA2MQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/237061?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/jander",
"html_url": "https://github.com/jander",
"followers_url": "https://api.github.com/users/jander/followers",
"following_url": "https://api.github.com/users/jander/following{/other_user}",
"gists_url": "https://api.github.com/users/jander/gists{/gist_id}",
"starred_url": "https://api.github.com/users/jander/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/jander/subscriptions",
"organizations_url": "https://api.github.com/users/jander/orgs",
"repos_url": "https://api.github.com/users/jander/repos",
"events_url": "https://api.github.com/users/jander/events{/privacy}",
"received_events_url": "https://api.github.com/users/jander/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Yeah, you're totally right -- looks like the syntax for creating a foreign key in mysql is a bit different. Django has a handy way of generating SQL so I created a simple model with a foreign key and generated some output for the 3 backends supported by peewee... the MySQL backend has an additional step:\n\nMySQL:\n\n```\nCREATE TABLE `xxx_a` (\n `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,\n `a_field` varchar(255) NOT NULL\n)\n;\nCREATE TABLE `xxx_b` (\n `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,\n `b_field` varchar(255) NOT NULL,\n `a_id` integer NOT NULL\n)\n;\nALTER TABLE `xxx_b` ADD CONSTRAINT `a_id_refs_id_78d26df2` FOREIGN KEY (`a_id`) REFERENCES `xxx_a` (`id`);\nCREATE INDEX `xxx_b_776cf5a8` ON `xxx_b` (`a_id`);\n```\n\nSqlite:\n\n```\nCREATE TABLE \"xxx_a\" (\n \"id\" integer NOT NULL PRIMARY KEY,\n \"a_field\" varchar(255) NOT NULL\n)\n;\nCREATE TABLE \"xxx_b\" (\n \"id\" integer NOT NULL PRIMARY KEY,\n \"b_field\" varchar(255) NOT NULL,\n \"a_id\" integer NOT NULL REFERENCES \"xxx_a\" (\"id\")\n)\n;\nCREATE INDEX \"xxx_b_776cf5a8\" ON \"xxx_b\" (\"a_id\");\n```\n\nPostgresql:\n\n```\nCREATE TABLE \"xxx_a\" (\n \"id\" serial NOT NULL PRIMARY KEY,\n \"a_field\" varchar(255) NOT NULL\n)\n;\nCREATE TABLE \"xxx_b\" (\n \"id\" serial NOT NULL PRIMARY KEY,\n \"b_field\" varchar(255) NOT NULL,\n \"a_id\" integer NOT NULL REFERENCES \"xxx_a\" (\"id\") DEFERRABLE INITIALLY DEFERRED\n)\n;\nCREATE INDEX \"xxx_b_a_id\" ON \"xxx_b\" (\"a_id\");\n```\n",
"it is simple to solve it.\n\n**1. in class Database, add a method: create_foreign_key.**\n\n``` python\nclass Database(object):\n\n def create_foreign_key(self, model_class, to_class, field_name, cascade=False):\n # just call create_index\n self.create_index(model_class, field_name)\n```\n\n**2. in class MyDatabase, add a method: create_foreign_key.**\n\n``` python\nclass MySQLDatabase(Database):\n\n def create_foreign_key(self, model_class, to_class, field_name, cascade=False):\n framing = '''ALTER TABLE %(model)s ADD CONSTRAINT fk_%(model)s_%(to)s_%(field)s\nFOREIGN KEY (%(field)s ) REFERENCES %(to)s(id) %(cascade)s;'''\n\n if field_name not in model_class._meta.fields:\n raise AttributeError(\n 'Field %s not on model %s' % (field_name, model_class)\n )\n\n query = framing % {\n 'model': model_class._meta.db_table,\n 'field': field_name,\n 'to': to_class._meta.db_table,\n 'cascade': ' ON DELETE CASCADE' if cascade else '',\n }\n\n self.execute(query)\n```\n\n**3. in class Model, change the method: create_table.**\n\n``` python\nclass Model(object):\n @classmethod\n def create_table(cls, fail_silently=False):\n if fail_silently and cls.table_exists():\n return\n\n cls._meta.database.create_table(cls)\n\n for field_name, field_obj in cls._meta.fields.items():\n if isinstance(field_obj, PrimaryKeyField):\n cls._meta.database.create_index(cls, field_obj.name, True)\n elif isinstance(field_obj, ForeignKeyField):\n # call create_foreign_key, but not create_index\n cls._meta.database.create_foreign_key(cls, field_obj.to, field_obj.name, field_obj.cascade)\n elif field_obj.db_index or field_obj.unique:\n cls._meta.database.create_index(cls, field_obj.name, field_obj.unique)\n```\n",
"I've adapted your changes here dccb160581d1f60405e9b15e6b892d8f5d149eeb\n\nThe cascade on delete test is now passing w/mysql as well! Thanks for bringing this up and for the implementation!\n"
] | 2011-12-14T03:23:51 | 2011-12-14T18:02:09 | 2011-12-14T18:02:09 | NONE | null | in my model, cascade for mysql not work, peewee generate create table sql:
```
('CREATE TABLE space (id integer AUTO_INCREMENT NOT NULL PRIMARY KEY, name VARCHAR(255));', None)
('CREATE UNIQUE INDEX space_id ON space(id);', None)
('CREATE TABLE page (id integer AUTO_INCREMENT NOT NULL PRIMARY KEY, space_id INTEGER REFERENCES space (id) ON DELETE CASCADE, name VARCHAR(255));', None)
('CREATE INDEX page_space_id ON page(space_id);', None)
('CREATE UNIQUE INDEX page_id ON page(id);', None)
```
it looks like lack mysql **FOREIGN KEY** statements:
```
[CONSTRAINT symbol] FOREIGN KEY [id] (index_col_name, ...)
REFERENCES tbl_name (index_col_name, ...)
[ON DELETE {RESTRICT | CASCADE | SET NULL | NO ACTION}]
[ON UPDATE {RESTRICT | CASCADE | SET NULL | NO ACTION}]
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/24/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/24/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/23 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/23/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/23/comments | https://api.github.com/repos/coleifer/peewee/issues/23/events | https://github.com/coleifer/peewee/pull/23 | 2,543,770 | MDExOlB1bGxSZXF1ZXN0NTkwNDEz | 23 | Small fixes and simplification | {
"login": "lukaszb",
"id": 190381,
"node_id": "MDQ6VXNlcjE5MDM4MQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/190381?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/lukaszb",
"html_url": "https://github.com/lukaszb",
"followers_url": "https://api.github.com/users/lukaszb/followers",
"following_url": "https://api.github.com/users/lukaszb/following{/other_user}",
"gists_url": "https://api.github.com/users/lukaszb/gists{/gist_id}",
"starred_url": "https://api.github.com/users/lukaszb/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/lukaszb/subscriptions",
"organizations_url": "https://api.github.com/users/lukaszb/orgs",
"repos_url": "https://api.github.com/users/lukaszb/repos",
"events_url": "https://api.github.com/users/lukaszb/events{/privacy}",
"received_events_url": "https://api.github.com/users/lukaszb/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Cool, will take a look\n",
"The two test failures are relted to non-deterministic ordering.. I need to work up a real fix for those.\n\nI cherry-picked 9c12013f48d447584584781114f59a8fc7ca126f however, which was your fixes to the test runner. Thanks a ton!\n"
] | 2011-12-13T21:35:55 | 2014-07-06T01:52:25 | 2011-12-14T18:27:42 | NONE | null | I've removed some not used imports, changed test runner a little bit (so it can actually run single test, i.e.:
```
./runtest.py QueryTests.test_count
```
Fixed 2 (out of 3) failing tests. Last one (_QueryTests.test_count_) ... well, tried to debug it but the problem seem to be somewhere during iteration of _SelectQuery(Blog)_, not sure where exactly.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/23/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/23/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/23",
"html_url": "https://github.com/coleifer/peewee/pull/23",
"diff_url": "https://github.com/coleifer/peewee/pull/23.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/23.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/22 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/22/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/22/comments | https://api.github.com/repos/coleifer/peewee/issues/22/events | https://github.com/coleifer/peewee/pull/22 | 2,515,852 | MDExOlB1bGxSZXF1ZXN0NTgxMzk0 | 22 | Features/allow custom commit settings | {
"login": "deytao",
"id": 492203,
"node_id": "MDQ6VXNlcjQ5MjIwMw==",
"avatar_url": "https://avatars.githubusercontent.com/u/492203?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/deytao",
"html_url": "https://github.com/deytao",
"followers_url": "https://api.github.com/users/deytao/followers",
"following_url": "https://api.github.com/users/deytao/following{/other_user}",
"gists_url": "https://api.github.com/users/deytao/gists{/gist_id}",
"starred_url": "https://api.github.com/users/deytao/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/deytao/subscriptions",
"organizations_url": "https://api.github.com/users/deytao/orgs",
"repos_url": "https://api.github.com/users/deytao/repos",
"events_url": "https://api.github.com/users/deytao/events{/privacy}",
"received_events_url": "https://api.github.com/users/deytao/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Thanks for bringing up this issue -- I've added per-connection methods to toggle autocommit, letting you run multiple queries in a single transaction. The changeset is here b46ede9548a80ce2a9f135404f39cd363b6ba03d\n\nYou can check the API in the test cases above, but looks like:\n\n```\nmy_database.set_autocommit(False) # turn it off\ninsert_a_bunch_of_rows()\nmy_database.commit() # they are all committed in a single transaction\n```\n\nAlso:\n\n```\n@my_database.commit_on_success\ndef some_function():\n insert_a_bunch_of_rows()\n insert_some_bad_data_and_die()\n```\n\nThe above will issue a rollback and then raise the exception, and the rows inserted by \"insert_a_bunch_of_rows\" will be rolled back as well.\n",
"That's perfect! Thanks!\n"
] | 2011-12-11T13:17:55 | 2014-07-06T01:52:29 | 2011-12-12T16:08:56 | NONE | null | Hi!
I was a lil bit confused that all my insert and update was commit immediately.
Sometime I need to insert several records at once, I saw a rollback method but it was never used.
I decided to add a commit arg in the save method.
It was the simplest and fastest way to fix my problem.
Maybe I missed something.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/22/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/22/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/22",
"html_url": "https://github.com/coleifer/peewee/pull/22",
"diff_url": "https://github.com/coleifer/peewee/pull/22.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/22.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/21 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/21/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/21/comments | https://api.github.com/repos/coleifer/peewee/issues/21/events | https://github.com/coleifer/peewee/pull/21 | 2,438,373 | MDExOlB1bGxSZXF1ZXN0NTU1MjM4 | 21 | Allow custom sequence name | {
"login": "deytao",
"id": 492203,
"node_id": "MDQ6VXNlcjQ5MjIwMw==",
"avatar_url": "https://avatars.githubusercontent.com/u/492203?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/deytao",
"html_url": "https://github.com/deytao",
"followers_url": "https://api.github.com/users/deytao/followers",
"following_url": "https://api.github.com/users/deytao/following{/other_user}",
"gists_url": "https://api.github.com/users/deytao/gists{/gist_id}",
"starred_url": "https://api.github.com/users/deytao/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/deytao/subscriptions",
"organizations_url": "https://api.github.com/users/deytao/orgs",
"repos_url": "https://api.github.com/users/deytao/repos",
"events_url": "https://api.github.com/users/deytao/events{/privacy}",
"received_events_url": "https://api.github.com/users/deytao/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Cool, at first glance it looks good. We'll need to ensure that if a pk_sequence is specified that the column is created with that sequence as well. Lastly, do you think this is something that should be inheritable from model to model? i.e., the database Meta attribute is inheritable, but the db_table is not.\n",
"I've added the \"read\" part of this feature in 22639933f3079e6f01be173e5637672ce14f35cf but have not come up with the correct approach for \"write\", i.e. table creation. Will be thinking about this, though for now should wokr.\n",
"It should be inheritable because it has two goals.\n- To let the developer set his own sequence name for each table\n- To allow one sequence for all table or a group of table, like table inheritance in postgresql\n\nI think we shouldn't allow a pk_sequence attribute in children Meta.\nTo lock this behavior maybe it could be interesting to raise an exception. But it could also be possible to avoid the check since the parent is found.\n",
"Yeah, I should've updated my notes. I've added logic to create sequences automatically when running `Model.create_table()` and to share them across models using inheritance. It's in commit cc5d86f15dee40d45a0eacc95d346175c40eb99e\n\nYou can run the test suite using postgres:\n\n```\ncreatedb peewee_test\nexport PEEWEE_TEST_BACKEND=postgresql\npython setup.py test\n```\n"
] | 2011-12-03T18:02:07 | 2014-07-06T01:52:30 | 2011-12-03T21:55:46 | NONE | null | - Use Meta class to set it like
``` python
class Meta:
pk_sequence = 'sequence_name'
```
Helpful when using a global sequence.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/21/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/21/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/21",
"html_url": "https://github.com/coleifer/peewee/pull/21",
"diff_url": "https://github.com/coleifer/peewee/pull/21.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/21.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/20 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/20/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/20/comments | https://api.github.com/repos/coleifer/peewee/issues/20/events | https://github.com/coleifer/peewee/issues/20 | 2,363,211 | MDU6SXNzdWUyMzYzMjEx | 20 | Selecting databases in Meta is very non-flexible | {
"login": "jamorton",
"id": 18852,
"node_id": "MDQ6VXNlcjE4ODUy",
"avatar_url": "https://avatars.githubusercontent.com/u/18852?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/jamorton",
"html_url": "https://github.com/jamorton",
"followers_url": "https://api.github.com/users/jamorton/followers",
"following_url": "https://api.github.com/users/jamorton/following{/other_user}",
"gists_url": "https://api.github.com/users/jamorton/gists{/gist_id}",
"starred_url": "https://api.github.com/users/jamorton/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/jamorton/subscriptions",
"organizations_url": "https://api.github.com/users/jamorton/orgs",
"repos_url": "https://api.github.com/users/jamorton/repos",
"events_url": "https://api.github.com/users/jamorton/events{/privacy}",
"received_events_url": "https://api.github.com/users/jamorton/received_events",
"type": "User",
"site_admin": false
} | [
{
"id": 191752,
"node_id": "MDU6TGFiZWwxOTE3NTI=",
"url": "https://api.github.com/repos/coleifer/peewee/labels/Design%20decision",
"name": "Design decision",
"color": "02d7e1",
"default": false,
"description": null
}
] | closed | false | null | [] | null | [
"Thanks for bringing this up - the need to have a database instance at model definition time is ... well, it is what it is. You brought up django -- django declares the database(s) in a global (and much maligned) settings object. One of the decisions I made with peewee was to make it _not_ need global database configuration. One question is, if you don't declare your database at class creation time, what time _is_ appropriate?\n\nI'm not sure if this will help you, but my general workflow looks like this (to avoid circular imports):\n- app.py\n - flask application instantiation\n - peewee database instantiation\n - create a \"BaseModel\" class that uses the above database\n- models.py or whatever\n - import the BaseModel from app.py and extend for any specific models I need\n- views.py\n - import the flask app from app.py to create blueprint/url rules/etc\n - import any models needed from app.py\n- main.py\n - import the flask app from app.py\n - import all the views so they get registered\n - run the flask app or whatever\n",
"I think that database selection should be be able to take place any time before a connection needs to be made, so in the case of flask, sometime before @app.before_request ideally. For example, instead of the model classes holding a pointer to a database object, they hold a pointer to a callable that will give them a database object when they're instantiated. Or, both are permitted so the simple case doesn't change.\n\nI understand that there are reasonable ways to do everything in the global scope - and maybe that's the pythonic way - but it seemed weird when I had to move a lot of my stuff from classes into toplevel code to get it working.\n",
"Cool, also bear in mind that there's a difference between the database object (what you use with models) and the underlying connection/when that connection is made. It is made when it is first needed if not explicitly created. Also, you may want to check out flask-peewee, which does some of the things you've mentioned.\n\nhttps://github.com/coleifer/flask-peewee/tree/master/example\n"
] | 2011-11-28T01:33:08 | 2011-11-28T21:43:21 | 2011-11-28T21:43:21 | NONE | null | I don't know Django very well, but as far as I could tell, Django doesn't use the Meta class in models to select the database to use, and probably for a good reason?
I really like peewee, but I had to restructure some of my base application flow because all Peewee model classes have to have the database instance available immediately on class creation and in some global scope. The examples of course look fine, but for an application like mine that is larger and uses blueprints and all that, the Meta/inheritance system was a bit awkward to use.
do you think there's a way to just have a global bind variable? Like Elixir:
```
elixir.metadata.bind = "sqlite:///db.sqlite"
```
Put simply, it would be nice to have a way to set the database object after the Model classes have been created.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/20/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/20/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/19 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/19/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/19/comments | https://api.github.com/repos/coleifer/peewee/issues/19/events | https://github.com/coleifer/peewee/issues/19 | 2,351,933 | MDU6SXNzdWUyMzUxOTMz | 19 | Investigate selecting related fields | {
"login": "coleifer",
"id": 119974,
"node_id": "MDQ6VXNlcjExOTk3NA==",
"avatar_url": "https://avatars.githubusercontent.com/u/119974?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/coleifer",
"html_url": "https://github.com/coleifer",
"followers_url": "https://api.github.com/users/coleifer/followers",
"following_url": "https://api.github.com/users/coleifer/following{/other_user}",
"gists_url": "https://api.github.com/users/coleifer/gists{/gist_id}",
"starred_url": "https://api.github.com/users/coleifer/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/coleifer/subscriptions",
"organizations_url": "https://api.github.com/users/coleifer/orgs",
"repos_url": "https://api.github.com/users/coleifer/repos",
"events_url": "https://api.github.com/users/coleifer/events{/privacy}",
"received_events_url": "https://api.github.com/users/coleifer/received_events",
"type": "User",
"site_admin": false
} | [
{
"id": 191751,
"node_id": "MDU6TGFiZWwxOTE3NTE=",
"url": "https://api.github.com/repos/coleifer/peewee/labels/Feature",
"name": "Feature",
"color": "02e10c",
"default": false,
"description": null
}
] | closed | false | null | [] | null | [
"That looks wonderful.\n",
"I added support for this in 62bd00b90686aea6d6440ff129c30cf28a2a9449 -- basically, it takes what you pass in to the select() method, queries the db, constructs instances (and related instances), then puts them all together. Can reduce your queries from _n_ to 1 when iterating and checking up the fk tree. It doesn't go 'down' the chain, though...ie you can't select Blog and then preload their related entries, though implementing this in python is not hard.\n\nFrom the test cases:\n\n```\ndef test_select_related_multiple(self):\n qc1 = len(self.queries())\n\n sq = EntryTag.select({\n EntryTag: ['*'],\n Entry: ['pk', 'blog_id'],\n Blog: ['title'],\n }).join(Entry).join(Blog).where(title='b1')\n\n results = list(sq)\n blog_titles = [r.entry.blog.title for r in results]\n blog_ids = [r.entry.blog.id for r in results]\n\n self.assertEqual(blog_titles, ['b1', 'b1', 'b1'])\n self.assertEqual(blog_ids, [self.b1.id, self.b1.id, self.b1.id])\n\n qc2 = len(self.queries())\n\n self.assertEqual(qc2 - qc1, 1)\n```\n"
] | 2011-11-25T20:05:33 | 2011-12-27T20:36:04 | 2011-12-27T20:36:04 | OWNER | null | Would be nice to be able to populate (or partially populate) instances of related objects when querying. Example would be querying a list of blog entries and wanting to additionally select the 'name' of the blog -- this can be done in 1 query with a join.
It shouldn't be too hard... related models can be queried passing a dictionary to Model.select() -- need to add the logic to the QueryResultWrapper. Looking at the returned rows and converting them into a dictionary may not work here if column names collide, so might need to list the columns and assign based on index.
Now that fields are exposed using descriptors it sohuld be possible to do "deferred" loading of field data as well, i.e. if it wasn't selected but then is asked for.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/19/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/19/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/18 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/18/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/18/comments | https://api.github.com/repos/coleifer/peewee/issues/18/events | https://github.com/coleifer/peewee/issues/18 | 2,331,667 | MDU6SXNzdWUyMzMxNjY3 | 18 | [Postgresql] Boolean data type | {
"login": "deytao",
"id": 492203,
"node_id": "MDQ6VXNlcjQ5MjIwMw==",
"avatar_url": "https://avatars.githubusercontent.com/u/492203?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/deytao",
"html_url": "https://github.com/deytao",
"followers_url": "https://api.github.com/users/deytao/followers",
"following_url": "https://api.github.com/users/deytao/following{/other_user}",
"gists_url": "https://api.github.com/users/deytao/gists{/gist_id}",
"starred_url": "https://api.github.com/users/deytao/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/deytao/subscriptions",
"organizations_url": "https://api.github.com/users/deytao/orgs",
"repos_url": "https://api.github.com/users/deytao/repos",
"events_url": "https://api.github.com/users/deytao/events{/privacy}",
"received_events_url": "https://api.github.com/users/deytao/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Fixed in 31b213e4db37f39fe3374ad2ea4143350e126242 - tested against postgresql, mysql and sqlite\n"
] | 2011-11-23T16:42:24 | 2011-11-25T05:30:11 | 2011-11-25T05:30:11 | NONE | null | If I create manually my table with a boolean type I can't insert a record using a field like BooleanField because it try to insert an integer.
Postgresql handles correctly bool() and stores a proper boolean field not like MySQL or Oracle which are casting in integer.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/18/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/18/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/17 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/17/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/17/comments | https://api.github.com/repos/coleifer/peewee/issues/17/events | https://github.com/coleifer/peewee/issues/17 | 2,331,618 | MDU6SXNzdWUyMzMxNjE4 | 17 | Add field inheritance | {
"login": "deytao",
"id": 492203,
"node_id": "MDQ6VXNlcjQ5MjIwMw==",
"avatar_url": "https://avatars.githubusercontent.com/u/492203?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/deytao",
"html_url": "https://github.com/deytao",
"followers_url": "https://api.github.com/users/deytao/followers",
"following_url": "https://api.github.com/users/deytao/following{/other_user}",
"gists_url": "https://api.github.com/users/deytao/gists{/gist_id}",
"starred_url": "https://api.github.com/users/deytao/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/deytao/subscriptions",
"organizations_url": "https://api.github.com/users/deytao/orgs",
"repos_url": "https://api.github.com/users/deytao/repos",
"events_url": "https://api.github.com/users/deytao/events{/privacy}",
"received_events_url": "https://api.github.com/users/deytao/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Totally -- creating models should be DRY. This should work and currently does not (need to add some logic in the metaclass). I'm not sure what you mean by using a global ID, but multi-table inheritance is not something I plan on implementing. If you're looking for that level of control, definitely would recommend http://www.sqlalchemy.org/docs/orm/inheritance.html\n",
"I saw you were creating a sequence for each primary key. Which is correct.\nBut with my proposition I was hoping to get one sequence for all tables inheriting of the \"coremodel\"\nI try to implement it, but my python skills are def not that good.\nReading your code taught me a lot about python, but not enough to fork it.\n\nSQLAlchemy is too heavy, I don't really need it for my project.\n",
"I've fixed the bug where fields are not inherited. As for the part about sharing a sequence, that is not something that will be implemented as part of peewee.\n"
] | 2011-11-23T16:38:56 | 2011-11-25T18:38:22 | 2011-11-25T18:38:22 | NONE | null | Hi,
It would be nice if something like that could work
``` python
import peewee
Class CoreModel(peewee.Model):
id = peewee.PrimaryKeyField()
created = peewee.DatetimeField()
Class Meta:
database = db
Class User(CoreModel):
firstname = peewee.CharField()
Class Car(CoreModel):
brand = peewee.CharField()
```
I don't want to duplicate my fields.
Also for the id when I'm using a global ID.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/17/reactions",
"total_count": 1,
"+1": 1,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/17/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/16 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/16/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/16/comments | https://api.github.com/repos/coleifer/peewee/issues/16/events | https://github.com/coleifer/peewee/issues/16 | 2,276,345 | MDU6SXNzdWUyMjc2MzQ1 | 16 | Add support for bigint and double fields | {
"login": "marmelo",
"id": 247440,
"node_id": "MDQ6VXNlcjI0NzQ0MA==",
"avatar_url": "https://avatars.githubusercontent.com/u/247440?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/marmelo",
"html_url": "https://github.com/marmelo",
"followers_url": "https://api.github.com/users/marmelo/followers",
"following_url": "https://api.github.com/users/marmelo/following{/other_user}",
"gists_url": "https://api.github.com/users/marmelo/gists{/gist_id}",
"starred_url": "https://api.github.com/users/marmelo/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/marmelo/subscriptions",
"organizations_url": "https://api.github.com/users/marmelo/orgs",
"repos_url": "https://api.github.com/users/marmelo/repos",
"events_url": "https://api.github.com/users/marmelo/events{/privacy}",
"received_events_url": "https://api.github.com/users/marmelo/received_events",
"type": "User",
"site_admin": false
} | [
{
"id": 191751,
"node_id": "MDU6TGFiZWwxOTE3NTE=",
"url": "https://api.github.com/repos/coleifer/peewee/labels/Feature",
"name": "Feature",
"color": "02e10c",
"default": false,
"description": null
}
] | closed | false | null | [] | null | [
"This will become handy. Thanks!\n"
] | 2011-11-18T02:38:13 | 2012-01-21T03:44:28 | 2012-01-17T05:30:56 | NONE | null | Currently you can only define IntegerField, FloatField and DecimalField.
What happens if you need to store a long (bigint)?
You have to use a Decimal without decimal places?
A new **LongField** (or BigIntField) should be added (**bigint, 8 bytes**).
Also, sometimes float is not enough.
For coherence, **DoubleField** should also be added (**double precision, 8 bytes**).
I believe both cases are extremely frequent.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/16/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/16/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/15 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/15/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/15/comments | https://api.github.com/repos/coleifer/peewee/issues/15/events | https://github.com/coleifer/peewee/issues/15 | 2,276,320 | MDU6SXNzdWUyMjc2MzIw | 15 | FloatField is translated differently between supported implementations | {
"login": "marmelo",
"id": 247440,
"node_id": "MDQ6VXNlcjI0NzQ0MA==",
"avatar_url": "https://avatars.githubusercontent.com/u/247440?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/marmelo",
"html_url": "https://github.com/marmelo",
"followers_url": "https://api.github.com/users/marmelo/followers",
"following_url": "https://api.github.com/users/marmelo/following{/other_user}",
"gists_url": "https://api.github.com/users/marmelo/gists{/gist_id}",
"starred_url": "https://api.github.com/users/marmelo/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/marmelo/subscriptions",
"organizations_url": "https://api.github.com/users/marmelo/orgs",
"repos_url": "https://api.github.com/users/marmelo/repos",
"events_url": "https://api.github.com/users/marmelo/events{/privacy}",
"received_events_url": "https://api.github.com/users/marmelo/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Thanks.\n"
] | 2011-11-18T02:29:38 | 2011-11-21T11:37:17 | 2011-11-18T20:10:54 | NONE | null | Floats, by definition, should only take 4 bytes.
_Currently:_
- SQLite, real, 8 bytes
- MySQL, double precision, 8 bytes
- PostgreSQL, real, 4 bytes
_Proposal:_
- SQLite should continue using real (I believe there is no 4 bytes floating point datatype).
- MySQL should be using float, 4 bytes.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/15/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/15/timeline | null | completed | null | null |