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/1018 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1018/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1018/comments | https://api.github.com/repos/coleifer/peewee/issues/1018/events | https://github.com/coleifer/peewee/issues/1018 | 166,441,534 | MDU6SXNzdWUxNjY0NDE1MzQ= | 1,018 | Implement alternative DeferredRelation semantics | {
"login": "c0ldcalamari",
"id": 11208820,
"node_id": "MDQ6VXNlcjExMjA4ODIw",
"avatar_url": "https://avatars.githubusercontent.com/u/11208820?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/c0ldcalamari",
"html_url": "https://github.com/c0ldcalamari",
"followers_url": "https://api.github.com/users/c0ldcalamari/followers",
"following_url": "https://api.github.com/users/c0ldcalamari/following{/other_user}",
"gists_url": "https://api.github.com/users/c0ldcalamari/gists{/gist_id}",
"starred_url": "https://api.github.com/users/c0ldcalamari/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/c0ldcalamari/subscriptions",
"organizations_url": "https://api.github.com/users/c0ldcalamari/orgs",
"repos_url": "https://api.github.com/users/c0ldcalamari/repos",
"events_url": "https://api.github.com/users/c0ldcalamari/events{/privacy}",
"received_events_url": "https://api.github.com/users/c0ldcalamari/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"That's a very nice API. Depending on the class name (a string) is something I try to shy away from, as errors can occur despite the code appearing to be perfectly valid, for instance a typo or you happen to change the model name in one place and not the other.\n\nI like the API, though, and agree that it would be worth supporting if done in a backwards-compatible way. Thanks for the patch, looking at it now.\n",
"Awesome. Thanks, I've merged your patch, really appreciate you taking the time to fix this one and implement such a clean patch.\n"
] | 2016-07-19T21:36:08 | 2016-07-20T15:50:01 | 2016-07-20T15:50:01 | NONE | null | The [semantics behind circular foreign key dependencies](http://docs.peewee-orm.com/en/latest/peewee/models.html#circular-foreign-key-dependencies) get kind of unwieldy when you have more than a few models (and they're spread over multiple files). This is because the `DeferredRelation` object has to be defined, used, then the other model defined in another file, then `set_model` has to be called on the original, and then you're left with the object reference dangling around that has no purpose. IE the example in the docs:
``` python
# Create a reference object to stand in for our as-yet-undefined Tweet model.
DeferredTweet = DeferredRelation()
class User(Model):
username = CharField()
# Tweet has not been defined yet so use the deferred reference.
favorite_tweet = ForeignKeyField(DeferredTweet, null=True)
class Tweet(Model):
message = TextField()
user = ForeignKeyField(User, related_name='tweets')
# Now that Tweet is defined, we can initialize the reference.
DeferredTweet.set_model(Tweet)
```
It would be better if it all happened in the model definition with an optional parameter given to `DeferredRelation`. Like:
``` python
class User(Model):
username = CharField()
# Tweet has not been defined yet so use the deferred reference.
favorite_tweet = ForeignKeyField(DeferredRelation('Tweet'), null=True)
class Tweet(Model):
message = TextField()
user = ForeignKeyField(User, related_name='tweets')
```
This would remove the need for the extra variable in the global namespace and the coordination of it over multiple files. And since the parameter is optional, it can be fully backwards-compatible with the old syntax.
Thank you!
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1018/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1018/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1017 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1017/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1017/comments | https://api.github.com/repos/coleifer/peewee/issues/1017/events | https://github.com/coleifer/peewee/issues/1017 | 166,265,605 | MDU6SXNzdWUxNjYyNjU2MDU= | 1,017 | Issues with counting uuid in Postgresql | {
"login": "bitnic028",
"id": 11515516,
"node_id": "MDQ6VXNlcjExNTE1NTE2",
"avatar_url": "https://avatars.githubusercontent.com/u/11515516?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/bitnic028",
"html_url": "https://github.com/bitnic028",
"followers_url": "https://api.github.com/users/bitnic028/followers",
"following_url": "https://api.github.com/users/bitnic028/following{/other_user}",
"gists_url": "https://api.github.com/users/bitnic028/gists{/gist_id}",
"starred_url": "https://api.github.com/users/bitnic028/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/bitnic028/subscriptions",
"organizations_url": "https://api.github.com/users/bitnic028/orgs",
"repos_url": "https://api.github.com/users/bitnic028/repos",
"events_url": "https://api.github.com/users/bitnic028/events{/privacy}",
"received_events_url": "https://api.github.com/users/bitnic028/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Thanks for including the traceback. Looks like the exception itself got cut off. Could you please include that? Will make debugging a bit easier... I'm just guessing here, but is psycopg2 already providing a uuid and peewee is treating it like it's a string?\n",
"All code with all traceback:\n\n```\n>>> from application.db.models import Department, User\n>>> from application.db.models import db\n>>> from peewee import fn\n>>> k = Department.select(Department.prefix, fn.COUNT(User.id).alias('total_users')).join(User).group_by(Department.prefix).dicts()\n>>> for t in k:\n... print t\n... \nTraceback (most recent call last):\n File \"<input>\", line 1, in <module>\n File \"/usr/local/lib/python2.7/dist-packages/peewee.py\", line 2047, in next\n obj = self.qrw.iterate()\n File \"/usr/local/lib/python2.7/dist-packages/peewee.py\", line 2107, in iterate\n return self.process_row(row)\n File \"/usr/local/lib/python2.7/dist-packages/peewee.py\", line 2196, in process_row\n res[column] = func(row[i])\n File \"/usr/local/lib/python2.7/dist-packages/peewee.py\", line 1105, in python_value\n return None if value is None else uuid.UUID(value)\n File \"/usr/lib/python2.7/uuid.py\", line 133, in __init__\n hex = hex.replace('urn:', '').replace('uuid:', '')\nAttributeError: 'long' object has no attribute 'replace'\n```\n",
"Oh of course! Sorry, yes. For now you can work around this by calling:\n\n``` python\nfn.COUNT(User.id).coerce(False).alias('total_users')\n```\n\nBut I am working up a patch to fix this.\n",
"Fixed in b84ca0c8bc724b8cccd0b5bbd557abc04885c478\n"
] | 2016-07-19T07:29:52 | 2016-07-20T16:26:25 | 2016-07-20T16:26:25 | NONE | null | Issues with counting uuid, with other type fields the problem is avoid.
For example:
```
import peewee
from uuid import UUID
class User():
id = UUIDField(primary_key=True)
login = CharField()
department = ForeignKeyField(Department, related_name=u"users_in_department", null=True)
class Department():
id = UUIDField(primary_key=True)
name = CharField()
```
Then:
```
d = (Department.select(
Department.name,
fn.COUNT(User.id).alias('total_users')
).join(User).group_by(Department.name))
for t in d:
pass
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 2047, in next
obj = self.qrw.iterate()
File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 2107, in iterate
return self.process_row(row)
File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 2185, in process_row
setattr(instance, column, func(row[i]))
File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 1105, in python_value
return None if value is None else uuid.UUID(value)
File "/usr/lib/python2.7/uuid.py", line 133, in __init__
hex = hex.replace('urn:', '').replace('uuid:', '')
```
But `User.login` instead `User.id`
```
d = (Department.select(
Department.name,
fn.COUNT(User.login).alias('total_users')
).join(User).group_by(Department.name))
for t in d:
pass
```
works correctly/
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1017/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1017/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1016 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1016/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1016/comments | https://api.github.com/repos/coleifer/peewee/issues/1016/events | https://github.com/coleifer/peewee/pull/1016 | 166,251,895 | MDExOlB1bGxSZXF1ZXN0Nzc5MTk5NjY= | 1,016 | The update of BooleanField coerce | {
"login": "mobishift2011",
"id": 3817564,
"node_id": "MDQ6VXNlcjM4MTc1NjQ=",
"avatar_url": "https://avatars.githubusercontent.com/u/3817564?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/mobishift2011",
"html_url": "https://github.com/mobishift2011",
"followers_url": "https://api.github.com/users/mobishift2011/followers",
"following_url": "https://api.github.com/users/mobishift2011/following{/other_user}",
"gists_url": "https://api.github.com/users/mobishift2011/gists{/gist_id}",
"starred_url": "https://api.github.com/users/mobishift2011/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/mobishift2011/subscriptions",
"organizations_url": "https://api.github.com/users/mobishift2011/orgs",
"repos_url": "https://api.github.com/users/mobishift2011/repos",
"events_url": "https://api.github.com/users/mobishift2011/events{/privacy}",
"received_events_url": "https://api.github.com/users/mobishift2011/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Is this in reference to a particular issue?\n",
"**Amazing!**\n",
"This patch seems more suitable for a subclass of BooleanField that is designed to handle things like strings or untrusted data.\n"
] | 2016-07-19T05:35:02 | 2016-07-29T14:18:16 | 2016-07-29T14:18:16 | NONE | null | Good afternoon, coleifer. We've found the most common case is that the data from the client(as browser) will send true or false, 1 or 0 to the server, but the conversion should be decided by peewee on the data field type. So may be the update of mine makes common sense.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1016/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1016/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/1016",
"html_url": "https://github.com/coleifer/peewee/pull/1016",
"diff_url": "https://github.com/coleifer/peewee/pull/1016.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/1016.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/1015 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1015/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1015/comments | https://api.github.com/repos/coleifer/peewee/issues/1015/events | https://github.com/coleifer/peewee/issues/1015 | 166,145,488 | MDU6SXNzdWUxNjYxNDU0ODg= | 1,015 | Pass params into where with kwargs. | {
"login": "alexpantyukhin",
"id": 6513121,
"node_id": "MDQ6VXNlcjY1MTMxMjE=",
"avatar_url": "https://avatars.githubusercontent.com/u/6513121?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/alexpantyukhin",
"html_url": "https://github.com/alexpantyukhin",
"followers_url": "https://api.github.com/users/alexpantyukhin/followers",
"following_url": "https://api.github.com/users/alexpantyukhin/following{/other_user}",
"gists_url": "https://api.github.com/users/alexpantyukhin/gists{/gist_id}",
"starred_url": "https://api.github.com/users/alexpantyukhin/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/alexpantyukhin/subscriptions",
"organizations_url": "https://api.github.com/users/alexpantyukhin/orgs",
"repos_url": "https://api.github.com/users/alexpantyukhin/repos",
"events_url": "https://api.github.com/users/alexpantyukhin/events{/privacy}",
"received_events_url": "https://api.github.com/users/alexpantyukhin/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Actually, this functionality does exist, but is currently marked as deprecated and no longer documented. You can view the docs [on the 2.0.2 build](http://docs.peewee-orm.com/en/2.0.2/peewee/querying.html#SelectQuery.filter), however.\n\nIf you use the alternative `filter()` API, you can use Django-style kwargs lookups:\n\n``` python\n# Works pretty much like you expect:\nactive = User.filter(active=True)\nsome_users = active.filter(username__in=('charlie', 'huey', 'zaizee'))\n\n# You can do \"OR\" using `DQ`:\neditors = User.filter(DQ(is_admin=True) | DQ(is_staff=True))\n```\n"
] | 2016-07-18T17:16:45 | 2016-07-20T15:35:27 | 2016-07-20T15:35:27 | NONE | null | Hi. Sometimes it's very useful to pass a collection of parameters with `kwargs` into the `where` clause.
What if to add some kind of function like `q(class, **kwargs)` into playhouse which gets params and translate it on expressions which are already used in the peewee.
(Not sure if such function already exists). Or maybe create another method like `where_by` likes it's done in SQLAlchemy.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1015/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1015/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1014 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1014/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1014/comments | https://api.github.com/repos/coleifer/peewee/issues/1014/events | https://github.com/coleifer/peewee/issues/1014 | 166,000,968 | MDU6SXNzdWUxNjYwMDA5Njg= | 1,014 | Minor: logging of queries after final string interpolation | {
"login": "bcattle",
"id": 620058,
"node_id": "MDQ6VXNlcjYyMDA1OA==",
"avatar_url": "https://avatars.githubusercontent.com/u/620058?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/bcattle",
"html_url": "https://github.com/bcattle",
"followers_url": "https://api.github.com/users/bcattle/followers",
"following_url": "https://api.github.com/users/bcattle/following{/other_user}",
"gists_url": "https://api.github.com/users/bcattle/gists{/gist_id}",
"starred_url": "https://api.github.com/users/bcattle/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/bcattle/subscriptions",
"organizations_url": "https://api.github.com/users/bcattle/orgs",
"repos_url": "https://api.github.com/users/bcattle/repos",
"events_url": "https://api.github.com/users/bcattle/events{/privacy}",
"received_events_url": "https://api.github.com/users/bcattle/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"It would be much better! If I recall correctly, you can also use psycopg2.mogrify to get the final query. Unfortunately pysqlite doesnt implement this:\n- http://bugs.python.org/issue9506\n- https://github.com/ghaering/pysqlite/issues/20#issuecomment-26258837\n\nLooks like mysql-python doesn't implement this either.\n\nSo, because it's just postgres, I think I'll favor lowest common denominator here.\n"
] | 2016-07-17T23:07:33 | 2016-07-18T00:20:31 | 2016-07-18T00:20:31 | CONTRIBUTOR | null | Hey, I love this library. The [docs](http://docs.peewee-orm.com/en/latest/peewee/database.html#logging-queries) say you can turn on logging of queries with
```
# Print all queries to stderr.
import logging
logger = logging.getLogger('peewee')
logger.setLevel(logging.DEBUG)
logger.addHandler(logging.StreamHandler())
```
This produces output such as the following:
```
('
SELECT count(DISTINCT username)
FROM get_rows_created_days_ago_with_lookback(NULL::stats_daily_active_users, %(days_prior)s, %(lookback_days)s)
', {'days_prior': 1, 'lookback_days': 7})
```
In other words, it's printing the output before the final string interpolation step.
By accessing the psycopg2 `cursor.query` attribute, you are able to get the output _after_ that final string interpolation step, returning:
```
SELECT count(DISTINCT username)
FROM get_rows_created_days_ago_with_lookback(NULL::stats_daily_active_users, 1, 7)
```
Would it be clearer if we change the logging code to use the psycopg2 `cursor.query` property? Thanks.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1014/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1014/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1013 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1013/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1013/comments | https://api.github.com/repos/coleifer/peewee/issues/1013/events | https://github.com/coleifer/peewee/issues/1013 | 165,507,045 | MDU6SXNzdWUxNjU1MDcwNDU= | 1,013 | Execute a transaction when use Read Slaves | {
"login": "huangzhw",
"id": 3366133,
"node_id": "MDQ6VXNlcjMzNjYxMzM=",
"avatar_url": "https://avatars.githubusercontent.com/u/3366133?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/huangzhw",
"html_url": "https://github.com/huangzhw",
"followers_url": "https://api.github.com/users/huangzhw/followers",
"following_url": "https://api.github.com/users/huangzhw/following{/other_user}",
"gists_url": "https://api.github.com/users/huangzhw/gists{/gist_id}",
"starred_url": "https://api.github.com/users/huangzhw/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/huangzhw/subscriptions",
"organizations_url": "https://api.github.com/users/huangzhw/orgs",
"repos_url": "https://api.github.com/users/huangzhw/repos",
"events_url": "https://api.github.com/users/huangzhw/events{/privacy}",
"received_events_url": "https://api.github.com/users/huangzhw/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"For that case I'd suggest using the [execution context helper](http://docs.peewee-orm.com/en/latest/peewee/api.html#ExecutionContext).\n\nHard to say more, though. So you're using the \"ReadSlaveModel\"...may I ask what for? Do you have a large number of read replicas and a lot of database load?\n",
"No. I just want to figure out whether some operation done when execute a transaction. Maybe when in a transaction, the ReadSlaveModel should return the master connection.\n",
"I'm not sure I follow, can you explain giving me a concrete example?\n",
"We did not user orm before. In our system, we have two mysql user, db_reader and db_writer. We use db_reader to execute read-only statement, and db_writer execute other statement. When use peewee, I think the ReadSlaveModel can solve this situation. \n",
"@hzweveryday -- thanks for the explanation of your database setup. Hmm... I know the `ReadSlaveModel` option sounds like the right solution, but I'm not sure how to go about ensuring the proper isolation between transactions/connections. This comes down to my lack of familiarity with the ins-and-outs of MySQL..\n\nI'm not actually sure what benefits having two particular database users provides you, if your application is freely using both the reader and the writer. If they are both connected to the same database, perhaps you could just use the db_writer exclusively?\n\nI'd suggest that you go ahead and try using the `ReadSlaveModel` if you plan to maintain a strict separation between the two users/connections. Otherwise, I'd suggest using the connection pool with the db_writer user.\n",
"Thank you! Now I use PooledMySQLDatabase. This should be a good solution.\n"
] | 2016-07-14T08:33:03 | 2016-07-15T03:20:51 | 2016-07-15T03:15:04 | NONE | null | When we are executing a transaction, we want the connection stay the same. But if we use Read Slaves, select will use slave connections? So, if we want use master connection, we have to instantiate the SelectQuery by hand?
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1013/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1013/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1012 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1012/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1012/comments | https://api.github.com/repos/coleifer/peewee/issues/1012/events | https://github.com/coleifer/peewee/issues/1012 | 165,380,289 | MDU6SXNzdWUxNjUzODAyODk= | 1,012 | null FKs return non-null objects with all-null attributes | {
"login": "neopunisher",
"id": 73310,
"node_id": "MDQ6VXNlcjczMzEw",
"avatar_url": "https://avatars.githubusercontent.com/u/73310?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/neopunisher",
"html_url": "https://github.com/neopunisher",
"followers_url": "https://api.github.com/users/neopunisher/followers",
"following_url": "https://api.github.com/users/neopunisher/following{/other_user}",
"gists_url": "https://api.github.com/users/neopunisher/gists{/gist_id}",
"starred_url": "https://api.github.com/users/neopunisher/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/neopunisher/subscriptions",
"organizations_url": "https://api.github.com/users/neopunisher/orgs",
"repos_url": "https://api.github.com/users/neopunisher/repos",
"events_url": "https://api.github.com/users/neopunisher/events{/privacy}",
"received_events_url": "https://api.github.com/users/neopunisher/received_events",
"type": "User",
"site_admin": false
} | [] | closed | true | null | [] | null | [
"Here's the plan for the fix:\n\n> If the user selects the foreign key field and it is null, then it's a safe bet to skip object creation. Same, as you mentioned, if they select the related object's primary key. Beyond that it gets murky. I'll look into implementing this.\n\n**Edit: fix has been merged**\n"
] | 2016-07-13T17:45:00 | 2016-07-17T05:27:24 | 2016-07-14T05:22:10 | NONE | null | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1012/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1012/timeline | null | completed | null | null |
|
https://api.github.com/repos/coleifer/peewee/issues/1011 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1011/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1011/comments | https://api.github.com/repos/coleifer/peewee/issues/1011/events | https://github.com/coleifer/peewee/issues/1011 | 165,227,590 | MDU6SXNzdWUxNjUyMjc1OTA= | 1,011 | Calling Model.save() changes PaswordField passwords | {
"login": "joeyespo",
"id": 634573,
"node_id": "MDQ6VXNlcjYzNDU3Mw==",
"avatar_url": "https://avatars.githubusercontent.com/u/634573?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/joeyespo",
"html_url": "https://github.com/joeyespo",
"followers_url": "https://api.github.com/users/joeyespo/followers",
"following_url": "https://api.github.com/users/joeyespo/following{/other_user}",
"gists_url": "https://api.github.com/users/joeyespo/gists{/gist_id}",
"starred_url": "https://api.github.com/users/joeyespo/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/joeyespo/subscriptions",
"organizations_url": "https://api.github.com/users/joeyespo/orgs",
"repos_url": "https://api.github.com/users/joeyespo/repos",
"events_url": "https://api.github.com/users/joeyespo/events{/privacy}",
"received_events_url": "https://api.github.com/users/joeyespo/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"That was _fast_! How do you do it? :smiley: \n",
"Also, thanks!\n"
] | 2016-07-13T03:10:42 | 2016-07-13T03:34:23 | 2016-07-13T03:19:58 | CONTRIBUTOR | null | I have a `User` model with a `PasswordField` and noticed that when I change some fields can call `user.save()`, the password gets regenerated. From skimming the code, it looks like it's re-hashing the password hash.
The following is my current workaround:
``` py
from playhouse.fields import PasswordField as PasswordFieldBase, PasswordHash
class PasswordField(PasswordFieldBase):
def db_value(self, value):
if isinstance(value, PasswordHash):
return value
return super(PasswordField, self).db_value(value)
```
If it matters, I'm using `flask_utils` and `Proxy` on `master` (since it contains [the proxy fix](https://github.com/coleifer/peewee/issues/933)).
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1011/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1011/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1010 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1010/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1010/comments | https://api.github.com/repos/coleifer/peewee/issues/1010/events | https://github.com/coleifer/peewee/issues/1010 | 165,077,137 | MDU6SXNzdWUxNjUwNzcxMzc= | 1,010 | Support for CASE or FILTER in COUNT | {
"login": "dev-zero",
"id": 11307,
"node_id": "MDQ6VXNlcjExMzA3",
"avatar_url": "https://avatars.githubusercontent.com/u/11307?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/dev-zero",
"html_url": "https://github.com/dev-zero",
"followers_url": "https://api.github.com/users/dev-zero/followers",
"following_url": "https://api.github.com/users/dev-zero/following{/other_user}",
"gists_url": "https://api.github.com/users/dev-zero/gists{/gist_id}",
"starred_url": "https://api.github.com/users/dev-zero/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/dev-zero/subscriptions",
"organizations_url": "https://api.github.com/users/dev-zero/orgs",
"repos_url": "https://api.github.com/users/dev-zero/repos",
"events_url": "https://api.github.com/users/dev-zero/events{/privacy}",
"received_events_url": "https://api.github.com/users/dev-zero/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I came up with the following hacks/workarounds:\n\n``` python\n q = Task.select(Task.machine,\n fn.COUNT(Task.id).alias('total'),\n fn.COUNT(SQL('t1.id) FILTER (WHERE t1.status = %s', 'running')).alias('running')) \\\n .group_by(Task.machine)\n\n```\n\n``` python\n q = Task.select(Task.machine,\n fn.COUNT(Task.machine).alias('total'),\n fn.COUNT(SQL('CASE WHEN t1.status = %s THEN t1.id END', 'running')).alias('running')) \\\n .group_by(Task.machine)\n```\n",
"There is support for `Case`: http://docs.peewee-orm.com/en/latest/peewee/playhouse.html#case\n\nFor other arbitrary ones, you can do:\n\n``` python\nClause(\n fn.COUNT(Task.id),\n fn.FILTER(Clause(SQL('WHERE'), Task.status == 'running'))\n)\n```\n"
] | 2016-07-12T13:14:31 | 2016-07-13T01:42:57 | 2016-07-13T01:42:57 | NONE | null | Given a table `tas` with the following columns:
```
id | machine | status
```
I would like to count the number of total and running tasks per machine.
In PostgreSQL 9.5 this is possible using:
``` sql
SELECT machine,
COUNT(id) FILTER (WHERE status='running') AS running,
COUNT(id) AS total
FROM task
GROUP BY(machine);
```
So I naively write:
``` py
q = Task.select(Task.machine,
fn.COUNT(Task.machine).alias('total'),
fn.COUNT(Task.machine).where(Task.status == "running").alias('running')) \
.group_by(Task.machine)
```
which gives me something like
``` sql
SELECT "t1"."machine", COUNT("t1"."id") AS total, filter("t1"."status" = 'running') AS running FROM "task" AS t1 GROUP BY "t1"."machine"'
```
Unfortunately, PostgresSQL prior to 9.5 seems to need a slightly different construct:
``` sql
SELECT machine,
COUNT(CASE WHEN status='running' THEN id END) AS running,
COUNT(id) AS total
FROM task
GROUP BY(machine);
```
From reading the code I guess one would have to write a function similar to the `over()` already present in `Func`.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1010/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1010/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1009 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1009/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1009/comments | https://api.github.com/repos/coleifer/peewee/issues/1009/events | https://github.com/coleifer/peewee/pull/1009 | 164,757,582 | MDExOlB1bGxSZXF1ZXN0NzY4OTc5Nzc= | 1,009 | Accept DATABASE_URL config variable in flask_utils | {
"login": "joeyespo",
"id": 634573,
"node_id": "MDQ6VXNlcjYzNDU3Mw==",
"avatar_url": "https://avatars.githubusercontent.com/u/634573?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/joeyespo",
"html_url": "https://github.com/joeyespo",
"followers_url": "https://api.github.com/users/joeyespo/followers",
"following_url": "https://api.github.com/users/joeyespo/following{/other_user}",
"gists_url": "https://api.github.com/users/joeyespo/gists{/gist_id}",
"starred_url": "https://api.github.com/users/joeyespo/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/joeyespo/subscriptions",
"organizations_url": "https://api.github.com/users/joeyespo/orgs",
"repos_url": "https://api.github.com/users/joeyespo/repos",
"events_url": "https://api.github.com/users/joeyespo/events{/privacy}",
"received_events_url": "https://api.github.com/users/joeyespo/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Your implementation is better. :+1: \n\nThank you :smiley:\n"
] | 2016-07-11T04:18:32 | 2016-07-12T17:56:31 | 2016-07-12T17:50:38 | CONTRIBUTOR | null | Makes working with Heroku's `DATABASE_URL` standard slightly more straightforward, since Flask Utils already works with a connection URL out-of-the-box.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1009/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1009/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/1009",
"html_url": "https://github.com/coleifer/peewee/pull/1009",
"diff_url": "https://github.com/coleifer/peewee/pull/1009.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/1009.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/1008 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1008/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1008/comments | https://api.github.com/repos/coleifer/peewee/issues/1008/events | https://github.com/coleifer/peewee/issues/1008 | 164,581,279 | MDU6SXNzdWUxNjQ1ODEyNzk= | 1,008 | [Bug] Prefetch and limit bug | {
"login": "elkranio",
"id": 2633533,
"node_id": "MDQ6VXNlcjI2MzM1MzM=",
"avatar_url": "https://avatars.githubusercontent.com/u/2633533?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/elkranio",
"html_url": "https://github.com/elkranio",
"followers_url": "https://api.github.com/users/elkranio/followers",
"following_url": "https://api.github.com/users/elkranio/following{/other_user}",
"gists_url": "https://api.github.com/users/elkranio/gists{/gist_id}",
"starred_url": "https://api.github.com/users/elkranio/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/elkranio/subscriptions",
"organizations_url": "https://api.github.com/users/elkranio/orgs",
"repos_url": "https://api.github.com/users/elkranio/repos",
"events_url": "https://api.github.com/users/elkranio/events{/privacy}",
"received_events_url": "https://api.github.com/users/elkranio/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2016-07-08T17:46:28 | 2016-07-08T17:56:35 | 2016-07-08T17:56:35 | NONE | null | Each game can have several platforms. When I use **limit** or **paginate**, some of the games end up without platforms.
Acts strangely:
`games = Game.select().limit(50)`
`platforms = GamePlatform.select()`
`games_pf = prefetch(games, platforms)`
Works fine
`games = Game.select().where(Game.id << [1, 2, 3 ... 50]`
`platforms = GamePlatform.select()`
`games_pf = prefetch(games, platforms)`
Not sure if it is a bug, but since your docs say
> Additionally, because of the semantics of subquerying, there may be some cases when prefetch does not act as you expect (for instance, when applying a LIMIT to subqueries, but there may be others) – please report anything you think is a bug to github.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1008/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1008/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1007 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1007/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1007/comments | https://api.github.com/repos/coleifer/peewee/issues/1007/events | https://github.com/coleifer/peewee/issues/1007 | 164,463,560 | MDU6SXNzdWUxNjQ0NjM1NjA= | 1,007 | Distribute sources instead of requiring Cython to be installed | {
"login": "thedrow",
"id": 48936,
"node_id": "MDQ6VXNlcjQ4OTM2",
"avatar_url": "https://avatars.githubusercontent.com/u/48936?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/thedrow",
"html_url": "https://github.com/thedrow",
"followers_url": "https://api.github.com/users/thedrow/followers",
"following_url": "https://api.github.com/users/thedrow/following{/other_user}",
"gists_url": "https://api.github.com/users/thedrow/gists{/gist_id}",
"starred_url": "https://api.github.com/users/thedrow/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/thedrow/subscriptions",
"organizations_url": "https://api.github.com/users/thedrow/orgs",
"repos_url": "https://api.github.com/users/thedrow/repos",
"events_url": "https://api.github.com/users/thedrow/events{/privacy}",
"received_events_url": "https://api.github.com/users/thedrow/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2016-07-08T05:50:00 | 2016-07-15T03:34:45 | 2016-07-15T03:34:45 | NONE | null | There's no reason to require Cython to be installed. We can just distribute the sources of the generated Cython code.
That will be easier for the users and you'll be able to distribute wheels that way.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1007/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1007/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1006 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1006/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1006/comments | https://api.github.com/repos/coleifer/peewee/issues/1006/events | https://github.com/coleifer/peewee/issues/1006 | 164,012,334 | MDU6SXNzdWUxNjQwMTIzMzQ= | 1,006 | peewee create index Error | {
"login": "rfyiamcool",
"id": 3785409,
"node_id": "MDQ6VXNlcjM3ODU0MDk=",
"avatar_url": "https://avatars.githubusercontent.com/u/3785409?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/rfyiamcool",
"html_url": "https://github.com/rfyiamcool",
"followers_url": "https://api.github.com/users/rfyiamcool/followers",
"following_url": "https://api.github.com/users/rfyiamcool/following{/other_user}",
"gists_url": "https://api.github.com/users/rfyiamcool/gists{/gist_id}",
"starred_url": "https://api.github.com/users/rfyiamcool/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/rfyiamcool/subscriptions",
"organizations_url": "https://api.github.com/users/rfyiamcool/orgs",
"repos_url": "https://api.github.com/users/rfyiamcool/repos",
"events_url": "https://api.github.com/users/rfyiamcool/events{/privacy}",
"received_events_url": "https://api.github.com/users/rfyiamcool/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"You need a trailing comma after (('article_id', 'content_md5'), False) -- otherwise, since it's the only item in the outer-most parentheses, Python treats it as a normal expression rather than a tuple.\n"
] | 2016-07-06T07:07:17 | 2016-07-06T14:34:37 | 2016-07-06T14:34:37 | NONE | null | I want to create table with index, But raise error. Mysql peewee version = 2.8.1
```
class ArticleContent(Model):
article_id = IntegerField()
content = BlobField()
content_md5 = CharField(null=True,default=''")
class Meta:
database = db
db_table= 'mirro_article_content'
indexes = (
(('article_id','content_md5'), False)
)
```
Error log:
```
Traceback (most recent call last):
File "core/models.py", line 138, in <module>
init_table_data()
File "core/models.py", line 133, in init_table_data
ArticleContent.create_table()
File "/Library/Python/2.7/site-packages/peewee.py", line 4562, in create_table
cls._create_indexes()
File "/Library/Python/2.7/site-packages/peewee.py", line 4586, in _create_indexes
db.create_index(cls, fields, unique)
File "/Library/Python/2.7/site-packages/peewee.py", line 3549, in create_index
'or tuple: "%s"' % fields)
ValueError: Fields passed to "create_index" must be a list or tuple: "article_id"
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1006/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1006/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1005 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1005/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1005/comments | https://api.github.com/repos/coleifer/peewee/issues/1005/events | https://github.com/coleifer/peewee/pull/1005 | 163,770,381 | MDExOlB1bGxSZXF1ZXN0NzYyMTczMzg= | 1,005 | Added PyPy support | {
"login": "thedrow",
"id": 48936,
"node_id": "MDQ6VXNlcjQ4OTM2",
"avatar_url": "https://avatars.githubusercontent.com/u/48936?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/thedrow",
"html_url": "https://github.com/thedrow",
"followers_url": "https://api.github.com/users/thedrow/followers",
"following_url": "https://api.github.com/users/thedrow/following{/other_user}",
"gists_url": "https://api.github.com/users/thedrow/gists{/gist_id}",
"starred_url": "https://api.github.com/users/thedrow/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/thedrow/subscriptions",
"organizations_url": "https://api.github.com/users/thedrow/orgs",
"repos_url": "https://api.github.com/users/thedrow/repos",
"events_url": "https://api.github.com/users/thedrow/events{/privacy}",
"received_events_url": "https://api.github.com/users/thedrow/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"This will require a bit more work.\nOn PyPy we can use psycopg2-cffi.\nLet me clone that branch. The build will pass soon.\n",
"I think pip is being silly here. Lemme check.\n",
"Now it skips the damm Cython generation step. I'll get back to you on that.\n",
"Closing for now, if you plan to re-open would you mind rebasing the existing commits into a single commit?\n",
"I wouldn't. It doesn't work yet though.\n",
"I mean I wouldn't mind rebasing...\n",
"Cool, I guess I should ask: is this something you plan on continuing to hack on until it's all working? If so be happy to reopen and you can rebase when it's closer to being done.\n"
] | 2016-07-05T04:37:05 | 2016-07-15T16:05:55 | 2016-07-14T05:43:46 | NONE | null | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1005/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1005/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/1005",
"html_url": "https://github.com/coleifer/peewee/pull/1005",
"diff_url": "https://github.com/coleifer/peewee/pull/1005.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/1005.patch",
"merged_at": null
} |
|
https://api.github.com/repos/coleifer/peewee/issues/1004 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1004/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1004/comments | https://api.github.com/repos/coleifer/peewee/issues/1004/events | https://github.com/coleifer/peewee/pull/1004 | 163,769,748 | MDExOlB1bGxSZXF1ZXN0NzYyMTY5Mzc= | 1,004 | Added a pip cache to Travis | {
"login": "thedrow",
"id": 48936,
"node_id": "MDQ6VXNlcjQ4OTM2",
"avatar_url": "https://avatars.githubusercontent.com/u/48936?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/thedrow",
"html_url": "https://github.com/thedrow",
"followers_url": "https://api.github.com/users/thedrow/followers",
"following_url": "https://api.github.com/users/thedrow/following{/other_user}",
"gists_url": "https://api.github.com/users/thedrow/gists{/gist_id}",
"starred_url": "https://api.github.com/users/thedrow/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/thedrow/subscriptions",
"organizations_url": "https://api.github.com/users/thedrow/orgs",
"repos_url": "https://api.github.com/users/thedrow/repos",
"events_url": "https://api.github.com/users/thedrow/events{/privacy}",
"received_events_url": "https://api.github.com/users/thedrow/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"What's going on in this PR? I'm not sure I understand the differences here.\n",
"It caches the compilation of the C extensions and also doesn't download pip dependencies.\nThe build as a result should be faster.\n",
"Just looking at the build times it doesn't appear to have made a difference.\n",
"Did a quick skim of the travis cache docs, I'm going to pass on this one.\n"
] | 2016-07-05T04:27:16 | 2016-07-08T13:45:50 | 2016-07-08T13:45:50 | NONE | null | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1004/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1004/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/1004",
"html_url": "https://github.com/coleifer/peewee/pull/1004",
"diff_url": "https://github.com/coleifer/peewee/pull/1004.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/1004.patch",
"merged_at": null
} |
|
https://api.github.com/repos/coleifer/peewee/issues/1003 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1003/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1003/comments | https://api.github.com/repos/coleifer/peewee/issues/1003/events | https://github.com/coleifer/peewee/pull/1003 | 163,553,431 | MDExOlB1bGxSZXF1ZXN0NzYwODQyMjg= | 1,003 | add "is_not", "not_in" django-style filter support | {
"login": "qulc",
"id": 4693764,
"node_id": "MDQ6VXNlcjQ2OTM3NjQ=",
"avatar_url": "https://avatars.githubusercontent.com/u/4693764?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/qulc",
"html_url": "https://github.com/qulc",
"followers_url": "https://api.github.com/users/qulc/followers",
"following_url": "https://api.github.com/users/qulc/following{/other_user}",
"gists_url": "https://api.github.com/users/qulc/gists{/gist_id}",
"starred_url": "https://api.github.com/users/qulc/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/qulc/subscriptions",
"organizations_url": "https://api.github.com/users/qulc/orgs",
"repos_url": "https://api.github.com/users/qulc/repos",
"events_url": "https://api.github.com/users/qulc/events{/privacy}",
"received_events_url": "https://api.github.com/users/qulc/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"This is a nice PR, very clean, but the Django-style querying is deprecated and I do not plan on adding new functionality as it will be removed soon in the next major version...which hopefully isn't too far away!\n"
] | 2016-07-03T08:52:15 | 2016-07-07T22:14:07 | 2016-07-07T22:14:07 | NONE | null | peewee filter not support `isnull`
https://docs.djangoproject.com/en/1.9/ref/models/querysets/#isnull
so i want add 'is_not' mapping to `OP.NOT_IN`
``` python
Blog.filter(user__username__not_in=['u1', 'u2'], pub_date__is_not=None)
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1003/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1003/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/1003",
"html_url": "https://github.com/coleifer/peewee/pull/1003",
"diff_url": "https://github.com/coleifer/peewee/pull/1003.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/1003.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/1002 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1002/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1002/comments | https://api.github.com/repos/coleifer/peewee/issues/1002/events | https://github.com/coleifer/peewee/issues/1002 | 163,028,958 | MDU6SXNzdWUxNjMwMjg5NTg= | 1,002 | Unique Constraint not being applied after schema migration | {
"login": "beerdedfellow",
"id": 13444979,
"node_id": "MDQ6VXNlcjEzNDQ0OTc5",
"avatar_url": "https://avatars.githubusercontent.com/u/13444979?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/beerdedfellow",
"html_url": "https://github.com/beerdedfellow",
"followers_url": "https://api.github.com/users/beerdedfellow/followers",
"following_url": "https://api.github.com/users/beerdedfellow/following{/other_user}",
"gists_url": "https://api.github.com/users/beerdedfellow/gists{/gist_id}",
"starred_url": "https://api.github.com/users/beerdedfellow/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/beerdedfellow/subscriptions",
"organizations_url": "https://api.github.com/users/beerdedfellow/orgs",
"repos_url": "https://api.github.com/users/beerdedfellow/repos",
"events_url": "https://api.github.com/users/beerdedfellow/events{/privacy}",
"received_events_url": "https://api.github.com/users/beerdedfellow/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I'm not able to replicate this locally. Here's the code I'm using:\n\n``` python\nimport os\nfrom peewee import *\n\nif os.path.exists('/tmp/x.db'):\n os.unlink('/tmp/x.db')\n\ndb = SqliteDatabase('/tmp/x.db')\n\nclass Ticket(Model):\n number = CharField(unique=True)\n modified = DateTimeField()\n subject = CharField()\n queue = CharField()\n assignee = CharField(null=True)\n status = CharField()\n ismodified = BooleanField(default=False)\n newtime = DateTimeField(null=True)\n #account_name = CharField(default='')\n #account_number = CharField(default='')\n class Meta:\n database = db\n\nTicket.create_table()\n\ndef main():\n from playhouse.migrate import SqliteMigrator, migrate\n migrator = SqliteMigrator(db)\n account_name_field = CharField(default='')\n account_number_field = CharField(default='')\n with db.transaction():\n migrate(\n migrator.add_column('Ticket', 'account_name', account_name_field),\n migrator.add_column('Ticket', 'account_number', account_number_field),\n )\n\nif __name__ == '__main__':\n main()\n```\n\nIf I just import the module, then the DB is created and has the following schema:\n\n``` sql\n-- ran .fullschema --indent in the sqlite console\nCREATE TABLE \"ticket\"(\n \"id\" INTEGER NOT NULL PRIMARY KEY,\n \"number\" VARCHAR(255) NOT NULL,\n \"modified\" DATETIME NOT NULL,\n \"subject\" VARCHAR(255) NOT NULL,\n \"queue\" VARCHAR(255) NOT NULL,\n \"assignee\" VARCHAR(255),\n \"status\" VARCHAR(255) NOT NULL,\n \"ismodified\" INTEGER NOT NULL,\n \"newtime\" DATETIME\n);\nCREATE UNIQUE INDEX \"ticket_number\" ON \"ticket\"(\"number\");\n```\n\nAfter running the migration, I have the following schema:\n\n``` sql\nCREATE TABLE \"ticket\"(\n \"id\" INTEGER NOT NULL PRIMARY KEY,\n \"number\" VARCHAR(255) NOT NULL,\n \"modified\" DATETIME NOT NULL,\n \"subject\" VARCHAR(255) NOT NULL,\n \"queue\" VARCHAR(255) NOT NULL,\n \"assignee\" VARCHAR(255),\n \"status\" VARCHAR(255) NOT NULL,\n \"ismodified\" INTEGER NOT NULL,\n \"newtime\" DATETIME,\n \"account_name\" VARCHAR(255) NOT NULL,\n \"account_number\" VARCHAR(255) NOT NULL\n);\nCREATE UNIQUE INDEX \"ticket_number\" ON \"ticket\"(\"number\");\n```\n\nBased on this quick test it seems to be working correctly. Using peewee@49eeec7c14be38f0ba21b428e94f716c45009230 with Python 2.7.12 and SQLite 3.14.\n",
"Can you provide any additional info, or try my script out on your own machine?\n",
"Please re-open if there's something I've missed or if the above code that I shared reproduces the issue on your computer.\n"
] | 2016-06-29T21:18:22 | 2016-07-14T19:47:13 | 2016-07-14T19:47:13 | NONE | null | Hello,
I am building a ticket tracking application using peewee to interact with sqlite. I am defining my model as follows
``` python
class Ticket(BaseModel):
number = CharField(unique=True)
modified = DateTimeField()
subject = CharField()
queue = CharField()
assignee = CharField(null=True)
status = CharField()
ismodified = BooleanField(default=False)
newtime = DateTimeField(null=True)
account_name = CharField(default='')
account_number = CharField(default='')
```
I am using `SqliteMigrator` to add rows to the schema for newer versions, like so:
``` python
if schema_version < 2:
migrator = SqliteMigrator(sqlite_db)
account_name_field = CharField(default='')
account_number_field = CharField(default='')
with sqlite_db.transaction():
migrate(
migrator.add_column('Ticket', 'account_name', account_name_field),
migrator.add_column('Ticket', 'account_number', account_number_field)
)
query = Config.update(config_value=2).where(Config.config_key == 'schema_version')
query.execute()
```
If the migration gets executed, the unique constraint for the `Ticket.number` field no longer applies. I also noticed that it no longer creates a primary key as well (which may be the cause of the unique constraint failure):
```
sqlite> select id,number from ticket;
5|160606-11739
6|160610-11206
9|160614-06385
11|160617-08108
15|160620-10616
|160516-13419
|160516-13419
|160620-10616
```
I've re-initialized a clean database and performed the schema migration again, but unfortunately I am unable to replicate the issue at this time :-(. Are there any conditions where peewee would not create a primary key? Thanks for any help and insight you're able to provide!
NOTE: to avoid this in the future I realize that using the ticket number as the primary key is probably ideal (they will always be unique). However, is there an easy way to add the `primary_key = True` initialization argument to an existing field? I'm guessing I may need to rename it, initialize a new one, and then migrate the records to it. If so, do you have any examples of how I can achieve this? (search is failing me)
Thanks again for your help and a great product!
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1002/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1002/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1001 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1001/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1001/comments | https://api.github.com/repos/coleifer/peewee/issues/1001/events | https://github.com/coleifer/peewee/pull/1001 | 162,664,376 | MDExOlB1bGxSZXF1ZXN0NzU0NjE3MTI= | 1,001 | Set composite PK | {
"login": "kepkin",
"id": 2153196,
"node_id": "MDQ6VXNlcjIxNTMxOTY=",
"avatar_url": "https://avatars.githubusercontent.com/u/2153196?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/kepkin",
"html_url": "https://github.com/kepkin",
"followers_url": "https://api.github.com/users/kepkin/followers",
"following_url": "https://api.github.com/users/kepkin/following{/other_user}",
"gists_url": "https://api.github.com/users/kepkin/gists{/gist_id}",
"starred_url": "https://api.github.com/users/kepkin/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/kepkin/subscriptions",
"organizations_url": "https://api.github.com/users/kepkin/orgs",
"repos_url": "https://api.github.com/users/kepkin/repos",
"events_url": "https://api.github.com/users/kepkin/events{/privacy}",
"received_events_url": "https://api.github.com/users/kepkin/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"What is the use-case for this?\n"
] | 2016-06-28T11:34:48 | 2018-01-31T12:42:41 | 2018-01-31T12:42:41 | NONE | null | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1001/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1001/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/1001",
"html_url": "https://github.com/coleifer/peewee/pull/1001",
"diff_url": "https://github.com/coleifer/peewee/pull/1001.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/1001.patch",
"merged_at": null
} |
|
https://api.github.com/repos/coleifer/peewee/issues/1000 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1000/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1000/comments | https://api.github.com/repos/coleifer/peewee/issues/1000/events | https://github.com/coleifer/peewee/issues/1000 | 162,618,780 | MDU6SXNzdWUxNjI2MTg3ODA= | 1,000 | a error log | {
"login": "rfyiamcool",
"id": 3785409,
"node_id": "MDQ6VXNlcjM3ODU0MDk=",
"avatar_url": "https://avatars.githubusercontent.com/u/3785409?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/rfyiamcool",
"html_url": "https://github.com/rfyiamcool",
"followers_url": "https://api.github.com/users/rfyiamcool/followers",
"following_url": "https://api.github.com/users/rfyiamcool/following{/other_user}",
"gists_url": "https://api.github.com/users/rfyiamcool/gists{/gist_id}",
"starred_url": "https://api.github.com/users/rfyiamcool/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/rfyiamcool/subscriptions",
"organizations_url": "https://api.github.com/users/rfyiamcool/orgs",
"repos_url": "https://api.github.com/users/rfyiamcool/repos",
"events_url": "https://api.github.com/users/rfyiamcool/events{/privacy}",
"received_events_url": "https://api.github.com/users/rfyiamcool/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Not enough info.\n"
] | 2016-06-28T07:20:54 | 2016-06-28T13:27:48 | 2016-06-28T13:27:48 | NONE | null | /Library/Python/2.7/site-packages/peewee.py:3454: Warning: Invalid utf8mb4 character string: '9C0300'
cursor.execute(sql, params or ())
mysql5.7
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1000/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1000/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/999 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/999/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/999/comments | https://api.github.com/repos/coleifer/peewee/issues/999/events | https://github.com/coleifer/peewee/issues/999 | 162,580,850 | MDU6SXNzdWUxNjI1ODA4NTA= | 999 | Support cockroachdb? | {
"login": "jet10000",
"id": 2258120,
"node_id": "MDQ6VXNlcjIyNTgxMjA=",
"avatar_url": "https://avatars.githubusercontent.com/u/2258120?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/jet10000",
"html_url": "https://github.com/jet10000",
"followers_url": "https://api.github.com/users/jet10000/followers",
"following_url": "https://api.github.com/users/jet10000/following{/other_user}",
"gists_url": "https://api.github.com/users/jet10000/gists{/gist_id}",
"starred_url": "https://api.github.com/users/jet10000/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/jet10000/subscriptions",
"organizations_url": "https://api.github.com/users/jet10000/orgs",
"repos_url": "https://api.github.com/users/jet10000/repos",
"events_url": "https://api.github.com/users/jet10000/events{/privacy}",
"received_events_url": "https://api.github.com/users/jet10000/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"[From one of their devs](https://github.com/cockroachdb/cockroachdb-python/issues/21#issuecomment-229755195),\n\n> Cockroach actually supports the Postgres wire protocol, so the Postgres driver builtin to Peewee should work (we support psycopg2 without issue). That said, we have found that a few drivers use some Postgres-specific SQL extensions (for instance, use of pg_catalog instead of the standard information_schema), so current levels of support for them vary.\n\nThis means that peewee, configured with a modified version of the `PostgresqlDatabase`, should be able to work with Cockroach -- at least in some sense.\n\nGoing to close this out as I do not plan on implementing support myself.\n\nThose interested can also follow along here:\n\nhttps://github.com/cockroachdb/cockroachdb-python/issues/21\n"
] | 2016-06-28T01:02:22 | 2016-07-14T09:02:14 | 2016-07-14T09:02:14 | NONE | null | https://www.cockroachlabs.com/blog/building-application-cockroachdb-sqlalchemy-2/
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/999/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/999/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/998 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/998/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/998/comments | https://api.github.com/repos/coleifer/peewee/issues/998/events | https://github.com/coleifer/peewee/issues/998 | 162,422,837 | MDU6SXNzdWUxNjI0MjI4Mzc= | 998 | db.create_table does not create indexes | {
"login": "sin5th",
"id": 7314785,
"node_id": "MDQ6VXNlcjczMTQ3ODU=",
"avatar_url": "https://avatars.githubusercontent.com/u/7314785?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/sin5th",
"html_url": "https://github.com/sin5th",
"followers_url": "https://api.github.com/users/sin5th/followers",
"following_url": "https://api.github.com/users/sin5th/following{/other_user}",
"gists_url": "https://api.github.com/users/sin5th/gists{/gist_id}",
"starred_url": "https://api.github.com/users/sin5th/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/sin5th/subscriptions",
"organizations_url": "https://api.github.com/users/sin5th/orgs",
"repos_url": "https://api.github.com/users/sin5th/repos",
"events_url": "https://api.github.com/users/sin5th/events{/privacy}",
"received_events_url": "https://api.github.com/users/sin5th/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Hey @sin5 - can you please take the 5 extra seconds and learn how to format your code? Did you even look at your issue after creating it?\n",
"Please read the documentation on submitting bugs: http://docs.peewee-orm.com/en/latest/peewee/contributing.html#bugs\n\nHere's a link to GitHub's documentation:\n\nhttps://help.github.com/articles/getting-started-with-writing-and-formatting-on-github/\n",
"Specifically, though, and this is a bad API -- I will be addressing it in a subsequent release -- calling `database.create_table` will _only_ create the table. Calling `Model.create_table()`, on the other hand, will create the table and the indexes.\n\nHowever,\n\nTo create multiple tables, and their indexes, with the dependency graph resolved to ensure the tables are created in the proper order, use the `Database.create_tables()` method.\n\nIn fact, I pretty much just recommend that people **always** use `database.create_tables([AModel, AnotherModel])`.\n",
"Also read the big fat warning in the docs:\n\nhttp://docs.peewee-orm.com/en/latest/peewee/api.html#Database.create_table\n",
"```\n sorry for my code format. and thanks for your answer:)\n```\n\n—You are receiving this because you were mentioned.Reply to this email directly, view it on GitHub, or mute the thread.\n",
"No probs!\n"
] | 2016-06-27T10:41:40 | 2016-06-27T22:46:44 | 2016-06-27T19:05:46 | NONE | null | class Client(peewee.Model):
"""
UNIQUE KEY `rip_rport_stime` (`ip_type`, `remote_ip`, `remote_port`, `start_time`),
KEY `app_stream_stime` (`app`, `stream`, `start_time`),
KEY `app_stime` (`app`, `start_time`)
"""
ip_type = UnsignedSmallIntegerField()
app = UnsignedIntegerField()
stream = UnsignedBigIntegerField()
url = UnsignedIntegerField()
start_time = UnsignedIntegerField()
end_time = UnsignedIntegerField()
remote_ip = UnsignedIntegerField()
remote_port = UnsignedSmallIntegerField()
local_ip = UnsignedIntegerField()
local_port = UnsignedSmallIntegerField()
```
class Meta:
database = db
indexes = [
(('ip_type', 'remote_ip', 'remote_port', 'start_time'), True),
(('app', 'stream', 'start_time'), False),
(('app', 'start_time'), False),
]
```
Client.create_table(fail_silently=True) # this create the right indexes
db.create_table(Client, safe=True) # but this can't
is it a bug? or i missed the doc?
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/998/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/998/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/997 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/997/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/997/comments | https://api.github.com/repos/coleifer/peewee/issues/997/events | https://github.com/coleifer/peewee/issues/997 | 161,825,989 | MDU6SXNzdWUxNjE4MjU5ODk= | 997 | get tables commit transaction | {
"login": "kaito-kidd",
"id": 9117028,
"node_id": "MDQ6VXNlcjkxMTcwMjg=",
"avatar_url": "https://avatars.githubusercontent.com/u/9117028?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/kaito-kidd",
"html_url": "https://github.com/kaito-kidd",
"followers_url": "https://api.github.com/users/kaito-kidd/followers",
"following_url": "https://api.github.com/users/kaito-kidd/following{/other_user}",
"gists_url": "https://api.github.com/users/kaito-kidd/gists{/gist_id}",
"starred_url": "https://api.github.com/users/kaito-kidd/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/kaito-kidd/subscriptions",
"organizations_url": "https://api.github.com/users/kaito-kidd/orgs",
"repos_url": "https://api.github.com/users/kaito-kidd/repos",
"events_url": "https://api.github.com/users/kaito-kidd/events{/privacy}",
"received_events_url": "https://api.github.com/users/kaito-kidd/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"How does this issue manifest itself?\n",
"For example, I have a log table, and is split by date table, every time you insert new data, checks the table exists, then call `create_table` methods, parameters `fail_silently = True`, it does not exist is automatically created to perform the `execute_sql` method.\n\nthe emergence of a large number of `show tables; commit;` \n`show tables` operation is not whether it is necessary to `commit`?\n",
"See #727, #806, #814 for why Peewee tends to issue commits with MySQL. In general I've found that users of the database are confused when it appears results are \"cached\" or they're not seeing changes. This happens when they have a long running process, for instance, and are issues reads with no commits.\n\nIf you would like to avoid the extra `COMMIT` statements, I'd suggest wrapping the code in a transaction using:\n\n``` python\nwith db.atomic():\n # your code here.\n```\n\nAlso, I don't know anything about your use case but it seems incredibly inefficient to be checking for the table existence before every insert statement when the data being inserted is log records. Just my .02 but that seems problematic.\n"
] | 2016-06-23T02:15:34 | 2016-06-24T16:57:42 | 2016-06-24T16:57:42 | NONE | null | ```
def get_tables(self, schema=None):
return [row for row, in self.execute_sql('SHOW TABLES')]
```
execute `execute_sql` method auto commit transaction.
but is it necessary to do so?
If often call `create_table` method will lead to too many invalid commit.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/997/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/997/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/996 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/996/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/996/comments | https://api.github.com/repos/coleifer/peewee/issues/996/events | https://github.com/coleifer/peewee/issues/996 | 161,440,906 | MDU6SXNzdWUxNjE0NDA5MDY= | 996 | Peewee throws error on cascade deletion if imports aren't present | {
"login": "Coderdreams",
"id": 4738090,
"node_id": "MDQ6VXNlcjQ3MzgwOTA=",
"avatar_url": "https://avatars.githubusercontent.com/u/4738090?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/Coderdreams",
"html_url": "https://github.com/Coderdreams",
"followers_url": "https://api.github.com/users/Coderdreams/followers",
"following_url": "https://api.github.com/users/Coderdreams/following{/other_user}",
"gists_url": "https://api.github.com/users/Coderdreams/gists{/gist_id}",
"starred_url": "https://api.github.com/users/Coderdreams/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/Coderdreams/subscriptions",
"organizations_url": "https://api.github.com/users/Coderdreams/orgs",
"repos_url": "https://api.github.com/users/Coderdreams/repos",
"events_url": "https://api.github.com/users/Coderdreams/events{/privacy}",
"received_events_url": "https://api.github.com/users/Coderdreams/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Please read the documentation on submitting bugs: http://docs.peewee-orm.com/en/latest/peewee/contributing.html#bugs\n\nSpecifically, take the extra 5 seconds and please format your code:\n\nhttps://help.github.com/articles/getting-started-with-writing-and-formatting-on-github/\n"
] | 2016-06-21T13:45:39 | 2016-06-24T17:00:13 | 2016-06-24T17:00:13 | NONE | null | I have something similar to this:
class Test(BaseModel):
name = CharField()
class Test2(BaseModel):
test = ForeignKeyField(Test)
class Test3(BaseModel):
test2 = ForeignKeyField(Test2)
I had a script that said:
from database.model.test import Test
test = Test.get(Test.name == testName)
test.delete_instance(recursive=True, delete_nullable=True)
And it threw something along this:
_mysql_exceptions.IntegrityError: (1451, 'Cannot delete or update a parent row: a foreign key constraint fails (`mydatabase`.`test3`, CONSTRAINT `test3_ibfk_1` FOREIGN KEY (`test2_id`) REFERENCES `test2` (`id`))')
And it fixed itself only when I added the imports for the dependent models like this:
from database.model.test import Test
from database.model.test2 import Test2
from database.model.test3 import Test3
test = Test.get(Test.name == testName)
test.delete_instance(recursive=True, delete_nullable=True)
This poses the problem that some linters are going to complain about unused imports, I don't know if something can be done to improve this though. Also, I found out what the problem was only by chance, maybe capturing these exceptions and showing some hint to the users that the imports are needed could help someone else.
Thanks!
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/996/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/996/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/995 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/995/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/995/comments | https://api.github.com/repos/coleifer/peewee/issues/995/events | https://github.com/coleifer/peewee/pull/995 | 161,425,864 | MDExOlB1bGxSZXF1ZXN0NzQ2MDM4Mzk= | 995 | Fix truncate_date for PostgreSQL | {
"login": "Zverik",
"id": 766031,
"node_id": "MDQ6VXNlcjc2NjAzMQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/766031?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/Zverik",
"html_url": "https://github.com/Zverik",
"followers_url": "https://api.github.com/users/Zverik/followers",
"following_url": "https://api.github.com/users/Zverik/following{/other_user}",
"gists_url": "https://api.github.com/users/Zverik/gists{/gist_id}",
"starred_url": "https://api.github.com/users/Zverik/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/Zverik/subscriptions",
"organizations_url": "https://api.github.com/users/Zverik/orgs",
"repos_url": "https://api.github.com/users/Zverik/repos",
"events_url": "https://api.github.com/users/Zverik/events{/privacy}",
"received_events_url": "https://api.github.com/users/Zverik/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Cool, thanks!\n"
] | 2016-06-21T12:38:23 | 2016-06-25T22:47:42 | 2016-06-25T22:47:37 | CONTRIBUTOR | null | The following script doesn't work:
``` python
#!/usr/bin/env python
import peewee, datetime
database = peewee.PostgresqlDatabase('mmwatch', host='localhost')
class Number(peewee.Model):
date = peewee.DateTimeField(default=datetime.datetime.now)
class Meta:
database = database
database.connect()
database.create_tables([Number], safe=True)
number = Number()
number.save()
q = Number.select(database.truncate_date('day', Number.date))
for row in q:
print row.date
```
It fails with the following error:
```
Traceback (most recent call last):
File "./date_trunc_pgsql_fail.py", line 19, in <module>
for row in q:
File "/Users/ilyazverev/Progr/git/mmwatch/mmwatch/venv/lib/python2.7/site-packages/peewee.py", line 2967, in __iter__
return iter(self.execute())
File "/Users/ilyazverev/Progr/git/mmwatch/mmwatch/venv/lib/python2.7/site-packages/peewee.py", line 2960, in execute
self._qr = ResultWrapper(model_class, self._execute(), query_meta)
File "/Users/ilyazverev/Progr/git/mmwatch/mmwatch/venv/lib/python2.7/site-packages/peewee.py", line 2656, in _execute
return self.database.execute_sql(sql, params, self.require_commit)
File "/Users/ilyazverev/Progr/git/mmwatch/mmwatch/venv/lib/python2.7/site-packages/peewee.py", line 3492, in execute_sql
self.commit()
File "/Users/ilyazverev/Progr/git/mmwatch/mmwatch/venv/lib/python2.7/site-packages/peewee.py", line 3316, in __exit__
reraise(new_type, new_type(*exc_args), traceback)
File "/Users/ilyazverev/Progr/git/mmwatch/mmwatch/venv/lib/python2.7/site-packages/peewee.py", line 3485, in execute_sql
cursor.execute(sql, params or ())
peewee.ProgrammingError: column "day" does not exist
LINE 1: SELECT DATE_TRUNC(day, "t1"."date") FROM "number" AS t1
^
```
The reason is that `'day'` is passed to the query builder as-is, not escaped as a string. This pull request fixes that.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/995/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/995/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/995",
"html_url": "https://github.com/coleifer/peewee/pull/995",
"diff_url": "https://github.com/coleifer/peewee/pull/995.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/995.patch",
"merged_at": "2016-06-25T22:47:37"
} |
https://api.github.com/repos/coleifer/peewee/issues/994 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/994/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/994/comments | https://api.github.com/repos/coleifer/peewee/issues/994/events | https://github.com/coleifer/peewee/pull/994 | 160,911,989 | MDExOlB1bGxSZXF1ZXN0NzQyNTkyODM= | 994 | impl for bring select.get() into parity with model.get() | {
"login": "keredson",
"id": 2049665,
"node_id": "MDQ6VXNlcjIwNDk2NjU=",
"avatar_url": "https://avatars.githubusercontent.com/u/2049665?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/keredson",
"html_url": "https://github.com/keredson",
"followers_url": "https://api.github.com/users/keredson/followers",
"following_url": "https://api.github.com/users/keredson/following{/other_user}",
"gists_url": "https://api.github.com/users/keredson/gists{/gist_id}",
"starred_url": "https://api.github.com/users/keredson/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/keredson/subscriptions",
"organizations_url": "https://api.github.com/users/keredson/orgs",
"repos_url": "https://api.github.com/users/keredson/repos",
"events_url": "https://api.github.com/users/keredson/events{/privacy}",
"received_events_url": "https://api.github.com/users/keredson/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2016-06-17T15:17:10 | 2016-06-17T15:20:17 | 2016-06-17T15:20:17 | CONTRIBUTOR | null | implements https://github.com/keredson/peewee/issues/3 / https://github.com/coleifer/peewee/issues/993
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/994/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/994/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/994",
"html_url": "https://github.com/coleifer/peewee/pull/994",
"diff_url": "https://github.com/coleifer/peewee/pull/994.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/994.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/993 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/993/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/993/comments | https://api.github.com/repos/coleifer/peewee/issues/993/events | https://github.com/coleifer/peewee/issues/993 | 160,911,945 | MDU6SXNzdWUxNjA5MTE5NDU= | 993 | bring select.get() into parity with model.get() | {
"login": "keredson",
"id": 2049665,
"node_id": "MDQ6VXNlcjIwNDk2NjU=",
"avatar_url": "https://avatars.githubusercontent.com/u/2049665?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/keredson",
"html_url": "https://github.com/keredson",
"followers_url": "https://api.github.com/users/keredson/followers",
"following_url": "https://api.github.com/users/keredson/following{/other_user}",
"gists_url": "https://api.github.com/users/keredson/gists{/gist_id}",
"starred_url": "https://api.github.com/users/keredson/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/keredson/subscriptions",
"organizations_url": "https://api.github.com/users/keredson/orgs",
"repos_url": "https://api.github.com/users/keredson/repos",
"events_url": "https://api.github.com/users/keredson/events{/privacy}",
"received_events_url": "https://api.github.com/users/keredson/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I would appreciate it if you respected my request that you not post things on my project.\n\nYou have your own fork, please use it.\n",
"i'm sorry, but you don't own github. i'm allowed to discuss this project with other users/devs (just like anyone else). you don't have to be involved in that discussion.\n",
"Derek, you seem to misunderstand free speech or your rights on GitHub.\n\nWhile I might not agree with Charles, I definitely think it is his right to\nask you not to post here.\nOn Jun 17, 2016 7:41 PM, \"Derek Anderson\" [email protected] wrote:\n\n> that is patently false. you've definitely deleted comments before issues\n> were closed. and you've not deleted other's comments after issues were\n> closed where you've deleted mine. (even when my comment was just \"i agree\n> w/ person XYZ\"). i don't even know how many, as GH doesn't notify me when\n> it happens, nor do i have any record of them (other than me luckily having\n> left the browser open for that one screenshot)\n> \n> besides, even the premise for your deletion is invalid. where is there a\n> rule of \"you can't comment after an issue is closed\"? where else would one\n> ever say \"IMO this is still and issue and should be re-opened, because\n> reason XYZ\"?\n> \n> refrain from commenting, creating tickets or posting here.\n> \n> sorry, but no. if i have something to say that's respectful and on topic,\n> i intend to reserve the right to say it. freedom of speech and whatnot.\n> \n> —\n> You are receiving this because you are subscribed to this thread.\n> Reply to this email directly, view it on GitHub\n> https://github.com/coleifer/peewee/issues/993#issuecomment-226819371,\n> or mute the thread\n> https://github.com/notifications/unsubscribe/AAEXLPEfY81fTY9jkYow2gQrxNrkJD2vks5qMs4rgaJpZM4I4daH\n> .\n",
"What am I supposed to think, @keredson . You are a toxic presence on my project, and I don't want you to keep harassing me.\n",
"Why can't you respect that, one person to another?\n"
] | 2016-06-17T15:16:57 | 2016-06-18T01:05:09 | 2016-06-17T15:20:24 | CONTRIBUTOR | null | currently this is allowed:
``` python
u = User.get(User.id==1)
```
and this is allowed
``` python
u = User.select().where(User.id==1).get()
```
but this is not:
``` python
u = User.select().get(User.id==1)
```
i suggest we impl the last option. (ie make it identical to the middle option just like the first option is)
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/993/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/993/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/992 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/992/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/992/comments | https://api.github.com/repos/coleifer/peewee/issues/992/events | https://github.com/coleifer/peewee/issues/992 | 160,880,273 | MDU6SXNzdWUxNjA4ODAyNzM= | 992 | djpeewee has no support for Field.db_column | {
"login": "nschagen",
"id": 439159,
"node_id": "MDQ6VXNlcjQzOTE1OQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/439159?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/nschagen",
"html_url": "https://github.com/nschagen",
"followers_url": "https://api.github.com/users/nschagen/followers",
"following_url": "https://api.github.com/users/nschagen/following{/other_user}",
"gists_url": "https://api.github.com/users/nschagen/gists{/gist_id}",
"starred_url": "https://api.github.com/users/nschagen/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/nschagen/subscriptions",
"organizations_url": "https://api.github.com/users/nschagen/orgs",
"repos_url": "https://api.github.com/users/nschagen/repos",
"events_url": "https://api.github.com/users/nschagen/events{/privacy}",
"received_events_url": "https://api.github.com/users/nschagen/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2016-06-17T12:46:19 | 2016-06-23T03:23:43 | 2016-06-23T03:23:43 | NONE | null | Hi,
I would like to use PeeWee in an existing django project to run analytics queries. I tried it in the Django shell, but the queries failed because my model contained a field whose name did not match the actual database column name. This is because I am using `Field.db_column` for many fields. I'm using 2.8.1.
It would be great if the djpeewee `translate()` function would support models with custom `db_column` values. Such behaviour could easily be enabled using an option passed to `translate()` to preserve backwards compatibility.
Thank you.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/992/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/992/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/991 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/991/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/991/comments | https://api.github.com/repos/coleifer/peewee/issues/991/events | https://github.com/coleifer/peewee/pull/991 | 160,749,320 | MDExOlB1bGxSZXF1ZXN0NzQxNDM2MDE= | 991 | Convert readthedocs links for their .org -> .io migration for hosted projects | {
"login": "adamchainz",
"id": 857609,
"node_id": "MDQ6VXNlcjg1NzYwOQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/857609?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/adamchainz",
"html_url": "https://github.com/adamchainz",
"followers_url": "https://api.github.com/users/adamchainz/followers",
"following_url": "https://api.github.com/users/adamchainz/following{/other_user}",
"gists_url": "https://api.github.com/users/adamchainz/gists{/gist_id}",
"starred_url": "https://api.github.com/users/adamchainz/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/adamchainz/subscriptions",
"organizations_url": "https://api.github.com/users/adamchainz/orgs",
"repos_url": "https://api.github.com/users/adamchainz/repos",
"events_url": "https://api.github.com/users/adamchainz/events{/privacy}",
"received_events_url": "https://api.github.com/users/adamchainz/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2016-06-16T20:08:28 | 2016-06-16T21:27:07 | 2016-06-16T21:27:07 | CONTRIBUTOR | null | As per [their blog post of the 27th April](https://blog.readthedocs.com/securing-subdomains/) ‘Securing subdomains’:
> Starting today, Read the Docs will start hosting projects from subdomains on the domain readthedocs.io, instead of on readthedocs.org. This change addresses some security concerns around site cookies while hosting user generated data on the same domain as our dashboard.
Test Plan: Manually visited all the links I’ve modified.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/991/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/991/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/991",
"html_url": "https://github.com/coleifer/peewee/pull/991",
"diff_url": "https://github.com/coleifer/peewee/pull/991.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/991.patch",
"merged_at": "2016-06-16T21:27:07"
} |
https://api.github.com/repos/coleifer/peewee/issues/990 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/990/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/990/comments | https://api.github.com/repos/coleifer/peewee/issues/990/events | https://github.com/coleifer/peewee/issues/990 | 160,745,063 | MDU6SXNzdWUxNjA3NDUwNjM= | 990 | Zip argument #2 must support iteration for pk_row | {
"login": "leerobert",
"id": 6231418,
"node_id": "MDQ6VXNlcjYyMzE0MTg=",
"avatar_url": "https://avatars.githubusercontent.com/u/6231418?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/leerobert",
"html_url": "https://github.com/leerobert",
"followers_url": "https://api.github.com/users/leerobert/followers",
"following_url": "https://api.github.com/users/leerobert/following{/other_user}",
"gists_url": "https://api.github.com/users/leerobert/gists{/gist_id}",
"starred_url": "https://api.github.com/users/leerobert/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/leerobert/subscriptions",
"organizations_url": "https://api.github.com/users/leerobert/orgs",
"repos_url": "https://api.github.com/users/leerobert/repos",
"events_url": "https://api.github.com/users/leerobert/events{/privacy}",
"received_events_url": "https://api.github.com/users/leerobert/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"That's very odd. So peewee is expecting to get back the primary key, and since Postgres supports the \"RETURNING\" clause, peewee says \"INSERT INTO my_table (cola, colb, colc) VALUES (vala, valb, valc) RETURNING primary_key\".\n\nFor whatever reason, it appears that the database cursor is not returning anything.\n\nCan you share the SQL that is generated by Peewee when it runs that above insert? You should be able to do:\n\n```\nSOOSItem.insert(**data).sql()\n```\n\nAny other ideas of what might be going on here?\n",
"Closing due to lack of response.\n",
"Please comment here and I'll reopen.\n",
"Just saw this happen when adding a trigger on a table changed the semantics of INSERT statements (inserts were not returning anything then). Dropping the trigger resolved the problem.",
"Aha! Many thanks @uzak !"
] | 2016-06-16T19:50:45 | 2017-02-15T15:39:15 | 2016-07-14T09:06:34 | NONE | null | I cannot figure out this issue for the life of me. On my test database, created primarily by the ORM create_table routines I do not experience this issue. When I deploy the tables to our production database and other users write partitions that listen to one of the ORM databases this issue occurs.
# Models
``` python
class BaseModel(Model):
"""
The BaseModel defines the abstract model bean
that all Models will inherit. It defines the
database where extended beans will connect.
It also contains the common data fields that all
beans will share in common:
model_created_at
The datetime object for when the bean was created
model_updated_at
The datetime object for when the bean was last updated
status
The status of the model bean. Provides functionality for
performing soft delete of inactive instances, rather than
hard deletes of data.
"""
model_created_at = DateTimeField(default=datetime.now)
model_updated_at = DateTimeField(default=None, null=True)
is_active = BooleanField(default=True)
class Meta:
# the database all BaseModel beans will connect
database = soos_db
def save(self, *args, **kwargs):
"""
Overrides the peewee save functionality to allow for
updating of the updated_at datetime field.
"""
self.model_updated_at = datetime.now()
return super(BaseModel, self).save(*args, **kwargs)
def soft_delete(self):
"""
Does a soft delete of all beans by giving a status of
deleted to the instance and changing the is_active
flag to False.
"""
self.is_active = False
return self.save()
def __repr__(self):
"""
Defines the 'toString' functionality for all extended
models. It grabs the class name, field names, and field
values associated to the extended class and displays it
when str or other repr displays are made on the object.
"""
field_values = [ ' {0}:{1}'.format(field, getattr(self, field))
for field in self._meta.fields.keys() ]
return '<' + self.__class__.__name__ + ''.join(field_values) + '>'
class SOOSItem(BaseModel):
"""
The SOOSItem is the base scanned out of stock item
"""
item = ForeignKeyField(Item)
site = ForeignKeyField(Site)
vendor = ForeignKeyField(Vendor, null=True)
manufacturer = ForeignKeyField(Manufacturer, null=True)
retailer = ForeignKeyField(Retailer, null=True)
upc = CharField(max_length=13)
description = CharField()
price = FloatField()
quantity_sold = FloatField()
quantity_sold_weekly = FloatField()
in_inventory = FloatField()
lost_sales = FloatField()
scanned_at = DateTimeField()
```
Here is some example data that I throw in to create the SOOSItem model.
``` python
>>> data = {'item': Item.get(id=2324), 'site': Site.get(id=90369), 'vendor': 92760, 'manufacturer': None, 'upc': '1820096147', 'description': 'BUD LT AZULITAS 24PK CAN', 'price': 0, 'quantity_sold': 0, 'quantity_sold_weekly': 0, 'in_inventory': 0, 'lost_sales': 0.0, 'scanned_at': datetime.now()}
>>> SOOSItem.create(**data)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/worx/oosworx/env/lib/python3.5/site-packages/peewee.py", line 4494, in create
inst.save(force_insert=True)
File "/usr/local/worx/oosworx/oosworx/models.py", line 54, in save
return super(BaseModel, self).save(*args, **kwargs)
File "/usr/local/worx/oosworx/env/lib/python3.5/site-packages/peewee.py", line 4680, in save
pk_from_cursor = self.insert(**field_dict).execute()
File "/usr/local/worx/oosworx/env/lib/python3.5/site-packages/peewee.py", line 3221, in execute
in zip(meta.get_primary_key_fields(), pk_row)]
TypeError: zip argument #2 must support iteration
```
Any thoughts at all what might be causing this issue? I compared both definitions in the production and development databases (postgres) and they match word to word.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/990/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/990/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/989 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/989/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/989/comments | https://api.github.com/repos/coleifer/peewee/issues/989/events | https://github.com/coleifer/peewee/issues/989 | 160,436,407 | MDU6SXNzdWUxNjA0MzY0MDc= | 989 | Index Creation in Postgresql, create_indexes | {
"login": "mlag",
"id": 2061960,
"node_id": "MDQ6VXNlcjIwNjE5NjA=",
"avatar_url": "https://avatars.githubusercontent.com/u/2061960?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/mlag",
"html_url": "https://github.com/mlag",
"followers_url": "https://api.github.com/users/mlag/followers",
"following_url": "https://api.github.com/users/mlag/following{/other_user}",
"gists_url": "https://api.github.com/users/mlag/gists{/gist_id}",
"starred_url": "https://api.github.com/users/mlag/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/mlag/subscriptions",
"organizations_url": "https://api.github.com/users/mlag/orgs",
"repos_url": "https://api.github.com/users/mlag/repos",
"events_url": "https://api.github.com/users/mlag/events{/privacy}",
"received_events_url": "https://api.github.com/users/mlag/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I think the \"first version\" you referred to is missing from the comment. I see your table definition and that calling `db.create_indexes()` creates the indexes, but not the part that may not have been working?\n",
"Sorry, nevermind.\nAfter having unrelatedly restarted postgres, it works.\nWhat I meant was, that calling `create_tables()` only created the table, but not the index for the `name` field. I had to call `create_indexes()` separately.\n",
"Cool, glad to hear it's working correctly! Thanks for the update.\n"
] | 2016-06-15T14:28:47 | 2016-06-15T19:00:39 | 2016-06-15T18:29:05 | NONE | null | The first version doesn't work, i.e. creates the table but fails to create an index in postgresql.
```
db = PostgresqlDatabase()
class TestTable(Model):
class Meta:
database = db
id = PrimaryKeyField()
name = CharField(index=True)
```
whereas the following works: `db.create_indexes(TestTable, ['name'])`
peewee 2.8.1 from pip
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/989/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/989/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/988 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/988/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/988/comments | https://api.github.com/repos/coleifer/peewee/issues/988/events | https://github.com/coleifer/peewee/pull/988 | 160,425,614 | MDExOlB1bGxSZXF1ZXN0NzM5MTM3NjA= | 988 | Add mention in the doc about calling order_by() without argument to remove the ORDER BY clause. | {
"login": "yohanboniface",
"id": 146023,
"node_id": "MDQ6VXNlcjE0NjAyMw==",
"avatar_url": "https://avatars.githubusercontent.com/u/146023?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/yohanboniface",
"html_url": "https://github.com/yohanboniface",
"followers_url": "https://api.github.com/users/yohanboniface/followers",
"following_url": "https://api.github.com/users/yohanboniface/following{/other_user}",
"gists_url": "https://api.github.com/users/yohanboniface/gists{/gist_id}",
"starred_url": "https://api.github.com/users/yohanboniface/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/yohanboniface/subscriptions",
"organizations_url": "https://api.github.com/users/yohanboniface/orgs",
"repos_url": "https://api.github.com/users/yohanboniface/repos",
"events_url": "https://api.github.com/users/yohanboniface/events{/privacy}",
"received_events_url": "https://api.github.com/users/yohanboniface/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I've committed a fix for this, thanks for bringing it to my attention!\n"
] | 2016-06-15T13:44:14 | 2016-06-17T15:23:37 | 2016-06-17T15:23:36 | CONTRIBUTOR | null | Note: my first attempt was to call `order_by(None)`. Would you mind a PR to allow also this signature?
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/988/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/988/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/988",
"html_url": "https://github.com/coleifer/peewee/pull/988",
"diff_url": "https://github.com/coleifer/peewee/pull/988.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/988.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/987 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/987/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/987/comments | https://api.github.com/repos/coleifer/peewee/issues/987/events | https://github.com/coleifer/peewee/issues/987 | 160,409,214 | MDU6SXNzdWUxNjA0MDkyMTQ= | 987 | Join multiple foreign keys to the same model | {
"login": "rudyryk",
"id": 4500,
"node_id": "MDQ6VXNlcjQ1MDA=",
"avatar_url": "https://avatars.githubusercontent.com/u/4500?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/rudyryk",
"html_url": "https://github.com/rudyryk",
"followers_url": "https://api.github.com/users/rudyryk/followers",
"following_url": "https://api.github.com/users/rudyryk/following{/other_user}",
"gists_url": "https://api.github.com/users/rudyryk/gists{/gist_id}",
"starred_url": "https://api.github.com/users/rudyryk/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/rudyryk/subscriptions",
"organizations_url": "https://api.github.com/users/rudyryk/orgs",
"repos_url": "https://api.github.com/users/rudyryk/repos",
"events_url": "https://api.github.com/users/rudyryk/events{/privacy}",
"received_events_url": "https://api.github.com/users/rudyryk/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Aha!\n\nIt seems like we can use `alias()` to resolve \"conflicts\":\n\n``` python\nuser_a = User.alias()\nuser_b = User.alias()\n\nquery = (Match.select(Match, user_a, user_b)\n .join(user_a, on=Match.user_a)\n .switch(Match)\n .join(user_b, on=Match.user_b)\n .where((Match.user_a == user) | (Match.user_b == user)))\n```\n\nWorked for me, but I'm not sure, whether this is intended usage of `alias()` :)\n",
"Yep, that's what the `alias()` helper is for -- allowing multiple table references in a single query .\n"
] | 2016-06-15T12:24:42 | 2016-06-15T14:34:22 | 2016-06-15T14:34:22 | NONE | null | Consider the `Match` model:
``` python
class Match(peewee.Model):
user_a = peewee.ForeignKeyField(User, index=True,
related_name='matches_a')
user_b = peewee.ForeignKeyField(User, index=True,
related_name='matches_b')
```
How can we perform query joining **both** fields: `user_a` and `user_b`?
There's a chapter in docs describing the [similar case](http://docs.peewee-orm.com/en/latest/peewee/querying.html#multiple-foreign-keys-to-the-same-model) with the `Relationship` model. But it's different, the model `Match` above can be considered as the symmetrical version of the `Relationship`.
Such query can't be executed:
``` python
matches_for_user = (Match.select()
.join(User, on=Match.user_a)
.join(User, on=Match.user_b)
.where((Match.user_a == user) |
(Match.user_b == user)))
```
I get an exception:
```
AttributeError: type object 'User' has no attribute 'user_b'
```
And when trying to add `switch(Match)` statement between joins, get another error:
```
peewee.ProgrammingError: table name "t2" specified more than once
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/987/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/987/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/985 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/985/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/985/comments | https://api.github.com/repos/coleifer/peewee/issues/985/events | https://github.com/coleifer/peewee/issues/985 | 160,379,451 | MDU6SXNzdWUxNjAzNzk0NTE= | 985 | Requesting item [-1] on the result of select() raises an error. | {
"login": "HughMacdonald",
"id": 625512,
"node_id": "MDQ6VXNlcjYyNTUxMg==",
"avatar_url": "https://avatars.githubusercontent.com/u/625512?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/HughMacdonald",
"html_url": "https://github.com/HughMacdonald",
"followers_url": "https://api.github.com/users/HughMacdonald/followers",
"following_url": "https://api.github.com/users/HughMacdonald/following{/other_user}",
"gists_url": "https://api.github.com/users/HughMacdonald/gists{/gist_id}",
"starred_url": "https://api.github.com/users/HughMacdonald/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/HughMacdonald/subscriptions",
"organizations_url": "https://api.github.com/users/HughMacdonald/orgs",
"repos_url": "https://api.github.com/users/HughMacdonald/repos",
"events_url": "https://api.github.com/users/HughMacdonald/events{/privacy}",
"received_events_url": "https://api.github.com/users/HughMacdonald/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Originally this is a design decision I borrowed from Django's ORM. I believe the idea is to that the API should reinforce the concept that the query result wrapper is not a list, and should not be treated as such. That said, I can see how this might cause confusion since the other `__getitem__` behaviors are available. I'll address this with a patch, using yours as a reference. Thanks!\n\nDiscussion on django issue tracker: https://code.djangoproject.com/ticket/13089\n",
"Thanks again @HughMacdonald\n",
"Cool - thanks for that.\n"
] | 2016-06-15T09:39:24 | 2016-06-15T14:18:43 | 2016-06-15T14:06:09 | NONE | null | I've found something that may or may not be considered an issue, but standard python conventions don't work.
If I do:
```
items = MyTable.select()
myItem = items[-1]
```
I get:
``` python
[code]Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/site-packages/peewee.py", line 2980, in __getitem__
res.fill_cache(index)
File "/usr/local/lib/python2.7/site-packages/peewee.py", line 2131, in fill_cache
raise ValueError('Negative values are not supported.')
ValueError: Negative values are not supported.[/code]
```
(These lines are actually 3094 and 2233 in the current master)
I've made a change in my own fork, but I wanted to flag it up here before putting a pull request in.
I've modified the tests too to test that this does the right job, and added some tests for slices using negative indices.
Here's my branch with this in - let me know if it's okay to put in as a PR.
https://github.com/HughMacdonald/peewee/tree/select_results_negative_index
Thanks
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/985/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/985/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/984 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/984/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/984/comments | https://api.github.com/repos/coleifer/peewee/issues/984/events | https://github.com/coleifer/peewee/issues/984 | 160,323,359 | MDU6SXNzdWUxNjAzMjMzNTk= | 984 | peewee 2.8.1 blob error | {
"login": "rfyiamcool",
"id": 3785409,
"node_id": "MDQ6VXNlcjM3ODU0MDk=",
"avatar_url": "https://avatars.githubusercontent.com/u/3785409?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/rfyiamcool",
"html_url": "https://github.com/rfyiamcool",
"followers_url": "https://api.github.com/users/rfyiamcool/followers",
"following_url": "https://api.github.com/users/rfyiamcool/following{/other_user}",
"gists_url": "https://api.github.com/users/rfyiamcool/gists{/gist_id}",
"starred_url": "https://api.github.com/users/rfyiamcool/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/rfyiamcool/subscriptions",
"organizations_url": "https://api.github.com/users/rfyiamcool/orgs",
"repos_url": "https://api.github.com/users/rfyiamcool/repos",
"events_url": "https://api.github.com/users/rfyiamcool/events{/privacy}",
"received_events_url": "https://api.github.com/users/rfyiamcool/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"So this error indicates that the `mysql` Python driver is not installed or is not import-able. Here is the code peewee executes at the top of the module:\n\n``` python\ntry:\n import MySQLdb as mysql # prefer the C module.\nexcept ImportError:\n try:\n import pymysql as mysql\n except ImportError:\n mysql = None\n```\n\nYou've triggered the \"mysql=None\" bit, meaning peewee could not import either driver.\n"
] | 2016-06-15T02:02:59 | 2016-06-15T19:10:55 | 2016-06-15T19:10:55 | NONE | null | in peewee 2.8.1 , use BlobField() raise error .
my peewee model example:
```
class ArticleContent(Model):
article_id = IntegerField()
content = BlobField()
class Meta:
database = db
db_table= 'mirro_article_content'
```
error:
```
[operation@wx-buzz-zhihu2 extractor_mirro]$ python core/mm.py
Traceback (most recent call last):
File "core/mm.py", line 30, in <module>
class ArticleContent(Model):
File "/usr/local/lib/python2.7/site-packages/peewee.py", line 4479, in __new__
field.add_to_class(cls, name)
File "/usr/local/lib/python2.7/site-packages/peewee.py", line 1081, in add_to_class
self._constructor = model_class._meta.database.get_binary_type()
File "/usr/local/lib/python2.7/site-packages/peewee.py", line 3985, in get_binary_type
return mysql.Binary
AttributeError: 'NoneType' object has no attribute 'Binary'
```
I use peewee 2.8.0 version, not raise error. Please fix it .
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/984/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/984/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/983 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/983/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/983/comments | https://api.github.com/repos/coleifer/peewee/issues/983/events | https://github.com/coleifer/peewee/issues/983 | 160,129,687 | MDU6SXNzdWUxNjAxMjk2ODc= | 983 | Extra `t2` while generating query | {
"login": "blueset",
"id": 553831,
"node_id": "MDQ6VXNlcjU1MzgzMQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/553831?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/blueset",
"html_url": "https://github.com/blueset",
"followers_url": "https://api.github.com/users/blueset/followers",
"following_url": "https://api.github.com/users/blueset/following{/other_user}",
"gists_url": "https://api.github.com/users/blueset/gists{/gist_id}",
"starred_url": "https://api.github.com/users/blueset/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/blueset/subscriptions",
"organizations_url": "https://api.github.com/users/blueset/orgs",
"repos_url": "https://api.github.com/users/blueset/repos",
"events_url": "https://api.github.com/users/blueset/events{/privacy}",
"received_events_url": "https://api.github.com/users/blueset/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"q = MsgLog.select().where(MsgLog.master_msg_id.startswith(\"%s.\" % chat_id)).order_by(MsgLog.id.desc())\n\nThe problem is you're ordering by MsgLog.id but MsgLog.master_msg_id is the primary key and the model (while it has an \"id\" attribute), does not consider it a valid field.\n\nTo fix this, just change your \"order_by()\" call to order on a field that's defined on the MsgLog model. Or alternatively, you could make \"master_msg_id\" have \"unique=True\" instead of being a primary key.\n",
"I think I may make some modifications to Peewee to drop the `id` attribute if a different field is used as the foreign key.\n",
"@coleifer deleting other user's comments just because you don't agree with the technical viewpoint is very uncool.\n",
"The truth is that I removed your comments because they were not constructive, and I was tired of having to defend aspects of my project because you felt entitled to a technical discussion because you happened to disagree with it. When I pointed to you that the things you disagreed with were documented and obviously intentional (via git log), you suggested I was trying to justify, post-hoc, bad design decisions, and was being an irresponsible maintainer. How is that constructive?\n",
"Reopening as I intend to fix. \n"
] | 2016-06-14T08:56:13 | 2016-07-14T14:41:51 | 2016-07-14T14:41:51 | NONE | null | # Model
``` python
class MsgLog(Model):
master_msg_id = CharField(unique=True, primary_key=True)
text = CharField()
slave_origin_uid = CharField()
slave_origin_display_name = CharField(null=True)
slave_member_uid = CharField(null=True)
slave_member_display_name = CharField(null=True)
msg_type = CharField()
sent_to = CharField()
class Meta:
database = SqliteDatabase('data.db')
```
# Query
``` python
chat_id = 1
q = MsgLog.select().where(MsgLog.master_msg_id.startswith("%s." % chat_id)).order_by(MsgLog.id.desc())
print(q)
```
## Expected result
``` sql
SELECT "t1"."master_msg_id", "t1"."text", "t1"."slave_origin_uid", "t1"."slave_origin_display_name", "t1"."slave_member_uid", "t1"."slave_member_display_name", "t1"."msg_type", "t1"."sent_to" FROM "msglog" AS t1 WHERE ("t1"."master_msg_id" LIKE ?) ORDER BY "t1"."id" DESC ['1.%']
```
## Returned result
``` sql
SELECT "t1"."master_msg_id", "t1"."text", "t1"."slave_origin_uid", "t1"."slave_origin_display_name", "t1"."slave_member_uid", "t1"."slave_member_display_name", "t1"."msg_type", "t1"."sent_to" FROM "msglog" AS t1 WHERE ("t1"."master_msg_id" LIKE ?) ORDER BY "t2"."id" DESC ['1.%']
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/983/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/983/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/982 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/982/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/982/comments | https://api.github.com/repos/coleifer/peewee/issues/982/events | https://github.com/coleifer/peewee/pull/982 | 160,059,076 | MDExOlB1bGxSZXF1ZXN0NzM2NTM2NjA= | 982 | Prevent the silent overwriting of model's attributes e.g. "foo_id" when "foo" foreign key added | {
"login": "quantumdark",
"id": 12005883,
"node_id": "MDQ6VXNlcjEyMDA1ODgz",
"avatar_url": "https://avatars.githubusercontent.com/u/12005883?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/quantumdark",
"html_url": "https://github.com/quantumdark",
"followers_url": "https://api.github.com/users/quantumdark/followers",
"following_url": "https://api.github.com/users/quantumdark/following{/other_user}",
"gists_url": "https://api.github.com/users/quantumdark/gists{/gist_id}",
"starred_url": "https://api.github.com/users/quantumdark/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/quantumdark/subscriptions",
"organizations_url": "https://api.github.com/users/quantumdark/orgs",
"repos_url": "https://api.github.com/users/quantumdark/repos",
"events_url": "https://api.github.com/users/quantumdark/events{/privacy}",
"received_events_url": "https://api.github.com/users/quantumdark/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I'm kind of curious what kind of model structure you'd have to have to run into this kind of thing... I understand that there may be a bug here, but I'm not sure how you would actually encounter it in practice?\n",
"I run into it not only once, last time we had save parameters from external API call in the model Inherited from the base model. In this case, the log of actions associated with a subscription entity.\nOur deveveloper did'nt know the _id thing and just save it like that:\n\nif v.validate(self.message):\n FortumoLog.create(\n subscription = self.subscription\n **self.message)\n\nSo about the stucture: we have several log entities for different APIs and one general subscription model.\n\nNobody has noticed that one of the parameters is not stored (it just stored for history), but sometimes it drove to crashes our flask-admin, only on the prod with disabled debugging.) with some error \n\"Failed to find field for filter: %s\"\nSo I think it may save a few hours for someone.\n",
"Fixed 34e56cb887751453680641695bdec1fc6518b2cf\n"
] | 2016-06-13T22:28:35 | 2016-07-14T08:58:51 | 2016-07-14T08:58:51 | NONE | null | In complex structures with a large number of fields easy to miss the collision, especially if it happened with parrent's model attribute.
Considering that the python dict doesn't guarantee the order of items, there are two possibilities:
1. The *_id attr will be overwritten by ObjectIdDescriptor and will no longer available, but field (if the attr is a field) still will be in _meta.fields. This leads to unexpected and floating bugs.
2. ObjectIdDescriptor will be overwritten by custom attribute. Much less harmful and may be unnoticed for a long time.
I think it should explicitly show the possible issue, by throwing an exception.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/982/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/982/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/982",
"html_url": "https://github.com/coleifer/peewee/pull/982",
"diff_url": "https://github.com/coleifer/peewee/pull/982.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/982.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/981 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/981/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/981/comments | https://api.github.com/repos/coleifer/peewee/issues/981/events | https://github.com/coleifer/peewee/issues/981 | 160,054,405 | MDU6SXNzdWUxNjAwNTQ0MDU= | 981 | Column.in_() should allow a set | {
"login": "keredson",
"id": 2049665,
"node_id": "MDQ6VXNlcjIwNDk2NjU=",
"avatar_url": "https://avatars.githubusercontent.com/u/2049665?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/keredson",
"html_url": "https://github.com/keredson",
"followers_url": "https://api.github.com/users/keredson/followers",
"following_url": "https://api.github.com/users/keredson/following{/other_user}",
"gists_url": "https://api.github.com/users/keredson/gists{/gist_id}",
"starred_url": "https://api.github.com/users/keredson/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/keredson/subscriptions",
"organizations_url": "https://api.github.com/users/keredson/orgs",
"repos_url": "https://api.github.com/users/keredson/repos",
"events_url": "https://api.github.com/users/keredson/events{/privacy}",
"received_events_url": "https://api.github.com/users/keredson/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
":+1: thanks!\n"
] | 2016-06-13T21:57:56 | 2016-06-23T01:27:26 | 2016-06-14T05:22:51 | CONTRIBUTOR | null | currently you have to convert the set to a list, which isn't hard, but it should also just accept the set directly.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/981/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/981/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/980 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/980/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/980/comments | https://api.github.com/repos/coleifer/peewee/issues/980/events | https://github.com/coleifer/peewee/issues/980 | 160,040,587 | MDU6SXNzdWUxNjAwNDA1ODc= | 980 | calling len() on a query should do a database count() rather than load the whole result set into memory | {
"login": "keredson",
"id": 2049665,
"node_id": "MDQ6VXNlcjIwNDk2NjU=",
"avatar_url": "https://avatars.githubusercontent.com/u/2049665?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/keredson",
"html_url": "https://github.com/keredson",
"followers_url": "https://api.github.com/users/keredson/followers",
"following_url": "https://api.github.com/users/keredson/following{/other_user}",
"gists_url": "https://api.github.com/users/keredson/gists{/gist_id}",
"starred_url": "https://api.github.com/users/keredson/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/keredson/subscriptions",
"organizations_url": "https://api.github.com/users/keredson/orgs",
"repos_url": "https://api.github.com/users/keredson/repos",
"events_url": "https://api.github.com/users/keredson/events{/privacy}",
"received_events_url": "https://api.github.com/users/keredson/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"so i have a feeling that i'm going to get a response along the lines of \"we preload all the data in case the user wants to access/use it later\", similar to the rationale given for why `first()` doesn't use a `limit 1`. i just would like to point out that both of these are directly counter to the stated \"peewee doesn't do things based on what it 'thinks' you might want\" policy.\n",
"> \"peewee doesn't do things based on what it 'thinks' you might want\"\n\nActually I think that current behavior is in line with this policy. If I wanted a database count query, I would've called the `count()` method instead of using `len`. \n",
"It actually was, and has been documented, for some time:\n\n45e096e94afb3c4496ac961f64ada374d27b2529\n"
] | 2016-06-13T20:44:09 | 2016-06-19T19:19:13 | 2016-06-13T21:57:55 | CONTRIBUTOR | null | currently calling `len()` on a query loads all the records from the database, and then calls `len()` on the resulting list of objects. this is hugely sub-optimal.
in most instances (ie if it hasn't already been cached, etc.) using `count()` on the database would be both the expected behavior and much more efficient.
i've not seen anything in the documentation that would warn users of the current behavior or any explanation as to why it would do this.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/980/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/980/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/978 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/978/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/978/comments | https://api.github.com/repos/coleifer/peewee/issues/978/events | https://github.com/coleifer/peewee/issues/978 | 159,983,880 | MDU6SXNzdWUxNTk5ODM4ODA= | 978 | should prefetches all happen inside a transaction? | {
"login": "keredson",
"id": 2049665,
"node_id": "MDQ6VXNlcjIwNDk2NjU=",
"avatar_url": "https://avatars.githubusercontent.com/u/2049665?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/keredson",
"html_url": "https://github.com/keredson",
"followers_url": "https://api.github.com/users/keredson/followers",
"following_url": "https://api.github.com/users/keredson/following{/other_user}",
"gists_url": "https://api.github.com/users/keredson/gists{/gist_id}",
"starred_url": "https://api.github.com/users/keredson/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/keredson/subscriptions",
"organizations_url": "https://api.github.com/users/keredson/orgs",
"repos_url": "https://api.github.com/users/keredson/repos",
"events_url": "https://api.github.com/users/keredson/events{/privacy}",
"received_events_url": "https://api.github.com/users/keredson/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"That all would depend on your databases default isolation level. Also recall please how, as a general rule, peewee doesn't use magic or do things based on what it \"thinks\" you might want. You have the tools to do your prefetching in an atomic block. If you always want this behavior, write a wrapper.\n",
"> That all would depend on your databases default isolation level.\n\ni don't think that's true. two subsequent queries outside of a transaction don't have any consistency guarantees between them at any isolation level on any database.\n\n> peewee doesn't use magic or do things based on what it \"thinks\" you might want\n\nall APIs are doing what they think you want to a certain degree, in the sense that they have reasonable defaults and behavior. anyone who makes a single API call to a peewee method would expect it to return an internally consistent collection of objects. i shouldn't have to know / worry about internal implementation details in order to get correct data, vs. this obvious race condition. \"it's usually right\" arguments aside.\n",
"> i shouldn't have to know / worry about internal implementation details in order to get correct data\n\nIn that case you should wrap your code in an `atomic()` block.\n",
"i get that that's an option. i'm arguing that that should be the default because as is the results are only \"usually\" right. :)\n"
] | 2016-06-13T15:52:58 | 2016-06-13T22:13:42 | 2016-06-13T17:16:25 | CONTRIBUTOR | null | i would argue they should, as otherwise there is no guarantee we're getting a read-consistent view of the data. seems like a simple fix on the face, given that peewee can already handle nesting `atomic()`.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/978/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/978/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/977 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/977/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/977/comments | https://api.github.com/repos/coleifer/peewee/issues/977/events | https://github.com/coleifer/peewee/issues/977 | 159,971,931 | MDU6SXNzdWUxNTk5NzE5MzE= | 977 | aliasing a FK prevents related objects from being populated | {
"login": "keredson",
"id": 2049665,
"node_id": "MDQ6VXNlcjIwNDk2NjU=",
"avatar_url": "https://avatars.githubusercontent.com/u/2049665?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/keredson",
"html_url": "https://github.com/keredson",
"followers_url": "https://api.github.com/users/keredson/followers",
"following_url": "https://api.github.com/users/keredson/following{/other_user}",
"gists_url": "https://api.github.com/users/keredson/gists{/gist_id}",
"starred_url": "https://api.github.com/users/keredson/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/keredson/subscriptions",
"organizations_url": "https://api.github.com/users/keredson/orgs",
"repos_url": "https://api.github.com/users/keredson/repos",
"events_url": "https://api.github.com/users/keredson/events{/privacy}",
"received_events_url": "https://api.github.com/users/keredson/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Why put an alias on the column when specifying the `on` column? Seems like a pretty contrived example unless I'm misunderstanding how this applies to a larger class of bugs?\n",
"It's only contrived because I simplified it to the smallest possible example for the purpose of the bug report. I hit it by accident in a larger query. I worked around it by not using the alias.\n",
"Well, what's even the point of putting an aliased column in the on parameter?\n",
"I don't know that there is a point to it here in this simplified example. But clearly it should not be doing what it's doing. (Surprising the user with O(n) queries.) Probably it should effectively ignore the alias, or second to that throw an exception saying you can't used aliased FKs in a join.\n",
"I should clarify: when you put an alias on the `on` column (either an expression or a field), that is treated as an instruction to Peewee to use that alias for the joined instance when reconstructing the model graph.\n\nSo, when you write `on=Article.author.alias('something')` you're clearly instructing Peewee that you want the Article's author to be accessible as \"article.something\".\n\nIf you go back and re-check your code, you'll see that accessing it does not result in a query:\n\n``` python\nx = Article.select(Article, Person).join(Person, on=Article.author.alias('something')).first()\nprint x.something.name\n```\n",
"hmmm... ok, i can get behind that. +1\n",
"I'm relieved. Thanks for the approval.\n"
] | 2016-06-13T15:02:32 | 2016-06-13T22:01:39 | 2016-06-13T21:51:37 | CONTRIBUTOR | null | aliasing a FK prevents related objects from being populated, which causes O(n) queries.
``` python
class Person(pw.Model):
name = pw.CharField()
class Article(pw.Model):
title = pw.CharField()
author = pw.ForeignKeyField(db_column='author_id', rel_model=Person, to_field='id')
derek = Person.create(name='Derek')
article = Article.create(title='My Article', author=derek)
x = Article.select(Article, Person).join(Person, on=Article.author.alias('something')).first()
print x.author.name
```
causes the following sql:
``` sql
('SELECT "t1"."id", "t1"."title", "t1"."author_id", "t1"."editor_id", "t2"."id", "t2"."name", "t2"."parent_id" FROM "article" AS t1 INNER JOIN "person" AS t2 ON ("t1"."author_id" = "t2"."id")', [])
('SELECT "t1"."id", "t1"."name", "t1"."parent_id" FROM "person" AS t1 WHERE ("t1"."id" = ?) LIMIT 1 OFFSET 0', [1])
Derek
```
whereas:
``` python
x = Article.select(Article, Person).join(Person, on=Article.author).first()
print x.author.name
```
behaves correctly:
``` sql
('SELECT "t1"."id", "t1"."title", "t1"."author_id", "t1"."editor_id", "t2"."id", "t2"."name", "t2"."parent_id" FROM "article" AS t1 INNER JOIN "person" AS t2 ON ("t1"."author_id" = "t2"."id")', [])
Derek
```
it looks like the _alias column is being used questionably here https://github.com/coleifer/peewee/blob/9f46db4e722178a2bc0408a1c5c39b31e204e61a/peewee.py#L2311 which is causing it to miss the lookup here https://github.com/coleifer/peewee/blob/9f46db4e722178a2bc0408a1c5c39b31e204e61a/peewee.py#L2380. which is assuming the model name not the alias. confusing to me how this is supposed to work. is the link between what's being selected and which children objects get populated just based on the model name?
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/977/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/977/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/976 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/976/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/976/comments | https://api.github.com/repos/coleifer/peewee/issues/976/events | https://github.com/coleifer/peewee/issues/976 | 159,753,925 | MDU6SXNzdWUxNTk3NTM5MjU= | 976 | exception when cloning a FK | {
"login": "keredson",
"id": 2049665,
"node_id": "MDQ6VXNlcjIwNDk2NjU=",
"avatar_url": "https://avatars.githubusercontent.com/u/2049665?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/keredson",
"html_url": "https://github.com/keredson",
"followers_url": "https://api.github.com/users/keredson/followers",
"following_url": "https://api.github.com/users/keredson/following{/other_user}",
"gists_url": "https://api.github.com/users/keredson/gists{/gist_id}",
"starred_url": "https://api.github.com/users/keredson/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/keredson/subscriptions",
"organizations_url": "https://api.github.com/users/keredson/orgs",
"repos_url": "https://api.github.com/users/keredson/repos",
"events_url": "https://api.github.com/users/keredson/events{/privacy}",
"received_events_url": "https://api.github.com/users/keredson/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2016-06-11T03:52:22 | 2016-06-11T04:38:32 | 2016-06-11T04:38:32 | CONTRIBUTOR | null | ran into this today...
``` python
class Post(pw.Model):
title = pw.CharField()
author = pw.ForeignKeyField(Person)
Post.author.alias('derek').clone()
```
throws:
```
Traceback (most recent call last):
File "test.py", line 30, in <module>
Post.author.alias('derek').clone()
File "/home/derek/projects/coleifer-peewee/peewee.py", line 469, in clone
inst = self.clone_base()
File "/home/derek/projects/coleifer-peewee/peewee.py", line 1342, in clone_base
related_name=self.related_name,
AttributeError: 'ForeignKeyField' object has no attribute 'related_name'
```
looks like `related_name` is only set when `add_to_class` is called.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/976/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/976/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/975 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/975/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/975/comments | https://api.github.com/repos/coleifer/peewee/issues/975/events | https://github.com/coleifer/peewee/issues/975 | 159,208,354 | MDU6SXNzdWUxNTkyMDgzNTQ= | 975 | Additive order_by | {
"login": "josefdlange",
"id": 1062835,
"node_id": "MDQ6VXNlcjEwNjI4MzU=",
"avatar_url": "https://avatars.githubusercontent.com/u/1062835?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/josefdlange",
"html_url": "https://github.com/josefdlange",
"followers_url": "https://api.github.com/users/josefdlange/followers",
"following_url": "https://api.github.com/users/josefdlange/following{/other_user}",
"gists_url": "https://api.github.com/users/josefdlange/gists{/gist_id}",
"starred_url": "https://api.github.com/users/josefdlange/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/josefdlange/subscriptions",
"organizations_url": "https://api.github.com/users/josefdlange/orgs",
"repos_url": "https://api.github.com/users/josefdlange/repos",
"events_url": "https://api.github.com/users/josefdlange/events{/privacy}",
"received_events_url": "https://api.github.com/users/josefdlange/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"> Maybe we could toss in a extend=False kwarg to the method that\n\ni can see the use, but a definite +1 on not changing the default behavior if this is done.\n",
"Of course. Default behavior is critical, especially when considering that this is likely a heavily-used feature of the ORM.\n"
] | 2016-06-08T16:17:40 | 2016-06-09T02:11:16 | 2016-06-09T02:11:16 | CONTRIBUTOR | null | Spent a few hours debugging something in a query only to find that the implementation of `order_by` on `SelectQuery` is:
```
@returns_clone
def order_by(self, *args):
self._order_by = list(args)
```
This means that if one was composing a query based on a number of inputs (of which more than one might affect ordering) if `order_by` is called more than once, any prior `order_by` statements will be obliterated. Maybe we could toss in a `extend=False` `kwarg` to the method that, if `True`, will extend the `_order_by` list with the value of `*args`.
If you like that idea I can implement and send you a PR. Wanted to get your take before I did it, however. Right now to get around it I'm directly accessing `_order_by` if it is not `None` and appending/extending as I need.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/975/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/975/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/974 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/974/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/974/comments | https://api.github.com/repos/coleifer/peewee/issues/974/events | https://github.com/coleifer/peewee/pull/974 | 159,028,748 | MDExOlB1bGxSZXF1ZXN0NzI5NTE0ODM= | 974 | Test case for RowID + insert_many bug | {
"login": "jberkel",
"id": 18891,
"node_id": "MDQ6VXNlcjE4ODkx",
"avatar_url": "https://avatars.githubusercontent.com/u/18891?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/jberkel",
"html_url": "https://github.com/jberkel",
"followers_url": "https://api.github.com/users/jberkel/followers",
"following_url": "https://api.github.com/users/jberkel/following{/other_user}",
"gists_url": "https://api.github.com/users/jberkel/gists{/gist_id}",
"starred_url": "https://api.github.com/users/jberkel/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/jberkel/subscriptions",
"organizations_url": "https://api.github.com/users/jberkel/orgs",
"repos_url": "https://api.github.com/users/jberkel/repos",
"events_url": "https://api.github.com/users/jberkel/events{/privacy}",
"received_events_url": "https://api.github.com/users/jberkel/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"There's some chicanery going on with Peewee in regards to implementing the `rowid` field. I'll take another look at the implementation and see if I can clean it up.\n",
"Thanks! Yes, the field gets removed here: \nhttps://github.com/coleifer/peewee/blob/master/playhouse/sqlite_ext.py#L90\n\nDo extension tests not get run by the CI? In theory the build should have failed. (I had to add `from playhouse.tests.test_sqlite_ext import *` to `tests.py` get them to run locally).\n",
"> Do extension tests not get run by the CI?\n\nThey should be getting run. The .travis.yml file specifies `./runtests.py -a` which includes all extensions (except those for which a dependency is missing, which shouldn't be the case for the sqlite extension tests).\n",
"Yes, looks like they ran there and passed. I suspect it's because some code paths don't get executed on the CI, for instance:\n\n``` python\n insert_many = sqlite3 and sqlite3.sqlite_version_info >= (3, 7, 11, 0)\n # ...\n def execute(self):\n insert_with_loop = (\n self._is_multi_row_insert and\n self._query is None and\n self._returning is None and\n not self.database.insert_many)\n if insert_with_loop:\n return self._insert_with_loop()\n```\n\nAnyway, with the lastest master everything works as expected and I can remove my workaround, thanks!\n"
] | 2016-06-07T21:27:14 | 2016-06-09T20:15:19 | 2016-06-09T13:42:55 | CONTRIBUTOR | null | This is the problem I mentioned in #971. Not sure how to fix this properly, for now just added a bunch of tests to document the problem. The first two tests pass, only the last one fails.
```
Traceback (most recent call last):
File "/Users/jan/projects/peewee/playhouse/tests/test_sqlite_ext.py", line 818, in test_insert_many_with_rowid_with_field_validation
RowIDModel.insert_many([{RowIDModel.rowid: 5, 'data': 1}], validate_fields=True).execute()
File "/Users/jan/projects/peewee/peewee.py", line 3351, in execute
cursor = self._execute()
File "/Users/jan/projects/peewee/peewee.py", line 2747, in _execute
sql, params = self.sql()
File "/Users/jan/projects/peewee/peewee.py", line 3319, in sql
return self.compiler().generate_insert(self)
File "/Users/jan/projects/peewee/peewee.py", line 1960, in generate_insert
for row_dict in query._iter_rows():
File "/Users/jan/projects/peewee/peewee.py", line 3271, in _iter_rows
validate_field(key)
File "/Users/jan/projects/peewee/peewee.py", line 3261, in validate_field
raise KeyError('"%s" is not a recognized field.' % field)
KeyError: '"<playhouse.sqlite_ext.RowIDField object at 0x102dc81d0>" is not a recognized field.'
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/974/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/974/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/974",
"html_url": "https://github.com/coleifer/peewee/pull/974",
"diff_url": "https://github.com/coleifer/peewee/pull/974.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/974.patch",
"merged_at": "2016-06-09T13:42:55"
} |
https://api.github.com/repos/coleifer/peewee/issues/973 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/973/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/973/comments | https://api.github.com/repos/coleifer/peewee/issues/973/events | https://github.com/coleifer/peewee/pull/973 | 159,015,916 | MDExOlB1bGxSZXF1ZXN0NzI5NDE5MzY= | 973 | Impl custom alias names | {
"login": "keredson",
"id": 2049665,
"node_id": "MDQ6VXNlcjIwNDk2NjU=",
"avatar_url": "https://avatars.githubusercontent.com/u/2049665?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/keredson",
"html_url": "https://github.com/keredson",
"followers_url": "https://api.github.com/users/keredson/followers",
"following_url": "https://api.github.com/users/keredson/following{/other_user}",
"gists_url": "https://api.github.com/users/keredson/gists{/gist_id}",
"starred_url": "https://api.github.com/users/keredson/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/keredson/subscriptions",
"organizations_url": "https://api.github.com/users/keredson/orgs",
"repos_url": "https://api.github.com/users/keredson/repos",
"events_url": "https://api.github.com/users/keredson/events{/privacy}",
"received_events_url": "https://api.github.com/users/keredson/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Oof...this implementation feels very fragile and hacky, and I don't think the extra lines of code are worth the feature of being able to specify an alias name.\n\nGoing to pass on this for now. The 3.0 stuff I'm working on can do this as a matter of course, so it'll land then.\n",
"+1 on it for the rewrite. including the alias equality?\n"
] | 2016-06-07T20:24:05 | 2016-06-07T20:45:09 | 2016-06-07T20:39:15 | CONTRIBUTOR | null | implements https://github.com/coleifer/peewee/issues/972
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/973/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/973/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/973",
"html_url": "https://github.com/coleifer/peewee/pull/973",
"diff_url": "https://github.com/coleifer/peewee/pull/973.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/973.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/972 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/972/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/972/comments | https://api.github.com/repos/coleifer/peewee/issues/972/events | https://github.com/coleifer/peewee/issues/972 | 159,015,854 | MDU6SXNzdWUxNTkwMTU4NTQ= | 972 | allow the user to specify the table alias name | {
"login": "keredson",
"id": 2049665,
"node_id": "MDQ6VXNlcjIwNDk2NjU=",
"avatar_url": "https://avatars.githubusercontent.com/u/2049665?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/keredson",
"html_url": "https://github.com/keredson",
"followers_url": "https://api.github.com/users/keredson/followers",
"following_url": "https://api.github.com/users/keredson/following{/other_user}",
"gists_url": "https://api.github.com/users/keredson/gists{/gist_id}",
"starred_url": "https://api.github.com/users/keredson/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/keredson/subscriptions",
"organizations_url": "https://api.github.com/users/keredson/orgs",
"repos_url": "https://api.github.com/users/keredson/repos",
"events_url": "https://api.github.com/users/keredson/events{/privacy}",
"received_events_url": "https://api.github.com/users/keredson/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"In rewriting the SQL generation, I've got this feature covered. The implementation of this in peewee 2.8 just feels a bit too hacky to me to want to merge.\n"
] | 2016-06-07T20:23:41 | 2016-06-07T20:40:04 | 2016-06-07T20:39:23 | CONTRIBUTOR | null | currently this:
``` python
UA = User.alias()
UA.select().where(UA.username=='derek')
```
generates this:
``` sql
SELECT "t1"."id", "t1"."username" FROM "users" AS t1
WHERE ("t1"."username" = ?)
```
we should allow the user to optionally specify the table alias. example:
``` python
UA = User.alias('u1')
UA.select().where(UA.username=='derek')
```
which would generate:
``` sql
SELECT "u1"."id", "u1"."username" FROM "users" AS u1
WHERE ("u1"."username" = ?)
```
optionally, a little syntax sugar that i prefer:
``` python
UA = User.as_('u1')
UA.select().where(UA.username=='derek')
```
also identical aliases in the same query are handled appropriately, so aliases can be used in one-liners:
``` python
User.as_('u1').select().where(User.as_('u1').username=='derek')
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/972/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/972/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/971 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/971/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/971/comments | https://api.github.com/repos/coleifer/peewee/issues/971/events | https://github.com/coleifer/peewee/pull/971 | 159,007,772 | MDExOlB1bGxSZXF1ZXN0NzI5MzU5NDA= | 971 | insert_many: pass on `validate_fields` parameter | {
"login": "jberkel",
"id": 18891,
"node_id": "MDQ6VXNlcjE4ODkx",
"avatar_url": "https://avatars.githubusercontent.com/u/18891?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/jberkel",
"html_url": "https://github.com/jberkel",
"followers_url": "https://api.github.com/users/jberkel/followers",
"following_url": "https://api.github.com/users/jberkel/following{/other_user}",
"gists_url": "https://api.github.com/users/jberkel/gists{/gist_id}",
"starred_url": "https://api.github.com/users/jberkel/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/jberkel/subscriptions",
"organizations_url": "https://api.github.com/users/jberkel/orgs",
"repos_url": "https://api.github.com/users/jberkel/repos",
"events_url": "https://api.github.com/users/jberkel/events{/privacy}",
"received_events_url": "https://api.github.com/users/jberkel/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I came across this while trying to work around another bug (insert_many + FTS5). Will follow up with another PR.\n",
"Awesome catch, thank you!\n"
] | 2016-06-07T19:44:14 | 2016-06-07T20:36:42 | 2016-06-07T20:36:42 | CONTRIBUTOR | null | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/971/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/971/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/971",
"html_url": "https://github.com/coleifer/peewee/pull/971",
"diff_url": "https://github.com/coleifer/peewee/pull/971.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/971.patch",
"merged_at": "2016-06-07T20:36:42"
} |
|
https://api.github.com/repos/coleifer/peewee/issues/970 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/970/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/970/comments | https://api.github.com/repos/coleifer/peewee/issues/970/events | https://github.com/coleifer/peewee/pull/970 | 158,985,438 | MDExOlB1bGxSZXF1ZXN0NzI5MTk5MDI= | 970 | Infer alias when only one interpretation | {
"login": "keredson",
"id": 2049665,
"node_id": "MDQ6VXNlcjIwNDk2NjU=",
"avatar_url": "https://avatars.githubusercontent.com/u/2049665?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/keredson",
"html_url": "https://github.com/keredson",
"followers_url": "https://api.github.com/users/keredson/followers",
"following_url": "https://api.github.com/users/keredson/following{/other_user}",
"gists_url": "https://api.github.com/users/keredson/gists{/gist_id}",
"starred_url": "https://api.github.com/users/keredson/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/keredson/subscriptions",
"organizations_url": "https://api.github.com/users/keredson/orgs",
"repos_url": "https://api.github.com/users/keredson/repos",
"events_url": "https://api.github.com/users/keredson/events{/privacy}",
"received_events_url": "https://api.github.com/users/keredson/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2016-06-07T17:56:27 | 2016-06-07T19:11:09 | 2016-06-07T19:11:09 | CONTRIBUTOR | null | likewise for the alias matching version of that same basic code change for https://github.com/coleifer/peewee/issues/965
not that this is now valid:
``` python
User.alias().select().where(User.username=='charlie')
```
but this is still not:
``` python
User.alias().select().join(User.alias(), on=User.username=='charlie')
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/970/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/970/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/970",
"html_url": "https://github.com/coleifer/peewee/pull/970",
"diff_url": "https://github.com/coleifer/peewee/pull/970.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/970.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/969 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/969/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/969/comments | https://api.github.com/repos/coleifer/peewee/issues/969/events | https://github.com/coleifer/peewee/pull/969 | 158,967,859 | MDExOlB1bGxSZXF1ZXN0NzI5MDcyNDA= | 969 | Throw error no alias | {
"login": "keredson",
"id": 2049665,
"node_id": "MDQ6VXNlcjIwNDk2NjU=",
"avatar_url": "https://avatars.githubusercontent.com/u/2049665?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/keredson",
"html_url": "https://github.com/keredson",
"followers_url": "https://api.github.com/users/keredson/followers",
"following_url": "https://api.github.com/users/keredson/following{/other_user}",
"gists_url": "https://api.github.com/users/keredson/gists{/gist_id}",
"starred_url": "https://api.github.com/users/keredson/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/keredson/subscriptions",
"organizations_url": "https://api.github.com/users/keredson/orgs",
"repos_url": "https://api.github.com/users/keredson/repos",
"events_url": "https://api.github.com/users/keredson/events{/privacy}",
"received_events_url": "https://api.github.com/users/keredson/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Thanks for sharing the changes. Closing as wontfix per earlier discussion.\n"
] | 2016-06-07T16:30:01 | 2016-06-07T17:43:49 | 2016-06-07T17:43:49 | CONTRIBUTOR | null | for https://github.com/coleifer/peewee/issues/964. i know you said no interest, but logging here anyway since i was doing it for my own fork regardless.
the `_join` wound up being unnecessary as far as i can tell. i couldn't find a path in which it didn't hit the alias_map.
also added a unit test for your concat concern.
changing the unit test because it genned `t4` instead of `t3` i didn't like, but in the end the alias name used doesn't matter, and because if the way the counters are being passed around i'm not sure how fixable it is to keep the `t3`. (and in my branch all that's gone anyway, so the personal ROI is low to continue debugging)
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/969/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/969/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/969",
"html_url": "https://github.com/coleifer/peewee/pull/969",
"diff_url": "https://github.com/coleifer/peewee/pull/969.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/969.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/968 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/968/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/968/comments | https://api.github.com/repos/coleifer/peewee/issues/968/events | https://github.com/coleifer/peewee/issues/968 | 158,963,978 | MDU6SXNzdWUxNTg5NjM5Nzg= | 968 | pwiz generates invalid model name for tables starting with numbers | {
"login": "kennes913",
"id": 7109431,
"node_id": "MDQ6VXNlcjcxMDk0MzE=",
"avatar_url": "https://avatars.githubusercontent.com/u/7109431?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/kennes913",
"html_url": "https://github.com/kennes913",
"followers_url": "https://api.github.com/users/kennes913/followers",
"following_url": "https://api.github.com/users/kennes913/following{/other_user}",
"gists_url": "https://api.github.com/users/kennes913/gists{/gist_id}",
"starred_url": "https://api.github.com/users/kennes913/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/kennes913/subscriptions",
"organizations_url": "https://api.github.com/users/kennes913/orgs",
"repos_url": "https://api.github.com/users/kennes913/repos",
"events_url": "https://api.github.com/users/kennes913/events{/privacy}",
"received_events_url": "https://api.github.com/users/kennes913/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2016-06-07T16:12:19 | 2016-06-07T19:15:25 | 2016-06-07T19:15:25 | NONE | null | Modified copy-paste of process to produce error:
```
$ python -m pwiz -e mysql XXXXX -H XXXXX -P -u dbadmin -t 1337_table > db_models.py
Password:
$ python
Python 3.5.1 (v3.5.1:37a07cee5969, Dec 5 2015, 21:12:44)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import db_models
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/some/file/location/db_models.py", line 12
class 1337Table(BaseModel):
^
SyntaxError: invalid syntax
>>>
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/968/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/968/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/967 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/967/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/967/comments | https://api.github.com/repos/coleifer/peewee/issues/967/events | https://github.com/coleifer/peewee/issues/967 | 158,859,125 | MDU6SXNzdWUxNTg4NTkxMjU= | 967 | primary_key on sqlite seems to make table not saveable | {
"login": "daveselinger",
"id": 10235862,
"node_id": "MDQ6VXNlcjEwMjM1ODYy",
"avatar_url": "https://avatars.githubusercontent.com/u/10235862?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/daveselinger",
"html_url": "https://github.com/daveselinger",
"followers_url": "https://api.github.com/users/daveselinger/followers",
"following_url": "https://api.github.com/users/daveselinger/following{/other_user}",
"gists_url": "https://api.github.com/users/daveselinger/gists{/gist_id}",
"starred_url": "https://api.github.com/users/daveselinger/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/daveselinger/subscriptions",
"organizations_url": "https://api.github.com/users/daveselinger/orgs",
"repos_url": "https://api.github.com/users/daveselinger/repos",
"events_url": "https://api.github.com/users/daveselinger/events{/privacy}",
"received_events_url": "https://api.github.com/users/daveselinger/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"force_insert=True\n"
] | 2016-06-07T07:42:13 | 2016-06-07T07:48:27 | 2016-06-07T07:48:27 | NONE | null | Potentially related to my other issue log. I've found that if I set a column to primary_key=true (I've tried this on a CHAR and UUID columns), I don't get any errors, but the "save()" method returns 0:
class SimpleTest(BaseModel):
name = CharField(primary_key=True)
name2 = CharField()
simple = SimpleTest(name="Charlie", name2="Bucket")
print("Saving %d simples" % simple.save())
running this yields:
Saving 0 simples
No compile time errors or other messages.
I've then logged into the sqlite file directly and not surprisingly, I see no rows when selecting from the table.
Apologies if these are already logged--I did some searching and all I found was a comment from you about a year ago discussing the "primary key as only column" on a forum post...
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/967/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/967/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/966 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/966/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/966/comments | https://api.github.com/repos/coleifer/peewee/issues/966/events | https://github.com/coleifer/peewee/issues/966 | 158,858,631 | MDU6SXNzdWUxNTg4NTg2MzE= | 966 | primary_key as only column on sqlite | {
"login": "daveselinger",
"id": 10235862,
"node_id": "MDQ6VXNlcjEwMjM1ODYy",
"avatar_url": "https://avatars.githubusercontent.com/u/10235862?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/daveselinger",
"html_url": "https://github.com/daveselinger",
"followers_url": "https://api.github.com/users/daveselinger/followers",
"following_url": "https://api.github.com/users/daveselinger/following{/other_user}",
"gists_url": "https://api.github.com/users/daveselinger/gists{/gist_id}",
"starred_url": "https://api.github.com/users/daveselinger/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/daveselinger/subscriptions",
"organizations_url": "https://api.github.com/users/daveselinger/orgs",
"repos_url": "https://api.github.com/users/daveselinger/repos",
"events_url": "https://api.github.com/users/daveselinger/events{/privacy}",
"received_events_url": "https://api.github.com/users/daveselinger/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"force_insert=True\nThe logging helped a ton--didn't find that till I looked at https://github.com/coleifer/peewee/issues/961 but super helpful.\n\nThx.\n"
] | 2016-06-07T07:39:14 | 2016-06-07T07:54:22 | 2016-06-07T07:54:22 | NONE | null | Hey there--great library, btw.
I'm running into a couple of issues (working directly on head/master):
1. A table with only a primary key as the sole field:
class SimpleTest(BaseModel):
name = CharField(primary_key=True)
When I call:
simple = SimpleTest(name="Charlie")
print("Saving %d simples" % simple.save())
I get:
File "./peewee/peewee.py", line 4862, in save
rows = self.update(*_field_dict).where(self._pk_expr()).execute()
File "./peewee/peewee.py", line 3224, in execute
return self.database.rows_affected(self._execute())
File "./peewee/peewee.py", line 2748, in _execute
return self.database.execute_sql(sql, params, self.require_commit)
File "./peewee/peewee.py", line 3599, in execute_sql
self.commit()
File "./peewee/peewee.py", line 3423, in __exit__
reraise(new_type, new_type(_exc_args), traceback)
File "./peewee/peewee.py", line 132, in reraise
raise value.with_traceback(tb)
File "./peewee/peewee.py", line 3592, in execute_sql
cursor.execute(sql, params or ())
peewee.OperationalError: near "WHERE": syntax error
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/966/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/966/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/965 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/965/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/965/comments | https://api.github.com/repos/coleifer/peewee/issues/965/events | https://github.com/coleifer/peewee/issues/965 | 158,757,855 | MDU6SXNzdWUxNTg3NTc4NTU= | 965 | peewee can infer alias references where the inference is unambiguous | {
"login": "keredson",
"id": 2049665,
"node_id": "MDQ6VXNlcjIwNDk2NjU=",
"avatar_url": "https://avatars.githubusercontent.com/u/2049665?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/keredson",
"html_url": "https://github.com/keredson",
"followers_url": "https://api.github.com/users/keredson/followers",
"following_url": "https://api.github.com/users/keredson/following{/other_user}",
"gists_url": "https://api.github.com/users/keredson/gists{/gist_id}",
"starred_url": "https://api.github.com/users/keredson/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/keredson/subscriptions",
"organizations_url": "https://api.github.com/users/keredson/orgs",
"repos_url": "https://api.github.com/users/keredson/repos",
"events_url": "https://api.github.com/users/keredson/events{/privacy}",
"received_events_url": "https://api.github.com/users/keredson/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Aliased models are frequently used with correlated subqueries, making the possibility of inferring the correct thing to do quite a bit more complicated than it might seem.\n\nPhilosophically, I'm opposed to adding _any_ heuristics into `peewee`. Peewee is incredibly easy to understand because it does what you tell it to do. For people who are comfortable writing SQL this is a big deal because there are no surprises in store when you go to try out your query. You don't need to know a bunch of specialized APIs, because peewee provides the right simple tools that you can use them to build up more complex tools.\n",
"Take a look at this post I wrote to get a longer take on these ideas: http://charlesleifer.com/blog/shortcomings-in-the-django-orm-and-a-look-at-peewee-a-lightweight-alternative/\n",
"yep, read that about a week and a half ago. one of the reasons i gave peewee a real hard look, and i very much agree w/ it. i did a lot of django work ~2006-2008 and know well how glitchy their ORM can be. (tho to be fair, then it was light years ahead of anything else, when everything was full on \"don't worry about the database, just pretend it's a giant in memory object graph\" hell.) then (when thrown back into an all-java world), i did internally for my company just what you did in 2.0. pure SQL constructs w/ an immutable builder API (all java).\n\nanyway, not meaning to life story here.\n\n> Philosophically, I'm opposed to adding any heuristics into peewee.\n\nagree that's a good philosophically. \n\nbtw, i found having dealing w/ the alias objects outside the scope of the query a significant source of user complaints. i tried a couple different techniques to ease the pain. this was one. another was having the aliases, but not having to be tied to a specific object instance. like:\n\n``` java\nTableA.ALL.join(TableB.as(\"x\")).where(TableB.as(\"x\").COLUMN_Y.eq(\"whatever\"));\n```\n\n(the `ALL` for me is like your `select()`)\n\nnote the first `as(\"x\")` is returning effectively what you call a model alias, where the second is (after the column is referenced) returning a bound field. this way people weren't having to declare an external variable outside their query. (granted, this declaration was more of a PITA in java)\n\nanyway... :)\n",
"Thanks for the input. Although the whole way peewee does model aliases currently is a bit of a lucky hack (see c118e434), I like using descriptive variable names for my table aliases. I've found it much easier to read and keep track of my queries when I can think of subsequent table references as distinct row sources. Nothing wrong with `.as('alias')`, but the repetition does create an equally easy avenue for one to forget to include the alias.\n",
"hah. been there.\n\nyeah, the references also worked as how yours do as well. you could also do:\n\n``` java\nTable tableb = TableB.as(\"x\");\nTableA.ALL.join(tableb).where(tableb.COLUMN_Y.eq(\"whatever\"));\n```\n\nbut it just was never used very much that way.\n"
] | 2016-06-06T19:42:20 | 2016-06-07T16:24:31 | 2016-06-07T02:18:33 | CONTRIBUTOR | null | code like:
``` python
Post.alias().select().where(Post.title=='something').get()
```
gens:
``` sql
SELECT "t1"."id", "t1"."title", "t1"."author_id" FROM "post" AS t1
WHERE ("t2"."title" = ?) LIMIT 1 OFFSET 0
```
which throws an exception because the conditional isn't using the alias as a reference.
i know the official way would be to pull out the alias as a variable and reference the column from that, but this gets cumbersome w/ many aliases. where it's safe and unambiguous what the user intended (ie that table is only being used once in the query), peewee should just make the connection for you.
again i have code locally i could pull into PR if this is generally agreed on.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/965/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/965/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/963 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/963/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/963/comments | https://api.github.com/repos/coleifer/peewee/issues/963/events | https://github.com/coleifer/peewee/issues/963 | 158,710,910 | MDU6SXNzdWUxNTg3MTA5MTA= | 963 | why does prefetch load results into related_name_prefetch instead of just related_name? | {
"login": "keredson",
"id": 2049665,
"node_id": "MDQ6VXNlcjIwNDk2NjU=",
"avatar_url": "https://avatars.githubusercontent.com/u/2049665?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/keredson",
"html_url": "https://github.com/keredson",
"followers_url": "https://api.github.com/users/keredson/followers",
"following_url": "https://api.github.com/users/keredson/following{/other_user}",
"gists_url": "https://api.github.com/users/keredson/gists{/gist_id}",
"starred_url": "https://api.github.com/users/keredson/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/keredson/subscriptions",
"organizations_url": "https://api.github.com/users/keredson/orgs",
"repos_url": "https://api.github.com/users/keredson/repos",
"events_url": "https://api.github.com/users/keredson/events{/privacy}",
"received_events_url": "https://api.github.com/users/keredson/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"This gets into a little bit of a gray area... I'm mainly opposed to stomping on the backref descriptor. Using `related_name_prefetch` isn't the greatest solution, but it's a convention that's been established by the documentation. Adding the ability to specify an alias to use for the prefetched objects seems like the best solution, but the implementation is already pretty out of control from successive attempts at adding functionality without really re-thinking things.\n\nAnother consideration is that accessing a backref creates a new query each time, so it's not the case that a backref query will ever be cached when accessed directly:\n\n``` python\nIn [9]: note = Note.public().get()\n\nIn [10]: query1 = note.notetag_set\n\nIn [11]: query2 = note.notetag_set\n\nIn [12]: id(query1) == id(query2)\nOut[12]: False\n```\n\nThe bad part is that `aggregate_rows()` behaves differently... `aggregate_rows()` supports the ability to assign prefetched objects to an alias of your choosing, but by default it uses the `related_name` and therefore overwrites it with a `list`. Not good to have `prefetch()` do one thing and `aggregate_rows()` another, but at this point both implementations gross me out so much that I'm not too inclined to change them. Furthermore, this would probably break a lot of people's code, as `prefetch()` and `aggregate_rows()` are pretty commonly-used APIs.\n\nSo, let's table this for now. With the 3.0 release I'm planning on completely dropping the `aggregate_rows()`-type functionality as my testing has never found it to be more performant than prefetch's O(k) or the naive O(n). I'll re-think `prefetch()` to make it less of a special-case and more tightly integrated with the rest of the APIs.\n",
"aren't all instance variables stomping on the table references already? the instance `post.title` is a string, while `Post.title` is a column reference. the backref seems no different.\n\n> accessing a backref creates a new query each time\n\nhmmm. i think that would make it easier. but i haven't looked at the code.\n\n> it's a convention that's been established by the documentation\n\nyeah, it'd have to be left there anyway for backwards compatibility obviously. just seeding ideas for 3.0. whatever replaces prefetch IMO should just store it in the backref pseudo-query/list rather than a secondary variable.\n",
"> aren't all instance variables stomping on the table references already? the instance post.title is a string, while Post.title is a column reference. the backref seems no different.\n\nThe class attributes are different from the instance attributes. For a reverse relation, it only has meaning if we have an instance with a value in the field the related model references, so again, it's an instances-only thing.\n"
] | 2016-06-06T15:49:32 | 2016-06-07T17:42:25 | 2016-06-07T01:56:06 | CONTRIBUTOR | null | I've looked through the documentation and I can't find anything mentioning why. Just that it does.
I can imagine it's because `related_name_prefetch` is a list whereas `related_name` is a `SelectQuery`, and generally it would be unwise to have two different object types returned in the same instance variable. But doesn't `SelectQuery` already have a query caching mechanism? Couldn't that just be populated per instance, rather than exposing a second variable name?
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/963/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/963/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/962 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/962/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/962/comments | https://api.github.com/repos/coleifer/peewee/issues/962/events | https://github.com/coleifer/peewee/pull/962 | 158,412,922 | MDExOlB1bGxSZXF1ZXN0NzI1Mzk3MDE= | 962 | Get should throw exception if not unique | {
"login": "keredson",
"id": 2049665,
"node_id": "MDQ6VXNlcjIwNDk2NjU=",
"avatar_url": "https://avatars.githubusercontent.com/u/2049665?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/keredson",
"html_url": "https://github.com/keredson",
"followers_url": "https://api.github.com/users/keredson/followers",
"following_url": "https://api.github.com/users/keredson/following{/other_user}",
"gists_url": "https://api.github.com/users/keredson/gists{/gist_id}",
"starred_url": "https://api.github.com/users/keredson/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/keredson/subscriptions",
"organizations_url": "https://api.github.com/users/keredson/orgs",
"repos_url": "https://api.github.com/users/keredson/repos",
"events_url": "https://api.github.com/users/keredson/events{/privacy}",
"received_events_url": "https://api.github.com/users/keredson/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I've commented already that the semantics of get() are not going to change, so I will pass on this change.\n",
"3.0 man, 3.0! :-)\n",
"It's not changing in 3.0 either man.\n"
] | 2016-06-03T17:13:24 | 2016-06-03T20:19:46 | 2016-06-03T17:35:51 | CONTRIBUTOR | null | again, behavior changing, so not for any point release, but hopefully some future incantation.
re: https://github.com/coleifer/peewee/issues/958
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/962/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/962/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/962",
"html_url": "https://github.com/coleifer/peewee/pull/962",
"diff_url": "https://github.com/coleifer/peewee/pull/962.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/962.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/961 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/961/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/961/comments | https://api.github.com/repos/coleifer/peewee/issues/961/events | https://github.com/coleifer/peewee/issues/961 | 158,412,504 | MDU6SXNzdWUxNTg0MTI1MDQ= | 961 | Problem with MySQL connections | {
"login": "felipevolpone",
"id": 1590527,
"node_id": "MDQ6VXNlcjE1OTA1Mjc=",
"avatar_url": "https://avatars.githubusercontent.com/u/1590527?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/felipevolpone",
"html_url": "https://github.com/felipevolpone",
"followers_url": "https://api.github.com/users/felipevolpone/followers",
"following_url": "https://api.github.com/users/felipevolpone/following{/other_user}",
"gists_url": "https://api.github.com/users/felipevolpone/gists{/gist_id}",
"starred_url": "https://api.github.com/users/felipevolpone/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/felipevolpone/subscriptions",
"organizations_url": "https://api.github.com/users/felipevolpone/orgs",
"repos_url": "https://api.github.com/users/felipevolpone/repos",
"events_url": "https://api.github.com/users/felipevolpone/events{/privacy}",
"received_events_url": "https://api.github.com/users/felipevolpone/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Weird..have you tried enabling the peewee logger and adding logging statements around your db connect/close code? That might help diagnose where things are going wrong.\n\nYou can enable the peewee debugger by following these instructions: http://docs.peewee-orm.com/en/latest/peewee/database.html#logging-queries\n\nThere's another logger in the `peewee.pool` namespace that should get picked up as well, so be sure to keep an eye out for that.\n\nTry enabling the logger and letting me know where the error occurs? Or alternatively, could you share the whole traceback?\n",
"Hi @coleifer, I put a print when I call database.open and database.close and both methods are being called and logged.\n\nHere is the entire log. You can see the calls to my backend and the peewee log\n\n``` bash\nNo connection available in pool.\nCreated new connection 23380784.\n('INSERT INTO `log` (`owner`, `action`, `date`, `value`) VALUES (%s, %s, %s, %s)', [None, u'RegisterService', 1465147903, u'{\"request_json\": {\"phone\": \"1111111111\", \"meta\": {\"rooted\": \"false\", \"app\": \"1.0\", \"appversion\": \"1.0\", \"Carrier\": \"Claro\", \"device_id\": \"12321\", \"OSVersion\": \"4.4\", \"gps\": \"13.03;15.033\"}, \"type\": \"buyer\", \"cpf\": \"1111111111\"}, \"mobile_meta_info\": {\"rooted\": \"false\", \"app\": \"1.0\", \"appversion\": \"1.0\", \"Carrier\": \"Claro\", \"device_id\": \"12321\", \"OSVersion\": \"4.4\", \"gps\": \"13.03;15.033\"}, \"method\": \"POST\", \"custom\": {}}'])\n('SELECT `t1`.`id`, `t1`.`name`, `t1`.`email`, `t1`.`profile`, `t1`.`cpf`, `t1`.`rg`, `t1`.`birthday`, `t1`.`ddd`, `t1`.`phone`, `t1`.`gender`, `t1`.`device_uuid`, `t1`.`city`, `t1`.`state`, `t1`.`address`, `t1`.`house_number`, `t1`.`neighborhood`, `t1`.`cep`, `t1`.`push_token` FROM `user` AS t1 WHERE (`t1`.`cpf` = %s)', [u'1111111111'])\n('SELECT `t1`.`id`, `t1`.`name`, `t1`.`email`, `t1`.`profile`, `t1`.`cpf`, `t1`.`rg`, `t1`.`birthday`, `t1`.`ddd`, `t1`.`phone`, `t1`.`gender`, `t1`.`device_uuid`, `t1`.`city`, `t1`.`state`, `t1`.`address`, `t1`.`house_number`, `t1`.`neighborhood`, `t1`.`cep`, `t1`.`push_token` FROM `user` AS t1 WHERE (`t1`.`phone` = %s)', [u'1111111111'])\n\n('SELECT `t1`.`id`, `t1`.`proposal_id`, `t1`.`account_id`, `t1`.`card_id`, `t1`.`card_number`, `t1`.`card_validation`, `t1`.`user_id`, `t1`.`has_bank_account`, `t1`.`contract_acceptance_date` FROM `customer` AS t1 WHERE (`t1`.`user_id` = %s)', [None])\n('SELECT `t1`.`id`, `t1`.`owner_id`, `t1`.`phone_invited`, `t1`.`status`, `t1`.`token` FROM `invite` AS t1 WHERE (`t1`.`phone_invited` = %s)', [u'1111111111'])\nMethod name: ORIGINA_CLIENTE\nParameters used: [\"1111111111\", \"11111111\", \"12321\", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \"11\", 1, {\"empresa\": \"20937849000101\", \"fluxo\": \"ORIGINA_CLIENTE\", \"senha\": \"x\", \"usuario\": \"x\"}]\nParameters used: {}\n('INSERT INTO `log` (`owner`, `action`, `date`, `value`) VALUES (%s, %s, %s, %s)', [None, u'ORIGINA_CLIENTE', 1465147906, u'{\"method\": \"GET\", \"custom\": {\"params\": [\"1111111111\", \"11111111\", \"12321\", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \"11\", 1, {\"empresa\": \"20937849000101\", \"fluxo\": \"ORIGINA_CLIENTE\", \"senha\": \"x\", \"usuario\": \"x\"}, {}], \"value\": {\"processReturn\": {\"ticket\": \"414D5120514D2E524F434B45542020201D884F57035B1C20\", \"variaveisContexto\": \"\", \"hash\": \"4380401e6d6a09706e6d08e24ebd40f6\"}}}}'])\n('INSERT INTO `user` (`profile`, `cpf`, `ddd`, `phone`, `device_uuid`) VALUES (%s, %s, %s, %s, %s)', [u'buyer', u'1111111111', u'11', u'1111111111', u'12321'])\n('INSERT INTO `rocketresource` (`user_id`, `ticket`, `hash_value`, `token`, `status`) VALUES (%s, %s, %s, %s, %s)', [10, u'414D5120514D2E524F434B45542020201D884F57035B1C20', u'4380401e6d6a09706e6d08e24ebd40f6', u'7749ba85-0d74-430a-a52b-2047177cd9ae', u'waiting_response'])\nReturning 23380784 to pool.\n\n[pid: 38|app: 0|req: 1/1] 127.0.0.1 () {48 vars in 825 bytes} [Sun Jun 5 14:31:43 2016] POST /s/user/Register => generated 155 bytes in 3162 msecs (HTTP/1.0 200) 3 headers in 112 bytes (2 switches on core 0)\n\n\n\n('INSERT INTO `log` (`owner`, `action`, `date`, `value`) VALUES (%s, %s, %s, %s)', [None, u'MockService', 1465147928, u'{\"method\": \"GET\", \"custom\": {}}'])\nReturning 23380784 to pool.\n[pid: 38|app: 0|req: 2/2] 127.0.0.1 () {42 vars in 703 bytes} [Sun Jun 5 14:32:08 2016] GET /s/mock/Mock => generated 0 bytes in 18 msecs (HTTP/1.0 403) 3 headers in 110 bytes (1 switches on core 1)\n\n\n\nConnection 23380784 was closed.\nNo connection available in pool.\nCreated new connection 25864240.\n('INSERT INTO `log` (`owner`, `action`, `date`, `value`) VALUES (%s, %s, %s, %s)', [None, u'RegisterService', 1465149152, u'{\"request_json\": {\"phone\": \"1111111111\", \"meta\": {\"rooted\": \"false\", \"app\": \"1.0\", \"appversion\": \"1.0\", \"Carrier\": \"Claro\", \"device_id\": \"12321\", \"OSVersion\": \"4.4\", \"gps\": \"13.03;15.033\"}, \"type\": \"buyer\", \"cpf\": \"1111111111\"}, \"mobile_meta_info\": {\"rooted\": \"false\", \"app\": \"1.0\", \"appversion\": \"1.0\", \"Carrier\": \"Claro\", \"device_id\": \"12321\", \"OSVersion\": \"4.4\", \"gps\": \"13.03;15.033\"}, \"method\": \"POST\", \"custom\": {}}'])\nReturning 25864240 to pool.\nERROR:root:(2006, 'MySQL server has gone away')\nTraceback (most recent call last):\n File \"/usr/local/lib/python2.7/dist-packages/webapp2.py\", line 1535, in __call__\n rv = self.handle_exception(request, response, e)\n File \"/usr/local/lib/python2.7/dist-packages/webapp2.py\", line 1529, in __call__\n rv = self.router.dispatch(request, response)\n File \"/usr/local/lib/python2.7/dist-packages/webapp2.py\", line 1278, in default_dispatcher\n return route.handler_adapter(request, response)\n File \"/usr/local/lib/python2.7/dist-packages/webapp2.py\", line 1102, in __call__\n return handler.dispatch()\n File \"./handler/service_handler.py\", line 16, in inner\n return func(*args, **kwargs)\n File \"./handler/service_handler.py\", line 30, in inner\n result = fnc(*a, **k)\n File \"./handler/service_handler.py\", line 54, in dispatch\n raise e\nOperationalError: (2006, 'MySQL server has gone away')\n[pid: 38|app: 0|req: 3/3] 127.0.0.1 () {48 vars in 824 bytes} [Sun Jun 5 14:52:32 2016] POST /s/user/Register => generated 114 bytes in 11 msecs (HTTP/1.0 500) 2 headers in 100 bytes (1 switches on core 0)\n\n```\n",
"Very strange... what causes that traceback to happen? It seems like it is not related to the connection pool.\n",
"Hi @coleifer, thanks for helping me. I put some logs and the exception is raised when I try to call the create method with one of my models. Check it out:\n\n``` bash\nConnection 16238048 was closed.\nDEBUG:peewee.pool:Connection 16238048 was closed.\nNo connection available in pool.\nDEBUG:peewee.pool:No connection available in pool.\nCreated new connection 139681664633120.\nDEBUG:peewee.pool:Created new connection 139681664633120.\n('INSERT INTO `log` (`owner`, `action`, `date`, `value`) VALUES (%s, %s, %s, %s)', [None, u'RegisterService', 1465213386, u'{\"request_json\": {\"phone\": \"1111121111\", \"meta\": {\"rooted\": \"false\", \"app\": \"1.0\", \"appversion\": \"1.0\", \"Carrier\": \"Claro\", \"device_id\": \"12321\", \"OSVersion\": \"4.4\", \"gps\": \"13.03;15.033\"}, \"type\": \"buyer\", \"cpf\": \"2222222222\"}, \"mobile_meta_info\": {\"rooted\": \"false\", \"app\": \"1.0\", \"appversion\": \"1.0\", \"Carrier\": \"Claro\", \"device_id\": \"12321\", \"OSVersion\": \"4.4\", \"gps\": \"13.03;15.033\"}, \"method\": \"POST\", \"custom\": {}}'])\nDEBUG:peewee:('INSERT INTO `log` (`owner`, `action`, `date`, `value`) VALUES (%s, %s, %s, %s)', [None, u'RegisterService', 1465213386, u'{\"request_json\": {\"phone\": \"1111121111\", \"meta\": {\"rooted\": \"false\", \"app\": \"1.0\", \"appversion\": \"1.0\", \"Carrier\": \"Claro\", \"device_id\": \"12321\", \"OSVersion\": \"4.4\", \"gps\": \"13.03;15.033\"}, \"type\": \"buyer\", \"cpf\": \"2222222222\"}, \"mobile_meta_info\": {\"rooted\": \"false\", \"app\": \"1.0\", \"appversion\": \"1.0\", \"Carrier\": \"Claro\", \"device_id\": \"12321\", \"OSVersion\": \"4.4\", \"gps\": \"13.03;15.033\"}, \"method\": \"POST\", \"custom\": {}}'])\nReturning 139681664633120 to pool.\nDEBUG:peewee.pool:Returning 139681664633120 to pool.\nERROR:root:(2006, 'MySQL server has gone away')\nTraceback (most recent call last):\n File \"/usr/local/lib/python2.7/dist-packages/webapp2.py\", line 1535, in __call__\n rv = self.handle_exception(request, response, e)\n File \"/usr/local/lib/python2.7/dist-packages/webapp2.py\", line 1529, in __call__\n rv = self.router.dispatch(request, response)\n File \"/usr/local/lib/python2.7/dist-packages/webapp2.py\", line 1278, in default_dispatcher\n return route.handler_adapter(request, response)\n File \"/usr/local/lib/python2.7/dist-packages/webapp2.py\", line 1102, in __call__\n return handler.dispatch()\n File \"./handler/service_handler.py\", line 18, in inner\n return func(*args, **kwargs)\n File \"./handler/service_handler.py\", line 34, in inner\n result = fnc(*a, **k)\n File \"./handler/service_handler.py\", line 47, in dispatch\n self.__saving_log(obj)\n File \"./handler/service_handler.py\", line 75, in __saving_log\n log_helper.log(action=obj.__class__.__name__, method=self.request.method, value=result, request=req)\n File \"./helper/log_helper.py\", line 42, in log\n return Log.create(owner=user, action=action, value=log_json, date=now)\n File \"/usr/local/lib/python2.7/dist-packages/peewee.py\", line 4551, in create\n inst.save(force_insert=True)\n File \"/usr/local/lib/python2.7/dist-packages/peewee.py\", line 4747, in save\n pk_from_cursor = self.insert(**field_dict).execute()\n File \"/usr/local/lib/python2.7/dist-packages/peewee.py\", line 3244, in execute\n cursor = self._execute()\n File \"/usr/local/lib/python2.7/dist-packages/peewee.py\", line 2656, in _execute\n return self.database.execute_sql(sql, params, self.require_commit)\n File \"/usr/local/lib/python2.7/dist-packages/peewee.py\", line 3492, in execute_sql\n self.commit()\n File \"/usr/local/lib/python2.7/dist-packages/peewee.py\", line 3316, in __exit__\n reraise(new_type, new_type(*exc_args), traceback)\n File \"/usr/local/lib/python2.7/dist-packages/peewee.py\", line 3485, in execute_sql\n cursor.execute(sql, params or ())\n File \"/usr/local/lib/python2.7/dist-packages/MySQLdb/cursors.py\", line 174, in execute\n self.errorhandler(self, exc, value)\n File \"/usr/local/lib/python2.7/dist-packages/MySQLdb/connections.py\", line 36, in defaulterrorhandler\n raise errorclass, errorvalue\nOperationalError: (2006, 'MySQL server has gone away')\n[pid: 38|app: 0|req: 4/4] 127.0.0.1 () {48 vars in 843 bytes} [Mon Jun 6 08:43:06 2016] POST /s/user/Register => generated 114 bytes in 12 msecs (HTTP/1.0 500) 2 headers in 100 bytes (1 switches on core 1)\n```\n",
"Cool thanks! So hmmm...are there a set of steps you follow to trigger the\nerror or does it just seem to happen sporadically? What values are you\nusing for your MySQL server connection timeout, and what is the\nstale_timeout on the peewee pool? My thought is if it's random, then you've\njust got to turn the pool stale timeout to a value lower than mysqls\ntimeout. Another option would be to stop using the pool and see how that\ngoes. Is this db getting a lot of traffic?\nOn Jun 6, 2016 6:49 AM, \"Felipe Volpone\" [email protected] wrote:\n\n> Hi @coleifer https://github.com/coleifer, thanks for helping me. I put\n> some logs and the exception is raised when I try to call the create method\n> with one of my models. Check it out:\n> \n> Connection 16238048 was closed.\n> DEBUG:peewee.pool:Connection 16238048 was closed.\n> No connection available in pool.\n> DEBUG:peewee.pool:No connection available in pool.\n> Created new connection 139681664633120.\n> DEBUG:peewee.pool:Created new connection 139681664633120.\n> ('INSERT INTO `log` (`owner`, `action`, `date`, `value`) VALUES (%s, %s, %s, %s)', [None, u'RegisterService', 1465213386, u'{\"request_json\": {\"phone\": \"1111121111\", \"meta\": {\"rooted\": \"false\", \"app\": \"1.0\", \"appversion\": \"1.0\", \"Carrier\": \"Claro\", \"device_id\": \"12321\", \"OSVersion\": \"4.4\", \"gps\": \"13.03;15.033\"}, \"type\": \"buyer\", \"cpf\": \"2222222222\"}, \"mobile_meta_info\": {\"rooted\": \"false\", \"app\": \"1.0\", \"appversion\": \"1.0\", \"Carrier\": \"Claro\", \"device_id\": \"12321\", \"OSVersion\": \"4.4\", \"gps\": \"13.03;15.033\"}, \"method\": \"POST\", \"custom\": {}}'])\n> DEBUG:peewee:('INSERT INTO `log` (`owner`, `action`, `date`, `value`) VALUES (%s, %s, %s, %s)', [None, u'RegisterService', 1465213386, u'{\"request_json\": {\"phone\": \"1111121111\", \"meta\": {\"rooted\": \"false\", \"app\": \"1.0\", \"appversion\": \"1.0\", \"Carrier\": \"Claro\", \"device_id\": \"12321\", \"OSVersion\": \"4.4\", \"gps\": \"13.03;15.033\"}, \"type\": \"buyer\", \"cpf\": \"2222222222\"}, \"mobile_meta_info\": {\"rooted\": \"false\", \"app\": \"1.0\", \"appversion\": \"1.0\", \"Carrier\": \"Claro\", \"device_id\": \"12321\", \"OSVersion\": \"4.4\", \"gps\": \"13.03;15.033\"}, \"method\": \"POST\", \"custom\": {}}'])\n> Returning 139681664633120 to pool.\n> DEBUG:peewee.pool:Returning 139681664633120 to pool.\n> ERROR:root:(2006, 'MySQL server has gone away')\n> Traceback (most recent call last):\n> File \"/usr/local/lib/python2.7/dist-packages/webapp2.py\", line 1535, in **call**\n> rv = self.handle_exception(request, response, e)\n> File \"/usr/local/lib/python2.7/dist-packages/webapp2.py\", line 1529, in **call**\n> rv = self.router.dispatch(request, response)\n> File \"/usr/local/lib/python2.7/dist-packages/webapp2.py\", line 1278, in default_dispatcher\n> return route.handler_adapter(request, response)\n> File \"/usr/local/lib/python2.7/dist-packages/webapp2.py\", line 1102, in **call**\n> return handler.dispatch()\n> File \"./handler/service_handler.py\", line 18, in inner\n> return func(_args, *_kwargs)\n> File \"./handler/service_handler.py\", line 34, in inner\n> result = fnc(_a, *_k)\n> File \"./handler/service_handler.py\", line 47, in dispatch\n> self.**saving_log(obj)\n> File \"./handler/service_handler.py\", line 75, in __saving_log\n> log_helper.log(action=obj.__class**.**name**, method=self.request.method, value=result, request=req)\n> File \"./helper/log_helper.py\", line 42, in log\n> return Log.create(owner=user, action=action, value=log_json, date=now)\n> File \"/usr/local/lib/python2.7/dist-packages/peewee.py\", line 4551, in create\n> inst.save(force_insert=True)\n> File \"/usr/local/lib/python2.7/dist-packages/peewee.py\", line 4747, in save\n> pk_from_cursor = self.insert(*_field_dict).execute()\n> File \"/usr/local/lib/python2.7/dist-packages/peewee.py\", line 3244, in execute\n> cursor = self._execute()\n> File \"/usr/local/lib/python2.7/dist-packages/peewee.py\", line 2656, in _execute\n> return self.database.execute_sql(sql, params, self.require_commit)\n> File \"/usr/local/lib/python2.7/dist-packages/peewee.py\", line 3492, in execute_sql\n> self.commit()\n> File \"/usr/local/lib/python2.7/dist-packages/peewee.py\", line 3316, in __exit__\n> reraise(new_type, new_type(_exc_args), traceback)\n> File \"/usr/local/lib/python2.7/dist-packages/peewee.py\", line 3485, in execute_sql\n> cursor.execute(sql, params or ())\n> File \"/usr/local/lib/python2.7/dist-packages/MySQLdb/cursors.py\", line 174, in execute\n> self.errorhandler(self, exc, value)\n> File \"/usr/local/lib/python2.7/dist-packages/MySQLdb/connections.py\", line 36, in defaulterrorhandler\n> raise errorclass, errorvalue\n> OperationalError: (2006, 'MySQL server has gone away')\n> [pid: 38|app: 0|req: 4/4] 127.0.0.1 () {48 vars in 843 bytes} [Mon Jun 6 08:43:06 2016] POST /s/user/Register => generated 114 bytes in 12 msecs (HTTP/1.0 500) 2 headers in 100 bytes (1 switches on core 1)\n> \n> —\n> You are receiving this because you were mentioned.\n> Reply to this email directly, view it on GitHub\n> https://github.com/coleifer/peewee/issues/961#issuecomment-223937057,\n> or mute the thread\n> https://github.com/notifications/unsubscribe/AAHUprAoWZngQWMLNHKtYIc01mfr7-kiks5qJAligaJpZM4Ituf3\n> .\n",
"Yes, when I do these steps, the error always happens:\n1. Run my uwsgi server\n2. Do the first request, who will use peewee to do some queries etc\n3. I wait for three minutes (180 seconds) and do another request to my backend: everything works fine. When I do the third request to my backend is when the error happens. In this third request I get the error \"mysql server has gone away\". Also, I can do 20, 30 or even 40 request before the 180 seconds, but the second after this time, shit happens.\n\nMySQL configuration:\nwait_timeout 180\ninteractive_timeout 180\n\nMy peewee db settings:\n\n``` python\nimport peewee\n\ndatabase = PooledMySQLDatabase(settings.db_DBNAME, host=settings.db_HOST, user=settings.db_USER,\n passwd=settings.db_PASSWORD, max_connections=8, stale_timeout=110,\n threadlocals=True)\n\n```\n\nThe database don't receive any traffic, just these requests that I said.\n\nI tried to use the MySQLDatabase with this config:\n\n``` python\nfrom playhouse.shortcuts import RetryOperationalError\n\ndatabase = peewee.MySQLDatabase(settings.db_DBNAME, host=settings.db_HOST, user=settings.db_USER,\n passwd=settings.db_PASSWORD, threadlocals=True)\n\n```\n\nIt took more time (almost 10 minutes) to get the error, but it happened. \n",
"Doing more tests, it's seems that if I leave mysql \"without use\" the problem happens. If I call my backend frequently, the error don't happen. \n",
"Hi @coleifer, I fixed it creating a uwsgi spooler that hit my API and do a simple select in the database each 3 minutes. Now, I'll change the timeout configuration at MySQL to 8 hours (the default) and increase the frequency of my spooler. This is not a \"best practice\" solution, but it's the only thing that worked after almost 10 days trying everything. \n\nAnyway, very thank you for your effort creating the project and maintaining it. :+1: \n",
"Glad you found something that works...I'm not very familiar with MySQL and am not too sure what might be going on. At any rate, feel free to comment with new details if you find anything out!\n",
"I solved it in the following way:\r\n```\r\ndef refresh_db_connection(fn):\r\n # It's fix to avoid error \"MySQL was gone away\".\r\n # Here we check whether our current db connection is accessible or not (if not, refresh it)\r\n db.get_conn().ping(True)\r\n\r\n@refresh_db_connection\r\ndef register_nickname(nickname=\"\"):\r\n pass\r\n```\r\nJust handled the decorator to refresh the connection if it was closed."
] | 2016-06-03T17:10:56 | 2016-12-07T21:40:24 | 2016-06-07T13:32:16 | NONE | null | Hey guys,
I've been facing a problem with peewee in the last days. I'm getting these errors: "Lost connection to MySQL server during query" and "MySQL server has gone away". The problem happens after the timeout time configured on MySQL, I changed it to 120 seconds to test faster. This is my scenario:
I run the server and do the first request: everything works.
After 120 seconds I do the second request: I got the error message.
I read all the issues in github and read the documentation, but I can't figure out whats is going on.
I'm using webapp2 and before each request I have:
``` python
from functools import wraps
def database_connection(func):
@wraps(func)
def inner(*args, **kwargs):
database.connect()
try:
return func(*args, **kwargs)
finally:
if not database.is_closed():
database.close()
return inner
```
I'm using the connection pool:
``` python
import peewee, settings
from playhouse.pool import PooledMySQLDatabase
database = PooledMySQLDatabase(settings.db_DBNAME, host=settings.db_HOST, user=settings.db_USER,
passwd=settings.db_PASSWORD, max_connections=8, stale_timeout=110,
threadlocals=True)
class MySQLModel(peewee.Model):
class Meta:
database = database
```
I tried to use MyRetryDB(RetryOperationalError, PooledMySQLDatabase) but it didn't solved the problem.
PS: I'm using Google Cloud SQL as MySQL SaaS.
PS2: I'm using MySQL-python==1.2.3
Any help it would be awesome.
Thank for all your effort to develop this project :) :+1:
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/961/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/961/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/960 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/960/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/960/comments | https://api.github.com/repos/coleifer/peewee/issues/960/events | https://github.com/coleifer/peewee/pull/960 | 158,384,634 | MDExOlB1bGxSZXF1ZXN0NzI1MTkzMTY= | 960 | First limit 1 | {
"login": "keredson",
"id": 2049665,
"node_id": "MDQ6VXNlcjIwNDk2NjU=",
"avatar_url": "https://avatars.githubusercontent.com/u/2049665?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/keredson",
"html_url": "https://github.com/keredson",
"followers_url": "https://api.github.com/users/keredson/followers",
"following_url": "https://api.github.com/users/keredson/following{/other_user}",
"gists_url": "https://api.github.com/users/keredson/gists{/gist_id}",
"starred_url": "https://api.github.com/users/keredson/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/keredson/subscriptions",
"organizations_url": "https://api.github.com/users/keredson/orgs",
"repos_url": "https://api.github.com/users/keredson/repos",
"events_url": "https://api.github.com/users/keredson/events{/privacy}",
"received_events_url": "https://api.github.com/users/keredson/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I'd like to preserve the behavior where multiple calls to `first()` does not yield multiple queries. I _do_ agree, though, that there is benefit in applying a limit and that a second `peek()` method might more correctly. I've gone ahead and implemented this in a separate patch. You can compare notes to see how I've done this a bit differently: eeb6d4d727da8536906a00c490f94352465e90bb\n",
"+1\n"
] | 2016-06-03T14:49:42 | 2016-06-03T17:18:08 | 2016-06-03T16:34:11 | CONTRIBUTOR | null | for possible future inclusion (not 2.8.2) regarding https://github.com/coleifer/peewee/issues/959 or if anyone else wants to pull it into their forks.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/960/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/960/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/960",
"html_url": "https://github.com/coleifer/peewee/pull/960",
"diff_url": "https://github.com/coleifer/peewee/pull/960.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/960.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/958 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/958/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/958/comments | https://api.github.com/repos/coleifer/peewee/issues/958/events | https://github.com/coleifer/peewee/issues/958 | 158,278,165 | MDU6SXNzdWUxNTgyNzgxNjU= | 958 | get() should throw an error if more than one row exists | {
"login": "keredson",
"id": 2049665,
"node_id": "MDQ6VXNlcjIwNDk2NjU=",
"avatar_url": "https://avatars.githubusercontent.com/u/2049665?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/keredson",
"html_url": "https://github.com/keredson",
"followers_url": "https://api.github.com/users/keredson/followers",
"following_url": "https://api.github.com/users/keredson/following{/other_user}",
"gists_url": "https://api.github.com/users/keredson/gists{/gist_id}",
"starred_url": "https://api.github.com/users/keredson/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/keredson/subscriptions",
"organizations_url": "https://api.github.com/users/keredson/orgs",
"repos_url": "https://api.github.com/users/keredson/repos",
"events_url": "https://api.github.com/users/keredson/events{/privacy}",
"received_events_url": "https://api.github.com/users/keredson/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Sorry but that has always been a design decision I've liked, and I'm not going to change it.\n",
"This is documented anyways, did you even bother to read it?\n\nhttp://docs.peewee-orm.com/en/latest/peewee/api.html#Model.get\n",
"just because the quirkiness of the API is documented doesn't mean there isn't room for improvement. and i've seen no documentation/description on _why_ you like this this design decision over other alternatives.\n",
"Who do you think you are?\n\n> just because the quirkiness of the API is documented doesn't mean there isn't room for improvement.\n\nYou're judging the API as being _quirky_, but don't you think that's a bit rude or presumptuous, especially given that you've only been using the library for a very very short while?\n",
"> Who do you think you are?\n\na developer who generally likes your API, wants to use it and contribute back improvements. is that not welcome here?\n\nlooking back at your accepted external PRs i see many regarding minor bug fixes and documentation tweaks, but nothing beyond that, nor any other non-trivial collaborators. at the risk of being blunt: is this project just your baby/territory and all worthwhile ideas flow only from your brain, and all questions regarding even the most trivial design decisions personally offensive to you?\n",
"I think you've got it backwards. You're new to the project, yet have submitted 5 issues and 4 pull-requests. Three of these issues were not actual issues - in two cases you had not read the docs, and in another (failing tests) you didn't see that it had been patched almost 2 weeks ago with a very clear commit message. The other two (which includes this one), you state that you disagree with the semantics of methods **which are clearly documented**. You call the APIs quirky, or create issues with titles implying that the implementations are incorrect -- that rubs me the wrong way.\n\nRegarding the pull-requests, you submitted a patch I found to be functionally useless, inelegantly implemented, potentially inefficient, and error-prone (are you sure you got _all_ the SQL reserved words? what about differences in database engines? what about folks who want to add a backend for a new database that has additional reserved words?). Oh, and best of all, you got your 3 buddies at work to come by and put emojis on it...or maybe it's just a coincidence you're all from houston, tx (@smtheard, @neopunisher, @ajbisberg).\n\nYou even have the gall to tell me you think it's a bad idea for me to improve my library by rewriting parts of it for a new major version.\n\nDude, you've been here for like a week, you're embarrassing yourself.\n",
"The build is passing locally and on Travis ci.\n",
"This is why [Ecto](https://github.com/elixir-ecto/ecto) chose to rename `get` to `first`. \n"
] | 2016-06-03T02:19:41 | 2016-07-14T01:05:21 | 2016-06-03T02:34:32 | CONTRIBUTOR | null | ``` python
import peewee as pw
class Person(pw.Model):
name = pw.CharField()
class Meta:
database = db
alice = Person.create(name='Alice')
alice2 = Person.create(name='Alice')
print Person.get(Person.name=='Alice')
```
this generates the following SQL:
``` sql
SELECT "t1"."id", "t1"."name" FROM "person" AS t1
WHERE ("t1"."name" = ?) LIMIT 1 OFFSET 0
```
if the conditional criteria don't uniquely identify a record, you're effectively randomly choosing which row is returned to the user when the user has clearly indicated a belief that the record is unique. as is this method is simply a shorthand for `.first()`.
it's fairly common for this feature to be implemented with a `LIMIT 2`, where the lib will throw some sort of `NotUniqueException` if more than one row are returned.
i'll be happy to implement if you don't disagree with it on principal.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/958/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/958/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/957 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/957/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/957/comments | https://api.github.com/repos/coleifer/peewee/issues/957/events | https://github.com/coleifer/peewee/pull/957 | 158,208,878 | MDExOlB1bGxSZXF1ZXN0NzIzOTUwNTM= | 957 | refactor _joins to use a defaultdict | {
"login": "keredson",
"id": 2049665,
"node_id": "MDQ6VXNlcjIwNDk2NjU=",
"avatar_url": "https://avatars.githubusercontent.com/u/2049665?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/keredson",
"html_url": "https://github.com/keredson",
"followers_url": "https://api.github.com/users/keredson/followers",
"following_url": "https://api.github.com/users/keredson/following{/other_user}",
"gists_url": "https://api.github.com/users/keredson/gists{/gist_id}",
"starred_url": "https://api.github.com/users/keredson/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/keredson/subscriptions",
"organizations_url": "https://api.github.com/users/keredson/orgs",
"repos_url": "https://api.github.com/users/keredson/repos",
"events_url": "https://api.github.com/users/keredson/events{/privacy}",
"received_events_url": "https://api.github.com/users/keredson/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"hah! these unit tests are infuriating. not sure how to reproduce this locally. going to try some test commits...\n",
"How is this any better? I'm going to pass.\n",
"it's simpler and eliminates a class of bugs where one might forget to do the \"if (does this key exist?) append else set\" conditional check.\nhttps://docs.python.org/2/library/collections.html#defaultdict-objects\n"
] | 2016-06-02T18:31:07 | 2016-06-02T20:01:12 | 2016-06-02T19:46:11 | CONTRIBUTOR | null | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/957/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/957/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/957",
"html_url": "https://github.com/coleifer/peewee/pull/957",
"diff_url": "https://github.com/coleifer/peewee/pull/957.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/957.patch",
"merged_at": null
} |
|
https://api.github.com/repos/coleifer/peewee/issues/956 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/956/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/956/comments | https://api.github.com/repos/coleifer/peewee/issues/956/events | https://github.com/coleifer/peewee/issues/956 | 158,207,384 | MDU6SXNzdWUxNTgyMDczODQ= | 956 | unit test failures | {
"login": "keredson",
"id": 2049665,
"node_id": "MDQ6VXNlcjIwNDk2NjU=",
"avatar_url": "https://avatars.githubusercontent.com/u/2049665?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/keredson",
"html_url": "https://github.com/keredson",
"followers_url": "https://api.github.com/users/keredson/followers",
"following_url": "https://api.github.com/users/keredson/following{/other_user}",
"gists_url": "https://api.github.com/users/keredson/gists{/gist_id}",
"starred_url": "https://api.github.com/users/keredson/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/keredson/subscriptions",
"organizations_url": "https://api.github.com/users/keredson/orgs",
"repos_url": "https://api.github.com/users/keredson/repos",
"events_url": "https://api.github.com/users/keredson/events{/privacy}",
"received_events_url": "https://api.github.com/users/keredson/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"This was fixed on May 20th, e4bd8e6cb04abc826143ac64dfd9ef1bc186f070\n",
"ic, thanks.\n\ni'm still getting 4 failures in `playhouse.tests.test_extra_fields`:\n\n```\n======================================================================\nERROR: test_valid_password (playhouse.tests.test_extra_fields.TestPasswordFields)\n----------------------------------------------------------------------\nTraceback (most recent call last):\n File \"/home/derek/projects/peewee/playhouse/tests/test_extra_fields.py\", line 143, in setUp\n super(TestPasswordFields, self).setUp()\n File \"/home/derek/projects/peewee/playhouse/tests/base.py\", line 285, in setUp\n test_db.create_tables(self.requires)\n File \"/home/derek/projects/peewee/peewee.py\", line 3574, in create_tables\n create_model_tables(models, fail_silently=safe)\n File \"/home/derek/projects/peewee/peewee.py\", line 4940, in create_model_tables\n m.create_table(**create_table_kwargs)\n File \"/home/derek/projects/peewee/peewee.py\", line 4624, in create_table\n db.create_table(cls)\n File \"/home/derek/projects/peewee/peewee.py\", line 3571, in create_table\n return self.execute_sql(*qc.create_table(model_class, safe))\n File \"/home/derek/projects/peewee/peewee.py\", line 3492, in execute_sql\n self.commit()\n File \"/home/derek/projects/peewee/peewee.py\", line 3316, in __exit__\n reraise(new_type, new_type(*exc_args), traceback)\n File \"/home/derek/projects/peewee/peewee.py\", line 3485, in execute_sql\n cursor.execute(sql, params or ())\nOperationalError: attempt to write a readonly database\n```\n\nboth off of 2.8.1 w/ that commit cherry-picked, and your current master.\n"
] | 2016-06-02T18:24:03 | 2016-06-03T01:56:02 | 2016-06-02T19:44:16 | CONTRIBUTOR | null | i keep getting semi-random failures in the test suite. example:
```
======================================================================
ERROR: test_array_iterables (playhouse.tests.test_postgres.TestArrayField)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/derek/projects/peewee/playhouse/tests/base.py", line 285, in setUp
test_db.create_tables(self.requires)
File "/home/derek/projects/peewee/peewee.py", line 3574, in create_tables
create_model_tables(models, fail_silently=safe)
File "/home/derek/projects/peewee/peewee.py", line 4940, in create_model_tables
m.create_table(**create_table_kwargs)
File "/home/derek/projects/peewee/peewee.py", line 4624, in create_table
db.create_table(cls)
File "/home/derek/projects/peewee/peewee.py", line 3571, in create_table
return self.execute_sql(*qc.create_table(model_class, safe))
File "/home/derek/projects/peewee/peewee.py", line 3492, in execute_sql
self.commit()
File "/home/derek/projects/peewee/peewee.py", line 3316, in __exit__
reraise(new_type, new_type(*exc_args), traceback)
File "/home/derek/projects/peewee/peewee.py", line 3485, in execute_sql
cursor.execute(sql, params or ())
OperationalError: attempt to write a readonly database
```
which is very odd as it's happening testing the sqlite engine:
```
$ python runtests.py -a -e sqlite
```
all the failures are in the `test_postgres` module. are they supposed to run at all when testing the sqlite engine?
debugging shows it's not able to write to `/tmp/peewee_test.db`, which i do have permission to write to:
```
$ ls -l /tmp/peewee_test.db
-rw-r--r-- 1 derek derek 52224 Jun 2 13:13 /tmp/peewee_test.db
```
has anyone run across this before? this is happening on a clean copy of 2.8.1 (7670c9e).
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/956/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/956/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/955 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/955/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/955/comments | https://api.github.com/repos/coleifer/peewee/issues/955/events | https://github.com/coleifer/peewee/issues/955 | 158,046,561 | MDU6SXNzdWUxNTgwNDY1NjE= | 955 | Support MySQL 5.7 JSON data type | {
"login": "ibushong",
"id": 9298422,
"node_id": "MDQ6VXNlcjkyOTg0MjI=",
"avatar_url": "https://avatars.githubusercontent.com/u/9298422?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/ibushong",
"html_url": "https://github.com/ibushong",
"followers_url": "https://api.github.com/users/ibushong/followers",
"following_url": "https://api.github.com/users/ibushong/following{/other_user}",
"gists_url": "https://api.github.com/users/ibushong/gists{/gist_id}",
"starred_url": "https://api.github.com/users/ibushong/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/ibushong/subscriptions",
"organizations_url": "https://api.github.com/users/ibushong/orgs",
"repos_url": "https://api.github.com/users/ibushong/repos",
"events_url": "https://api.github.com/users/ibushong/events{/privacy}",
"received_events_url": "https://api.github.com/users/ibushong/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"No plans on my part, but I would be willing to accept a patch that implemented it somewhat along the same lines as the `postgres_ext` or `sqlite_ext` playhouse modules.\n"
] | 2016-06-02T02:25:16 | 2016-06-02T12:38:24 | 2016-06-02T12:38:24 | NONE | null | Is there plan to support the [JSON](https://dev.mysql.com/doc/refman/5.7/en/json.html) data type introduced in MySQL 5.7?
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/955/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/955/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/954 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/954/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/954/comments | https://api.github.com/repos/coleifer/peewee/issues/954/events | https://github.com/coleifer/peewee/issues/954 | 157,977,771 | MDU6SXNzdWUxNTc5Nzc3NzE= | 954 | Can not use PickledField with database proxy | {
"login": "alexpantyukhin",
"id": 6513121,
"node_id": "MDQ6VXNlcjY1MTMxMjE=",
"avatar_url": "https://avatars.githubusercontent.com/u/6513121?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/alexpantyukhin",
"html_url": "https://github.com/alexpantyukhin",
"followers_url": "https://api.github.com/users/alexpantyukhin/followers",
"following_url": "https://api.github.com/users/alexpantyukhin/following{/other_user}",
"gists_url": "https://api.github.com/users/alexpantyukhin/gists{/gist_id}",
"starred_url": "https://api.github.com/users/alexpantyukhin/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/alexpantyukhin/subscriptions",
"organizations_url": "https://api.github.com/users/alexpantyukhin/orgs",
"repos_url": "https://api.github.com/users/alexpantyukhin/repos",
"events_url": "https://api.github.com/users/alexpantyukhin/events{/privacy}",
"received_events_url": "https://api.github.com/users/alexpantyukhin/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Fixed in b2d52ba7973e6d980ed9efae36322c16e9fec074 see #933 \n"
] | 2016-06-01T18:39:00 | 2016-06-01T20:19:18 | 2016-06-01T20:19:18 | NONE | null | The following code raise an error
``` python
from peewee import *
from playhouse.fields import *
database_proxy = Proxy()
db = SqliteDatabase('test.db')
class BaseModel(Model):
class Meta:
database = database_proxy
class TestModel(BaseModel):
data = PickledField()
database_proxy.initialize(db)
db.create_tables([TestModel])
```
the error:
`raise AttributeError('Cannot use uninitialized Proxy.')`
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/954/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/954/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/953 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/953/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/953/comments | https://api.github.com/repos/coleifer/peewee/issues/953/events | https://github.com/coleifer/peewee/issues/953 | 157,968,300 | MDU6SXNzdWUxNTc5NjgzMDA= | 953 | joining on two FKs to the same table doesn't work | {
"login": "keredson",
"id": 2049665,
"node_id": "MDQ6VXNlcjIwNDk2NjU=",
"avatar_url": "https://avatars.githubusercontent.com/u/2049665?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/keredson",
"html_url": "https://github.com/keredson",
"followers_url": "https://api.github.com/users/keredson/followers",
"following_url": "https://api.github.com/users/keredson/following{/other_user}",
"gists_url": "https://api.github.com/users/keredson/gists{/gist_id}",
"starred_url": "https://api.github.com/users/keredson/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/keredson/subscriptions",
"organizations_url": "https://api.github.com/users/keredson/orgs",
"repos_url": "https://api.github.com/users/keredson/repos",
"events_url": "https://api.github.com/users/keredson/events{/privacy}",
"received_events_url": "https://api.github.com/users/keredson/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"You need to use a model alias. See the [querying docs -- using model aliases](http://docs.peewee-orm.com/en/latest/peewee/querying.html?highlight=modelalias#using-model-aliases)\n\n``` python\nAuthor = Person.alias()\nEditor = Person.alias()\nquery = (Post\n .select(Post, Author, Editor)\n .join(Author, on=(Post.author == Author.id))\n .switch(Post)\n .join(Editor, on=(Post.editor == Editor.id)))\n```\n",
"ok, that second version works, but there is still a bug here. an ORM api should not generate obviously invalid SQL.\n",
"> but there is still a bug here\n\nIn your opinion there is, in my opinion this is documented behavior. If you want to use a model and have it aliased to multiple aliases, you need to call `Model.alias()`.\n",
"```\nPost.select(Post) \\\n .join(Person, on=Post.author).switch(Post) \\\n .join(Person, on=Post.editor)\n```\n\ngens non-nonsensical SQL. how is non-nonsensical SQL not a bug? there is no possible use case for having your lib generate duplicate table aliases.\n"
] | 2016-06-01T17:53:25 | 2016-06-05T00:16:18 | 2016-06-01T19:38:57 | CONTRIBUTOR | null | gens bad SQL:
``` python
import logging, os
import peewee as pw
logger = logging.getLogger('peewee')
logger.setLevel(logging.DEBUG)
logger.addHandler(logging.StreamHandler())
db_fn = 'example.db'
if os.path.exists(db_fn): os.remove(db_fn)
db = pw.SqliteDatabase(db_fn)
class Person(pw.Model):
name = pw.CharField()
class Meta:
database = db
class Post(pw.Model):
title = pw.CharField()
author = pw.ForeignKeyField(db_column='author_id', rel_model=Person, to_field='id')
editor = pw.ForeignKeyField(db_column='editor_id', rel_model=Person, to_field='id', related_name='edited_posts', null=True)
class Meta:
database = db
db.connect()
db.create_tables([Person, Post])
alice = Person.create(name='Alice')
bob = Person.create(name='Bob')
post = Post.create(title='My Post', author=alice, editor=bob)
for post in Post.select(Post).join(Person, on=Post.author).switch(Post).join(Person, on=Post.editor):
print post #, post.author, post.editor
```
gens:
```
$ python test2.py
[...]
('INSERT INTO "person" ("name") VALUES (?)', [u'Alice'])
('INSERT INTO "person" ("name") VALUES (?)', [u'Bob'])
('INSERT INTO "post" ("title", "author_id", "editor_id") VALUES (?, ?, ?)', [u'My Post', 1, 2])
('SELECT "t1"."id", "t1"."title", "t1"."author_id", "t1"."editor_id" FROM "post" AS t1 INNER JOIN "person" AS t2 ON ("t1"."author_id" = "t2"."id") INNER JOIN "person" AS t2 ON ("t1"."editor_id" = "t2"."id")', [])
```
notice the join conditions are right but the table aliases conflict.
i have a potential fix but i wanted an opinion if i'm using the API wrong somehow.
this is with the latest release:
```
$ git status
HEAD detached at 7670c9e
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/953/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/953/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/952 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/952/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/952/comments | https://api.github.com/repos/coleifer/peewee/issues/952/events | https://github.com/coleifer/peewee/pull/952 | 157,949,627 | MDExOlB1bGxSZXF1ZXN0NzIyMTA4NTk= | 952 | make genned table aliases more human-friendly | {
"login": "keredson",
"id": 2049665,
"node_id": "MDQ6VXNlcjIwNDk2NjU=",
"avatar_url": "https://avatars.githubusercontent.com/u/2049665?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/keredson",
"html_url": "https://github.com/keredson",
"followers_url": "https://api.github.com/users/keredson/followers",
"following_url": "https://api.github.com/users/keredson/following{/other_user}",
"gists_url": "https://api.github.com/users/keredson/gists{/gist_id}",
"starred_url": "https://api.github.com/users/keredson/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/keredson/subscriptions",
"organizations_url": "https://api.github.com/users/keredson/orgs",
"repos_url": "https://api.github.com/users/keredson/repos",
"events_url": "https://api.github.com/users/keredson/events{/privacy}",
"received_events_url": "https://api.github.com/users/keredson/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I'm going to pass on this one as well. Seems like a special-case that really isn't that special. If you want to see an example of a custom query compiler, check out the tests -- there is one that will use the table name instead of `t{\\d}`.\n",
"this is just totally bizarre to me. why would you **prefer** meaningless table alias names? what possible benefit is that?\n",
"If you're concerned about table aliases, you can always specify a default to use with a given model. Again, this is [documented](http://docs.peewee-orm.com/en/latest/peewee/models.html?highlight=table_alias#model-options-and-table-metadata).\n\n``` python\nclass MyModel(Model):\n class Meta:\n table_alias = 'mm'\n```\n\nAnd @keredson tell your little buddies their emojis are really not helping anybody.\n",
"> this is just totally bizarre to me. why would you prefer meaningless table alias names? what possible benefit is that?\n\nCan you please dial down your outrage? Can you dial down your tone? It's not helpful.\n",
"For posterity, this is not a bad idea in that using the table's name to create the alias will make the SQL more easy to scan. It was for the following reasons I decided not to merge this:\r\n\r\n* Requires the addition of code to \"fix\" something that is technically not broken.\r\n* The purpose of Peewee is to abstract away the process of writing SQL.\r\n* You can explicitly set a model's table alias per-query or globally using existing APIs.\r\n* The implementation is (subjectively) gross.\r\n* Requires rewriting a huge number of test assertions.\r\n\r\nAnother misguided PR, not aligned with peewee's goals or aesthetic."
] | 2016-06-01T16:22:09 | 2017-05-17T04:46:12 | 2016-06-01T19:43:51 | CONTRIBUTOR | null | instead of: `select t1.id from ledger_entry as t1`
generate the alias from the table name: `select le1.id from ledger_entry as le1`
where the alias is an acronym of the table name. makes it easier to read large joins w/ many tables.
@coleifer unit tests not updated yet. i want to know if you're ok-with/opposed to this before i spend the time on that part.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/952/reactions",
"total_count": 1,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 1,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/952/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/952",
"html_url": "https://github.com/coleifer/peewee/pull/952",
"diff_url": "https://github.com/coleifer/peewee/pull/952.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/952.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/951 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/951/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/951/comments | https://api.github.com/repos/coleifer/peewee/issues/951/events | https://github.com/coleifer/peewee/pull/951 | 157,833,192 | MDExOlB1bGxSZXF1ZXN0NzIxMjkyMDA= | 951 | workaround for issue 820 | {
"login": "dhaase-de",
"id": 12261985,
"node_id": "MDQ6VXNlcjEyMjYxOTg1",
"avatar_url": "https://avatars.githubusercontent.com/u/12261985?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/dhaase-de",
"html_url": "https://github.com/dhaase-de",
"followers_url": "https://api.github.com/users/dhaase-de/followers",
"following_url": "https://api.github.com/users/dhaase-de/following{/other_user}",
"gists_url": "https://api.github.com/users/dhaase-de/gists{/gist_id}",
"starred_url": "https://api.github.com/users/dhaase-de/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/dhaase-de/subscriptions",
"organizations_url": "https://api.github.com/users/dhaase-de/orgs",
"repos_url": "https://api.github.com/users/dhaase-de/repos",
"events_url": "https://api.github.com/users/dhaase-de/events{/privacy}",
"received_events_url": "https://api.github.com/users/dhaase-de/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Is this the right check? I had been operating on the assumption that if Cython was present but too old, that peewee would raise an exception.\n",
"Yes, I believe this is the right check.\n\nCurrently, `peewee` can't even be installed under vanilla Debian 8 with Python 3.4.2 and Cython 0.21.1 installed:\n\n**via pip:**\n\n``` bash\n$ pip3 install peewee\nDownloading/unpacking peewee\n Downloading peewee-2.8.1.tar.gz (474kB): 474kB downloaded\n Running setup.py (path:/tmp/pip-build-oy3l4ssv/peewee/setup.py) egg_info for package peewee\n /tmp/pip-build-oy3l4ssv/peewee/setup.py:17: UserWarning: Your Cython appears to be an older version. You may need to upgrade Cython in order to build the peewee C extensions.\n warnings.warn('Your Cython appears to be an older version. You may '\n\nInstalling collected packages: peewee\n Running setup.py install for peewee\n cythoning playhouse/_speedups.pyx to playhouse/_speedups.c\n building 'playhouse._speedups' extension\n x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector-strong -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/python3.4m -c playhouse/_speedups.c -o build/temp.linux-x86_64-3.4/playhouse/_speedups.o\n playhouse/_speedups.c:1:2: error: #error Do not use this file, it is the result of a failed Cython compilation.\n #error Do not use this file, it is the result of a failed Cython compilation.\n ^\n /tmp/pip-build-oy3l4ssv/peewee/setup.py:17: UserWarning: Your Cython appears to be an older version. You may need to upgrade Cython in order to build the peewee C extensions.\n warnings.warn('Your Cython appears to be an older version. You may '\n\n Error compiling Cython file:\n ------------------------------------------------------------\n ...\n cdef:\n set model_set = set(models)\n set seen = set()\n list accum = []\n\n for model in sorted(model_set, key=_sort_key, reverse=True):\n ^\n ------------------------------------------------------------\n\n playhouse/_speedups.pyx:318:48: Cannot convert 'tuple (object)' to Python object\n error: command 'x86_64-linux-gnu-gcc' failed with exit status 1\n Complete output from command /usr/bin/python3 -c \"import setuptools, tokenize;__file__='/tmp/pip-build-oy3l4ssv/peewee/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\\r\\n', '\\n'), __file__, 'exec'))\" install --record /tmp/pip-8z0qr59j-record/install-record.txt --single-version-externally-managed --compile:\n running install\n\nrunning build\n\nrunning build_py\n\ncreating build\n\ncreating build/lib.linux-x86_64-3.4\n\ncopying peewee.py -> build/lib.linux-x86_64-3.4\n\ncopying pwiz.py -> build/lib.linux-x86_64-3.4\n\ncreating build/lib.linux-x86_64-3.4/playhouse\n\ncopying playhouse/dataset.py -> build/lib.linux-x86_64-3.4/playhouse\n\ncopying playhouse/sqlcipher_ext.py -> build/lib.linux-x86_64-3.4/playhouse\n\ncopying playhouse/apsw_ext.py -> build/lib.linux-x86_64-3.4/playhouse\n\ncopying playhouse/signals.py -> build/lib.linux-x86_64-3.4/playhouse\n\ncopying playhouse/shortcuts.py -> build/lib.linux-x86_64-3.4/playhouse\n\ncopying playhouse/__init__.py -> build/lib.linux-x86_64-3.4/playhouse\n\ncopying playhouse/kv.py -> build/lib.linux-x86_64-3.4/playhouse\n\ncopying playhouse/test_utils.py -> build/lib.linux-x86_64-3.4/playhouse\n\ncopying playhouse/sqlite_udf.py -> build/lib.linux-x86_64-3.4/playhouse\n\ncopying playhouse/flask_utils.py -> build/lib.linux-x86_64-3.4/playhouse\n\ncopying playhouse/hybrid.py -> build/lib.linux-x86_64-3.4/playhouse\n\ncopying playhouse/migrate.py -> build/lib.linux-x86_64-3.4/playhouse\n\ncopying playhouse/db_url.py -> build/lib.linux-x86_64-3.4/playhouse\n\ncopying playhouse/csv_utils.py -> build/lib.linux-x86_64-3.4/playhouse\n\ncopying playhouse/pool.py -> build/lib.linux-x86_64-3.4/playhouse\n\ncopying playhouse/reflection.py -> build/lib.linux-x86_64-3.4/playhouse\n\ncopying playhouse/djpeewee.py -> build/lib.linux-x86_64-3.4/playhouse\n\ncopying playhouse/read_slave.py -> build/lib.linux-x86_64-3.4/playhouse\n\ncopying playhouse/berkeleydb.py -> build/lib.linux-x86_64-3.4/playhouse\n\ncopying playhouse/csv_loader.py -> build/lib.linux-x86_64-3.4/playhouse\n\ncopying playhouse/postgres_ext.py -> build/lib.linux-x86_64-3.4/playhouse\n\ncopying playhouse/fields.py -> build/lib.linux-x86_64-3.4/playhouse\n\ncopying playhouse/sqlite_ext.py -> build/lib.linux-x86_64-3.4/playhouse\n\ncopying playhouse/gfk.py -> build/lib.linux-x86_64-3.4/playhouse\n\nrunning build_ext\n\ncythoning playhouse/_speedups.pyx to playhouse/_speedups.c\n\nbuilding 'playhouse._speedups' extension\n\ncreating build/temp.linux-x86_64-3.4\n\ncreating build/temp.linux-x86_64-3.4/playhouse\n\nx86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector-strong -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/python3.4m -c playhouse/_speedups.c -o build/temp.linux-x86_64-3.4/playhouse/_speedups.o\n\nplayhouse/_speedups.c:1:2: error: #error Do not use this file, it is the result of a failed Cython compilation.\n\n #error Do not use this file, it is the result of a failed Cython compilation.\n\n ^\n\n/tmp/pip-build-oy3l4ssv/peewee/setup.py:17: UserWarning: Your Cython appears to be an older version. You may need to upgrade Cython in order to build the peewee C extensions.\n\n warnings.warn('Your Cython appears to be an older version. You may '\n\n\n\nError compiling Cython file:\n\n------------------------------------------------------------\n\n...\n\n cdef:\n\n set model_set = set(models)\n\n set seen = set()\n\n list accum = []\n\n\n\n for model in sorted(model_set, key=_sort_key, reverse=True):\n\n ^\n\n------------------------------------------------------------\n\n\n\nplayhouse/_speedups.pyx:318:48: Cannot convert 'tuple (object)' to Python object\n\nerror: command 'x86_64-linux-gnu-gcc' failed with exit status 1\n\n----------------------------------------\nCleaning up...\nCommand /usr/bin/python3 -c \"import setuptools, tokenize;__file__='/tmp/pip-build-oy3l4ssv/peewee/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\\r\\n', '\\n'), __file__, 'exec'))\" install --record /tmp/pip-8z0qr59j-record/install-record.txt --single-version-externally-managed --compile failed with error code 1 in /tmp/pip-build-oy3l4ssv/peewee\nStoring debug log for failure in /home/dh/.pip/pip.log\n```\n\n**via install.py**\n\n``` bash\n$ python3 setup.py install --user\nsetup.py:17: UserWarning: Your Cython appears to be an older version. You may need to upgrade Cython in order to build the peewee C extensions.\n warnings.warn('Your Cython appears to be an older version. You may '\nrunning install\nrunning build\nrunning build_py\ncreating build/lib.linux-x86_64-3.4\ncopying peewee.py -> build/lib.linux-x86_64-3.4\ncopying pwiz.py -> build/lib.linux-x86_64-3.4\ncreating build/lib.linux-x86_64-3.4/playhouse\ncopying playhouse/dataset.py -> build/lib.linux-x86_64-3.4/playhouse\ncopying playhouse/sqlcipher_ext.py -> build/lib.linux-x86_64-3.4/playhouse\ncopying playhouse/apsw_ext.py -> build/lib.linux-x86_64-3.4/playhouse\ncopying playhouse/signals.py -> build/lib.linux-x86_64-3.4/playhouse\ncopying playhouse/shortcuts.py -> build/lib.linux-x86_64-3.4/playhouse\ncopying playhouse/__init__.py -> build/lib.linux-x86_64-3.4/playhouse\ncopying playhouse/kv.py -> build/lib.linux-x86_64-3.4/playhouse\ncopying playhouse/test_utils.py -> build/lib.linux-x86_64-3.4/playhouse\ncopying playhouse/sqlite_udf.py -> build/lib.linux-x86_64-3.4/playhouse\ncopying playhouse/flask_utils.py -> build/lib.linux-x86_64-3.4/playhouse\ncopying playhouse/hybrid.py -> build/lib.linux-x86_64-3.4/playhouse\ncopying playhouse/migrate.py -> build/lib.linux-x86_64-3.4/playhouse\ncopying playhouse/db_url.py -> build/lib.linux-x86_64-3.4/playhouse\ncopying playhouse/csv_utils.py -> build/lib.linux-x86_64-3.4/playhouse\ncopying playhouse/pool.py -> build/lib.linux-x86_64-3.4/playhouse\ncopying playhouse/reflection.py -> build/lib.linux-x86_64-3.4/playhouse\ncopying playhouse/djpeewee.py -> build/lib.linux-x86_64-3.4/playhouse\ncopying playhouse/read_slave.py -> build/lib.linux-x86_64-3.4/playhouse\ncopying playhouse/berkeleydb.py -> build/lib.linux-x86_64-3.4/playhouse\ncopying playhouse/csv_loader.py -> build/lib.linux-x86_64-3.4/playhouse\ncopying playhouse/postgres_ext.py -> build/lib.linux-x86_64-3.4/playhouse\ncopying playhouse/fields.py -> build/lib.linux-x86_64-3.4/playhouse\ncopying playhouse/sqlite_ext.py -> build/lib.linux-x86_64-3.4/playhouse\ncopying playhouse/gfk.py -> build/lib.linux-x86_64-3.4/playhouse\nrunning build_ext\ncythoning playhouse/_speedups.pyx to playhouse/_speedups.c\n\nError compiling Cython file:\n------------------------------------------------------------\n...\n cdef:\n set model_set = set(models)\n set seen = set()\n list accum = []\n\n for model in sorted(model_set, key=_sort_key, reverse=True):\n ^\n------------------------------------------------------------\n\nplayhouse/_speedups.pyx:330:48: Cannot convert 'tuple (object)' to Python object\nbuilding 'playhouse._speedups' extension\ncreating build/temp.linux-x86_64-3.4\ncreating build/temp.linux-x86_64-3.4/playhouse\nx86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector-strong -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/python3.4m -c playhouse/_speedups.c -o build/temp.linux-x86_64-3.4/playhouse/_speedups.o\nplayhouse/_speedups.c:1:2: error: #error Do not use this file, it is the result of a failed Cython compilation.\n #error Do not use this file, it is the result of a failed Cython compilation.\n ^\nerror: command 'x86_64-linux-gnu-gcc' failed with exit status 1\n```\n\nSo `peewee` dosn't even get to the point of raising an exception. The installation fails during Cython compilation.\n\nAnd here is the result after the proposed fix:\n\n``` bash\n$ python3 setup.py install --user\nsetup.py:19: UserWarning: Your Cython appears to be an older version. You may need to upgrade Cython in order to build the peewee C extensions. For now, Cython support is disabled.\n warnings.warn('Your Cython appears to be an older version. You may '\nrunning install\nrunning build\nrunning build_py\nrunning build_scripts\nrunning install_lib\nrunning install_scripts\nchanging mode of /home/dh/.local/bin/pwiz.py to 755\nrunning install_egg_info\nWriting /home/dh/.local/lib/python3.4/site-packages/peewee-2.8.1.egg-info\n```\n",
"I see...Maybe you can make the warning state clearly that even though you have Cython, the extensions are **not** being built?\n",
"Ok, there are now two warning messages (Cython not installed, Cython too old) which clearly state that Cython extensions will not be built.\n",
"Noice. Thanks!\n"
] | 2016-06-01T06:32:10 | 2016-06-02T12:32:04 | 2016-06-02T12:32:04 | CONTRIBUTOR | null | For me, issue #820 wasn't really solved yet - I run Debian 8 (stable) on several machines, and it comes with Cython 0.21.1. Because I want to keep program versions on my machines in sync, I tend to not install newer versions manually. This commit proposes a workaround for issue #820 which disables Cython support for Cython versions below 0.22.1.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/951/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/951/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/951",
"html_url": "https://github.com/coleifer/peewee/pull/951",
"diff_url": "https://github.com/coleifer/peewee/pull/951.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/951.patch",
"merged_at": "2016-06-02T12:32:04"
} |
https://api.github.com/repos/coleifer/peewee/issues/950 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/950/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/950/comments | https://api.github.com/repos/coleifer/peewee/issues/950/events | https://github.com/coleifer/peewee/pull/950 | 157,791,517 | MDExOlB1bGxSZXF1ZXN0NzIxMDA5NjY= | 950 | don't unnecessarily quote entities | {
"login": "keredson",
"id": 2049665,
"node_id": "MDQ6VXNlcjIwNDk2NjU=",
"avatar_url": "https://avatars.githubusercontent.com/u/2049665?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/keredson",
"html_url": "https://github.com/keredson",
"followers_url": "https://api.github.com/users/keredson/followers",
"following_url": "https://api.github.com/users/keredson/following{/other_user}",
"gists_url": "https://api.github.com/users/keredson/gists{/gist_id}",
"starred_url": "https://api.github.com/users/keredson/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/keredson/subscriptions",
"organizations_url": "https://api.github.com/users/keredson/orgs",
"repos_url": "https://api.github.com/users/keredson/repos",
"events_url": "https://api.github.com/users/keredson/events{/privacy}",
"received_events_url": "https://api.github.com/users/keredson/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Human-friendly? What the hell does that mean \n",
"example: `select t1.id from posts as t1`\ninstead of: `select \"t1\".\"id\" from \"posts\" as \"t1\"`\n\nhelps esp. w/ longer queries. (obviously identifiers that need them would still be quoted.)\n",
"I'd debate the merits of dropping the quotes...seems like they provide safety guarantees that would require some bad workarounds if dropped.\n",
"Plus, I'm working on a rewrite for 3.0 that will make all this work moot.\n",
"hmmm. i can't replicate the travis error locally:\n`ERROR: test_granular_transaction (playhouse.tests.test_sqlite_ext.TestUserDefinedCallbacks)`\ncan you?\n\n> Plus, I'm working on a rewrite for 3.0 that will make all this work moot.\n\nit wasn't supposed to be a lot of work - i've mostly been fighting the unit tests. (string comparisons are so frustratingly fragile...)\n\nhow extensive is this rewrite? would just about any enhancement be moot then? what's the timeframe?\n\n> I'd debate the merits of dropping the quotes...\n\nfrom experience it is well worth it. the more you can make your sql look like what you'd normally type the easier it is to debug (both the lib and the code using the lib). even stuff like making the table aliases something other than `t1`...`t8` goes a long way towards usability.\n",
"> from experience it is well worth it. the more you can make your sql look like what you'd normally type the easier it is to debug (both the lib and the code using the lib). even stuff like making the table aliases something other than t1...t8 goes a long way towards usability.\n\nI think that a change like this, for the purposes of readability, could better be handled by a logging formatter or something similar.\n",
"> how extensive is this rewrite? would just about any enhancement be moot then? what's the timeframe?\n\nComplete rewrite, more or less. From the point of view of the SQL generation, it's 100% new code.\n",
"> Complete rewrite, more or less. From the point of view of the SQL generation, it's 100% new code.\n\nthat's scary. why? (is there something broken w/ the current code?) is the API going to change too? also: where? i don't see an obvious branch for it.\n\nyou seem to have a sizable user base here. a 100% rewrite of the core of your ORM is a pretty drastic measure.\n",
"> that's scary. why? ...more questions...\n\nBecause I know how to implement it in a much cleaner, more robust way.\n\nI'll try to preserve the APIs, though there are some that may change because the current APIs are confusing. Probably nothing major in the actual query building APIs but I'm not positive yet.\n\nI haven't pushed the code because it's not ready for people to look at yet.\n\n> you seem to have a sizable user base here. a 100% rewrite of the core of your ORM is a pretty drastic measure.\n\nI rewrote it for 2.0 and the improvements were massive.\n\nFurthermore, the entire line of your questions comes off as extremely entitled and presumptuous.\n",
"> Furthermore, the entire line of your questions comes off as extremely entitled and presumptuous.\n\nwasn't intending any offense. just trying to understand the lay of the land and plan future development. just one more question then:\n\nif there is a (currently totally private) pending 3.0 re-write, are you not accepting any external PRs until that is complete? and if so, is there an ETA on when 3.0 will be made public?\n",
"I'm certainly accepting prs, but I don't think this particular pr is one I'd want to merge. No timeline but I'll definitely document the changes and make an announcement when it's closer.\n",
"fair enough. mind if i ask what could make it better? micro-benchmarks showing the quote method is still performant, or other improvements to the quality of the PR? or is it the goal of the PR you've no interest in?\n",
"Well, at first I noticed what seemed to me to be a potential performance issue. But when I thought about it, the implementation just doesn't seem elegant and the same could be easily accomplished without modifying existing logic...ie logging handler, custom query compiler etc\n",
"ignoring the unit test changes it's like 13 lines of code. that seems fairly simple to me. :)\n\na logging handler is a bad approach, as it's effectively going to have to implement a SQL parser to be accurate. plus the point of logging is to know exactly what was sent to the database, not some munged copy of it.\n\na custom query compiler is more palatable. but does anyone actually _want_ all the quotes? i can't imagine why they would, and if that's true it makes more sense to just change the default behavior.\n\nif the concern is safety, the quoting/no-quoting rule as implemented covers all the supported databases. See:\n\nPostgres:\n\n> SQL identifiers and key words must begin with a letter (a-z, but also letters with diacritical marks and non-Latin letters) or an underscore (_). Subsequent characters in an identifier or key word can be letters, underscores, digits (0-9), or dollar signs ($).\n\nMysql:\n\n> Backticks are to be used for table and column identifiers, but are only necessary when the identifier is a MySQL reserved keyword, or when the identifier contains whitespace characters or characters beyond a limited set (see below)\n\nSQLite:\nI can't find an official spec (http://www.sqlite.org/lang_createtable.html is the closest i found) but many stackoverflow comments suggest the same rule (alphanumeric+underscore, starting w/ an alpha).\n\ni also just updated the reserved keyword set to have complete coverage over postgres/mysql/sqlite3/mssql: https://github.com/keredson/peewee/commit/0068226e1f77f589f0acf4c7457624138b854ed6\n\nmore generally, do you really not see the usability gain here? isn't this:\n\n``` sql\nSELECT c1.id, c1.blog_id, c1.comment \nFROM comment AS c1 \nWHERE (c1.blog_id IN (\n SELECT b1.pk \n FROM blog AS b1 \n WHERE (b1.user_id IN (\n SELECT u1.id \n FROM users AS u1 \n LEFT OUTER JOIN blog AS b2 ON (u1.id = b2.user_id) \n ORDER BY u1.id\n ))\n))\n```\n\nclearly more readable than this?\n\n``` sql\nSELECT \"t1\".\"id\", \"t1\".\"blog_id\", \"t1\".\"comment\" \nFROM \"comment\" AS t1 \nWHERE (\"t1\".\"blog_id\" IN (\n SELECT \"t2\".\"pk\" \n FROM \"blog\" AS t2 \n WHERE (\"t2\".\"user_id\" IN (\n SELECT \"t3\".\"id\" \n FROM \"users\" AS t3 \n LEFT OUTER JOIN \"blog\" AS t4 ON (\"t3\".\"id\" = \"t4\".\"user_id\") \n ORDER BY \"t3\".\"id\"\n ))\n))\n```\n\ni understand it's kind of tedious/shit programming and you've probably personally got better things to work on, but when you've got someone volunteering to shovel it for you... :)\n",
"It's not so readable as to warrant the code changes, no. Not in my opinion. Having a list of SQL reserved words is awful. Using a regex on every single entity is _awful_. Dude, seriously. You can strip the quotes using a log handler or a custom query compiler. Jesus.\n",
"> Having a list of SQL reserved words is awful.\n\nthis is a database ORM. why is it being aware of SQL reserved words awful?\n\n> Using a regex on every single entity is awful.\n\njust stating an \"it's bad\" opinion without any explanation of why is of little use. you've already conceded your original performance concern is likely unwarranted. you use `re` elsewhere, so you're clearly not opposed to them in general. regex seems a reasonable solution to a \"does this string follow these rules?\" conditional to me.\n",
"I never concede! It's still an issue. But even if it weren't, these changes still are bad.\n",
"> I never concede! It's still an issue.\n\njoking aside, that's a concern i can work with! :)\n\nhere's with the quoting regex (and set check):\n\n```\n$ python test_quote_speed.py \n10000 loops, 11.901063 total time, 0.001190 per iteration\n$ python test_quote_speed.py \n10000 loops, 11.715667 total time, 0.001172 per iteration\n$ python test_quote_speed.py \n10000 loops, 11.997566 total time, 0.001200 per iteration\n```\n\nhere's without it (rev 7670c9e):\n\n```\n$ python test_quote_speed.py \n10000 loops, 11.948870 total time, 0.001195 per iteration\n$ python test_quote_speed.py \n10000 loops, 11.784187 total time, 0.001178 per iteration\n$ python test_quote_speed.py \n10000 loops, 11.700121 total time, 0.001170 per iteration\n```\n\nyou can see it's within the statistical noise.\n\ntest code:\n\n``` python\nimport logging, os, timeit\nimport peewee as pw\n\ndb = pw.PostgresqlDatabase('test_quoting_speed')\n\nclass Person(pw.Model):\n first_name = pw.CharField()\n class Meta:\n database = db\n\ndb.connect()\ndb.drop_table(Person)\ndb.create_tables([Person])\n\nfor i in range(100):\n Person.create(first_name='Me%i' % i)\n\ndef to_time():\n list(Person.select().where(~(Person.first_name << ('Me10', 'Me20'))))\n\ncount = 10000\nseconds = timeit.timeit(to_time, number=count)\nprint '%i loops, %f total time, %f per iteration' % (count, seconds, seconds / count)\n```\n",
"Explanation https://github.com/coleifer/peewee/pull/949#issuecomment-301983388"
] | 2016-05-31T23:17:57 | 2017-05-17T04:40:22 | 2016-06-01T04:59:30 | CONTRIBUTOR | null | as it makes the SQL not very human-friendly.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/950/reactions",
"total_count": 3,
"+1": 3,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/950/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/950",
"html_url": "https://github.com/coleifer/peewee/pull/950",
"diff_url": "https://github.com/coleifer/peewee/pull/950.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/950.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/949 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/949/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/949/comments | https://api.github.com/repos/coleifer/peewee/issues/949/events | https://github.com/coleifer/peewee/pull/949 | 157,770,053 | MDExOlB1bGxSZXF1ZXN0NzIwODUzMzA= | 949 | make genned SQL easier on the eyes by removing unnecessary quotes (ex… | {
"login": "keredson",
"id": 2049665,
"node_id": "MDQ6VXNlcjIwNDk2NjU=",
"avatar_url": "https://avatars.githubusercontent.com/u/2049665?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/keredson",
"html_url": "https://github.com/keredson",
"followers_url": "https://api.github.com/users/keredson/followers",
"following_url": "https://api.github.com/users/keredson/following{/other_user}",
"gists_url": "https://api.github.com/users/keredson/gists{/gist_id}",
"starred_url": "https://api.github.com/users/keredson/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/keredson/subscriptions",
"organizations_url": "https://api.github.com/users/keredson/orgs",
"repos_url": "https://api.github.com/users/keredson/repos",
"events_url": "https://api.github.com/users/keredson/events{/privacy}",
"received_events_url": "https://api.github.com/users/keredson/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Just noting for posterity, this is a horrible suggestion because it requires:\r\n\r\n* The maintenance of a cross-vendor list of all SQL keywords to avoid invalid SQL (i.e. only quote names if they correspond to a SQL keyword)\r\n* Inspecting each named entity to see if it contains spaces or other characters that would otherwise require quoting\r\n* Requires re-writing hundreds of test assertions\r\n\r\nAll for ... fewer quotes in the SQL that this library is designed to abstract away. The idea is not a bad one in the sense that, yes, fewer quotes would make the sql more easy to read. But it is a bad one in the way it forces the implementation to become special-cased in numerous ways. Special cases are bad and are avoided as much as possible in peewee. It was for this latter reason, more than anything else, that this was closed without merge."
] | 2016-05-31T21:02:50 | 2017-05-17T04:40:53 | 2016-05-31T21:10:21 | CONTRIBUTOR | null | …: `select id from posts` instead of `select "id" from "posts"`)
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/949/reactions",
"total_count": 1,
"+1": 0,
"-1": 1,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/949/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/949",
"html_url": "https://github.com/coleifer/peewee/pull/949",
"diff_url": "https://github.com/coleifer/peewee/pull/949.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/949.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/948 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/948/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/948/comments | https://api.github.com/repos/coleifer/peewee/issues/948/events | https://github.com/coleifer/peewee/issues/948 | 157,719,643 | MDU6SXNzdWUxNTc3MTk2NDM= | 948 | insert_many fails when inserting too many rows under Python 3.5.1 | {
"login": "zweger",
"id": 15678442,
"node_id": "MDQ6VXNlcjE1Njc4NDQy",
"avatar_url": "https://avatars.githubusercontent.com/u/15678442?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/zweger",
"html_url": "https://github.com/zweger",
"followers_url": "https://api.github.com/users/zweger/followers",
"following_url": "https://api.github.com/users/zweger/following{/other_user}",
"gists_url": "https://api.github.com/users/zweger/gists{/gist_id}",
"starred_url": "https://api.github.com/users/zweger/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/zweger/subscriptions",
"organizations_url": "https://api.github.com/users/zweger/orgs",
"repos_url": "https://api.github.com/users/zweger/repos",
"events_url": "https://api.github.com/users/zweger/events{/privacy}",
"received_events_url": "https://api.github.com/users/zweger/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Fortunately, if you run into this, it looks like pysqlite supports modifying the limit.\n- https://www.sqlite.org/limits.html#max_variable_number\n- https://www.sqlite.org/c3ref/limit.html\n- http://pysqlite.readthedocs.io/en/latest/sqlite3.html#sqlite3.Connection.set_limit\n\nSo in your peewee code, you could just write:\n\n``` python\nconn = peewee_db.get_conn()\nconn.set_limit(sqlite3.SQLITE_LIMIT_VARIABLE_NUMBER, 1337)\n```\n\nI don't think this is a peewee issue, however hopefully this code helps any other people who stumble on this issue.\n",
"Unfortunately, the version of sqlite3 which Python 3.5.1 distributes (2.6.0) does not support the `set_limit` function. Moreover, pysqlite does not support Python 3 (`pip install` gives `pysqlite is not supported on Python 3. When using Python 3, use the sqlite3 module from the standard library.`). So I'd expect it to be nontrivial to get a Python 3 install where you could do that.\n\nHowever, SQLite only allows you to _lower_ this limit. From the docs:\n\n> The maximum host parameter number can be lowered at run-time using the sqlite3_limit(db,SQLITE_LIMIT_VARIABLE_NUMBER,size) interface.\n\nAnd indeed, setting the limit to a larger number under Python 2.7.11 with pysqlite 2.8.2 has no effect.\n\nIf this is intended behavior, then I see this as a bug in peewee's documentation, which make no mention of this limit, or that it differs across Python versions for which peewee claims support.\n\nOtherwise, for ways to actually resolve this: I'm dubious that there are actually any performance differences between the multi-valued insert statement and compound inserts. (See [here](http://www.mail-archive.com/[email protected]/msg68113.html)). Perhaps peewee should always just use the compound insert form for SQLite? If there are indeed performance differences, then peewee should do multi-valued inserts inside a loop.\n",
"Wow, nice info, thank you for the thorough comment and for digging into this. I can't believe how janky the Python 3.5 sqlite3 library is, what an embarassment.\n\nLooking at https://www.sqlite.org/compile.html it does seem that the upper limit can be changed using compile-time directives.\n\nI'll take a look at the docs.\n",
"0cf8988\n",
"Just ran into this as well, it also happens when using apsw. Some platforms compile sqlite with higher defaults, e.g. homebrew / Debian / Ubuntu use 250000 (cf [Formula/sqlite.rb](https://github.com/Homebrew/homebrew-core/blob/master/Formula/sqlite.rb#L48%29)).\n\nFor apsw, use \n\n``` shell\n$ CFLAGS=\"-DSQLITE_MAX_VARIABLE_NUMBER=250000\" python setup.py fetch \\\n --all build --enable-all-extensions install\n```\n"
] | 2016-05-31T16:53:30 | 2016-06-10T21:47:00 | 2016-05-31T19:00:22 | NONE | null | It seems the underlying behavior of peewee.Model.insert_many differs when running under more modern versions of sqlite3 (and thus with more recent Python versions).
Under older versions of SQLite, peewee's `insert_many` behavior is to insert one row per SQL statement. But under SQLite versions past 3.7.11.0, peewee will attempt to insert every row in a single statement.
However, SQLite sets a limit on the number of SQL variables: `SQLITE_MAX_VARIABLE_NUMBER`, which defaults to 999. Thus the maximum number of rows SQLite can actually insert at a time is `999 // num_columns`.
See also #536, which I believe may have been running into the same problem. The issue isn't necessarily that the caller needs a suggestion for how many rows it would be best to insert at a time, but rather that when trying to insert too many things, the insert fails.
Here's a MWE:
```
import unittest
from peewee import *
db = SqliteDatabase(':memory:')
class Alpha(Model):
a = IntegerField()
b = IntegerField()
c = IntegerField()
d = IntegerField()
e = IntegerField()
f = IntegerField()
g = IntegerField()
h = IntegerField()
i = IntegerField()
class Meta:
database = db
db.create_table(Alpha)
class TestInsertMany(unittest.TestCase):
def setUp(self):
self.rows = [{'a': i, 'b': i, 'c': i, 'd': i, 'e': i, 'f': i, 'g': i, 'h': i, 'i': i} for i in range(1000)]
def test_insert_many(self):
Alpha.insert_many(self.rows).execute()
```
Under Python 2.7.11, this works. But under 3.5.1 I get the following error:
(This is from master. I get the same behavior under 2.8.1).
```
$ python -m unittest playhouse.tests.test_insert_many
E
======================================================================
ERROR: test_insert_many (playhouse.tests.test_insert_many.TestInsertMany)
----------------------------------------------------------------------
Traceback (most recent call last):
File "peewee.py", line 3586, in execute_sql
cursor.execute(sql, params or ())
sqlite3.OperationalError: too many SQL variables
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "playhouse/tests/test_insert_many.py", line 32, in test_insert_many
Alpha.insert_many(self.rows).execute()
File "peewee.py", line 3345, in execute
cursor = self._execute()
File "peewee.py", line 2748, in _execute
return self.database.execute_sql(sql, params, self.require_commit)
File "peewee.py", line 3593, in execute_sql
self.commit()
File "peewee.py", line 3417, in __exit__
reraise(new_type, new_type(*exc_args), traceback)
File "peewee.py", line 132, in reraise
raise value.with_traceback(tb)
File "peewee.py", line 3586, in execute_sql
cursor.execute(sql, params or ())
peewee.OperationalError: too many SQL variables
----------------------------------------------------------------------
Ran 1 test in 0.213s
FAILED (errors=1)
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/948/reactions",
"total_count": 1,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 1,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/948/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/947 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/947/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/947/comments | https://api.github.com/repos/coleifer/peewee/issues/947/events | https://github.com/coleifer/peewee/issues/947 | 157,309,098 | MDU6SXNzdWUxNTczMDkwOTg= | 947 | Signal models save method is not returning rows affected | {
"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 | [] | 2016-05-27T23:56:25 | 2016-05-30T22:58:44 | 2016-05-30T22:58:44 | CONTRIBUTOR | null | Using the signals model from playhouse, and wanted to get the number of rows affected by my `save` call. It is getting swallowed though.
https://github.com/coleifer/peewee/blob/master/playhouse/signals.py#L69
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/947/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/947/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/946 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/946/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/946/comments | https://api.github.com/repos/coleifer/peewee/issues/946/events | https://github.com/coleifer/peewee/issues/946 | 157,231,647 | MDU6SXNzdWUxNTcyMzE2NDc= | 946 | cannot prefetch on a joined class | {
"login": "keredson",
"id": 2049665,
"node_id": "MDQ6VXNlcjIwNDk2NjU=",
"avatar_url": "https://avatars.githubusercontent.com/u/2049665?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/keredson",
"html_url": "https://github.com/keredson",
"followers_url": "https://api.github.com/users/keredson/followers",
"following_url": "https://api.github.com/users/keredson/following{/other_user}",
"gists_url": "https://api.github.com/users/keredson/gists{/gist_id}",
"starred_url": "https://api.github.com/users/keredson/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/keredson/subscriptions",
"organizations_url": "https://api.github.com/users/keredson/orgs",
"repos_url": "https://api.github.com/users/keredson/repos",
"events_url": "https://api.github.com/users/keredson/events{/privacy}",
"received_events_url": "https://api.github.com/users/keredson/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"First of all this won't work because you need to specifically select values from both the Post and the Person:\n\n``` python\nPost.select().join(Person)\n```\n\nShould be:\n\n``` python\nPost.select(Post, Person).join(Person)\n```\n\nMore importantly, the way to accomplish what you're trying to specify a chain of models:\n\n``` python\nfor post in pw.prefetch(Post.select(), Person, Pet):\n print post, post.author,\n for pet in post.author.pets_prefetch:\n print pet,\n print\n```\n\nThis yields:\n\n``` sql\nSELECT \"t1\".\"id\", \"t1\".\"name\", \"t1\".\"owner_id\" \nFROM \"pet\" AS t1 \nWHERE (\"t1\".\"owner_id\" IN (\n SELECT \"t2\".\"id\" FROM \"person\" AS t2 \n WHERE (\"t2\".\"id\" IN (\n SELECT \"t3\".\"author_id\" FROM \"post\" AS t3))))\n\nSELECT \"t1\".\"id\", \"t1\".\"name\" FROM \"person\" AS t1 \nWHERE (\"t1\".\"id\" IN (\n SELECT \"t2\".\"author_id\" FROM \"post\" AS t2))\n\nSELECT \"t1\".\"id\", \"t1\".\"title\", \"t1\".\"author_id\" FROM \"post\" AS t1\n```\n",
"Be sure to read everything here: http://docs.peewee-orm.com/en/latest/peewee/querying.html#avoiding-n-1-queries\n",
"I see. So is it accurate to say that joins and prefetches cannot be mixed? Is there any way to get just two queries? (One for the post/person, the second for the pets?)\n"
] | 2016-05-27T15:26:10 | 2016-05-31T15:11:30 | 2016-05-30T23:14:41 | CONTRIBUTOR | null | I often need to include all the children of a child table. For example, if I have a `Post` that FKs to a `Person`, and that `Person` can have multiple `Pets`, I want to query the post with its author and all of that author's pets populated. Can this be done with peewee? The documentation for `prefetch` doesn't really say one way or another.
Example:
``` python
import logging, os
import peewee as pw
logger = logging.getLogger('peewee')
logger.setLevel(logging.DEBUG)
logger.addHandler(logging.StreamHandler())
db_fn = 'example.db'
if os.path.exists(db_fn): os.remove(db_fn)
db = pw.SqliteDatabase(db_fn)
class Person(pw.Model):
name = pw.CharField()
class Meta:
database = db
class Post(pw.Model):
title = pw.CharField()
author = pw.ForeignKeyField(db_column='author_id', rel_model=Person, to_field='id')
class Meta:
database = db
class Pet(pw.Model):
name = pw.CharField()
owner = pw.ForeignKeyField(db_column='owner_id', rel_model=Person, to_field='id', related_name='pets')
class Meta:
database = db
db.connect()
db.create_tables([Person, Post, Pet])
derek = Person.create(name='Me')
post = Post.create(title='My Post', author=derek)
pet = Pet.create(name='My Pet', owner=derek)
for post in pw.prefetch(Post.select().join(Person), Pet):
print post, post.author, post.author.pets
```
Gives:
```
$ python test.py
('CREATE TABLE "person" ("id" INTEGER NOT NULL PRIMARY KEY, "name" VARCHAR(255) NOT NULL)', [])
('CREATE TABLE "pet" ("id" INTEGER NOT NULL PRIMARY KEY, "name" VARCHAR(255) NOT NULL, "owner_id" INTEGER NOT NULL, FOREIGN KEY ("owner_id") REFERENCES "person" ("id"))', [])
('CREATE INDEX "pet_owner_id" ON "pet" ("owner_id")', [])
('CREATE TABLE "post" ("id" INTEGER NOT NULL PRIMARY KEY, "title" VARCHAR(255) NOT NULL, "author_id" INTEGER NOT NULL, FOREIGN KEY ("author_id") REFERENCES "person" ("id"))', [])
('CREATE INDEX "post_author_id" ON "post" ("author_id")', [])
('INSERT INTO "person" ("name") VALUES (?)', [u'Me'])
('INSERT INTO "post" ("title", "author_id") VALUES (?, ?)', [u'My Post', 1])
('INSERT INTO "pet" ("name", "owner_id") VALUES (?, ?)', [u'My Pet', 1])
Traceback (most recent call last):
File "test.py", line 37, in <module>
for post in pw.prefetch(Post.select().join(Person), Pet):
File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 4913, in prefetch
fixed_queries = prefetch_add_subquery(sq, subqueries)
File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 4845, in prefetch_add_subquery
'query: %s%s' % (subquery, tgt_err))
AttributeError: Error: unable to find foreign key for query: <class '__main__.Pet'> SELECT "t1"."id", "t1"."name", "t1"."owner_id" FROM "pet" AS t1 []
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/946/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/946/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/945 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/945/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/945/comments | https://api.github.com/repos/coleifer/peewee/issues/945/events | https://github.com/coleifer/peewee/issues/945 | 156,968,423 | MDU6SXNzdWUxNTY5Njg0MjM= | 945 | Perhaps DB connection URI retrieval in playhouse.flask_utils.FlaskDB can be deferred (init_app) until db_connect | {
"login": "nad2000",
"id": 177266,
"node_id": "MDQ6VXNlcjE3NzI2Ng==",
"avatar_url": "https://avatars.githubusercontent.com/u/177266?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/nad2000",
"html_url": "https://github.com/nad2000",
"followers_url": "https://api.github.com/users/nad2000/followers",
"following_url": "https://api.github.com/users/nad2000/following{/other_user}",
"gists_url": "https://api.github.com/users/nad2000/gists{/gist_id}",
"starred_url": "https://api.github.com/users/nad2000/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/nad2000/subscriptions",
"organizations_url": "https://api.github.com/users/nad2000/orgs",
"repos_url": "https://api.github.com/users/nad2000/repos",
"events_url": "https://api.github.com/users/nad2000/events{/privacy}",
"received_events_url": "https://api.github.com/users/nad2000/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Well, you can always just initialize your FlaskDB object by specifying `app=None`. Then when you're ready, you can call `init_app()` on it. That is the standard pattern for doing plugins and plugin factories with Flask.\n\nFor anything more than that you'll probably want to look at the following docs:\n- [Run-time database configuration](http://docs.peewee-orm.com/en/latest/peewee/database.html#run-time-database-configuration)\n- [Dynamically defining a database](http://docs.peewee-orm.com/en/latest/peewee/database.html#dynamically-defining-a-database)\n"
] | 2016-05-26T12:05:43 | 2016-05-30T23:01:20 | 2016-05-30T23:01:20 | NONE | null | I run into a configuration problem doing testing. FlaskDB ignores Flask configuration changes made in **setUp**, eg, `app.config["DATABASE"] = ...`. FlaskDB uses the "global" (original application configurations). I'd done testing **flask-sqlalchemy** and it has lazy DB connection initialization. Perhaps DB connection URI retrieval and connecton initialization in playhouse.flask_utils.FlaskDB can be deferred (init_app) until db_connect.
A test for the "expected" behaviour in the context of a test would be:
``` python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import unittest
from flask import Flask
from playhouse.flask_utils import FlaskDB
import re
app = Flask(__name__)
app.config["DATABASE"] = "sqlite:///app.db" ## this URI shouldn't be used
db = FlaskDB(app)
class Atable(db.Model):
pass
@app.route('/')
def index():
return "Configuration DATABASE: %s\n\nModel DATABASE: %s" \
% (app.config["DATABASE"], Atable._meta.database.database)
class UserTest(unittest.TestCase):
def setUp(self):
app.config["DATABASE"] = "sqlite:///test.db"
self.app = app.test_client()
def test_app_db_settings(self):
rv = self.app.get('/')
assert "Model DATABASE: test.db" in str(rv.data)
assert "Model DATABASE: app.db" not in str(rv.data)
app_db_file, model_db_file = re.findall("\w*\.db", str(rv.data), re.M)
assert app_db_file == model_db_file
if __name__ == "__main__":
unittest.main()
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/945/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/945/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/944 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/944/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/944/comments | https://api.github.com/repos/coleifer/peewee/issues/944/events | https://github.com/coleifer/peewee/pull/944 | 156,347,818 | MDExOlB1bGxSZXF1ZXN0NzExMDY4MzI= | 944 | fix the support of schema for PostgreSQL when we try to create a new table | {
"login": "matrixise",
"id": 38737,
"node_id": "MDQ6VXNlcjM4NzM3",
"avatar_url": "https://avatars.githubusercontent.com/u/38737?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/matrixise",
"html_url": "https://github.com/matrixise",
"followers_url": "https://api.github.com/users/matrixise/followers",
"following_url": "https://api.github.com/users/matrixise/following{/other_user}",
"gists_url": "https://api.github.com/users/matrixise/gists{/gist_id}",
"starred_url": "https://api.github.com/users/matrixise/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/matrixise/subscriptions",
"organizations_url": "https://api.github.com/users/matrixise/orgs",
"repos_url": "https://api.github.com/users/matrixise/repos",
"events_url": "https://api.github.com/users/matrixise/events{/privacy}",
"received_events_url": "https://api.github.com/users/matrixise/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"ok, my branch has some issues with travis, I will try to fix it asap\n"
] | 2016-05-23T19:27:22 | 2016-07-14T08:59:20 | 2016-07-14T08:59:20 | CONTRIBUTOR | null | In the Meta data of a class, we can specify the `schema` attribute, but this one is not used when we try to create the table. in fact the schema must be existing. in this case, we will create it after the creation of the table.
I prefer to propose a solution, I can rewrite it if necessary.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/944/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/944/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/944",
"html_url": "https://github.com/coleifer/peewee/pull/944",
"diff_url": "https://github.com/coleifer/peewee/pull/944.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/944.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/943 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/943/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/943/comments | https://api.github.com/repos/coleifer/peewee/issues/943/events | https://github.com/coleifer/peewee/issues/943 | 156,162,951 | MDU6SXNzdWUxNTYxNjI5NTE= | 943 | peewee.fn.Lower / Upper do not work correctly for some unicode characters | {
"login": "anqxyr",
"id": 1102094,
"node_id": "MDQ6VXNlcjExMDIwOTQ=",
"avatar_url": "https://avatars.githubusercontent.com/u/1102094?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/anqxyr",
"html_url": "https://github.com/anqxyr",
"followers_url": "https://api.github.com/users/anqxyr/followers",
"following_url": "https://api.github.com/users/anqxyr/following{/other_user}",
"gists_url": "https://api.github.com/users/anqxyr/gists{/gist_id}",
"starred_url": "https://api.github.com/users/anqxyr/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/anqxyr/subscriptions",
"organizations_url": "https://api.github.com/users/anqxyr/orgs",
"repos_url": "https://api.github.com/users/anqxyr/repos",
"events_url": "https://api.github.com/users/anqxyr/events{/privacy}",
"received_events_url": "https://api.github.com/users/anqxyr/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"You need to load the ICU extension, which can be compiled in automatically or built as a loadable extension. Check the sqlite docs on the subject. This is a database-specific problem as opposed to a peewee issue.\n"
] | 2016-05-22T17:31:13 | 2016-05-23T15:14:42 | 2016-05-23T15:14:42 | NONE | null | Table Q looks like this:
| id | user |
| --- | --- |
| 1 | À |
| 2 | à |
And here is some code doing stuff to it.
``` python
In [1]: [i.id for i in Q.select().where(Q.user == 'À')]
Out[1]: [1]
In [2]: [i.id for i in Q.select().where(Q.user == 'à')]
Out[2]: [2]
In [3]: [i.id for i in Q.select().where(peewee.fn.Lower(Q.user) == 'À')]
Out[3]: [1]
In [4]: [i.id for i in Q.select().where(peewee.fn.Upper(Q.user) == 'à')]
Out[4]: [2]
In [5]: [i.id for i in Q.select().where(peewee.fn.Lower(Q.user) == 'à')]
Out[5]: [2]
```
Peewee version is 2.8.0. SQLite version 3.7.9
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/943/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/943/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/942 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/942/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/942/comments | https://api.github.com/repos/coleifer/peewee/issues/942/events | https://github.com/coleifer/peewee/issues/942 | 155,902,499 | MDU6SXNzdWUxNTU5MDI0OTk= | 942 | Postgresql ON CONFLICT | {
"login": "paulfariello",
"id": 273684,
"node_id": "MDQ6VXNlcjI3MzY4NA==",
"avatar_url": "https://avatars.githubusercontent.com/u/273684?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/paulfariello",
"html_url": "https://github.com/paulfariello",
"followers_url": "https://api.github.com/users/paulfariello/followers",
"following_url": "https://api.github.com/users/paulfariello/following{/other_user}",
"gists_url": "https://api.github.com/users/paulfariello/gists{/gist_id}",
"starred_url": "https://api.github.com/users/paulfariello/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/paulfariello/subscriptions",
"organizations_url": "https://api.github.com/users/paulfariello/orgs",
"repos_url": "https://api.github.com/users/paulfariello/repos",
"events_url": "https://api.github.com/users/paulfariello/events{/privacy}",
"received_events_url": "https://api.github.com/users/paulfariello/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Well... so for one, I am working in the background on a rewrite of all the sql generation, cleaning it up quite a bit in the process. So I don't know that it'd be worth the effort. \n",
"Ok so I'll wait for the complete rewrite.\n\nThanks\n\nLe 20 mai 2016 16:32:12 GMT+02:00, Charles Leifer [email protected] a écrit :\n\n> Well... so for one, I am working in the background on a rewrite of all\n> the sql generation, cleaning it up quite a bit in the process. So I\n> don't know that it'd be worth the effort. \n> \n> ---\n> \n> You are receiving this because you authored the thread.\n> Reply to this email directly or view it on GitHub:\n> https://github.com/coleifer/peewee/issues/942#issuecomment-220622010\n\n## \n\nPaul Fariello\nEnvoyé de mon téléphone. Veuillez excuser ma brièveté.\n",
"Reopening to add implementation to 2.8.x.\n",
"Is 2.8.x containing the sql generation rewrite ? Do you need some workforce for this issue ? \n",
"The rewrite will be the 3.0 release, so as not to rock the boat for existing Peewee users.\n\nI'd like to get upsert in 2.8 as it will allow people to use the feature without worrying about a significant upgrade.\n",
"One thing I've run into implementing this is the requirement that you must manually specify the constraint you expect to be violated.\n\nI'm wondering how much of the `INSERT ... ON CONFLICT` API should be exposed to end-users? The full spec allows for a WHERE clause in the conflict target **and** conflict action. What a shit-show!\n\nThere was a patch submitted to PokemonGo-Map (https://github.com/AHAAAAAAA/PokemonGo-Map/commit/ae13302c75f6005aa4c33e13aac9b98c71dc0bd7) that added very basic Postgresql upsert support to Peewee. It only covers violations of the primary key constraint, which seems sensible for an application, but in practice I am sure it needs to be more flexible for general usage.\n\nNo constraint needs to be specified if the resulting action is \"DO NOTHING\", but in many cases I would guess that people would instead want the \"DO UPDATE SET\" logic to update the existing row.\n\nMy current thinking is that, while I had hoped the approach from the PokemonGo-Map project would work, I think I need to build something that more closely matches Postgresql's APIs.\n",
"Any updates on that?\n\nI'm currently using a insert_many statement and want to efficiently bypass record already exists by updating it with the latest attributes.\n",
"No updates :( but still very much on my radar.\n",
"That's totally ok :). You've done plenty of good work as it is and we should all be very thankful to you.\nI was able to circumvent the challenge with a custom SQL statement.\n\nThanks again!\n",
"why not just accept this PR and be done with it for time being\r\n\r\nhttps://github.com/coleifer/peewee/pull/1153",
"https://www.postgresql.org/docs/9.5/static/sql-insert.html -- the need to be able to support more than just the trivial case seems to outweigh merging in a fix that addresses a single case. Also note that there are no test-cases for that PR. Nor any documentation. It's just not the kind of patch I like to merge.",
"Please see new discussion thread in #1307 (which consolidates discussion of upsert functionality for sqlite/mysql/postgres)."
] | 2016-05-20T07:23:12 | 2017-07-05T04:23:10 | 2017-07-05T04:23:10 | NONE | null | Hi,
we can read in documentation that `INSERT … ON CONFLICT` is planed to be supported soon.
I'm currently using some home made query to do it, but I think it would be more stable to add support for it in peewee. I would be glad to give a try but I have some question before creating a merge request.
Looking at `generate_insert` (https://github.com/coleifer/peewee/blob/master/peewee.py#L1912) I'm wondering if the `ON CONFLICT` should be added as an `upsert` or as a `on_conflict`.
In any case the general construction of the query is rather different for sqlite `ON CONFLICT` is at the beginning of the query while for postgresql it is after the values. Is it ok to add some specific variable on Database class such as `on_conflict_position` and then do some `if`in `generate_insert`.
Thanks
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/942/reactions",
"total_count": 2,
"+1": 2,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/942/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/941 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/941/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/941/comments | https://api.github.com/repos/coleifer/peewee/issues/941/events | https://github.com/coleifer/peewee/issues/941 | 155,739,952 | MDU6SXNzdWUxNTU3Mzk5NTI= | 941 | "is_null" and ">> None" operator is parsed as "IS None" instead of "IS NULL" | {
"login": "iraklikhitarishvili",
"id": 7589748,
"node_id": "MDQ6VXNlcjc1ODk3NDg=",
"avatar_url": "https://avatars.githubusercontent.com/u/7589748?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/iraklikhitarishvili",
"html_url": "https://github.com/iraklikhitarishvili",
"followers_url": "https://api.github.com/users/iraklikhitarishvili/followers",
"following_url": "https://api.github.com/users/iraklikhitarishvili/following{/other_user}",
"gists_url": "https://api.github.com/users/iraklikhitarishvili/gists{/gist_id}",
"starred_url": "https://api.github.com/users/iraklikhitarishvili/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/iraklikhitarishvili/subscriptions",
"organizations_url": "https://api.github.com/users/iraklikhitarishvili/orgs",
"repos_url": "https://api.github.com/users/iraklikhitarishvili/repos",
"events_url": "https://api.github.com/users/iraklikhitarishvili/events{/privacy}",
"received_events_url": "https://api.github.com/users/iraklikhitarishvili/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Since the value is parameterized, it will go in as the string 'NULL'.\n",
"thank you very mach. you are right. issue was that i tried to run it with `django_model.objects.raw(sql_query,params)` and django orm putted `None` from `params` as `None` instead of `NULL`.\n"
] | 2016-05-19T13:43:24 | 2016-05-19T15:39:50 | 2016-05-19T15:04:26 | NONE | null | `column_name.is_null(True)` and `column_name >> None` expressions in `where` clause are returning `WHERE column_name IS None` in postgresql query.
i think just changing [`db_value`](https://github.com/coleifer/peewee/blob/master/peewee.py#L928) to
``` python
def db_value(self, value):
"""Convert the python value for storage in the database."""
return 'NULL' if value is None else self.coerce(value)
```
will help
p.s i was using models translated from django
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/941/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/941/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/940 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/940/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/940/comments | https://api.github.com/repos/coleifer/peewee/issues/940/events | https://github.com/coleifer/peewee/issues/940 | 155,596,400 | MDU6SXNzdWUxNTU1OTY0MDA= | 940 | Pass through field default values to SQL schema, or allow explicit creation of default values in model Meta class | {
"login": "bcattle",
"id": 620058,
"node_id": "MDQ6VXNlcjYyMDA1OA==",
"avatar_url": "https://avatars.githubusercontent.com/u/620058?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/bcattle",
"html_url": "https://github.com/bcattle",
"followers_url": "https://api.github.com/users/bcattle/followers",
"following_url": "https://api.github.com/users/bcattle/following{/other_user}",
"gists_url": "https://api.github.com/users/bcattle/gists{/gist_id}",
"starred_url": "https://api.github.com/users/bcattle/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/bcattle/subscriptions",
"organizations_url": "https://api.github.com/users/bcattle/orgs",
"repos_url": "https://api.github.com/users/bcattle/repos",
"events_url": "https://api.github.com/users/bcattle/events{/privacy}",
"received_events_url": "https://api.github.com/users/bcattle/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Oh, I see you can already do this. From the [docs](http://docs.peewee-orm.com/en/latest/peewee/models.html#default-field-values): \n\n> The database can also provide the default value for a field. While peewee does not explicitly provide an API for setting a server-side default value, you can use the constraints parameter to specify the server default:\n> \n> ```\n> class Message(Model):\n> context = TextField()\n> timestamp = DateTimeField(constraints=[SQL('DEFAULT CURRENT_TIMESTAMP')])\n> ```\n\nNice!\n",
"Yep! Thanks for checking the docs!\n"
] | 2016-05-18T20:41:17 | 2016-05-19T21:26:03 | 2016-05-18T20:42:28 | CONTRIBUTOR | null | Currently you can specify a model field's default value like
```
new_users = peewee.IntegerField(default=0)
```
Currently this default is applied at the application level, in the [`add_field`](https://github.com/coleifer/peewee/blob/master/peewee.py#L4304) method of the ModelOptions class.
It would be nice if this definition were passed through to the underlying SQL schema. So, when the table is created, a SQL statement of the form
```
CREATE TABLE "stats" (
"new_users" INTEGER NOT NULL DEFAULT 0,
)
```
Is generated. This seems more consistent with how the `null=True` attribute produces SQL with the `NULL` attribute set appropriately.
Since you can specify any Python callable for the `default=` value, either the calllable would be called once when the module is loaded, or you could use a syntax like the current `Check('price < 10000')` syntax to pass through a SQL string. This would allow you to use a sequence, etc. as a field default value. For example:
```
new_users = peewee.IntegerField(default=Default('nextval('user_no_seq')'))
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/940/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/940/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/939 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/939/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/939/comments | https://api.github.com/repos/coleifer/peewee/issues/939/events | https://github.com/coleifer/peewee/pull/939 | 154,992,164 | MDExOlB1bGxSZXF1ZXN0NzAxNzA4ODY= | 939 | fix:playhouse connect database_url error | {
"login": "jmpews",
"id": 4661301,
"node_id": "MDQ6VXNlcjQ2NjEzMDE=",
"avatar_url": "https://avatars.githubusercontent.com/u/4661301?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/jmpews",
"html_url": "https://github.com/jmpews",
"followers_url": "https://api.github.com/users/jmpews/followers",
"following_url": "https://api.github.com/users/jmpews/following{/other_user}",
"gists_url": "https://api.github.com/users/jmpews/gists{/gist_id}",
"starred_url": "https://api.github.com/users/jmpews/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/jmpews/subscriptions",
"organizations_url": "https://api.github.com/users/jmpews/orgs",
"repos_url": "https://api.github.com/users/jmpews/repos",
"events_url": "https://api.github.com/users/jmpews/events{/privacy}",
"received_events_url": "https://api.github.com/users/jmpews/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2016-05-16T09:26:00 | 2016-05-16T19:43:57 | 2016-05-16T19:43:57 | NONE | null | fix:playhouse connect database_url, the max_connections is mistaken for the type of 'str', so the error occur at https://github.com/coleifer/peewee/blob/master/playhouse/pool.py#L126
example:
```
BACKEND_MYSQL="mysql+pool://root:[email protected]/torweb?max_connections=20&stale_timeout=300"
```
`max_connections` and `stale_timeout` are mistaken for the type of 'str', and error occur
```
Traceback (most recent call last):
File "/Users/jmpews/virtualenv/torweb/lib/python3.5/site-packages/tornado/web.py", line 1422, in _execute
result = self.prepare()
File "/Users/jmpews/Desktop/codesnippet/python/torweb/handlers/basehandlers/basehandler.py", line 18, in prepare
db_mysql.connect()
File "/Users/jmpews/virtualenv/torweb/lib/python3.5/site-packages/peewee.py", line 3402, in connect
**self.connect_kwargs)
File "/Users/jmpews/virtualenv/torweb/lib/python3.5/site-packages/playhouse/pool.py", line 126, in _connect
len(self._in_use) >= self.max_connections):
TypeError: unorderable types: int() >= str()
```
and
perhaps there are still other types of errors
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/939/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/939/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/939",
"html_url": "https://github.com/coleifer/peewee/pull/939",
"diff_url": "https://github.com/coleifer/peewee/pull/939.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/939.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/938 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/938/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/938/comments | https://api.github.com/repos/coleifer/peewee/issues/938/events | https://github.com/coleifer/peewee/issues/938 | 154,893,377 | MDU6SXNzdWUxNTQ4OTMzNzc= | 938 | PostgreSQL Full text search failing on multiple words and/or special characters | {
"login": "ZucchiniZe",
"id": 5256942,
"node_id": "MDQ6VXNlcjUyNTY5NDI=",
"avatar_url": "https://avatars.githubusercontent.com/u/5256942?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/ZucchiniZe",
"html_url": "https://github.com/ZucchiniZe",
"followers_url": "https://api.github.com/users/ZucchiniZe/followers",
"following_url": "https://api.github.com/users/ZucchiniZe/following{/other_user}",
"gists_url": "https://api.github.com/users/ZucchiniZe/gists{/gist_id}",
"starred_url": "https://api.github.com/users/ZucchiniZe/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/ZucchiniZe/subscriptions",
"organizations_url": "https://api.github.com/users/ZucchiniZe/orgs",
"repos_url": "https://api.github.com/users/ZucchiniZe/repos",
"events_url": "https://api.github.com/users/ZucchiniZe/events{/privacy}",
"received_events_url": "https://api.github.com/users/ZucchiniZe/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Sorry, after some debugging I found out that you have to do some weird quoting on the variables or use `plainto_tsquery` for it to recognize spacing. my bad\n",
"http://docs.peewee-orm.com/en/latest/peewee/playhouse.html#pg-fts\n\nThe docs say:\n\n> The [Match()](http://docs.peewee-orm.com/en/latest/peewee/playhouse.html#Match) function will automatically convert the left-hand operand to a tsvector, and the right-hand operand to a tsquery. For better performance, it is recommended you create a GIN index on the column you plan to search.\n\nDid you see that in the docs?\n"
] | 2016-05-15T06:30:00 | 2016-05-16T01:38:03 | 2016-05-15T07:10:39 | NONE | null | I am trying to use the full text search feature offered by peewee and when I run the `Match()` function on something that contains special characters or spaces it fails and give the error `peewee.ProgrammingError: syntax error in tsquery:`. Looking through the traceback it looks like the %s is not getting quoted when running the SQL causing it to fail when executing.
here is the full traceback
``````
Traceback (most recent call last):
File "/usr/lib/python3.4/site-packages/flask/app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "/usr/lib/python3.4/site-packages/flask/app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/usr/lib/python3.4/site-packages/flask/app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "/usr/lib/python3.4/site-packages/flask/_compat.py", line 33, in reraise
raise value
File "/usr/lib/python3.4/site-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/usr/lib/python3.4/site-packages/flask/app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/lib/python3.4/site-packages/flask/app.py", line 1381, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/usr/lib/python3.4/site-packages/flask/_compat.py", line 33, in reraise
raise value
File "/usr/lib/python3.4/site-packages/flask/app.py", line 1475, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/lib/python3.4/site-packages/flask/app.py", line 1461, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/alex/code/personal/marvel/marvel.py", line 83, in show_search
return render_template('show_search.html', totals=(tcount, icount), results=query, search=True)
File "/usr/lib/python3.4/site-packages/flask/templating.py", line 128, in render_template
context, ctx.app)
File "/usr/lib/python3.4/site-packages/flask/templating.py", line 110, in _render
rv = template.render(context)
File "/usr/lib/python3.4/site-packages/jinja2/environment.py", line 989, in render
return self.environment.handle_exception(exc_info, True)
File "/usr/lib/python3.4/site-packages/jinja2/environment.py", line 754, in handle_exception
reraise(exc_type, exc_value, tb)
File "/usr/lib/python3.4/site-packages/jinja2/_compat.py", line 37, in reraise
raise value.with_traceback(tb)
File "/home/alex/code/personal/marvel/templates/show_search.html", line 1, in top-level template code
{% extends "layout.html" %}
File "/home/alex/code/personal/marvel/templates/layout.html", line 16, in top-level template code
{% block body %}{% endblock %}
File "/home/alex/code/personal/marvel/templates/show_search.html", line 8, in block "body"
{% if results %}
File "/usr/lib/python3.4/site-packages/peewee.py", line 2984, in __len__
return len(self.execute())
File "/usr/lib/python3.4/site-packages/peewee.py", line 2960, in execute
self._qr = ResultWrapper(model_class, self._execute(), query_meta)
File "/usr/lib/python3.4/site-packages/peewee.py", line 2656, in _execute
return self.database.execute_sql(sql, params, self.require_commit)
File "/usr/lib/python3.4/site-packages/playhouse/postgres_ext.py", line 380, in execute_sql
self.commit()
File "/usr/lib/python3.4/site-packages/peewee.py", line 3316, in __exit__
reraise(new_type, new_type(*exc_args), traceback)
File "/usr/lib/python3.4/site-packages/peewee.py", line 127, in reraise
raise value.with_traceback(tb)
File "/usr/lib/python3.4/site-packages/playhouse/postgres_ext.py", line 373, in execute_sql
cursor.execute(sql, params or ())
peewee.ProgrammingError: syntax error in tsquery: "amazing spider-man"```
``````
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/938/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/938/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/937 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/937/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/937/comments | https://api.github.com/repos/coleifer/peewee/issues/937/events | https://github.com/coleifer/peewee/issues/937 | 154,774,343 | MDU6SXNzdWUxNTQ3NzQzNDM= | 937 | Cyclic ManyToManyField issues | {
"login": "maciej-irl",
"id": 2553960,
"node_id": "MDQ6VXNlcjI1NTM5NjA=",
"avatar_url": "https://avatars.githubusercontent.com/u/2553960?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/maciej-irl",
"html_url": "https://github.com/maciej-irl",
"followers_url": "https://api.github.com/users/maciej-irl/followers",
"following_url": "https://api.github.com/users/maciej-irl/following{/other_user}",
"gists_url": "https://api.github.com/users/maciej-irl/gists{/gist_id}",
"starred_url": "https://api.github.com/users/maciej-irl/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/maciej-irl/subscriptions",
"organizations_url": "https://api.github.com/users/maciej-irl/orgs",
"repos_url": "https://api.github.com/users/maciej-irl/repos",
"events_url": "https://api.github.com/users/maciej-irl/events{/privacy}",
"received_events_url": "https://api.github.com/users/maciej-irl/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"It's actually not necessary to add a \"backref\" `ManyToManyField` as Peewee already does this. What you want is something like:\n\n``` python\nclass Author(BaseModel):\n author = TextField(unique=True)\n\nclass Software(BaseModel):\n program = TextField()\n contributors = ManyToManyField(Author, through_model=DeferredContributor, related_name='software')\n```\n\n`Author.software` will now be a many-to-many field as well, without the need to re-define it.\n"
] | 2016-05-13T18:34:08 | 2016-05-19T15:25:52 | 2016-05-19T15:25:52 | NONE | null | Code below produces, instead of expected "1". Running Peewee 2.8.1. Same result when running HEAD.
```
Traceback (most recent call last):
File "orm.py", line 26, in <module>
DeferredAuthor.set_model(Software)
File "/usr/local/lib/python3.5/site-packages/peewee.py", line 422, in set_model
self.field.rel_model = rel_model
AttributeError: 'DeferredRelation' object has no attribute 'field'
```
ManyToManyField works great when just one object contains it. DeferredRelation seems to break it. If this is not a bug I would love some advice on making this work. Note I am not using `get_through_model` because in reality I'm using Postgres with all the tables in already place.
``` py
from peewee import *
from playhouse.fields import *
db = SqliteDatabase(':memory:')
class BaseModel(Model):
class Meta:
database = db
DeferredContributor = DeferredThroughModel()
DeferredAuthor = DeferredRelation()
class Software(BaseModel):
program = TextField()
contributors = ManyToManyField(DeferredAuthor, through_model=DeferredContributor)
class Author(BaseModel):
author = TextField(unique=True)
software = ManyToManyField(Software, through_model=DeferredContributor)
class Contributor(BaseModel):
contributor = ForeignKeyField(Author)
software = ForeignKeyField(Software)
DeferredContributor.set_model(Contributor)
DeferredAuthor.set_model(Software)
db.create_tables([Contributor, Author, Software], safe=True)
Author.create(author='john')
Software.create(program='hello', author=1)
Contributor.create(contributor=1, software=1)
db.commit()
print(Software.get(Software.program=='hello').contributors.count())
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/937/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/937/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/936 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/936/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/936/comments | https://api.github.com/repos/coleifer/peewee/issues/936/events | https://github.com/coleifer/peewee/issues/936 | 154,772,802 | MDU6SXNzdWUxNTQ3NzI4MDI= | 936 | Postgres syntax error while using db.execute_sql | {
"login": "hkarasek",
"id": 1782618,
"node_id": "MDQ6VXNlcjE3ODI2MTg=",
"avatar_url": "https://avatars.githubusercontent.com/u/1782618?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/hkarasek",
"html_url": "https://github.com/hkarasek",
"followers_url": "https://api.github.com/users/hkarasek/followers",
"following_url": "https://api.github.com/users/hkarasek/following{/other_user}",
"gists_url": "https://api.github.com/users/hkarasek/gists{/gist_id}",
"starred_url": "https://api.github.com/users/hkarasek/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/hkarasek/subscriptions",
"organizations_url": "https://api.github.com/users/hkarasek/orgs",
"repos_url": "https://api.github.com/users/hkarasek/repos",
"events_url": "https://api.github.com/users/hkarasek/events{/privacy}",
"received_events_url": "https://api.github.com/users/hkarasek/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Where are the single-quotes coming from? I'm kinda confused.\n",
"There are a few weird things going on in the code you shared:\n- Parameterizing the table name: typically you don't want to parameterize things like table names or other things that exist as part of the schema...it's more for external data.\n- Postgres uses double-quotes for columns, tables, etc. Single quotes are used for string data.\n- Any reason not to define a database model, or are you just using peewee for low-level database access?\n\nTo answer your question, though, you should just write:\n\n``` python\nsql = 'CREATE TABLE \"test42\" (id SERIAL PRIMARY KEY);'\ndb.execute_sql(sql)\n```\n\nIf the table name is coming from an untrusted source (i.e. not hard-coded into your application) then this stackoverflow answer might be helpful:\n\nhttp://stackoverflow.com/questions/13793399/passing-table-name-as-a-parameter-in-psycopg2\n"
] | 2016-05-13T18:25:57 | 2016-05-14T00:28:06 | 2016-05-14T00:28:06 | NONE | null | I have problem with the ' (single quote) in SQL query when passing arguments. I am doing something wrong or it's a bug?
### Reproducer:
``` python
import peewee as pw
EVENTS_TABLE_PREFIX = 'events_'
db = pw.PostgresqlDatabase('events_api', user='test', password='passwd', host='localhost')
sql = 'CREATE TABLE %s (id SERIAL PRIMARY KEY);'
db.execute_sql(sql, ['test42'])
```
### Raises:
```
Traceback (most recent call last):
File "/home/hkar/.virtualenvs/events_api/lib/python3.5/site-packages/peewee.py", line 3485, in execute_sql
cursor.execute(sql, params or ())
psycopg2.ProgrammingError: syntax error at or near "'test42'"
LINE 1: CREATE TABLE 'test42' (id SERIAL PRIMARY KEY);
^
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "peewee_bug.py", line 8, in <module>
db.execute_sql(sql, ['test42'])
File "/home/hkar/.virtualenvs/events_api/lib/python3.5/site-packages/peewee.py", line 3492, in execute_sql
self.commit()
File "/home/hkar/.virtualenvs/events_api/lib/python3.5/site-packages/peewee.py", line 3316, in __exit__
reraise(new_type, new_type(*exc_args), traceback)
File "/home/hkar/.virtualenvs/events_api/lib/python3.5/site-packages/peewee.py", line 127, in reraise
raise value.with_traceback(tb)
File "/home/hkar/.virtualenvs/events_api/lib/python3.5/site-packages/peewee.py", line 3485, in execute_sql
cursor.execute(sql, params or ())
peewee.ProgrammingError: syntax error at or near "'test42'"
LINE 1: CREATE TABLE 'test42' (id SERIAL PRIMARY KEY);
```
### Environment
Ubuntu 16.04
python 3.5.1
python modules:
ecdsa==0.13
falcon==1.0.0
future==0.15.2
gunicorn==19.5.0
jsonschema==2.5.1
peewee==2.8.1
psycopg2==2.6.1
pycrypto==2.6.1
python-jose==0.6.1
python-mimeparse==1.5.2
simplejson==3.8.2
six==1.10.0
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/936/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/936/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/935 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/935/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/935/comments | https://api.github.com/repos/coleifer/peewee/issues/935/events | https://github.com/coleifer/peewee/issues/935 | 154,316,835 | MDU6SXNzdWUxNTQzMTY4MzU= | 935 | DateTimeField fetched with scalar() has different type in Postgres vs. SQLite | {
"login": "jonklein",
"id": 194568,
"node_id": "MDQ6VXNlcjE5NDU2OA==",
"avatar_url": "https://avatars.githubusercontent.com/u/194568?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/jonklein",
"html_url": "https://github.com/jonklein",
"followers_url": "https://api.github.com/users/jonklein/followers",
"following_url": "https://api.github.com/users/jonklein/following{/other_user}",
"gists_url": "https://api.github.com/users/jonklein/gists{/gist_id}",
"starred_url": "https://api.github.com/users/jonklein/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/jonklein/subscriptions",
"organizations_url": "https://api.github.com/users/jonklein/orgs",
"repos_url": "https://api.github.com/users/jonklein/repos",
"events_url": "https://api.github.com/users/jonklein/events{/privacy}",
"received_events_url": "https://api.github.com/users/jonklein/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Whoa...what version of SQLite is your Python driver using? You can run `from peewee import sqlite3; print sqlite3.sqlite_version_info` I believe. Are the sqlite values being inserted as timestamps? You can open a sqlite shell and check. \n",
"As an example, here's what I get when I run a similar query against my blog's database:\n\n``` python\nIn [1]: Entry.created_date\nOut[1]: <peewee.DateTimeField at 0x7fc87b4ac7d0>\n\nIn [2]: Entry.select(fn.MAX(Entry.created_date)).scalar()\nOut[2]: u'2016-03-22 23:16:57.058839'\n\nIn [3]: from peewee import sqlite3; print sqlite3.sqlite_version_info\n(3, 11, 0)\n```\n\nAre you using a trigger to set the `updated_at` value, or specifying a default value generated by the database?\n",
"Looks like it's 3.9.2. I was inserting is as a `time` in my first example, but updating to insert a `datetime.datetime` I receive a unicode string back, also not what I'm getting from Postgres (`datetime.datetime`).\n\nHere are how the columns are defined in the Postgres database:\n\n```\n created_at timestamp without time zone NOT NULL,\n updated_at timestamp without time zone NOT NULL,\n```\n\nTo give some context here, I'm using SQLite just for running the test suite, and Postgres for actual app usage.\n",
"Welllll, I think you answered your own question. It's called a `DateTimeField` because it should be given `datetime` objects.\n\nI meant to also show the use of the `convert` parameter to `scalar()` which I had sadly forgotten to document. At any rate, [I've added documentation](http://docs.peewee-orm.com/en/latest/peewee/api.html#Query.scalar), and this is the behavior:\n\n``` python\nIn [1]: Entry.select(fn.MAX(Entry.created_date)).scalar(convert=True)\nOut[1]: datetime.datetime(2016, 3, 22, 23, 16, 57, 58839)\n\nIn [2]: Entry.select(fn.MAX(Entry.created_date)).scalar(convert=False)\nOut[2]: u'2016-03-22 23:16:57.058839'\n```\n\nThe reason, I believe, that you aren't seeing similar behavior with Postgresql is because `psycopg2`, the Postgresql/Python library, is doing the conversion before the data gets to peewee.\n\nI think you're best off just hucking some `datetime.datetime()` objects in there, or implementing a custom field that converts timestamps into datetime objects (and remembering to pass `convert=True` when using scalar).\n"
] | 2016-05-11T18:58:15 | 2016-05-11T20:37:19 | 2016-05-11T20:37:19 | NONE | null | Fetching a DateTimeField with scalar() yields a datetime for Postgres, and a float for SQLite. While SQLite does not have a distinct storage type for dates/times, I'd still expect the same type to be returned from Peewee.
With Postgres
```
>>> Profiles.select(fn.Max(Profiles.updated_at)).scalar()
datetime.datetime(2016, 4, 29, 16, 52, 33, 445791)
```
With SQLite
```
>>> Profiles.select(fn.Max(Profiles.updated_at)).scalar()
1462992876.32
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/935/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/935/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/934 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/934/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/934/comments | https://api.github.com/repos/coleifer/peewee/issues/934/events | https://github.com/coleifer/peewee/issues/934 | 154,274,972 | MDU6SXNzdWUxNTQyNzQ5NzI= | 934 | Id field is not created with AUTOINCREMENT | {
"login": "mamcx",
"id": 238983,
"node_id": "MDQ6VXNlcjIzODk4Mw==",
"avatar_url": "https://avatars.githubusercontent.com/u/238983?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/mamcx",
"html_url": "https://github.com/mamcx",
"followers_url": "https://api.github.com/users/mamcx/followers",
"following_url": "https://api.github.com/users/mamcx/following{/other_user}",
"gists_url": "https://api.github.com/users/mamcx/gists{/gist_id}",
"starred_url": "https://api.github.com/users/mamcx/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/mamcx/subscriptions",
"organizations_url": "https://api.github.com/users/mamcx/orgs",
"repos_url": "https://api.github.com/users/mamcx/repos",
"events_url": "https://api.github.com/users/mamcx/events{/privacy}",
"received_events_url": "https://api.github.com/users/mamcx/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"It appears you are using Sqlite. Please read http://sqlite.org/autoinc.html for an explanation why this is not the default behavior. If you want autoincrement with Sqlite, you can use [PrimaryKeyAutoIncrementField](http://docs.peewee-orm.com/en/latest/peewee/playhouse.html#PrimaryKeyAutoIncrementField) in `playhouse.sqlite_ext`.\n"
] | 2016-05-11T15:38:37 | 2016-05-11T16:02:50 | 2016-05-11T16:02:30 | NONE | null | I have a normal model and the tables have the ID marked as not AUTOINCREMENT.
This is the code:
``` python
class BaseModel(Model):
class Meta:
database = db
class Cobro(BaseModel):
nombre = CharField()
```
``` sql
CREATE TABLE "cobro"(
"id" Integer NOT NULL PRIMARY KEY,
"nombre" Text NOT NULL )
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/934/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/934/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/933 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/933/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/933/comments | https://api.github.com/repos/coleifer/peewee/issues/933/events | https://github.com/coleifer/peewee/issues/933 | 154,263,885 | MDU6SXNzdWUxNTQyNjM4ODU= | 933 | BlobField cannot be used with uninitialized Proxy | {
"login": "vkrizan",
"id": 7695766,
"node_id": "MDQ6VXNlcjc2OTU3NjY=",
"avatar_url": "https://avatars.githubusercontent.com/u/7695766?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/vkrizan",
"html_url": "https://github.com/vkrizan",
"followers_url": "https://api.github.com/users/vkrizan/followers",
"following_url": "https://api.github.com/users/vkrizan/following{/other_user}",
"gists_url": "https://api.github.com/users/vkrizan/gists{/gist_id}",
"starred_url": "https://api.github.com/users/vkrizan/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/vkrizan/subscriptions",
"organizations_url": "https://api.github.com/users/vkrizan/orgs",
"repos_url": "https://api.github.com/users/vkrizan/repos",
"events_url": "https://api.github.com/users/vkrizan/events{/privacy}",
"received_events_url": "https://api.github.com/users/vkrizan/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Nice catch and fantastic issue report. I'll work on a solution.\n",
"Thank you. I resolved it with lazy imports, right after Proxy initialization.\n",
"The proxy should have a way to attach callbacks if I remember correctly, so I just need to move the binary type binding to a hook. I'll fix it regardless, but glad you're not blocked at the moment.\n",
"@coleifer I've run into an almost identical issue. Let me know if this should be its own issue.\r\n\r\nName: peewee\r\nVersion: 3.14.8 causes this issue with bind_ctx.\r\n\r\nIf I use bind instead of bind_ctx, this works fine, however I ultimately need bind_ctx to work. \r\n\r\n```python\r\ndb=SqliteDatabase(None, pragmas={'journal_mode': 'wal',\r\n 'cache_size': -1 * 64000, # 64MB\r\n 'foreign_keys': 1,\r\n 'ignore_check_constraints': 0,\r\n 'synchronous': 0})\r\ndatabase_proxy=DatabaseProxy()\r\n\r\nclass SomeModel(Model):\r\n some_id_field=AutoField()\r\n image_data=BlobField()\r\n \r\n class Meta: \r\n database=database_proxy\r\n \r\nSomeModel()\r\n\r\ndb_path='test_data/peewee.pb'\r\n\r\nwith db.bind_ctx([SomeModel]):\r\n db.init(db_path)\r\n db.create_tables([SomeModel])\r\n db.close()\r\n```\r\nOutputs:\r\n```bash\r\n---------------------------------------------------------------------------\r\nAttributeError Traceback (most recent call last)\r\n/tmp/ipykernel_102/1075978240.py in <module>\r\n 22 db.init(db_path)\r\n 23 db.create_tables([SomeModel])\r\n---> 24 db.close()\r\n\r\n/opt/conda/lib/python3.9/site-packages/peewee.py in __exit__(self, exc_type, exc_val, exc_tb)\r\n 6291 def __exit__(self, exc_type, exc_val, exc_tb):\r\n 6292 for model, db in zip(self.models, self._orig_database):\r\n-> 6293 model.bind(db, self.bind_refs, self.bind_backrefs,\r\n 6294 _exclude=set(self.models))\r\n 6295 \r\n\r\n/opt/conda/lib/python3.9/site-packages/peewee.py in bind(cls, database, bind_refs, bind_backrefs, _exclude)\r\n 6687 def bind(cls, database, bind_refs=True, bind_backrefs=True, _exclude=None):\r\n 6688 is_different = cls._meta.database is not database\r\n-> 6689 cls._meta.set_database(database)\r\n 6690 if bind_refs or bind_backrefs:\r\n 6691 if _exclude is None:\r\n\r\n/opt/conda/lib/python3.9/site-packages/peewee.py in set_database(self, database)\r\n 6124 # Apply any hooks that have been registered.\r\n 6125 for hook in self._db_hooks:\r\n-> 6126 hook(database)\r\n 6127 \r\n 6128 def set_table_name(self, table_name):\r\n\r\n/opt/conda/lib/python3.9/site-packages/peewee.py in _db_hook(self, database)\r\n 4761 self._constructor = bytearray\r\n 4762 else:\r\n-> 4763 self._constructor = database.get_binary_type()\r\n 4764 \r\n 4765 def bind(self, model, name, set_attribute=True):\r\n\r\n/opt/conda/lib/python3.9/site-packages/peewee.py in __getattr__(self, attr)\r\n 446 def __getattr__(self, attr):\r\n 447 if self.obj is None:\r\n--> 448 raise AttributeError('Cannot use uninitialized Proxy.')\r\n 449 return getattr(self.obj, attr)\r\n 450 \r\nAttributeError: Cannot use uninitialized Proxy.\r\n```\r\n### My opinion:\r\nSeems like on exit, when switching back to the Proxy, it tries getting the binary type.\r\nWe could fix this by converting:\r\n```python\r\n# BlobField...\r\n def _db_hook(self, database):\r\n if database is None:\r\n self._constructor = bytearray\r\n else:\r\n self._constructor = database.get_binary_type()\r\n```\r\nto\r\n```python\r\n# BlobField...\r\n def _db_hook(self, database):\r\n if database is None or isinstance(database, Proxy):\r\n self._constructor = bytearray\r\n else:\r\n self._constructor = database.get_binary_type()\r\n```\r\n\r\n\r\n",
"@josiahlaivins - see 13e05a3 for fix."
] | 2016-05-11T14:53:51 | 2022-01-06T14:18:50 | 2016-05-20T14:44:45 | NONE | null | BlobField determines its binary type on its initialization. BlobField then cannot be used with Proxied database that is not initialized. An `AttributeError` is risen right after module execution/import.
Reproducer:
```
import peewee
class NonWorkingBlobFieldOnProxy(peewee.Model):
class Meta:
database = peewee.Proxy()
myblob = peewee.BlobField()
```
Raises:
```
Traceback (most recent call last):
File "proxy_example.py", line 3, in <module>
class NonWorkingBlobFieldOnProxy(peewee.Model):
File "venv/lib/python2.7/site-packages/peewee.py", line 4479, in __new__
field.add_to_class(cls, name)
File "venv/lib/python2.7/site-packages/peewee.py", line 1081, in add_to_class
self._constructor = model_class._meta.database.get_binary_type()
File "venv/lib/python2.7/site-packages/peewee.py", line 407, in __getattr__
raise AttributeError('Cannot use uninitialized Proxy.')
AttributeError: Cannot use uninitialized Proxy.
```
This affects version 2.8.1. In later versions (2.6.X) this problem did not occur.
Commit that introduced this regression: b32e967e
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/933/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/933/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/932 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/932/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/932/comments | https://api.github.com/repos/coleifer/peewee/issues/932/events | https://github.com/coleifer/peewee/issues/932 | 154,172,565 | MDU6SXNzdWUxNTQxNzI1NjU= | 932 | MySQL: peewee adds extra characters to table name when db.create_tables() | {
"login": "Eric-hjy",
"id": 19300603,
"node_id": "MDQ6VXNlcjE5MzAwNjAz",
"avatar_url": "https://avatars.githubusercontent.com/u/19300603?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/Eric-hjy",
"html_url": "https://github.com/Eric-hjy",
"followers_url": "https://api.github.com/users/Eric-hjy/followers",
"following_url": "https://api.github.com/users/Eric-hjy/following{/other_user}",
"gists_url": "https://api.github.com/users/Eric-hjy/gists{/gist_id}",
"starred_url": "https://api.github.com/users/Eric-hjy/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/Eric-hjy/subscriptions",
"organizations_url": "https://api.github.com/users/Eric-hjy/orgs",
"repos_url": "https://api.github.com/users/Eric-hjy/repos",
"events_url": "https://api.github.com/users/Eric-hjy/events{/privacy}",
"received_events_url": "https://api.github.com/users/Eric-hjy/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2016-05-11T06:54:05 | 2016-05-11T07:10:52 | 2016-05-11T07:10:52 | NONE | null | As the title, when I used peewee to create mysql tables, some characters were added by peewee and that made table creation fail. To make sure it was not my python codes making the error, I printed out
the table names before calling db.create_tables()
Below are the logs of my codes plus the reported error traces:
Connect to DB: AFA_INF_TATA // this is the traces of my codes
Instance BAIDU_INF_MOLA Start // this is the traces of my codes
Log: Create Database table dfd-df-4-345d-67-init-done_other-tata_all_stats_table, dfd-df-4-345d-67-init-done_other-mola_all_host_table //these are printed table names
Traceback (most recent call last):
File "./mon_query.py", line 496, in <module>
mon_query_func()
File "./mon_query.py", line 474, in mon_query_func
db.create_tables([MonQueryTable, ServiceHostTable], safe = True)
File "/usr/lib/python2.6/site-packages/peewee-2.6.3-py2.6.egg/peewee.py", line 3386, in create_tables
create_model_tables(models, fail_silently=safe)
File "/usr/lib/python2.6/site-packages/peewee-2.6.3-py2.6.egg/peewee.py", line 4565, in create_model_tables
m.create_table(*_create_table_kwargs)
File "/usr/lib/python2.6/site-packages/peewee-2.6.3-py2.6.egg/peewee.py", line 4309, in create_table
cls._create_indexes()
File "/usr/lib/python2.6/site-packages/peewee-2.6.3-py2.6.egg/peewee.py", line 4333, in _create_indexes
db.create_index(cls, fields, unique)
File "/usr/lib/python2.6/site-packages/peewee-2.6.3-py2.6.egg/peewee.py", line 3396, in create_index
return self.execute_sql(_qc.create_index(model_class, fobjs, unique))
File "/usr/lib/python2.6/site-packages/peewee-2.6.3-py2.6.egg/peewee.py", line 3304, in execute_sql
self.commit()
File "/usr/lib/python2.6/site-packages/peewee-2.6.3-py2.6.egg/peewee.py", line 3152, in **exit**
reraise(new_type, new_type(*exc_args), traceback)
File "/usr/lib/python2.6/site-packages/peewee-2.6.3-py2.6.egg/peewee.py", line 3296, in execute_sql
cursor.execute(sql, params or ())
File "/usr/lib64/python2.6/site-packages/MySQL_python-1.2.3c1-py2.6-linux-x86_64.egg/MySQLdb/cursors.py", line 173, in execute
self.errorhandler(self, exc, value)
File "/usr/lib64/python2.6/site-packages/MySQL_python-1.2.3c1-py2.6-linux-x86_64.egg/MySQLdb/connections.py", line 36, in defaulterrorhandler
raise errorclass, errorvalue
peewee.OperationalError: (1059, "Identifier name 'dfd-df-4-345d-67-init-done_other-mola_all_host_table_fb51e9a09dcfdac685fc80af91c194d7' is too long")
From error traces, I saw the table name is changed to "dfd-df-4-345d-67-init-done_other-mola_all_host_table_fb51e9a09dcfdac685fc80af91c194d7"
Below is the related python codes:
```
statsTableName = get_query_table_name(service_name)
hostTableName = get_service_host_table_name(service_name)
LogFunc(log_f, 1, 'Create Database table ' + statsTableName + ', ' + hostTableName + '\n')
QueryTable._meta.db_table = statsTableName
ServiceHostTable._meta.db_table = hostTableName
db.create_tables([QueryTable, HostTable], safe = True)
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/932/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/932/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/931 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/931/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/931/comments | https://api.github.com/repos/coleifer/peewee/issues/931/events | https://github.com/coleifer/peewee/issues/931 | 154,135,249 | MDU6SXNzdWUxNTQxMzUyNDk= | 931 | Peewee and custom primary keys | {
"login": "SegFaultAX",
"id": 87773,
"node_id": "MDQ6VXNlcjg3Nzcz",
"avatar_url": "https://avatars.githubusercontent.com/u/87773?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/SegFaultAX",
"html_url": "https://github.com/SegFaultAX",
"followers_url": "https://api.github.com/users/SegFaultAX/followers",
"following_url": "https://api.github.com/users/SegFaultAX/following{/other_user}",
"gists_url": "https://api.github.com/users/SegFaultAX/gists{/gist_id}",
"starred_url": "https://api.github.com/users/SegFaultAX/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/SegFaultAX/subscriptions",
"organizations_url": "https://api.github.com/users/SegFaultAX/orgs",
"repos_url": "https://api.github.com/users/SegFaultAX/repos",
"events_url": "https://api.github.com/users/SegFaultAX/events{/privacy}",
"received_events_url": "https://api.github.com/users/SegFaultAX/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"> Of course setting force_insert=True works as expected, but why is that necessary in this context?\n\nIt's [explained in the documentation](http://docs.peewee-orm.com/en/latest/peewee/models.html#id3).\n\nPerhaps showing the SQL will help:\n\n``` python\nimport logging\nlogger=logging.getLogger('peewee')\nlogger.setLevel(logging.DEBUG)\nlogger.addHandler(logging.StreamHandler())\n\n>>> e2 = ExampleTwo(field1='f1', field2='f2')\n>>> e2.save()\n('UPDATE \"exampletwo\" SET \"field2\" = ? WHERE (\"exampletwo\".\"field1\" = ?)', [u'f2', u'f1'])\n0\n\n>>> e2.save(force_insert=True)\n('INSERT INTO \"exampletwo\" (\"field1\", \"field2\") VALUES (?, ?)', [u'f1', u'f2'])\n1\n\n>>> ex3 = ExampleThree(field1='f1', field2='f2')\n>>> ex3.save()\n('UPDATE \"examplethree\" SET WHERE ((\"examplethree\".\"field1\" = ?) AND (\"examplethree\".\"field2\" = ?))', [u'f1', u'f2'])\nOPERATIONAL ERROR BECAUSE NO VALUES BEING SET\"\n\n>>> ex3.save(force_insert=True)\n('INSERT INTO \"examplethree\" (\"field1\", \"field2\") VALUES (?, ?)', [u'f1', u'f2'])\nINTEGRITY ERROR BECAUSE YOU DECLARED FIELD3 AS NOT NULL (pass null=True for nullable)\n\n>>> ex3,field3 = 'not null'\n>>> ex3.save(force_insert=True)\n('INSERT INTO \"examplethree\" (\"field1\", \"field2\", \"field3\") VALUES (?, ?, ?)', [u'f1', u'f2', u'not null'])\n1\n```\n\nWhat did you expect? How is peewee supposed to know, when dealing with a non-auto-incremented primary key, whether the user means to update an existing record in the db or they are creating one? To perform runtime checks would be incredibly inefficient.\n\nPeewee provides a shortcut, `ExampleTwo.create(field1='foo', field2='bar')` that will use `force_insert` behind the scenes.\n\nHopefully this clarifies the issue for you.\n",
"@coleifer First of all, I did completely miss that paragraph after glancing over that section more than once. Whoops. :) Thanks for the clarification! My expectation was simply that it would always try an insert on a record it knew was not constructed as the result of a query to the database, rather than automatically varying the operation based on the presence (or non-presence) of the primary key. (I'm fine with a constraint violation error in that case, because if I meant `get_or_create`/`upsert` I would have used that explicitly). But otherwise this logic makes sense to me. Thanks again!\n",
"Glad to help. Peewee is active record as opposed to a more stateful orm. As such there is no in memory representation of an object from a query vs an object constructed in code. This simplifies the orm implementation as well as the intuition behind its operation but it may not be obvious immediately.\n",
"I removed my prior comment because it was redundant with the documentation and I need to slow down and read! Thanks again for all your time. :D\n"
] | 2016-05-11T00:22:07 | 2016-05-11T17:03:11 | 2016-05-11T16:16:22 | NONE | null | Hello peewee team! I'm trying to understand some odd behavior when using custom primary keys with peewee. Kindly consider the following snippet:
``` python
# dependencies: peewee==2.8.1
import peewee
db = peewee.SqliteDatabase(":memory:")
class BaseModel(peewee.Model):
class Meta:
database = db
class ExampleOne(BaseModel):
field1 = peewee.TextField()
field2 = peewee.TextField()
class ExampleTwo(BaseModel):
field1 = peewee.TextField(primary_key=True)
field2 = peewee.TextField()
class ExampleThree(BaseModel):
field1 = peewee.TextField()
field2 = peewee.TextField()
field3 = peewee.TextField()
class Meta:
primary_key = peewee.CompositeKey("field1", "field2")
def main():
db.create_tables([ExampleOne, ExampleTwo, ExampleThree])
ex1 = ExampleOne()
ex1.field1 = "Field 1 value"
ex1.field2 = "Field 2 value"
print ex1.save()
ex2 = ExampleTwo()
ex2.field1 = "Field 1 value"
ex2.field2 = "Field 2 value"
print ex2.save()
ex3 = ExampleThree()
ex3.field1 = "Field 1 value"
ex3.field2 = "Field 2 value"
ex3.field3 = "Why is this required?"
print ex3.save()
if __name__ == "__main__":
main()
```
If you run this script, the output will be
```
1
0
0
```
My _expectation_ was 1's across the board (indicating 3 rows inserted into 3 separate tables). But that's not what happened...
Why do `ExampleTwo` and `ExampleThree` above fail to persist to the database? Specifically, I don't understand why specifying `primary_key=True` on `field1` of `ExampleTwo` means that it cannot save a new record (especially in a database we know a priori has no data in it and therefore no conflict). Of course setting `force_insert=True` works as expected, but why is that **necessary** in this context? Furthermore, composite primary keys [seem to be natively supported](http://docs.peewee-orm.com/en/latest/peewee/models.html#composite-primary-keys), but for whatever reason `ExampleThree` still fails to persist the new record (I'm guessing for the same reason `ExampleTwo` fails).
Finally (and I think unrelated to my actual question), you'll notice that I added a third field to `ExampleThree`. If I omit that field, I get the following error:
```
Traceback (most recent call last):
File "wat.py", line 44, in <module>
main()
File "wat.py", line 41, in main
print ex3.save()
File "/Users/mkbernard/.pyenv/versions/vmware-scripts/lib/python2.7/site-packages/peewee.py", line 4742, in save
rows = self.update(**field_dict).where(self._pk_expr()).execute()
File "/Users/mkbernard/.pyenv/versions/vmware-scripts/lib/python2.7/site-packages/peewee.py", line 3117, in execute
return self.database.rows_affected(self._execute())
File "/Users/mkbernard/.pyenv/versions/vmware-scripts/lib/python2.7/site-packages/peewee.py", line 2656, in _execute
return self.database.execute_sql(sql, params, self.require_commit)
File "/Users/mkbernard/.pyenv/versions/vmware-scripts/lib/python2.7/site-packages/peewee.py", line 3492, in execute_sql
self.commit()
File "/Users/mkbernard/.pyenv/versions/vmware-scripts/lib/python2.7/site-packages/peewee.py", line 3316, in __exit__
reraise(new_type, new_type(*exc_args), traceback)
File "/Users/mkbernard/.pyenv/versions/vmware-scripts/lib/python2.7/site-packages/peewee.py", line 3485, in execute_sql
cursor.execute(sql, params or ())
peewee.OperationalError: near "WHERE": syntax error
```
I haven't dug in to figure out why that last bit happened, but it's shocking to me that a table with only primary key fields blows up peewee. Regardless, my bigger issue is understanding the failing examples above. Any insight would be greatly appreciated!
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/931/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/931/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/930 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/930/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/930/comments | https://api.github.com/repos/coleifer/peewee/issues/930/events | https://github.com/coleifer/peewee/issues/930 | 154,068,615 | MDU6SXNzdWUxNTQwNjg2MTU= | 930 | pwiz fails to generate correct code: UnknownField | {
"login": "james-lawrence",
"id": 2835871,
"node_id": "MDQ6VXNlcjI4MzU4NzE=",
"avatar_url": "https://avatars.githubusercontent.com/u/2835871?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/james-lawrence",
"html_url": "https://github.com/james-lawrence",
"followers_url": "https://api.github.com/users/james-lawrence/followers",
"following_url": "https://api.github.com/users/james-lawrence/following{/other_user}",
"gists_url": "https://api.github.com/users/james-lawrence/gists{/gist_id}",
"starred_url": "https://api.github.com/users/james-lawrence/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/james-lawrence/subscriptions",
"organizations_url": "https://api.github.com/users/james-lawrence/orgs",
"repos_url": "https://api.github.com/users/james-lawrence/repos",
"events_url": "https://api.github.com/users/james-lawrence/events{/privacy}",
"received_events_url": "https://api.github.com/users/james-lawrence/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2016-05-10T17:58:03 | 2016-05-11T16:01:05 | 2016-05-11T16:01:05 | CONTRIBUTOR | null | ```
createdb
psql <<EOF
CREATE TABLE example (
address inet DEFAULT '0.0.0.0'::inet NOT NULL PRIMARY KEY
);
EOF
python -m pwiz -e postgresql -u $USER $USER
```
generates the following code:
```
class UnknownField(object):
pass
class BaseModel(Model):
class Meta:
database = database
class Example(BaseModel):
address = UnknownField(primary_key=True) # inet
class Meta:
db_table = 'example'
```
UnknownField blows up because it expects named args and it has no initializer.
it should be:
```
class UnknownField(object):
def __init__(self, **kwargs):
pass
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/930/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/930/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/929 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/929/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/929/comments | https://api.github.com/repos/coleifer/peewee/issues/929/events | https://github.com/coleifer/peewee/issues/929 | 154,067,115 | MDU6SXNzdWUxNTQwNjcxMTU= | 929 | pwiz fails to generate correct code: missing extension import. | {
"login": "james-lawrence",
"id": 2835871,
"node_id": "MDQ6VXNlcjI4MzU4NzE=",
"avatar_url": "https://avatars.githubusercontent.com/u/2835871?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/james-lawrence",
"html_url": "https://github.com/james-lawrence",
"followers_url": "https://api.github.com/users/james-lawrence/followers",
"following_url": "https://api.github.com/users/james-lawrence/following{/other_user}",
"gists_url": "https://api.github.com/users/james-lawrence/gists{/gist_id}",
"starred_url": "https://api.github.com/users/james-lawrence/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/james-lawrence/subscriptions",
"organizations_url": "https://api.github.com/users/james-lawrence/orgs",
"repos_url": "https://api.github.com/users/james-lawrence/repos",
"events_url": "https://api.github.com/users/james-lawrence/events{/privacy}",
"received_events_url": "https://api.github.com/users/james-lawrence/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Not the author but I'll answer anyways.\n\n`JSONField` is contained in `playhouse.postgres_ext` so you need another import, i.e\n\n``` python\nfrom peewee import *\nfrom playhouse.postgres_ext import JSONField # <----------\n\ndatabase = PostgresqlDatabase('user', **{'user': 'user'})\n\nclass UnknownField(object):\n pass\n\nclass BaseModel(Model):\n class Meta:\n database = database\n\nclass Example(BaseModel):\n field1 = JSONField(null=True)\n\n class Meta:\n db_table = 'example'\n```\n\nSee http://peewee.readthedocs.io/en/latest/peewee/playhouse.html#postgresql-extensions\n",
"I'm well aware of the fix and how to fix it. my point is if pwiz is going to generate this code it should generate it correctly. i.e.) it includes the required import automatically. I shouldn't have to modify the code after.\n",
"Oh, sorry, didn't realize that all of it was generated.\n"
] | 2016-05-10T17:50:58 | 2016-05-30T23:26:50 | 2016-05-30T23:26:50 | CONTRIBUTOR | null | if a table contains a json field, NameError: name 'JSONField' is not defined is raised.
pwiz should just include the import, it shouldn't generate code that doesn't work.
```
createdb
psql <<EOF
CREATE TABLE example (
field1 json
);
EOF
python -m pwiz -e postgresql -u $USER $USER
```
generated the following code:
```
from peewee import *
database = PostgresqlDatabase('user', **{'user': 'user'})
class UnknownField(object):
pass
class BaseModel(Model):
class Meta:
database = database
class Example(BaseModel):
field1 = JSONField(null=True)
class Meta:
db_table = 'example'
```
generated code blows up on the JSONField()
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/929/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/929/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/928 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/928/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/928/comments | https://api.github.com/repos/coleifer/peewee/issues/928/events | https://github.com/coleifer/peewee/issues/928 | 153,936,898 | MDU6SXNzdWUxNTM5MzY4OTg= | 928 | How to use "select distinct binary content from table;" in peewee? | {
"login": "ladder1984",
"id": 3875374,
"node_id": "MDQ6VXNlcjM4NzUzNzQ=",
"avatar_url": "https://avatars.githubusercontent.com/u/3875374?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/ladder1984",
"html_url": "https://github.com/ladder1984",
"followers_url": "https://api.github.com/users/ladder1984/followers",
"following_url": "https://api.github.com/users/ladder1984/following{/other_user}",
"gists_url": "https://api.github.com/users/ladder1984/gists{/gist_id}",
"starred_url": "https://api.github.com/users/ladder1984/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/ladder1984/subscriptions",
"organizations_url": "https://api.github.com/users/ladder1984/orgs",
"repos_url": "https://api.github.com/users/ladder1984/repos",
"events_url": "https://api.github.com/users/ladder1984/events{/privacy}",
"received_events_url": "https://api.github.com/users/ladder1984/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"You can do a couple things, but think the simplest would be something like:\n\n``` python\nfrom peewee import *\n\nMyModel.select(Clause(SQL('distinct binary'), MyModel.content))\n\n# select distinct binary t1.content from ...\n```\n\nYou may need to attach an alias to the clause so peewee knows what attribute the value belongs to:\n\n`, MyModel.content).alias('content')`\n"
] | 2016-05-10T07:02:48 | 2016-05-11T15:14:04 | 2016-05-11T15:14:04 | NONE | null | How to use "select distinct binary content from table;" in peewee? I want to use "binary" when "select distinct " .
What's more,I use peewee 2.6.4.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/928/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/928/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/927 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/927/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/927/comments | https://api.github.com/repos/coleifer/peewee/issues/927/events | https://github.com/coleifer/peewee/issues/927 | 153,385,802 | MDU6SXNzdWUxNTMzODU4MDI= | 927 | peewee-versioned 0.1 | {
"login": "kramer65",
"id": 596581,
"node_id": "MDQ6VXNlcjU5NjU4MQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/596581?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/kramer65",
"html_url": "https://github.com/kramer65",
"followers_url": "https://api.github.com/users/kramer65/followers",
"following_url": "https://api.github.com/users/kramer65/following{/other_user}",
"gists_url": "https://api.github.com/users/kramer65/gists{/gist_id}",
"starred_url": "https://api.github.com/users/kramer65/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/kramer65/subscriptions",
"organizations_url": "https://api.github.com/users/kramer65/orgs",
"repos_url": "https://api.github.com/users/kramer65/repos",
"events_url": "https://api.github.com/users/kramer65/events{/privacy}",
"received_events_url": "https://api.github.com/users/kramer65/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Looks nice! I'll leave it to Google to help people find your project but if someone should ask about similar work I'll certainly keep this in mind. I'm kind of curious how foreign keys / referential integrity works when you delete a model but older versions of another table relate to the now-deleted object. There are maybe some edge cases? It also looks like there are gaps in the valid_from / valid_until that probably shouldn't be there... Other than that, though looks good!\n"
] | 2016-05-06T06:22:11 | 2016-05-06T19:59:09 | 2016-05-06T19:59:09 | NONE | null | Hi @coleifer - after using the code in our own website for a little while I've now released the code for peewee versioned on my github account here: https://github.com/kramer65/peewee-versioned
It would be great if you can have a look at it and possibly test it. I'd appreciate feedback on how to usage works now and how we can make that more intuitive.
And of course feel free to link to it from the peewee docs. Other people might find this useful as well. :-)
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/927/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/927/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/926 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/926/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/926/comments | https://api.github.com/repos/coleifer/peewee/issues/926/events | https://github.com/coleifer/peewee/issues/926 | 153,239,747 | MDU6SXNzdWUxNTMyMzk3NDc= | 926 | Extra Parenthesis | {
"login": "stanep",
"id": 3240661,
"node_id": "MDQ6VXNlcjMyNDA2NjE=",
"avatar_url": "https://avatars.githubusercontent.com/u/3240661?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/stanep",
"html_url": "https://github.com/stanep",
"followers_url": "https://api.github.com/users/stanep/followers",
"following_url": "https://api.github.com/users/stanep/following{/other_user}",
"gists_url": "https://api.github.com/users/stanep/gists{/gist_id}",
"starred_url": "https://api.github.com/users/stanep/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/stanep/subscriptions",
"organizations_url": "https://api.github.com/users/stanep/orgs",
"repos_url": "https://api.github.com/users/stanep/repos",
"events_url": "https://api.github.com/users/stanep/events{/privacy}",
"received_events_url": "https://api.github.com/users/stanep/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Sorry, you'll need to write a tool to strip them out or extend the QueryCompiler class.\n"
] | 2016-05-05T14:07:33 | 2016-05-05T14:29:01 | 2016-05-05T14:29:01 | NONE | null | Hi if I have query like this
qr = Cwle.select(Cwle.WaitlistEntryID).filter(
(Cwle.WaitlistEntryID == 1) & (Cwle.WaitlistEntryID == 4)
)
print qr , will give you
SELECT CWLE.WaitlistEntryID FROM WCPRDDB1.dbo.CardiacWaitListEntry AS CWLE WHERE ((CWLE.WaitlistEntryID = ?) AND (CWLE.WaitlistEntryID = ?)) [1, 4]
Is it possible to remove outer Parenthesis?
SELECT CWLE.WaitlistEntryID FROM WCPRDDB1.dbo.CardiacWaitListEntry AS CWLE WHERE (CWLE.WaitlistEntryID = ? AND CWLE.WaitlistEntryID = ?) [1, 4]
Reason being that sometimes I want to get query from peewee and run it in db management tool, all
these extra Parenthesis makes your eyes bleeds :)
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/926/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/926/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/925 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/925/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/925/comments | https://api.github.com/repos/coleifer/peewee/issues/925/events | https://github.com/coleifer/peewee/issues/925 | 153,074,396 | MDU6SXNzdWUxNTMwNzQzOTY= | 925 | Alias doesn't work if it's not the first join | {
"login": "Pirheas",
"id": 15324922,
"node_id": "MDQ6VXNlcjE1MzI0OTIy",
"avatar_url": "https://avatars.githubusercontent.com/u/15324922?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/Pirheas",
"html_url": "https://github.com/Pirheas",
"followers_url": "https://api.github.com/users/Pirheas/followers",
"following_url": "https://api.github.com/users/Pirheas/following{/other_user}",
"gists_url": "https://api.github.com/users/Pirheas/gists{/gist_id}",
"starred_url": "https://api.github.com/users/Pirheas/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/Pirheas/subscriptions",
"organizations_url": "https://api.github.com/users/Pirheas/orgs",
"repos_url": "https://api.github.com/users/Pirheas/repos",
"events_url": "https://api.github.com/users/Pirheas/events{/privacy}",
"received_events_url": "https://api.github.com/users/Pirheas/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Dude, I'm not going to read all that crap. Can you distill this into a short model or two and a query that fails?\n",
"Well, yeah, only the tests are important, the \"crap\" was only there to make it easier to reproduce.\n\n``` python\ndef test2():\n # It doesn't work. \"teacher\" alias is not present in data element\n data = (Student.select(Student, Teacher)\n .join(Studentcourse)\n .join(Course)\n .join(Teacher, \n on=(Teacher.id_teacher == Course.id_teacher).alias('teacher')))\n for d in data:\n print(d.name, '|', d.teacher.name)\n\n\ndef test3():\n data = (Student.select(Student, Studentcourse, Course)\n .join(Studentcourse, \n on=(Student.id_student == Studentcourse.id_student).alias('sc'))\n .join(Course, \n on=(Course.id_course == Studentcourse.id_course).alias('course')))\n\n for d in data: # It works\n print(d.name, ' -> ', d.sc.id_course.name)\n\n for d in data: # It doesn't\n print(d.name, '|', d.course.name)\n```\n",
"Well, I think you've just misunderstood the way the models are re-constructed by the query result wrapper.\n\nIn `test3`, you will be able to access the course like this:\n\n``` python\nfor d in data:\n print d.name, d.sc.course.name\n```\n\nYour comment that \"it works\" is actually wrong because that `sc.id_course` lookup is resolving the foreign key, costing you _n_ extra queries.\n\nIn `test2` a similar thing is happening, though it's less apparent why. You've selected Student and Teacher but none of the intermediary models needed to reconstruct the join graph. To fix this you can do this:\n\n``` python\ndata = (Student.select(Student, Studentcourse, Course, Teacher).join(...)\nfor d in data:\n print d.studentcourse.id_course.teacher.name\n```\n\nOr you can just use `naive` and do:\n\n``` python\ndata = Student.select(Student, Teacher.name.alias('teacher_name')).join(...)\n```\n\nOther things to consider would be renaming your foreign key fields. Why use `id_xxx` when Peewee provides the `db_column` attribute so you can avoid mangling up your python code?\n"
] | 2016-05-04T17:47:56 | 2016-05-06T19:35:21 | 2016-05-06T19:35:21 | NONE | null | Hello,
It seems that aliases only works if they are used on the first join.
Well, a small example will explain better:
SQL database creation:
``` sql
CREATE TABLE Student(
id_student INTEGER PRIMARY KEY,
name TEXT NOT NULL
);
CREATE TABLE Teacher(
id_teacher INTEGER PRIMARY KEY,
name TEXT NOT NULL
);
CREATE TABLE Course(
id_course INTEGER PRIMARY KEY,
name TEXT NOT NULL,
id_teacher INTEGER NOT NULL,
FOREIGN KEY (id_teacher) REFERENCES Teacher(id_teacher) ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE StudentCourse(
id_student_course SERIAL PRIMARY KEY,
id_student INTEGER NOT NULL,
id_course INTEGER NOT NULL,
FOREIGN KEY (id_student) REFERENCES Student(id_student) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY (id_course) REFERENCES Course(id_course) ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE UNIQUE INDEX unique_student_course ON StudentCourse(id_student, id_course);
INSERT INTO Student(id_student, name) VALUES (1, 'Pirheas'), (2, 'Mike'), (3, 'Clara');
INSERT INTO Teacher(id_teacher, name) VALUES (1, 'Guido Van Rossum'), (2, 'Coleifer');
INSERT INTO Course(id_course, name, id_teacher) VALUES (1, 'Python', 1), (2, 'Peewee', 2);
INSERT INTO StudentCourse(id_student, id_course) VALUES (1,1), (1,2), (2,1), (3,2);
```
Tests:
``` python
#!/usr/bin/env python3
from peewee import *
database = PostgresqlDatabase('peewee_test', **{'user': 'postgres', 'host': '127.0.0.1', 'port': 8888, 'password': '<#redacted>'})
class UnknownField(object):
pass
class BaseModel(Model):
class Meta:
database = database
class Teacher(BaseModel):
id_teacher = PrimaryKeyField()
name = TextField()
class Meta:
db_table = 'teacher'
class Course(BaseModel):
id_course = PrimaryKeyField()
id_teacher = ForeignKeyField(db_column='id_teacher', rel_model=Teacher, to_field='id_teacher')
name = TextField()
class Meta:
db_table = 'course'
class Student(BaseModel):
id_student = PrimaryKeyField()
name = TextField()
class Meta:
db_table = 'student'
class Studentcourse(BaseModel):
id_course = ForeignKeyField(db_column='id_course', rel_model=Course, to_field='id_course')
id_student = ForeignKeyField(db_column='id_student', rel_model=Student, to_field='id_student')
id_student_course = PrimaryKeyField()
class Meta:
db_table = 'studentcourse'
indexes = (
(('id_student', 'id_course'), True),
)
########################################################################################################
def test1():
# This works perfectly
data = (Student.select(Student, Teacher)
.join(Teacher, on=(Teacher.id_teacher == Student.id_student).alias('teacher'))) # Just for testing
for d in data:
print(d.name, '|', d.teacher.name)
def test2():
#It doesn't work. "teacher" alias is not present in data element
data = (Student.select(Student, Teacher)
.join(Studentcourse)
.join(Course)
.join(Teacher, on=(Teacher.id_teacher == Course.id_teacher).alias('teacher')))
for d in data:
print(d.name, '|', d.teacher.name)
def test3():
data = (Student.select(Student, Studentcourse, Course)
.join(Studentcourse, on=(Student.id_student == Studentcourse.id_student).alias('sc'))
.join(Course, on=(Course.id_course == Studentcourse.id_course).alias('course')))
for d in data: # It works
print(d.name, ' -> ', d.sc.id_course.name)
for d in data: # It doesn't
print(d.name, '|', d.course.name)
if __name__ == '__main__':
print(' == Test 1 ==')
test1()
print('\n == Test 2 ==')
try:
test2()
except Exception as e:
print('Error: ', str(e))
print('\n == Test 3 ==')
try:
test3()
except Exception as e:
print('Error: ', str(e))
```
Thanks
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/925/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/925/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/924 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/924/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/924/comments | https://api.github.com/repos/coleifer/peewee/issues/924/events | https://github.com/coleifer/peewee/issues/924 | 153,039,833 | MDU6SXNzdWUxNTMwMzk4MzM= | 924 | Abstract Model database metadata inheritance doesn't work | {
"login": "erwagasore",
"id": 1290048,
"node_id": "MDQ6VXNlcjEyOTAwNDg=",
"avatar_url": "https://avatars.githubusercontent.com/u/1290048?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/erwagasore",
"html_url": "https://github.com/erwagasore",
"followers_url": "https://api.github.com/users/erwagasore/followers",
"following_url": "https://api.github.com/users/erwagasore/following{/other_user}",
"gists_url": "https://api.github.com/users/erwagasore/gists{/gist_id}",
"starred_url": "https://api.github.com/users/erwagasore/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/erwagasore/subscriptions",
"organizations_url": "https://api.github.com/users/erwagasore/orgs",
"repos_url": "https://api.github.com/users/erwagasore/repos",
"events_url": "https://api.github.com/users/erwagasore/events{/privacy}",
"received_events_url": "https://api.github.com/users/erwagasore/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"First off, where did you get the `meta.abstract` thing? That is a django orm thing, not peewee.\n",
"Oh. I thought peewee have similar implementation. My mistake.\nDoes peewee have something like this?\n",
"I should close this issue then\n",
"Also the code works fine for me:\n\n``` python\n\nIn [5]: from peewee import *\n\nIn [6]: db = SqliteDatabase('foo.db')\n\nIn [7]: db.database\nOut[7]: 'foo.db'\n\nIn [8]: class BaseModel(Model):\n timestamp = DateTimeField()\n class Meta:\n database = db\n db_table_func = lambda model_cls: model_cls.__name__.title()\n ...: \n\nIn [9]: class TestModel(BaseModel):\n ...: name = CharField()\n ...: \n\nIn [10]: tm = TestModel(name='test')\n\nIn [11]: tm._meta.database.database\nOut[11]: 'foo.db'\n\nIn [12]: tm._meta.db_table\nOut[12]: 'Testmodel'\n```\n",
"I am using `from playhouse.flask_utils import FlaskDB` and `from playhouse.signals import Model` I guess that mix is the one causing issues \n",
"It is trick if you want to benefit from both playhouse flask utils `FlaskDB` and also benefit from signals\n",
"@coleifer I found out the cause of such wild behaviour.\n\nThe cause was that I was using `playhouse.signals.Model`with `playhouse.flask_utils.FlaskDB`.\n\nI solved it by using both\n\n``` python\nfrom playhouse.flask_utils import FlaskDB\nfrom playhouse.signals import Model\n\ndb = FlaskDB(app, ....)\n\nclass BaseModel(db.Model, Model):\n class Meta:\n database = db.database\n\nclass Foo(BaseModel):\n name = CharField()\n...\n```\n\nI don't know if this is the sane way to do it but it seems to work\n",
"Yes, FlaskDB is a wrapper and you still need to point at the underlying peewee db\n",
"Cool. Thanks\n",
"@coleifer, `BaseModel` from your example will also generate a table in db. Do we have any option to specify that for a specific model we don't want a table?",
"Only if you call `BasModel.create_table()` or pass it to database.create_tables(), so I'm not sure I see the problem."
] | 2016-05-04T15:21:57 | 2019-05-18T10:59:57 | 2016-05-04T17:07:07 | NONE | null | ``` python
db = PostgresqlDatabase(...)
class BaseModel(Model):
created_at = DateTimeField(default=datetime.now)
modified_at = DateTimeField(default=datetime.now)
class Meta:
abstract = True
db_table_func = lambda model_cls: tableize(model_cls.__name__)
database = db
class Foo(BaseModel):
name = CharField()
foo = Foo(name="Foo Bar")
foo.name #-> Foo Bar
foo._meta.db_table #-> foos
foo._meta.database #-> <peewee.SqliteDatabase object at 0x1012e64a8>
```
Inheritance from the abstract model works on field and other _meta arguments but database.
when I call `create_tables` for all model i found that an sqlite db have been created called `peewee.db`
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/924/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/924/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/923 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/923/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/923/comments | https://api.github.com/repos/coleifer/peewee/issues/923/events | https://github.com/coleifer/peewee/issues/923 | 153,014,439 | MDU6SXNzdWUxNTMwMTQ0Mzk= | 923 | PooledMySQL is not working with connect | {
"login": "gfreezy",
"id": 510012,
"node_id": "MDQ6VXNlcjUxMDAxMg==",
"avatar_url": "https://avatars.githubusercontent.com/u/510012?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/gfreezy",
"html_url": "https://github.com/gfreezy",
"followers_url": "https://api.github.com/users/gfreezy/followers",
"following_url": "https://api.github.com/users/gfreezy/following{/other_user}",
"gists_url": "https://api.github.com/users/gfreezy/gists{/gist_id}",
"starred_url": "https://api.github.com/users/gfreezy/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/gfreezy/subscriptions",
"organizations_url": "https://api.github.com/users/gfreezy/orgs",
"repos_url": "https://api.github.com/users/gfreezy/repos",
"events_url": "https://api.github.com/users/gfreezy/events{/privacy}",
"received_events_url": "https://api.github.com/users/gfreezy/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I've (finally) released 2.8.1. Thanks!\n"
] | 2016-05-04T13:39:42 | 2016-05-04T18:04:20 | 2016-05-04T18:04:20 | NONE | null | `PooledMySQL.ping()` is not working with the latest release. Please issue a new release.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/923/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/923/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/922 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/922/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/922/comments | https://api.github.com/repos/coleifer/peewee/issues/922/events | https://github.com/coleifer/peewee/issues/922 | 152,939,152 | MDU6SXNzdWUxNTI5MzkxNTI= | 922 | RetryOperationalError should raise peewee.OperationalError | {
"login": "yami",
"id": 77224,
"node_id": "MDQ6VXNlcjc3MjI0",
"avatar_url": "https://avatars.githubusercontent.com/u/77224?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/yami",
"html_url": "https://github.com/yami",
"followers_url": "https://api.github.com/users/yami/followers",
"following_url": "https://api.github.com/users/yami/following{/other_user}",
"gists_url": "https://api.github.com/users/yami/gists{/gist_id}",
"starred_url": "https://api.github.com/users/yami/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/yami/subscriptions",
"organizations_url": "https://api.github.com/users/yami/orgs",
"repos_url": "https://api.github.com/users/yami/repos",
"events_url": "https://api.github.com/users/yami/events{/privacy}",
"received_events_url": "https://api.github.com/users/yami/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"What will happen, if there are several statements in one transaction, and in the middle of execution, an operation error is raised?\n",
"> What will happen, if there are several statements in one transaction, and in the middle of execution, an operation error is raised?\n\nYou can read the code to find out!\n\nIts actually a bit complex so I'll try to explain. If you are not in a transaction, have autocommit enabled (on by default), and autorollback enabled (**off** by default), then the txn will be rolled back and the exception raised for your application to handle.\n\nWhen you enter a transaction, peewee tells the database to disable autocommit, so the automatic rollback will not happen in `execute_sql()`. If an unhandled exception does bubble up to the `transaction` object, though, it will rollback before raising the exception to your code.\n\nSo if you're using the `RetryOperationalError`mixin, the first `OperationalError` is caught before it bubbles up to the txn so nothing happens. If the retry fails, though, you will get a rollback and an exception.\n",
"should have commit or rollback before to raise exception?\n\n``` python\n def execute_sql(self, sql, params=None, require_commit=True):\n try:\n cursor = super(RetryOperationalError, self).execute_sql(\n sql, params, require_commit)\n except OperationalError:\n if not self.is_closed():\n self.close()\n with self.exception_wrapper():\n cursor = self.get_cursor()\n try:\n cursor.execute(sql, params or ())\n except Exception:\n if self.get_autocommit() and self.autorollback:\n self.rollback()\n raise\n else:\n if require_commit and self.get_autocommit():\n self.commit()\n return cursor\n```\n",
"@mathisonqin -- I'm sorry but I'm not following your comment. Do you mind clarifying?\n"
] | 2016-05-04T06:28:51 | 2016-07-20T16:49:36 | 2016-05-04T18:07:29 | NONE | null | With current RetryOperationalError implementation, for mysql, a second operation error will cause _mysql_exceptions.OperationalError being re-raised. I'd expect peewee.OperationalError in this case.
``` python
class RetryOperationalError(object):
def execute_sql(self, sql, params=None, require_commit=True):
try:
cursor = super(RetryOperationalError, self).execute_sql(
sql, params, require_commit)
except OperationalError:
if not self.is_closed():
self.close()
cursor = self.get_cursor()
cursor.execute(sql, params or ())
if require_commit and self.get_autocommit():
self.commit()
return cursor
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/922/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/922/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/921 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/921/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/921/comments | https://api.github.com/repos/coleifer/peewee/issues/921/events | https://github.com/coleifer/peewee/issues/921 | 151,903,260 | MDU6SXNzdWUxNTE5MDMyNjA= | 921 | Is there an API on ForeignKeyField to generate dynamically related_name | {
"login": "erwagasore",
"id": 1290048,
"node_id": "MDQ6VXNlcjEyOTAwNDg=",
"avatar_url": "https://avatars.githubusercontent.com/u/1290048?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/erwagasore",
"html_url": "https://github.com/erwagasore",
"followers_url": "https://api.github.com/users/erwagasore/followers",
"following_url": "https://api.github.com/users/erwagasore/following{/other_user}",
"gists_url": "https://api.github.com/users/erwagasore/gists{/gist_id}",
"starred_url": "https://api.github.com/users/erwagasore/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/erwagasore/subscriptions",
"organizations_url": "https://api.github.com/users/erwagasore/orgs",
"repos_url": "https://api.github.com/users/erwagasore/repos",
"events_url": "https://api.github.com/users/erwagasore/events{/privacy}",
"received_events_url": "https://api.github.com/users/erwagasore/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I would question the usefulness of dynamically generated backrefs, but whatever.\n\nPushed a commit 5f7078929b8731b74ab2bf0dede28d7bc103c8e1 that allows foreign key related_name init param to be a callable that accepts the field as it's only param.\n"
] | 2016-04-29T15:55:17 | 2016-04-29T16:47:31 | 2016-04-29T16:47:31 | NONE | null | I would like to create a base model with some dynamically generated foreignkeyfield `related_name`. I was hoping for a way to deal with it without touching the model constructor. Same thing you did with `db_table` by providing `db_table_func`
``` python
class AwareModel(Model):
created_by = ForeignKeyField(User, related_name_func = lambda model_cls: ...)
modified_by = ForeignKeyField(User, related_name_func = lambda model_cls: ...)
...
class Restaurant(AwareModel):
name = CharField()
...
# supposed there is a user called foo then I would be able to call the restaurants from the user
foo.created_restaurants # -> A list of restaurants foo created
foo.modified_restaurants # -> A list of restaurants foo modified
class Comment(AwareModel):
content = TextField()
...
# supposed there is a user called foo then I would be able to call the restaurants from the user
foo.created_comments # -> A list of comments foo created
foo.modified_comments # -> A list of comments foo modified
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/921/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/921/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/920 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/920/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/920/comments | https://api.github.com/repos/coleifer/peewee/issues/920/events | https://github.com/coleifer/peewee/issues/920 | 151,818,529 | MDU6SXNzdWUxNTE4MTg1Mjk= | 920 | Dynamically generate db_table name | {
"login": "erwagasore",
"id": 1290048,
"node_id": "MDQ6VXNlcjEyOTAwNDg=",
"avatar_url": "https://avatars.githubusercontent.com/u/1290048?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/erwagasore",
"html_url": "https://github.com/erwagasore",
"followers_url": "https://api.github.com/users/erwagasore/followers",
"following_url": "https://api.github.com/users/erwagasore/following{/other_user}",
"gists_url": "https://api.github.com/users/erwagasore/gists{/gist_id}",
"starred_url": "https://api.github.com/users/erwagasore/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/erwagasore/subscriptions",
"organizations_url": "https://api.github.com/users/erwagasore/orgs",
"repos_url": "https://api.github.com/users/erwagasore/repos",
"events_url": "https://api.github.com/users/erwagasore/events{/privacy}",
"received_events_url": "https://api.github.com/users/erwagasore/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"You could do something like this:\n\n``` python\nimport peewee as p\nfrom inflection import tableize\n\nclass BaseModelMeta(p.BaseModel):\n def __new__(cls, name, bases, attrs):\n cls = super(BaseModel, cls).__new__(cls, name, bases, attrs)\n\n # overwrite db_table name\n cls._meta.db_table = tableize(name)\n\n return cls\n\nclass BaseModel(p.with_metaclass(BaseModelMeta, p.Model), p.Model):\n # the second p.Model is optional, it gives me autocompletion in pyCharm\n pass\n```\n",
"There's an API for this:\n\n``` python\nclass MyModel(Model):\n class Meta:\n db_table_func = lambda model_cls: ...\n```\n",
"Listed a little below this section heading: http://docs.peewee-orm.com/en/latest/peewee/models.html#model-options-and-table-metadata\n",
"Here I was, thinking I knew the documentation by heart... Back to the school-books for me then!\n"
] | 2016-04-29T08:36:51 | 2016-04-29T13:46:49 | 2016-04-29T13:43:56 | NONE | null | I want to create an abstract base model which will generate db_table name dynamically.
Below is an illustration of what I need to accomplish.
``` python
from inflection import tableize
...
class User(Model):
pass
...
class BaseModel(Model):
class Meta:
abstract = True
# make db_table dynamically generated based on the class name
# db_table = tableize(cls.__name__) ------ 'RoomService' -> 'room_services'
...
class RoomService(BaseModel):
name = CharField()
foo = RoomService.create(name='Foo Bar')
# foo._meta.db_table ---> room_services
```
Is this a thing that can be done in Peewee? Thanks
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/920/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/920/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/919 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/919/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/919/comments | https://api.github.com/repos/coleifer/peewee/issues/919/events | https://github.com/coleifer/peewee/pull/919 | 151,670,670 | MDExOlB1bGxSZXF1ZXN0NjgyMzk1Mjk= | 919 | Add configuration check for sqlite | {
"login": "M157q",
"id": 1645228,
"node_id": "MDQ6VXNlcjE2NDUyMjg=",
"avatar_url": "https://avatars.githubusercontent.com/u/1645228?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/M157q",
"html_url": "https://github.com/M157q",
"followers_url": "https://api.github.com/users/M157q/followers",
"following_url": "https://api.github.com/users/M157q/following{/other_user}",
"gists_url": "https://api.github.com/users/M157q/gists{/gist_id}",
"starred_url": "https://api.github.com/users/M157q/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/M157q/subscriptions",
"organizations_url": "https://api.github.com/users/M157q/orgs",
"repos_url": "https://api.github.com/users/M157q/repos",
"events_url": "https://api.github.com/users/M157q/events{/privacy}",
"received_events_url": "https://api.github.com/users/M157q/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Thanks, good idea!\n"
] | 2016-04-28T15:21:15 | 2018-07-02T13:38:41 | 2016-04-28T15:36:53 | CONTRIBUTOR | null | Some operating systems don't have sqlite3 module within python3.
without this commit, they will get unclear error message like this:
```
File "/usr/local/lib/python3.4/site-packages/peewee.py", line 3371, in
connect
**self.connect_kwargs)
File "/usr/local/lib/python3.4/site-packages/peewee.py", line 3609, in
_connect
conn = sqlite3.connect(database, **kwargs)
AttributeError: 'NoneType' object has no attribute 'connect'
```
Those users who encounter this ImproperlyConfiguredError
may have to install sqlite dependencies and recompile their python3
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/919/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/919/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/919",
"html_url": "https://github.com/coleifer/peewee/pull/919",
"diff_url": "https://github.com/coleifer/peewee/pull/919.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/919.patch",
"merged_at": "2016-04-28T15:36:53"
} |
https://api.github.com/repos/coleifer/peewee/issues/918 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/918/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/918/comments | https://api.github.com/repos/coleifer/peewee/issues/918/events | https://github.com/coleifer/peewee/issues/918 | 151,231,279 | MDU6SXNzdWUxNTEyMzEyNzk= | 918 | Many to many relationship within itself | {
"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 | [
"and throw in an .aggregate_rows() at the end, though i'm not sure how it'd respond with so many joins.\n",
"@Thomaxo -- what you want is to probably use a combination of model aliases and explicit join predicates.\n\nFirst off, it might make better sense to query the \"B\" table (the junction table). For example:\n\n``` python\nA2 = A.alias()\nC2 = C.alias()\nquery = (B\n .select(B, A, A2, C, C2)\n .join(A, on=(B.original_A == A.id))\n .join(C, on=(A.c == C.id))\n .switch(B)\n .join(A2, on=(B.related_A == A2.id).alias('related_A'))\n .join(C2, on=(A2.c == C2.id).alias('c')))\n\nfor b in query:\n print b.original_A, b.original_A.c\n print b.related_A, b.related_A.c\n```\n",
"If you believe you've found an issue with Peewee, please open an issue. Otherwise, if you're still stuck, I'd suggest the mailing list or stackoverflow.\n",
"Thanks for the help! :)\n"
] | 2016-04-26T20:28:29 | 2016-04-28T20:24:04 | 2016-04-28T15:19:07 | NONE | null | Not sure if this is an issue rather than a question, but here it goes..
Given a model A, and a model B (a many to many table)
``` python
class B(Model):
original_A = ForeignKeyField(
A,
related_name='AB'
)
related_A = ForeignKeyField(
A,
related_name='BA'
)
class Meta:
database = db
```
The 2 foreign keys, as you can see, relate to the same model.
The tricky part gets when you try to query it,
The query is: (C is something relating to A)
``` python
query = models.A.select(
A,
B,
C
).join(
models.C
).switch( ##
models.A
).join(
models.B
).join(
models.A
).join(
models.C
)
```
So, how can i get rid of the ambiguity and say that the first join of A with model B neets to relate to the first column of B, and the second join of B with A needs to relate to the second column of B?
In the end what i want to get is:
``` python
for a in query:
#do something with a
for c in a:
#do something with its related c
for b in a:
for ba in b:
#do something with its relations with itself
for c in ba:
#do something with its related c of its related self..
```
kind regards,
Thomas
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/918/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/918/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/917 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/917/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/917/comments | https://api.github.com/repos/coleifer/peewee/issues/917/events | https://github.com/coleifer/peewee/issues/917 | 150,924,527 | MDU6SXNzdWUxNTA5MjQ1Mjc= | 917 | get_or_create with 'self' ForeignKeyField : fails due to ambiguous column name | {
"login": "1bpm",
"id": 6190541,
"node_id": "MDQ6VXNlcjYxOTA1NDE=",
"avatar_url": "https://avatars.githubusercontent.com/u/6190541?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/1bpm",
"html_url": "https://github.com/1bpm",
"followers_url": "https://api.github.com/users/1bpm/followers",
"following_url": "https://api.github.com/users/1bpm/following{/other_user}",
"gists_url": "https://api.github.com/users/1bpm/gists{/gist_id}",
"starred_url": "https://api.github.com/users/1bpm/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/1bpm/subscriptions",
"organizations_url": "https://api.github.com/users/1bpm/orgs",
"repos_url": "https://api.github.com/users/1bpm/repos",
"events_url": "https://api.github.com/users/1bpm/events{/privacy}",
"received_events_url": "https://api.github.com/users/1bpm/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"This is working in master:\n\n``` python\n>>> parent, new = TM.get_or_create(data='parent')\n('SELECT \"t1\".\"id\", \"t1\".\"data\", \"t1\".\"parent_id\" FROM \"tm\" AS t1 WHERE (\"t1\".\"data\" = ?) LIMIT 1 OFFSET 0', [u'parent'])\n('BEGIN DEFERRED', None)\n('INSERT INTO \"tm\" (\"data\") VALUES (?)', [u'parent'])\n\n>>> child, new = TM.get_or_create(data='child', parent=parent)\n('SELECT \"t1\".\"id\", \"t1\".\"data\", \"t1\".\"parent_id\" FROM \"tm\" AS t1 WHERE ((\"t1\".\"data\" = ?) AND (\"t1\".\"parent_id\" = ?)) LIMIT 1 OFFSET 0', [u'child', 4])\n('BEGIN DEFERRED', None)\n('INSERT INTO \"tm\" (\"data\", \"parent_id\") VALUES (?, ?)', [u'child', 4])\n\n>>> print child.data, child.parent.data, new\nchild parent True\n\n>>> print TM.get_or_create(data='child', parent=parent)\n('SELECT \"t1\".\"id\", \"t1\".\"data\", \"t1\".\"parent_id\" FROM \"tm\" AS t1 WHERE ((\"t1\".\"data\" = ?) AND (\"t1\".\"parent_id\" = ?)) LIMIT 1 OFFSET 0', [u'child', 4])\n\n(<__main__.TM at 0x7f6bdaa95710>, False)\n```\n\nLooks like I may need to push a new release! I've been meaning to for some time so apologies for that. If you'd like to checkout the master branch and give your code a try, I believe you'll find that it works.\n",
"Ah, yes it does. Thank you!\n"
] | 2016-04-25T16:55:31 | 2016-04-26T09:28:26 | 2016-04-26T09:28:26 | NONE | null | When using a ForeignKeyField referring to 'self', get_or_create fails with 'ambiguous column name', as it produces a statement with two "t1" aliases.
Peewee 2.8.0 using Postgresql, tested with Sqlite and example here using Sqlite.
``` python
from peewee import *
db = SqliteDatabase("sqlite.db")
class TestModel(Model):
somefield = TextField()
parent = ForeignKeyField("self", null = True)
class Meta:
database = db
db.create_tables([TestModel], safe = True)
```
Initial record creation ok:
``` python
parent, new = TestModel.get_or_create(somefield = "parent")
```
`('SELECT "t1"."id", "t1"."somefield", "t1"."parent_id" FROM "testmodel" AS t1 WHERE ("t1"."somefield" = ?) LIMIT 1', [u'parent'])
`
Dependent record creation fails:
``` python
child, new = TestModel.get_or_create(somefield = "child", parent = parent)
```
`('SELECT "t1"."id", "t1"."somefield", "t1"."parent_id" FROM "testmodel" AS t1 INNER JOIN "testmodel" AS t1 ON ("t1"."parent_id" = "t1"."id") WHERE (("t1"."parent_id" = ?) AND ("t1"."somefield" = ?)) LIMIT 1', [1, u'child'])`
OperationalError: ambiguous column name: t1.id
Trace:
``` python
/usr/local/lib/python2.7/dist-packages/peewee.pyc in get_or_create(cls, **kwargs)
4510 sq = cls.select().filter(**kwargs)
4511 try:
-> 4512 return sq.get(), False
4513 except cls.DoesNotExist:
4514 try:
/usr/local/lib/python2.7/dist-packages/peewee.pyc in get(self)
2883 clone = self.paginate(1, 1)
2884 try:
-> 2885 return next(clone.execute())
2886 except StopIteration:
2887 raise self.model_class.DoesNotExist(
/usr/local/lib/python2.7/dist-packages/peewee.pyc in execute(self)
2930 query_meta = self.get_query_meta()
2931 ResultWrapper = self._get_result_wrapper()
-> 2932 self._qr = ResultWrapper(model_class, self._execute(), query_meta)
2933 self._dirty = False
2934 return self._qr
/usr/local/lib/python2.7/dist-packages/peewee.pyc in _execute(self)
2626 def _execute(self):
2627 sql, params = self.sql()
-> 2628 return self.database.execute_sql(sql, params, self.require_commit)
2629
2630 def execute(self):
/usr/local/lib/python2.7/dist-packages/peewee.pyc in execute_sql(self, sql, params, require_commit)
3459 else:
3460 if require_commit and self.get_autocommit():
-> 3461 self.commit()
3462 return cursor
3463
/usr/local/lib/python2.7/dist-packages/peewee.pyc in __exit__(self, exc_type, exc_value, traceback)
3283 else:
3284 exc_args = exc_value.args
-> 3285 reraise(new_type, new_type(*exc_args), traceback)
3286
3287 class _BaseConnectionLocal(object):
/usr/local/lib/python2.7/dist-packages/peewee.pyc in execute_sql(self, sql, params, require_commit)
3452 cursor = self.get_cursor()
3453 try:
-> 3454 cursor.execute(sql, params or ())
3455 except Exception:
3456 if self.get_autocommit() and self.autorollback:
```
Separating the get/create just to check doing it 'manually' works:
``` python
parent, new = TestModel.get_or_create(somefield = "parent")
test = TestModel.select().where((TestModel.somefield == "child") & (TestModel.parent == parent))
child = test[0] if test.exists() else TestModel.create(somefield = "child", parent = parent)
```
`('SELECT 1 FROM "testmodel" AS t1 WHERE (("t1"."somefield" = ?) AND ("t1"."parent_id" = ?)) LIMIT 1', [u'child', 1])
('INSERT INTO "testmodel" ("somefield", "parent_id") VALUES (?, ?)', [u'child', 1])
`
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/917/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/917/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/916 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/916/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/916/comments | https://api.github.com/repos/coleifer/peewee/issues/916/events | https://github.com/coleifer/peewee/issues/916 | 149,990,765 | MDU6SXNzdWUxNDk5OTA3NjU= | 916 | Using date_part on an aliased field generates new alias | {
"login": "CorverDevelopment",
"id": 15232654,
"node_id": "MDEyOk9yZ2FuaXphdGlvbjE1MjMyNjU0",
"avatar_url": "https://avatars.githubusercontent.com/u/15232654?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/CorverDevelopment",
"html_url": "https://github.com/CorverDevelopment",
"followers_url": "https://api.github.com/users/CorverDevelopment/followers",
"following_url": "https://api.github.com/users/CorverDevelopment/following{/other_user}",
"gists_url": "https://api.github.com/users/CorverDevelopment/gists{/gist_id}",
"starred_url": "https://api.github.com/users/CorverDevelopment/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/CorverDevelopment/subscriptions",
"organizations_url": "https://api.github.com/users/CorverDevelopment/orgs",
"repos_url": "https://api.github.com/users/CorverDevelopment/repos",
"events_url": "https://api.github.com/users/CorverDevelopment/events{/privacy}",
"received_events_url": "https://api.github.com/users/CorverDevelopment/received_events",
"type": "Organization",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I'm confused...what's different in the 2nd and 3rd queries? I can see that in the first it uses t3 for the alias, but don't understand why it uses t4 in the last query.\n",
"Oops, I see: it's using Person in the second example query. I swear I looked at them for a minute and didn't see that. Ok, makes sense.\n",
"d7720d95335d607add81f2d2dbc5e8fc5424b1fd\r\n\r\nThis is a stab at an implementation. What do you think?",
"I just tested the example and tested it in my project and I can now remove a lot of work-arounds! Keep up the awesome work!",
"This is fixed in 3.0a, commit: f81a30b621bebef103950a2667aed6df2bf69ddd"
] | 2016-04-21T07:28:39 | 2017-07-07T04:12:58 | 2017-07-07T04:12:58 | NONE | null | When using the `date_part` functionality (and others, e.g. `contains_any` in ArrayField), the field is passed as `self`. This works beautifully if you are using the model it is defined in, but, when using it on an aliased table, it generates a new alias.
Below is a very crude example from how I found this "problem". This first query shows that the part of the query that will be constructed works when called with the aliased field: `fn.DATE_PART('year', Client.birth) > 1980)`.
Calling `Client.birth.year` is what is generating the problem here, as it will refer to the `Person` model instead of the `Client` alias, generating the fourth alias. Would I not alias `Owner`, but use the `Person` model, it would construct the where part based on that alias, instead of the `Client`.
```
from peewee import *
import logging
database = SqliteDatabase(':memory:')
logger = logging.getLogger('peewee')
logger.setLevel(logging.DEBUG)
logger.addHandler(logging.StreamHandler())
class Base(Model):
class Meta:
database = database
class Person(Base):
name = CharField()
birth = DateField()
class Traject(Base):
owner = ForeignKeyField(Person, related_name='trajects_owned')
client = ForeignKeyField(Person, related_name='trajects')
Person.create_table()
Traject.create_table()
john = Person.create(name='John', birth='1979-1-1')
suzi = Person.create(name='Suzi', birth='1982-1-1')
louise = Person.create(name='Louise', birth='1970-1-1')
cody = Person.create(name='Cody', birth='1990-1-1')
Traject.create(owner=john, client=suzi)
Traject.create(owner=john, client=louise)
Traject.create(owner=john, client=cody)
Client = Person.alias()
Owner = Person.alias()
trajects = (Traject.select()
.join(Client, on=(Traject.client == Client.id))
.join(Owner, on=(Traject.owner == Owner.id))
.where(fn.DATE_PART('year', Client.birth) > 1980))
assert trajects.count() == 2
# good so far
trajects = (Traject.select()
.join(Client, on=(Traject.client == Client.id))
.join(Person, on=(Traject.owner == Person.id))
.where(Client.birth.year > 1980))
assert trajects.count() == 0
# this should be two, but the where is based on the owner
trajects = (Traject.select()
.join(Client, on=(Traject.client == Client.id))
.join(Owner, on=(Traject.owner == Owner.id))
.where(Client.birth.year > 1980))
assert trajects.count() == 2
# this will generate an exception
```
Here are the two generated queries by _peewee_.
```
SELECT Count(*)
FROM "traject" AS t1
INNER JOIN "person" AS t2 ON ("t1"."client_id" = "t2"."id")
INNER JOIN "person" AS t3 ON ("t1"."owner_id" = "t3"."id")
WHERE (DATE_PART(?, "t2"."birth") > ?)
-- parameters: ['year', 1980]
SELECT Count(*)
FROM "traject" AS t1
INNER JOIN "person" AS t2 ON ("t1"."client_id" = "t2"."id")
INNER JOIN "person" AS t3 ON ("t1"."owner_id" = "t3"."id")
WHERE (date_part(?, "t3"."birth") > ?)
-- parameters: ['year', 1980]
SELECT Count(*) FROM "traject" AS t1
INNER JOIN "person" AS t2 ON ("t1"."client_id" = "t2"."id")
INNER JOIN "person" AS t3 ON ("t1"."owner_id" = "t3"."id")
WHERE (date_part(?, "t4"."birth") > ?)
-- parameters: ['year', 1980])
```
The exception that was caused by the third query:
```
Traceback (most recent call last):
File "app.py", line 61, in <module>
assert trajects.count() == 2
File "$/site-packages/peewee.py", line 2865, in count
return self.aggregate(convert=False) or 0
File "$/site-packages/peewee.py", line 2858, in aggregate
return self._aggregate(aggregation).scalar(convert=convert)
File "$/site-packages/peewee.py", line 2637, in scalar
row = self._execute().fetchone()
File "$/site-packages/peewee.py", line 2628, in _execute
return self.database.execute_sql(sql, params, self.require_commit)
File "$/site-packages/peewee.py", line 3461, in execute_sql
self.commit()
File "$/site-packages/peewee.py", line 3285, in __exit__
reraise(new_type, new_type(*exc_args), traceback)
File "$/site-packages/peewee.py", line 3454, in execute_sql
cursor.execute(sql, params or ())
peewee.OperationalError: no such column: t4.birth
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/916/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/916/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/915 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/915/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/915/comments | https://api.github.com/repos/coleifer/peewee/issues/915/events | https://github.com/coleifer/peewee/pull/915 | 149,690,300 | MDExOlB1bGxSZXF1ZXN0NjcxNDMwMjQ= | 915 | doc_fix | {
"login": "piperck",
"id": 8776176,
"node_id": "MDQ6VXNlcjg3NzYxNzY=",
"avatar_url": "https://avatars.githubusercontent.com/u/8776176?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/piperck",
"html_url": "https://github.com/piperck",
"followers_url": "https://api.github.com/users/piperck/followers",
"following_url": "https://api.github.com/users/piperck/following{/other_user}",
"gists_url": "https://api.github.com/users/piperck/gists{/gist_id}",
"starred_url": "https://api.github.com/users/piperck/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/piperck/subscriptions",
"organizations_url": "https://api.github.com/users/piperck/orgs",
"repos_url": "https://api.github.com/users/piperck/repos",
"events_url": "https://api.github.com/users/piperck/events{/privacy}",
"received_events_url": "https://api.github.com/users/piperck/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2016-04-20T07:57:12 | 2016-04-20T15:29:40 | 2016-04-20T15:29:40 | CONTRIBUTOR | null | doc_fix
Pass by to repair
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/915/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/915/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/915",
"html_url": "https://github.com/coleifer/peewee/pull/915",
"diff_url": "https://github.com/coleifer/peewee/pull/915.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/915.patch",
"merged_at": "2016-04-20T15:29:40"
} |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.