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/814
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/814/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/814/comments
https://api.github.com/repos/coleifer/peewee/issues/814/events
https://github.com/coleifer/peewee/issues/814
126,332,337
MDU6SXNzdWUxMjYzMzIzMzc=
814
PooledMySQLDatabase has cache or buffer?.md
{ "login": "tradaniel", "id": 10319846, "node_id": "MDQ6VXNlcjEwMzE5ODQ2", "avatar_url": "https://avatars.githubusercontent.com/u/10319846?v=4", "gravatar_id": "", "url": "https://api.github.com/users/tradaniel", "html_url": "https://github.com/tradaniel", "followers_url": "https://api.github.com/users/tradaniel/followers", "following_url": "https://api.github.com/users/tradaniel/following{/other_user}", "gists_url": "https://api.github.com/users/tradaniel/gists{/gist_id}", "starred_url": "https://api.github.com/users/tradaniel/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/tradaniel/subscriptions", "organizations_url": "https://api.github.com/users/tradaniel/orgs", "repos_url": "https://api.github.com/users/tradaniel/repos", "events_url": "https://api.github.com/users/tradaniel/events{/privacy}", "received_events_url": "https://api.github.com/users/tradaniel/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "You don't need a pool for multi-threaded, for what it's worth. Peewee correctly handles connections and will open a connection per thread.\n\nThe issue is related to #727 and #806 . I've reverted the change in #727 so this should resolve itself. In the meantime, make sure you are using transactions! Wrap your code in `database.atomic()` blocks where you are making changes. That should help until I create a new release that has the `commit_select` change.\n", "See 6087199320a3ad8968add5d50f6c3a047767afdd\n" ]
2016-01-13T03:23:31
2016-01-13T16:29:27
2016-01-13T16:29:18
NONE
null
i create a mysql pool like this: ``` database = PooledMySQLDatabase('test', max_connections=10, **{'host': 'localhost', 'port': 3306, 'user': 'root', 'password': ''}) class BaseModel(Model): class Meta: database = database class Tb1(BaseModel): point_id = PrimaryKeyField() class Meta: db_table = 'tb1' ``` however, where i insert a record or delete a record in database manully, in my program, select result is not change. ``` while True: database.connect() tb_list = Tb1.select() print(len(tb_list)) database.close() import time time.sleep(2) ``` when i repalce PooledMySQLDatabase to MySQLDatabase the result is normal. In my project, I want to use multithread, so I need to create a mysql pool. thanks a lot
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/814/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/814/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/813
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/813/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/813/comments
https://api.github.com/repos/coleifer/peewee/issues/813/events
https://github.com/coleifer/peewee/pull/813
125,972,752
MDExOlB1bGxSZXF1ZXN0NTU2MzgyNTU=
813
Docs update for #790
{ "login": "foxx", "id": 651797, "node_id": "MDQ6VXNlcjY1MTc5Nw==", "avatar_url": "https://avatars.githubusercontent.com/u/651797?v=4", "gravatar_id": "", "url": "https://api.github.com/users/foxx", "html_url": "https://github.com/foxx", "followers_url": "https://api.github.com/users/foxx/followers", "following_url": "https://api.github.com/users/foxx/following{/other_user}", "gists_url": "https://api.github.com/users/foxx/gists{/gist_id}", "starred_url": "https://api.github.com/users/foxx/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/foxx/subscriptions", "organizations_url": "https://api.github.com/users/foxx/orgs", "repos_url": "https://api.github.com/users/foxx/repos", "events_url": "https://api.github.com/users/foxx/events{/privacy}", "received_events_url": "https://api.github.com/users/foxx/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Oh, good deal\n", "@coleifer Was this meant to be closed without merging? Does it need improvement?\n", "Whoops!\n" ]
2016-01-11T15:47:46
2016-01-14T16:32:29
2016-01-11T16:42:05
CONTRIBUTOR
null
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/813/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/813/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/813", "html_url": "https://github.com/coleifer/peewee/pull/813", "diff_url": "https://github.com/coleifer/peewee/pull/813.diff", "patch_url": "https://github.com/coleifer/peewee/pull/813.patch", "merged_at": "2016-01-11T16:42:05" }
https://api.github.com/repos/coleifer/peewee/issues/812
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/812/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/812/comments
https://api.github.com/repos/coleifer/peewee/issues/812/events
https://github.com/coleifer/peewee/issues/812
125,970,390
MDU6SXNzdWUxMjU5NzAzOTA=
812
Transaction decorator not working with Tornado and Python 3.5's "async"
{ "login": "csytan", "id": 16357, "node_id": "MDQ6VXNlcjE2MzU3", "avatar_url": "https://avatars.githubusercontent.com/u/16357?v=4", "gravatar_id": "", "url": "https://api.github.com/users/csytan", "html_url": "https://github.com/csytan", "followers_url": "https://api.github.com/users/csytan/followers", "following_url": "https://api.github.com/users/csytan/following{/other_user}", "gists_url": "https://api.github.com/users/csytan/gists{/gist_id}", "starred_url": "https://api.github.com/users/csytan/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/csytan/subscriptions", "organizations_url": "https://api.github.com/users/csytan/orgs", "repos_url": "https://api.github.com/users/csytan/repos", "events_url": "https://api.github.com/users/csytan/events{/privacy}", "received_events_url": "https://api.github.com/users/csytan/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "This doesn't seem like a peewee issue to me, as peewee doesn't know about your event loop and is designed using normal python APIs. I am not familiar with tornado/twisted so I can't really offer much more in the way of advice for debugging this.\n", "Understood. Thanks for having a look!\n" ]
2016-01-11T15:36:07
2016-01-11T17:09:28
2016-01-11T16:44:10
NONE
null
The transaction decorator doesn't rollback correctly when used with an async function in Tornado. ``` @database.transaction() async def test_txn(): Test.create() raise Exception() ``` Results of test code: ``` $ py peeweetest.py <function test_asyncio at 0x10e033ea0> Success <function test_tornado at 0x10e24b2f0> Failed ``` Here's some test code, using Python 3.5, Peewee, and Tornado: ``` import asyncio import peewee import tornado.ioloop # Database setup database = peewee.SqliteDatabase('testdb') database.connect() class Model(peewee.Model): class Meta: database = database database.create_tables([Model], safe=True) @database.transaction() async def test_txn(): Model.create() raise Exception() def test_asyncio(): # Start event loop, then block until test completes return (asyncio.get_event_loop() .run_until_complete(test_txn)) def test_tornado(): # Start event loop, then block until test completes return (tornado.ioloop.IOLoop.instance() .run_sync(test_txn)) # Run tests for test in (test_asyncio, test_tornado): print(test) count_before = Model.select().count() try: test() except Exception: pass count_after = Model.select().count() # Compare Model counts, they should be the same before and after if count_before == count_after: print('Success') else: print('Failed') print() ``` Manual transactions seem to work fine. I suspect this may have something to do with Tornado's generator based co-routine support where you raise an Exception to return a value. I'm really not sure though.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/812/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/812/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/811
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/811/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/811/comments
https://api.github.com/repos/coleifer/peewee/issues/811/events
https://github.com/coleifer/peewee/issues/811
125,842,162
MDU6SXNzdWUxMjU4NDIxNjI=
811
MySQL not included in Travis CI
{ "login": "foxx", "id": 651797, "node_id": "MDQ6VXNlcjY1MTc5Nw==", "avatar_url": "https://avatars.githubusercontent.com/u/651797?v=4", "gravatar_id": "", "url": "https://api.github.com/users/foxx", "html_url": "https://github.com/foxx", "followers_url": "https://api.github.com/users/foxx/followers", "following_url": "https://api.github.com/users/foxx/following{/other_user}", "gists_url": "https://api.github.com/users/foxx/gists{/gist_id}", "starred_url": "https://api.github.com/users/foxx/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/foxx/subscriptions", "organizations_url": "https://api.github.com/users/foxx/orgs", "repos_url": "https://api.github.com/users/foxx/repos", "events_url": "https://api.github.com/users/foxx/events{/privacy}", "received_events_url": "https://api.github.com/users/foxx/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Added this. MySQL has always been a 2nd-class citizen since I don't use it and don't typically even have it installed. I've added it, however, so let's hope things work!\n", "Well, lots of issues... reopening to fix.\n", "Admittedly MySQL is a flawed technology in comparison with Postgres, but fwiw MariaDB is a fantastic improvement and also backwards compatible with Oracle/Percona MySQL, right down to the binlogs. \n\nFigured there would probably be a lot of failed tests. I can contribute a couple of hours next week to help get this working if needed (if so, just let me know where you'd like me to focus efforts)\n", "These appear to be the two errors:\n\n```\n======================================================================\nERROR: test_add_not_null (playhouse.tests.test_migrate.MySQLMigrationTestCase)\n----------------------------------------------------------------------\nTraceback (most recent call last):\n File \"/home/travis/build/coleifer/peewee/playhouse/tests/test_migrate.py\", line 278, in test_add_not_null\n dob=None)\n File \"/opt/python/2.7.9/lib/python2.7/unittest/case.py\", line 473, in assertRaises\n callableObj(*args, **kwargs)\n File \"/home/travis/build/coleifer/peewee/peewee.py\", line 4493, in create\n inst.save(force_insert=True)\n File \"/home/travis/build/coleifer/peewee/peewee.py\", line 4679, in save\n pk_from_cursor = self.insert(**field_dict).execute()\n File \"/home/travis/build/coleifer/peewee/peewee.py\", line 3213, in execute\n cursor = self._execute()\n File \"/home/travis/build/coleifer/peewee/peewee.py\", line 2628, in _execute\n return self.database.execute_sql(sql, params, self.require_commit)\n File \"/home/travis/build/coleifer/peewee/peewee.py\", line 3461, in execute_sql\n self.commit()\n File \"/home/travis/build/coleifer/peewee/peewee.py\", line 3285, in __exit__\n reraise(new_type, new_type(*exc_args), traceback)\n File \"/home/travis/build/coleifer/peewee/peewee.py\", line 3454, in execute_sql\n cursor.execute(sql, params or ())\n File \"/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/pymysql/cursors.py\", line 146, in execute\n result = self._query(query)\n File \"/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/pymysql/cursors.py\", line 296, in _query\n conn.query(q)\n File \"/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/pymysql/connections.py\", line 819, in query\n self._affected_rows = self._read_query_result(unbuffered=unbuffered)\n File \"/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/pymysql/connections.py\", line 1001, in _read_query_result\n result.read()\n File \"/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/pymysql/connections.py\", line 1286, in read\n first_packet = self.connection._read_packet()\n File \"/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/pymysql/connections.py\", line 965, in _read_packet\n packet.check_error()\n File \"/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/pymysql/connections.py\", line 394, in check_error\n err.raise_mysql_exception(self._data)\n File \"/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/pymysql/err.py\", line 120, in raise_mysql_exception\n _check_mysql_exception(errinfo)\n File \"/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/pymysql/err.py\", line 112, in _check_mysql_exception\n raise errorclass(errno, errorvalue)\nIntegrityError: (1048, u\"Column 'dob' cannot be null\")\n======================================================================\nERROR: test_modify_not_null_foreign_key (playhouse.tests.test_migrate.MySQLMigrationTestCase)\n----------------------------------------------------------------------\nTraceback (most recent call last):\n File \"/home/travis/build/coleifer/peewee/playhouse/tests/test_migrate.py\", line 315, in test_modify_not_null_foreign_key\n user=None)\n File \"/opt/python/2.7.9/lib/python2.7/unittest/case.py\", line 473, in assertRaises\n callableObj(*args, **kwargs)\n File \"/home/travis/build/coleifer/peewee/peewee.py\", line 4493, in create\n inst.save(force_insert=True)\n File \"/home/travis/build/coleifer/peewee/peewee.py\", line 4679, in save\n pk_from_cursor = self.insert(**field_dict).execute()\n File \"/home/travis/build/coleifer/peewee/peewee.py\", line 3213, in execute\n cursor = self._execute()\n File \"/home/travis/build/coleifer/peewee/peewee.py\", line 2628, in _execute\n return self.database.execute_sql(sql, params, self.require_commit)\n File \"/home/travis/build/coleifer/peewee/peewee.py\", line 3461, in execute_sql\n self.commit()\n File \"/home/travis/build/coleifer/peewee/peewee.py\", line 3285, in __exit__\n reraise(new_type, new_type(*exc_args), traceback)\n File \"/home/travis/build/coleifer/peewee/peewee.py\", line 3454, in execute_sql\n cursor.execute(sql, params or ())\n File \"/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/pymysql/cursors.py\", line 146, in execute\n result = self._query(query)\n File \"/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/pymysql/cursors.py\", line 296, in _query\n conn.query(q)\n File \"/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/pymysql/connections.py\", line 819, in query\n self._affected_rows = self._read_query_result(unbuffered=unbuffered)\n File \"/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/pymysql/connections.py\", line 1001, in _read_query_result\n result.read()\n File \"/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/pymysql/connections.py\", line 1286, in read\n first_packet = self.connection._read_packet()\n File \"/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/pymysql/connections.py\", line 965, in _read_packet\n packet.check_error()\n File \"/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/pymysql/connections.py\", line 394, in check_error\n err.raise_mysql_exception(self._data)\n File \"/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/pymysql/err.py\", line 120, in raise_mysql_exception\n _check_mysql_exception(errinfo)\n File \"/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/pymysql/err.py\", line 112, in _check_mysql_exception\n raise errorclass(errno, errorvalue)\nIntegrityError: (1048, u\"Column 'user_id' cannot be null\")\n----------------------------------------------------------------------\n```\n", "I'm not quite sure what's going on, those tests are passing locally for me.\n", "Only had a few minutes spare to look at this, I think the problem might be because `pymysql` is raising it's own class of `IntegrityError` seen [here](https://github.com/PyMySQL/PyMySQL/blob/master/pymysql/err.py#L44).\n\nAlso note that your `assertRaises` is looking for `_exception_not_null_violation = OperationalError`, where as MySQL is raising `IntegrityError`.\n\nSo either;\n\nA) assertRaises needs to look for `peewee.OperationalError`\nB) assertRaises needs to look for `pymysql.OperationalError`\nC) There is something wrong with `migrate.add_not_null`\n\nAs for why it's working locally, it could be due to differences in MySQL version (e.g. behaviour changes between 5.0 ~ 5.5), although 5.0 doesn't really need to be supported imho (it's as old as Python 2.6 iirc)\n", "Alright, I believe this one is now fixed. Thanks for keeping me honest @foxx!\n", "Awesome! I'm curious, what was the problem with this in the end?\n\nPS) Lol @ dropping 3.2/3.3, that's what I had to do as well, it's not widely used so should be fine.\n", "Ummmm, let's see. pymysql wasn't compat with 3.2/3.3. Then you were\ncorrect, I just needed to catch both integrity/operational errors for mysql\nfor whatever reason.\n\nOn Thu, Jan 14, 2016 at 3:59 AM, Cal Leeming [email protected]\nwrote:\n\n> Awesome! I'm curious, what was the problem with this in the end?\n> \n> PS) Lol @ dropping 3.2/3.3, that's what I had to do as well, it's not\n> widely used so should be fine.\n> \n> —\n> Reply to this email directly or view it on GitHub\n> https://github.com/coleifer/peewee/issues/811#issuecomment-171592148.\n", "Doh sorry, I just realised you pushed the code to master, I would have checked the commit history myself if I had realised lol, my bad.\n" ]
2016-01-10T20:06:30
2016-01-14T12:27:29
2016-01-14T05:02:49
CONTRIBUTOR
null
Just looking over [`.travis.yml`](https://github.com/coleifer/peewee/blob/master/.travis.yml), and it appears that MySQL is not included in the backend tests. Any particular reason for this, or would a PR fix be accepted?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/811/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/811/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/810
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/810/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/810/comments
https://api.github.com/repos/coleifer/peewee/issues/810/events
https://github.com/coleifer/peewee/issues/810
125,489,186
MDU6SXNzdWUxMjU0ODkxODY=
810
add DictField
{ "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
[ "You can use the `PickledField`, added just now:\n\nhttps://github.com/coleifer/peewee/blob/master/playhouse/fields.py#L293-L302\n\nIf you're using a new-ish version of Postgres you can use the JSON field or the HStore field.\n\nIf you're using a new-ish version of SQLite with the JSON1 extension compiled in or loadable, you can use the JSONField from the SQLite extension module.\n" ]
2016-01-07T21:34:23
2016-01-07T22:46:43
2016-01-07T22:46:43
NONE
null
Hello! Is it possible to implement DictField (basing for example TextField)? I need to store unstructed data in model and I think such feature would be useful.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/810/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/810/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/809
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/809/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/809/comments
https://api.github.com/repos/coleifer/peewee/issues/809/events
https://github.com/coleifer/peewee/issues/809
125,170,366
MDU6SXNzdWUxMjUxNzAzNjY=
809
Model object constructor using kwargs puts FKs in weird state on local instance
{ "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
[ "Yes, its because null=False. That is normal behavior. It happens whether or not you initialize the fk with None, if there is no value. The null False tells us that a missing value is an error.\n" ]
2016-01-06T12:44:52
2016-01-06T18:11:17
2016-01-06T18:11:17
CONTRIBUTOR
null
Hey! Found an interesting one, and I'm curious if it's intended behavior or a bug. When I create a model object using a dictionary exploded into `kwargs`, if that dictionary has a None for the value of a FK field, I get a `(ModelClass).DoesNotExist` error on the local instance of the model when trying to access that field, as opposed to just receiving `None`. Example: ``` class User(Model): name = CharField() email = CharField() class Tweet(Model): user = ForeignKeyField(User, null=False) contents = TextField() t = Tweet(**{"user": None, "contents": "Some contents"}) print t.user # (raises User.DoesNotExist, expected to print None) ``` As I'm writing this, I'm curious if the `null=False` on the `ForeignKeyField` might have something to do with it, but I imagine the accessor pattern for a ForeignKeyField doesn't change based on that; only the database behavior would be different based on that flag. Any thoughts on the validity of this as a bug or workarounds I should consider if this is expected behavior? I'm just `try`/`except`ing in these cases and it's good enough for now, but it feels Java-y.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/809/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/809/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/808
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/808/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/808/comments
https://api.github.com/repos/coleifer/peewee/issues/808/events
https://github.com/coleifer/peewee/issues/808
125,149,936
MDU6SXNzdWUxMjUxNDk5MzY=
808
IndexError: list index out of range
{ "login": "gjedeer", "id": 315648, "node_id": "MDQ6VXNlcjMxNTY0OA==", "avatar_url": "https://avatars.githubusercontent.com/u/315648?v=4", "gravatar_id": "", "url": "https://api.github.com/users/gjedeer", "html_url": "https://github.com/gjedeer", "followers_url": "https://api.github.com/users/gjedeer/followers", "following_url": "https://api.github.com/users/gjedeer/following{/other_user}", "gists_url": "https://api.github.com/users/gjedeer/gists{/gist_id}", "starred_url": "https://api.github.com/users/gjedeer/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/gjedeer/subscriptions", "organizations_url": "https://api.github.com/users/gjedeer/orgs", "repos_url": "https://api.github.com/users/gjedeer/repos", "events_url": "https://api.github.com/users/gjedeer/events{/privacy}", "received_events_url": "https://api.github.com/users/gjedeer/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "There is no object matching your query. Use .get() instead if you only need 1 object.\n" ]
2016-01-06T10:28:07
2016-01-06T18:08:07
2016-01-06T18:08:07
NONE
null
I have a problem that I can't figure out. Npm is a peewee model which I'm using like this: ``` package = Npm.select().where(Npm.id==package_name)[0] ``` However peewee throws an exception which is not very meaningful: ![peewee](https://cloud.githubusercontent.com/assets/315648/12140463/7b0206a0-b468-11e5-986c-2c821ab43b59.png) Any idea what I'm doing wrong or how this can be fixed in peewee code ?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/808/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/808/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/807
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/807/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/807/comments
https://api.github.com/repos/coleifer/peewee/issues/807/events
https://github.com/coleifer/peewee/issues/807
125,104,906
MDU6SXNzdWUxMjUxMDQ5MDY=
807
Adding table to existing db does not add unique constrant.
{ "login": "vincentdavis", "id": 232564, "node_id": "MDQ6VXNlcjIzMjU2NA==", "avatar_url": "https://avatars.githubusercontent.com/u/232564?v=4", "gravatar_id": "", "url": "https://api.github.com/users/vincentdavis", "html_url": "https://github.com/vincentdavis", "followers_url": "https://api.github.com/users/vincentdavis/followers", "following_url": "https://api.github.com/users/vincentdavis/following{/other_user}", "gists_url": "https://api.github.com/users/vincentdavis/gists{/gist_id}", "starred_url": "https://api.github.com/users/vincentdavis/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/vincentdavis/subscriptions", "organizations_url": "https://api.github.com/users/vincentdavis/orgs", "repos_url": "https://api.github.com/users/vincentdavis/repos", "events_url": "https://api.github.com/users/vincentdavis/events{/privacy}", "received_events_url": "https://api.github.com/users/vincentdavis/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "How did you create the table, as in what method? You should have either called db.create_tables or model.create_table, but not db.create_table as this will not create indexes.\n", "I used db.create_table.\nThanks\n", "Yeah, it's an older API and can unfortunately cause some confusion... db.create_table() just creates the table. However create_tables() will create the tables for a number of models, resolving the foreign key dependencies to ensure a proper order of operations. Model.create_table() will just create the table and indexes for the model.\n" ]
2016-01-06T03:49:05
2016-01-06T20:03:13
2016-01-06T19:56:25
NONE
null
Existing SQLite DB defines and created by peewee. Adding a new table, with a field that has unique=True. The resulting table does not get the unique constrat added. In my case the line below is needed but not added. I had to remove the entire db to get peewee to add the table correctly. The table had no ForeignKeyField. ``` sql CREATE UNIQUE INDEX addresses_IdHash ON addresses (IdHash); ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/807/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/807/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/806
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/806/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/806/comments
https://api.github.com/repos/coleifer/peewee/issues/806/events
https://github.com/coleifer/peewee/issues/806
124,947,645
MDU6SXNzdWUxMjQ5NDc2NDU=
806
query always return same data even the data is updated in mysql db
{ "login": "dista", "id": 674913, "node_id": "MDQ6VXNlcjY3NDkxMw==", "avatar_url": "https://avatars.githubusercontent.com/u/674913?v=4", "gravatar_id": "", "url": "https://api.github.com/users/dista", "html_url": "https://github.com/dista", "followers_url": "https://api.github.com/users/dista/followers", "following_url": "https://api.github.com/users/dista/following{/other_user}", "gists_url": "https://api.github.com/users/dista/gists{/gist_id}", "starred_url": "https://api.github.com/users/dista/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/dista/subscriptions", "organizations_url": "https://api.github.com/users/dista/orgs", "repos_url": "https://api.github.com/users/dista/repos", "events_url": "https://api.github.com/users/dista/events{/privacy}", "received_events_url": "https://api.github.com/users/dista/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I turn on mysql log, it seems the query really go to mysql\n\n```\nmysql> select * from mysql.general_log;\n+---------------------+------------------------------------+-----------+-----------+--------------+--------------------------------------------------------------------------------------------------------------------------------------------------------+\n| event_time | user_host | thread_id | server_id | command_type | argument |\n+---------------------+------------------------------------+-----------+-----------+--------------+--------------------------------------------------------------------------------------------------------------------------------------------------------+\n| 2016-01-05 19:58:04 | tvie[tvie] @ localhost [] | 31 | 0 | Query | select * from mysql.general_log |\n| 2016-01-05 19:58:15 | tvie[tvie] @ localhost [127.0.0.1] | 83 | 0 | Query | SELECT `t1`.`id`, `t1`.`hostname`, `t1`.`processname`, `t1`.`version`, `t1`.`start_time` FROM `processstate` AS t1 WHERE (`t1`.`hostname` = 'dista81') |\n| 2016-01-05 19:58:21 | tvie[tvie] @ localhost [] | 31 | 0 | Query | select * from mysql.general_log |\n| 2016-01-05 19:58:32 | tvie[tvie] @ localhost [127.0.0.1] | 83 | 0 | Query | SELECT `t1`.`id`, `t1`.`hostname`, `t1`.`processname`, `t1`.`version`, `t1`.`start_time` FROM `processstate` AS t1 WHERE (`t1`.`hostname` = 'dista81') |\n| 2016-01-05 19:58:34 | tvie[tvie] @ localhost [] | 31 | 0 | Query | select * from mysql.general_log |\n| 2016-01-05 19:58:50 | tvie[tvie] @ localhost [127.0.0.1] | 83 | 0 | Query | SELECT `t1`.`id`, `t1`.`hostname`, `t1`.`processname`, `t1`.`version`, `t1`.`start_time` FROM `processstate` AS t1 WHERE (`t1`.`hostname` = 'dista81') |\n| 2016-01-05 19:58:51 | tvie[tvie] @ localhost [] | 31 | 0 | Query | select * from mysql.general_log |\n| 2016-01-05 19:59:43 | tvie[tvie] @ localhost [127.0.0.1] | 83 | 0 | Query | SELECT `t1`.`id`, `t1`.`hostname`, `t1`.`processname`, `t1`.`version`, `t1`.`start_time` FROM `processstate` AS t1 WHERE (`t1`.`hostname` = 'dista81') |\n| 2016-01-05 19:59:48 | tvie[tvie] @ localhost [] | 31 | 0 | Query | select * from mysql.general_log |\n+---------------------+------------------------------------+-----------+-----------+--------------+--------------------------------------------------------------------------------------------------------------------------------------------------------+\n9 rows in set (0.00 sec)\n\n```\n", "After change code to the following, it works\n\n```\n processes_q = ProcessState.select().where(ProcessState.hostname == \"dista81\")\n\n for item in processes_q:\n print item.start_time\n\n db.commit()\n```\n\nBut I do not want to write that because it is ugly, Is there any other way to make sure it will read the latest result?\n\nmy connection statement\n\n```\nconnect('mysql://xx:[email protected]:3306/lava_log_cluster')\n```\n", "I check mysql log again, I found this:\n\n```\n+---------------------+------------------------------------+-----------+-----------+--------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+\n| 2016-01-05 20:56:28 | tvie[tvie] @ localhost [] | 31 | 0 | Query | select * from mysql.general_log order by event_time desc limit 10 |\n| 2016-01-05 20:56:12 | tvie[tvie] @ localhost [] | 31 | 0 | Query | select * from mysql.general_log order by event_time desc limit 10 |\n| 2016-01-05 20:56:08 | [tvie] @ localhost [127.0.0.1] | 94 | 0 | Connect | tvie@localhost on lava_log_cluster |\n| 2016-01-05 20:56:08 | tvie[tvie] @ localhost [127.0.0.1] | 94 | 0 | Query | SET NAMES utf8 |\n| 2016-01-05 20:56:08 | tvie[tvie] @ localhost [127.0.0.1] | 94 | 0 | Query | set autocommit=0 \n```\n\nthe autocommit mode in the log is 0.\n\nBut I do set autocommit=True in code:\n\n```\nrealdb = MySQLDatabase(\"lava_log_cluster\", host=\"127.0.0.1\",port=3306,user=\"xx\",passwd=\"xxx\", autocommit=True)\n#realdb = connect('mysql://xx:[email protected]:3306/lava_log_cluster')\ndb.initialize(realdb)\nprint db.get_autocommit()\ndb.set_autocommit(True)\n\n```\n\nWhy is that?\n", "We've just noticed the same issue. We've reverted to 2.6.4 which works fine, the bug was introduced in version 2.7.0.\n", "issue #727 introduced this bug, commit is required after select for mysql.\n\nWell, at least for long living connections. IF you disconnect after each request there should be no problem. Or commit at the end of each request.\n", "What about wrapping your code in a transaction?\n\n``` python\nwith db.atomic():\n processes_q = ProcessState.select().where(ProcessState.hostname == \"dista81\")\n\n for item in processes_q:\n print item.start_time\n```\n\nFurthermore, for a web app you really should not be using a single static connection. Did you read the docs here:\n\nhttp://docs.peewee-orm.com/en/latest/peewee/database.html#adding-request-hooks\n\nIf you read that and still are sure that a long-lived conn is what you want, I'd suggest wrapping each view in a transaction using the `atomic()` decorator or context manager.\n", "I use bottle and I read the document the one you specified, but I am a little confused,\n\n```\n# app.py\nfrom bottle import hook #, route, etc, etc.\nfrom peewee import *\n\ndb = SqliteDatabase('my-bottle-app.db')\n\n@hook('before_request')\ndef _connect_db():\n db.connect()\n\n@hook('after_request')\ndef _close_db():\n if not db.is_closed():\n db.close()\n\n# Rest of your bottle app goes here.\n```\n\nIf I run bottle in multi thread server like `cherrypy cherrypy Multi-threaded and very stable`, can it work?\n\nfor example:\nthread 1 call the db.connect hook, then execute the request, before thread 1 call db.close hook,\nthread 2 call db.connect hook. \n", "@goir , thanks, I manually set commit_select = True to db, and the problem is gone\n", "Database connections are thread local and are safe in multithreaded environments.\n", "thanks\n", "Wanted to get some clarification on this, since while debugging performance of my web app, I noticed that a lot of time is being spend doing commits after every SELECT (notably on requests that involve a lot of SELECT queries), which led me to finding the `commit_select = True` attribute in `MySQLDatabase`.\r\n\r\nIs my understanding correct, that if I properly wrap my request start/end with db connect/close (in my case I am just using `playhouse.flask_utils.FlaskDB`), then I can safely set `commit_select = False`?", "> Is my understanding correct, that if I properly wrap my request start/end with db connect/close (in my case I am just using playhouse.flask_utils.FlaskDB), then I can safely set commit_select = False?\r\n\r\nAhh, perhaps. Better would be to wrap your database code with the `db.atomic()` decorator, as this will disable the autocommit-type behavior.", "Hmm well my application is pretty large and there are a lot of queries all over the place so it's not really practical to wrap each one with an atomic() decorator. Unless you mean to wrap the whole request itself? But that wouldn't be great either because there are several endpoints/APIs where I would still want the write operations to commit, even if an exception happens mid-request.\r\n\r\nAlso I'm curious about this from a high-level/architecture perspective. At least in the case of web services, I would think that the expected/default behavior should be for all queries within a request to operate in the same \"commit lifecycle\" (not sure on the correct terminology here). E.g. if I am re-reading rows from the same table, I don't want the data to change mid-request if a write in a separate request changed the data.\r\n\r\nAlso, even with `commit_select = False`, I still see `set autocommit=0` at the beginning of each request in the mysql log. Is that expected?\r\n", "I am not suggesting you wrap each query with `atomic()`. That's silly.\r\n\r\nWrapping the whole request in a transaction is a very good idea and very sensible. Wrapping even distinct subsets of operations in `atomic()` is fine.\r\n\r\n> E.g. if I am re-reading rows from the same table, I don't want the data to change mid-request if a write in a separate request changed the data.\r\n\r\nThis is called isolation, and you need to wrap your blocks with `atomic()` to get this.\r\n\r\n> I still see set autocommit=0 at the beginning of each request in the mysql log. Is that expected?\r\n\r\nYes. Peewee handles all this stuff.\r\n\r\n-------------------\r\n\r\nSo to step back. Peewee operates in autocommit mode by default. No, not your database server's \"autocommit\", but it is effectively the same. This is to help beginners and not be confusing...e.g., when you save a model or call `create()`, then the operation happens and is committed immediately. But it is not ideal from a performance or even correctness point-of-view.\r\n\r\nTo achieve better performance, isolation, etc., you should make use of the `atomic()` helpers provided by Peewee (which can even be nested, committed/rolled-back mid-way through, and all sorts of stuff). For web apps, a transaction-per-request is usually a good way to go. If you need to commit midway through, you can do this:\r\n\r\n```python\r\n\r\nwith db.atomic() as txn:\r\n # do some stuff.\r\n txn.commit() # everything up til now is committed, new txn starts.\r\n\r\n # do some stuff\r\n\r\n# txn is committed implicitly at end of \"with\" block, unless\r\n# an exception occurred, in which case it is rolled-back.\r\n```\r\n\r\nI'd suggest you probably would want to read up on ACID and how COMMIT works in your db. ", "> I am not suggesting you wrap each query with `atomic()`. That's silly.\r\n\r\nOk, that's what I thought :), but just checking.\r\n\r\nThanks for the details. I do have a basic understanding of ACID and I do currently use `db.atomic`/rollback/etc in some places with expected results, but I admit my knowledge on it could be improved, especially as to exactly what's going on at the lower levels. I'll do some more reading on that. And yeah, it hadn't occurred to me that it makes sense to have each request operate in its own transaction (and make use of nested transaction and commits). I think that's the missing piece that will solve a lot of my questions/issues.\r\n\r\nThanks again for the support/explanation." ]
2016-01-05T11:36:32
2019-05-05T22:26:29
2016-01-06T01:44:26
NONE
null
I have encountered such problem: There is an simple web application that using peewee to retrieve data from db. something like this: ``` @route('/log_cluster/test') def test(): processes_q = ProcessState.select().where(ProcessState.hostname == "dista81") for item in processes_q: print item.start_time ``` This app does `NOT` have any modification action to db, only 'select' calls. I update data in mysql using mysql cli, but after I changed the data in mysql, the data returned in my simple web application is `NOT` updated.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/806/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/806/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/805
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/805/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/805/comments
https://api.github.com/repos/coleifer/peewee/issues/805/events
https://github.com/coleifer/peewee/issues/805
124,626,851
MDU6SXNzdWUxMjQ2MjY4NTE=
805
Some troubles with SQLite autoincrementing primary key.
{ "login": "JoanSoConfused", "id": 16522559, "node_id": "MDQ6VXNlcjE2NTIyNTU5", "avatar_url": "https://avatars.githubusercontent.com/u/16522559?v=4", "gravatar_id": "", "url": "https://api.github.com/users/JoanSoConfused", "html_url": "https://github.com/JoanSoConfused", "followers_url": "https://api.github.com/users/JoanSoConfused/followers", "following_url": "https://api.github.com/users/JoanSoConfused/following{/other_user}", "gists_url": "https://api.github.com/users/JoanSoConfused/gists{/gist_id}", "starred_url": "https://api.github.com/users/JoanSoConfused/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/JoanSoConfused/subscriptions", "organizations_url": "https://api.github.com/users/JoanSoConfused/orgs", "repos_url": "https://api.github.com/users/JoanSoConfused/repos", "events_url": "https://api.github.com/users/JoanSoConfused/events{/privacy}", "received_events_url": "https://api.github.com/users/JoanSoConfused/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "You don't need the `force_insert=True` since you are using an auto-incrementing primary key. That might be the first problem.\n\n> When I inspect the person table I see the id field that peewee added does not have autoincrement!\n\nSQLite and autoincrement is more involved than you might think. There's a reason peewee doesn't specify `AUTOINCREMENT` with SQLite, described here:\n\nhttps://www.sqlite.org/autoinc.html\n\nPeewee instead will use the unique `rowid` which uses the algorithm MAX(rowid) + 1 to generate new rowids, rather than ensuring they are unique across deletions, etc.\n", "I remove the force_insert=True and it does work! Many thank yous!\n\nI think there are still bugs here even if some of them are just bugs with the documentations.\n1. I do not see why using force_insert=True should cause the code to fail with such an unobvious error. The error should be more obvious or force_insert=True should be ok to use all the time. I was doing an insert so being able to force it is something I should be able to do, no? The documentations say \"If force_insert=True an INSERT will be issued regardless of whether or not the primary key exists.\" And I do not see the documentations warning me that I should not use it or not use it if I am using SQLite! So I think the documentations are very misleading and maybe even wrong in this case.\n2. The reason for there being no autoincrement for the SQLite would be good note in documentation so we know what going on! It is very confusing when the documentation say \"Because we have not specified a primary key, peewee will automatically add an auto-incrementing integer primary key field named id.\" but there is no warning that SQLite has special handlings!\n\nRight now the documentations are very misleading and the actual behaviors are very surprising. The documentations say it is ok to do things that it is not ok to do apparently, like use force_insert=True. They also do not explain very unexpected behaviors with SQLite like there being no autoincrement.\n\nI would contributes the documentation changes by my written English is not so good! But the documentations should be there to help us not confuse us with things that are misleading or wrong or if they do not say we should beware of surprises that would surprise us.\n\nI think it be very helpful if the documentations are fixed to be clear about how SQLite is different from what would be expected by long time SQLite users and SQLite users who have used other ORM with SQLite that works in ways different from peewee.\n", "1. Why are you calling `force_insert=True`? The docs indicate that parameter is only needed if you have a non-auto-incrementing primary key, or if you explicitly want to set the primary key to the value in the model instance.\n2. I don't see how I can document every little quirk of each db engine. Know your database, simple as that.\n\nI disagree that the docs are misleading. peewee has been around for 5 years and nobody's been that confused by the way `force_insert` works.\n", "1. I was a user of force_insert=True because I was creating an object for the first time and when I was looked at the table that peewee itself created with its default id primary key column it was like `\"id\" INTEGER NOT NULL PRIMARY KEY` with no auto-increment! So I did exactly what you and the documentation said to do: used force_insert=True because when I look at table schema it has a, as you said, \"a non-auto-incrementing primary key\"! I see not auto-increment in the column definition so it is by definition not non-auto-incrementing primary key! Now I know this wrong apparently in peewee land but the documentations are not clear at all so I ask for clarification.\n2. This is not \"little quirk\". It is peewee specific. In other ORM and hand written code they and we just use SQLite autoincrement directly. The deceiving part is peewee documents saying \"Because we have not specified a primary key, peewee will automatically add an auto-incrementing integer primary key field named id.\" but then on SQLite not actually using the built in autoincrement and instead doing its own peewee specific magic. I'm not saying peewee approach is unjustified but it is unusual and that is why it should be documented so that long time SQLite users who know how SQLite is typically work know that peewee is doing things so differently! Primary keys are not a \"little\" part of relational databases. Primary keys are very important!\n\nI must state that this my first experiences with peewee and I not impressed! I do not think I being unreasonable for asking for documentations to be clearer. And I probably am not first person to experience this. There probably others but I am first to speak up. Other people probably do what I am thinking of doing and moving to other Python ORM that has documentations that are clear and not misleading like peewee documentations current are. I want to be a user of peewee so bad but peewee is supposed to save me time and me having to deal with peewee-specific quirk only wastes time! I do not understand why you are not willing to add but like 2 sentences to documentations to help people now and in future. peewee work in unusual way and documentation should say so!\n", "Peewee does create an auto-incrementing primary key field named \"id\" automatically. In order to save CPU and RAM with SQLite, Peewee uses the native `rowid` field rather than specifically requiring globally unique auto-incrementing ids with SQLite. The docs are correct, you just misinterpreted the behavior of SQLite and Peewee in this case. I could care less which ORM you use, peewee would have saved you time if you had just used it like it is used in the docs.\n" ]
2016-01-03T03:41:12
2016-01-04T03:26:28
2016-01-03T15:03:36
NONE
null
I am new to the peewee and I am using peewee 2.7.4 with Python 3.5.0 and with SQLite and I am very confused about SQLite autoincrementing primary keys on tables. The peewee documentations says "peewee will automatically add an auto-incrementing integer primary key field named id." I am using code based on some documentation sample code: ``` #!/usr/bin/env python3.5 from peewee import * db = SqliteDatabase('people.db') class Person(Model): name = CharField() birthday = DateField() is_relative = BooleanField() class Meta: database = db # This model uses the "people.db" database. db.connect() db.create_tables([Person], True) person = Person.create(name='Joan', birthday='1970-01-01', is_relative=False) person.save(force_insert=True) ``` So class Person has no primary key field so peewee should add one I think. When I run the code it dies: "sqlite3.IntegrityError: UNIQUE constraint failed: person.id" When I inspect the person table I see the id field that peewee added does not have autoincrement! ``` sqlite> .schema person CREATE TABLE "person" ("id" INTEGER NOT NULL PRIMARY KEY, "name" VARCHAR(255) NOT NULL, "birthday" DATE NOT NULL, "is_relative" SMALLINT NOT NULL); sqlite> ``` I do not know what is bug here! Should id column have autoincrement? Or should documentations be clearer about specialistic SQLite behaviors? Your friend, Joan
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/805/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/805/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/804
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/804/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/804/comments
https://api.github.com/repos/coleifer/peewee/issues/804/events
https://github.com/coleifer/peewee/issues/804
124,333,082
MDU6SXNzdWUxMjQzMzMwODI=
804
Proposal for plugins support
{ "login": "foxx", "id": 651797, "node_id": "MDQ6VXNlcjY1MTc5Nw==", "avatar_url": "https://avatars.githubusercontent.com/u/651797?v=4", "gravatar_id": "", "url": "https://api.github.com/users/foxx", "html_url": "https://github.com/foxx", "followers_url": "https://api.github.com/users/foxx/followers", "following_url": "https://api.github.com/users/foxx/following{/other_user}", "gists_url": "https://api.github.com/users/foxx/gists{/gist_id}", "starred_url": "https://api.github.com/users/foxx/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/foxx/subscriptions", "organizations_url": "https://api.github.com/users/foxx/orgs", "repos_url": "https://api.github.com/users/foxx/repos", "events_url": "https://api.github.com/users/foxx/events{/privacy}", "received_events_url": "https://api.github.com/users/foxx/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "+1!\n\n> This could also open the door for potentially cleaning up Playhouse, allowing each of the extensions to be segregated into it's own plugin, keeping the core repo clean and lean.\n\nWould be a really really nice move :)\n", "Also, see http://www.devork.be/talks/pluggy/pluggy.html about pluggy.py (which lacks proper doc), the plugin facility of pytest.\n", "I'm not familiar with the setup.py magic, but that's definitely pretty cool. I recall Flask used to namespace extensions under `flask_ext` using some kind of magic, but then they moved away from it. From a personal standpoint, I'm not sure what it gets you beyond having your `import` statement slightly different. Am I missing something?\n", "In my particular use case, the primary benefits are nicer import statements and easier monkeypatching.\n\nI've got a collection of approx 15 extensions/plugins for Peewee that I'd like to open source, but some of them require a monkeypatch entry point, meaning the user has to do this;\n\n``` python\nfrom peewee_dbmanager import DBManager, monkeypatch\nmonkeypatch()\n```\n\nInstead of just this;\n\n``` python\nfrom peewee.dbmanager import DBManager\n```\n\nOr even just this;\n\n``` python\nfrom peewee import DBManager\n```\n\nDepending on how many of the additional libraries are being used, all of a sudden a single line import turns into 20 lines of boilerplate code.\n\nI've had a look at `pluggy` and the `setup.py` magic, it's quite awesome indeed but my primary concern is that this proposal would be rejected due to additional complexity, at the same time any plugin enhancement patch should cover future use cases, making `pluggy` the best candidate thus far due to maturity from `pytest`.\n", "> my primary concern is that this proposal would be rejected due to additional complexity\n\nIndeed. I'm not sure having what amounts to \"vanity\" imports would justify adding this additional complexity to peewee. Going to pass for now.\n", "I think that the \"vanity\" imports are not only less important but might be even counter productive. I mean, when reviewing someone's code, it's not immediately clear where this import comes from (is it from peewee itself? some other library?).\n\nBut on the other hand, hooks to allow extending peewee to avoid monkey patching are very important. There are many improvements that can be offered as plugins, but shouldn't go into core, that are hard to implement or maintain without proper hooks.\n\nJust today I monkey patched `Query` class, to be able to measure query execution time: https://github.com/getredash/redash/blob/feature/permissions/redash/metrics/database.py#L36-L62\n\nI've also [extended the `PostgresExtDatabase` class](https://github.com/getredash/redash/blob/feature/permissions/redash/metrics/database.py#L12-L33) for similar purposes. I would preferred to offer this as a library for all `Database` derived classes, but I'm not sure if it's possible without monkey patching without proper hooks.\n", "If the primary reason for rejection is complexity of `pluggy`, then we can achieve the same goal with just 10 lines of code added to the core, by using `entry_points` as seen in the thorough example [here](http://stackoverflow.com/questions/774824/explain-python-entry-points). This would simply look for any advertised objects, which should be callable, on `peewee_plugins` and then call them. \n\nThis would give us simple plugins with monkeypatching support, whilst also keeping the implementation clean and simple. Thoughts @coleifer / @arikfr ?\n", "@coleifer Has this been re-opened for consideration? If so, is there's anything I can do to help? Should I send a PR for POC?\n", "I reopened the issue because it seems that there may be some way to add hooks to avoid 3rd party packages needing to monkey-patch. I'd like to hear some use-cases that you all are currently considering, and that would require monkey-patching, so we can come up with a better solution.\n", "Well, I haven't really heard any use-cases where monkey-patching is currently necessary but a plugin approach would help avoid this... Please chime in if you think of something.\n", "There is the metrics tracking use case I had:\nhttps://github.com/getredash/redash/blob/feature/permissions/redash/metrics/database.py#L38-L64\n\nOr being able to override `execute_sql` of the base `Database` class: \nhttps://github.com/getredash/redash/blob/feature/permissions/redash/metrics/database.py#L18-L29\n\nI would love to generalize these two into a plugin.\n", "In the first case extending via subclass + override seems correct. In the second case I'd hardly call that a common use-case...\n", "I've tried subclassing first -- I've subclassed `Model` and changed all the query methods to return wrapped query object, but then it was lost when `.clone` was called on the query object. Obviously I can override it too, but it becomes more an more complex, and I ended up monkey patching the methods on the base class.\n\nOn the other hand if there were `before_execute` and `after_execute` hooks, I could implement it easily without overriding or monkey patching.\n\nThe second case is part of the same thing I tried to accomplish -- measure query execution time and number of queries executed per web request. And the same thing here: simple before/after hooks on execute would be enough.\n", "For my use case, creating a database manager for Peewee requires monkeypatching to override `_execute` and `Node`, similar to @arikfr, but as he mentioned if Peewee had a hooks system then monkeypatching would not be necessary at all.\n", "After some testing and consideration, I'm not convinced that `entry_points` is the correct approach for monkeypatch hooks. If this approach was used, then installing and importing a plugin would cause monkeypatching to happen behind the scenes, breaking the mantra of \"explicit is better than implicit\", meaning it's cleaner to call `someplugin.monkeypatch()`.\n\nThe problem in mine and @arikfr's use case is the inability to change Peewee internals without modifying global namespace, and a lack of hooks such as `before_execute` and `after_execute`. However even if we had those hooks, they would still impact global namespace due to the design of Peewee. Although we can subclass `Query` with the `_execute()` modifications, then apply this by subclassing `Model` and overloading `select()`, doing so could cause future problems because the entire `select()` class needs to be duplicated and modified.\n\nOne approach would be assigning class attributes to `Model` and `Database`, which are then used to determine the target class used. This approach could be quite tedious however, resulting in a lot of boilerplate on each class. For example;\n\n``` python\nclass Model(with_metaclass(BaseModel)):\n select_query_class = SelectQuery\n\n @classmethod\n def select(cls, *selection):\n query = self.select_query_class(cls, *selection)\n\n```\n\nInstead it might be cleaner to use a single method which a subclass can implement;\n\n``` python\nclass Model(with_metaclass(BaseModel)):\n @classmethod\n def get_class(cls):\n return cls\n\n @classmethod\n def select(cls, *selection):\n query = self.get_class(SelectQuery)(cls, *selection)\n\nclass MySelectQuery(SelectQuery):\n def _execute(self, *args, **kwargs):\n print(\"do something\")\n super()._execute(*args, **kwargs)\n\nclass MyModel(Model):\n @classmethod\n def get_class(cls):\n if cls == SelectQuery:\n return MySelectQuery\n return cls\n```\n\nThe above would allow us to easily patch Peewee internals on a per instance basis, without resorting to monkeypatching or peewee core duplication.\n\nI've done some trials of implementing this into Peewee and the results so far have been fantastic, very little change in performance and no monkeypatching required.\n\nAssuming this was accepted, I would probably be -0 on adding plugins support for now, as I wouldn't have a use case for it any longer.\n\nThoughts @arikfr / @coleifer ?\n", "Urgh, yeah I'm definitely not loving it.\n", "@coleifer This is pretty much the cleanest implementation I can think of, and after trying it some more, I've almost come to the conclusion that this isn't particularly clean from a core lib standpoint either.\n\nAnother option is module inheritance [overloading](http://stackoverflow.com/questions/7483022/clone-a-module-and-make-changes-to-the-copy), although this isn't always guaranteed to work is classes have been referenced in the original import, and therefore wouldn't be advisable.\n\nThe only clear path I'm seeing is sadly monkeypatching `peewee` module on import, and using something like [this](https://gist.github.com/foxx/87e44e00901ebddb5f93) to apply late subclasses. This has been the approach I've used since day 1, and has served me well for 6 months so far.\n\nSadly this does mean that my vote in this issue would be \"wontfix\", on the grounds that there doesn't appear to be a better alternative than monkeypatching.\n\nInstead of a code modification, perhaps we could include a docs update which explains how to do monkeypatching and extending, along with an example, using the tools shown in the above mentioned [gist](https://gist.github.com/foxx/87e44e00901ebddb5f93). Thoughts?\n", "+1 for avoiding entry points for the implicitness of it (and the need to publish plugins as Python packages).\n\nHow about starting with a set of simple hooks (like the before/after execute), that are global to peewee in the context of a single codebase/application? \n\nThe implementation for the above should be straightforward and still allow many interesting extensions. If @coleifer is cool with that, I can make pull request with a suggestion for implementation.\n", "@arikfr Could you give an example of how these hooks might be implemented and exposed? Every option I've explored has resulted with unnecessary complexity in the core, for a feature that could be easily implemented with monkey patching. Having `pre_execute` and `post_execute` can be easily done with;\n\n``` python\nclass Query(peewee.Query):\n def _execute(self, *args, **kwargs):\n print(\"pre\")\n r = super()._execute(*args, **kwargs)\n print(\"post\")\n return r\n\npeewee.Query = Query\n```\n\nFrom what I can see, the only benefit of extending Peewee internals to support hooks would be if they were on a per instance basis, however due to the design of Peewee this cannot be easily achieved (for reasons mentioned earlier, least not without a lot of redesign which results in something even more convoluted).\n\nThat being said, let me know if I've overlooked anything and I'll happily reconsider/review.\n", "Thought I'd share my discoveries from #825, as getting monkeypatching to work consistently has been troublesome.\n\nThere is an outstanding [bug](http://bugs.python.org/issue672115) in Python which prevents dynamic modification of `__bases__`, meaning that classes which are an immediate subclass of `object` cannot be extended, where as classes which are a distant subclass can. For example;\n\n``` python\nclass ModelOptions(object): pass # this cannot be extended in-line\nclass SqliteDatabase(Database): pass # this can\n```\n\nFor classes that cannot be modified inline, the alternative approach is to overwrite classes in peewee namespace, before anything else has a chance to access them. However this is not always guaranteed to work, as seen here;\n\n``` python\nimport peewee\n\nclass ModifiedSqliteDatabase(peewee.SqliteDatabase):\n pass\n\npeewee.SqliteDatabase = ModifiedSqliteDatabase\npeewee.SqliteDatabase(':memory:')\n```\n\n``` python\n File \"peewee-2.8.0-py3.4.egg/peewee.py\", line 3606, in __init__\n File \"peewee-2.8.0-py3.4.egg/peewee.py\", line 3606, in __init__\n File \"peewee-2.8.0-py3.4.egg/peewee.py\", line 3606, in __init__\nRuntimeError: maximum recursion depth exceeded\n```\n\nThis also means putting your `monkeypatch()` call before anything else, something you cannot guarantee if your application is loaded by another tool, such as py.test. Any objects created prior to the monkeypatch will use the old class, hence why this \"late\" approach is not preferred.\n\nOther approaches include using a custom metaclass, such as subclassing `BaseModel` for `Model`, however this will break other libraries using the same hacks, due to [multiple inheritance inconsistencies](http://stackoverflow.com/questions/3003053/metaclass-multiple-inheritance-inconsistency).\n\nAnd finally, you can manipulate an existing class, rather than applying a mixin subclass. Naturally you'll lose the ability to do `issubclass()` or `isinstance()` comparisons against your mixin, but chances are you will not need this anyway.\n\n``` py\ndatabase = property(getter, setter, del)\npeewee.ModelOptions.database = database\n```\n\ntl;dr - Different objects will require different monkeypatching approaches, and hopefully the above will save you a couple of hours.\n", "Does the custom base ModelOptions commit in #825 (e773c620de3d7dc686dab3c2325e02d1e86407d6) address some of the concerns brought up here?\n", "Looks like #825 resolves every issue I had with implementing a database manager for Peewee. \n\nThere are still some situations where monkeypatching cannot be avoid, as adding certain hooks would add significant mess/complexity into the core, as seen in earlier discussions.\n\nI'd be happy to contribute a docs patch explaining some of the monkeypatching tricks above, if you feel it would be beneficial, although it can be argued that this is a topic outside of Peewee.\n\nOther than a possible docs patch, I'd +1 closing this issue.\n", "Oh there is something that comes to mind, relating specifically to the example from @arikfr.\n\nIn his use case, he was overloading `Query._execute()` in order to measure execution times. Doing this by overloading `Model.select()` isn't really an option, because it would require copy/paste of Peewee internals, as mentioned earlier.\n\nFor his situation, a similar patch might also help with those cases;\n\n``` python\nclass A(Model):\n class Meta:\n select_query_class = CustomSelectQuery\n raw_query_class = CustomRawQuery\n ..etc etc\n```\n\nThis is the same approach as the `ModelOptions` patch, but it does result in more mess as these classes are referenced in several places. From an implementation standpoint, it would look like this;\n\n``` python\n @classmethod\n def select(cls, *selection):\n query = self._meta.select_query_class(cls, *selection)\n if cls._meta.order_by:\n query = query.order_by(*cls._meta.order_by)\n return query\n```\n\nThat being said, this would handle a significant range of plugin functionality without the need for monkeypaching. It also prevents peewee namespace from being modified, which is a huge benefit.\n\nIf this was in the core, the only instance I can think of where monkeypatching would be needed would be hotfixing internals.\n\nAssuming @coleifer was happy with the additional mess caused, I would certainly be +1\n", "Ehh, I'm not quite sure again why you couldn't just override `select`. Is it that common of an occurance that you need a custom `SelectQuery` implementation?\n", "Actually I just realised something, you can override `insert()` without having to copy a bunch of internals as seen;\n\n``` python\n@classmethod\n def insert(cls, __data=None, **insert):\n fdict = __data or {} # needs copying\n fdict.update([(cls._meta.fields[f], insert[f]) for f in insert]) # needs copying\n return MyInsertQueryHere(cls, fdict) # custom lines here\n```\n\nBecause the `Query()` is an instance, it becomes super easy to extend `__bases__` with none of the horrible monkeypatching bugs I mentioned earlier. For example;\n\n``` python\n@classmethod\n def insert(cls, __data=None, **insert):\n r = super(Model, cls).insert(data, **insert)\n extend_instance(r, InsertQueryMixin) # see below for gist\n return r\n```\n\nYou can find my version of `extend_instance` [here](https://gist.github.com/foxx/5807755d92a76970dae6), it's fully doc tested and been used in prod with no problems.\n\nI can't think of any scenario that the above won't cover, including the use case mentioned by @arikfr. \n\nIf anyone can't make their plugin work using the variety of solutions mentioned above and in this thread, then please let me know and I'll do my best to help.\n\nThanks for the feedback @coleifer !\n", "Thanks for the comments, hopefully folks will be able to find this thread if they encounter similar issues.\n", "> Is it that common of an occurrence that you need a custom SelectQuery implementation?\n\nI also have a custom SelectQuery, and being able to just change a Meta option to use it instead of overriding `select` (including some internals copy-pasting) would be really awesome.\nSo I really appreciate the suggestion of @foxx exposed in [this comment](#issuecomment-173238786) (actually I was to suggest the same approach because I'm already [using](https://github.com/etalab/ban/blob/master/ban/db/model.py#L22) it).\n\n@coleifer would you consider a PR for this?\n", "@yohanboniface You can actually achieve this behaviour by using late mixins via [`extend_instance`](https://gist.github.com/foxx/5807755d92a76970dae6). \n\nThis function injects other classes into an instance `__bases__`, allowing for only that specific instance to be affected by the patch. Although it might feel a bit strange relying on a non standard function, this is a tried and tested technique for monkeypatching and has proven very reliable. I've actually included it as part of a helpers library I've [released](https://github.com/foxx/bottlecap/blob/master/helpful.py), but it's not yet documented.\n\n``` python\nclass SelectQueryMixin(peewee.SelectQuery):\n def _get_result_wrapper(self):\n super_func = super(SelectQueryMixin, self)._get_result_wrapper\n return getattr(self, '_result_wrapper', None) or super_func()\n\n def __len__(self):\n return self.count()\n\n\nclass Model(peewee.Model):\n class Meta:\n database = default\n\n @classmethod\n def select(cls, *args, **kwargs):\n obj = super(Model, cls).select(*args, **kwargs)\n extend_instance(obj, SelectQueryMixin)\n return obj\n```\n" ]
2015-12-30T10:54:40
2016-01-29T15:06:38
2016-01-21T00:14:59
CONTRIBUTOR
null
There is currently no easy way to build third party plugins within the same namespace as `peewee`, aside from monkeypatching. Projects such as [pytest](https://pytest.org/latest/plugins.html) allow plugins to be registered into the Peewee namespace, giving a much cleaner syntax, as seen [here](https://github.com/kissgyorgy/pytest-raisesregexp), for example; ``` python from pytest_raisesregexp import raisesregexp # without plugins from pytest import raises_regexp # with plugins ``` This is apparently achieved via `entry_points` as seen [here](http://pytest.org/2.2.4/plugins.html#making-your-plugin-installable-by-others), and allows the plugin to interact via hooks, as seen [here](http://pytest.org/2.2.4/plugins.html#well-specified-hooks). In particular, the plugin can access `pytest_namespace` which allows manipulation of the namespace. The use case in this situation would be for providing third party plugins which are not suitable for the core or playhouse, whilst keeping everything in a single namespace. ``` python from peewee_dbmanager import DBManager # without plugins from peewee.dbmanager import DBManager # with plugins OR from peewee import DBManager # with plugins ``` This could also open the door for potentially cleaning up Playhouse, allowing each of the `extensions` to be segregated into it's own plugin, keeping the core repo clean and lean. Thoughts @coleifer ?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/804/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/804/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/803
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/803/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/803/comments
https://api.github.com/repos/coleifer/peewee/issues/803/events
https://github.com/coleifer/peewee/issues/803
124,139,785
MDU6SXNzdWUxMjQxMzk3ODU=
803
Proposal for create/destroy database
{ "login": "foxx", "id": 651797, "node_id": "MDQ6VXNlcjY1MTc5Nw==", "avatar_url": "https://avatars.githubusercontent.com/u/651797?v=4", "gravatar_id": "", "url": "https://api.github.com/users/foxx", "html_url": "https://github.com/foxx", "followers_url": "https://api.github.com/users/foxx/followers", "following_url": "https://api.github.com/users/foxx/following{/other_user}", "gists_url": "https://api.github.com/users/foxx/gists{/gist_id}", "starred_url": "https://api.github.com/users/foxx/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/foxx/subscriptions", "organizations_url": "https://api.github.com/users/foxx/orgs", "repos_url": "https://api.github.com/users/foxx/repos", "events_url": "https://api.github.com/users/foxx/events{/privacy}", "received_events_url": "https://api.github.com/users/foxx/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I've always felt that this type of thing did not belong as a part of peewee. I will pass on this feature.\n", "Got it, I'll put this into a separate repo, thanks for the quick reply!\n", "So there is no way to create a database using peewee, right?\n", "@gitttt -- just use the tool from your vendor. For sqlite you don't have to do anything, as it will create if not exists. For MySQL:\n- https://dev.mysql.com/doc/refman/5.5/en/mysqladmin.html\n- https://dev.mysql.com/doc/refman/5.5/en/create-database.html\n\nFor postgresql, use `createdb`: http://www.postgresql.org/docs/9.1/static/app-createdb.html\n", "ok, thanks\n", "for future MySQL readers, the way I chose to do this (after ending up here) was this: \r\n\r\n```\r\n db = MySQLdb.connect(host='', user='', passwd='')\r\n c = db.cursor()\r\n c.execute(\"drop database %s\" % db_name)\r\n```" ]
2015-12-28T23:16:24
2017-01-03T23:24:59
2015-12-29T00:56:32
CONTRIBUTOR
null
There is a common use case of creating/destroying databases, for example when running tests. Currently there is no support for automating detecting the source database and acting appropriately, for example; ``` python x = SqliteDatabase("file:/tmp/lala.sql", uri=True) x.create_database() # this would create /tmp/lala.sql x.destroy_database() # this would unlink /tmp/lala x = SqliteDatabase(":memory:", uri=True) x.create_database() # this would create in-memory db space x.destroy_database() # this would close all connections, thus destroying DB space x = MySQLDatabase(host='127.0.0.1', database='helloworld') x.create_database() # this would execute "CREATE DATABASE helloworld;" x.destroy_database() # this would execute "DROP DATABASE helloworld;" ``` I've got the majority of the above working for Sqlite, however I haven't done Postgres or MySQL yet. If this was put forward as a well formed PR, would this sort of functionality be accepted into the core, or playhouse?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/803/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/803/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/802
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/802/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/802/comments
https://api.github.com/repos/coleifer/peewee/issues/802/events
https://github.com/coleifer/peewee/pull/802
124,089,980
MDExOlB1bGxSZXF1ZXN0NTQ2Njc4NDI=
802
Add support for BINARY field in MySQL
{ "login": "foxx", "id": 651797, "node_id": "MDQ6VXNlcjY1MTc5Nw==", "avatar_url": "https://avatars.githubusercontent.com/u/651797?v=4", "gravatar_id": "", "url": "https://api.github.com/users/foxx", "html_url": "https://github.com/foxx", "followers_url": "https://api.github.com/users/foxx/followers", "following_url": "https://api.github.com/users/foxx/following{/other_user}", "gists_url": "https://api.github.com/users/foxx/gists{/gist_id}", "starred_url": "https://api.github.com/users/foxx/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/foxx/subscriptions", "organizations_url": "https://api.github.com/users/foxx/orgs", "repos_url": "https://api.github.com/users/foxx/repos", "events_url": "https://api.github.com/users/foxx/events{/privacy}", "received_events_url": "https://api.github.com/users/foxx/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Needs tests in order to merge.\n", "You can add tests to the `test_fields.TestFieldTypes` or you can just create a one-off test-case. Either is fine.\n", "Done. Apologies for the initial lack of tests, I got lazy!\n", "Those tests don't actually test the binary field.\n", "Ah crap, it looks like my cherry pick didn't apply properly due to lack of concentration, will get this fixed in the morning, sorry\n", "Done, I'm pretty sure this is fine but any problems let me know\n", "Thank you!\n" ]
2015-12-28T16:47:07
2015-12-29T13:35:40
2015-12-29T13:35:36
CONTRIBUTOR
null
See #801
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/802/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/802/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/802", "html_url": "https://github.com/coleifer/peewee/pull/802", "diff_url": "https://github.com/coleifer/peewee/pull/802.diff", "patch_url": "https://github.com/coleifer/peewee/pull/802.patch", "merged_at": "2015-12-29T13:35:36" }
https://api.github.com/repos/coleifer/peewee/issues/801
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/801/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/801/comments
https://api.github.com/repos/coleifer/peewee/issues/801/events
https://github.com/coleifer/peewee/issues/801
124,089,739
MDU6SXNzdWUxMjQwODk3Mzk=
801
Support for binary in MySQL
{ "login": "foxx", "id": 651797, "node_id": "MDQ6VXNlcjY1MTc5Nw==", "avatar_url": "https://avatars.githubusercontent.com/u/651797?v=4", "gravatar_id": "", "url": "https://api.github.com/users/foxx", "html_url": "https://github.com/foxx", "followers_url": "https://api.github.com/users/foxx/followers", "following_url": "https://api.github.com/users/foxx/following{/other_user}", "gists_url": "https://api.github.com/users/foxx/gists{/gist_id}", "starred_url": "https://api.github.com/users/foxx/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/foxx/subscriptions", "organizations_url": "https://api.github.com/users/foxx/orgs", "repos_url": "https://api.github.com/users/foxx/repos", "events_url": "https://api.github.com/users/foxx/events{/privacy}", "received_events_url": "https://api.github.com/users/foxx/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Thank you, merged #802.\n" ]
2015-12-28T16:44:57
2015-12-29T13:36:10
2015-12-29T13:36:10
CONTRIBUTOR
null
Currently there is no support for creating a `BINARY` field in MySQL. Although you can use `BLOB`, this is not a fixed length and requires an index prefix length to be applied.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/801/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/801/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/800
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/800/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/800/comments
https://api.github.com/repos/coleifer/peewee/issues/800/events
https://github.com/coleifer/peewee/pull/800
124,082,874
MDExOlB1bGxSZXF1ZXN0NTQ2NjM1OTU=
800
Patch proposal for better database routing - see #701
{ "login": "foxx", "id": 651797, "node_id": "MDQ6VXNlcjY1MTc5Nw==", "avatar_url": "https://avatars.githubusercontent.com/u/651797?v=4", "gravatar_id": "", "url": "https://api.github.com/users/foxx", "html_url": "https://github.com/foxx", "followers_url": "https://api.github.com/users/foxx/followers", "following_url": "https://api.github.com/users/foxx/following{/other_user}", "gists_url": "https://api.github.com/users/foxx/gists{/gist_id}", "starred_url": "https://api.github.com/users/foxx/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/foxx/subscriptions", "organizations_url": "https://api.github.com/users/foxx/orgs", "repos_url": "https://api.github.com/users/foxx/repos", "events_url": "https://api.github.com/users/foxx/events{/privacy}", "received_events_url": "https://api.github.com/users/foxx/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Although I agree this is a pretty clean patch, I am going to pass on merging.\n\nI think that database routing is a complex enough topic that I do not want to include it in peewee itself (as I don't want to maintain it). One option would be to create a new package `peewee-routing` or something similar that encapsulates this logic.\n", "Thanks for the quick reply! If I put myself forward as a maintainer for this, and submitted a fully documented PR, would you consider merging into playhouse? As a last option I could create a new repo, but would argue the use cases are common enough to justify being in the playhouse.\n", "I appreciate the offer and don't want to seem to be discouraging, but I'm actively trying to rein in some of the sprawl in the code-base and tighten things up. Database-routing, to me, both complex and uninteresting from a maintenance perspective. It is my strong preference to keep it out of this repo.\n", "Okay no worries, I'll look into creating a separate repo for this. I'll update the original issue with the URL once finished, if you're happy with it then (and agree with the approach used), then perhaps it might be worthy of a small section in the docs, so at least people know where to look?\n", "> then perhaps it might be worthy of a small section in the docs, so at least people know where to look?\n\nI'm sure it'll turn out well, and I'd be happy to link it up.\n" ]
2015-12-28T15:46:26
2015-12-28T22:56:48
2015-12-28T22:26:17
CONTRIBUTOR
null
After several different attempts, this seems to be the cleanest way forward. For this patch to be merge worthy, I'd need sign off from @coleifer on these questions about `Using()`. Also feedback from @stas and @alexanderad would be appreciated This has minimal code impact as `_execute()` seems to handle every edge case, whilst ensuring that queries are still executed in the correct database order (to the extent of all tests passing, there /might/ be untested edge cases). On the model there is now `determine_database`, by default uses the same SQL string inspection method as `read slave`, but in the event that users are making heavy use of raw queries with `IF()` conditionals, then they can extend to their hearts content. There is also now `get_read_database()` and `get_write_database()`, by default these continue to use `self._meta.database` but can be modified to whatever the user wants. The remaining problems now rests with `Using()`, as it does not support two database args. Altering the syntax with extra keywords would make it backwards incompatible, therefore I'd propose that we support the following syntax; ``` Using(database) Using((read_database, write_database)) ``` The last gotcha is whether `Using()` should override model, or visa versa. In my personal opinion, if someone has specified a `Using()` context then this should override whatever is in `get_read_database()` and `get_write_database()`. From what I can tell, this /should/ cover all use cases from #701.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/800/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/800/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/800", "html_url": "https://github.com/coleifer/peewee/pull/800", "diff_url": "https://github.com/coleifer/peewee/pull/800.diff", "patch_url": "https://github.com/coleifer/peewee/pull/800.patch", "merged_at": null }
https://api.github.com/repos/coleifer/peewee/issues/799
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/799/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/799/comments
https://api.github.com/repos/coleifer/peewee/issues/799/events
https://github.com/coleifer/peewee/issues/799
124,072,965
MDU6SXNzdWUxMjQwNzI5NjU=
799
Deprecation proposal for Proxy()
{ "login": "foxx", "id": 651797, "node_id": "MDQ6VXNlcjY1MTc5Nw==", "avatar_url": "https://avatars.githubusercontent.com/u/651797?v=4", "gravatar_id": "", "url": "https://api.github.com/users/foxx", "html_url": "https://github.com/foxx", "followers_url": "https://api.github.com/users/foxx/followers", "following_url": "https://api.github.com/users/foxx/following{/other_user}", "gists_url": "https://api.github.com/users/foxx/gists{/gist_id}", "starred_url": "https://api.github.com/users/foxx/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/foxx/subscriptions", "organizations_url": "https://api.github.com/users/foxx/orgs", "repos_url": "https://api.github.com/users/foxx/repos", "events_url": "https://api.github.com/users/foxx/events{/privacy}", "received_events_url": "https://api.github.com/users/foxx/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "The only legit use case I can think of is for circular foreign keys. Which are also a code smell...\n", "Ah I hadn't considered this. There are some legit situations where you might need circular foreign keys, for example a self relating [hierarchical table](http://stackoverflow.com/a/3891612/1267398) (with most other situations being an anti pattern). Are there any better ways that circular FK dependancies could be exposed? If not, then `Proxy` deprecation is probably a no-go.\n", "Hierarchical self references are already special cases through the use of\nForeignKeyField('self'). Also many to many junction tables when used with\nManyToManyField.\n\nHonestly, we probably can ditch it and add specific APIs for the valid use\ncases.\nOn Dec 28, 2015 8:32 AM, \"Cal Leeming\" [email protected] wrote:\n\n> Ah I hadn't considered this. There are some legit situations where you\n> might need circular foreign keys, for example a self relating hierarchical\n> table http://stackoverflow.com/a/3891612/1267398. Are there any better\n> ways that circular FK dependancies could be exposed? If not, then Proxy\n> deprecation is probably a no-go.\n> \n> —\n> Reply to this email directly or view it on GitHub\n> https://github.com/coleifer/peewee/issues/799#issuecomment-167581145.\n", "Oh beautiful, I didn't know Peewee had self-referential FKs. In that case, I'm +1 for deprecation.\n", "Alright, so places where `Proxy` is used in the code-base (or tests):\n1. To allow circular foreign key dependencies. Example would be `Tweet` has a foreign key to `User` to represent the user who created the tweet, and `User` has a foreign key to `Tweet` to represent the user's favorite tweet.\n2. To allow `ManyToManyField()` to reference a custom junction model that, by necessity, has to be defined after both models. This is similar to 1.\n3. To allow users to define a database object, reference it in their code, then dynamically assign at run-time. This occurs typically when a user wants to run with one database engine for tests, one for local dev, and one for prod.\n\nTo remove `Proxy` I'd like to have suitable replacements for these use-cases. Now, none of these are impossible without Proxy, proxy just makes them convenient and is used in the docs.\n\nPriority-wise, this is very low on my list, since any replacement will necessarily require tests and docs changes, and has potential negative impact on users.\n\nI think I'm going to close this for now and will reopen when I have some time.\n", "Okay sounds good, happy to help if needed. \n\nFor item 3, I've been able to achieve this behaviour easily without `Proxy()`, so I think this can be handled with a good docs example.\n", "Getting a start, added `DeferredRelation` for foreign keys, and `DeferredThroughModel` for many-to-many.\n", "I was thinking about it and while it's a kludge, I think a lot of people have a hard time structuring their code without the Proxy object as a stand-in for their database. I've made some changes, but am going to keep proxy as the recommended way for separating the definition of model classes from a database implementation.\n", "Sounds good, at least we now have `DeferredRelation` and `DeferredThroughModel` for encouraging a better paradigm.\n" ]
2015-12-28T14:16:09
2015-12-29T09:41:34
2015-12-29T03:18:26
CONTRIBUTOR
null
After reviewing docs and source code, it seems that `Proxy()` is somewhat of an anti-pattern, with most (if not all) edge cases handled by simply moving the database initialization routines before the model definitions. Are there any other edge cases that `Proxy()` solves a particular problem for? If not, I'd propose deprecation on the grounds of removing unnecessary complexity, both from the users code and peewee core. Thoughts @coleifer ?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/799/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/799/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/798
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/798/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/798/comments
https://api.github.com/repos/coleifer/peewee/issues/798/events
https://github.com/coleifer/peewee/issues/798
123,812,044
MDU6SXNzdWUxMjM4MTIwNDQ=
798
"'playhouse._speedups._ModelQueryResultWrapper' object has no attribute 'next'" with cython
{ "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
[ "Fixed.\n", "Thanks :)\n" ]
2015-12-24T15:12:29
2015-12-24T20:03:10
2015-12-24T19:38:56
CONTRIBUTOR
null
With latest master, using cython, doing a `User.select().where(User.id == 1).get()`: ``` def get(self): clone = self.paginate(1, 1) try: > return clone.execute().next() E AttributeError: 'playhouse._speedups._ModelQueryResultWrapper' object has no attribute 'next' ``` Does that ring a bell to you as is or should I investigate?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/798/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/798/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/797
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/797/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/797/comments
https://api.github.com/repos/coleifer/peewee/issues/797/events
https://github.com/coleifer/peewee/pull/797
123,638,860
MDExOlB1bGxSZXF1ZXN0NTQ0NTg1MDQ=
797
Fix PasswordField on postgres (fix #766)
{ "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
[ "@coleifer any feedback on this? :)\n", "LGTM. I haven't tested with Postgres, but the changes looks sane. Changing from BaseModel to TestModel allows it to be ran with `--engine postgres`, and changing from TextField to BlobField allows bytes to be stored safely. Needs sign off from @coleifer \n", "Thank you!\n" ]
2015-12-23T10:53:00
2015-12-29T09:25:49
2015-12-28T22:20:46
CONTRIBUTOR
null
Fix #766 This also makes the PasswordField tests to be ran with postgres.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/797/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/797/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/797", "html_url": "https://github.com/coleifer/peewee/pull/797", "diff_url": "https://github.com/coleifer/peewee/pull/797.diff", "patch_url": "https://github.com/coleifer/peewee/pull/797.patch", "merged_at": "2015-12-28T22:20:46" }
https://api.github.com/repos/coleifer/peewee/issues/796
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/796/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/796/comments
https://api.github.com/repos/coleifer/peewee/issues/796/events
https://github.com/coleifer/peewee/issues/796
122,953,641
MDU6SXNzdWUxMjI5NTM2NDE=
796
PostgresqlDatabase unable to connect with any database
{ "login": "davidthewatson", "id": 150892, "node_id": "MDQ6VXNlcjE1MDg5Mg==", "avatar_url": "https://avatars.githubusercontent.com/u/150892?v=4", "gravatar_id": "", "url": "https://api.github.com/users/davidthewatson", "html_url": "https://github.com/davidthewatson", "followers_url": "https://api.github.com/users/davidthewatson/followers", "following_url": "https://api.github.com/users/davidthewatson/following{/other_user}", "gists_url": "https://api.github.com/users/davidthewatson/gists{/gist_id}", "starred_url": "https://api.github.com/users/davidthewatson/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/davidthewatson/subscriptions", "organizations_url": "https://api.github.com/users/davidthewatson/orgs", "repos_url": "https://api.github.com/users/davidthewatson/repos", "events_url": "https://api.github.com/users/davidthewatson/events{/privacy}", "received_events_url": "https://api.github.com/users/davidthewatson/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "in case anyone else stumbles upon this combination (Heroku Postgres with peewee), the trick seems to be to parse the Heroku-provided URL first, and then provide the parsed components to the PostgresqlDatabase constructor. It looks like this:\r\n\r\n```python\r\nurl = urlparse.urlparse(os.environ[\"DATABASE_URL\"])\r\ndb = PostgresqlDatabase(database=url.path[1:], user=url.username, password=url.password, host=url.hostname, port=url.port)\r\n```\r\n\r\nSource:\r\nhttps://swifthorseman.com/2015/06/18/deploying-a-flask-app-with-peewee-to-heroku/", "Thanks @gregsadetsky " ]
2015-12-18T14:02:00
2020-12-29T10:19:06
2015-12-18T14:29:07
NONE
null
I have a project with a virtualenv running CPython 2.7 and a pip installed peewee. When I do: ``` psql_db = PostgresqlDatabase('postgres://me@localhost/whatever') psql_db.connect() ``` on a pre-existing database that has schema, tables, and rows of data, I get the following stacktrace: ``` Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Users/dwatson/Environments/sensor_data/lib/python2.7/site-packages/peewee.py", line 3296, in connect self.initialize_connection(self.__local.conn) File "/Users/dwatson/Environments/sensor_data/lib/python2.7/site-packages/peewee.py", line 3212, in __exit__ reraise(new_type, new_type(*exc_args), traceback) File "/Users/dwatson/Environments/sensor_data/lib/python2.7/site-packages/peewee.py", line 3294, in connect **self.connect_kwargs) File "/Users/dwatson/Environments/sensor_data/lib/python2.7/site-packages/peewee.py", line 3632, in _connect conn = psycopg2.connect(database=database, **kwargs) File "/Users/dwatson/Environments/sensor_data/lib/python2.7/site-packages/psycopg2/__init__.py", line 164, in connect conn = _connect(dsn, connection_factory=connection_factory, async=async) peewee.OperationalError: FATAL: database "postgres://me@localhost/whatever" does not exist ``` In the same virtualenv: ``` from postgres import Postgres db = Postgres("postgres://me@localhost/whatever") db.all('select * from some_table;') ``` And I get several thousand rows of data. I've tried all variants of Postgresql URI I could think of including password, port, etc. None of them will connect. I am using Heroku Postgres.app on Mac OS X 10.10 and I can telnet to localhost:5432 and get the postgres interface.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/796/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/796/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/795
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/795/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/795/comments
https://api.github.com/repos/coleifer/peewee/issues/795/events
https://github.com/coleifer/peewee/pull/795
122,771,988
MDExOlB1bGxSZXF1ZXN0NTM5OTk1MjQ=
795
Allow to pass ids to m2m.add and m2m.remove methods
{ "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 opted for a slightly different route for getting the ID list. Thanks for the diff.\n" ]
2015-12-17T16:37:30
2015-12-18T16:10:07
2015-12-18T16:09:47
CONTRIBUTOR
null
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/795/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/795/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/795", "html_url": "https://github.com/coleifer/peewee/pull/795", "diff_url": "https://github.com/coleifer/peewee/pull/795.diff", "patch_url": "https://github.com/coleifer/peewee/pull/795.patch", "merged_at": null }
https://api.github.com/repos/coleifer/peewee/issues/794
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/794/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/794/comments
https://api.github.com/repos/coleifer/peewee/issues/794/events
https://github.com/coleifer/peewee/issues/794
122,702,357
MDU6SXNzdWUxMjI3MDIzNTc=
794
ManyToManyField not in Model._meta.fields
{ "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
[ "ManyToManyField does not call `model_class.add_field`, so a \"solution\" may be to just add this to `ManyToManyField.add_to_class`:\n\n```\nmodel_class._meta.fields[name] = self\n```\n\n(It's not DRY, but we can't call `add_field` itself, because it expects the field to have a column, so maybe a bit of refactor is needed.)\n\nEdit: it crashes in `_fields_to_index` (`AttributeError: 'ManyToManyField' object has no attribute 'index'`), so certainly a filter needs to be added there.\n", "It's not technically a field, so it is not present in the field lists. It's just a descriptor that provides convenient access to the through table relationship.\n" ]
2015-12-17T10:07:33
2015-12-18T16:10:53
2015-12-18T16:10:53
CONTRIBUTOR
null
``` import peewee from playhouse.fields import ManyToManyField db = peewee.SqliteDatabase(':memory:') class Student(peewee.Model): name = peewee.CharField() class Meta: database = db class Course(peewee.Model): name = peewee.CharField() students = ManyToManyField(Student, related_name='courses') class Meta: database = db if __name__ == '__main__': assert 'name' in Course._meta.fields assert 'students' in Course._meta.fields ``` ``` $ python peewee_many2many.py Traceback (most recent call last): File "peewee_many2many.py", line 23, in <module> assert 'students' in Course._meta.fields AssertionError ``` Is that by design?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/794/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/794/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/793
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/793/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/793/comments
https://api.github.com/repos/coleifer/peewee/issues/793/events
https://github.com/coleifer/peewee/issues/793
122,698,959
MDU6SXNzdWUxMjI2OTg5NTk=
793
Delete/Update Many-to-Many tables
{ "login": "samsoft00", "id": 5300891, "node_id": "MDQ6VXNlcjUzMDA4OTE=", "avatar_url": "https://avatars.githubusercontent.com/u/5300891?v=4", "gravatar_id": "", "url": "https://api.github.com/users/samsoft00", "html_url": "https://github.com/samsoft00", "followers_url": "https://api.github.com/users/samsoft00/followers", "following_url": "https://api.github.com/users/samsoft00/following{/other_user}", "gists_url": "https://api.github.com/users/samsoft00/gists{/gist_id}", "starred_url": "https://api.github.com/users/samsoft00/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/samsoft00/subscriptions", "organizations_url": "https://api.github.com/users/samsoft00/orgs", "repos_url": "https://api.github.com/users/samsoft00/repos", "events_url": "https://api.github.com/users/samsoft00/events{/privacy}", "received_events_url": "https://api.github.com/users/samsoft00/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Wait... I'm confused by your code. You're doing a select? I think you copy/pasted wrong.\n\nThis is really not appropriate for github, please ask on stackoverflow.\n", "sorry for the mistake in updateEntries method, my intention was to delete all entries in Job table and everything that associate with it using this code \n\n```\nquery = models.Job.delete().where(models.Job.timestamp < datetime.date.today()-datetime.timedelta(days=2)) \nquery.execute()\n```\n\n but generate \n\n```\npeewee.IntegrityError: (1451, 'Cannot delete or update a parent row: a foreign key constraint fails (career.category_job_through, CONSTRAINT category_job_through_ibfk_2 FOREIGN KEY (job_id) REFERENCES job (id))')\n```\n\nwhat can i do?\n", "You need to first delete the rows from the through table that reference the job you're deleting.\n" ]
2015-12-17T09:47:51
2015-12-18T14:52:19
2015-12-18T00:26:40
NONE
null
@coleifer great job, kindly help... i'm having challenge deleting and updating many to many tables, below is the model and code ``` class Job(Model): """docstring for Jobs""" url = CharField(max_length=200, unique=True) title = TextField() description = TextField() sponsor = CharField(max_length=100) location = CharField(max_length=100) uuid = CharField(max_length=150) timestamp = DateTimeField(default=datetime.datetime.now) class Meta: database = DATABASE order_by = ('-timestamp',) class Category(Model): """docstring for JobCategory""" category = CharField(max_length=100, unique=True) cat_slug = TextField() jobs = ManyToManyField(Job, related_name='categories') class Meta: database = DATABASE JobsCategory = Category.jobs.get_through_model() ``` here is the method to delete queries, actually it work but it only delete a row, how can i delete multiple rows ``` def updateEntries(self): try: query = models.Job.select().where(models.Job.timestamp < datetime.date.today()-datetime.timedelta(days=2)): return jobs.execute() # Returns the number of rows deleted. delete_instance() except models.DoesNotExist: pass ``` Using the method below will raise error ``` query = models.Job.delete().where(models.Job.timestamp < datetime.date.today()-datetime.timedelta(days=2)) return query.execute() Error: peewee.IntegrityError: (1451, 'Cannot delete or update a parent row: a foreign key constraint fails (`career`.`category_job_through`, CONSTRAINT `category_job_through_ibfk_2` FOREIGN KEY (`job_id`) REFERENCES `job` (`id`))') ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/793/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/793/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/792
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/792/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/792/comments
https://api.github.com/repos/coleifer/peewee/issues/792/events
https://github.com/coleifer/peewee/issues/792
122,449,334
MDU6SXNzdWUxMjI0NDkzMzQ=
792
load csv into database - boolean values always convert to TRUE
{ "login": "adsahay", "id": 375799, "node_id": "MDQ6VXNlcjM3NTc5OQ==", "avatar_url": "https://avatars.githubusercontent.com/u/375799?v=4", "gravatar_id": "", "url": "https://api.github.com/users/adsahay", "html_url": "https://github.com/adsahay", "followers_url": "https://api.github.com/users/adsahay/followers", "following_url": "https://api.github.com/users/adsahay/following{/other_user}", "gists_url": "https://api.github.com/users/adsahay/gists{/gist_id}", "starred_url": "https://api.github.com/users/adsahay/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/adsahay/subscriptions", "organizations_url": "https://api.github.com/users/adsahay/orgs", "repos_url": "https://api.github.com/users/adsahay/repos", "events_url": "https://api.github.com/users/adsahay/events{/privacy}", "received_events_url": "https://api.github.com/users/adsahay/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "You need to probably specify a custom `RowConverter` and override the `Loader.get_converter` method to appropriately handle your CSV data.\n", "You can pass in a custom converter using the `converter` parameter.\n", "I am trying the following (no luck):\n\n```\n # use a custom RowConverter to handle boolean values, as it is not\n # handled out of the box.\n class CustomRowConverter(RowConverter):\n def field(field_class, **field_kwargs):\n def decorator(fn):\n fn.field = lambda: field_class(**field_kwargs)\n return fn\n\n return decorator\n\n @field(BooleanField, default=0)\n def is_boolean(self, value):\n # True if value is a boolean\n # ref: http://www.postgresql.org/docs/9.4/static/datatype-boolean.html\n print('is_boolean %s' % value)\n true_literals = ['TRUE', 't', 'true', 'y', 'yes', 'on', '1']\n false_literals = ['FALSE', 'f', 'false', 'n', 'no', 'off', '0']\n return value in true_literals or value in false_literals\n\n def get_checks(self):\n \"\"\"Return a list of functions to use when testing values.\"\"\"\n return [\n self.is_date, self.is_datetime, self.is_integer, self.is_float,\n self.is_boolean, self.default\n ]\n\n custom_converter = CustomRowConverter(database=database)\n try:\n load_csv(MyModel,\n 'file.csv',\n converter=custom_converter)\n except Exception as e:\n app.logger.error('Exception while loading csv %s - %s' %\n (e.__class__, e))\n```\n\nCan you please tell me where the problem is? I can't trigger the `is_boolean` check above.\n", "I put together a test-case and was able to verify that the custom converter could interpret a booleanfield. Maybe you can look at the new test-case and get some ideas on the implementation. It's a little bit of a crummy API, I definitely would like to take a crack at rewriting it in the future, but for now hopefully this helps.\n", "See: 58d0fcbb75faa6200ea63db11a4c43e304f39c73\n", "Thanks for this. I think if we supply a `model` instead of a `database` to the loader custom converter isn't working. \n" ]
2015-12-16T08:01:20
2015-12-24T07:51:13
2015-12-18T16:15:00
NONE
null
While loading a csv with a boolean field into a db table, the boolean value is always converting to `TRUE`. Please find reproducible test case on this [gist](https://gist.github.com/adsahay/38d73837beccd560ad66). Expected behaviour - `0` should map to `false`, `1` should map to `true`. I have tried using `t/f`, `TRUE/FALSE` and `0/1` in the csv.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/792/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/792/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/791
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/791/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/791/comments
https://api.github.com/repos/coleifer/peewee/issues/791/events
https://github.com/coleifer/peewee/issues/791
122,000,780
MDU6SXNzdWUxMjIwMDA3ODA=
791
Custom uint64 field and foreign keys
{ "login": "user5642", "id": 16286595, "node_id": "MDQ6VXNlcjE2Mjg2NTk1", "avatar_url": "https://avatars.githubusercontent.com/u/16286595?v=4", "gravatar_id": "", "url": "https://api.github.com/users/user5642", "html_url": "https://github.com/user5642", "followers_url": "https://api.github.com/users/user5642/followers", "following_url": "https://api.github.com/users/user5642/following{/other_user}", "gists_url": "https://api.github.com/users/user5642/gists{/gist_id}", "starred_url": "https://api.github.com/users/user5642/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/user5642/subscriptions", "organizations_url": "https://api.github.com/users/user5642/orgs", "repos_url": "https://api.github.com/users/user5642/repos", "events_url": "https://api.github.com/users/user5642/events{/privacy}", "received_events_url": "https://api.github.com/users/user5642/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "SQLite does not have a bigint type natively. Check out the sqlite docs on type affinities. Regarding the specific issue it sounds to me like it's coming from the SQLite driver and not peewee.\n", "Sorry it was not the best illustration of problem encountered by me. This code should be more demonstrative:\n\n```\nfrom peewee import *\n\ndb = SqliteDatabase('test.db')\n\nclass UInt32(Field):\n db_field = 'int'\n\n def db_value(self, value):\n return value - (1<<31)\n\n def python_value(self, value):\n return value + (1<<31)\n\nclass Foo(Model):\n id = UInt32(primary_key = True)\n\n class Meta:\n database = db\n\nclass Bar(Model):\n id = UInt32(primary_key = True)\n foo = ForeignKeyField(Foo, related_name='bars')\n\n class Meta:\n database = db\n\ndb.create_tables([Foo, Bar])\n\nf = Foo.create(id=(1<<31)+1000)\nBar.create(id=0, foo=f)\nb = Bar.get()\nb.foo\n```\n\nThis will fall with following error:\n\n```\n__main__.FooDoesNotExist: Instance matching query does not exist:\nSQL: SELECT \"t1\".\"id\" FROM \"foo\" AS t1 WHERE (\"t1\".\"id\" = ?)\nPARAMS: [-2147484648]\n```\n\nIt's clear that it tries to query for entry with id equal to 1000 - (1<<31) instead of 1000. So it's seems that peewee applies `db_value` where it should not. (or other way around not applying `python_value` where it should have)\n", "It applies db_value when sending values to the database. So technically it shouldn't be necessary to do the conversion yourself when calling create(), right?\n", "\"Python id\" is equal to (1<<31)+1000 = 2147484648 (I specially chose value outside of signed int32 range for demonstration purposes)\n\"Database id\" is equal to (1<<31)+1000 - (1<<31) = 1000 (record with such id is successfully created in DB)\nBut `b.foo` for some reason makes query for id -2147484648 = 1000 - (1<<31) , not for 1000 as it should have been.\n", "Maybe try this:\n\n``` python\nclass UInt32(Field):\n db_field = 'int'\n\n def db_value(self, value):\n return long(value - (1<<31))\n\n def python_value(self, value):\n return long(value + (1<<31))\n```\n", "Actually, I think you may be onto something, I'm looking into it.\n", "Alright, I believe the commit in 9e9e0bd should have things fixed.\n", "Now it works as expected.Thank you!\n" ]
2015-12-14T09:05:21
2016-01-08T03:35:59
2016-01-07T03:11:32
NONE
null
I needed uint64 field as primary key field for my database, expectedly other models used foreign key to point to this model. Resulting code was something like this: ``` from peewee import * db = SqliteDatabase('test.db') class UInt64(Field): db_field = 'bigint' def db_value(self, value): return value - (1<<63) def python_value(self, value): return value + (1<<63) class Foo(Model): id = UInt64(primary_key = True) class Meta: database = db class Bar(Model): id = UInt64(primary_key = True) foo = ForeignKeyField(Foo, related_name='bars') class Meta: database = db ``` This code works properly for all requests used by me expect one: ``` >>> f = Foo.create(id=10000) >>> Bar.create(id=123, foo=f) <ptest.Bar object at 0x7f2fde7f7e10> >>> b = Bar.get() >>> b.id 123 >>> b.foo Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/lib/python3.4/dist-packages/peewee.py", line 1151, in __get__ return self.get_object_or_id(instance) File "/usr/local/lib/python3.4/dist-packages/peewee.py", line 1142, in get_object_or_id obj = self.rel_model.get(self.field.to_field == rel_id) File "/usr/local/lib/python3.4/dist-packages/peewee.py", line 4403, in get return sq.get() File "/usr/local/lib/python3.4/dist-packages/peewee.py", line 2812, in get return clone.execute().next() File "/usr/local/lib/python3.4/dist-packages/peewee.py", line 2859, in execute self._qr = ResultWrapper(model_class, self._execute(), query_meta) File "/usr/local/lib/python3.4/dist-packages/peewee.py", line 2555, in _execute return self.database.execute_sql(sql, params, self.require_commit) File "/usr/local/lib/python3.4/dist-packages/peewee.py", line 3359, in execute_sql cursor.execute(sql, params or ()) OverflowError: Python int too large to convert to SQLite INTEGER ``` It seems that somewhere conversion between python value and db value was not done properly. Looks like a bug to me.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/791/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/791/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/790
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/790/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/790/comments
https://api.github.com/repos/coleifer/peewee/issues/790/events
https://github.com/coleifer/peewee/pull/790
121,535,007
MDExOlB1bGxSZXF1ZXN0NTMyODgyOTg=
790
Fixes #788
{ "login": "foxx", "id": 651797, "node_id": "MDQ6VXNlcjY1MTc5Nw==", "avatar_url": "https://avatars.githubusercontent.com/u/651797?v=4", "gravatar_id": "", "url": "https://api.github.com/users/foxx", "html_url": "https://github.com/foxx", "followers_url": "https://api.github.com/users/foxx/followers", "following_url": "https://api.github.com/users/foxx/following{/other_user}", "gists_url": "https://api.github.com/users/foxx/gists{/gist_id}", "starred_url": "https://api.github.com/users/foxx/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/foxx/subscriptions", "organizations_url": "https://api.github.com/users/foxx/orgs", "repos_url": "https://api.github.com/users/foxx/repos", "events_url": "https://api.github.com/users/foxx/events{/privacy}", "received_events_url": "https://api.github.com/users/foxx/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Sweet, thanks!\n" ]
2015-12-10T17:14:23
2015-12-10T17:49:01
2015-12-10T17:48:58
CONTRIBUTOR
null
Fixes #788
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/790/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/790/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/790", "html_url": "https://github.com/coleifer/peewee/pull/790", "diff_url": "https://github.com/coleifer/peewee/pull/790.diff", "patch_url": "https://github.com/coleifer/peewee/pull/790.patch", "merged_at": "2015-12-10T17:48:58" }
https://api.github.com/repos/coleifer/peewee/issues/789
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/789/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/789/comments
https://api.github.com/repos/coleifer/peewee/issues/789/events
https://github.com/coleifer/peewee/issues/789
121,043,664
MDU6SXNzdWUxMjEwNDM2NjQ=
789
More useful error classes
{ "login": "macks22", "id": 3409997, "node_id": "MDQ6VXNlcjM0MDk5OTc=", "avatar_url": "https://avatars.githubusercontent.com/u/3409997?v=4", "gravatar_id": "", "url": "https://api.github.com/users/macks22", "html_url": "https://github.com/macks22", "followers_url": "https://api.github.com/users/macks22/followers", "following_url": "https://api.github.com/users/macks22/following{/other_user}", "gists_url": "https://api.github.com/users/macks22/gists{/gist_id}", "starred_url": "https://api.github.com/users/macks22/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/macks22/subscriptions", "organizations_url": "https://api.github.com/users/macks22/orgs", "repos_url": "https://api.github.com/users/macks22/repos", "events_url": "https://api.github.com/users/macks22/events{/privacy}", "received_events_url": "https://api.github.com/users/macks22/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I think I will pass on this functionality.\n", "@macks22 but you know what key was passed to your function. Why not use it instead of taking this value from the exception? \n", "@arikfr that's basically what I was getting at...there's no new info there.\n", "Yes, this is what I ended up doing. I guess I just have a habit of packing as much info as possible into my exception instances. In this case it's not necessary though. Thanks for the quick feedback.\n" ]
2015-12-08T16:24:12
2015-12-10T12:28:14
2015-12-10T11:47:27
NONE
null
It would be useful to be able to access pieces of the sql query that raised the error. Right now this requires parsing the `message` instance variable of the error. For instance, assume I have some `Model` instance stored in a variable `table` and I run `Model.get` using a key that does not exist. This will raise a `Model.DoesNotExist` exception: ``` try: table.get(key = 'test') except table.DoesNotExist as err: print(dir(err)) ``` The output shows that only two instance variables are present: the standard `args` and `message`. The `message` is (table fields are "key" and "val"): ``` 'Instance matching query does not exist:\nSQL: SELECT "t1"."key", "t1"."val" FROM "keyvaluepair" AS t1 WHERE ("t1"."key" = ?)\nPARAMS: [u\'test2\']' ``` For this particular error, it would be nice to have another instance variable with the key. In general, it could be a `tuple` that contains all the parameters used to fill in the "?" placeholders in the query. Why would this be useful? Well in this case, I'm implementing a simple DB-backed dictionary. I'd like to except the `table.DoesNotExist` exception and repackage it as a `KeyError` to be raised up to the user. However, I don't know what key caused the error without parsing the `message` attribute.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/789/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/789/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/788
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/788/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/788/comments
https://api.github.com/repos/coleifer/peewee/issues/788/events
https://github.com/coleifer/peewee/issues/788
121,022,986
MDU6SXNzdWUxMjEwMjI5ODY=
788
Better support for UUIDField
{ "login": "foxx", "id": 651797, "node_id": "MDQ6VXNlcjY1MTc5Nw==", "avatar_url": "https://avatars.githubusercontent.com/u/651797?v=4", "gravatar_id": "", "url": "https://api.github.com/users/foxx", "html_url": "https://github.com/foxx", "followers_url": "https://api.github.com/users/foxx/followers", "following_url": "https://api.github.com/users/foxx/following{/other_user}", "gists_url": "https://api.github.com/users/foxx/gists{/gist_id}", "starred_url": "https://api.github.com/users/foxx/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/foxx/subscriptions", "organizations_url": "https://api.github.com/users/foxx/orgs", "repos_url": "https://api.github.com/users/foxx/repos", "events_url": "https://api.github.com/users/foxx/events{/privacy}", "received_events_url": "https://api.github.com/users/foxx/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Ahh yeah good call, and I should know cause I got bitten by just this issue.\n\nYeah a PR b great, thx\n", "Awesome, PR coming shortly :)\n", "Also there could be an argument for storing as `BINARY` instead of TEXT, but I'd need to think about the edge cases. I'll open a new issue if I can think of a compelling argument\n", "@coleifer Any idea when this fix will make it into next release? Just got stung by it again lol\n", "Ahh, dang have I not pushed a release? OK I'll get one out.\n", "PS - I'm not sure if you use MySQL/MariaDB but I had to modify the UUID type to VARCHAR(255) in order to get it working. Not sure if that matters, it was LONGTEXT before.\n", "Ah sorry that's my bad, although for indexing purposes it should probably be `CHAR(16)`. I've added `OptimizedUUIDField` and `BinaryUUIDField` into my `peewee-extras` repo, for anyone that wants to store UUIDs in MySQL on a larger scale. It'll be a couple of weeks before the repo is ready for prime time, as I haven't finished adding all the tests yet.\n", "PS @foxx you may want to add a LICENSE file to peewee-extras, as I'd like to maybe borrow some of those tidbits :)\n", "@coleifer Yup will do, in a few weeks it will be as clean as [bottlecap](https://github.com/foxx/bottlecap) (travis/coveralls/py2.7/py3.4/100% test coverage etc), will ping you when ready.\n" ]
2015-12-08T14:50:53
2016-01-13T18:31:28
2015-12-10T17:48:58
CONTRIBUTOR
null
As an extension from #780, databases which don't support UUID natively may encounter consistency problems. Postgres will correctly handle multiple input variants [[1]](http://www.postgresql.org/docs/9.1/static/datatype-uuid.html), such as `a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11` and `a0eebc999c0b4ef8bb6d6bb9bd380a11`. However SQLite, which now uses `TEXT` since #780, does not support multiple input types properly, and will end up with different variants being stored in the backend, rather than being normalised. Other databases, such as MySQL, are not supported at all as they don't have the necessary `field_overrides`. The most viable fix I can see for this would be; ``` py class UUIDField(Field): ... def db_value(self, value): if isinstance(value, uuid.UUID): return value.hex try: return uuid.UUID(value).hex except: return value ``` The above would ensure that the UUID output is always consistent, whilst also allowing non confirming values to be used with `filter()`, e.g. `0f0f0f0f-` I'd also like to propose that we add a `field_override` for `MySQLDatabase`, much the same as `SqliteDatabase`. If you're happy with the above solution, I'll throw up a PR, let me know
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/788/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/788/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/787
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/787/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/787/comments
https://api.github.com/repos/coleifer/peewee/issues/787/events
https://github.com/coleifer/peewee/issues/787
120,941,116
MDU6SXNzdWUxMjA5NDExMTY=
787
Is it possible to select table data when doing a multiple-join without mentioning every selected table?
{ "login": "perplexedfingers", "id": 14918698, "node_id": "MDQ6VXNlcjE0OTE4Njk4", "avatar_url": "https://avatars.githubusercontent.com/u/14918698?v=4", "gravatar_id": "", "url": "https://api.github.com/users/perplexedfingers", "html_url": "https://github.com/perplexedfingers", "followers_url": "https://api.github.com/users/perplexedfingers/followers", "following_url": "https://api.github.com/users/perplexedfingers/following{/other_user}", "gists_url": "https://api.github.com/users/perplexedfingers/gists{/gist_id}", "starred_url": "https://api.github.com/users/perplexedfingers/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/perplexedfingers/subscriptions", "organizations_url": "https://api.github.com/users/perplexedfingers/orgs", "repos_url": "https://api.github.com/users/perplexedfingers/repos", "events_url": "https://api.github.com/users/perplexedfingers/events{/privacy}", "received_events_url": "https://api.github.com/users/perplexedfingers/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "You have to join on permission since you're selecting from it. That will never change.\n\nIf you don't need the order by, why are you calling it? I'm confused why that's an issue.\n", "It requires an action after `join()`.\n", "I figure it out. Sorry about wasting your time.\n\n``` python\n(PermissionInGroup.select(Permission.name,\n Group.name,\n PermissionInGroup)\n .join(Permission)\n .switch(PermissionInGroup)\n .join(Group)\n .join(UserInGroup)\n .join(User)\n .where(User.ID == user_id,\n Group.app_account_id == app_account_id,\n Group.company_id == company_id)\n)\n```\n" ]
2015-12-08T06:22:16
2015-12-09T05:36:49
2015-12-09T05:34:45
NONE
null
The following query does _**not**_ work. ``` python (PermissionInGroup .select(PermissionInGroup, Permission, Group) .join(Group) .where(Group.app_account == app_account_id, Group.company_id == company_id) .join(UserInGroup) .join(User) .where(User.ID == user_id) ) ``` SQL statement would be like ``` sql SELECT "t1"."id", "t1"."permission_id", "t1"."group_id", "t5"."name", "t4"."primary_key", "t4"."name", "t4"."company_id", "t4"."app_account_id" FROM "permissioningroup" AS t1 INNER JOIN "group" AS t4 ON ("t1"."group_id" = "t4"."primary_key") INNER JOIN "useringroup" AS t2 ON ("t4"."primary_key" = "t2"."group_id") INNER JOIN "user" AS t3 ON ("t2"."user_id" = "t3"."ID") WHERE ((("t4"."app_account_id" = ?) AND ("t4"."company_id" = ?)) AND ("t3"."ID" = ?)) [722, 25, 32] ``` I will have this exception while trying to iterate over it ``` python peewee.OperationalError: no such column: t5.name ``` But this one works. ``` python (PermissionInGroup .select(PermissionInGroup, Permission, Group) .join(Group) .where(Group.app_account == app_account_id, Group.company_id == company_id) .join(UserInGroup) .join(User) .where(User.ID == user_id) ####### mark the difference .switch(PermissionInGroup) .join(Permission) .order_by(Permission.name) ####### ) ``` SQL statement ``` sql SELECT "t1"."id", "t1"."permission_id", "t1"."group_id", "t5"."name", "t4"."primary_key", "t4"."name", "t4"."company_id", "t4"."app_account_id" FROM "permissioningroup" AS t1 INNER JOIN "group" AS t4 ON ("t1"."group_id" = "t4"."primary_key") ####### mark the difference INNER JOIN "permission" AS t5 ON ("t1"."permission_id" = "t5"."name") ####### INNER JOIN "useringroup" AS t2 ON ("t4"."primary_key" = "t2"."group_id") INNER JOIN "user" AS t3 ON ("t2"."user_id" = "t3"."ID") WHERE ((("t4"."app_account_id" = ?) AND ("t4"."company_id" = ?)) AND ("t3"."ID" = ?)) ####### mark the difference ORDER BY "t5"."name" ####### [722, 25, 32] ``` Can I have a better way to do this query? I don't need to do `order_by`.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/787/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/787/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/786
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/786/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/786/comments
https://api.github.com/repos/coleifer/peewee/issues/786/events
https://github.com/coleifer/peewee/issues/786
120,881,234
MDU6SXNzdWUxMjA4ODEyMzQ=
786
Support for triggers in DDL
{ "login": "macks22", "id": 3409997, "node_id": "MDQ6VXNlcjM0MDk5OTc=", "avatar_url": "https://avatars.githubusercontent.com/u/3409997?v=4", "gravatar_id": "", "url": "https://api.github.com/users/macks22", "html_url": "https://github.com/macks22", "followers_url": "https://api.github.com/users/macks22/followers", "following_url": "https://api.github.com/users/macks22/following{/other_user}", "gists_url": "https://api.github.com/users/macks22/gists{/gist_id}", "starred_url": "https://api.github.com/users/macks22/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/macks22/subscriptions", "organizations_url": "https://api.github.com/users/macks22/orgs", "repos_url": "https://api.github.com/users/macks22/repos", "events_url": "https://api.github.com/users/macks22/events{/privacy}", "received_events_url": "https://api.github.com/users/macks22/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "You can use the fields constraints param to specify default values: DateTimeField(constraints=(SQL('default now'),))\n\nI do not plan on supporting triggers at this time.\n", "Got it; thanks for the constraints tip.\n" ]
2015-12-07T22:17:23
2015-12-09T13:43:19
2015-12-09T03:45:46
NONE
null
It would be very useful to be able to define triggers when using `create_table` to create database schemas. [I had this issue and came up with a very simple solution](http://stackoverflow.com/q/34142550/2486302). It fit my use case for a particular type of trigger using sqlite. However, based on my reading of the source, it didn't seem like supporting the full trigger API would be too difficult.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/786/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/786/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/785
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/785/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/785/comments
https://api.github.com/repos/coleifer/peewee/issues/785/events
https://github.com/coleifer/peewee/issues/785
120,547,615
MDU6SXNzdWUxMjA1NDc2MTU=
785
how to use "insert ignore" sql in peewee?
{ "login": "pc10201", "id": 8475089, "node_id": "MDQ6VXNlcjg0NzUwODk=", "avatar_url": "https://avatars.githubusercontent.com/u/8475089?v=4", "gravatar_id": "", "url": "https://api.github.com/users/pc10201", "html_url": "https://github.com/pc10201", "followers_url": "https://api.github.com/users/pc10201/followers", "following_url": "https://api.github.com/users/pc10201/following{/other_user}", "gists_url": "https://api.github.com/users/pc10201/gists{/gist_id}", "starred_url": "https://api.github.com/users/pc10201/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/pc10201/subscriptions", "organizations_url": "https://api.github.com/users/pc10201/orgs", "repos_url": "https://api.github.com/users/pc10201/repos", "events_url": "https://api.github.com/users/pc10201/events{/privacy}", "received_events_url": "https://api.github.com/users/pc10201/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "http://docs.peewee-orm.com/en/latest/peewee/api.html#InsertQuery.on_conflict\n\nPlease search the docs before posting tickets like this. Github tickets are more appropriate for **bugs**. If you have a question, post to stackoverflow, the mailing list, or the IRC channel. All of these are described in the documentation: http://docs.peewee-orm.com/en/latest/peewee/contributing.html\n" ]
2015-12-05T11:11:36
2015-12-05T15:47:02
2015-12-05T15:47:02
NONE
null
how to use "insert ignore" sql in peewee?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/785/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/785/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/784
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/784/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/784/comments
https://api.github.com/repos/coleifer/peewee/issues/784/events
https://github.com/coleifer/peewee/issues/784
120,540,718
MDU6SXNzdWUxMjA1NDA3MTg=
784
pwiz password
{ "login": "pc10201", "id": 8475089, "node_id": "MDQ6VXNlcjg0NzUwODk=", "avatar_url": "https://avatars.githubusercontent.com/u/8475089?v=4", "gravatar_id": "", "url": "https://api.github.com/users/pc10201", "html_url": "https://github.com/pc10201", "followers_url": "https://api.github.com/users/pc10201/followers", "following_url": "https://api.github.com/users/pc10201/following{/other_user}", "gists_url": "https://api.github.com/users/pc10201/gists{/gist_id}", "starred_url": "https://api.github.com/users/pc10201/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/pc10201/subscriptions", "organizations_url": "https://api.github.com/users/pc10201/orgs", "repos_url": "https://api.github.com/users/pc10201/repos", "events_url": "https://api.github.com/users/pc10201/events{/privacy}", "received_events_url": "https://api.github.com/users/pc10201/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "The idea is that it is bad practice to accept passwords on the command-line, since they get written to your bash history, etc.\n", "So you specify `-P`, then when prompted you enter your password in.\n", "Interesting that you chose not to accept the passwords on the command line which is an explicit choice that the end user makes, however the pwiz tool itself _echos the password into the console or is piped into the file you store the models in without explicitly telling the user that their password is going to get written_. This has led me to accidentally commit a password into a repo. You should be able to specify os.env variables to retrieve the passwords in the generated files, or else find some other paradigm to set the database on the BaseModel.", "> This has led me to accidentally commit a password into a repo.\r\n\r\nWhoops, I can add a note to the docs that the password will be outputted as a connection parameter.\r\n\r\nAs far as using an environment variable, just modify the generated code to do what you want it to.", "I am using peewee in a containerized project. There is a console program that manages the project, and I just want to run pwiz in a container where my python backend lives to get an updated schema from the database when developers change it.\r\n\r\nAll the database credentials are env variables inside the container, and this is a standard practice. We are working with dev environment with pwiz, as expected.\r\n\r\nInstead of simply running something like\r\n\r\n`docker exec <CONTAINER_ID> 'python -m pwiz -H $DBHOST -p $DBPORT -u $DBUSER -p $DBPASSWORD -e postgresql $DBNAME'`\r\n\r\nI have to ask for password or have to write an expect script just because there is no way for pwiz to accept a password non-interactively.\r\n\r\nThis is to show that enforcing users to enter password from the terminal is a flawed practice, and this is an issue we are facing with this tool, otherwise excellent. Maybe you reconsider your policy, thanks!\r\n", "`pwiz` is not typically something intended for use outside of interactive sessions, since it is really just a generator for skeleton code. You could, for your purposes, probably just look at the code inside pwiz's main and write your own short script." ]
2015-12-05T08:35:01
2021-07-19T12:47:23
2015-12-05T15:43:40
NONE
null
when I run ``` python -m pwiz --host=127.0.0.1 --port=3306 --user=root --password=root -e mysql forex ``` result ``` Usage: pwiz.py [options] database_name pwiz.py: error: --password option does not take a value ``` when I run ``` python -m pwiz --host=127.0.0.1 --port=3306 --user=root -P root -e mysql forex ``` result ``` Password: ``` It need to input password again.Why?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/784/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/784/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/783
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/783/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/783/comments
https://api.github.com/repos/coleifer/peewee/issues/783/events
https://github.com/coleifer/peewee/issues/783
120,407,308
MDU6SXNzdWUxMjA0MDczMDg=
783
RetryOperationalError mixin failing on retry w/ error 2006
{ "login": "bakemecookies", "id": 2167033, "node_id": "MDQ6VXNlcjIxNjcwMzM=", "avatar_url": "https://avatars.githubusercontent.com/u/2167033?v=4", "gravatar_id": "", "url": "https://api.github.com/users/bakemecookies", "html_url": "https://github.com/bakemecookies", "followers_url": "https://api.github.com/users/bakemecookies/followers", "following_url": "https://api.github.com/users/bakemecookies/following{/other_user}", "gists_url": "https://api.github.com/users/bakemecookies/gists{/gist_id}", "starred_url": "https://api.github.com/users/bakemecookies/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/bakemecookies/subscriptions", "organizations_url": "https://api.github.com/users/bakemecookies/orgs", "repos_url": "https://api.github.com/users/bakemecookies/repos", "events_url": "https://api.github.com/users/bakemecookies/events{/privacy}", "received_events_url": "https://api.github.com/users/bakemecookies/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Unfortunately, I don't think I will be going back to the \"sql error handler\" API. I think the implementation in the `RetryOperationalError` mixin is an appropriate way to try to handle re-connect/re-try logic. Maybe you can make some changes to your pool implementation, particularly overriding the `_is_closed()` method to perform some sort of test to check that the conn is really active. Take a look at the pool module's code, particularly the `PooledMySQLDatabase._is_closed()` method...I bet you can find something that'll work for you.\n" ]
2015-12-04T14:01:18
2015-12-06T02:47:53
2015-12-06T02:47:53
CONTRIBUTOR
null
Tried using the new RetryOperationalError mixin and although it's reaching the exception block properly (known because it's going to shortcuts.py, line 208, execute_sql), the retry fails and raises the same error. My hunch is that since we're using PooledMySQLDatabase, could it be that we're closing one stale connection but just getting another stale one on the retry? Not that it's necessarily a solution, but in the past we've used a combo of sql_error_handler to close stale connections and recursion on execute_sql (i.e., infinite retry only in the case of 2006 errors, as opposed to the single retry in RetryOperationalError) within its exception block to handle this.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/783/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/783/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/782
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/782/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/782/comments
https://api.github.com/repos/coleifer/peewee/issues/782/events
https://github.com/coleifer/peewee/pull/782
120,316,770
MDExOlB1bGxSZXF1ZXN0NTI2MjE3NzA=
782
Fix constaints typo
{ "login": "xr09", "id": 1380243, "node_id": "MDQ6VXNlcjEzODAyNDM=", "avatar_url": "https://avatars.githubusercontent.com/u/1380243?v=4", "gravatar_id": "", "url": "https://api.github.com/users/xr09", "html_url": "https://github.com/xr09", "followers_url": "https://api.github.com/users/xr09/followers", "following_url": "https://api.github.com/users/xr09/following{/other_user}", "gists_url": "https://api.github.com/users/xr09/gists{/gist_id}", "starred_url": "https://api.github.com/users/xr09/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/xr09/subscriptions", "organizations_url": "https://api.github.com/users/xr09/orgs", "repos_url": "https://api.github.com/users/xr09/repos", "events_url": "https://api.github.com/users/xr09/events{/privacy}", "received_events_url": "https://api.github.com/users/xr09/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Thnx\n" ]
2015-12-04T02:14:41
2015-12-04T02:53:11
2015-12-04T02:53:09
CONTRIBUTOR
null
Fix constaints typo
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/782/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/782/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/782", "html_url": "https://github.com/coleifer/peewee/pull/782", "diff_url": "https://github.com/coleifer/peewee/pull/782.diff", "patch_url": "https://github.com/coleifer/peewee/pull/782.patch", "merged_at": "2015-12-04T02:53:09" }
https://api.github.com/repos/coleifer/peewee/issues/781
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/781/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/781/comments
https://api.github.com/repos/coleifer/peewee/issues/781/events
https://github.com/coleifer/peewee/issues/781
120,275,463
MDU6SXNzdWUxMjAyNzU0NjM=
781
provide an entry_point for third party drivers
{ "login": "mfussenegger", "id": 38700, "node_id": "MDQ6VXNlcjM4NzAw", "avatar_url": "https://avatars.githubusercontent.com/u/38700?v=4", "gravatar_id": "", "url": "https://api.github.com/users/mfussenegger", "html_url": "https://github.com/mfussenegger", "followers_url": "https://api.github.com/users/mfussenegger/followers", "following_url": "https://api.github.com/users/mfussenegger/following{/other_user}", "gists_url": "https://api.github.com/users/mfussenegger/gists{/gist_id}", "starred_url": "https://api.github.com/users/mfussenegger/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/mfussenegger/subscriptions", "organizations_url": "https://api.github.com/users/mfussenegger/orgs", "repos_url": "https://api.github.com/users/mfussenegger/repos", "events_url": "https://api.github.com/users/mfussenegger/events{/privacy}", "received_events_url": "https://api.github.com/users/mfussenegger/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[]
2015-12-03T21:36:30
2015-12-03T22:37:51
2015-12-03T22:37:51
NONE
null
As far as I can see there is currently no way for a third party Database drivers to hook into peewees db_url functionality. It would be great if there was an extension mechanism, maybe similar to how SQLAlchemy does it (see http://sqlalchemy.readthedocs.org/en/latest/core/connections.html#registering-new-dialects) so that a user can install a third party driver via pip install and then use that in his application without changing any line of code except the db uri.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/781/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/781/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/780
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/780/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/780/comments
https://api.github.com/repos/coleifer/peewee/issues/780/events
https://github.com/coleifer/peewee/issues/780
120,197,953
MDU6SXNzdWUxMjAxOTc5NTM=
780
Support for UUID in Sqlite3
{ "login": "foxx", "id": 651797, "node_id": "MDQ6VXNlcjY1MTc5Nw==", "avatar_url": "https://avatars.githubusercontent.com/u/651797?v=4", "gravatar_id": "", "url": "https://api.github.com/users/foxx", "html_url": "https://github.com/foxx", "followers_url": "https://api.github.com/users/foxx/followers", "following_url": "https://api.github.com/users/foxx/following{/other_user}", "gists_url": "https://api.github.com/users/foxx/gists{/gist_id}", "starred_url": "https://api.github.com/users/foxx/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/foxx/subscriptions", "organizations_url": "https://api.github.com/users/foxx/orgs", "repos_url": "https://api.github.com/users/foxx/repos", "events_url": "https://api.github.com/users/foxx/events{/privacy}", "received_events_url": "https://api.github.com/users/foxx/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "LGTM, you're too fast!!\n" ]
2015-12-03T15:34:38
2015-12-04T13:07:56
2015-12-03T22:30:27
CONTRIBUTOR
null
As per the docs, UUID is not natively supported in Sqlite3, resulting in an error when you try and use it; ``` File "/home/vagrant/.virtualenvs/vagrant/lib/python3.4/site-packages/peewee.py", line 1824, in inner return self.parse_node(fn(*args, **kwargs)) File "/home/vagrant/.virtualenvs/vagrant/lib/python3.4/site-packages/peewee.py", line 1852, in _create_table columns.append(self.field_definition(field)) File "/home/vagrant/.virtualenvs/vagrant/lib/python3.4/site-packages/peewee.py", line 1802, in field_definition column_type = self.get_column_type(field.get_db_field()) File "/home/vagrant/.virtualenvs/vagrant/lib/python3.4/site-packages/peewee.py", line 1431, in get_column_type return self._field_map[f] KeyError: 'uuid' ``` This can be easily added by using a `VARCHAR` instead, sure it's not a native column but at least we get something rather than nothing. Therefore I'd like to propose adding a field mapping into Sqlite3 for 'uuid=VARCHAR'. If I submit a PR, would this be accepted @coleifer? In the mean time, I was able to get this working with a monkey patch; ``` overrides = peewee.SqliteDatabase.field_overrides.copy() overrides['uuid'] = 'VARCHAR' peewee.SqliteDatabase.field_overrides = overrides ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/780/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/780/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/779
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/779/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/779/comments
https://api.github.com/repos/coleifer/peewee/issues/779/events
https://github.com/coleifer/peewee/issues/779
119,948,634
MDU6SXNzdWUxMTk5NDg2MzQ=
779
MyModel.DoesNotExist throws TypeError: exceptions must derive from BaseException
{ "login": "amorphic", "id": 1538480, "node_id": "MDQ6VXNlcjE1Mzg0ODA=", "avatar_url": "https://avatars.githubusercontent.com/u/1538480?v=4", "gravatar_id": "", "url": "https://api.github.com/users/amorphic", "html_url": "https://github.com/amorphic", "followers_url": "https://api.github.com/users/amorphic/followers", "following_url": "https://api.github.com/users/amorphic/following{/other_user}", "gists_url": "https://api.github.com/users/amorphic/gists{/gist_id}", "starred_url": "https://api.github.com/users/amorphic/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/amorphic/subscriptions", "organizations_url": "https://api.github.com/users/amorphic/orgs", "repos_url": "https://api.github.com/users/amorphic/repos", "events_url": "https://api.github.com/users/amorphic/events{/privacy}", "received_events_url": "https://api.github.com/users/amorphic/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Apologies... this had absolutely nothing to do with peewee.\n", "What was the actual problem? I have a similar error.\n", "I honestly can't remember but I was doing something stupid which was unrelated to peewee.\n\nThe module I was working on is [here](https://github.com/re-3D/opengb/blob/master/opengb/database.py) in case it's useful.\n" ]
2015-12-02T14:08:35
2016-01-14T01:22:14
2015-12-02T14:48:44
NONE
null
Using Python 3.4.0 and Peewee 2.7.3 I am attempting to handle the case where MyModel.get() returns no results as [described in the docs](http://docs.peewee-orm.com/en/latest/peewee/api.html#Model.get). Something like: ``` try: user = User.get(User.username == 'charlie') except User.DoesNotExist: print "No user found" ``` However this results in: `TypeError: exceptions must derive from BaseException`.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/779/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/779/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/778
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/778/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/778/comments
https://api.github.com/repos/coleifer/peewee/issues/778/events
https://github.com/coleifer/peewee/issues/778
119,807,280
MDU6SXNzdWUxMTk4MDcyODA=
778
Deadlock restart
{ "login": "ccario83", "id": 3374143, "node_id": "MDQ6VXNlcjMzNzQxNDM=", "avatar_url": "https://avatars.githubusercontent.com/u/3374143?v=4", "gravatar_id": "", "url": "https://api.github.com/users/ccario83", "html_url": "https://github.com/ccario83", "followers_url": "https://api.github.com/users/ccario83/followers", "following_url": "https://api.github.com/users/ccario83/following{/other_user}", "gists_url": "https://api.github.com/users/ccario83/gists{/gist_id}", "starred_url": "https://api.github.com/users/ccario83/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/ccario83/subscriptions", "organizations_url": "https://api.github.com/users/ccario83/orgs", "repos_url": "https://api.github.com/users/ccario83/repos", "events_url": "https://api.github.com/users/ccario83/events{/privacy}", "received_events_url": "https://api.github.com/users/ccario83/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "> But wouldn't this sort of boilerplate code be better included in peewee itself?\n\nNot in my opinion, no. There are far too many things involved for me to feel comfortable implementing a canonical / library solution to the problem of deadlocks.\n", "@lucidv01d Did you implement some generic(ish) retry logic or how did you end up tackling it?" ]
2015-12-01T21:02:20
2017-02-06T10:38:26
2015-12-01T22:13:34
NONE
null
I'm running a multi-threaded app with many threads read/writing a central database at the same time. I've wrapped my queries in transactions and have tried to limit their sizes to prevent too many rows from being locked at the same time. However, I still occasionally get **deadlocks**: `peewee.InternalError: (1213, u'Deadlock found when trying to get lock; try restarting transaction')` Peewee recommends large bulk inserts as a performance improvement which is contrary to the deadlock solution. The obvious answer to my problem is to **catch this exception and retry the transaction**, which I will do. But wouldn't this sort of boilerplate code be better included **in peewee** itself? Can a feature be added where peewee will automatically retry a deadlocked transaction after waiting a brief amount of time? This feature could be disabled by default if not recommended as best practice, though a lot of mysql newbies would appreciate this sort of thing being handled for them behind the scenes.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/778/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/778/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/777
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/777/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/777/comments
https://api.github.com/repos/coleifer/peewee/issues/777/events
https://github.com/coleifer/peewee/issues/777
119,705,229
MDU6SXNzdWUxMTk3MDUyMjk=
777
Aliased column is not converted to attribute when selected as alias as a part of join
{ "login": "alexanderad", "id": 888394, "node_id": "MDQ6VXNlcjg4ODM5NA==", "avatar_url": "https://avatars.githubusercontent.com/u/888394?v=4", "gravatar_id": "", "url": "https://api.github.com/users/alexanderad", "html_url": "https://github.com/alexanderad", "followers_url": "https://api.github.com/users/alexanderad/followers", "following_url": "https://api.github.com/users/alexanderad/following{/other_user}", "gists_url": "https://api.github.com/users/alexanderad/gists{/gist_id}", "starred_url": "https://api.github.com/users/alexanderad/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/alexanderad/subscriptions", "organizations_url": "https://api.github.com/users/alexanderad/orgs", "repos_url": "https://api.github.com/users/alexanderad/repos", "events_url": "https://api.github.com/users/alexanderad/events{/privacy}", "received_events_url": "https://api.github.com/users/alexanderad/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Ah, `naive()` can help. Sorry.\n" ]
2015-12-01T12:18:43
2015-12-01T12:23:54
2015-12-01T12:23:54
NONE
null
``` python class User(Model): ... # it works in this way for user in User.select(User, User.id.alias('some_alias_name'): print user.some_alias_name # it does not in this way for user in User.select(User, Group.id.alias('group_id')).join(Group): print user.group_id # AttributeError # however for user_dict in User.select(User, Group.id.alias('group_id')).join(Group).dicts(): print 'group_id' in user_dict # True ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/777/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/777/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/776
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/776/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/776/comments
https://api.github.com/repos/coleifer/peewee/issues/776/events
https://github.com/coleifer/peewee/issues/776
119,674,987
MDU6SXNzdWUxMTk2NzQ5ODc=
776
Question: ability to implicitly select joined model instance
{ "login": "alexanderad", "id": 888394, "node_id": "MDQ6VXNlcjg4ODM5NA==", "avatar_url": "https://avatars.githubusercontent.com/u/888394?v=4", "gravatar_id": "", "url": "https://api.github.com/users/alexanderad", "html_url": "https://github.com/alexanderad", "followers_url": "https://api.github.com/users/alexanderad/followers", "following_url": "https://api.github.com/users/alexanderad/following{/other_user}", "gists_url": "https://api.github.com/users/alexanderad/gists{/gist_id}", "starred_url": "https://api.github.com/users/alexanderad/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/alexanderad/subscriptions", "organizations_url": "https://api.github.com/users/alexanderad/orgs", "repos_url": "https://api.github.com/users/alexanderad/repos", "events_url": "https://api.github.com/users/alexanderad/events{/privacy}", "received_events_url": "https://api.github.com/users/alexanderad/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "It seems pretty straightforward to me:\n\n``` python\nIn [15]: with assert_query_count(1):\n ....: q = User.select(User, Group).join(Group)\n ....: for user in q:\n ....: print user.username, user.group.name\n ....: \n... prints users and groups ...\n```\n" ]
2015-12-01T09:26:28
2015-12-01T14:44:20
2015-12-01T14:44:20
NONE
null
Given two tables ``` python class User(Model): ... class Group(Model): user = FK(User) ``` and database contains ``` python user1 = User() group1 = Group(user=user1) group2 = Group(user=user1) ``` Is there any way to select group related instance (resolved automatically if any) as a part of `selection`? ``` python for user in User.select().join(Group): print user.group ``` I know model aliases are used differently but I imagine this could be something like `User.select(Group.alias('group')).join(Group)`
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/776/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/776/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/775
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/775/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/775/comments
https://api.github.com/repos/coleifer/peewee/issues/775/events
https://github.com/coleifer/peewee/pull/775
119,575,101
MDExOlB1bGxSZXF1ZXN0NTIxNzUxNTE=
775
prefetch() now loads all foreign keys to given table
{ "login": "hedger", "id": 277532, "node_id": "MDQ6VXNlcjI3NzUzMg==", "avatar_url": "https://avatars.githubusercontent.com/u/277532?v=4", "gravatar_id": "", "url": "https://api.github.com/users/hedger", "html_url": "https://github.com/hedger", "followers_url": "https://api.github.com/users/hedger/followers", "following_url": "https://api.github.com/users/hedger/following{/other_user}", "gists_url": "https://api.github.com/users/hedger/gists{/gist_id}", "starred_url": "https://api.github.com/users/hedger/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/hedger/subscriptions", "organizations_url": "https://api.github.com/users/hedger/orgs", "repos_url": "https://api.github.com/users/hedger/repos", "events_url": "https://api.github.com/users/hedger/events{/privacy}", "received_events_url": "https://api.github.com/users/hedger/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Yay, all checks have passed.\n", "I've pushed a branch that has some of your changes integrated, 89cd2c4f74a526591f3804d04b2252c489be5432\n", "That's great, thanks!\n", "Pushed 2f028c32225c5aad9b97f0f451b9d238c3846e0d to the `multiprefetch` branch. Things aren't working quite right in the test-case. I think the identity map needs to differentiate things by field, but haven't dug into it too much yet.\n", "Got things fixed and have merged into master.\n" ]
2015-11-30T20:32:26
2015-12-02T04:39:00
2015-12-02T04:39:00
NONE
null
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/775/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/775/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/775", "html_url": "https://github.com/coleifer/peewee/pull/775", "diff_url": "https://github.com/coleifer/peewee/pull/775.diff", "patch_url": "https://github.com/coleifer/peewee/pull/775.patch", "merged_at": null }
https://api.github.com/repos/coleifer/peewee/issues/774
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/774/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/774/comments
https://api.github.com/repos/coleifer/peewee/issues/774/events
https://github.com/coleifer/peewee/issues/774
119,487,952
MDU6SXNzdWUxMTk0ODc5NTI=
774
prefetch() only loads the first ForeignKeyField of given type
{ "login": "hedger", "id": 277532, "node_id": "MDQ6VXNlcjI3NzUzMg==", "avatar_url": "https://avatars.githubusercontent.com/u/277532?v=4", "gravatar_id": "", "url": "https://api.github.com/users/hedger", "html_url": "https://github.com/hedger", "followers_url": "https://api.github.com/users/hedger/followers", "following_url": "https://api.github.com/users/hedger/following{/other_user}", "gists_url": "https://api.github.com/users/hedger/gists{/gist_id}", "starred_url": "https://api.github.com/users/hedger/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/hedger/subscriptions", "organizations_url": "https://api.github.com/users/hedger/orgs", "repos_url": "https://api.github.com/users/hedger/repos", "events_url": "https://api.github.com/users/hedger/events{/privacy}", "received_events_url": "https://api.github.com/users/hedger/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Tried to fix that, https://github.com/coleifer/peewee/pull/775.\nTested on some backrefs in my project. Still needs more testing.\n", "Fix merged.\n" ]
2015-11-30T13:05:01
2015-12-02T04:39:12
2015-12-02T04:39:12
NONE
null
``` class M1(Model): i1 = IntegerField() ... class M2(Model): i2 = IntegerField() f1 = ForeignKeyField(M1, related_name='origin') f2 = ForeignKeyField(M1, related_name='target') ... ``` In this example, `prefetch(M2.select().where(M2.i2>10), M1)` only fetches `f1` entries. `f2` is loaded with separate queries when iterating over results, since `rel_for_model` in `prefetch_add_subquery` returns single (first) foreign key of given type.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/774/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/774/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/773
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/773/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/773/comments
https://api.github.com/repos/coleifer/peewee/issues/773/events
https://github.com/coleifer/peewee/issues/773
119,362,733
MDU6SXNzdWUxMTkzNjI3MzM=
773
Adding request hooks to pyramid
{ "login": "perplexedfingers", "id": 14918698, "node_id": "MDQ6VXNlcjE0OTE4Njk4", "avatar_url": "https://avatars.githubusercontent.com/u/14918698?v=4", "gravatar_id": "", "url": "https://api.github.com/users/perplexedfingers", "html_url": "https://github.com/perplexedfingers", "followers_url": "https://api.github.com/users/perplexedfingers/followers", "following_url": "https://api.github.com/users/perplexedfingers/following{/other_user}", "gists_url": "https://api.github.com/users/perplexedfingers/gists{/gist_id}", "starred_url": "https://api.github.com/users/perplexedfingers/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/perplexedfingers/subscriptions", "organizations_url": "https://api.github.com/users/perplexedfingers/orgs", "repos_url": "https://api.github.com/users/perplexedfingers/repos", "events_url": "https://api.github.com/users/perplexedfingers/events{/privacy}", "received_events_url": "https://api.github.com/users/perplexedfingers/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Sure thanks!\n" ]
2015-11-29T14:33:02
2015-11-29T16:37:09
2015-11-29T16:37:09
NONE
null
Although there is already [pyramid_peewee](https://pypi.python.org/pypi/pyramid_peewee), I think it would be great to mention about the possibility to use peewee along with pyramid in the document.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/773/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/773/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/772
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/772/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/772/comments
https://api.github.com/repos/coleifer/peewee/issues/772/events
https://github.com/coleifer/peewee/issues/772
119,353,422
MDU6SXNzdWUxMTkzNTM0MjI=
772
Full migration framework
{ "login": "mekanix", "id": 610855, "node_id": "MDQ6VXNlcjYxMDg1NQ==", "avatar_url": "https://avatars.githubusercontent.com/u/610855?v=4", "gravatar_id": "", "url": "https://api.github.com/users/mekanix", "html_url": "https://github.com/mekanix", "followers_url": "https://api.github.com/users/mekanix/followers", "following_url": "https://api.github.com/users/mekanix/following{/other_user}", "gists_url": "https://api.github.com/users/mekanix/gists{/gist_id}", "starred_url": "https://api.github.com/users/mekanix/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/mekanix/subscriptions", "organizations_url": "https://api.github.com/users/mekanix/orgs", "repos_url": "https://api.github.com/users/mekanix/repos", "events_url": "https://api.github.com/users/mekanix/events{/privacy}", "received_events_url": "https://api.github.com/users/mekanix/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "@mekanix -- https://github.com/cam-stitt/arnold is one such project I'm aware of. I don't have plans for adding anything more than what is already present in the `playhouse.migrate` module. Perhaps you can bring this up on the mailing list? https://groups.google.com/group/peewee-orm\n" ]
2015-11-29T11:14:58
2015-11-29T16:35:14
2015-11-29T16:35:14
NONE
null
In short, if anyone is working on full fledged migration framework, I'd like to contribute. If nobody is working on it, I'd like to do it. Any pointers on how to contribute/implement migrations ala Django (or maybe something better?) are welcome.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/772/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/772/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/771
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/771/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/771/comments
https://api.github.com/repos/coleifer/peewee/issues/771/events
https://github.com/coleifer/peewee/issues/771
119,250,552
MDU6SXNzdWUxMTkyNTA1NTI=
771
apsw driver rejecting datetime object
{ "login": "rlander", "id": 368935, "node_id": "MDQ6VXNlcjM2ODkzNQ==", "avatar_url": "https://avatars.githubusercontent.com/u/368935?v=4", "gravatar_id": "", "url": "https://api.github.com/users/rlander", "html_url": "https://github.com/rlander", "followers_url": "https://api.github.com/users/rlander/followers", "following_url": "https://api.github.com/users/rlander/following{/other_user}", "gists_url": "https://api.github.com/users/rlander/gists{/gist_id}", "starred_url": "https://api.github.com/users/rlander/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/rlander/subscriptions", "organizations_url": "https://api.github.com/users/rlander/orgs", "repos_url": "https://api.github.com/users/rlander/repos", "events_url": "https://api.github.com/users/rlander/events{/privacy}", "received_events_url": "https://api.github.com/users/rlander/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "```\nPython version: 2.7.9\nSqlite version: 3.9.2\n\npeewee==2.7.3\napsw==3.9.2-r1\n\n\n```\n", "You need to use the `DateTimeField` object from the `apsw_ext` module.\n\n``` python\nfrom playhouse.apsw_ext import DateTimeField\n```\n" ]
2015-11-27T21:37:39
2015-11-29T16:29:55
2015-11-29T16:29:55
NONE
null
I have a model that looks like this: ``` python class Log(Model): name = CharField() platform = CharField(null=True) language = CharField(null=True) created = DateTimeField(default=datetime.datetime.now) ``` When I try to insert a new record ``` python Log.create(name=agent.name, platform=agent.platform, language=agent.language) ``` I get the following error: ``` bash File "/Users/rlander/.pythonbrew/venvs/Python-2.7.9/app/lib/python2.7/site-packages/playhouse/apsw_ext.py", line 95, in _execute_sql cursor.execute(sql, params or ()) TypeError: Bad binding argument type supplied - argument #7: type datetime.datetime ``` When I remove the "created" field from the Log class or use the default sqlite driver, I get no errors.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/771/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/771/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/770
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/770/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/770/comments
https://api.github.com/repos/coleifer/peewee/issues/770/events
https://github.com/coleifer/peewee/issues/770
119,017,544
MDU6SXNzdWUxMTkwMTc1NDQ=
770
Migrator freezes
{ "login": "JornPet", "id": 9035151, "node_id": "MDQ6VXNlcjkwMzUxNTE=", "avatar_url": "https://avatars.githubusercontent.com/u/9035151?v=4", "gravatar_id": "", "url": "https://api.github.com/users/JornPet", "html_url": "https://github.com/JornPet", "followers_url": "https://api.github.com/users/JornPet/followers", "following_url": "https://api.github.com/users/JornPet/following{/other_user}", "gists_url": "https://api.github.com/users/JornPet/gists{/gist_id}", "starred_url": "https://api.github.com/users/JornPet/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/JornPet/subscriptions", "organizations_url": "https://api.github.com/users/JornPet/orgs", "repos_url": "https://api.github.com/users/JornPet/repos", "events_url": "https://api.github.com/users/JornPet/events{/privacy}", "received_events_url": "https://api.github.com/users/JornPet/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I'm not sure, maybe something holding a lock on the table? Are any other processes connected to the db?\n", "Closing due to lack of feedback.\n" ]
2015-11-26T10:43:26
2015-12-01T14:46:44
2015-12-01T14:46:44
NONE
null
I'm trying to migrate a database using the peewee migrator. I added a column to a table the migrator worked and updated the table. No problem. I then tried to remove the column again, but in the process it totally froze. I let it run for about 10 minutes, but nothing happened. So I quit it, and dropped and created the database again. After that I tried the upgrade again with the exact same code I used before, but unfortunately it now also freezes. When i quit the process i get this stack trace: ``` Traceback (most recent call last): File "./migrate_db.py", line 145, in <module> migrateDatabase() File "./migrate_db.py", line 116, in migrateDatabase migrations[i]['up']() File "./migrate_db.py", line 81, in from9To10 migrate(migrator.add_column('ticket', 'ticket_code_doc_id', Ticket.ticket_code_doc_id)) File "/usr/local/lib/python2.7/dist-packages/playhouse/migrate.py", line 579, in migrate operation.run() File "/usr/local/lib/python2.7/dist-packages/playhouse/migrate.py", line 144, in run getattr(self.migrator, self.method)(*self.args, **kwargs)) File "/usr/local/lib/python2.7/dist-packages/playhouse/migrate.py", line 138, in _handle_result self._handle_result(item) File "/usr/local/lib/python2.7/dist-packages/playhouse/migrate.py", line 135, in _handle_result result.run() File "/usr/local/lib/python2.7/dist-packages/playhouse/migrate.py", line 144, in run getattr(self.migrator, self.method)(*self.args, **kwargs)) File "/usr/local/lib/python2.7/dist-packages/playhouse/migrate.py", line 133, in _handle_result self.execute(result) File "/usr/local/lib/python2.7/dist-packages/playhouse/migrate.py", line 129, in execute self.migrator.database.execute_sql(sql, params) File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 3331, in execute_sql cursor.execute(sql, params or ()) File "/usr/local/lib/python2.7/dist-packages/pymysql/cursors.py", line 146, in execute result = self._query(query) File "/usr/local/lib/python2.7/dist-packages/pymysql/cursors.py", line 296, in _query conn.query(q) File "/usr/local/lib/python2.7/dist-packages/pymysql/connections.py", line 781, in query self._affected_rows = self._read_query_result(unbuffered=unbuffered) File "/usr/local/lib/python2.7/dist-packages/pymysql/connections.py", line 942, in _read_query_result result.read() File "/usr/local/lib/python2.7/dist-packages/pymysql/connections.py", line 1138, in read first_packet = self.connection._read_packet() File "/usr/local/lib/python2.7/dist-packages/pymysql/connections.py", line 895, in _read_packet packet_header = self._read_bytes(4) File "/usr/local/lib/python2.7/dist-packages/pymysql/connections.py", line 912, in _read_bytes data = self._rfile.read(num_bytes) File "/usr/local/lib/python2.7/dist-packages/pymysql/_socketio.py", line 59, in readinto return self._sock.recv_into(b) KeyboardInterrupt ``` Does anybody know what's going on here? All tips are welcome!
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/770/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/770/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/769
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/769/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/769/comments
https://api.github.com/repos/coleifer/peewee/issues/769/events
https://github.com/coleifer/peewee/issues/769
118,729,714
MDU6SXNzdWUxMTg3Mjk3MTQ=
769
Unexpected parentheses required when using multiple WHERE conditions
{ "login": "martinburch", "id": 2335284, "node_id": "MDQ6VXNlcjIzMzUyODQ=", "avatar_url": "https://avatars.githubusercontent.com/u/2335284?v=4", "gravatar_id": "", "url": "https://api.github.com/users/martinburch", "html_url": "https://github.com/martinburch", "followers_url": "https://api.github.com/users/martinburch/followers", "following_url": "https://api.github.com/users/martinburch/following{/other_user}", "gists_url": "https://api.github.com/users/martinburch/gists{/gist_id}", "starred_url": "https://api.github.com/users/martinburch/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/martinburch/subscriptions", "organizations_url": "https://api.github.com/users/martinburch/orgs", "repos_url": "https://api.github.com/users/martinburch/repos", "events_url": "https://api.github.com/users/martinburch/events{/privacy}", "received_events_url": "https://api.github.com/users/martinburch/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Peewee leans on pythons parser to generate expressions. Because of pythons operator precedence you need parentheses around most comparisons. No magic here, just python.\n", "And yet I can do this without needed extra parens:\n\n```\n.where(\n (modelObject.field_name << ['a','b','c'] |\n modelObject.field_name % \"%word%\")\n )\n```\n\nSeems inconsistent. I think this needs to be explained in the docs. At least \"you should use parentheses around all comparisons, just to be safe.\" But a list of situations would be ideal.\n", "What do you suggest? Best practice is just put parentheses around binary expressions, then you won't have any issues.\n", "You can created the equivalent expressions by calling the appropriate doubles underscore method on the field object. You can also instantiate expression objects by hand.\n", "The use of parentheses in your python code won't affect the SQL being generated, improves readability for complex, mutli-clause queries (as I typically assume you line-break each expression), and leaves no room for error.\n\nhttp://docs.peewee-orm.com/en/latest/peewee/querying.html?highlight=precedence#expressions\n", "Sorry, I think you've already got a note in the docs to this effect.\n\n> Note that the actual comparisons are wrapped in parentheses. Python’s operator precedence necessitates that comparisons be wrapped in parentheses.\n\nThanks for your additional thoughts on this solidly closed issue.\n" ]
2015-11-24T23:59:39
2015-11-25T06:30:23
2015-11-25T00:51:29
NONE
null
I would expect to be able to write: ``` where( ( modelObject.field_name.is_null(True) | modelObject.field_name == "" ) ) ``` but I must add parentheses around `modelObject.field_name == ""` or the query will be generated improperly. The improperly generated query is essentially ``` WHERE `t1`.`field_name` IS NULL = '' ``` which is exactly the opposite of what I want, returning all records that are not null. For more discussion, please see: http://stackoverflow.com/questions/33905987/why-is-peewee-not-nesting-this-where-clause-correctly/33906132
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/769/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/769/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/768
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/768/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/768/comments
https://api.github.com/repos/coleifer/peewee/issues/768/events
https://github.com/coleifer/peewee/pull/768
118,367,801
MDExOlB1bGxSZXF1ZXN0NTE1MTUzNTA=
768
Fix _SortedFieldList, Model._meta.remove_field
{ "login": "klen", "id": 90699, "node_id": "MDQ6VXNlcjkwNjk5", "avatar_url": "https://avatars.githubusercontent.com/u/90699?v=4", "gravatar_id": "", "url": "https://api.github.com/users/klen", "html_url": "https://github.com/klen", "followers_url": "https://api.github.com/users/klen/followers", "following_url": "https://api.github.com/users/klen/following{/other_user}", "gists_url": "https://api.github.com/users/klen/gists{/gist_id}", "starred_url": "https://api.github.com/users/klen/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/klen/subscriptions", "organizations_url": "https://api.github.com/users/klen/orgs", "repos_url": "https://api.github.com/users/klen/repos", "events_url": "https://api.github.com/users/klen/events{/privacy}", "received_events_url": "https://api.github.com/users/klen/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Thank you!\n" ]
2015-11-23T12:06:17
2015-12-01T15:08:52
2015-12-01T15:08:48
CONTRIBUTOR
null
Hello, the last release has broken migrations, because `Model._meta.remove_fields` actually doesn't work. The PR fixes it. I'm waiting for your response and new release.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/768/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/768/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/768", "html_url": "https://github.com/coleifer/peewee/pull/768", "diff_url": "https://github.com/coleifer/peewee/pull/768.diff", "patch_url": "https://github.com/coleifer/peewee/pull/768.patch", "merged_at": "2015-12-01T15:08:48" }
https://api.github.com/repos/coleifer/peewee/issues/767
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/767/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/767/comments
https://api.github.com/repos/coleifer/peewee/issues/767/events
https://github.com/coleifer/peewee/issues/767
118,233,745
MDU6SXNzdWUxMTgyMzM3NDU=
767
Test failures in 2.7.3
{ "login": "felixonmars", "id": 1006477, "node_id": "MDQ6VXNlcjEwMDY0Nzc=", "avatar_url": "https://avatars.githubusercontent.com/u/1006477?v=4", "gravatar_id": "", "url": "https://api.github.com/users/felixonmars", "html_url": "https://github.com/felixonmars", "followers_url": "https://api.github.com/users/felixonmars/followers", "following_url": "https://api.github.com/users/felixonmars/following{/other_user}", "gists_url": "https://api.github.com/users/felixonmars/gists{/gist_id}", "starred_url": "https://api.github.com/users/felixonmars/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/felixonmars/subscriptions", "organizations_url": "https://api.github.com/users/felixonmars/orgs", "repos_url": "https://api.github.com/users/felixonmars/repos", "events_url": "https://api.github.com/users/felixonmars/events{/privacy}", "received_events_url": "https://api.github.com/users/felixonmars/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Looks like you're missing the JSON1 extension. I'll add a conditional.\n" ]
2015-11-22T02:04:51
2015-11-24T15:11:35
2015-11-22T02:20:36
CONTRIBUTOR
null
Hi, I am getting the following failures in 2.7.3, and they are not present in previous versions: ``` ====================================================================== ERROR: test_children (playhouse.tests.test_sqlite_ext.TestJSONField) ---------------------------------------------------------------------- Traceback (most recent call last): File "/build/python-peewee/src/peewee/peewee.py", line 3359, in execute_sql cursor.execute(sql, params or ()) sqlite3.OperationalError: no such table: json_each During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/build/python-peewee/src/peewee/playhouse/tests/test_sqlite_ext.py", line 328, in test_children self.assertEqual([row for row, in query], [ File "/build/python-peewee/src/peewee/peewee.py", line 2866, in __iter__ return iter(self.execute()) File "/build/python-peewee/src/peewee/peewee.py", line 2859, in execute self._qr = ResultWrapper(model_class, self._execute(), query_meta) File "/build/python-peewee/src/peewee/peewee.py", line 2555, in _execute return self.database.execute_sql(sql, params, self.require_commit) File "/build/python-peewee/src/peewee/peewee.py", line 3366, in execute_sql self.commit() File "/build/python-peewee/src/peewee/peewee.py", line 3212, in __exit__ reraise(new_type, new_type(*exc_args), traceback) File "/build/python-peewee/src/peewee/peewee.py", line 125, in reraise raise value.with_traceback(tb) File "/build/python-peewee/src/peewee/peewee.py", line 3359, in execute_sql cursor.execute(sql, params or ()) peewee.OperationalError: no such table: json_each ====================================================================== ERROR: test_extract (playhouse.tests.test_sqlite_ext.TestJSONField) ---------------------------------------------------------------------- Traceback (most recent call last): File "/build/python-peewee/src/peewee/peewee.py", line 3359, in execute_sql cursor.execute(sql, params or ()) sqlite3.OperationalError: no such function: json_extract During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/build/python-peewee/src/peewee/playhouse/tests/test_sqlite_ext.py", line 197, in test_extract self.assertEqual([row for row, in titles], [ File "/build/python-peewee/src/peewee/peewee.py", line 2866, in __iter__ return iter(self.execute()) File "/build/python-peewee/src/peewee/peewee.py", line 2859, in execute self._qr = ResultWrapper(model_class, self._execute(), query_meta) File "/build/python-peewee/src/peewee/peewee.py", line 2555, in _execute return self.database.execute_sql(sql, params, self.require_commit) File "/build/python-peewee/src/peewee/peewee.py", line 3366, in execute_sql self.commit() File "/build/python-peewee/src/peewee/peewee.py", line 3212, in __exit__ reraise(new_type, new_type(*exc_args), traceback) File "/build/python-peewee/src/peewee/peewee.py", line 125, in reraise raise value.with_traceback(tb) File "/build/python-peewee/src/peewee/peewee.py", line 3359, in execute_sql cursor.execute(sql, params or ()) peewee.OperationalError: no such function: json_extract ====================================================================== ERROR: test_length (playhouse.tests.test_sqlite_ext.TestJSONField) ---------------------------------------------------------------------- Traceback (most recent call last): File "/build/python-peewee/src/peewee/peewee.py", line 3359, in execute_sql cursor.execute(sql, params or ()) sqlite3.OperationalError: no such function: json_array_length During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/build/python-peewee/src/peewee/playhouse/tests/test_sqlite_ext.py", line 223, in test_length self.assertEqual(list(tag_len), [ File "/build/python-peewee/src/peewee/peewee.py", line 2866, in __iter__ return iter(self.execute()) File "/build/python-peewee/src/peewee/peewee.py", line 2859, in execute self._qr = ResultWrapper(model_class, self._execute(), query_meta) File "/build/python-peewee/src/peewee/peewee.py", line 2555, in _execute return self.database.execute_sql(sql, params, self.require_commit) File "/build/python-peewee/src/peewee/peewee.py", line 3366, in execute_sql self.commit() File "/build/python-peewee/src/peewee/peewee.py", line 3212, in __exit__ reraise(new_type, new_type(*exc_args), traceback) File "/build/python-peewee/src/peewee/peewee.py", line 125, in reraise raise value.with_traceback(tb) File "/build/python-peewee/src/peewee/peewee.py", line 3359, in execute_sql cursor.execute(sql, params or ()) peewee.OperationalError: no such function: json_array_length ====================================================================== ERROR: test_multi_set (playhouse.tests.test_sqlite_ext.TestJSONField) ---------------------------------------------------------------------- Traceback (most recent call last): File "/build/python-peewee/src/peewee/peewee.py", line 3359, in execute_sql cursor.execute(sql, params or ()) sqlite3.OperationalError: no such function: json_set During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/build/python-peewee/src/peewee/playhouse/tests/test_sqlite_ext.py", line 305, in test_multi_set .where(APIData.value.contains('LSM Storage')) File "/build/python-peewee/src/peewee/peewee.py", line 3013, in execute return self.database.rows_affected(self._execute()) File "/build/python-peewee/src/peewee/peewee.py", line 2555, in _execute return self.database.execute_sql(sql, params, self.require_commit) File "/build/python-peewee/src/peewee/peewee.py", line 3366, in execute_sql self.commit() File "/build/python-peewee/src/peewee/peewee.py", line 3212, in __exit__ reraise(new_type, new_type(*exc_args), traceback) File "/build/python-peewee/src/peewee/peewee.py", line 125, in reraise raise value.with_traceback(tb) File "/build/python-peewee/src/peewee/peewee.py", line 3359, in execute_sql cursor.execute(sql, params or ()) peewee.OperationalError: no such function: json_set ====================================================================== ERROR: test_remove (playhouse.tests.test_sqlite_ext.TestJSONField) ---------------------------------------------------------------------- Traceback (most recent call last): File "/build/python-peewee/src/peewee/peewee.py", line 3359, in execute_sql cursor.execute(sql, params or ()) sqlite3.OperationalError: no such function: json_remove During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/build/python-peewee/src/peewee/playhouse/tests/test_sqlite_ext.py", line 238, in test_remove self.assertEqual([row for row, in query], ['{}'] * 5) File "/build/python-peewee/src/peewee/peewee.py", line 2866, in __iter__ return iter(self.execute()) File "/build/python-peewee/src/peewee/peewee.py", line 2859, in execute self._qr = ResultWrapper(model_class, self._execute(), query_meta) File "/build/python-peewee/src/peewee/peewee.py", line 2555, in _execute return self.database.execute_sql(sql, params, self.require_commit) File "/build/python-peewee/src/peewee/peewee.py", line 3366, in execute_sql self.commit() File "/build/python-peewee/src/peewee/peewee.py", line 3212, in __exit__ reraise(new_type, new_type(*exc_args), traceback) File "/build/python-peewee/src/peewee/peewee.py", line 125, in reraise raise value.with_traceback(tb) File "/build/python-peewee/src/peewee/peewee.py", line 3359, in execute_sql cursor.execute(sql, params or ()) peewee.OperationalError: no such function: json_remove ====================================================================== ERROR: test_set (playhouse.tests.test_sqlite_ext.TestJSONField) ---------------------------------------------------------------------- Traceback (most recent call last): File "/build/python-peewee/src/peewee/peewee.py", line 3359, in execute_sql cursor.execute(sql, params or ()) sqlite3.OperationalError: no such function: json_set During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/build/python-peewee/src/peewee/playhouse/tests/test_sqlite_ext.py", line 273, in test_set [json.loads(row) for row, in query], File "/build/python-peewee/src/peewee/peewee.py", line 2866, in __iter__ return iter(self.execute()) File "/build/python-peewee/src/peewee/peewee.py", line 2859, in execute self._qr = ResultWrapper(model_class, self._execute(), query_meta) File "/build/python-peewee/src/peewee/peewee.py", line 2555, in _execute return self.database.execute_sql(sql, params, self.require_commit) File "/build/python-peewee/src/peewee/peewee.py", line 3366, in execute_sql self.commit() File "/build/python-peewee/src/peewee/peewee.py", line 3212, in __exit__ reraise(new_type, new_type(*exc_args), traceback) File "/build/python-peewee/src/peewee/peewee.py", line 125, in reraise raise value.with_traceback(tb) File "/build/python-peewee/src/peewee/peewee.py", line 3359, in execute_sql cursor.execute(sql, params or ()) peewee.OperationalError: no such function: json_set ---------------------------------------------------------------------- Ran 496 tests in 526.219s FAILED (errors=6) ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/767/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/767/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/766
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/766/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/766/comments
https://api.github.com/repos/coleifer/peewee/issues/766/events
https://github.com/coleifer/peewee/issues/766
118,223,951
MDU6SXNzdWUxMTgyMjM5NTE=
766
PasswordField does not seem to work with Postgres
{ "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
[ "Thanks :)\n", "Same code, with updated peewee:\n\n```\nTraceback (most recent call last):\n File \"peewee_password_field.py\", line 19, in <module>\n assert user.password.check_password('password')\n File \"/home/ybon/.virtualenvs/p3/local/lib/python3.4/site-packages/playhouse/fields.py\", line 47, in check_password\n return hashpw(password, self) == self\n File \"/home/ybon/.virtualenvs/p3/local/lib/python3.4/site-packages/bcrypt/__init__.py\", line 66, in hashpw\n raise ValueError(\"Invalid salt\")\nValueError: Invalid salt\n```\n\nMissing unittests in Postgres? :)\n", "(I can't reopen the issue, dunno why…)\n", "I'm not sure what's going on exactly. Having trouble getting `bcrypt` to build in a python3 virtualenv but testing locally with python2+sqlite is working fine. What is the salt of the particular password you're having trouble with, and what is it's type?\n", "Thanks for looking into this @coleifer :)\n\nI'm just running the snippet from https://github.com/coleifer/peewee/issues/766#issue-118223951 (I'm on IRC if it helps debugging).\n", "This diff fixes my usecase:\n\n``` diff\ndiff --git a/playhouse/fields.py b/playhouse/fields.py\nindex fcebae7..bfa2d90 100644\n--- a/playhouse/fields.py\n+++ b/playhouse/fields.py\n@@ -47,7 +47,7 @@ if hashpw and gensalt:\n return hashpw(password, self) == self\n\n\n- class PasswordField(TextField):\n+ class PasswordField(BlobField):\n def __init__(self, iterations=12, *args, **kwargs):\n if None in (hashpw, gensalt):\n raise ValueError('Missing library required for PasswordField: bcrypt')\n```\n\nBasically, the issue seems to be that we are sending bytes to a Text field in Postgres.\nNot sure though why tests passe without this change (they also pass with the fix)…\n", "Ah, now I know why tests passe even without the fix: they are never ran with postgres…\nEven if I pass `--engine postgres`, simply because the Model used in the tests only use \"in memory database\": https://github.com/coleifer/peewee/blob/master/playhouse/tests/test_extra_fields.py#L22\n\nIs there a reason for that?\n" ]
2015-11-21T22:06:24
2015-12-28T22:20:46
2015-12-28T22:20:46
CONTRIBUTOR
null
``` python import peewee from playhouse.fields import PasswordField db = peewee.PostgresqlDatabase('peewee') class User(peewee.Model): username = peewee.CharField(max_length=10) password = PasswordField() class Meta: database = db if __name__ == '__main__': User.create_table() user = User.create(username='yo', password='password') user = User.get(User.id == user.id) assert user.password.check_password('password') ``` Fails with this traceback: ``` Traceback (most recent call last): File "peewee_password_field.py", line 22, in <module> user = User.get(User.id == user.id) File "/home/ybon/.virtualenvs/ban/lib/python3.4/site-packages/peewee.py", line 4393, in get return sq.get() File "/home/ybon/.virtualenvs/ban/lib/python3.4/site-packages/peewee.py", line 2812, in get return clone.execute().next() File "/home/ybon/.virtualenvs/ban/lib/python3.4/site-packages/peewee.py", line 2029, in next obj = self.iterate() File "/home/ybon/.virtualenvs/ban/lib/python3.4/site-packages/peewee.py", line 2015, in iterate return self.process_row(row) File "/home/ybon/.virtualenvs/ban/lib/python3.4/site-packages/peewee.py", line 2090, in process_row setattr(instance, column, func(row[i])) File "/home/ybon/.virtualenvs/ban/lib/python3.4/site-packages/playhouse/fields.py", line 66, in python_value return PasswordHash(value) TypeError: string argument without an encoding ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/766/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/766/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/765
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/765/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/765/comments
https://api.github.com/repos/coleifer/peewee/issues/765/events
https://github.com/coleifer/peewee/issues/765
118,172,423
MDU6SXNzdWUxMTgxNzI0MjM=
765
AttributeError: 'ModelOptions' object has no attribute 'get_sorted_fields'
{ "login": "pawl", "id": 992533, "node_id": "MDQ6VXNlcjk5MjUzMw==", "avatar_url": "https://avatars.githubusercontent.com/u/992533?v=4", "gravatar_id": "", "url": "https://api.github.com/users/pawl", "html_url": "https://github.com/pawl", "followers_url": "https://api.github.com/users/pawl/followers", "following_url": "https://api.github.com/users/pawl/following{/other_user}", "gists_url": "https://api.github.com/users/pawl/gists{/gist_id}", "starred_url": "https://api.github.com/users/pawl/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/pawl/subscriptions", "organizations_url": "https://api.github.com/users/pawl/orgs", "repos_url": "https://api.github.com/users/pawl/repos", "events_url": "https://api.github.com/users/pawl/events{/privacy}", "received_events_url": "https://api.github.com/users/pawl/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I'd look into updating the code to use `.sorted_fields`. there is also `.sorted_field_names`. This is a performance improvement, as that code had potential to be called a _lot_.\n", "@rudyryk has a good suggestion here for a temporary solution: https://github.com/flask-admin/flask-admin/issues/1117\n\n```\n for n, f in zip(model._meta.sorted_field_names,\n model._meta.sorted_fields):\n```\n", "Folks, I'm still getting this error.\r\n\r\nTraceback:\r\n```\r\n File \"app.py\", line 30, in <module>\r\n admin.add_view(ModelView(database.Comic))\r\n File \"/usr/local/lib/python3.5/dist-packages/flask_admin/contrib/peewee/view.py\", line 144, in __init__\r\n menu_icon_value=menu_icon_value)\r\n File \"/usr/local/lib/python3.5/dist-packages/flask_admin/model/base.py\", line 584, in __init__\r\n self._refresh_cache()\r\n File \"/usr/local/lib/python3.5/dist-packages/flask_admin/model/base.py\", line 653, in _refresh_cache\r\n self._list_columns = self.get_list_columns()\r\n File \"/usr/local/lib/python3.5/dist-packages/flask_admin/model/base.py\", line 729, in get_list_columns\r\n columns = self.scaffold_list_columns()\r\n File \"/usr/local/lib/python3.5/dist-packages/flask_admin/contrib/peewee/view.py\", line 163, in scaffold_list_columns\r\n for n, f in self._get_model_fields():\r\n File \"/usr/local/lib/python3.5/dist-packages/flask_admin/contrib/peewee/view.py\", line 152, in _get_model_fields\r\n return model._meta.get_sorted_fields()\r\nAttributeError: 'ModelOptions' object has no attribute 'get_sorted_fields'\r\n```\r\n\r\nVersions:\r\n```\r\nFlask==0.12.2\r\nFlask-Admin==1.1.0\r\npeewee==2.10.1\r\nwtf-peewee==0.2.6\r\n```\r\n\r\nWhat is going on?\r\n\r\n\r\n" ]
2015-11-21T05:40:25
2017-08-22T14:51:18
2015-11-22T02:42:30
NONE
null
I noticed `get_sorted_fields()`, `get_field_names()`, and `get_fields()` were removed by these commits: https://github.com/coleifer/peewee/commit/2619fcc12b01e34933861de51918507d118655c4 and https://github.com/coleifer/peewee/commit/50c9c1dd24b7a4c48a396a9f5e88f3ea1647859a It's causing some flask-admin tests to fail, with this error: ``` AttributeError: 'ModelOptions' object has no attribute 'get_sorted_fields' ``` What's the most backwards compatible replacement for get_sorted_fields()? model._meta.sorted_fields?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/765/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/765/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/764
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/764/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/764/comments
https://api.github.com/repos/coleifer/peewee/issues/764/events
https://github.com/coleifer/peewee/issues/764
118,169,295
MDU6SXNzdWUxMTgxNjkyOTU=
764
make code more beautiful
{ "login": "olivetree123", "id": 5275647, "node_id": "MDQ6VXNlcjUyNzU2NDc=", "avatar_url": "https://avatars.githubusercontent.com/u/5275647?v=4", "gravatar_id": "", "url": "https://api.github.com/users/olivetree123", "html_url": "https://github.com/olivetree123", "followers_url": "https://api.github.com/users/olivetree123/followers", "following_url": "https://api.github.com/users/olivetree123/following{/other_user}", "gists_url": "https://api.github.com/users/olivetree123/gists{/gist_id}", "starred_url": "https://api.github.com/users/olivetree123/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/olivetree123/subscriptions", "organizations_url": "https://api.github.com/users/olivetree123/orgs", "repos_url": "https://api.github.com/users/olivetree123/repos", "events_url": "https://api.github.com/users/olivetree123/events{/privacy}", "received_events_url": "https://api.github.com/users/olivetree123/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "No, that has been that way since version 0.1.0. Are you serious? Do you think I'd actually change it?\n", "Also, cluttering up the namespace is grosser to me.\n", "Also bite me.\n" ]
2015-11-21T04:25:33
2016-01-14T04:56:14
2015-11-21T04:27:06
NONE
null
The 'Meta class' makes code ugly,would you prepare to make code like this: class Gym(Model): **db_table** = 'gym' id = IntegerField(primary_key=True)
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/764/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/764/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/763
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/763/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/763/comments
https://api.github.com/repos/coleifer/peewee/issues/763/events
https://github.com/coleifer/peewee/issues/763
118,148,213
MDU6SXNzdWUxMTgxNDgyMTM=
763
Fail to install peewee under WinPython
{ "login": "mindv0rtex", "id": 10409817, "node_id": "MDQ6VXNlcjEwNDA5ODE3", "avatar_url": "https://avatars.githubusercontent.com/u/10409817?v=4", "gravatar_id": "", "url": "https://api.github.com/users/mindv0rtex", "html_url": "https://github.com/mindv0rtex", "followers_url": "https://api.github.com/users/mindv0rtex/followers", "following_url": "https://api.github.com/users/mindv0rtex/following{/other_user}", "gists_url": "https://api.github.com/users/mindv0rtex/gists{/gist_id}", "starred_url": "https://api.github.com/users/mindv0rtex/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/mindv0rtex/subscriptions", "organizations_url": "https://api.github.com/users/mindv0rtex/orgs", "repos_url": "https://api.github.com/users/mindv0rtex/repos", "events_url": "https://api.github.com/users/mindv0rtex/events{/privacy}", "received_events_url": "https://api.github.com/users/mindv0rtex/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Hmm, well this isn't exactly a solution, but I've released a new versoin 2.7.2 that does not build SQLite extension by default.\n\nIf you want the sqlite extension it should be built using `python setup.py build_sqlite_ext`.\n\nI will look into checking the python version and renaming the entry-point per the stackoverflow answer. (`PyInit__sqlite_ext`).\n\nFuck python 3 and it's stupid ass changes.\n", "FWIW, I confirm that I could successfully perform the `python setup.py build_sqlite_ext` under WinPython 2, so this indeed looks like a Python 3 issue.\n", "Some issues with the `_sqlite_ext` extension:\n1. On Python 3, the extension module fails to link. The module's init function is actually named `PyInit__sqlite_ext`, not [`init_sqlite_ext`](https://github.com/coleifer/peewee/blob/master/playhouse/_sqlite_ext.pyx#L289)\n2. On Python 3 for Windows, the [`sqlite3_sqliteext_init`](https://github.com/coleifer/peewee/blob/master/playhouse/_sqlite_ext.pyx#L283) function is not exported from the module. I think this is a Cython bug.\n3. On Windows, the [`load_extension`](https://github.com/coleifer/peewee/blob/master/playhouse/sqlite_ext.py#L711) function fails to load the `_sqlite_ext` module because the file extension of the Python extension module is `.pyd`, not `.dll`. Also, on Python 3.5, the name of the Python extension is `_sqlite_ext.cp35-win_amd64.pyd` or `_sqlite_ext.cp35-win32.pyd`, not `_sqlite_ext.pyd`\n", "Hello, encountered this problem again (sorry for the duplicate issue). Would there be a fix, other than to not use peewee with Py3.X on windows?\n", "@shirish93 can you please paste the traceback?\n", "I solved the issue (probably more #831) with my python 3.5 setup by insalling VS 2015 with the instructions of this thread:\n\nhttp://stackoverflow.com/questions/33323172/vcvarsall-bat-needed-for-python-to-compile-missing-from-visual-studio-2015-v-1\n" ]
2015-11-20T23:24:31
2016-04-24T10:14:38
2015-11-21T03:03:19
NONE
null
Hi guys. I am trying to install peewee under WinPython. It comes with Cython pre-intalled, so peewee attempts to compile extensions and this is where the install fails. It complains about sqlite3.h absence and I don't know how to resolve this. Compiling sqlite3 and putting the .a file in the lib folder did not help... I asked the same question on stackoverflow and received a comment which I cannot parse... http://stackoverflow.com/questions/33834113/fail-to-install-peewee-under-winpython
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/763/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/763/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/762
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/762/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/762/comments
https://api.github.com/repos/coleifer/peewee/issues/762/events
https://github.com/coleifer/peewee/issues/762
118,128,380
MDU6SXNzdWUxMTgxMjgzODA=
762
Escaping `%` for parameterized queries
{ "login": "skatenerd", "id": 880217, "node_id": "MDQ6VXNlcjg4MDIxNw==", "avatar_url": "https://avatars.githubusercontent.com/u/880217?v=4", "gravatar_id": "", "url": "https://api.github.com/users/skatenerd", "html_url": "https://github.com/skatenerd", "followers_url": "https://api.github.com/users/skatenerd/followers", "following_url": "https://api.github.com/users/skatenerd/following{/other_user}", "gists_url": "https://api.github.com/users/skatenerd/gists{/gist_id}", "starred_url": "https://api.github.com/users/skatenerd/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/skatenerd/subscriptions", "organizations_url": "https://api.github.com/users/skatenerd/orgs", "repos_url": "https://api.github.com/users/skatenerd/repos", "events_url": "https://api.github.com/users/skatenerd/events{/privacy}", "received_events_url": "https://api.github.com/users/skatenerd/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Just use `%%` instead of `%`\n" ]
2015-11-20T21:22:43
2015-11-20T21:41:47
2015-11-20T21:41:47
NONE
null
When I try to run the trigram Postgres query: `db.execute_sql("select * from person where person.name % 'bobby'")` The query crashes with `tuple index out of range` because it thinks the `%` is an argument I'm wondering if there's a way to escape the `%` sign, so that can put the `%` in the query safely. If I try to pass it in as an argument to the query, it gets wrapped in a string and the query fails: `db.execute_sql("select * from person where person.name %s 'foo'", ("%",))`
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/762/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/762/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/761
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/761/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/761/comments
https://api.github.com/repos/coleifer/peewee/issues/761/events
https://github.com/coleifer/peewee/issues/761
117,991,168
MDU6SXNzdWUxMTc5OTExNjg=
761
pip install peewee failed
{ "login": "openmartin", "id": 2059728, "node_id": "MDQ6VXNlcjIwNTk3Mjg=", "avatar_url": "https://avatars.githubusercontent.com/u/2059728?v=4", "gravatar_id": "", "url": "https://api.github.com/users/openmartin", "html_url": "https://github.com/openmartin", "followers_url": "https://api.github.com/users/openmartin/followers", "following_url": "https://api.github.com/users/openmartin/following{/other_user}", "gists_url": "https://api.github.com/users/openmartin/gists{/gist_id}", "starred_url": "https://api.github.com/users/openmartin/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/openmartin/subscriptions", "organizations_url": "https://api.github.com/users/openmartin/orgs", "repos_url": "https://api.github.com/users/openmartin/repos", "events_url": "https://api.github.com/users/openmartin/events{/privacy}", "received_events_url": "https://api.github.com/users/openmartin/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "on Ubuntu 14.04.2 LTS\npython 2.7.6\n", "I confirm we got the same issue this morning on our CI.\nOur trace is:\n\n`````` python\nDownloading/unpacking peewee>=2.6.4 (from ...->-r /home/u877/src/repo/app-api/requirements.txt (line 7))\n Running setup.py (path:/home/u877/python-env/build/peewee/setup.py) egg_info for package peewee\n Traceback (most recent call last):\n File \"<string>\", line 17, in <module>\n File \"/home/u877/python-env/build/peewee/setup.py\", line 42, in <module>\n scripts = ['pwiz.py'],\n File \"/usr/local/python/cpython-2.7/lib/python2.7/distutils/core.py\", line 138, in setup\n ok = dist.parse_command_line()\n File \"/home/u877/python-env/lib/python2.7/site-packages/setuptools/dist.py\", line 250, in parse_command_line\n result = _Distribution.parse_command_line(self)\n File \"/usr/local/python/cpython-2.7/lib/python2.7/distutils/dist.py\", line 467, in parse_command_line\n args = self._parse_command_opts(parser, args)\n File \"/home/u877/python-env/lib/python2.7/site-packages/setuptools/dist.py\", line 534, in _parse_command_opts\n nargs = _Distribution._parse_command_opts(self, parser, args)\n File \"/usr/local/python/cpython-2.7/lib/python2.7/distutils/dist.py\", line 523, in _parse_command_opts\n cmd_class = self.get_command_class(command)\n File \"/home/u877/python-env/lib/python2.7/site-packages/setuptools/dist.py\", line 359, in get_command_class\n if command in self.cmdclass:\n TypeError: argument of type 'NoneType' is not iterable\n Complete output from command python setup.py egg_info:\n Traceback (most recent call last):\n\n File \"<string>\", line 17, in <module>\n\n File \"/home/u877/python-env/build/peewee/setup.py\", line 42, in <module>\n\n scripts = ['pwiz.py'],\n\n File \"/usr/local/python/cpython-2.7/lib/python2.7/distutils/core.py\", line 138, in setup\n\n ok = dist.parse_command_line()\n\n File \"/home/u877/python-env/lib/python2.7/site-packages/setuptools/dist.py\", line 250, in parse_command_line\n\n result = _Distribution.parse_command_line(self)\n\n File \"/usr/local/python/cpython-2.7/lib/python2.7/distutils/dist.py\", line 467, in parse_command_line\n\n args = self._parse_command_opts(parser, args)\n\n File \"/home/u877/python-env/lib/python2.7/site-packages/setuptools/dist.py\", line 534, in _parse_command_opts\n\n nargs = _Distribution._parse_command_opts(self, parser, args)\n\n File \"/usr/local/python/cpython-2.7/lib/python2.7/distutils/dist.py\", line 523, in _parse_command_opts\n\n cmd_class = self.get_command_class(command)\n\n File \"/home/u877/python-env/lib/python2.7/site-packages/setuptools/dist.py\", line 359, in get_command_class\n\n if command in self.cmdclass:\n\nTypeError: argument of type 'NoneType' is not iterable\n\n----------------------------------------\nCleaning up...\nCommand python setup.py egg_info failed with error code 1 in /home/u877/python-env/build/peewee\nStoring debug log for failure in /home/u877/.pip/pip.log\n[exit status: 1]```\n\n``````\n", ":+1: Python 3.4.2 https://travis-ci.org/klen/muffin-admin/builds/92235523\n\nLooks like setup with peewee 2.7.0 is broken.\n", "Same error occurs on Mac OS X 10.11, Python 3.5\n", "This should be fixed with the 2.7.1 release. Tested with and without cython on py 2.7.9.\n" ]
2015-11-20T08:35:41
2015-11-20T14:47:25
2015-11-20T14:47:25
NONE
null
(1.0.0)ubuntu@localhost:/home/ubuntu/v_env$ pip install peewee Collecting peewee Using cached peewee-2.7.0.tar.gz Complete output from command python setup.py egg_info: Traceback (most recent call last): File "<string>", line 20, in <module> File "/tmp/pip-build-M40xkD/peewee/setup.py", line 42, in <module> scripts = ['pwiz.py'], File "/usr/lib/python2.7/distutils/core.py", line 137, in setup ok = dist.parse_command_line() File "/opt/test/crazzkeyboard/1.0.0/local/lib/python2.7/site-packages/setuptools/dist.py", line 299, in parse_command_line result = _Distribution.parse_command_line(self) File "/usr/lib/python2.7/distutils/dist.py", line 467, in parse_command_line args = self._parse_command_opts(parser, args) File "/opt/test/crazzkeyboard/1.0.0/local/lib/python2.7/site-packages/setuptools/dist.py", line 601, in _parse_command_opts nargs = _Distribution._parse_command_opts(self, parser, args) File "/usr/lib/python2.7/distutils/dist.py", line 523, in _parse_command_opts cmd_class = self.get_command_class(command) File "/opt/test/crazzkeyboard/1.0.0/local/lib/python2.7/site-packages/setuptools/dist.py", line 425, in get_command_class if command in self.cmdclass: TypeError: argument of type 'NoneType' is not iterable ``` ---------------------------------------- ``` Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-M40xkD/peewee
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/761/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/761/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/760
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/760/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/760/comments
https://api.github.com/repos/coleifer/peewee/issues/760/events
https://github.com/coleifer/peewee/issues/760
117,988,840
MDU6SXNzdWUxMTc5ODg4NDA=
760
How to make the result to be dict ?
{ "login": "olivetree123", "id": 5275647, "node_id": "MDQ6VXNlcjUyNzU2NDc=", "avatar_url": "https://avatars.githubusercontent.com/u/5275647?v=4", "gravatar_id": "", "url": "https://api.github.com/users/olivetree123", "html_url": "https://github.com/olivetree123", "followers_url": "https://api.github.com/users/olivetree123/followers", "following_url": "https://api.github.com/users/olivetree123/following{/other_user}", "gists_url": "https://api.github.com/users/olivetree123/gists{/gist_id}", "starred_url": "https://api.github.com/users/olivetree123/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/olivetree123/subscriptions", "organizations_url": "https://api.github.com/users/olivetree123/orgs", "repos_url": "https://api.github.com/users/olivetree123/repos", "events_url": "https://api.github.com/users/olivetree123/events{/privacy}", "received_events_url": "https://api.github.com/users/olivetree123/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "First off this is completely inappropriate for a GitHub issue. Questions go on stack overflow, irc or the mailing list.\n\nSecond, to answer, write:\n\nGym.select().dicts().get()\n" ]
2015-11-20T08:26:24
2015-11-20T16:18:37
2015-11-20T16:18:37
NONE
null
g = Gym.get() I want to make variable g to be a dict , like g = dict(g) , how could I do ?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/760/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/760/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/759
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/759/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/759/comments
https://api.github.com/repos/coleifer/peewee/issues/759/events
https://github.com/coleifer/peewee/issues/759
117,967,846
MDU6SXNzdWUxMTc5Njc4NDY=
759
The build depends on Cython, not noted in `setup.py`
{ "login": "skatenerd", "id": 880217, "node_id": "MDQ6VXNlcjg4MDIxNw==", "avatar_url": "https://avatars.githubusercontent.com/u/880217?v=4", "gravatar_id": "", "url": "https://api.github.com/users/skatenerd", "html_url": "https://github.com/skatenerd", "followers_url": "https://api.github.com/users/skatenerd/followers", "following_url": "https://api.github.com/users/skatenerd/following{/other_user}", "gists_url": "https://api.github.com/users/skatenerd/gists{/gist_id}", "starred_url": "https://api.github.com/users/skatenerd/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/skatenerd/subscriptions", "organizations_url": "https://api.github.com/users/skatenerd/orgs", "repos_url": "https://api.github.com/users/skatenerd/repos", "events_url": "https://api.github.com/users/skatenerd/events{/privacy}", "received_events_url": "https://api.github.com/users/skatenerd/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Fixed with the 2.7.1 release. Cython is not required, but if you have it peewee will build some c extension.\n" ]
2015-11-20T05:27:42
2015-11-20T14:48:52
2015-11-20T14:48:52
NONE
null
If you don't have Cython, this line: https://github.com/coleifer/peewee/blob/master/setup.py#L12 Sets `cmdclass` to `None`, which causes the (pip) installation to crash, when `dist.py` tries to iterate over `self.cmdclass`: https://github.com/jaraco/setuptools/blob/master/setuptools/dist.py#L425 Should we just add an `install_requires` argument when we call `setup`? https://github.com/coleifer/peewee/blob/master/setup.py#L21
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/759/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/759/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/758
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/758/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/758/comments
https://api.github.com/repos/coleifer/peewee/issues/758/events
https://github.com/coleifer/peewee/issues/758
117,615,159
MDU6SXNzdWUxMTc2MTUxNTk=
758
Creating a custom field that automatically converts between db types and python types
{ "login": "larsks", "id": 82622, "node_id": "MDQ6VXNlcjgyNjIy", "avatar_url": "https://avatars.githubusercontent.com/u/82622?v=4", "gravatar_id": "", "url": "https://api.github.com/users/larsks", "html_url": "https://github.com/larsks", "followers_url": "https://api.github.com/users/larsks/followers", "following_url": "https://api.github.com/users/larsks/following{/other_user}", "gists_url": "https://api.github.com/users/larsks/gists{/gist_id}", "starred_url": "https://api.github.com/users/larsks/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/larsks/subscriptions", "organizations_url": "https://api.github.com/users/larsks/orgs", "repos_url": "https://api.github.com/users/larsks/repos", "events_url": "https://api.github.com/users/larsks/events{/privacy}", "received_events_url": "https://api.github.com/users/larsks/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I would just create wrapper methods that do what you want, since by the time you're calling `python_value()` it's technically too late as the value has already been pulled from the database. As to `db_value()` doing the inverse, that's not really the intended purpose of the method.\n\nSince you're using Postgres, you can also register custom adapters: https://github.com/coleifer/peewee/blob/master/playhouse/postgres_ext.py#L106-L120\n", "@larsks FYI, I have the same need, and started working on https://github.com/yohanboniface/psycopg-postgis\nExample usage: https://github.com/etalab/ban/blob/master/ban/db/fields.py#L16\nI may wrap all this in a `peewee-postgis` module at some point, but for now it's experimental and I just need Point in my app. So work in progress… ;)\n", "Thanks for the pointer! I ultimately followed @coleifer suggestion and set up an adapter, which is pretty much straight out of the psycopg docs:\n\n```\nPoint = namedtuple('Point', ['x', 'y', 'srid'])\n\ndef adapt_point(point):\n x = adapt(point.x).getquoted()\n y = adapt(point.y).getquoted()\n srid = adapt(point.srid).getquoted()\n return AsIs(\"st_setsrid(st_makepoint(%s, %s), %s)\" % (x,y,srid))\n\nregister_adapter(Point, adapt_point)\n```\n\nAnd then in my PointField class:\n\n```\ndef db_value(self, value): \n if isinstance(value, tuple): \n return Point(value[0], value[1], self.geom_srid) \n else: \n return value \n```\n\nAnd this Just Works as far as storing data goes. It doesn't handle\nconverting the stored data back into Python tapes on load, because\nthis seemed a bit trickier, since it involves querying the database\nfor oid information.\n\nI also discovered the [shapely](https://pypi.python.org/pypi/Shapely) module, which has functions for\nhandling WKT/WKB data in Python, which would probably make this all\nmuch simpler (and less tied to psycopg-specific features).\n", "> It doesn't handle\n> converting the stored data back into Python tapes on load, because\n> this seemed a bit trickier, since it involves querying the database\n> for oid information.\n\nYep, that's what psycopg-postgis does. I need the conversion also on data fetching :)\n\n> I also discovered the shapely module, which has functions for\n> handling WKT/WKB data in Python\n\nAFAIK, it does not handle srid. :/\n", "@coleifer is there a way to override the fn called when performing a read?\r\n\r\nIE, instead of \r\n\r\n```sql\r\nselect foo, bar, baz from table\r\n```\r\n\r\nYou could specify a wrapper fn for a field, so you could so something like\r\n\r\n```sql\r\nselect foo, bar, ST_AsText(baz) from table\r\n```\r\n\r\nwhich would alleviate a lot of the trouble here (I too am trying to figure out how to read/write a simple `geometry(Point)` field with postgis.", "Have you tried implementing the `db_value` method such that it calls the function when passing the value into the db?\r\n\r\n```python\r\nclass GeometryField(WhateverField):\r\n def db_value(self, value):\r\n return fn.ST_AsText(value)\r\n```", "FYI, for those curious, the adapt code linked above was lost in recent code changes but I found it here in a 2.x release: https://github.com/coleifer/peewee/blob/761f9144a0e17381147a81658019cffe14c118ca/playhouse/postgres_ext.py#L106-L120", "As of commit 090dc61d08929bec863fc08da342284116807a42, the OP's original attempt should be working:\r\n\r\n```python\r\ndef db_value(self, value):\r\n return fn.st_setsrid(\r\n fn.st_makepoint(value[0],value[1],self.geom_srid))\r\n```\r\n\r\nAlthough if the value is a list, it may be necessary to wrap it in `AsIs()` additionally.", "First off, I want to say thanks to @coleifer for writing and maintaining such a great library.\r\n\r\nI think what @whalesalad is getting at is the same problem / hassle I'm running into: the extension (e.g. PostGIS) stores a different native type in the database, so when you want to use it outside the DB you need to serialize it to something like WKT. This has to be done at the time of query generation, as in their example:\r\n\r\n`select foo, bar, ST_AsText(baz) from table`\r\n\r\nI initially thought I could use fn.AsText (I'm trying this with Spatialite) in a `python_value` method, but as you pointed out this doesn't run until after the query and just ends up returning a useless function object.\r\n\r\nIf I understand right, the example given by @coleifer would wrap geometry fields with ST_AsText in INSERT and UPDATE statements in addition to SELECTS:\r\n\r\n class GeometryField(WhateverField):\r\n def db_value(self, value):\r\n return fn.ST_AsText(value)\r\n\r\nI think this would break INSERT and UPDATE statements attempting to store geometries in db-native format - it would write strings instead.\r\n\r\nAt the moment, I have a utility function that checks if a field name is 'geometry' and if so, wraps it in fn.AsText:\r\n\r\n def fix_geom_field(table, query_fields):\r\n fields = []\r\n for field_name in table._meta.sorted_field_names:\r\n if field_name in query_fields:\r\n field = getattr(table, field_name)\r\n if field_name == 'geometry':\r\n field = fn.AsText(field)\r\n fields.append(field)\r\n\r\nThis gets run on a list of field names that get converted into field instances associated with the table of interest, and wraps a column names geometry (this could also work with introspection into field types). The results of this query can then be used in ORM selects:\r\n\r\n Table.select(*fix_geom_field(Table, query_fields))", "Experienced developer learning PeeWee for the first time. Thank you so much, @coleifer.\r\n\r\nHas this updated in the last year? In @nbolten 's implementation, it does seem as though the map from field -> fn.AsText(field) ought to be able to be inserted into the GeometryField declaration class itself. ", "This appears to create the same outcome as @nbolten , and allows the containment to be on the field itself. It is unclear to me whether _returning is only those fields selected by the select() method, and how this will affect performance in more complex queries. Posting here, though.\r\n\r\n```\r\nclass PointField(pw.Field):\r\n \"\"\"Geometry field type Point, conforming to MySQL 8.0+, format is WKT: 'POINT(18 23)'\"\"\"\r\n\r\n # Field type in MySQL is Point with a capital P.\r\n field_type = 'Point'\r\n\r\n def python_value(self, value):\r\n return value\r\n\r\n def db_value(self, ewkt):\r\n \"\"\"Converts EWKT format to MySQL database requirements, e.g., SRID=3857;POINT(10,10)\"\"\"\r\n\r\n # Does the ewkt start with \"SRID=XXXX;...\".\r\n # If so, remove the value from the geometry and parse/extract the srid\r\n s = ewkt.split(\";\")\r\n if s[0].startswith(\"SRID=\"):\r\n geo = \";\".join(s[1:])\r\n srid = s[0].split(\"=\")[1]\r\n return pw.fn.ST_GeomFromText(geo, srid)\r\n else:\r\n return pw.fn.ST_GeomFromText(ewkt)\r\n\r\n def _db_wrangler(self, field):\r\n return pw.fn.ST_AsText(field).alias(field.name)\r\n```\r\n\r\n```\r\nquery = PadsLocations.select(PadsLocations)\r\nfor r_i, r in enumerate(query._returning):\r\n if hasattr(r, '_db_wrangler'):\r\n query._returning[r_i] = r._db_wrangler(r)\r\n```", "@davidbernat Thanks for your post - I finally got lat/lon in and out of a PeeWee PostGIS database (which I barely understand) with your code. I clearly still don't understand something, though: `ST_GeomFromText` returns `Geometry`, not `Point`, and I only get your code to work by specifying `field_type = 'Geometry'`. " ]
2015-11-18T15:48:02
2021-03-11T07:02:48
2015-11-18T18:00:34
NONE
null
I want to use Peewee to manage a collection of GIS data. I've defined some custom fields to handle the PostGIS `geometry` type: ``` class GeomField(Field): db_field = 'geometry' def __init__(self, geom_type=None, geom_srid=None, **kwargs): self.geom_srid = geom_srid self.geom_type = geom_type super(GeomField, self).__init__(**kwargs) if geom_type: if geom_srid: self.db_field = 'geometry(%s, %s)' % (geom_type, geom_srid) else: self.db_field = 'geometry(%s)' % (geom_type, ) class PointField(GeomField): def __init__(self, geom_srid=None, **kwargs): super(PointField, self).__init__( geom_type='Point', geom_srid=geom_srid, **kwargs) ``` This works fine so far. I would like to be able to set a `PointField` to a Python tuple and have it converted automatically to a `geometry` value (and I want the inverse as well). I started with this: ``` def db_value(self, value): return fn.st_setsrid( fn.st_makepoint(value[0],value[1],self.geom_srid)) ``` But I guess that Peewee doesn't interpolate these functions at the right point, because that gets me: ``` ValueError: only bytes values expected, got Func ``` So instead I've done this: ``` def python_value(self, value): res = database.execute_sql('select st_x(%s), st_y(%s)', (value, value)) return res.fetchone() def db_value(self, value): res = database.execute_sql( 'select st_setsrid(st_makepoint(%s,%s), %s)', (value[0], value[1], self.geom_srid)) return res.fetchone() ``` This works, but it seems less than elegant and I am curious if I am missing a simpler solution.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/758/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/758/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/757
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/757/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/757/comments
https://api.github.com/repos/coleifer/peewee/issues/757/events
https://github.com/coleifer/peewee/pull/757
117,441,427
MDExOlB1bGxSZXF1ZXN0NTA5OTg4MTI=
757
Pwiz preservation of composite indices and uniques
{ "login": "SarahFowler73", "id": 5266362, "node_id": "MDQ6VXNlcjUyNjYzNjI=", "avatar_url": "https://avatars.githubusercontent.com/u/5266362?v=4", "gravatar_id": "", "url": "https://api.github.com/users/SarahFowler73", "html_url": "https://github.com/SarahFowler73", "followers_url": "https://api.github.com/users/SarahFowler73/followers", "following_url": "https://api.github.com/users/SarahFowler73/following{/other_user}", "gists_url": "https://api.github.com/users/SarahFowler73/gists{/gist_id}", "starred_url": "https://api.github.com/users/SarahFowler73/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/SarahFowler73/subscriptions", "organizations_url": "https://api.github.com/users/SarahFowler73/orgs", "repos_url": "https://api.github.com/users/SarahFowler73/repos", "events_url": "https://api.github.com/users/SarahFowler73/events{/privacy}", "received_events_url": "https://api.github.com/users/SarahFowler73/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[]
2015-11-17T20:19:40
2015-11-18T18:23:41
2015-11-18T18:23:41
NONE
null
When pwiz creates your model, it will preserve the composite indices and composite unique constraints that you have on your tables in your model.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/757/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/757/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/757", "html_url": "https://github.com/coleifer/peewee/pull/757", "diff_url": "https://github.com/coleifer/peewee/pull/757.diff", "patch_url": "https://github.com/coleifer/peewee/pull/757.patch", "merged_at": null }
https://api.github.com/repos/coleifer/peewee/issues/756
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/756/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/756/comments
https://api.github.com/repos/coleifer/peewee/issues/756/events
https://github.com/coleifer/peewee/pull/756
116,963,337
MDExOlB1bGxSZXF1ZXN0NTA3MzYxODM=
756
pwiz: changed to allow for keyboard interactive authentication
{ "login": "therealchalz", "id": 3590449, "node_id": "MDQ6VXNlcjM1OTA0NDk=", "avatar_url": "https://avatars.githubusercontent.com/u/3590449?v=4", "gravatar_id": "", "url": "https://api.github.com/users/therealchalz", "html_url": "https://github.com/therealchalz", "followers_url": "https://api.github.com/users/therealchalz/followers", "following_url": "https://api.github.com/users/therealchalz/following{/other_user}", "gists_url": "https://api.github.com/users/therealchalz/gists{/gist_id}", "starred_url": "https://api.github.com/users/therealchalz/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/therealchalz/subscriptions", "organizations_url": "https://api.github.com/users/therealchalz/orgs", "repos_url": "https://api.github.com/users/therealchalz/repos", "events_url": "https://api.github.com/users/therealchalz/events{/privacy}", "received_events_url": "https://api.github.com/users/therealchalz/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[]
2015-11-15T00:31:47
2015-11-17T03:31:47
2015-11-17T03:31:47
NONE
null
It's nice to be able to keep your DB password off the command line (and therefore .bash_history or similar logs). This change to pwiz prompts for the DB password if it is not given on the command line.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/756/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/756/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/756", "html_url": "https://github.com/coleifer/peewee/pull/756", "diff_url": "https://github.com/coleifer/peewee/pull/756.diff", "patch_url": "https://github.com/coleifer/peewee/pull/756.patch", "merged_at": null }
https://api.github.com/repos/coleifer/peewee/issues/755
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/755/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/755/comments
https://api.github.com/repos/coleifer/peewee/issues/755/events
https://github.com/coleifer/peewee/pull/755
116,897,768
MDExOlB1bGxSZXF1ZXN0NTA3MTY3NTc=
755
querying.rst: update ManyToManyField module belong
{ "login": "franciscod", "id": 726447, "node_id": "MDQ6VXNlcjcyNjQ0Nw==", "avatar_url": "https://avatars.githubusercontent.com/u/726447?v=4", "gravatar_id": "", "url": "https://api.github.com/users/franciscod", "html_url": "https://github.com/franciscod", "followers_url": "https://api.github.com/users/franciscod/followers", "following_url": "https://api.github.com/users/franciscod/following{/other_user}", "gists_url": "https://api.github.com/users/franciscod/gists{/gist_id}", "starred_url": "https://api.github.com/users/franciscod/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/franciscod/subscriptions", "organizations_url": "https://api.github.com/users/franciscod/orgs", "repos_url": "https://api.github.com/users/franciscod/repos", "events_url": "https://api.github.com/users/franciscod/events{/privacy}", "received_events_url": "https://api.github.com/users/franciscod/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Is fields the right ref?\n", "No sir! It's `extra-fields`! fixing that up, sorry!\n", "push-forced the changes, but i've not yet built the docs locally so this is untested\n", "installed sphinx, `make html`, links are working! should I check anything else?\n", "Thanks a lot!\n" ]
2015-11-14T05:12:03
2015-11-14T13:51:49
2015-11-14T13:51:34
CONTRIBUTOR
null
ManyToManyField is now on the playhouse.fields module, docs were slightly misleading
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/755/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/755/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/755", "html_url": "https://github.com/coleifer/peewee/pull/755", "diff_url": "https://github.com/coleifer/peewee/pull/755.diff", "patch_url": "https://github.com/coleifer/peewee/pull/755.patch", "merged_at": "2015-11-14T13:51:34" }
https://api.github.com/repos/coleifer/peewee/issues/754
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/754/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/754/comments
https://api.github.com/repos/coleifer/peewee/issues/754/events
https://github.com/coleifer/peewee/issues/754
116,897,436
MDU6SXNzdWUxMTY4OTc0MzY=
754
When using playground.fields.ManyToManyField, I get "no such table: firstmodel_secondmodel_through"
{ "login": "franciscod", "id": 726447, "node_id": "MDQ6VXNlcjcyNjQ0Nw==", "avatar_url": "https://avatars.githubusercontent.com/u/726447?v=4", "gravatar_id": "", "url": "https://api.github.com/users/franciscod", "html_url": "https://github.com/franciscod", "followers_url": "https://api.github.com/users/franciscod/followers", "following_url": "https://api.github.com/users/franciscod/following{/other_user}", "gists_url": "https://api.github.com/users/franciscod/gists{/gist_id}", "starred_url": "https://api.github.com/users/franciscod/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/franciscod/subscriptions", "organizations_url": "https://api.github.com/users/franciscod/orgs", "repos_url": "https://api.github.com/users/franciscod/repos", "events_url": "https://api.github.com/users/franciscod/events{/privacy}", "received_events_url": "https://api.github.com/users/franciscod/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "(edited the title so model names are general, mines are `TelegramChat` and `TwitterUser`)\n", "I'm stupid:\n\n> We still need a junction table to store the relationships between students and courses. This model can be accessed by calling the get_through_model() method. This is useful when creating tables.\n\nhttp://docs.peewee-orm.com/en/latest/peewee/playhouse.html#ManyToManyField\n\nsearch for \"creating tables\"\n" ]
2015-11-14T05:08:17
2015-11-14T05:17:36
2015-11-14T05:14:50
CONTRIBUTOR
null
Am I missing something silly ***** ? I've already done create_tables on both models (in the same order that they're defined as classes). I can post a minimal reproduction file if that's useful! ***SPOILERS: YES I WAS**
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/754/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/754/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/753
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/753/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/753/comments
https://api.github.com/repos/coleifer/peewee/issues/753/events
https://github.com/coleifer/peewee/issues/753
116,297,852
MDU6SXNzdWUxMTYyOTc4NTI=
753
peewee mysql how to execute 'insert many on duplicate key update'
{ "login": "yangbh", "id": 7778764, "node_id": "MDQ6VXNlcjc3Nzg3NjQ=", "avatar_url": "https://avatars.githubusercontent.com/u/7778764?v=4", "gravatar_id": "", "url": "https://api.github.com/users/yangbh", "html_url": "https://github.com/yangbh", "followers_url": "https://api.github.com/users/yangbh/followers", "following_url": "https://api.github.com/users/yangbh/following{/other_user}", "gists_url": "https://api.github.com/users/yangbh/gists{/gist_id}", "starred_url": "https://api.github.com/users/yangbh/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/yangbh/subscriptions", "organizations_url": "https://api.github.com/users/yangbh/orgs", "repos_url": "https://api.github.com/users/yangbh/repos", "events_url": "https://api.github.com/users/yangbh/events{/privacy}", "received_events_url": "https://api.github.com/users/yangbh/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "here is my poor solution\n\n```\nq=basicinfo_ip_finger.insert_many(result).sql()\ndb.execute_sql(q[0]+' on duplicate key update hostname=values(hostname),...', q[1])\n```\n\nany good idea?\nthanks\n", "I looked at the docs and it seems like MySQL supports a command `REPLACE` that does what you want. I've added support for this in 2d2df5ca3b69073f4b9efef1ed6d2ad21406298b . I think this is actually preferable to using ON DUPLICATE KEY UPDATE because REPLACE does not require a separate clause describing the values.\n", "Hi there, quick question regarding this comment\r\n\r\nhttps://stackoverflow.com/a/9168948/2774823\r\n\r\nit seems sometimes ON DUPLICATE KEY UPDATE is preferable?", "Peewee does support ON DUPLICATE KEY UPDATE:\r\n\r\nhttp://docs.peewee-orm.com/en/latest/peewee/querying.html#upsert\r\n\r\n> MySQL supports upsert via the ON DUPLICATE KEY UPDATE clause. For example:\r\n\r\n```python\r\nclass User(Model):\r\n username = TextField(unique=True)\r\n last_login = DateTimeField(null=True)\r\n login_count = IntegerField()\r\n\r\n# Insert a new user.\r\nUser.create(username='huey', login_count=0)\r\n\r\n# Simulate the user logging in. The login count and timestamp will be\r\n# either created or updated correctly.\r\nnow = datetime.now()\r\nrowid = (User\r\n .insert(username='huey', last_login=now, login_count=1)\r\n .on_conflict(\r\n preserve=[User.last_login], # Use the value we would have inserted.\r\n update={User.login_count: User.login_count + 1})\r\n .execute())\r\n```", "@coleifer \r\nif I have a filed with ddl like this \r\n\r\n> `created_on` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP\r\n\r\nif I use replace, it will result in the filed \"created_on\" is \"updated\" to current time, because the origin record is deleted and a new record created,this is not my expected.Otherwise, Insert into ..... ON DUPLICATE KEY UPDATE work well.\r\n", "@xzycn - you should consult the documentation for your database, my dude. It clearly says that REPLACE works by deleting and re-inserting in the event of a conflict.\r\n\r\nhttps://dev.mysql.com/doc/refman/8.0/en/replace.html", "@coleifer \r\nI know that, just didn't claim it.I just want to say:\"it seems sometimes ON DUPLICATE KEY UPDATE is preferable\", thank you for your reply :)" ]
2015-11-11T09:38:47
2019-11-28T14:38:42
2015-11-19T22:33:03
NONE
null
Hi Charles, how to execute sql command like ``` insert into table(ip,hostname,...) values ('','',...) ('','',...) ('','',...) ... on duplicate key update hostname=values(hostname), ``` upsert and on_conflict does not work ``` In [49]: result Out[49]: [{'country': '', 'guid': '122.225.227.21:80', 'head': '', 'hostname': '122.225.227.21', 'ip': '122.225.227.21', 'ipr': '', 'port': 80, 'protocol_type': 'tcp', 'province': '', 'server': '', 'title': ''}, ...] In [50]: basicinfo_ip_finger.insert_many(result).on_conflict('REPLACE').execute() ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'OR REPLACE INTO `basicinfo_ip_finger` (`ip`, `port`, `protocol_type`, `hostname`' at line 1") ``` please help, thanks
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/753/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/753/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/752
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/752/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/752/comments
https://api.github.com/repos/coleifer/peewee/issues/752/events
https://github.com/coleifer/peewee/issues/752
116,169,293
MDU6SXNzdWUxMTYxNjkyOTM=
752
How to design models in a ManyToManyField with a through_model
{ "login": "bcthomas", "id": 86821, "node_id": "MDQ6VXNlcjg2ODIx", "avatar_url": "https://avatars.githubusercontent.com/u/86821?v=4", "gravatar_id": "", "url": "https://api.github.com/users/bcthomas", "html_url": "https://github.com/bcthomas", "followers_url": "https://api.github.com/users/bcthomas/followers", "following_url": "https://api.github.com/users/bcthomas/following{/other_user}", "gists_url": "https://api.github.com/users/bcthomas/gists{/gist_id}", "starred_url": "https://api.github.com/users/bcthomas/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/bcthomas/subscriptions", "organizations_url": "https://api.github.com/users/bcthomas/orgs", "repos_url": "https://api.github.com/users/bcthomas/repos", "events_url": "https://api.github.com/users/bcthomas/events{/privacy}", "received_events_url": "https://api.github.com/users/bcthomas/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "You can use the `Proxy` object [see circular foreign keys](http://docs.peewee-orm.com/en/latest/peewee/models.html#circular-foreign-key-dependencies).\n\n``` python\nclass User(BaseModel):\n email = CharField(unique=True)\n\nProjectUserProxy = Proxy()\n\nclass Project(BaseModel):\n name = CharField(null=True)\n users = ManyToManyField(\n User, \n related_name='projects', \n through_model=ProjectUserProxy)\n\n class Meta:\n db_table = 'projects'\n\nclass ProjectUser(BaseModel):\n project = ForeignKeyField(Project, db_column='project_id', index=True, null=True)\n user = ForeignKeyField(User, db_column='user_id', index=True, null=True)\n\n class Meta:\n db_table = 'project_users'\n\nProjectUserProxy.initialize(ProjectUser)\n```\n\nEverything worked correctly with the above code when I tried creating some users, projects, and the relationships between them. The custom through table appeared to be working as well.\n" ]
2015-11-10T18:15:59
2015-11-10T21:18:36
2015-11-10T21:18:36
NONE
null
(new to peewee/python orms, coming from a "legacy" rails database) I'm trying to model 2 elements in a many to many relationship, using a join table; I have a User and a Project, and a join table called ProjectUser. I've tried this, and I'm getting circular dependency errors because as is ProjectUser is not defined in Project, and if I swap where I define each, then Project isn't defined in ProjectUser: ``` # models/projects.py from peewee import * from playhouse.fields import ManyToManyField from . import users as u class Project(BaseModel): name = CharField(null=True) users = ManyToManyField(u.User, related_name='projects', through_model=ProjectUser) class Meta: db_table = 'projects' class ProjectUser(BaseModel): project = ForeignKeyField(Project, db_column='project_id', index=True, null=True) user = ForeignKeyField(u.User, db_column='user_id', index=True, null=True) class Meta: db_table = 'project_users' # models/users.py class User(BaseModel): email = CharField(unique=True) ``` When I let peewee determine the table name (by removing the through_model param), it seems to be ok, but obviously my join table isn't named correctly that way. Can the ForeignKeyField declarations in the ProjectUser model be defined dynamically so I can avoid the circular dependency? Or phrased differently, how would I accomplish this with a custom-named through_model table? or or... am I just not thinking about this correctly? TIA! ps all my models were generated by using pwiz on my rails database.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/752/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/752/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/751
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/751/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/751/comments
https://api.github.com/repos/coleifer/peewee/issues/751/events
https://github.com/coleifer/peewee/issues/751
116,153,562
MDU6SXNzdWUxMTYxNTM1NjI=
751
AttributeError: 'bool' object has no attribute 'is_pk' in migrator
{ "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
[ "The problem, not obvious at all, is that the `ticket` column is not found. I bet that if you change it to `ticket_id` you will be set:\n\n``` python\nfrom playhouse.migrate import MySQLMigrator, migrate\nmigrator = MySQLMigrator(db.database)\nmigrate(migrator.drop_not_null('emailsending', 'ticket_id'))\n```\n", "Looking at the tests, there may be some additional issues with the mysql migrations regarding dropping constraints on foreign keys. Looking into it.\n", "@coleifer - Seeing that you closed this issue I presume that after you looked into it you concluded that there were no additional issues with the mysql migrations regarding dropping constraints on foreign keys?\n\nThe reason I'm asking is that I'm using this in beta/production now and I wanted to wait with migrating the db until you had a conclusion.\n", "Just to be safe I added another testcase adding and dropping not null constraints to a foreign key to verify they worked.\n", "Thanks for adding the tests. I tested it on 3 test setups before deploying the migration to the production server, and everything went perfectly fine.\n\nThanks for creating peewee!\n" ]
2015-11-10T17:09:56
2015-11-15T19:44:31
2015-11-11T17:06:48
NONE
null
I've successfully used the peewee migrator to add and drop columns, and today I wanted to use the migrator for the first time to drop a not null constrain on a column. In my model I added and set the null constraint to `True`: ``` ticket = ForeignKeyField(Ticket, related_name='sent_to_email_addresses', null=True) ``` So I wrote the following lines to do the migration: ``` from playhouse.migrate import MySQLMigrator, migrate migrator = MySQLMigrator(db.database) migrate(migrator.drop_not_null('emailsending', 'ticket')) ``` But I'm getting the following error: ``` File "./migrate_db.py", line 55, in from7To8 migrate(migrator.drop_not_null('emailsending', 'ticket')) File "/usr/local/lib/python2.7/dist-packages/playhouse/migrate.py", line 579, in migrate operation.run() File "/usr/local/lib/python2.7/dist-packages/playhouse/migrate.py", line 144, in run getattr(self.migrator, self.method)(*self.args, **kwargs)) File "/usr/local/lib/python2.7/dist-packages/playhouse/migrate.py", line 152, in inner return fn(self, *args, **kwargs) File "/usr/local/lib/python2.7/dist-packages/playhouse/migrate.py", line 390, in drop_not_null if column.is_pk: AttributeError: 'bool' object has no attribute 'is_pk' ``` Does anybody know what I'm doing wrong here?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/751/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/751/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/750
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/750/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/750/comments
https://api.github.com/repos/coleifer/peewee/issues/750/events
https://github.com/coleifer/peewee/pull/750
115,536,711
MDExOlB1bGxSZXF1ZXN0NDk5NzI2NDg=
750
Add connection management documentation for Falcon
{ "login": "arpankapoor", "id": 3677810, "node_id": "MDQ6VXNlcjM2Nzc4MTA=", "avatar_url": "https://avatars.githubusercontent.com/u/3677810?v=4", "gravatar_id": "", "url": "https://api.github.com/users/arpankapoor", "html_url": "https://github.com/arpankapoor", "followers_url": "https://api.github.com/users/arpankapoor/followers", "following_url": "https://api.github.com/users/arpankapoor/following{/other_user}", "gists_url": "https://api.github.com/users/arpankapoor/gists{/gist_id}", "starred_url": "https://api.github.com/users/arpankapoor/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/arpankapoor/subscriptions", "organizations_url": "https://api.github.com/users/arpankapoor/orgs", "repos_url": "https://api.github.com/users/arpankapoor/repos", "events_url": "https://api.github.com/users/arpankapoor/events{/privacy}", "received_events_url": "https://api.github.com/users/arpankapoor/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Does the response middleware method not need to return anything? (Or the request middleware for that matter)\n", "Nothing needs to be returned.\n\nThe middleware methods may modify the request and response objects passed in as parameters. These objects are routed to the appropriate responder method by Falcon.\n\nSee the docstring of the middleware methods [here](https://falcon.readthedocs.org/en/latest/api/middleware.html#middleware-components). \n", "Thanks!\n", "Not sure if it should be documented, but calling db.close in the process_response kills the cursor, and then a response via stream will fail\r\n\r\nA poor man workaround in this case could be to check the existence of the stream:\r\n\r\n```\r\n def process_response(self, req, resp, resource):\r\n if resp.stream==None and not db.is_closed():\r\n db.close()\r\n```\r\n\r\nAnd then use some stream incorporating a close() method, which falcon will call.\r\n\r\n```\r\nclass closingMap(map):\r\n def close(self):\r\n db.close()\r\n```\r\n for python > 3.6 some technique more \"awaitable\" could be better\r\n" ]
2015-11-06T16:16:48
2019-03-28T14:21:35
2015-11-06T20:27:49
CONTRIBUTOR
null
Middleware components in Falcon framework (http://falconframework.org/) can be used to add database connection management.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/750/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/750/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/750", "html_url": "https://github.com/coleifer/peewee/pull/750", "diff_url": "https://github.com/coleifer/peewee/pull/750.diff", "patch_url": "https://github.com/coleifer/peewee/pull/750.patch", "merged_at": "2015-11-06T20:27:49" }
https://api.github.com/repos/coleifer/peewee/issues/749
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/749/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/749/comments
https://api.github.com/repos/coleifer/peewee/issues/749/events
https://github.com/coleifer/peewee/issues/749
115,534,412
MDU6SXNzdWUxMTU1MzQ0MTI=
749
Filter does not behave like where with NULL ForeignKey
{ "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
[ "You need to use `.filter(one__is=None)`\n", "To be more specific, the filter API has been deprecated since 2.0.0. Why are you using it?\n", "> You need to use .filter(one__is=None)\n\nAh, ok, thanks.\n\n> To be more specific, the filter API has been deprecated since 2.0.0. Why are you using it?\n- Easier to build dynamically (for example from query parameters (?xxx=yyy&aaa=bbb), or any situation where you need to map from key/value).\n- More concise (we need to fit in 80 lines, no? ;) ).\n- more consistant: `Class.field != value` vs `Class.field.contains(value)`\n- feels pythonic at first view, but then we hit the \"or\", \"not\", \"in\"… limit, so a bit frustrating system at use _imho_\n- my brain refuses to remember `<<` and `>>` own operation ;)\n\nCan you explain (or point me to an explanation about) why it is deprecated? :)\n", "Well, you don't have to use `<<` and `>>`. You can use:\n\n``` python\nClass.field.in_()\nClass.field.is_null(True)\nClass.field.is_null(False)\n```\n\nAs to being concise, the way to format your code is up to you of course, but I never have issues with 80 character lines, e.g.\n\n``` python\n# Get blogs tagged with \"python\".\npython_blogs = (BlogEntry\n .select()\n .join(BlogEntryTags)\n .join(Tag)\n .where(\n (BlogEntry.is_published == True) &\n (Tag.tag == 'python'))\n .order_by(BlogEntry.timestamp.desc()))\n```\n\n---\n\nThe APIs are deprecated because they are not good APIs. Keyword arguments do not preserve ordering, which can be important when constructing where clauses that will hit an index. Keyword arguments necessitate hacks like `DQ(foo__bar='whatev') | DQ(whatever='nug')`. The set of operators is not nearly as rich. You cannot easily do things like express SQL aggregations, function calls, etc.\n", "> Keyword arguments do not preserve ordering, which can be important when constructing where clauses that will hit an index.\n\nSounds like a strong argument.\nThanks your answer. :)\n", "What about adding a [DeprecationWarning](https://docs.python.org/2/library/exceptions.html#exceptions.DeprecationWarning) when the function is called then?\n", "> To be more specific, the filter API has been deprecated since 2.0.0.\n\nDoes that means `get_or_create` is deprecated too, given that it relies on `filter`? If yes, is there a recommended way (bonus: that allows using HStore fields)?\n", "`get_or_create()` is not recommended, but is left in place because a lot of people have come to rely on it. I never use it myself, preferring to code things up explicitly:\n\n``` python\nwith db.atomic():\n try:\n user = User.create(username='whatever') # unique constraint on username\n except IntegrityError:\n user = User.get(User.username == 'whatever')\n```\n", "Thanks for the suggestion, that's indeed a nice pattern, but that's a `create_or_get`, which works only when you have a DB constraint to rely on. Anyway, I'll will dig this way. Thanks!\n" ]
2015-11-06T16:09:06
2016-02-02T10:29:05
2015-11-06T16:20:31
CONTRIBUTOR
null
``` python import peewee db = peewee.SqliteDatabase(':memory:') class One(peewee.Model): name = peewee.CharField() class Meta: database = db class Two(peewee.Model): name = peewee.CharField() one = peewee.ForeignKeyField(One, null=True) class Meta: database = db if __name__ == '__main__': One.create_table() Two.create_table() Two.create(name='no one') # This works. # SQL: SELECT "t1"."id", "t1"."name", "t1"."one_id" FROM "two" AS t1 WHERE ("t1"."one_id" IS ?) [None] assert Two.select().where(Two.one == None).count() == 1 # This does not. # SQL: SELECT "t1"."id", "t1"."name", "t1"."one_id" FROM "two" AS t1 INNER JOIN "one" AS t2 ON ("t1"."one_id" = "t2"."id") WHERE ("t1"."one_id" = ?) [None] assert Two.select().filter(one=None).count() == 1 ``` ``` $ python test.py Traceback (most recent call last): File "peewee_fk_none.py", line 31, in <module> assert Two.select().filter(one=None).count() == 1 AssertionError ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/749/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/749/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/748
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/748/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/748/comments
https://api.github.com/repos/coleifer/peewee/issues/748/events
https://github.com/coleifer/peewee/issues/748
115,128,919
MDU6SXNzdWUxMTUxMjg5MTk=
748
OperationalError when deferring foreign keys
{ "login": "notdaniel", "id": 3722519, "node_id": "MDQ6VXNlcjM3MjI1MTk=", "avatar_url": "https://avatars.githubusercontent.com/u/3722519?v=4", "gravatar_id": "", "url": "https://api.github.com/users/notdaniel", "html_url": "https://github.com/notdaniel", "followers_url": "https://api.github.com/users/notdaniel/followers", "following_url": "https://api.github.com/users/notdaniel/following{/other_user}", "gists_url": "https://api.github.com/users/notdaniel/gists{/gist_id}", "starred_url": "https://api.github.com/users/notdaniel/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/notdaniel/subscriptions", "organizations_url": "https://api.github.com/users/notdaniel/orgs", "repos_url": "https://api.github.com/users/notdaniel/repos", "events_url": "https://api.github.com/users/notdaniel/events{/privacy}", "received_events_url": "https://api.github.com/users/notdaniel/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "What database are you using?\n", "Ha! I was using SQLite (which I usually use when starting something out) but after your response, I just tried it with Postgres and it worked fine. Is this a SQLite limitation, then? Either way, this is helpful since I was going to move this to Postgres eventually anyway.\n", "SQLite does not support adding constraints. So basically you can follow the documentation example and simply skip the call to add the constraint. I've added a test and updated the docs to make this clear.\n" ]
2015-11-04T19:28:13
2015-11-06T04:19:03
2015-11-06T04:18:58
NONE
null
I've been trying to use the Proxy() trick, followed by its initialization, then table creation, and finally foreign key creation, exactly as shown in the [Circular foreign key dependencies](https://peewee.readthedocs.org/en/latest/peewee/models.html?highlight=defer#circular-foreign-key-dependencies) documentation. However, I always receive the following error: ``` python Traceback (most recent call last): File "<input>", line 1, in <module> File "/home/dkh/devel/peeweetest/venv/lib/python2.7/site-packages/peewee.py", line 3436, in create_foreign_key model_class, field, constraint)) File "/home/dkh/devel/peeweetest/venv/lib/python2.7/site-packages/peewee.py", line 3339, in execute_sql self.commit() File "/home/dkh/devel/peeweetest/venv/lib/python2.7/site-packages/peewee.py", line 3185, in __exit__ reraise(new_type, new_type(*exc_args), traceback) File "/home/dkh/devel/peeweetest/venv/lib/python2.7/site-packages/peewee.py", line 3331, in execute_sql cursor.execute(sql, params or ()) OperationalError: near "CONSTRAINT": syntax error ``` Wondering if it was with my models or something else on my end, I have tried using the exact models and code on the documentation with the same result. Any thoughts?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/748/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/748/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/747
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/747/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/747/comments
https://api.github.com/repos/coleifer/peewee/issues/747/events
https://github.com/coleifer/peewee/issues/747
114,927,277
MDU6SXNzdWUxMTQ5MjcyNzc=
747
`model_to_dict`'s `extra_attrs` only applies to the top-level object in the case where `recurse=True`
{ "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
[ "Immediately after posting it I of course thought of the way a method or property lives on the class level, and how it might be difficult to reconcile to an instance's bound method. Hmm...\n", "I'm seeing the difficulty here. If you pass in the unbound method, there's no (apparent) way to match a bound instance method with said unbound class method. If there's no way you can figure out either, I'll probably close this one up.\n", "@coleifer Which means itsn't possible to get `extra_attrs` on recursive items?", "No, for such cases as that you're probably best off just writing your own serializer." ]
2015-11-03T22:42:02
2023-03-11T07:57:17
2015-11-05T04:14:31
CONTRIBUTOR
null
Might I suggest a couple of solutions: 1) Have `extra_attrs` actually take in the attributes as the list members -- so instead of: ``` model_to_dict(x, extra_attrs=['method_bar', 'property_foo'] ``` You would see: ``` model_to_dict(x, extra_attrs=[ClassX.method_bar, ClassX.property_foo]) ``` This interface is more familiar and consistent with the `exclude`, `only`, etc parameters of the same function. Is there a particular reason why this one is purely string-based?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/747/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/747/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/746
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/746/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/746/comments
https://api.github.com/repos/coleifer/peewee/issues/746/events
https://github.com/coleifer/peewee/issues/746
114,903,698
MDU6SXNzdWUxMTQ5MDM2OTg=
746
Support declaring non-serializable fields on a Model
{ "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
[ "I am going to pass on this particular API or implementation. The `model_to_dict` is a simple but flexible piece of code, but it mostly stands on its own. Introducing APIs at the model level seems like too tight a coupling.\n" ]
2015-11-03T20:36:34
2015-11-05T04:13:29
2015-11-05T04:13:29
CONTRIBUTOR
null
Hey, Can you help me think of a way to blacklist certain model fields from being serialized in `model_to_dict`? I can see something like the `Meta` class having a field you can populate with a list of fields, and `model_to_dict` respecting that. The issue I'm running into is that because of the recursive nature of `model_to_dict`, it's not really possible (short of rolling my own entire implementation) to change the behavior of it at each depth. I've been trying to come up with a solid way of doing this with what peewee currently has to offer, and I'll show you the best I have, but I'm curious if there might be more first-class support for this kind of feature in the future. More or less, right now I have a base model class (`BaseModel`) that declares two class-level attributes `no_serialize` and `dynamic_serialize` (to add on `extra_attrs` support!) and a property in front of each (`excludes` and `extra_attrs`). The property method recursively follows down foreign keys to aggregate everyone's `no_serialize` and `dynamic_serialize` fields. The class-level attributes may belong in the `Meta` class but I just frankly hadn't gotten around to putting them in the right place. The `BaseModel` class then implements a method, `to_dict`, which is a convenience wrapper for getting the above properties and calling `model_to_dict` with both those parameters and the ones passed in by the caller. All in all, it looks like this: ``` class BaseModel(Model): created_at = DateTimeField(null=True) modified_at = DateTimeField(null=True) some_secret_field = CharField(null=True) @property def lifespan(self): return (self.modified_at - self.created_at).total_seconds() no_serialize = [some_secret_field] dynamic_serialize = [lifespan] # TODO the below methods do not handle GFKs, but I'm not too worried about that for now. @property def excludes(self): ex = self.no_serialize for f in self._meta.get_fields(): if isinstance(f, ForeignKeyField): ex.extend(f.rel_model.no_serialize) return ex @property def extra_attrs(self): dyn = self.dynamic_serialize for f in self._meta.get_fields(): if isinstance(f, ForeignKeyField): dyn.extend(f.rel_model.no_serialize) return dyn def to_dict(self, recurse=False, backrefs=False, only=None, exclude=None, seen=None, extra_attrs=None): if exclude and isinstance(exclude, list): exclude.extend(self.excludes) else: exclude = self.excludes if only: exclude = None if extra_attrs: extra_attrs.extend(self.extra_attrs) else: extra_attrs = self.extra_attrs return model_to_dict(self, recurse=recurse, backrefs=backrefs, only=only, exclude=exclude, seen=seen, extra_attrs=extra_attrs) ``` This is a really rough attempt at what I'm trying to accomplish, but I'd be glad to take some feedback and contribute what I can to making this a real feature of peewee. Thanks!
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/746/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/746/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/745
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/745/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/745/comments
https://api.github.com/repos/coleifer/peewee/issues/745/events
https://github.com/coleifer/peewee/issues/745
114,647,678
MDU6SXNzdWUxMTQ2NDc2Nzg=
745
Error when using JSONField() with case()
{ "login": "scribu", "id": 225715, "node_id": "MDQ6VXNlcjIyNTcxNQ==", "avatar_url": "https://avatars.githubusercontent.com/u/225715?v=4", "gravatar_id": "", "url": "https://api.github.com/users/scribu", "html_url": "https://github.com/scribu", "followers_url": "https://api.github.com/users/scribu/followers", "following_url": "https://api.github.com/users/scribu/following{/other_user}", "gists_url": "https://api.github.com/users/scribu/gists{/gist_id}", "starred_url": "https://api.github.com/users/scribu/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/scribu/subscriptions", "organizations_url": "https://api.github.com/users/scribu/orgs", "repos_url": "https://api.github.com/users/scribu/repos", "events_url": "https://api.github.com/users/scribu/events{/privacy}", "received_events_url": "https://api.github.com/users/scribu/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Postgres is actually right in this case, and this isn't a bug in peewee. It looks like the value returned by the attribute lookup is not numeric. You can cast it, but you have to cast both return values it seems.\n\nOne way that seemed to work was:\n\n``` sql\nSELECT \nCASE \"t1\".\"price_info\"->>'currency' \nWHEN 'EUR' THEN (\"t1\".\"price_info\"->>'value')::float \nWHEN 'RON' THEN ((\"t1\".\"price_info\"->>'value')::float * 1.5) \nEND AS price \nFROM \"xxtest\" AS t1;\n```\n\nTo accomplish this with peewee, you can do something like this. It's not super elegant, but it should work.\n\n``` python\nfrom peewee import Clause, SQL, fn\n\ndef to_float(node):\n return fn.CAST(Clause(node, SQL('AS float')))\n\nprice = case(\n Posting.price_info['currency'],\n (\n ('EUR', to_float(Posting.price_info['value'])),\n ('RON', to_float(Posting.price_info['value']) * 1.5),\n )\n).alias('price')\n```\n", "With 73cfdc1824f4161db062fc74fc77a5a13660888e it should be possible to now write:\n\n```\nprice = case(\n Posting.price_info['currency'],\n (\n ('EUR', Posting.price_info['value'].cast('float')),\n ('RON', Posting.price_info['value'].cast('float') / ONE_EURO_IN_RON)\n )\n).alias('price')\n```\n", "Works! Thanks for the syntax sugar.\n" ]
2015-11-02T17:51:51
2015-11-03T15:09:43
2015-11-02T20:55:01
NONE
null
Here's my simplified model: ``` python from peewee import * from playhouse.postgres_ext import * db = PostgresqlExtDatabase('mobster') class Posting(BaseModel): class Meta: database = db price_info = JSONField() ``` And here's a query I'm trying to make: ``` python from playhouse.shortcuts import case ONE_EURO_IN_RON = 4.4407 price = case( Posting.price_info['currency'], ( ('EUR', Posting.price_info['value']), ('RON', Posting.price_info['value'] / ONE_EURO_IN_RON) ) ).alias('price') query = Posting.select(price) postings = list(query) ``` And here's the error: ``` DataError: invalid input syntax for type numeric: "value" LINE 1: ...o"->>'value' WHEN 'RON' THEN ("t1"."price_info"->>'value' / ... ``` Full query info: ``` <class 'Posting'> SELECT CASE "t1"."price_info"->>%s WHEN %s THEN "t1"."price_info"->>%s WHEN %s THEN ("t1"."price_info"->>%s / %s) END AS price FROM "posting" AS t1 ['currency', 'EUR', 'value', 'RON', 'value', 4.4407] ``` Versions: - Postgres 9.4.4 - psycopg2 2.6.1 - peewee 2.6.4
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/745/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/745/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/744
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/744/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/744/comments
https://api.github.com/repos/coleifer/peewee/issues/744/events
https://github.com/coleifer/peewee/pull/744
114,598,358
MDExOlB1bGxSZXF1ZXN0NDk0MzM2ODc=
744
readme: typo on irc.freenode hostname
{ "login": "franciscod", "id": 726447, "node_id": "MDQ6VXNlcjcyNjQ0Nw==", "avatar_url": "https://avatars.githubusercontent.com/u/726447?v=4", "gravatar_id": "", "url": "https://api.github.com/users/franciscod", "html_url": "https://github.com/franciscod", "followers_url": "https://api.github.com/users/franciscod/followers", "following_url": "https://api.github.com/users/franciscod/following{/other_user}", "gists_url": "https://api.github.com/users/franciscod/gists{/gist_id}", "starred_url": "https://api.github.com/users/franciscod/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/franciscod/subscriptions", "organizations_url": "https://api.github.com/users/franciscod/orgs", "repos_url": "https://api.github.com/users/franciscod/repos", "events_url": "https://api.github.com/users/franciscod/events{/privacy}", "received_events_url": "https://api.github.com/users/franciscod/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Thank you!\n", "np! :)\n" ]
2015-11-02T13:55:48
2015-11-14T05:12:42
2015-11-02T14:51:03
CONTRIBUTOR
null
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/744/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/744/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/744", "html_url": "https://github.com/coleifer/peewee/pull/744", "diff_url": "https://github.com/coleifer/peewee/pull/744.diff", "patch_url": "https://github.com/coleifer/peewee/pull/744.patch", "merged_at": "2015-11-02T14:51:03" }
https://api.github.com/repos/coleifer/peewee/issues/743
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/743/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/743/comments
https://api.github.com/repos/coleifer/peewee/issues/743/events
https://github.com/coleifer/peewee/pull/743
114,488,094
MDExOlB1bGxSZXF1ZXN0NDkzNzg4OTE=
743
Foreign key to the composite primary key
{ "login": "Maillol", "id": 2394534, "node_id": "MDQ6VXNlcjIzOTQ1MzQ=", "avatar_url": "https://avatars.githubusercontent.com/u/2394534?v=4", "gravatar_id": "", "url": "https://api.github.com/users/Maillol", "html_url": "https://github.com/Maillol", "followers_url": "https://api.github.com/users/Maillol/followers", "following_url": "https://api.github.com/users/Maillol/following{/other_user}", "gists_url": "https://api.github.com/users/Maillol/gists{/gist_id}", "starred_url": "https://api.github.com/users/Maillol/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/Maillol/subscriptions", "organizations_url": "https://api.github.com/users/Maillol/orgs", "repos_url": "https://api.github.com/users/Maillol/repos", "events_url": "https://api.github.com/users/Maillol/events{/privacy}", "received_events_url": "https://api.github.com/users/Maillol/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I've waffled about this some. I dislike implicitly creating the columns. Additionally, when querying, things seem like they might get a little weird, e.g.:\n\n``` python\nclass Person(Model):\n first_name = CharField()\n last_name = CharField()\n class Meta:\n primary_key = CompositeKey('first_name', 'last_name')\n\n# API from your PR:\nclass Pet(Model):\n owner = ForeignKeyField(Person)\n\n# API I had considered:\nclass Pet(Model):\n owner_first_name = CharField()\n owner_last_name = CharField()\n owner = CompositeForeignKey(Person)\n```\n\nEach has its downsides. In the former, the related person's first and last name, which are present on the Pet, are abstracted away and not easily accessible. In the latter, I'm left wondering how useful that `owner` attribute is really going to be.\n", "I agree with you, creating columns must be explicit.\n\ncurrently the problem appear when we want create a weak entity which contains an other weak entity. \ni.e:\nBook -> Chapter -> Paragraph \nor\nTrain -> Wagon -> Seat\n\nThe PK Wagon is (PK train + num Wagon) and PK Seat is (PK train + num Wagon + num Seat).\nThe Wagon num field isn't unique, I can't create a foreign key on it, I must use composite FK. \n\nWhat do you think about API like this ?\n\n``` python\nclass Pet(Model):\n owner_first_name = ForeignKey(Person, first_name)\n owner_last_name = ForeignKey(Person, last_name)\n\n class Meta:\n foreign_keys = [\n CompositeKey(owner_first_name, owner_last_name)\n ]\n```\n", "> What do you think about API like this ?\n\nThat would be confusing I think. By making `owner_first_name` and `owner_last_name` ForeignKeyFields, it is unclear what value you are supposed to assign to them. Typically with a foreign key field you would assign the related model instance (although it is possible to assign the underyling scalar key value). This \"overloads\" the concept of foreign keys in a way I find ambiguous.\n\nIf there were going to be an API, it would be this most likely:\n\n``` python\nclass Pet(Model):\n owner_first_name = CharField()\n owner_last_name = CharField()\n owner = CompositeForeignKey(Person)\n```\n\nBut as I said I have doubts about the utility of this.\n\nI think that for now I am going to close this as _wontfix_, since there doesn't seem to me to be a clear path forward. You can specify table-level constraints as model meta options, so if you want schema-level referential integrity, you can do something like:\n\n``` python\nclass Pet(Model):\n owner_first_name = CharField()\n owner_last_name = CharField()\n\n class Meta:\n constraints = [SQL('FOREIGN KEY(owner_first, owner_last) REFERENCES person(first, last)')]\n```\n", "Documentation: http://docs.peewee-orm.com/en/latest/peewee/models.html#indexes-and-constraints\n" ]
2015-11-01T19:38:36
2015-11-07T05:34:39
2015-11-07T05:34:05
NONE
null
Create unit test in order to reproduce bug when we create foreign key to the composite primary key.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/743/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/743/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/743", "html_url": "https://github.com/coleifer/peewee/pull/743", "diff_url": "https://github.com/coleifer/peewee/pull/743.diff", "patch_url": "https://github.com/coleifer/peewee/pull/743.patch", "merged_at": null }
https://api.github.com/repos/coleifer/peewee/issues/742
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/742/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/742/comments
https://api.github.com/repos/coleifer/peewee/issues/742/events
https://github.com/coleifer/peewee/pull/742
114,443,759
MDExOlB1bGxSZXF1ZXN0NDkzNjMxODg=
742
Remove extraneous replacement field
{ "login": "bakemecookies", "id": 2167033, "node_id": "MDQ6VXNlcjIxNjcwMzM=", "avatar_url": "https://avatars.githubusercontent.com/u/2167033?v=4", "gravatar_id": "", "url": "https://api.github.com/users/bakemecookies", "html_url": "https://github.com/bakemecookies", "followers_url": "https://api.github.com/users/bakemecookies/followers", "following_url": "https://api.github.com/users/bakemecookies/following{/other_user}", "gists_url": "https://api.github.com/users/bakemecookies/gists{/gist_id}", "starred_url": "https://api.github.com/users/bakemecookies/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/bakemecookies/subscriptions", "organizations_url": "https://api.github.com/users/bakemecookies/orgs", "repos_url": "https://api.github.com/users/bakemecookies/repos", "events_url": "https://api.github.com/users/bakemecookies/events{/privacy}", "received_events_url": "https://api.github.com/users/bakemecookies/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[]
2015-11-01T01:18:26
2015-11-01T02:16:10
2015-11-01T02:16:10
CONTRIBUTOR
null
There is a mismatch between the number of arguments (two) and the number of fields (three) and the sample output implies that there is an unnecessary replacement field in the format string.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/742/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/742/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/742", "html_url": "https://github.com/coleifer/peewee/pull/742", "diff_url": "https://github.com/coleifer/peewee/pull/742.diff", "patch_url": "https://github.com/coleifer/peewee/pull/742.patch", "merged_at": "2015-11-01T02:16:10" }
https://api.github.com/repos/coleifer/peewee/issues/741
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/741/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/741/comments
https://api.github.com/repos/coleifer/peewee/issues/741/events
https://github.com/coleifer/peewee/issues/741
113,862,248
MDU6SXNzdWUxMTM4NjIyNDg=
741
Issue with `test_database()` helper
{ "login": "coleifer", "id": 119974, "node_id": "MDQ6VXNlcjExOTk3NA==", "avatar_url": "https://avatars.githubusercontent.com/u/119974?v=4", "gravatar_id": "", "url": "https://api.github.com/users/coleifer", "html_url": "https://github.com/coleifer", "followers_url": "https://api.github.com/users/coleifer/followers", "following_url": "https://api.github.com/users/coleifer/following{/other_user}", "gists_url": "https://api.github.com/users/coleifer/gists{/gist_id}", "starred_url": "https://api.github.com/users/coleifer/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/coleifer/subscriptions", "organizations_url": "https://api.github.com/users/coleifer/orgs", "repos_url": "https://api.github.com/users/coleifer/repos", "events_url": "https://api.github.com/users/coleifer/events{/privacy}", "received_events_url": "https://api.github.com/users/coleifer/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "The code indicates that `create_tables=True`:\n\n``` python\nclass test_database(object):\n def __init__(self, db, models, create_tables=True, drop_tables=True,\n fail_silently=False):\n self.db = db\n self.models = models\n self.create_tables = create_tables\n self.drop_tables = drop_tables\n self.fail_silently = fail_silently\n```\n\nThis issue seems invalid.\n" ]
2015-10-28T16:31:40
2015-10-29T00:23:19
2015-10-29T00:23:19
OWNER
null
VIA: http://stackoverflow.com/a/33346767/254346 When using `test_database` I encountered problems with `test_db` not being initialized: ``` nose.proxy.Exception: Error, database not properly initialized before opening connection -------------------- >> begin captured logging << -------------------- peewee: DEBUG: ('SELECT "t1"."id", "t1"."name", "t1"."count" FROM "counter" AS t1', []) --------------------- >> end captured logging << --------------------- ``` I eventually fixed this by passing `create_tables=True` like so: ``` python def test_timeline(self): with test_database(test_db, (User, Tweet), create_tables=True): # This data will be created in `test_db` self.create_test_data() ``` According to [the docs](http://docs.peewee-orm.com/en/latest/peewee/playhouse.html#test-utils) `create_tables` should default to `True` but it seems that isn't the case in the latest release of `peewee`.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/741/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/741/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/740
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/740/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/740/comments
https://api.github.com/repos/coleifer/peewee/issues/740/events
https://github.com/coleifer/peewee/issues/740
113,853,207
MDU6SXNzdWUxMTM4NTMyMDc=
740
Foreign key collision regarding related_name
{ "login": "dzeban", "id": 230409, "node_id": "MDQ6VXNlcjIzMDQwOQ==", "avatar_url": "https://avatars.githubusercontent.com/u/230409?v=4", "gravatar_id": "", "url": "https://api.github.com/users/dzeban", "html_url": "https://github.com/dzeban", "followers_url": "https://api.github.com/users/dzeban/followers", "following_url": "https://api.github.com/users/dzeban/following{/other_user}", "gists_url": "https://api.github.com/users/dzeban/gists{/gist_id}", "starred_url": "https://api.github.com/users/dzeban/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/dzeban/subscriptions", "organizations_url": "https://api.github.com/users/dzeban/orgs", "repos_url": "https://api.github.com/users/dzeban/repos", "events_url": "https://api.github.com/users/dzeban/events{/privacy}", "received_events_url": "https://api.github.com/users/dzeban/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I wouldn't consider this an error per se, just a quirk of the way peewee does backref validation. If you want to suppress the error, just declare your model with `validate_backrefs = False`:\n\n``` python\nclass Entry(BaseModel):\n class Meta:\n validate_backrefs = False\n```\n" ]
2015-10-28T15:50:52
2015-10-29T00:19:41
2015-10-29T00:19:41
NONE
null
I have 2 tables ``` sql CREATE TABLE "Feed" ( id serial NOT NULL, url text, CONSTRAINT "Feed_pkey" PRIMARY KEY (id) ) CREATE TABLE "Entry" ( id serial NOT NULL, link text, feed_id integer, CONSTRAINT "Entry_pkey" PRIMARY KEY (id), CONSTRAINT "Entry_feed_id_fkey" FOREIGN KEY (feed_id) REFERENCES "Feed" (id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION ) ``` Next I'm generating models with pwiz: ``` python from peewee import * database = PostgresqlDatabase('test', **{'host': 'localhost', 'user': 'ribbo'}) class UnknownField(object): pass class BaseModel(Model): class Meta: database = database class Feed(BaseModel): url = TextField(null=True) class Meta: db_table = 'Feed' class Entry(BaseModel): feed = ForeignKeyField(db_column='feed_id', null=True, rel_model=Feed, to_field='id') link = TextField(null=True) class Meta: db_table = 'Entry' ``` But when I'm subclassing on Entry I get the error: ``` python $ cat Entry.py from models import database from models import Entry as EntryModel class Entry(EntryModel): myattr = 'somestring' def some(): print('Hi') e = Entry() ``` ``` $ python3 Entry.py Traceback (most recent call last): File "Entry.py", line 4, in <module> class Entry(EntryModel): File "/usr/lib/python3.4/site-packages/peewee.py", line 4224, in __new__ field.add_to_class(cls, name) File "/usr/lib/python3.4/site-packages/peewee.py", line 1250, in add_to_class self.model_class._meta.name, self.name, self.related_name)) AttributeError: Foreign key: entry.feed related name "entry_set" collision with foreign key using same related_name. ``` The fun part is that if I change `class Entry(EntryModel)` class name to `class Entry2(EntryModel)` problem disappears.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/740/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/740/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/739
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/739/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/739/comments
https://api.github.com/repos/coleifer/peewee/issues/739/events
https://github.com/coleifer/peewee/issues/739
113,455,460
MDU6SXNzdWUxMTM0NTU0NjA=
739
Ability to verify inputs based on field type
{ "login": "kostasdizas", "id": 254960, "node_id": "MDQ6VXNlcjI1NDk2MA==", "avatar_url": "https://avatars.githubusercontent.com/u/254960?v=4", "gravatar_id": "", "url": "https://api.github.com/users/kostasdizas", "html_url": "https://github.com/kostasdizas", "followers_url": "https://api.github.com/users/kostasdizas/followers", "following_url": "https://api.github.com/users/kostasdizas/following{/other_user}", "gists_url": "https://api.github.com/users/kostasdizas/gists{/gist_id}", "starred_url": "https://api.github.com/users/kostasdizas/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/kostasdizas/subscriptions", "organizations_url": "https://api.github.com/users/kostasdizas/orgs", "repos_url": "https://api.github.com/users/kostasdizas/repos", "events_url": "https://api.github.com/users/kostasdizas/events{/privacy}", "received_events_url": "https://api.github.com/users/kostasdizas/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Peewee does not do any validation. The field's value is converted (if necessary) when the field is used in a query. When reading values from a cursor, the value is converted to Python when the model object is created.\n\nI suppose you could add validation of some kind to your fields, but that would exist outside of peewee.\n" ]
2015-10-26T21:30:16
2015-10-27T00:20:57
2015-10-27T00:20:57
NONE
null
Hello, is it possible to verify whether a value is appropriate for a specific field? Is there a comparison/verification function? Is the equivalent primitive type stored somewhere in the field type (after a very quick search I didn't find one) in order to compare it with the type of the input value? What's the best way to achieve that?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/739/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/739/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/738
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/738/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/738/comments
https://api.github.com/repos/coleifer/peewee/issues/738/events
https://github.com/coleifer/peewee/issues/738
113,148,177
MDU6SXNzdWUxMTMxNDgxNzc=
738
create_tables() fails
{ "login": "timeyyy", "id": 6135075, "node_id": "MDQ6VXNlcjYxMzUwNzU=", "avatar_url": "https://avatars.githubusercontent.com/u/6135075?v=4", "gravatar_id": "", "url": "https://api.github.com/users/timeyyy", "html_url": "https://github.com/timeyyy", "followers_url": "https://api.github.com/users/timeyyy/followers", "following_url": "https://api.github.com/users/timeyyy/following{/other_user}", "gists_url": "https://api.github.com/users/timeyyy/gists{/gist_id}", "starred_url": "https://api.github.com/users/timeyyy/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/timeyyy/subscriptions", "organizations_url": "https://api.github.com/users/timeyyy/orgs", "repos_url": "https://api.github.com/users/timeyyy/repos", "events_url": "https://api.github.com/users/timeyyy/events{/privacy}", "received_events_url": "https://api.github.com/users/timeyyy/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "You can pass `safe=True` and Peewee will not try to create it if it already exists.\n" ]
2015-10-24T09:48:51
2015-10-25T18:20:40
2015-10-25T18:20:40
NONE
null
on a sqlitedatabase, using create_tables() results in a peewee.OperationalError, table xyz already exists, i am able to create the tables if i use create_tables()
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/738/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/738/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/737
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/737/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/737/comments
https://api.github.com/repos/coleifer/peewee/issues/737/events
https://github.com/coleifer/peewee/issues/737
113,062,499
MDU6SXNzdWUxMTMwNjI0OTk=
737
peewee.IntegrityError: (1452, 'Cannot add or update a child row: a foreign key constraint fails (test_peewee_tree.node, CONSTRAINT node_ibfk_1 FOREIGN KEY (parent_id) REFERENCES node (id))') db = MySQLDatabase
{ "login": "slukin1", "id": 3098561, "node_id": "MDQ6VXNlcjMwOTg1NjE=", "avatar_url": "https://avatars.githubusercontent.com/u/3098561?v=4", "gravatar_id": "", "url": "https://api.github.com/users/slukin1", "html_url": "https://github.com/slukin1", "followers_url": "https://api.github.com/users/slukin1/followers", "following_url": "https://api.github.com/users/slukin1/following{/other_user}", "gists_url": "https://api.github.com/users/slukin1/gists{/gist_id}", "starred_url": "https://api.github.com/users/slukin1/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/slukin1/subscriptions", "organizations_url": "https://api.github.com/users/slukin1/orgs", "repos_url": "https://api.github.com/users/slukin1/repos", "events_url": "https://api.github.com/users/slukin1/events{/privacy}", "received_events_url": "https://api.github.com/users/slukin1/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Uhh, did you make the `parent` foreign key nullable? This looks like a data integrity error rather than peewee.\n", "Yes, parent foreign ey made nullable:\n\n``` python\nmysql_db = MySQLDatabase('test_peewee_tree')\nclass BaseModel(Model):\nclass Meta:\n database = mysql_db\nclass Node(BaseModel):\n label = CharField()\n parent = ForeignKeyField('self', default=0)\n left = IntegerField(default=0)\n right = IntegerField(default=1)\n depth = IntegerField(default=0)\ndef get_parent(self, level=1):\n parent = self\n for i in range(level):\n parent = parent.parent\n return parent\nif __name__ == '__main__':\n\n Node.create_table()\n\n n1 = Node(label='root')\n n2 = Node(label='a')\n n3 = Node(label='b')\n n4 = Node(label='c')\n n1.append(n2)\n n1.append(n3)\n n2.append(n4)\n```\n", "Same peewee.IntegrityError: (1452....\nif changed to\nparent = ForeignKeyField('self', default=0, null = True)\nor\nparent = ForeignKeyField('self', db_column='parent_id', default=0, null = True)\n", "No error peewee.IntegrityError: (1452...\nwith peewee version 2.2.4 and parent = ForeignKeyField('self', null = True)\n", "With parent = ForeignKeyField('self', default=None, null=True) works well if peewee version 2.2.4\nbut with peewee version 2.6.4 error:\nrow = self.select().where(self.pk_expr()).first()\nAttributeError: 'Node' object has no attribute 'pk_expr'\n", "It's very difficult to read your comments as you have not bothered to format the code. I edited one of your comments so you can see how to do it.\n\nFor what it's worth, 2.2.4 is quite old (about a year and a half). Where is the `row = self.select().where(self.pk_expr())` coming from?\n", "I use hierarchical models in a couple places as well as in the test suite. The right way to do it is\n\n``` python\nparent = ForeignKeyField('self', null=True)\n```\n\nIf you aren't re-creating your tables every time you change the field then just changing the Python field deifnition won't alter the underlying schema which may have a not-null constraint.\n", "For peewee version 2.6.4:\nself.pk_expr() => self._pk_expr() # pk -> _pk\n" ]
2015-10-23T17:18:00
2015-10-26T07:06:32
2015-10-26T07:06:32
NONE
null
peewee.IntegrityError: (1452, 'Cannot add or update a child row: a foreign key constraint fails (test_peewee_tree.node, CONSTRAINT node_ibfk_1 FOREIGN KEY (parent_id) REFERENCES node (id))') db = MySQLDatabase
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/737/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/737/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/736
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/736/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/736/comments
https://api.github.com/repos/coleifer/peewee/issues/736/events
https://github.com/coleifer/peewee/issues/736
112,969,256
MDU6SXNzdWUxMTI5NjkyNTY=
736
psycopg2.InternalError when skipping duplicate records
{ "login": "dzeban", "id": 230409, "node_id": "MDQ6VXNlcjIzMDQwOQ==", "avatar_url": "https://avatars.githubusercontent.com/u/230409?v=4", "gravatar_id": "", "url": "https://api.github.com/users/dzeban", "html_url": "https://github.com/dzeban", "followers_url": "https://api.github.com/users/dzeban/followers", "following_url": "https://api.github.com/users/dzeban/following{/other_user}", "gists_url": "https://api.github.com/users/dzeban/gists{/gist_id}", "starred_url": "https://api.github.com/users/dzeban/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/dzeban/subscriptions", "organizations_url": "https://api.github.com/users/dzeban/orgs", "repos_url": "https://api.github.com/users/dzeban/repos", "events_url": "https://api.github.com/users/dzeban/events{/privacy}", "received_events_url": "https://api.github.com/users/dzeban/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "You need to recover, as your connection is in a bad state after the integrity error. One way is to write:\n\n``` python\n try:\n with database.atomic():\n Feed.create(**d)\n except peewee.IntegrityError:\n print('Skipping duplicate')\n```\n\nWrapping it this way will roll back the transaction in the event things get wild.\n" ]
2015-10-23T07:43:10
2015-10-25T14:40:30
2015-10-25T14:40:30
NONE
null
Fedora 22 Python 3.4.2 Peewee version 2.6.4 PostgreSQL 9.4 I have a simple table with pwiz generated model ``` python from peewee import * database = PostgresqlDatabase('ribbo', **{'password': 'secret', 'host': 'localhost', 'user': 'ribbo'}) class UnknownField(object): pass class BaseModel(Model): class Meta: database = database class Feed(BaseModel): description = TextField(null=True) htmlurl = TextField(null=True) title = TextField(null=True) url = TextField(null=True) class Meta: db_table = 'feed' ``` `url` field has unique constraint ``` sql CONSTRAINT feed_url_key UNIQUE (url) ``` Now I'm trying to insert feeds with the following code ``` python #!/usr/bin/env python3 from models import * import peewee import sys def makedict(i): return {'url': str(i), 'title': 'foo', 'description': 'bar'} for i in range(10): d = makedict(i) print('Trying to insert {}'.format(d)) try: Feed.create(**d) except peewee.IntegrityError: print('Skipping duplicate') ``` First round it's good: ``` $ python3 peewee-bug.py Trying to insert {'url': '0', 'description': 'bar', 'title': 'foo'} Trying to insert {'url': '1', 'description': 'bar', 'title': 'foo'} Trying to insert {'url': '2', 'description': 'bar', 'title': 'foo'} Trying to insert {'url': '3', 'description': 'bar', 'title': 'foo'} Trying to insert {'url': '4', 'description': 'bar', 'title': 'foo'} Trying to insert {'url': '5', 'description': 'bar', 'title': 'foo'} Trying to insert {'url': '6', 'description': 'bar', 'title': 'foo'} Trying to insert {'url': '7', 'description': 'bar', 'title': 'foo'} Trying to insert {'url': '8', 'description': 'bar', 'title': 'foo'} Trying to insert {'url': '9', 'description': 'bar', 'title': 'foo'} ``` But on the second round it fails like this: ``` $ python3 peewee-bug.py Trying to insert {'title': 'foo', 'description': 'bar', 'url': '0'} Skipping duplicate Trying to insert {'title': 'foo', 'description': 'bar', 'url': '1'} Traceback (most recent call last): File "/usr/lib/python3.4/site-packages/peewee.py", line 3331, in execute_sql cursor.execute(sql, params or ()) psycopg2.InternalError: current transaction is aborted, commands ignored until end of transaction block During handling of the above exception, another exception occurred: Traceback (most recent call last): File "peewee-bug.py", line 13, in <module> Feed.create(**d) File "/usr/lib/python3.4/site-packages/peewee.py", line 4289, in create inst.save(force_insert=True) File "/usr/lib/python3.4/site-packages/peewee.py", line 4461, in save pk_from_cursor = self.insert(**field_dict).execute() File "/usr/lib/python3.4/site-packages/peewee.py", line 3113, in execute cursor = self._execute() File "/usr/lib/python3.4/site-packages/peewee.py", line 2535, in _execute return self.database.execute_sql(sql, params, self.require_commit) File "/usr/lib/python3.4/site-packages/peewee.py", line 3339, in execute_sql self.commit() File "/usr/lib/python3.4/site-packages/peewee.py", line 3185, in __exit__ reraise(new_type, new_type(*exc_args), traceback) File "/usr/lib/python3.4/site-packages/peewee.py", line 123, in reraise raise value.with_traceback(tb) File "/usr/lib/python3.4/site-packages/peewee.py", line 3331, in execute_sql cursor.execute(sql, params or ()) peewee.InternalError: current transaction is aborted, commands ignored until end of transaction block ``` Note, that exception occurs only after first row was skipped. So, I understand that it fails because I skip iteration and not do proper cleanup in exception. So is there anything I can do in exception handler to properly skip duplicate row? If I change constraint to be deferred ``` sql CONSTRAINT feed_url_key UNIQUE (url) DEFERRABLE INITIALLY DEFERRED ``` it works well all the time, so I might be just stick to it, but anyway I would like to know other ways. Thanks.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/736/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/736/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/735
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/735/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/735/comments
https://api.github.com/repos/coleifer/peewee/issues/735/events
https://github.com/coleifer/peewee/pull/735
112,678,881
MDExOlB1bGxSZXF1ZXN0NDgzODc3Nzc=
735
adding a .collate_nocase() query feature
{ "login": "aerickson", "id": 47889, "node_id": "MDQ6VXNlcjQ3ODg5", "avatar_url": "https://avatars.githubusercontent.com/u/47889?v=4", "gravatar_id": "", "url": "https://api.github.com/users/aerickson", "html_url": "https://github.com/aerickson", "followers_url": "https://api.github.com/users/aerickson/followers", "following_url": "https://api.github.com/users/aerickson/following{/other_user}", "gists_url": "https://api.github.com/users/aerickson/gists{/gist_id}", "starred_url": "https://api.github.com/users/aerickson/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/aerickson/subscriptions", "organizations_url": "https://api.github.com/users/aerickson/orgs", "repos_url": "https://api.github.com/users/aerickson/repos", "events_url": "https://api.github.com/users/aerickson/events{/privacy}", "received_events_url": "https://api.github.com/users/aerickson/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I guess this is unnecessary and only works on Sqlite.\n\nfn.Lower() seems to work fine.\n\n```\norder_by(fn.Lower(Object.name))\n```\n", "Yeah you can also do:\n\n.order_by(Clause(Model.field, SQL(' collate nocase')))\n" ]
2015-10-21T21:06:31
2015-10-21T21:55:58
2015-10-21T21:55:58
NONE
null
Please let me know if you'd like me to make test and/or documentation changes. Usage example: ``` order_by(Object.name).collate_nocase() ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/735/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/735/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/735", "html_url": "https://github.com/coleifer/peewee/pull/735", "diff_url": "https://github.com/coleifer/peewee/pull/735.diff", "patch_url": "https://github.com/coleifer/peewee/pull/735.patch", "merged_at": null }
https://api.github.com/repos/coleifer/peewee/issues/734
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/734/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/734/comments
https://api.github.com/repos/coleifer/peewee/issues/734/events
https://github.com/coleifer/peewee/pull/734
112,504,987
MDExOlB1bGxSZXF1ZXN0NDgyODQ0NTA=
734
Enable automated testing with Python 3.5
{ "login": "felixonmars", "id": 1006477, "node_id": "MDQ6VXNlcjEwMDY0Nzc=", "avatar_url": "https://avatars.githubusercontent.com/u/1006477?v=4", "gravatar_id": "", "url": "https://api.github.com/users/felixonmars", "html_url": "https://github.com/felixonmars", "followers_url": "https://api.github.com/users/felixonmars/followers", "following_url": "https://api.github.com/users/felixonmars/following{/other_user}", "gists_url": "https://api.github.com/users/felixonmars/gists{/gist_id}", "starred_url": "https://api.github.com/users/felixonmars/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/felixonmars/subscriptions", "organizations_url": "https://api.github.com/users/felixonmars/orgs", "repos_url": "https://api.github.com/users/felixonmars/repos", "events_url": "https://api.github.com/users/felixonmars/events{/privacy}", "received_events_url": "https://api.github.com/users/felixonmars/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Thanks!\n" ]
2015-10-21T03:28:04
2015-10-21T13:28:17
2015-10-21T13:28:05
CONTRIBUTOR
null
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/734/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/734/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/734", "html_url": "https://github.com/coleifer/peewee/pull/734", "diff_url": "https://github.com/coleifer/peewee/pull/734.diff", "patch_url": "https://github.com/coleifer/peewee/pull/734.patch", "merged_at": "2015-10-21T13:28:05" }
https://api.github.com/repos/coleifer/peewee/issues/733
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/733/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/733/comments
https://api.github.com/repos/coleifer/peewee/issues/733/events
https://github.com/coleifer/peewee/issues/733
112,467,864
MDU6SXNzdWUxMTI0Njc4NjQ=
733
Problem with alias when joining subquery
{ "login": "srolija", "id": 307150, "node_id": "MDQ6VXNlcjMwNzE1MA==", "avatar_url": "https://avatars.githubusercontent.com/u/307150?v=4", "gravatar_id": "", "url": "https://api.github.com/users/srolija", "html_url": "https://github.com/srolija", "followers_url": "https://api.github.com/users/srolija/followers", "following_url": "https://api.github.com/users/srolija/following{/other_user}", "gists_url": "https://api.github.com/users/srolija/gists{/gist_id}", "starred_url": "https://api.github.com/users/srolija/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/srolija/subscriptions", "organizations_url": "https://api.github.com/users/srolija/orgs", "repos_url": "https://api.github.com/users/srolija/repos", "events_url": "https://api.github.com/users/srolija/events{/privacy}", "received_events_url": "https://api.github.com/users/srolija/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "What exactly is your query supposed to be calculating? It seems odd that you've got a `group_by(Scan.code)` but no aggregation. Additionally, you're explicitly selecting all the columns from `Scan` in your subquery. Typically when grouping you select only the column(s) that you want to group by.\n\nTo get tickets with confirmed scans, you could write:\n\n``` python\nexists = fn.EXISTS(Scan.select().where((Scan.confirmed == True) & (Scan.code == Ticket.code)))\nquery = Ticket.select(Ticket, exists.alias('confirmed_scan'))\nfor ticket in query:\n print ticket.code, ticket.confirmed_scan\n```\n\nAnother way would be:\n\n``` python\nconfirmed = fn.COUNT(Scan.id).alias('confirmed')\nquery = Ticket.select(Ticket, confirmed).join(\n Scan, JOIN.LEFT_OUTER, on=(\n (Ticket.code == Scan.code) &\n (Scan.confirmed == True))).group_by(Ticket)\nfor ticket in query:\n print ticket.code, ticket.confirmed\n```\n", "My query should return all records that are confirmed joined with their scan information, since there is slight chance that record could be scanned as confirmed twice (and without confirmation many times - both of those by design) I am grouping them together since I need only to know whether it was confirmed and if it was when (additional field on Scan). Records that are not confirmed or do not have matching scan at all shouldn't be joined with anything but should be returned in resulting dataset (having scan field equal to None).\n\nI do know how to work around this problem using two queries (which works for my needs):\n\n```\nq1 = Ticket.select(Ticket, Scan) \\\n .join(Scan, peewee.JOIN.LEFT_OUTER, on=(Ticket.code == Scan.code).alias(\"scan\")) \\\n .where((Ticket.event == self) & (Scan.confirmed == True)) \\\n .group_by(Ticket.code)\n\nsq = Scan.select(Scan.code).where((Scan.event == self) & (Scan.confirmed == True)).alias()\nq2 = Ticket.select(Ticket, Scan) \\\n .join(Scan, peewee.JOIN.LEFT_OUTER, on=(Ticket.code == Scan.code).alias(\"scan\")) \\\n .where((Ticket.event == self) & (~(Ticket.code << sq))) \\\n .group_by(Ticket.code)\n```\n\nHowever I would expect query from my original post to work, since it seemed logical (given how API is generaly nice) that one could join subquery in given way.\n\nDon't know if it helps but raw SQL would be something like (and yes, I do need all fields of both ticket and scan):\n\n```\nSELECT * FROM \"ticket\" AS t1 \nLEFT OUTER JOIN (\n SELECT * FROM \"scan\" AS t3 \n WHERE (t3.confirmed = 1) \n GROUP BY t3.code\n) AS x \nON (t1.code = x.code) \nGROUP BY t1.code\n```\n\nHowever I do not know way how to execute given query using Ticket.raw to make scan data available (using .scan or similar notaion) when result contains it.\n\nThank you for support and for great library! :)\n", "Did you try either of the example queries I included in my above comment? Both of those should get you where you need to be, or at least get you most of the way there.\n\nI still think that the way you're grouping in the join query is incorrect. If a column is selected and is not an aggregate, it should technically be included in the grouping.\n", "Yes.\nBoth would work if I just wanted to know whether item is confirmed and I didn't need additional fields that are on Scan model (for simplicity and since it wasn't needed to demonstrate what I thought was an issue I didn't include all fields that models contain just ones used in query).\n\nItems are grouped that way since if ticket does have confirmed scan I do not care which one it is (it is expected that all but one of confirmed scans will be ignored this way) since I can use its details to respond to request.\n\nMain reason for opening this ticket was because I thought that it is possible to do select and then do join on it as on subquery (and still be able to access additional data from subquery using aliased name).\n", "Then you should be able to write:\n\n``` python\nquery = (Ticket\n .select(Ticket, Scan, confirmed)\n .join(\n Scan,\n JOIN.LEFT_OUTER,\n on=(\n (Ticket.code == Scan.code) &\n (Scan.confirmed == True)).alias('scan_obj'))\n .group_by(Ticket))\n\nfor ticket in query:\n print ticket.code, ticket.scan_obj.code, ticket.scan_obj.confirmed, ticket.confirmed\n```\n", "Fantastic, that was exactly what I wanted to do, but did not know that it is possible to use alias on multiple conditions when using it as join on parameter.\n\nThank you very much!\n", "Awesome! Glad to help\nOn Oct 23, 2015 4:48 PM, \"Sergej Jakovljev\" [email protected]\nwrote:\n\n> Fantastic, that was exactly what I wanted to do, but did not know that it\n> is possible to use alias on multiple conditions when using it as join on\n> parameter.\n> \n> Thank you very much!\n> \n> —\n> Reply to this email directly or view it on GitHub\n> https://github.com/coleifer/peewee/issues/733#issuecomment-150701209.\n" ]
2015-10-20T21:50:13
2015-10-23T21:49:33
2015-10-21T01:41:50
NONE
null
Maybe I assume wrong that following sould work, but there seems to be a issue with alias when I join subquery with table. Since entire subquery will be inserted in SELECT and JOIN clause but should be only in JOIN. Following is simplified version that includes most basic form where I could show problem. ``` from peewee import Model, CharField, DateTimeField, ForeignKeyField, BooleanField import peewee database = peewee.SqliteDatabase("data2.db") class BaseModel(Model): class Meta: database = database class Ticket(BaseModel): code = CharField(max_length=16, index=True) class Scan(BaseModel): code = CharField(max_length=24) confirmed = BooleanField(default=True) database.create_tables([Ticket, Scan]) Ticket.create(code="a") Ticket.create(code="b") Ticket.create(code="c") Ticket.create(code="d") Scan.create(code="a", confirmed=True) Scan.create(code="a", confirmed=False) Scan.create(code="a", confirmed=False) Scan.create(code="b", confirmed=False) Scan.create(code="b", confirmed=False) Scan.create(code="c", confirmed=True) sq = Scan.select(Scan).where(Scan.confirmed == True).group_by(Scan.code) sq = sq.alias("x") q = Ticket.select(Ticket, sq) \ .join(sq, peewee.JOIN.LEFT_OUTER, on=(Ticket.code == sq.c.code).alias("scan")) \ .group_by(Ticket.code) for t in q: print(t.code + ": " + str(t.scan.confirmed)) ``` My attempt to fix it generates SQL that returns expected result set (all tickets joined only with confirmed scans), but it is not possible to access joined data (via t.scan, results in AttributeError) which in real models contain additional fields. ``` q = Ticket.select(peewee.SQL("*")) \ .join(sq, peewee.JOIN.LEFT_OUTER, on=(Ticket.code == sq.c.code).alias("scan")) \ .group_by(Ticket.code) ``` While I would expect it to output: ``` a: True b: None c: True d: None ``` Meanwhile following works as expected, but query is not the one I want, since it could do join a with scan whose confirmed=False while there do exist some with confirmed=True: ``` q = Ticket.select(Ticket, Scan) \ .join(Scan, peewee.JOIN.LEFT_OUTER, on=(Ticket.code == Scan.code).alias("scan")) \ .group_by(Ticket.code) ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/733/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/733/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/732
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/732/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/732/comments
https://api.github.com/repos/coleifer/peewee/issues/732/events
https://github.com/coleifer/peewee/pull/732
112,137,382
MDExOlB1bGxSZXF1ZXN0NDgwNjY4NjU=
732
Fix typo
{ "login": "bakemecookies", "id": 2167033, "node_id": "MDQ6VXNlcjIxNjcwMzM=", "avatar_url": "https://avatars.githubusercontent.com/u/2167033?v=4", "gravatar_id": "", "url": "https://api.github.com/users/bakemecookies", "html_url": "https://github.com/bakemecookies", "followers_url": "https://api.github.com/users/bakemecookies/followers", "following_url": "https://api.github.com/users/bakemecookies/following{/other_user}", "gists_url": "https://api.github.com/users/bakemecookies/gists{/gist_id}", "starred_url": "https://api.github.com/users/bakemecookies/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/bakemecookies/subscriptions", "organizations_url": "https://api.github.com/users/bakemecookies/orgs", "repos_url": "https://api.github.com/users/bakemecookies/repos", "events_url": "https://api.github.com/users/bakemecookies/events{/privacy}", "received_events_url": "https://api.github.com/users/bakemecookies/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Thanks!\n" ]
2015-10-19T12:48:37
2015-10-21T01:21:40
2015-10-21T01:21:37
CONTRIBUTOR
null
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/732/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/732/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/732", "html_url": "https://github.com/coleifer/peewee/pull/732", "diff_url": "https://github.com/coleifer/peewee/pull/732.diff", "patch_url": "https://github.com/coleifer/peewee/pull/732.patch", "merged_at": "2015-10-21T01:21:37" }
https://api.github.com/repos/coleifer/peewee/issues/731
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/731/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/731/comments
https://api.github.com/repos/coleifer/peewee/issues/731/events
https://github.com/coleifer/peewee/issues/731
112,040,899
MDU6SXNzdWUxMTIwNDA4OTk=
731
[Support Request] Threadlocals and pooled connections
{ "login": "alexlatchford", "id": 628146, "node_id": "MDQ6VXNlcjYyODE0Ng==", "avatar_url": "https://avatars.githubusercontent.com/u/628146?v=4", "gravatar_id": "", "url": "https://api.github.com/users/alexlatchford", "html_url": "https://github.com/alexlatchford", "followers_url": "https://api.github.com/users/alexlatchford/followers", "following_url": "https://api.github.com/users/alexlatchford/following{/other_user}", "gists_url": "https://api.github.com/users/alexlatchford/gists{/gist_id}", "starred_url": "https://api.github.com/users/alexlatchford/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/alexlatchford/subscriptions", "organizations_url": "https://api.github.com/users/alexlatchford/orgs", "repos_url": "https://api.github.com/users/alexlatchford/repos", "events_url": "https://api.github.com/users/alexlatchford/events{/privacy}", "received_events_url": "https://api.github.com/users/alexlatchford/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "> My question is once that thread completes the connection will be returned to the pool, since it's returned will it ever be picked up by any other thread? Or is it orphaned never to be used again?\n\nAre you calling `close()` from the thread, when it finishes?\n\nCan you share some code?\n", "I'm not explicitly calling it at the moment, looks like if you close it you get the desired behaviour.. I wrote up this testing script:\n\n``` python\nimport threading\nfrom time import sleep\nfrom peewee import *\nfrom playhouse.pool import PooledPostgresqlExtDatabase\n\n\ndb = PooledPostgresqlExtDatabase(None, max_connections=5, threadlocals=True, register_hstore=False)\ndb.init('peewee_test', host='localhost', user='postgres')\n\n\ncounter = 1\ncounter_lock = threading.Lock()\n\n\ndef num_connections(state):\n global counter\n\n with counter_lock:\n print counter, \" State: \", state, \" - Num conns: \", len(db._in_use), \\\n \" - Thread: \", threading.current_thread().name\n counter += 1\n\n\nclass MyModel(Model):\n name = CharField()\n\n class Meta:\n database = db\n\nnum_connections('start')\n\n# MyModel.create_table()\n\n# num_connections()\n\n# MyModel.create(name=\"Rosie\")\n\n# num_connections()\n\n# db.close()\n\n\ndef query():\n db.connect()\n num_connections('connect')\n\n MyModel.select().execute()\n\n db.close()\n num_connections('close')\n\nfor i in xrange(5):\n thread = threading.Thread(target=query)\n thread.start()\n\nnum_connections('interval')\nsleep(1)\n\nfor i in xrange(5):\n thread = threading.Thread(target=query)\n thread.start()\n```\n\nIf you comment out the explicit `connect` and `close` you should have some open connections left at the end but if you call close looks like it works as expected. I'll update my code to reflect and hopefully that'll do the job!\n", "Expected output with `connect` and `close` in place (inside `query()`):\n\n```\nalexlatchford@Alexs-Air Desktop $ python peewee_test.py \n1 State: start - Num conns: 0 - Thread: MainThread\n2 State: interval - Num conns: 0 - Thread: MainThread\n3 State: connect - Num conns: 1 - Thread: Thread-1\n4 State: connect - Num conns: 2 - Thread: Thread-2\n5 State: connect - Num conns: 3 - Thread: Thread-3\n6 State: connect - Num conns: 4 - Thread: Thread-4\n7 State: connect - Num conns: 4 - Thread: Thread-5\n8 State: close - Num conns: 4 - Thread: Thread-1\n9 State: close - Num conns: 3 - Thread: Thread-2\n10 State: close - Num conns: 2 - Thread: Thread-3\n11 State: close - Num conns: 1 - Thread: Thread-4\n12 State: close - Num conns: 0 - Thread: Thread-5\n13 State: connect - Num conns: 2 - Thread: Thread-6\n14 State: connect - Num conns: 3 - Thread: Thread-7\n15 State: connect - Num conns: 4 - Thread: Thread-8\n16 State: connect - Num conns: 4 - Thread: Thread-9\n17 State: close - Num conns: 3 - Thread: Thread-6\n18 State: connect - Num conns: 3 - Thread: Thread-10\n19 State: close - Num conns: 3 - Thread: Thread-7\n20 State: close - Num conns: 1 - Thread: Thread-8\n21 State: close - Num conns: 1 - Thread: Thread-9\n22 State: close - Num conns: 0 - Thread: Thread-10\n```\n\nAnd with them commented out I get:\n\n```\nalexlatchford@Alexs-Air Desktop $ python peewee_test.py \n1 State: start - Num conns: 0 - Thread: MainThread\n2 State: connect - Num conns: 0 - Thread: Thread-1\n3 State: connect - Num conns: 0 - Thread: Thread-2\n4 State: connect - Num conns: 0 - Thread: Thread-3\n5 State: connect - Num conns: 0 - Thread: Thread-4\n6 State: connect - Num conns: 0 - Thread: Thread-5\n7 State: interval - Num conns: 0 - Thread: MainThread\n8 State: close - Num conns: 1 - Thread: Thread-1\n9 State: close - Num conns: 2 - Thread: Thread-2\n10 State: close - Num conns: 2 - Thread: Thread-3\n11 State: close - Num conns: 2 - Thread: Thread-4\n12 State: close - Num conns: 2 - Thread: Thread-5\n13 State: connect - Num conns: 2 - Thread: Thread-6\n14 State: connect - Num conns: 2 - Thread: Thread-7\n\n15 State: connect - Num conns: 2 - Thread: Thread-8\n16 State: connect - Num conns: 2 - Thread: Thread-9\n17 State: connect - Num conns: 2 - Thread: Thread-10\n18 State: close - Num conns: 2 - Thread: Thread-6\n19 State: close - Num conns: 2 - Thread: Thread-7\n20 State: close - Num conns: 2 - Thread: Thread-8\n21 State: close - Num conns: 2 - Thread: Thread-9\n22 State: close - Num conns: 2 - Thread: Thread-10\n```\n", "![conn1](https://cloud.githubusercontent.com/assets/119974/10566871/20a3b3b4-75b8-11e5-80f1-3fe6d3d28498.png)\n\n![conn2](https://cloud.githubusercontent.com/assets/119974/10566872/20a3b134-75b8-11e5-9e49-11d492432cd3.png)\n", "Yep missed that detail, we've got the connections being used all over the show so difficult to check everywhere they're being used but certainly will be more diligent in the future :)\n\nThanks for the taking the time to respond.\n" ]
2015-10-18T20:59:25
2015-10-18T21:53:16
2015-10-18T21:42:48
CONTRIBUTOR
null
Hi Charles, Not sure if this is the best place for support advice so feel free to direct me elsewhere. I'm using `PooledPostgresqlExtDatabase` class with `threadlocals=True` and `max_connections=50`. We're hitting the max number of connections within ~24 hours and I think I've narrowed down the problem to some background processing threads we spin up. We spin up 1 time use threads for tasks that do some processing in the background for a few seconds after a HTTP request is complete. My question is once that thread completes the connection will be returned to the pool, since it's returned will it ever be picked up by any other thread? Or is it orphaned never to be used again? If not picked up again, (which I'm assuming is the case), I'm guessing the best solution is to use a non-pooled connection for those tasks right. Many thanks, Alex
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/731/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/731/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/730
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/730/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/730/comments
https://api.github.com/repos/coleifer/peewee/issues/730/events
https://github.com/coleifer/peewee/issues/730
112,024,895
MDU6SXNzdWUxMTIwMjQ4OTU=
730
In meta ,how to set "order by synax"
{ "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
[ "Well, I think setting a default ordering is _always_ a bad idea, but since you asked:\n\n``` python\nclass Meta:\n order_by = ('location', '-position')\n```\n\n`order_by` is a tuple. The elements of the tuple are field names. If prefixed by a \"-\", then the field is ordered descending.\n", "6969201d22676e4e7557949fcccd13d835a662a4 contains doc updates.\n" ]
2015-10-18T15:13:28
2015-10-18T16:52:41
2015-10-18T16:44:24
NONE
null
I'm use Peewee ORM. I have a class such as this: ``` python class Sample(PMBaseModel): id = peewee.PrimaryKeyField() location = peewee.CharField(max_length=255) position = peewee.IntegerField() class Meta: db_table = 'sample' ``` how i can use Meta Class for set default ordering and define Order type?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/730/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/730/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/729
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/729/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/729/comments
https://api.github.com/repos/coleifer/peewee/issues/729/events
https://github.com/coleifer/peewee/issues/729
111,732,703
MDU6SXNzdWUxMTE3MzI3MDM=
729
Exceeded maximum connections.
{ "login": "Darnok99", "id": 341063, "node_id": "MDQ6VXNlcjM0MTA2Mw==", "avatar_url": "https://avatars.githubusercontent.com/u/341063?v=4", "gravatar_id": "", "url": "https://api.github.com/users/Darnok99", "html_url": "https://github.com/Darnok99", "followers_url": "https://api.github.com/users/Darnok99/followers", "following_url": "https://api.github.com/users/Darnok99/following{/other_user}", "gists_url": "https://api.github.com/users/Darnok99/gists{/gist_id}", "starred_url": "https://api.github.com/users/Darnok99/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/Darnok99/subscriptions", "organizations_url": "https://api.github.com/users/Darnok99/orgs", "repos_url": "https://api.github.com/users/Darnok99/repos", "events_url": "https://api.github.com/users/Darnok99/events{/privacy}", "received_events_url": "https://api.github.com/users/Darnok99/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "`self._connections` and `self._in_use` should be mutually exclusive, though, right? i.e., the pool of connections we are pulling the connection /from/ should not be in use. The second branch there, the `elif key in self._in_use:` is there to pre-emptively remove stale connections on close, i.e. if the conn was very close to being stale when checked out, then while in use it became stale, we can simply close it when it's checked back in.\n\nAre you sure you are not forgetting to close a connection somewhere in your app?\n", "Hmm but I think second branch `elif key in self._in_use` won't be invoked since we have \n\n``` python\ndef _close(self, conn, close_conn=False):\n key = self.conn_key(conn)\n if close_conn:\n self._closed.add(key)\n super(PooledDatabase, self)._close(conn)\n\n # this one won't be invoked because close_conn is true\n elif key in self._in_use:\n ts = self._in_use[key]\n del self._in_use[key]\n if self.stale_timeout and self._is_stale(ts):\n logger.debug('Closing stale connection %s.', key)\n self._close(conn, close_conn=True)\n else:\n logger.debug('Returning %s to pool.', key)\n heapq.heappush(self._connections, (ts, conn))\n\n```\n\nMain thing is \"where do we remove connection from _in_use collection\" because check on this throws error I'm facing.\n", "Can you share some of the code you're using to connect and close the conn? Or some more details about your app? The pool is covered by unit tests, so I'm not sure what I'm missing here.\n\nMy point is that I figured `self._connections` and `self._in_use` are mutually exclusive.\n", "Hey, sorry for bugging you earlier. The problem is on our end, we removed stale time and still have same error. I can't provide you code samples because peewee is in quite many places in our project.\nSorry for shooting from the hip.\nCheers,\nKonrad\n" ]
2015-10-16T00:09:58
2015-10-16T03:46:59
2015-10-16T03:46:59
NONE
null
We're using PooledPostgresqlExtDatabase in our application but it looks like it doesn't clean closed connections what leads to error from the subject. After digging a little in the PooledDatabase class i think the problem is when connection is stale. Then _connect invokes _close with parameter close_conn=True ``` python if self.stale_timeout and self._is_stale(ts): logger.debug('Connection %s was stale, closing.', key) self._close(conn, True) # HERE ts = conn = None ``` and later in _close function in the same class we have ``` python if close_conn: self._closed.add(key) super(PooledDatabase, self)._close(conn) ``` which doesn't remove connection from _in_use and after some time this leads to "Exceeded maximum connections.". I guess changing close_conn from True to False in _connect function should do the trick.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/729/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/729/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/728
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/728/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/728/comments
https://api.github.com/repos/coleifer/peewee/issues/728/events
https://github.com/coleifer/peewee/issues/728
110,860,330
MDU6SXNzdWUxMTA4NjAzMzA=
728
commit_on_success raises an OperationalError after db.begin() since 2.4.5
{ "login": "felixonmars", "id": 1006477, "node_id": "MDQ6VXNlcjEwMDY0Nzc=", "avatar_url": "https://avatars.githubusercontent.com/u/1006477?v=4", "gravatar_id": "", "url": "https://api.github.com/users/felixonmars", "html_url": "https://github.com/felixonmars", "followers_url": "https://api.github.com/users/felixonmars/followers", "following_url": "https://api.github.com/users/felixonmars/following{/other_user}", "gists_url": "https://api.github.com/users/felixonmars/gists{/gist_id}", "starred_url": "https://api.github.com/users/felixonmars/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/felixonmars/subscriptions", "organizations_url": "https://api.github.com/users/felixonmars/orgs", "repos_url": "https://api.github.com/users/felixonmars/repos", "events_url": "https://api.github.com/users/felixonmars/events{/privacy}", "received_events_url": "https://api.github.com/users/felixonmars/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Your code is very strange. Why are you beginning a transaction explicitly? I don't think this is a bug.\n", "This snippet is simplified from deepin-movie's source code, and as I am only porting the software to Arch, I am not very sure the original purpose of delayCommit either.\n\nLink to original code that having the same problem: https://github.com/linuxdeepin/deepin-movie/blob/release/2.3/src/models/playlist.py\n", "I have no idea but I think that these bugs are not bugs in peewee, but someone doing something weird.\n\nSetting autocommit to False and calling `begin()` on a SQLite database will execute a `BEGIN` statement. When you open a transaction, via the decorator, `begin()` is again called.\n\nPeewee maintains transactional state but not at the `begin()` API level. Instead, you should use the `transaction()` or `atomic()` methods.\n\n```\ndb = SqliteDatabase(\":memory:\")\ndb.connect()\nwith db.atomic():\n # Do some stuff.\n i_want_to_commit()\n\[email protected]()\ndef i_want_to_commit():\n return\n```\n", "Sorry, I just want to clarify my comment about transaction state.\n\nYour best bet with Peewee is to use the `db.atomic()` method. This method works as both a context-manager or a decorator, so you can:\n\n``` python\n\nwith db.atomic():\n with db.atomic():\n something_else()\n\n\[email protected]()\ndef something_else()\n pass\n```\n\nThe nice thing about `atomic()` is that it's smart and knows when to use transactions or savepoints.\n\nBy explicitly calling `begin()`, the code you referenced is bypassing Peewee's transactional state tracker, so the call to `@commit_on_success` fails to see that a transaction was opened higher up the call-stack, and throws an error because it tries to open one.\n\nDoes that help?\n", "Thank you. I believe the original code was meant to delay commit for 500ms, and currently I don't see a way without calling `begin()` explicitly. Does `db.atomic()` work the same way as `@commit_on_success` and would work even if `begin()` was called explicitly?\n", "> I believe the original code was meant to delay commit for 500ms, and currently I don't see a way without calling begin() explicitly.\n\nWell, I'm curious about that. Why is it necessary to delay for 500ms?\n\n> Does db.atomic() work the same way as @commit_on_success and would work even if begin() was called explicitly?\n\nNo, and the commit_on_success should really be considered deprecated. You can use `db.atomic()` or `db.transaction()`. Atomic has the benefit that nested blocks will use savepoints. If you just use transactions, you will only get a single transaction on the outermost block.\n", "I see. I'll try to reach the original author and figure out the reason for 500ms delay. Many thanks for the info!\n" ]
2015-10-11T14:42:05
2015-10-12T05:46:34
2015-10-12T02:48:51
CONTRIBUTOR
null
The following code works with peewee 2.4.4 but fails with 2.4.5+. Replacing the commit_on_success part with a simple `db.commit()` won't fail, though. Any hints for the behavior change? ``` from peewee import SqliteDatabase db = SqliteDatabase(":memory:") db.set_autocommit(False) db.connect() db.begin() db.set_autocommit(True) @db.commit_on_success def i_want_to_commit(): return i_want_to_commit() ``` The error: ``` Traceback (most recent call last): File "test.py", line 13, in <module> i_want_to_commit() File "/usr/lib/python2.7/site-packages/peewee.py", line 2880, in inner with self.transaction(): File "/usr/lib/python2.7/site-packages/peewee.py", line 3330, in __enter__ self._begin() File "/usr/lib/python2.7/site-packages/peewee.py", line 3314, in _begin self.db.begin() File "/usr/lib/python2.7/site-packages/peewee.py", line 2985, in begin self.execute_sql('BEGIN %s' % lock_type, require_commit=False) File "/usr/lib/python2.7/site-packages/peewee.py", line 2833, in execute_sql self.commit() File "/usr/lib/python2.7/site-packages/peewee.py", line 2688, in __exit__ reraise(new_type, new_type(*exc_value.args), traceback) File "/usr/lib/python2.7/site-packages/peewee.py", line 2825, in execute_sql cursor.execute(sql, params or ()) peewee.OperationalError: cannot start a transaction within a transaction ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/728/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/728/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/727
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/727/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/727/comments
https://api.github.com/repos/coleifer/peewee/issues/727/events
https://github.com/coleifer/peewee/issues/727
109,629,962
MDU6SXNzdWUxMDk2Mjk5NjI=
727
MySQLDatabase missing __init__ function, cannot set commit_select when constructing connection
{ "login": "pushinginertia", "id": 1499061, "node_id": "MDQ6VXNlcjE0OTkwNjE=", "avatar_url": "https://avatars.githubusercontent.com/u/1499061?v=4", "gravatar_id": "", "url": "https://api.github.com/users/pushinginertia", "html_url": "https://github.com/pushinginertia", "followers_url": "https://api.github.com/users/pushinginertia/followers", "following_url": "https://api.github.com/users/pushinginertia/following{/other_user}", "gists_url": "https://api.github.com/users/pushinginertia/gists{/gist_id}", "starred_url": "https://api.github.com/users/pushinginertia/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/pushinginertia/subscriptions", "organizations_url": "https://api.github.com/users/pushinginertia/orgs", "repos_url": "https://api.github.com/users/pushinginertia/repos", "events_url": "https://api.github.com/users/pushinginertia/events{/privacy}", "received_events_url": "https://api.github.com/users/pushinginertia/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "> It seems to me that defaulting to NOT committing on all select queries should be the default since select is a non-mutating operation\n\nI pushed a commit to remove it in master, which will be in the next release. I know with postgres the reason I was doing that was to avoid connections hanging idle in transactions. I'm honestly not sure if mysql requires similar logic, but you can remove it for the time being by subclassing `MySQLDatabase`:\n\n``` python\nclass MySQLDatabaseNoCommit(MySQLDatabase):\n commit_select = False\n```\n", "I'm going to revert this change as it has caused lots of confusion for MySQL users. Say what you will, but yeah, I think it's better for the users to not be confused. For the time being, you'll have to subclass MySQLDatabase and override the `commit_select` attribute:\n\n``` python\n\nclass CustomMySQLDatabase(MySQLDatabase):\n commit_select = False\n```\n" ]
2015-10-03T16:04:00
2016-01-13T16:27:31
2015-10-03T19:16:01
NONE
null
This is related to issue #431. In order to use a cursor with MySQL and avoid an out of memory error, I need to use the `MySQLdb.cursors.SSCursor` class and disable commits on select. It seems to me that defaulting to NOT committing on all select queries should be the default since select is a non-mutating operation, but it would be helpful to give the flexibility of overriding this value when instantiating the db connection. In this specific case, by overriding the default cursor provided by the MySQL driver to `SSCursor`, I am changing the behaviour so that results are stored server-side and a call to `Database.execute_sql` attempts to execute a commit after initializing the cursor. This results in the error: `Exception _mysql_exceptions.ProgrammingError: (2014, "Commands out of sync; you can't run this command now") in <bound method SSCursor.__del__ of <MySQLdb.cursors.SSCursor object at 0x10a706990>> ignored` I can solve this problem by instantiating my connection as: ``` db = MySQLDatabase( 'databasename', ..., cursorclass=cursors.SSCursor, commit_select = False, ) ``` However, `MySQLDatabase` does not have an `__init__` function and is defined as follows: ``` class MySQLDatabase(Database): commit_select = True .. more initialization of variables .. ``` Because of the above implementation, `commit_select` does not get set to `False` as I would expect. I suggest the following implementation instead: ``` class MySQLDatabase(Database): def __init__(commit_select=True, **kwargs): super(MySQLDatabase, self).__init__() self.commit_select = commit_select .. any other initialization .. ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/727/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/727/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/726
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/726/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/726/comments
https://api.github.com/repos/coleifer/peewee/issues/726/events
https://github.com/coleifer/peewee/issues/726
109,522,246
MDU6SXNzdWUxMDk1MjIyNDY=
726
Maximum recursion depth exceeded
{ "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
[ "I don't seem to be able to replicate this:\n\n``` python\nIn [1]: from peewee import *\n\nIn [2]: db = SqliteDatabase(':memory:')\n\nIn [3]: class User(Model):\n ...: username = CharField()\n ...: class Meta:\n ...: database = db\n ...: \n\nIn [4]: User.create_table()\n\nIn [5]: User.create(username='charlie')\nOut[5]: <__main__.User at 0xb52263b0>\n\nIn [6]: User.get(User.id == 1)\nOut[6]: <__main__.User at 0xb5226610>\n\nIn [7]: User.get(User.id == 12)\n---------------------------------------------------------------------------\nUserDoesNotExist Traceback (most recent call last)\n<ipython-input-7-862c3fc1e569> in <module>()\n----> 1 User.get(User.id == 12)\n\n/home/charles/code/peewee/peewee.py in get(cls, *query, **kwargs)\n 4295 if kwargs:\n 4296 sq = sq.filter(**kwargs)\n-> 4297 return sq.get()\n 4298 \n 4299 @classmethod\n\n/home/charles/code/peewee/peewee.py in get(self)\n 2794 raise self.model_class.DoesNotExist(\n 2795 'Instance matching query does not exist:\\nSQL: %s\\nPARAMS: %s'\n-> 2796 % self.sql())\n 2797 \n 2798 def first(self):\n\nUserDoesNotExist: Instance matching query does not exist:\nSQL: SELECT \"t1\".\"id\", \"t1\".\"username\" FROM \"user\" AS t1 WHERE (\"t1\".\"id\" = ?)\nPARAMS: [12]\n\nIn [9]: import peewee\n\nIn [10]: peewee.__version__\nOut[10]: '2.6.4'\n```\n", "I will check again , I am using proxy class from playhouse though\nOn Oct 2, 2015 12:16, \"Charles Leifer\" [email protected] wrote:\n\n> I don't seem to be able to replicate this:\n> \n> In [1]: from peewee import *\n> \n> In [2]: db = SqliteDatabase(':memory:')\n> \n> In [3]: class User(Model):\n> ...: username = CharField()\n> ...: class Meta:\n> ...: database = db\n> ...:\n> \n> In [4]: User.create_table()\n> \n> In [5]: User.create(username='charlie')\n> Out[5]: <**main**.User at 0xb52263b0>\n> \n> In [6]: User.get(User.id == 1)\n> Out[6]: <**main**.User at 0xb5226610>\n> \n> In [7]: User.get(User.id == 12)---------------------------------------------------------------------------\n> UserDoesNotExist Traceback (most recent call last)<ipython-input-7-862c3fc1e569> in <module>()----> 1 User.get(User.id == 12)\n> /home/charles/code/peewee/peewee.py in get(cls, _query, *_kwargs)\n> 4295 if kwargs:\n> 4296 sq = sq.filter(**kwargs)-> 4297 return sq.get()\n> 4298\n> 4299 @classmethod\n> /home/charles/code/peewee/peewee.py in get(self)\n> 2794 raise self.model_class.DoesNotExist(\n> 2795 'Instance matching query does not exist:\\nSQL: %s\\nPARAMS: %s'-> 2796 % self.sql())\n> 2797\n> 2798 def first(self):\n> \n> UserDoesNotExist: Instance matching query does not exist:\n> SQL: SELECT \"t1\".\"id\", \"t1\".\"username\" FROM \"user\" AS t1 WHERE (\"t1\".\"id\" = ?)\n> PARAMS: [12]\n> \n> In [9]: import peewee\n> \n> In [10]: peewee.**version**\n> Out[10]: '2.6.4'\n> \n> —\n> Reply to this email directly or view it on GitHub\n> https://github.com/coleifer/peewee/issues/726#issuecomment-145074759.\n", "Hi, sorry I found the problem I had override get method on my User model\nclass, sorry\n\nOn Fri, Oct 2, 2015 at 12:27 PM, Stanko Petrovic [email protected] wrote:\n\n> I will check again , I am using proxy class from playhouse though\n> On Oct 2, 2015 12:16, \"Charles Leifer\" [email protected] wrote:\n> \n> > I don't seem to be able to replicate this:\n> > \n> > In [1]: from peewee import *\n> > \n> > In [2]: db = SqliteDatabase(':memory:')\n> > \n> > In [3]: class User(Model):\n> > ...: username = CharField()\n> > ...: class Meta:\n> > ...: database = db\n> > ...:\n> > \n> > In [4]: User.create_table()\n> > \n> > In [5]: User.create(username='charlie')\n> > Out[5]: <**main**.User at 0xb52263b0>\n> > \n> > In [6]: User.get(User.id == 1)\n> > Out[6]: <**main**.User at 0xb5226610>\n> > \n> > In [7]: User.get(User.id == 12)---------------------------------------------------------------------------\n> > UserDoesNotExist Traceback (most recent call last)<ipython-input-7-862c3fc1e569> in <module>()----> 1 User.get(User.id == 12)\n> > /home/charles/code/peewee/peewee.py in get(cls, _query, *_kwargs)\n> > 4295 if kwargs:\n> > 4296 sq = sq.filter(**kwargs)-> 4297 return sq.get()\n> > 4298\n> > 4299 @classmethod\n> > /home/charles/code/peewee/peewee.py in get(self)\n> > 2794 raise self.model_class.DoesNotExist(\n> > 2795 'Instance matching query does not exist:\\nSQL: %s\\nPARAMS: %s'-> 2796 % self.sql())\n> > 2797\n> > 2798 def first(self):\n> > \n> > UserDoesNotExist: Instance matching query does not exist:\n> > SQL: SELECT \"t1\".\"id\", \"t1\".\"username\" FROM \"user\" AS t1 WHERE (\"t1\".\"id\" = ?)\n> > PARAMS: [12]\n> > \n> > In [9]: import peewee\n> > \n> > In [10]: peewee.**version**\n> > Out[10]: '2.6.4'\n> > \n> > —\n> > Reply to this email directly or view it on GitHub\n> > https://github.com/coleifer/peewee/issues/726#issuecomment-145074759.\n" ]
2015-10-02T16:09:56
2015-10-02T17:16:02
2015-10-02T17:16:02
NONE
null
Hi, how are you? I have installed peewee 2.6.4 and have simple sqlite db with one User record. when I try to run query as this User.get(User.id == 1) I am getting maximum recursion depth error User.select().where(User.id == 1) # works fine
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/726/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/726/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/725
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/725/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/725/comments
https://api.github.com/repos/coleifer/peewee/issues/725/events
https://github.com/coleifer/peewee/issues/725
108,680,404
MDU6SXNzdWUxMDg2ODA0MDQ=
725
Confused about inconsistency of *DoesNotExist exceptions
{ "login": "pitchforks", "id": 4378791, "node_id": "MDQ6VXNlcjQzNzg3OTE=", "avatar_url": "https://avatars.githubusercontent.com/u/4378791?v=4", "gravatar_id": "", "url": "https://api.github.com/users/pitchforks", "html_url": "https://github.com/pitchforks", "followers_url": "https://api.github.com/users/pitchforks/followers", "following_url": "https://api.github.com/users/pitchforks/following{/other_user}", "gists_url": "https://api.github.com/users/pitchforks/gists{/gist_id}", "starred_url": "https://api.github.com/users/pitchforks/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/pitchforks/subscriptions", "organizations_url": "https://api.github.com/users/pitchforks/orgs", "repos_url": "https://api.github.com/users/pitchforks/repos", "events_url": "https://api.github.com/users/pitchforks/events{/privacy}", "received_events_url": "https://api.github.com/users/pitchforks/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "For anyone like me who stumbles upon this from google with the same question, just use the exception at the top level of the package, and ignore the concatenation of your model name onto the exception in the traceback. For example, for model `MyModel` with id field `id`:\r\n```python\r\nimport peewee\r\nfrom my_app.models import MyModel\r\n\r\ndef get_mymodel(requested_id):\r\n try:\r\n result = MyModel.get(MyModel.id == requested_id)\r\n except peewee.DoesNotExist:\r\n raise ValueError('No instance of MyModel exists at {}'.format(requested_id))\r\n```\r\n" ]
2015-09-28T15:18:48
2019-04-15T18:49:43
2015-09-29T01:59:14
NONE
null
peewee-2.6.4 Suppose I have a model named `MyModel`. I am trying to fetch a `my_model` row by using `MyModel.get(CONDITION)`. If such a row can't be found - an exception is raised. The displayed traceback says `peewee.MyModelDoesNotExist`. If I try to catch this exception - the result does not change! Diving deeper with a debugger reveals that I should actually catch `MyModel.DoesNotExist`! This makes the traceback displayed by peewee confusing and very misleading. Can you please change the traceback message to hint about the correct exception name that should be caught or is there any technical limitation for not doing so?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/725/reactions", "total_count": 5, "+1": 5, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/725/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/724
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/724/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/724/comments
https://api.github.com/repos/coleifer/peewee/issues/724/events
https://github.com/coleifer/peewee/issues/724
108,509,959
MDU6SXNzdWUxMDg1MDk5NTk=
724
Testing IS NULL for JSONFields fails
{ "login": "alexlatchford", "id": 628146, "node_id": "MDQ6VXNlcjYyODE0Ng==", "avatar_url": "https://avatars.githubusercontent.com/u/628146?v=4", "gravatar_id": "", "url": "https://api.github.com/users/alexlatchford", "html_url": "https://github.com/alexlatchford", "followers_url": "https://api.github.com/users/alexlatchford/followers", "following_url": "https://api.github.com/users/alexlatchford/following{/other_user}", "gists_url": "https://api.github.com/users/alexlatchford/gists{/gist_id}", "starred_url": "https://api.github.com/users/alexlatchford/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/alexlatchford/subscriptions", "organizations_url": "https://api.github.com/users/alexlatchford/orgs", "repos_url": "https://api.github.com/users/alexlatchford/repos", "events_url": "https://api.github.com/users/alexlatchford/events{/privacy}", "received_events_url": "https://api.github.com/users/alexlatchford/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Hello, I'm not sure if you've wrapped this up into your package yet, but in version 2.5.1 this is still an issue with [](as opposed to None):\n\n```\nTraceback (most recent call last):\n File \"/opt/corndog/pagerDutyDumper.py\", line 73, in run\n self.dump()\n File \"/opt/corndog/pagerDutyDumper.py\", line 57, in dump\n dbalerts = set([int(i.alertId) for i in dbalerts])\n File \"/usr/lib/python2.7/site-packages/peewee.py\", line 2689, in __iter__\n @returns_clone\n File \"/usr/lib/python2.7/site-packages/peewee.py\", line 2682, in execute\n if args:\n File \"/usr/lib/python2.7/site-packages/peewee.py\", line 2371, in _execute\n instance._prepare_instance()\n File \"/usr/lib/python2.7/site-packages/playhouse/postgres_ext.py\", line 369, in execute_sql\n self.rollback()\n File \"/usr/lib/python2.7/site-packages/peewee.py\", line 2922, in __exit__\n if not db.returning_clause:\n File \"/usr/lib/python2.7/site-packages/playhouse/postgres_ext.py\", line 360, in execute_sql\n cursor = self.get_cursor(name=str(uuid.uuid1()))\nProgrammingError: syntax error at or near \")\"\nLINE 1: ...t1\".\"hosted\" FROM \"alert\" AS t1 WHERE (\"t1\".\"alertId\" IN ())\n ^\n```\n\nMy offending lines are \n\n```\n# nums gets generated above\nprint 'Nums is \"{}\"'.format(nums)\ndbalerts = psql.Alert.select().where(psql.Alert.alertId << nums)\ndbalerts = set([int(i.alertId) for i in dbalerts])\n```\n\nNums is \"[]\"\n\nFor now I've wrapped up the query and list comprehension in a try/except.\n\nThanks!\n\nEDIT: Huh. I `pip install --upgrade peewee`'d this morning and just for giggles, did it again. It's at 2.6.4 now.\n", "\"<<\" is \"in\", whereas \">>\" is \"IS\".\n", "Fair enough, however this still seems (to me, anyway) to be a problem. I can submit a separate issue if you'd like.\n", "Oh, I see, you weren't trying to check for `NULL` but passing an empty list. I'd just check the list before running the query, that seems the best path forward.\n" ]
2015-09-27T03:03:02
2015-10-05T23:56:04
2015-09-27T14:44:26
CONTRIBUTOR
null
Hi Charles, Just found a nice little one. ``` from peewee import * from playhouse.postgres_ext import JSONField db = PostgresqlDatabase('mydb', user="postgres") class MyModel(Model): data = JSONField(null=True) class Meta: database = db MyModel.create_table() query = MyModel.select().where(MyModel.data >> None) for d in query: print d.data ``` Will fail with the following: ``` alexlatchford@Alexs-Air Desktop $ python peewee_test.py Traceback (most recent call last): File "peewee_test.py", line 15, in <module> for d in query: File "/Users/alexlatchford/Code/peewee/peewee.py", line 2846, in __iter__ return iter(self.execute()) File "/Users/alexlatchford/Code/peewee/peewee.py", line 2839, in execute self._qr = ResultWrapper(model_class, self._execute(), query_meta) File "/Users/alexlatchford/Code/peewee/peewee.py", line 2535, in _execute return self.database.execute_sql(sql, params, self.require_commit) File "/Users/alexlatchford/Code/peewee/peewee.py", line 3339, in execute_sql self.commit() File "/Users/alexlatchford/Code/peewee/peewee.py", line 3185, in __exit__ reraise(new_type, new_type(*exc_args), traceback) File "/Users/alexlatchford/Code/peewee/peewee.py", line 3331, in execute_sql cursor.execute(sql, params or ()) peewee.ProgrammingError: syntax error at or near "'null'" LINE 1: ...1"."data" FROM "mymodel" AS t1 WHERE ("t1"."data" IS 'null') ``` Did a little bit of digging to see if it was an easy fix but couldn't seem to find the cause of the issue, sorry! Cheers, Alex PS. Tested with the latest copy from master
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/724/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/724/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/723
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/723/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/723/comments
https://api.github.com/repos/coleifer/peewee/issues/723/events
https://github.com/coleifer/peewee/issues/723
108,499,317
MDU6SXNzdWUxMDg0OTkzMTc=
723
Columns disappear on INSERT, UPDATE with UUID foreign key
{ "login": "kennethklee", "id": 838810, "node_id": "MDQ6VXNlcjgzODgxMA==", "avatar_url": "https://avatars.githubusercontent.com/u/838810?v=4", "gravatar_id": "", "url": "https://api.github.com/users/kennethklee", "html_url": "https://github.com/kennethklee", "followers_url": "https://api.github.com/users/kennethklee/followers", "following_url": "https://api.github.com/users/kennethklee/following{/other_user}", "gists_url": "https://api.github.com/users/kennethklee/gists{/gist_id}", "starred_url": "https://api.github.com/users/kennethklee/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/kennethklee/subscriptions", "organizations_url": "https://api.github.com/users/kennethklee/orgs", "repos_url": "https://api.github.com/users/kennethklee/repos", "events_url": "https://api.github.com/users/kennethklee/events{/privacy}", "received_events_url": "https://api.github.com/users/kennethklee/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Should note that updates work except when I change the `user` field. Column seems to just, disappear from the query.\n", "That's bizarre. What version of peewee are you using? Can you put together a small snippet so I can replicate the bug?\n", "peewee==2.6.4\n\nRequires postgres, with a db and user already created. I haven't tried with sqlite, though I'm not sure if sqlite has uuid.\n\nBelow is the bug:\n\n```\nimport os\nimport uuid\n\nfrom datetime import datetime\nfrom peewee import PostgresqlDatabase, Proxy, Model, UUIDField, CharField, BooleanField, DateTimeField, TextField, ForeignKeyField\n\nsession = PostgresqlDatabase(\n 'testdb',\n host='localhost',\n port='5432',\n user='postgres',\n password='postgres'\n)\n\nclass BaseModel(Model):\n class Meta:\n database = session\n\nclass User(BaseModel):\n id = UUIDField(primary_key=True, default=uuid.uuid4, null=False)\n created_at = DateTimeField(default=datetime.now, null=False, verbose_name='Created At')\n active = BooleanField(default=True, null=False, verbose_name='Active')\n name = CharField(max_length=255, null=False)\n\nclass UnitRevision(BaseModel):\n id = UUIDField(primary_key=True, default=uuid.uuid4, null=False)\n user = ForeignKeyField(User, null=False) # uuid relationship\n created_at = DateTimeField(default=datetime.now, null=False, verbose_name='Created At')\n name = CharField(max_length=255, null=False)\n config = TextField(null=False)\n\nuser = User()\nuser.create(name='Test')\n\nrev = UnitRevision(user=user, name='test', config='test')\nprint(rev.insert()) # see odd output\nrev.create() # fails\n```\n\nForgot to mention, you might want to do `User.create_table()` and `UnitRevision.create_table()` sometime before creating the users.\n", "I should have read this more carefully. You've got your APIs mixed up. `create()` is a classmethod that accepts `kwargs` of field->value. `insert()` is also a classmethod. You should call `save()` on instances you've built up programmatically.\n\nRewritten:\n\n``` python\nuser = User.create(name='Test')\n\nrev = UnitRevision(user=user, name='test', config='test')\nrev.save(force_insert=True)\n```\n\nNote that when using UUIDs or other \"non integer primary keys\" you need to save with `force_insert=True`: http://docs.peewee-orm.com/en/latest/peewee/models.html#id3\n", "Thanks, that works.\n" ]
2015-09-26T22:23:09
2015-09-28T00:26:06
2015-09-27T01:55:15
NONE
null
Cannot insert, update the uuid foreign key with this model: ``` python class UnitRevision(BaseModel): id = UUIDField(primary_key=True, default=uuid.uuid4, null=False) user = ForeignKeyField(User, null=False) # uuid relationship created_at = DateTimeField(default=datetime.now, null=False, verbose_name='Created At') name = CharField(max_length=255, null=False) config = TextField(null=False) # Instantiate unit = UnitRevision(user=user, name='test', config='test') # user is an existing user with a uuid primary key ``` Here's the error I get when trying `create()`: ``` *** IntegrityError: null value in column "user_id" violates not-null constraint DETAIL: Failing row contains (5844081c-d4e2-4a23-8240-7246bf2474a7, null, 2015-09-26 18:09:26.787624+00, null, null). ``` I get the following when I call `insert()`: ``` <class 'app.database.UnitRevision'> INSERT INTO "unitrevision" ("id", "created_at") VALUES (%s, %s) RETURNING "id" ['17daa1fa-b01a-45cf-a8c9-fe78c0a7f4ea', datetime.datetime(2015, 9, 26, 18, 10, 25, 15981)] ``` What happened to the columns, `user_id`, `name`, and `config`? Why aren't they present?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/723/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/723/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/722
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/722/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/722/comments
https://api.github.com/repos/coleifer/peewee/issues/722/events
https://github.com/coleifer/peewee/issues/722
108,417,693
MDU6SXNzdWUxMDg0MTc2OTM=
722
How do I avoid circular imports?
{ "login": "danieldiekmeier", "id": 2098462, "node_id": "MDQ6VXNlcjIwOTg0NjI=", "avatar_url": "https://avatars.githubusercontent.com/u/2098462?v=4", "gravatar_id": "", "url": "https://api.github.com/users/danieldiekmeier", "html_url": "https://github.com/danieldiekmeier", "followers_url": "https://api.github.com/users/danieldiekmeier/followers", "following_url": "https://api.github.com/users/danieldiekmeier/following{/other_user}", "gists_url": "https://api.github.com/users/danieldiekmeier/gists{/gist_id}", "starred_url": "https://api.github.com/users/danieldiekmeier/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/danieldiekmeier/subscriptions", "organizations_url": "https://api.github.com/users/danieldiekmeier/orgs", "repos_url": "https://api.github.com/users/danieldiekmeier/repos", "events_url": "https://api.github.com/users/danieldiekmeier/events{/privacy}", "received_events_url": "https://api.github.com/users/danieldiekmeier/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "One possibility is, of course, to move the import of Resolution into the `resolution` function. This definitely works, but it feels dirty. :(\n", "You can use `Proxy` for this.\n\nhttp://docs.peewee-orm.com/en/latest/peewee/models.html?highlight=proxy#circular-foreign-key-dependencies\n" ]
2015-09-25T22:27:51
2015-09-26T13:28:31
2015-09-26T13:28:31
NONE
null
I use peewee in my webapp http://lesetagebu.ch, and it's great! Thank you. But I have a problem: All my models lived in a models.py, but the file was several hundred lines long and hard to manage. So I refactored each model into its own file in ./models. But now I have problems with circular imports. For example: ``` python # models/user.py (irrelevant parts omitted) from .rootmodel import RootModel from .resolution import Resolution class User(RootModel): username = CharField(unique=True) password = CharField() def resolution(self): year = arrow.now('Europe/Berlin').year try: resolution = self.resolutions.where( (Resolution.year == year) ) if resolution.count() == 0: raise(DoesNotExist) except DoesNotExist: resolution = Resolution.create( amount=0, active=True, year=year ) return sresolution ``` ``` python # models/resolution.py (irrelevant parts omitted) from .rootmodel import RootModel from .user import User class Resolution(RootModel): amount = IntegerField() active = BooleanField() year = IntegerField() user = ForeignKeyField(User, related_name='resolutions') ``` This is the traceback: ``` Traceback (most recent call last): File "run.py", line 1, in <module> import lesetagebuch.main as main File "/Users/Daniel/dev/python/lesetagebuch/lesetagebuch/main.py", line 19, in <module> from lesetagebuch.models import * File "/Users/Daniel/dev/python/lesetagebuch/lesetagebuch/models/__init__.py", line 1, in <module> from .apikey import APIKey File "/Users/Daniel/dev/python/lesetagebuch/lesetagebuch/models/apikey.py", line 6, in <module> from .user import User File "/Users/Daniel/dev/python/lesetagebuch/lesetagebuch/models/user.py", line 14, in <module> from .resolution import Resolution File "/Users/Daniel/dev/python/lesetagebuch/lesetagebuch/models/resolution.py", line 8, in <module> from .user import User ImportError: cannot import name 'User' ``` The problem is, I need the User in the resolution.py, because I need to define the Foreign Key, but I also need the Resolution in the user.py, because I need to be able to create a new Resolution instance. In Django, there seems to be a way by using strings: http://stackoverflow.com/questions/4379042/django-circular-model-import-issue, but that doesn't work in peewee, because the first argument of ForeignKeyField needs to be a class. Maybe the solution is quite obvious, but I can't find it. What do you recommend?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/722/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/722/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/721
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/721/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/721/comments
https://api.github.com/repos/coleifer/peewee/issues/721/events
https://github.com/coleifer/peewee/pull/721
108,181,484
MDExOlB1bGxSZXF1ZXN0NDU5MjgzNTk=
721
Make array field adapter independent from the connection.
{ "login": "stas", "id": 112147, "node_id": "MDQ6VXNlcjExMjE0Nw==", "avatar_url": "https://avatars.githubusercontent.com/u/112147?v=4", "gravatar_id": "", "url": "https://api.github.com/users/stas", "html_url": "https://github.com/stas", "followers_url": "https://api.github.com/users/stas/followers", "following_url": "https://api.github.com/users/stas/following{/other_user}", "gists_url": "https://api.github.com/users/stas/gists{/gist_id}", "starred_url": "https://api.github.com/users/stas/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/stas/subscriptions", "organizations_url": "https://api.github.com/users/stas/orgs", "repos_url": "https://api.github.com/users/stas/repos", "events_url": "https://api.github.com/users/stas/events{/privacy}", "received_events_url": "https://api.github.com/users/stas/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Hmm, it looks like there's something strange with the way py3 handles the unicode string adapter.\n\nThis could be related to psycopg/psycopg2#331\nI've tried a couple of things, including calling `adapted.prepare(conn)` and explicitly setting the connection encoding to `UTF8`, still on py3 I get the adapter result as bytea.\n\nWe can close this until the py3 support is not ready... :|\n" ]
2015-09-24T17:55:59
2015-09-24T21:19:37
2015-09-24T21:19:37
NONE
null
Since the field does not depend on the database OIDs, calling `prepare()` is not necessary. This is also mentioned in the docs[1](http://initd.org/psycopg/docs/extensions.html#psycopg2.extensions.ISQLQuote.prepare). The reason this is not dependent on the connection since we don't try to adapt any special OIDs that can vary from one Postgres version to another. We discovered this when a wrapped connection was used to adapt the new type. Relevant: opbeat/opbeat_python#68 Thanks in advance for reviewing this.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/721/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/721/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/721", "html_url": "https://github.com/coleifer/peewee/pull/721", "diff_url": "https://github.com/coleifer/peewee/pull/721.diff", "patch_url": "https://github.com/coleifer/peewee/pull/721.patch", "merged_at": null }
https://api.github.com/repos/coleifer/peewee/issues/720
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/720/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/720/comments
https://api.github.com/repos/coleifer/peewee/issues/720/events
https://github.com/coleifer/peewee/issues/720
107,964,786
MDU6SXNzdWUxMDc5NjQ3ODY=
720
Wrong code sample in docs
{ "login": "ael-code", "id": 4229536, "node_id": "MDQ6VXNlcjQyMjk1MzY=", "avatar_url": "https://avatars.githubusercontent.com/u/4229536?v=4", "gravatar_id": "", "url": "https://api.github.com/users/ael-code", "html_url": "https://github.com/ael-code", "followers_url": "https://api.github.com/users/ael-code/followers", "following_url": "https://api.github.com/users/ael-code/following{/other_user}", "gists_url": "https://api.github.com/users/ael-code/gists{/gist_id}", "starred_url": "https://api.github.com/users/ael-code/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/ael-code/subscriptions", "organizations_url": "https://api.github.com/users/ael-code/orgs", "repos_url": "https://api.github.com/users/ael-code/repos", "events_url": "https://api.github.com/users/ael-code/events{/privacy}", "received_events_url": "https://api.github.com/users/ael-code/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[]
2015-09-23T17:11:02
2015-09-23T17:24:23
2015-09-23T17:24:23
NONE
null
I'm using peewee for the first time but it seems to me that the docs on [querying#joining-on-multiple-tables](http://peewee.readthedocs.org/en/latest/peewee/querying.html#joining-on-multiple-tables) has two wrong code samples: ``` python User.join(Tweet).join(Comment) ``` ``` python # Join the Artist table on both `Ablum` and `Genre`. Artist.join(Album).switch(Artist).join(Genre) ``` Is the `select()` missing?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/720/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/720/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/719
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/719/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/719/comments
https://api.github.com/repos/coleifer/peewee/issues/719/events
https://github.com/coleifer/peewee/issues/719
107,878,750
MDU6SXNzdWUxMDc4Nzg3NTA=
719
deferred ManyToManyField assignment
{ "login": "ael-code", "id": 4229536, "node_id": "MDQ6VXNlcjQyMjk1MzY=", "avatar_url": "https://avatars.githubusercontent.com/u/4229536?v=4", "gravatar_id": "", "url": "https://api.github.com/users/ael-code", "html_url": "https://github.com/ael-code", "followers_url": "https://api.github.com/users/ael-code/followers", "following_url": "https://api.github.com/users/ael-code/following{/other_user}", "gists_url": "https://api.github.com/users/ael-code/gists{/gist_id}", "starred_url": "https://api.github.com/users/ael-code/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/ael-code/subscriptions", "organizations_url": "https://api.github.com/users/ael-code/orgs", "repos_url": "https://api.github.com/users/ael-code/repos", "events_url": "https://api.github.com/users/ael-code/events{/privacy}", "received_events_url": "https://api.github.com/users/ael-code/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "> Is this normal?\n\nOke I've read [peewee.py#L4194](https://github.com/coleifer/peewee/blob/master/peewee.py#L4194). and I've understood that Fields are replaced on class creation, so you cannot deferred Model fields definition. In some cases you can you can use model proxies as workaround.\n\nAm I wrong?\n", "You should just need to call `add_to_class()`. Untested, but:\n\n``` python\nusers_field = ManyToManyField(User, related_name='groups')\nusers_field.add_to_class(Group, 'users')\n```\n", "Given it is 2023, and API have changed, now we (as far as I get) should use:\r\n```\r\nusers_field = ManyToManyField(User, backref='groups')\r\nGroup._meta.add_field('users', users_field)\r\n```" ]
2015-09-23T09:18:38
2023-04-25T15:19:15
2015-09-23T17:26:54
NONE
null
If the `ManyToManyField` assignment is made after class declaration you will encounter errors. The following code represent the scenario. ``` python from peewee import PrimaryKeyField, CharField,\ Model, SqliteDatabase from playhouse.fields import ManyToManyField db = SqliteDatabase(':memory:') class BaseModel(Model): class Meta: database = db # Use proxy for our DB. class User(BaseModel): id = PrimaryKeyField() name = CharField(unique=True) class Group(BaseModel): id = PrimaryKeyField() name = CharField(unique=True) Group.users = ManyToManyField(User, related_name='groups') UserToGroup = Group.users.get_through_model() def main(): db.connect() db.create_tables([User, Group, UserToGroup]) anons = Group.create(name='anons') jhondohe = User.create(name='jhondhoe') anons.users.add(jhondohe) anons.save() print [u.name for u in anons.users] print [g.name for g in jhondohe.groups] if __name__ == '__main__': main() ``` Output: ``` python File "peewee_test.py", line 25, in <module> UserToGroup = Group.users.get_through_model() File "/home/anon/peewee_test/ve/local/lib/python2.7/site-packages/playhouse/fields.py", line 74, in get_through_model lhs, rhs = self.get_models() File "/home/anon/peewee_test/ve/local/lib/python2.7/site-packages/playhouse/fields.py", line 69, in get_models (self._is_backref, self.model_class), AttributeError: 'ManyToManyField' object has no attribute 'model_class' ``` Is this normal?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/719/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/719/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/718
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/718/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/718/comments
https://api.github.com/repos/coleifer/peewee/issues/718/events
https://github.com/coleifer/peewee/issues/718
107,843,645
MDU6SXNzdWUxMDc4NDM2NDU=
718
return " ProgrammingError: execute() first" in sql_error_handler
{ "login": "Funnyhao", "id": 864265, "node_id": "MDQ6VXNlcjg2NDI2NQ==", "avatar_url": "https://avatars.githubusercontent.com/u/864265?v=4", "gravatar_id": "", "url": "https://api.github.com/users/Funnyhao", "html_url": "https://github.com/Funnyhao", "followers_url": "https://api.github.com/users/Funnyhao/followers", "following_url": "https://api.github.com/users/Funnyhao/following{/other_user}", "gists_url": "https://api.github.com/users/Funnyhao/gists{/gist_id}", "starred_url": "https://api.github.com/users/Funnyhao/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/Funnyhao/subscriptions", "organizations_url": "https://api.github.com/users/Funnyhao/orgs", "repos_url": "https://api.github.com/users/Funnyhao/repos", "events_url": "https://api.github.com/users/Funnyhao/events{/privacy}", "received_events_url": "https://api.github.com/users/Funnyhao/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I don't see how this is a bug in peewee.\n", "it's not possible to allow returning a new cursor to execute_sql when \"Mysql gone away\" happens?\n", "Hmm, that would change the contract of the function and I'm not sure I'd like to make the change.\n\nI do see, though, how returning the old cursor from before the reconnect is causing the issue.\n", "See 017e4e4952f0b429dd21f0e90465a0f644cf6015 for a fix.\n", "thx a lot \n" ]
2015-09-23T03:35:14
2015-10-05T14:17:41
2015-09-30T03:34:20
NONE
null
class MyMYSQL(MySQLDatabase): ``` def sql_error_handler(self,exception,sql,params,require_commit): db.close(); db.connect(); db.execute_sql(sql, params or (), require_commit = require_commit); return False; ``` I find test sql_error_handler with kill mysql process but it gets : ``` File "/data1/wejobssvr/handler/base.py", line 64, in get result = self._do(args); File "/data1/wejobssvr/handler/main.py", line 75, in _do result = getattr(op_controller, action_type, self.error_result)(params); File "/data1/wejobssvr/controller/oneoff_controller.py", line 489, in get_job job_meta = JobMetaInfo.get(id=int(params_dict["job_meta_id"])); File "/data1/wejobssvr/client/../util/peewee.py", line 3395, in get return sq.get() File "/data1/wejobssvr/client/../util/peewee.py", line 2383, in get return clone.execute().next() File "/data1/wejobssvr/client/../util/peewee.py", line 1686, in next obj = self.iterate() File "/data1/wejobssvr/client/../util/peewee.py", line 1667, in iterate row = self.cursor.fetchone() File "build/bdist.linux-x86_64/egg/MySQLdb/cursors.py", line 365, in fetchone self._check_executed() File "build/bdist.linux-x86_64/egg/MySQLdb/cursors.py", line 105, in _check_executed self.errorhandler(self, ProgrammingError, "execute() first") File "build/bdist.linux-x86_64/egg/MySQLdb/connections.py", line 36, in defaulterrorhandler raise errorclass, errorvalue ProgrammingError: execute() first ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/718/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/718/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/717
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/717/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/717/comments
https://api.github.com/repos/coleifer/peewee/issues/717/events
https://github.com/coleifer/peewee/issues/717
107,609,514
MDU6SXNzdWUxMDc2MDk1MTQ=
717
New release soon?
{ "login": "bahadir", "id": 655413, "node_id": "MDQ6VXNlcjY1NTQxMw==", "avatar_url": "https://avatars.githubusercontent.com/u/655413?v=4", "gravatar_id": "", "url": "https://api.github.com/users/bahadir", "html_url": "https://github.com/bahadir", "followers_url": "https://api.github.com/users/bahadir/followers", "following_url": "https://api.github.com/users/bahadir/following{/other_user}", "gists_url": "https://api.github.com/users/bahadir/gists{/gist_id}", "starred_url": "https://api.github.com/users/bahadir/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/bahadir/subscriptions", "organizations_url": "https://api.github.com/users/bahadir/orgs", "repos_url": "https://api.github.com/users/bahadir/repos", "events_url": "https://api.github.com/users/bahadir/events{/privacy}", "received_events_url": "https://api.github.com/users/bahadir/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Released 2.6.4: https://pypi.python.org/pypi/peewee/\n\nChanges: https://github.com/coleifer/peewee/releases/tag/2.6.4\n" ]
2015-09-21T22:15:34
2015-09-22T03:32:58
2015-09-22T03:32:58
NONE
null
Hi, I'm happy with changes after last tagged release and I want to use peewee without messing my requirements.txt / setup.py. Are you planning to tag a new release soon? Thanks & keep up the great work!
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/717/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/717/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/716
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/716/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/716/comments
https://api.github.com/repos/coleifer/peewee/issues/716/events
https://github.com/coleifer/peewee/issues/716
107,364,229
MDU6SXNzdWUxMDczNjQyMjk=
716
PostgresqlExtDatabase unsupported psycopg2cffi
{ "login": "cutso", "id": 237805, "node_id": "MDQ6VXNlcjIzNzgwNQ==", "avatar_url": "https://avatars.githubusercontent.com/u/237805?v=4", "gravatar_id": "", "url": "https://api.github.com/users/cutso", "html_url": "https://github.com/cutso", "followers_url": "https://api.github.com/users/cutso/followers", "following_url": "https://api.github.com/users/cutso/following{/other_user}", "gists_url": "https://api.github.com/users/cutso/gists{/gist_id}", "starred_url": "https://api.github.com/users/cutso/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/cutso/subscriptions", "organizations_url": "https://api.github.com/users/cutso/orgs", "repos_url": "https://api.github.com/users/cutso/repos", "events_url": "https://api.github.com/users/cutso/events{/privacy}", "received_events_url": "https://api.github.com/users/cutso/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Try passing in `register_hstore=False`:\n\n``` python\ndb = PostgresqlExtDatabase('my_db', register_hstore=False)\n```\n\nLooks like the psycopg2.extras helper I was using to register_hstore does not accept the psycopg2cffi `Connection` object.\n" ]
2015-09-20T00:30:35
2015-09-21T13:05:14
2015-09-21T13:05:14
NONE
null
Peewee is a nice project, thank you! Today, i have a problem with peewee when used psycopg2cffi connect to postgresql. As i run programm under a virtual environ with pypy-2.6.1, that can not install psycopg2, so i used psycpog2cffi instead. Everything wroks well but PostgresqlExtDatabase. I do not know why, then i use python 2.7.3 and create virtual environ directly and use psycopg2, it works well. My connnecting code are: from playhouse.postgres_ext import PostgresqlExtDatabase psql_db = PostgresqlExtDatabase('mydb', user="postgres", password="mypass", host="127.0.0.1") psql_db.connect() The problem was happened when use pypy + psycopg2cffi + PostgresqlExtDatabase Can anybody helps? Thank you! Here are the error log: Traceback (most recent call last): File "/Users/cutso/server/pyenv/1.8.3/lib/python2.7/site-packages/tornado/web.py", line 1415, in _execute result = yield result File "/Users/cutso/server/pyenv/1.8.3/lib/python2.7/site-packages/tornado/gen.py", line 870, in run value = future.result() File "/Users/cutso/server/pyenv/1.8.3/lib/python2.7/site-packages/tornado/concurrent.py", line 215, in result raise_exc_info(self._exc_info) File "/Users/cutso/server/pyenv/1.8.3/lib/python2.7/site-packages/tornado/gen.py", line 879, in run yielded = self.gen.send(value) File "/Users/cutso/Documents/projects/fancalno/app/default/handlers.py", line 21, in get self.render("index.html", users=users, result=result, total=total) File "/Users/cutso/server/pyenv/1.8.3/lib/python2.7/site-packages/tornado/web.py", line 704, in render html = self.render_string(template_name, **kwargs) File "/Users/cutso/Documents/projects/fancalno/app/template.py", line 33, in render_string auto_reload=self.settings['debug'], **context) File "/Users/cutso/Documents/projects/fancalno/app/template.py", line 42, in _jinja_render self.write(template.render(**context)) File "/Users/cutso/server/pyenv/1.8.3/lib/python2.7/site-packages/jinja2/environment.py", line 989, in render return self.environment.handle_exception(exc_info, True) File "/Users/cutso/server/pyenv/1.8.3/lib/python2.7/site-packages/jinja2/environment.py", line 754, in handle_exception reraise(exc_type, exc_value, tb) File "/Users/cutso/Documents/projects/fancalno/template/index.html", line 1, in top-level template code {% extends "base.html" %} File "/Users/cutso/Documents/projects/fancalno/template/base.html", line 22, in top-level template code {% block body %} File "/Users/cutso/Documents/projects/fancalno/template/index.html", line 9, in block "body" <ul>{% for user in users %} File "/Users/cutso/server/pyenv/1.8.3/lib/python2.7/site-packages/peewee.py", line 2794, in __iter__ return iter(self.execute()) File "/Users/cutso/server/pyenv/1.8.3/lib/python2.7/site-packages/peewee.py", line 2787, in execute self._qr = ResultWrapper(model_class, self._execute(), query_meta) File "/Users/cutso/server/pyenv/1.8.3/lib/python2.7/site-packages/peewee.py", line 2470, in _execute return self.database.execute_sql(sql, params, self.require_commit) File "/Users/cutso/server/pyenv/1.8.3/lib/python2.7/site-packages/playhouse/postgres_ext.py", line 358, in execute_sql cursor = self.get_cursor() File "/Users/cutso/server/pyenv/1.8.3/lib/python2.7/site-packages/playhouse/postgres_ext.py", line 345, in get_cursor return self.get_conn().cursor() File "/Users/cutso/server/pyenv/1.8.3/lib/python2.7/site-packages/peewee.py", line 3148, in get_conn self.connect() File "/Users/cutso/server/pyenv/1.8.3/lib/python2.7/site-packages/peewee.py", line 3128, in connect **self.connect_kwargs) File "/Users/cutso/server/pyenv/1.8.3/lib/python2.7/site-packages/playhouse/postgres_ext.py", line 375, in _connect register_hstore(conn, globally=True) File "/Users/cutso/server/pyenv/1.8.3/lib/python2.7/site-packages/psycopg2/extras.py", line 772, in register_hstore oid = HstoreAdapter.get_oids(conn_or_curs) File "/Users/cutso/server/pyenv/1.8.3/lib/python2.7/site-packages/psycopg2/extras.py", line 712, in get_oids conn, curs = _solve_conn_curs(conn_or_curs) File "/Users/cutso/server/pyenv/1.8.3/lib/python2.7/site-packages/psycopg2/extras.py", line 599, in _solve_conn_curs curs = conn.cursor(cursor_factory=_cursor) File "/Users/cutso/server/pyenv/1.8.3/lib/python2.7/site-packages/psycopg2cffi/_impl/connection.py", line 333, in cursor cur = cursor_factory(self, name) TypeError: argument 1 must be psycopg2.extensions.connection, not Connection
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/716/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/716/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/715
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/715/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/715/comments
https://api.github.com/repos/coleifer/peewee/issues/715/events
https://github.com/coleifer/peewee/issues/715
107,361,754
MDU6SXNzdWUxMDczNjE3NTQ=
715
Peewee multiple join with same table
{ "login": "serkandaglioglu", "id": 1669906, "node_id": "MDQ6VXNlcjE2Njk5MDY=", "avatar_url": "https://avatars.githubusercontent.com/u/1669906?v=4", "gravatar_id": "", "url": "https://api.github.com/users/serkandaglioglu", "html_url": "https://github.com/serkandaglioglu", "followers_url": "https://api.github.com/users/serkandaglioglu/followers", "following_url": "https://api.github.com/users/serkandaglioglu/following{/other_user}", "gists_url": "https://api.github.com/users/serkandaglioglu/gists{/gist_id}", "starred_url": "https://api.github.com/users/serkandaglioglu/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/serkandaglioglu/subscriptions", "organizations_url": "https://api.github.com/users/serkandaglioglu/orgs", "repos_url": "https://api.github.com/users/serkandaglioglu/repos", "events_url": "https://api.github.com/users/serkandaglioglu/events{/privacy}", "received_events_url": "https://api.github.com/users/serkandaglioglu/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Try this:\n\n``` python\nt = (Test\n .select(Test,A,B)\n .join(A, on=(Test.a == A.test2_id) )\n .switch(Test) # set query ctx back to test \n .join(B, on=(Test.b == B.test2_id) )\n .where( Test.test_id==1 )\n t.get()\n )\n```\n\nIf you are still having trouble try explicitly aliasing the join predicate:\n\n``` python\nt = (Test\n .select(Test,A,B)\n .join(A, on=(Test.a == A.test2_id).alias('a') )\n .switch(Test) # set query ctx back to test \n .join(B, on=(Test.b == B.test2_id).alias('b') )\n .where( Test.test_id==1 )\n t.get()\n )\n```\n", "@coleifer I tried both of your code, They print same output.\n\nPrinting code : \n\n``` python\nprint t.test_name\nprint t.a.test2_name\nprint t.b.test2_name\n```\n\nThe output :\n\n```\nTest 1\nTest2-2\nTest2-2\n```\n\nThe query log : \n\n``` sql\n('SELECT `t1`.`test_id`, `t1`.`test_name`, `t1`.`a_id`, `t1`.`b_id`, `t2`.`test2_id`, `t2`.`test2_name`, `t3`.`test2_id`, `t3`.`test2_name` FROM `test` AS t1 INNER JOIN `test2` AS t2 ON (`t1`.`a_id` = `t2`.`test2_id`) INNER JOIN `test2` AS t3 ON (`t1`.`b_id` = `t3`.`test2_id`) WHERE (`t1`.`test_id` = %s) ORDER BY `t1`.`test_id` ASC LIMIT 1', [1])\n\n('SELECT `t1`.`test2_id`, `t1`.`test2_name` FROM `test2` AS t1 WHERE (`t1`.`test2_id` = %s) ORDER BY `t1`.`test2_id` ASC LIMIT 1', [2])\n```\n\nThe query is correct but result is not correct. t.a.test2_name and t.b.test2_name have same values. I runned query on mysql there is no problem.\n\nQuery result on mysql console :\n\n```\n+---------+-----------+------+------+----------+------------+-------------+---------------+\n| test_id | test_name | a_id | b_id | test2_id | test2_name | test2_id(2) | test2_name(2) |\n+---------+-----------+------+------+----------+------------+-------------+---------------+\n| 1 | Test 1 | 1 | 2 | 1 | Test2-1 | 2 | Test2-2 |\n+---------+-----------+------+------+----------+------------+-------------+---------------+\n```\n", "When I tested the 2nd query against master, it only issued one query.\n\n``` python\nquery = (Test\n .select(Test, A, B)\n .join(A, on=(Test.a == A.id).alias('a'))\n .switch(Test)\n .join(B, on=(Test.b == B.id).alias('b'))\n .where(Test.name == 't1'))\n\nobj = query.get()\nprint obj.name\nprint obj.a.t2_name\nprint obj.b.t2_name\n```\n\nConsole output:\n\n```\n('SELECT \"t1\".\"id\", \"t1\".\"name\", \"t1\".\"a_id\", \"t1\".\"b_id\", \"t2\".\"id\", \"t2\".\"t2_name\", \"t3\".\"id\", \"t3\".\"t2_name\" FROM \"test\" AS t1 INNER JOIN \"test2\" AS t2 ON (\"t1\".\"a_id\" = \"t2\".\"id\") INNER JOIN \"test2\" AS t3 ON (\"t1\".\"b_id\" = \"t3\".\"id\") WHERE (\"t1\".\"name\" = ?) LIMIT 1', [u't1'])\nt1\nt1a\nt1b\n\n```\n", "After I use `.alias('a')` and `.alias('b')`, The problem is solved.\nThanks.\n" ]
2015-09-19T23:25:02
2015-11-19T22:37:44
2015-09-20T02:52:45
NONE
null
``` class Test2(BaseModel): test2_id = PrimaryKeyField() test2_name = CharField(null=True) class Meta: db_table = 'test2' order_by = ('test2_id',) class Test(BaseModel): test_id = PrimaryKeyField() test_name = CharField(null=True) a = ForeignKeyField(Test2,db_column="a_id",to_field="test2_id",related_name="x") b = ForeignKeyField(Test2,db_column="b_id",to_field="test2_id", related_name="y") class Meta: db_table = 'test' order_by = ('test_id',) A = Test2.alias() B = Test2.alias() t = (Test .select(Test,A,B) .join(A, on=(Test.a == A.test2_id) ) .join(B, on=(Test.b == B.test2_id) ) .where( Test.test_id==1 ) .get() ) print t.test_name print t.a.test2_name print t.b.test2_name ``` This is the log: ``` ('SELECT `t1`.`test_id`, `t1`.`test_name`, `t1`.`a_id`, `t1`.`b_id`, `t2`.`test2_id`, `t2`.`test2_name`, `t3`.`test2_id`, `t3`.`test2_name` FROM `test` AS t1 INNER JOIN `test2` AS t2 ON (`t1`.`a_id` = `t2`.`test2_id`) INNER JOIN `test2` AS t3 ON (`t1`.`b_id` = `t3`.`test2_id`) WHERE (`t1`.`test_id` = %s) ORDER BY `t1`.`test_id` ASC LIMIT 1', [1]) Test 1 Test2-1 ('SELECT `t1`.`test2_id`, `t1`.`test2_name` FROM `test2` AS t1 WHERE (`t1`.`test2_id` = %s) ORDER BY `t1`.`test2_id` ASC LIMIT 1', [2]) Test2-2 ``` In query I already selected A,B but peewee run another query for getting "Test2-2". I have same situation in my application and it set A and B same values. I checked A and B on database they have different values. ---
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/715/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/715/timeline
null
completed
null
null