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/1118
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1118/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1118/comments
https://api.github.com/repos/coleifer/peewee/issues/1118/events
https://github.com/coleifer/peewee/issues/1118
187,488,949
MDU6SXNzdWUxODc0ODg5NDk=
1,118
Error installing under PyPy
{ "login": "rcarmo", "id": 392683, "node_id": "MDQ6VXNlcjM5MjY4Mw==", "avatar_url": "https://avatars.githubusercontent.com/u/392683?v=4", "gravatar_id": "", "url": "https://api.github.com/users/rcarmo", "html_url": "https://github.com/rcarmo", "followers_url": "https://api.github.com/users/rcarmo/followers", "following_url": "https://api.github.com/users/rcarmo/following{/other_user}", "gists_url": "https://api.github.com/users/rcarmo/gists{/gist_id}", "starred_url": "https://api.github.com/users/rcarmo/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/rcarmo/subscriptions", "organizations_url": "https://api.github.com/users/rcarmo/orgs", "repos_url": "https://api.github.com/users/rcarmo/repos", "events_url": "https://api.github.com/users/rcarmo/events{/privacy}", "received_events_url": "https://api.github.com/users/rcarmo/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I'm not sure what all is going on in the error you pasted. I literally have no idea.\n", "My best guess so far is that speedups are probably missing some kind of definition to match PyPy's C headers. Cython also has issues with PyPy, so these probably need to move to cffi or something.\n\nEither way, I need to figure out how to disable speedups when installing under PyPy...\n", "Updated setup.py f42aa3cc76d7f3506fe714355626f4a771652c3c\n" ]
2016-11-05T10:25:18
2016-11-13T22:38:07
2016-11-13T22:38:07
CONTRIBUTOR
null
When trying to install under `pyenv`, I'm getting the following: ``` Running setup.py install for peewee Complete output from command /home/rcarmo/.pyenv/versions/pypy-5.4.1/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip-build-T8dLe0/peewee/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-tOb4RG-record/install-record.txt --single-version-externally-managed --compile: running install running build running build_py creating build creating build/lib.linux-x86_64-2.7 copying peewee.py -> build/lib.linux-x86_64-2.7 copying pwiz.py -> build/lib.linux-x86_64-2.7 creating build/lib.linux-x86_64-2.7/playhouse copying playhouse/db_url.py -> build/lib.linux-x86_64-2.7/playhouse copying playhouse/csv_loader.py -> build/lib.linux-x86_64-2.7/playhouse copying playhouse/test_utils.py -> build/lib.linux-x86_64-2.7/playhouse copying playhouse/sqlcipher_ext.py -> build/lib.linux-x86_64-2.7/playhouse copying playhouse/hybrid.py -> build/lib.linux-x86_64-2.7/playhouse copying playhouse/reflection.py -> build/lib.linux-x86_64-2.7/playhouse copying playhouse/shortcuts.py -> build/lib.linux-x86_64-2.7/playhouse copying playhouse/postgres_ext.py -> build/lib.linux-x86_64-2.7/playhouse copying playhouse/djpeewee.py -> build/lib.linux-x86_64-2.7/playhouse copying playhouse/sqliteq.py -> build/lib.linux-x86_64-2.7/playhouse copying playhouse/read_slave.py -> build/lib.linux-x86_64-2.7/playhouse copying playhouse/csv_utils.py -> build/lib.linux-x86_64-2.7/playhouse copying playhouse/migrate.py -> build/lib.linux-x86_64-2.7/playhouse copying playhouse/berkeleydb.py -> build/lib.linux-x86_64-2.7/playhouse copying playhouse/sqlite_udf.py -> build/lib.linux-x86_64-2.7/playhouse copying playhouse/gfk.py -> build/lib.linux-x86_64-2.7/playhouse copying playhouse/kv.py -> build/lib.linux-x86_64-2.7/playhouse copying playhouse/dataset.py -> build/lib.linux-x86_64-2.7/playhouse copying playhouse/flask_utils.py -> build/lib.linux-x86_64-2.7/playhouse copying playhouse/apsw_ext.py -> build/lib.linux-x86_64-2.7/playhouse copying playhouse/signals.py -> build/lib.linux-x86_64-2.7/playhouse copying playhouse/fields.py -> build/lib.linux-x86_64-2.7/playhouse copying playhouse/__init__.py -> build/lib.linux-x86_64-2.7/playhouse copying playhouse/sqlite_ext.py -> build/lib.linux-x86_64-2.7/playhouse copying playhouse/pool.py -> build/lib.linux-x86_64-2.7/playhouse running build_ext cythoning playhouse/_speedups.pyx to playhouse/_speedups.c building 'playhouse._speedups' extension creating build/temp.linux-x86_64-2.7 creating build/temp.linux-x86_64-2.7/playhouse cc -O2 -fPIC -Wimplicit -I/home/rcarmo/.pyenv/versions/pypy-5.4.1/include -c playhouse/_speedups.c -o build/temp.linux-x86_64-2.7/playhouse/_speedups.o playhouse/_speedups.c: In function ‘__pyx_f_7cpython_8datetime_time_tzinfo’: playhouse/_speedups.c:7782:46: error: ‘PyDateTime_Time {aka struct <anonymous>}’ has no member named ‘hastzinfo’ __pyx_t_1 = (((PyDateTime_Time *)__pyx_v_o)->hastzinfo != 0); ^ In file included from /home/rcarmo/.pyenv/versions/pypy-5.4.1/include/Python.h:88:0, from playhouse/_speedups.c:4: playhouse/_speedups.c:7793:61: error: ‘PyDateTime_Time {aka struct <anonymous>}’ has no member named ‘tzinfo’ __Pyx_INCREF(((PyObject *)((PyDateTime_Time *)__pyx_v_o)->tzinfo)); ^ /home/rcarmo/.pyenv/versions/pypy-5.4.1/include/object.h:50:40: note: in definition of macro ‘Py_INCREF’ #define Py_INCREF(ob) (((PyObject *)(ob))->ob_refcnt++) ^ playhouse/_speedups.c:7793:5: note: in expansion of macro ‘__Pyx_INCREF’ __Pyx_INCREF(((PyObject *)((PyDateTime_Time *)__pyx_v_o)->tzinfo)); ^ playhouse/_speedups.c:7794:58: error: ‘PyDateTime_Time {aka struct <anonymous>}’ has no member named ‘tzinfo’ __pyx_r = ((PyObject *)((PyDateTime_Time *)__pyx_v_o)->tzinfo); ^ playhouse/_speedups.c: In function ‘__pyx_f_7cpython_8datetime_datetime_tzinfo’: playhouse/_speedups.c:7856:50: error: ‘PyDateTime_DateTime {aka struct <anonymous>}’ has no member named ‘hastzinfo’ __pyx_t_1 = (((PyDateTime_DateTime *)__pyx_v_o)->hastzinfo != 0); ^ In file included from /home/rcarmo/.pyenv/versions/pypy-5.4.1/include/Python.h:88:0, from playhouse/_speedups.c:4: playhouse/_speedups.c:7867:65: error: ‘PyDateTime_DateTime {aka struct <anonymous>}’ has no member named ‘tzinfo’ __Pyx_INCREF(((PyObject *)((PyDateTime_DateTime *)__pyx_v_o)->tzinfo)); ^ /home/rcarmo/.pyenv/versions/pypy-5.4.1/include/object.h:50:40: note: in definition of macro ‘Py_INCREF’ #define Py_INCREF(ob) (((PyObject *)(ob))->ob_refcnt++) ^ playhouse/_speedups.c:7867:5: note: in expansion of macro ‘__Pyx_INCREF’ __Pyx_INCREF(((PyObject *)((PyDateTime_DateTime *)__pyx_v_o)->tzinfo)); ^ playhouse/_speedups.c:7868:62: error: ‘PyDateTime_DateTime {aka struct <anonymous>}’ has no member named ‘tzinfo’ __pyx_r = ((PyObject *)((PyDateTime_DateTime *)__pyx_v_o)->tzinfo); ^ playhouse/_speedups.c: In function ‘__pyx_f_7cpython_8datetime_timedelta_days’: playhouse/_speedups.c:8447:44: error: ‘PyDateTime_Delta {aka struct <anonymous>}’ has no member named ‘days’ __pyx_r = ((PyDateTime_Delta *)__pyx_v_o)->days; ^ playhouse/_speedups.c: In function ‘__pyx_f_7cpython_8datetime_timedelta_seconds’: playhouse/_speedups.c:8484:44: error: ‘PyDateTime_Delta {aka struct <anonymous>}’ has no member named ‘seconds’ __pyx_r = ((PyDateTime_Delta *)__pyx_v_o)->seconds; ^ playhouse/_speedups.c: In function ‘__pyx_f_7cpython_8datetime_timedelta_microseconds’: playhouse/_speedups.c:8518:44: error: ‘PyDateTime_Delta {aka struct <anonymous>}’ has no member named ‘microseconds’ __pyx_r = ((PyDateTime_Delta *)__pyx_v_o)->microseconds; ^ error: command 'cc' failed with exit status 1 ---------------------------------------- Command "/home/rcarmo/.pyenv/versions/pypy-5.4.1/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip-build-T8dLe0/peewee/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-tOb4RG-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-T8dLe0/peewee ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1118/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1118/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1117
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1117/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1117/comments
https://api.github.com/repos/coleifer/peewee/issues/1117/events
https://github.com/coleifer/peewee/issues/1117
186,958,602
MDU6SXNzdWUxODY5NTg2MDI=
1,117
Nested brackets in the documentation?
{ "login": "NathanWailes", "id": 1755791, "node_id": "MDQ6VXNlcjE3NTU3OTE=", "avatar_url": "https://avatars.githubusercontent.com/u/1755791?v=4", "gravatar_id": "", "url": "https://api.github.com/users/NathanWailes", "html_url": "https://github.com/NathanWailes", "followers_url": "https://api.github.com/users/NathanWailes/followers", "following_url": "https://api.github.com/users/NathanWailes/following{/other_user}", "gists_url": "https://api.github.com/users/NathanWailes/gists{/gist_id}", "starred_url": "https://api.github.com/users/NathanWailes/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/NathanWailes/subscriptions", "organizations_url": "https://api.github.com/users/NathanWailes/orgs", "repos_url": "https://api.github.com/users/NathanWailes/repos", "events_url": "https://api.github.com/users/NathanWailes/events{/privacy}", "received_events_url": "https://api.github.com/users/NathanWailes/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "These are optional keyword arguments. The arguments in brackets are shown with their default values (if they have one).\n", "I understand that brackets indicate optional arguments; I'm asking why they're nested.\n", "Because that's how you do it. https://docs.python.org/3/library/collections.html#collections.deque\n" ]
2016-11-03T00:58:31
2016-11-04T19:49:16
2016-11-03T04:45:02
NONE
null
What do the nested brackets mean in the documentation? `model_to_dict(model[, recurse=True[, backrefs=False[, only=None[, exclude=None[, extra_attrs=None[, fields_from_query=None]]]]]])` ([Link](http://docs.peewee-orm.com/en/latest/peewee/playhouse.html#model_to_dict)) I looked online and it seems that having brackets nested like that can be used to show that one optional argument requires the presence of another optional argument, but that doesn't seem to be the case here, as I've seen examples of calls to this function that specify (for example) the 'extra_attrs' parameter without some of the earlier ones.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1117/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1117/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1116
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1116/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1116/comments
https://api.github.com/repos/coleifer/peewee/issues/1116/events
https://github.com/coleifer/peewee/issues/1116
186,837,520
MDU6SXNzdWUxODY4Mzc1MjA=
1,116
Silence Signals Support
{ "login": "smittysmee", "id": 8376011, "node_id": "MDQ6VXNlcjgzNzYwMTE=", "avatar_url": "https://avatars.githubusercontent.com/u/8376011?v=4", "gravatar_id": "", "url": "https://api.github.com/users/smittysmee", "html_url": "https://github.com/smittysmee", "followers_url": "https://api.github.com/users/smittysmee/followers", "following_url": "https://api.github.com/users/smittysmee/following{/other_user}", "gists_url": "https://api.github.com/users/smittysmee/gists{/gist_id}", "starred_url": "https://api.github.com/users/smittysmee/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/smittysmee/subscriptions", "organizations_url": "https://api.github.com/users/smittysmee/orgs", "repos_url": "https://api.github.com/users/smittysmee/repos", "events_url": "https://api.github.com/users/smittysmee/events{/privacy}", "received_events_url": "https://api.github.com/users/smittysmee/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I'm not following this at all. \n", "The signals all have a disconnect method, so you could use that. Alternatively you could use a global variable or thread local to keep track of the state.\n" ]
2016-11-02T15:41:20
2016-11-02T17:17:56
2016-11-02T17:17:56
NONE
null
Would it be possible to add the ability to silence signals for the pre_save handler, post_save handler, etc. This would allow for pre_save and post_save actions on the objects to prevent a loop modification within a handler. Essentially, I have a process that once it is posted, the handler will take the object and perform a call within a module that takes the object, verifies it again our API, and modifies the object where need be. Because it performs a save again when updating the object, I would like not run the call again to the API and save it again... etc. Proposed solution would be able to pass a kwarg to the save method that is overwritten by the playhouse signal method, that would look for the kwarg. If available and the value equates to true, then to skip over the signal method from running.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1116/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1116/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1115
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1115/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1115/comments
https://api.github.com/repos/coleifer/peewee/issues/1115/events
https://github.com/coleifer/peewee/issues/1115
186,366,882
MDU6SXNzdWUxODYzNjY4ODI=
1,115
FlaskDB with existing proxy
{ "login": "timster", "id": 173666, "node_id": "MDQ6VXNlcjE3MzY2Ng==", "avatar_url": "https://avatars.githubusercontent.com/u/173666?v=4", "gravatar_id": "", "url": "https://api.github.com/users/timster", "html_url": "https://github.com/timster", "followers_url": "https://api.github.com/users/timster/followers", "following_url": "https://api.github.com/users/timster/following{/other_user}", "gists_url": "https://api.github.com/users/timster/gists{/gist_id}", "starred_url": "https://api.github.com/users/timster/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/timster/subscriptions", "organizations_url": "https://api.github.com/users/timster/orgs", "repos_url": "https://api.github.com/users/timster/repos", "events_url": "https://api.github.com/users/timster/events{/privacy}", "received_events_url": "https://api.github.com/users/timster/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Argh. This can be closed. After posting, I wondered why I was using FlaskDB in the first place. I updated my code to just connect/disconnect before/after app requests. No FlaskDB needed.\n\n``` python\[email protected]_request\ndef connect_proxy():\n initialize_proxy()\n proxy.connect()\n\[email protected]_request\ndef close_proxy(exc):\n if not proxy.is_closed():\n proxy.close()\n```\n" ]
2016-10-31T18:54:11
2016-11-01T13:21:35
2016-11-01T13:21:35
NONE
null
I have an existing set of models that I'm trying to integrate into a new Flask app. For all these models, I'm using a Proxy object as the database. It would be great if FlaskDB accepted a Proxy instance as the `database` argument, but it seems like it only works with a Database instance. Here's a minimal reproducible example: ```python from flask import Flask from peewee import Proxy from playhouse.flask_utils import FlaskDB app = Flask(__name__) proxy = Proxy() proxy.initialize('sqlite:///:memory:') db = FlaskDB(app=app, database=proxy) app.run() ``` Results in... ``` File "/opt/.virtualenvs/flask/lib/python3.5/site-packages/peewee.py", line 421, in __getattr__ return getattr(self.obj, attr) AttributeError: 'str' object has no attribute 'database' ``` Seems like the chance would need to be in the [_load_database](https://github.com/coleifer/peewee/blob/master/playhouse/flask_utils.py#L103) method. Or is there another/better way to use an existing proxy with FlaskDB?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1115/reactions", "total_count": 1, "+1": 1, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1115/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1114
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1114/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1114/comments
https://api.github.com/repos/coleifer/peewee/issues/1114/events
https://github.com/coleifer/peewee/issues/1114
186,196,086
MDU6SXNzdWUxODYxOTYwODY=
1,114
unsafe in multi-thread context
{ "login": "argpass", "id": 16532113, "node_id": "MDQ6VXNlcjE2NTMyMTEz", "avatar_url": "https://avatars.githubusercontent.com/u/16532113?v=4", "gravatar_id": "", "url": "https://api.github.com/users/argpass", "html_url": "https://github.com/argpass", "followers_url": "https://api.github.com/users/argpass/followers", "following_url": "https://api.github.com/users/argpass/following{/other_user}", "gists_url": "https://api.github.com/users/argpass/gists{/gist_id}", "starred_url": "https://api.github.com/users/argpass/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/argpass/subscriptions", "organizations_url": "https://api.github.com/users/argpass/orgs", "repos_url": "https://api.github.com/users/argpass/repos", "events_url": "https://api.github.com/users/argpass/events{/privacy}", "received_events_url": "https://api.github.com/users/argpass/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Can you explain in greater detail? Peewee stores the connection state in a thread-local, so each thread should by default have its own connection.\n", "Whatever, closing.\n", "Please comment if you have any information you can provide to clarify the issue.\n" ]
2016-10-31T03:30:50
2016-11-02T17:19:38
2016-11-02T17:18:48
NONE
null
``` class MyModel(Model): name = CharField() class Meta: db = my_db ``` using `MyModel` in multi-thread environment is unsafe, as db can not be shared in different threads.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1114/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1114/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1113
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1113/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1113/comments
https://api.github.com/repos/coleifer/peewee/issues/1113/events
https://github.com/coleifer/peewee/pull/1113
185,766,274
MDExOlB1bGxSZXF1ZXN0OTEyNzA0NTU=
1,113
Add IntegrityError check in case post title is already in database.
{ "login": "bdauer", "id": 13219866, "node_id": "MDQ6VXNlcjEzMjE5ODY2", "avatar_url": "https://avatars.githubusercontent.com/u/13219866?v=4", "gravatar_id": "", "url": "https://api.github.com/users/bdauer", "html_url": "https://github.com/bdauer", "followers_url": "https://api.github.com/users/bdauer/followers", "following_url": "https://api.github.com/users/bdauer/following{/other_user}", "gists_url": "https://api.github.com/users/bdauer/gists{/gist_id}", "starred_url": "https://api.github.com/users/bdauer/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/bdauer/subscriptions", "organizations_url": "https://api.github.com/users/bdauer/orgs", "repos_url": "https://api.github.com/users/bdauer/repos", "events_url": "https://api.github.com/users/bdauer/events{/privacy}", "received_events_url": "https://api.github.com/users/bdauer/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Was just running through your awesome tutorial and caught an error when playing with it. Figured I'd submit a PR.\n", "I appreciate the intentions, but your change-set has more problems than it attempts to solve. I've fixed the underlying issue with 6a07c8e1d949724ae10c9e304b1d7d30214cf2c6\n", "Oh shoot I didn't copy over my whole change. I had added an additional line after the flash to render_template('create.html') in my local code, forked and made a quick change in github's editor. But reading over your fix I suspect there's a good reason why that's also not the best option. \n", "The reason it's not a good option (and whoops I need to fix something else, just remembered) is because you lose all your changes that you had been working on.\n", "Oh actually nvm, I see that the template is pulling straight from request.form. Nevermind!\n" ]
2016-10-27T20:02:54
2016-10-28T01:12:53
2016-10-27T22:08:45
NONE
null
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1113/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1113/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/1113", "html_url": "https://github.com/coleifer/peewee/pull/1113", "diff_url": "https://github.com/coleifer/peewee/pull/1113.diff", "patch_url": "https://github.com/coleifer/peewee/pull/1113.patch", "merged_at": null }
https://api.github.com/repos/coleifer/peewee/issues/1112
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1112/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1112/comments
https://api.github.com/repos/coleifer/peewee/issues/1112/events
https://github.com/coleifer/peewee/issues/1112
185,413,975
MDU6SXNzdWUxODU0MTM5NzU=
1,112
BooleanField is_true and is_false methods
{ "login": "danilobellini", "id": 2096474, "node_id": "MDQ6VXNlcjIwOTY0NzQ=", "avatar_url": "https://avatars.githubusercontent.com/u/2096474?v=4", "gravatar_id": "", "url": "https://api.github.com/users/danilobellini", "html_url": "https://github.com/danilobellini", "followers_url": "https://api.github.com/users/danilobellini/followers", "following_url": "https://api.github.com/users/danilobellini/following{/other_user}", "gists_url": "https://api.github.com/users/danilobellini/gists{/gist_id}", "starred_url": "https://api.github.com/users/danilobellini/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/danilobellini/subscriptions", "organizations_url": "https://api.github.com/users/danilobellini/orgs", "repos_url": "https://api.github.com/users/danilobellini/repos", "events_url": "https://api.github.com/users/danilobellini/events{/privacy}", "received_events_url": "https://api.github.com/users/danilobellini/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I appreciate you taking the time to submit this issue. Unfortunately, peewee does quite a few things that many linters find egregious. I don't use linters myself, so it doesn't bother me and personally I'm not interested in adding code simply to satisfy flake8. Thanks for providing a reference implementation, anyone who is interested can use your code or subclass `BooleanField` and add the suggested methods.\n", "I'm also not concerned with the peewee code style, I'm concerned that peewee is clearly forcing its users to take a move against PEP8 when using boolean fields, besides the consistency with `is_null`. I mean, what I propose is about the API, not about the peewee code itself.\n", "Peewee isn't forcing anyone to do anything.\n", "It's not forcing people to become peewee users, but it's forcing its users to follow its API.\n\nThe `== True` is spread in the documentation examples. Is there any example with some different approach to avoid `Something.my_field == True` while doing the same? I might be missing something.\n", "> Is there any example with some different approach to avoid `Something.my_field == True` while doing the same?\n\nYou've shared a nice one.\n", "A lot of things have changed since this discussion, and I think the original \"gripe\" has been fixed. But I wanted to confirm...\r\n\r\nThe main point is that you no longer need to use the `== True/False` syntax, though there are certain cases where it could be necessary (mainly when dealing with NULL values)\r\n\r\n\r\n```SQL\r\n q1 = Event.select(Event.id).where(Event.is_published)\r\n print(q1)\r\n >> SELECT `t1`.`id` FROM `event` AS `t1` WHERE `t1`.`is_published`\r\n\r\n q1 = Event.select(Event.id).where(~Event.is_published)\r\n print(q1)\r\n >> SELECT `t1`.`id` FROM `event` AS `t1` WHERE NOT `t1`.`is_published`\r\n\r\n q1 = Event.select(Event.id).where(Event.is_published == True)\r\n print(q1)\r\n >> SELECT `t1`.`id` FROM `event` AS `t1` WHERE (`t1`.`is_published` = 1)\r\n\r\n q1 = Event.select(Event.id).where(Event.is_published == False)\r\n print(q1)\r\n >> SELECT `t1`.`id` FROM `event` AS `t1` WHERE (`t1`.`is_published` = 0)\r\n```\r\n\r\nUsually both versions will be equivalent. But if the boolean field supports NULL, then you need to be careful which version you use.\r\n\r\nThe same things goes for hybrid attributes. The reason I arrived at this ticket was because I noticed a query was not using an index that it should have been. It was using the `== False` syntax on a hybrid attribute/expression, which resulted in the query being something like `WHERE (( complex expression ) == 0)`, but when using the negation operator `~`, the SQL is `WHERE NOT ( complex expression)` and the index was used correctly. \r\n\r\n\r\nThe documentation seems to mainly still use the `== True/False` variation. Maybe I missed it, but it could be good to add some details on the difference between these two variations of boolean expressions." ]
2016-10-26T14:42:04
2021-02-26T21:41:44
2016-10-26T15:14:15
NONE
null
# Proposal Add methods to BooleanField so that we can create expressions like `MyModel.my_field.is_true()` and `MyModel.my_field.is_false()` instead of `MyModel.my_field == True` and `MyModel.my_field == False`. # Rationale I'm using `flake8`, with a selected list of [pycodestyle error codes](http://pycodestyle.readthedocs.io/en/latest/intro.html#error-codes), and using `MyModel.my_field == True` triggers the E712 error, _comparison to True should be 'if cond is True:' or 'if cond:'_. That would be consistent with the `is_null` method, which is used instead of a "MyModel.my_field == None". # Reference implementation ``` peewee.BooleanField.is_true = lambda self: peewee.Expression(self, peewee.OP.EQ, True) peewee.BooleanField.is_false = lambda self: peewee.Expression(self, peewee.OP.EQ, False) ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1112/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/1112/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1111
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1111/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1111/comments
https://api.github.com/repos/coleifer/peewee/issues/1111/events
https://github.com/coleifer/peewee/issues/1111
185,240,500
MDU6SXNzdWUxODUyNDA1MDA=
1,111
How do I make a CharField(collate='nocase')?
{ "login": "stenci", "id": 5955495, "node_id": "MDQ6VXNlcjU5NTU0OTU=", "avatar_url": "https://avatars.githubusercontent.com/u/5955495?v=4", "gravatar_id": "", "url": "https://api.github.com/users/stenci", "html_url": "https://github.com/stenci", "followers_url": "https://api.github.com/users/stenci/followers", "following_url": "https://api.github.com/users/stenci/following{/other_user}", "gists_url": "https://api.github.com/users/stenci/gists{/gist_id}", "starred_url": "https://api.github.com/users/stenci/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/stenci/subscriptions", "organizations_url": "https://api.github.com/users/stenci/orgs", "repos_url": "https://api.github.com/users/stenci/repos", "events_url": "https://api.github.com/users/stenci/events{/privacy}", "received_events_url": "https://api.github.com/users/stenci/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "You can add a constraint:\n\n``` python\ncolumn = CharField(constraints=[SQL('COLLATE NOCASE')])\n```\n" ]
2016-10-25T21:35:35
2016-10-25T21:41:18
2016-10-25T21:41:18
CONTRIBUTOR
null
Is it possible to create a field with [`COLLATE nocase`](https://www.sqlite.org/datatype3.html#collation_sequence_examples)? ``` CREATE TABLE tab (col TEXT COLLATE nocase); ``` I looked for something like this, but I couldn't find it: ``` class Tab(Model): col = CharField(collate='nocase') ``` The alternative is to make either a lowercase index or a collate nocase index, and make sure all the queries are either lowercase or collate nocase. It would be much easier to create the columns as collate nocase and get sorting and querying automatically case insensitive.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1111/reactions", "total_count": 1, "+1": 1, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1111/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1110
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1110/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1110/comments
https://api.github.com/repos/coleifer/peewee/issues/1110/events
https://github.com/coleifer/peewee/issues/1110
185,189,542
MDU6SXNzdWUxODUxODk1NDI=
1,110
MySQL - TimestampField Issue
{ "login": "Byte-Lorenz", "id": 17599866, "node_id": "MDQ6VXNlcjE3NTk5ODY2", "avatar_url": "https://avatars.githubusercontent.com/u/17599866?v=4", "gravatar_id": "", "url": "https://api.github.com/users/Byte-Lorenz", "html_url": "https://github.com/Byte-Lorenz", "followers_url": "https://api.github.com/users/Byte-Lorenz/followers", "following_url": "https://api.github.com/users/Byte-Lorenz/following{/other_user}", "gists_url": "https://api.github.com/users/Byte-Lorenz/gists{/gist_id}", "starred_url": "https://api.github.com/users/Byte-Lorenz/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/Byte-Lorenz/subscriptions", "organizations_url": "https://api.github.com/users/Byte-Lorenz/orgs", "repos_url": "https://api.github.com/users/Byte-Lorenz/repos", "events_url": "https://api.github.com/users/Byte-Lorenz/events{/privacy}", "received_events_url": "https://api.github.com/users/Byte-Lorenz/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "> Inserting TimestampFied with value: 1475411420001 will be stored in the MySQL database as 1475411420001000.\n> Although the resolution of the field is set to milliseconds (1.000) and not to microseconds (1.000.000)\n\nIt looks to me like you've over-thought it and done the multiplication yourself. The purpose of the `TimestampField` is to make all that unnecessary. `TimestampField` allows you to work with `datetime` objects in Python but store them as integers in the database. If you want to explicitly pass in a timestamp as an integer or floating point, then Peewee will scale that accordingly before storing it.\n" ]
2016-10-25T17:58:04
2016-10-25T18:22:24
2016-10-25T18:22:24
NONE
null
**Model:** `class Issue(BaseModel): time = TimestampField(resolution=1000)` Doc: [http://docs.peewee-orm.com/en/latest/peewee/api.html#TimestampField](url) **Issue:** Inserting TimestampFied with value: `1475411420001` will be stored in the MySQL database as `1475411420001000`. Although the resolution of the field is set to milliseconds (1.000) and not to microseconds (1.000.000) When I'm reading out the data of the database and transforming it to the corresponding model with model_to_dict(...). I'm encountering the following error: "ValueError: year is out of range". (on line 1283 of peewee.py)
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1110/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1110/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1109
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1109/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1109/comments
https://api.github.com/repos/coleifer/peewee/issues/1109/events
https://github.com/coleifer/peewee/issues/1109
185,059,843
MDU6SXNzdWUxODUwNTk4NDM=
1,109
AttributeError with db.atomic() and SqliteQ
{ "login": "theotherp", "id": 14368889, "node_id": "MDQ6VXNlcjE0MzY4ODg5", "avatar_url": "https://avatars.githubusercontent.com/u/14368889?v=4", "gravatar_id": "", "url": "https://api.github.com/users/theotherp", "html_url": "https://github.com/theotherp", "followers_url": "https://api.github.com/users/theotherp/followers", "following_url": "https://api.github.com/users/theotherp/following{/other_user}", "gists_url": "https://api.github.com/users/theotherp/gists{/gist_id}", "starred_url": "https://api.github.com/users/theotherp/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/theotherp/subscriptions", "organizations_url": "https://api.github.com/users/theotherp/orgs", "repos_url": "https://api.github.com/users/theotherp/repos", "events_url": "https://api.github.com/users/theotherp/events{/privacy}", "received_events_url": "https://api.github.com/users/theotherp/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Are you running on the current, very latest commit? Because `sqliteq`'s `atomic()` is kinda broken right now in a totally different way, as I'm in the process of implementing something like a pipeline in Redis.\n", "Yeah, that's why I mentioned the commit hash. Not sure if you want feedback on your current development code.\n" ]
2016-10-25T09:08:31
2016-10-25T19:22:50
2016-10-25T19:22:49
NONE
null
It's me again... With 6ffc93cd867a7f3b28783ad4f533b1f9a205f540 I get an AttributeError using db.atomic() because lock_type is not set: ``` File "C:/Users/user/PycharmProjects/nzbhydra\nzbhydra\search.py", line 318, in search with db.atomic(): File "C:\Users\user\PycharmProjects\nzbhydra\libs\peewee.py", line 4471, in __enter__ self.context_manager = self.db.transaction(self.transaction_type) File "C:\Users\user\PycharmProjects\nzbhydra\libs\playhouse\sqlite_ext.py", line 957, in transaction assert lock_type.lower() in ('deferred', 'immediate', 'exclusive') AttributeError: 'NoneType' object has no attribute 'lower' ``` I'm using `with db.atomic("deferred")` to fix that but wanted to let you know.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1109/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1109/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1108
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1108/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1108/comments
https://api.github.com/repos/coleifer/peewee/issues/1108/events
https://github.com/coleifer/peewee/pull/1108
184,795,802
MDExOlB1bGxSZXF1ZXN0OTA1ODAzNjc=
1,108
Added a test to check whether a connection is already open.
{ "login": "romanek-adam", "id": 760766, "node_id": "MDQ6VXNlcjc2MDc2Ng==", "avatar_url": "https://avatars.githubusercontent.com/u/760766?v=4", "gravatar_id": "", "url": "https://api.github.com/users/romanek-adam", "html_url": "https://github.com/romanek-adam", "followers_url": "https://api.github.com/users/romanek-adam/followers", "following_url": "https://api.github.com/users/romanek-adam/following{/other_user}", "gists_url": "https://api.github.com/users/romanek-adam/gists{/gist_id}", "starred_url": "https://api.github.com/users/romanek-adam/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/romanek-adam/subscriptions", "organizations_url": "https://api.github.com/users/romanek-adam/orgs", "repos_url": "https://api.github.com/users/romanek-adam/repos", "events_url": "https://api.github.com/users/romanek-adam/events{/privacy}", "received_events_url": "https://api.github.com/users/romanek-adam/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I'd like to add something like this, but am worried about breaking too many people's code... I'll look into a similar patch.\n", "9e76c999868197a4911fa2fa457c50ab42431ff1\n", "Thanks!\n", "FYI: this did break our code like you mentioned above. I can work around it in our codebase but I expect this caused problems for a lot of people; is there any more robust way of doing this?", "Just run `database.get_conn()` which will only open a connection if the DB is closed." ]
2016-10-24T09:51:44
2017-02-23T16:15:46
2016-10-25T19:29:25
NONE
null
Most importantly the check prevents from leaking database connections, which can be disasterous when using connection pools. Moreover it allows one to catch errors in the code which were caused by not using database.connect() / database.close() properly.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1108/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1108/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/1108", "html_url": "https://github.com/coleifer/peewee/pull/1108", "diff_url": "https://github.com/coleifer/peewee/pull/1108.diff", "patch_url": "https://github.com/coleifer/peewee/pull/1108.patch", "merged_at": null }
https://api.github.com/repos/coleifer/peewee/issues/1107
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1107/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1107/comments
https://api.github.com/repos/coleifer/peewee/issues/1107/events
https://github.com/coleifer/peewee/pull/1107
184,769,370
MDExOlB1bGxSZXF1ZXN0OTA1NjI0NjM=
1,107
some string can't been decoded by utf8, return s
{ "login": "bagel", "id": 706788, "node_id": "MDQ6VXNlcjcwNjc4OA==", "avatar_url": "https://avatars.githubusercontent.com/u/706788?v=4", "gravatar_id": "", "url": "https://api.github.com/users/bagel", "html_url": "https://github.com/bagel", "followers_url": "https://api.github.com/users/bagel/followers", "following_url": "https://api.github.com/users/bagel/following{/other_user}", "gists_url": "https://api.github.com/users/bagel/gists{/gist_id}", "starred_url": "https://api.github.com/users/bagel/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/bagel/subscriptions", "organizations_url": "https://api.github.com/users/bagel/orgs", "repos_url": "https://api.github.com/users/bagel/repos", "events_url": "https://api.github.com/users/bagel/events{/privacy}", "received_events_url": "https://api.github.com/users/bagel/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Nice, thanks for this.\n" ]
2016-10-24T07:39:37
2016-10-25T19:10:20
2016-10-25T19:09:41
CONTRIBUTOR
null
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1107/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1107/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/1107", "html_url": "https://github.com/coleifer/peewee/pull/1107", "diff_url": "https://github.com/coleifer/peewee/pull/1107.diff", "patch_url": "https://github.com/coleifer/peewee/pull/1107.patch", "merged_at": "2016-10-25T19:09:41" }
https://api.github.com/repos/coleifer/peewee/issues/1106
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1106/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1106/comments
https://api.github.com/repos/coleifer/peewee/issues/1106/events
https://github.com/coleifer/peewee/issues/1106
184,580,650
MDU6SXNzdWUxODQ1ODA2NTA=
1,106
"<<" operator does not function on Python sets
{ "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 think I'm going to pass on fixing this, as it's a bit of a slippery slope in terms of supporting every data-type. I'd suggest just doing as you showed, and coerce to list.\n", "Can `Node._in` coerce to list automatically? [`list`](https://docs.python.org/2.6/library/functions.html#list) accepts any iterable, so the only thing the data-type needs to implement is the iterator.\n\nThat would work also with generators:\n\n```\n# Python 3\nUser.select().where(User.id << range(1, 10))\n```\n" ]
2016-10-21T22:06:57
2016-11-10T17:06:52
2016-10-24T00:12:20
CONTRIBUTOR
null
The `<<` operator in a query where the right-hand side of a `.where()` clause is a Python `set()` causes for a `ProgrammingError` on query (at least via Postgres): ``` users = set([1, 2, 3]) # Assume the set is not as trivial as this... for u in User.select().where(User.id << users): print u.name ProgrammingError: can't adapt type 'set' ``` Of course, this works, but seems tedious: ``` users = set([1, 2, 3]) # Assume the set is not as trivial as this... for u in User.select().where(User.id << list(users)): print u.name Jimmy Neutron Spongebob Squarepants Rocky Balboa Luke Skywalker ``` This issue in `psycopg2` suggests that higher-level abstractions should handle the adaptation from `set` to `list` in these cases. Do you think `peewee` is adequately "high" or should applications using it be responsible? https://github.com/psycopg/psycopg2/issues/340 I think the solution, if implemented in `peewee`, would go at/near the line linked below, casting `rhs` to a `list` if it is a `set`... but I wanted feedback before trying it and submitting a PR. https://github.com/coleifer/peewee/blob/master/peewee.py#L1661
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1106/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1106/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1105
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1105/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1105/comments
https://api.github.com/repos/coleifer/peewee/issues/1105/events
https://github.com/coleifer/peewee/issues/1105
184,426,639
MDU6SXNzdWUxODQ0MjY2Mzk=
1,105
Tuples in SQL
{ "login": "maaaks", "id": 3010238, "node_id": "MDQ6VXNlcjMwMTAyMzg=", "avatar_url": "https://avatars.githubusercontent.com/u/3010238?v=4", "gravatar_id": "", "url": "https://api.github.com/users/maaaks", "html_url": "https://github.com/maaaks", "followers_url": "https://api.github.com/users/maaaks/followers", "following_url": "https://api.github.com/users/maaaks/following{/other_user}", "gists_url": "https://api.github.com/users/maaaks/gists{/gist_id}", "starred_url": "https://api.github.com/users/maaaks/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/maaaks/subscriptions", "organizations_url": "https://api.github.com/users/maaaks/orgs", "repos_url": "https://api.github.com/users/maaaks/repos", "events_url": "https://api.github.com/users/maaaks/events{/privacy}", "received_events_url": "https://api.github.com/users/maaaks/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Traditionally, peewee hasn't supported this explicitly. Though with SQLite's new row-values stuff getting released I think it should, so I'll look at a patch.\n", "I haven't tried yet, but I just suddenly thought that I maybe could get what I want using `CommaClause`, couldn't I?\n", "Yes that should certainly work.\n", "In fact most likely that's how I'll end up implementing this: interpret tuples as CommaClause.\n", "Actually, and of course I should have realized this, the Python interpreter won't let us override the comparators for tuples, so writing:\n\n```\n(User.id, User.username) == (1, 'user-1')\n```\n\nWill be evaluated by the Python interpreter (as `True`) and at no point are we aware that the comparison is operating on a 2-tuple.\n\nSo for now, if you wish to use tuples in Peewee, you should use the new `Tuple` class (available if you `from peewee import *`). The `Tuple` class is simply an alias for `EnclosedClause`, as you had suggested.\n\nHere is how you would express the above:\n\n```\nTuple(User.id, User.username) == (1, 'user-1')\n```\n", "Hi @coleifer , I was looking for a way to express [SQLite Row Values](https://www.sqlite.org/rowvalue.html#search_against_multi_column_keys) and only found the solution above by chance.\r\nI believe this should be documented, and I'm willing to write a few words about it.\r\nWhere do you think it would be more appropriate?\r\nPerhaps in the [Expressions section of the Query Operators chapter](http://docs.peewee-orm.com/en/latest/peewee/query_operators.html?highlight=where#expressions)?", "Added some docs.", "http://docs.peewee-orm.com/en/latest/peewee/query_operators.html#row-values" ]
2016-10-21T08:23:06
2019-02-04T15:18:57
2016-11-14T02:44:45
CONTRIBUTOR
null
In a query, I need to compare tuples of values (I'm not sure how are they correctly called in SQL, maybe «records»?..), like this: ``` sql where (a.field1, a.field2) < (b.field1, b.field2) ``` Currently I achieved this by calling an empty-named function through `fn` which works but seems to be a hack or maybe even a bug, depending on how you look at it: ``` python getattr(fn, "")(a.field1, a.field2) < getattr(fn, "")(b.field1, b.field2) ``` Is there a better way to do this thing in Peewee? I am sure that it can be written manually using different `Node`s but shouldn't there be something for this out of the box?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1105/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1105/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1104
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1104/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1104/comments
https://api.github.com/repos/coleifer/peewee/issues/1104/events
https://github.com/coleifer/peewee/issues/1104
184,122,362
MDU6SXNzdWUxODQxMjIzNjI=
1,104
Segmentation fault (core dumped) when executing model_to_dict(recurse=False)
{ "login": "ajpen", "id": 4834786, "node_id": "MDQ6VXNlcjQ4MzQ3ODY=", "avatar_url": "https://avatars.githubusercontent.com/u/4834786?v=4", "gravatar_id": "", "url": "https://api.github.com/users/ajpen", "html_url": "https://github.com/ajpen", "followers_url": "https://api.github.com/users/ajpen/followers", "following_url": "https://api.github.com/users/ajpen/following{/other_user}", "gists_url": "https://api.github.com/users/ajpen/gists{/gist_id}", "starred_url": "https://api.github.com/users/ajpen/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/ajpen/subscriptions", "organizations_url": "https://api.github.com/users/ajpen/orgs", "repos_url": "https://api.github.com/users/ajpen/repos", "events_url": "https://api.github.com/users/ajpen/events{/privacy}", "received_events_url": "https://api.github.com/users/ajpen/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "It appears this could be due to low memory. I'll check that possibility.\n", "Okay, after some digging, I got this. \n\nThe segfault is a `SIGSEGV`. \n\nHere's the backtrace from gdb\n\n```\n#0 0x00000000005377c7 in _PyObject_GC_New ()\n#1 0x00000000005379da in PyDict_New ()\n#2 0x00000000004ad2fd in _PyObject_GenericSetAttrWithDict ()\n#3 0x00000000004ad9dd in PyObject_SetAttr ()\n#4 0x000000000049a356 in PyEval_EvalFrameEx ()\n#5 0x00000000004a1c9a in ?? ()\n#6 0x00000000004dfe94 in ?? ()\n#7 0x0000000000505f96 in PyObject_Call ()\n#8 0x00000000004de41a in ?? ()\n#9 0x00000000005039eb in ?? ()\n#10 0x0000000000499be5 in PyEval_EvalFrameEx ()\n#11 0x0000000000499ef2 in PyEval_EvalFrameEx ()\n#12 0x0000000000499ef2 in PyEval_EvalFrameEx ()\n#13 0x00000000004a1c9a in ?? ()\n#14 0x00000000004dfe94 in ?? ()\n#15 0x0000000000505f96 in PyObject_Call ()\n#16 0x00000000004cac9f in ?? ()\n#17 0x000000000049990f in PyEval_EvalFrameEx ()\n#18 0x00000000004a1c9a in ?? ()\n#19 0x0000000000505f96 in PyObject_Call ()\n#20 0x000000000049b07a in PyEval_EvalFrameEx ()\n#21 0x0000000000499ef2 in PyEval_EvalFrameEx ()\n#22 0x0000000000499ef2 in PyEval_EvalFrameEx ()\n#23 0x0000000000499ef2 in PyEval_EvalFrameEx ()\n#24 0x00000000004a1c9a in ?? ()\n#25 0x00000000004dfe94 in ?? ()\n#26 0x0000000000505f96 in PyObject_Call ()\n#27 0x00000000004dddad in ?? ()\n#28 0x0000000000499be5 in PyEval_EvalFrameEx ()\n#29 0x00000000004a090c in PyEval_EvalCodeEx ()\n#30 0x000000000049ab45 in PyEval_EvalFrameEx ()\n#31 0x00000000004a090c in PyEval_EvalCodeEx ()\n#32 0x000000000049ab45 in PyEval_EvalFrameEx ()\n#33 0x00000000004a090c in PyEval_EvalCodeEx ()\n#34 0x000000000049ab45 in PyEval_EvalFrameEx ()\n#35 0x00000000004a1c9a in ?? ()\n#36 0x00000000004dfe94 in ?? ()\n#37 0x0000000000499be5 in PyEval_EvalFrameEx ()\n#38 0x00000000004a090c in PyEval_EvalCodeEx ()\n#39 0x000000000049ab45 in PyEval_EvalFrameEx ()\n#40 0x00000000004a1c9a in ?? ()\n#41 0x00000000004dfe94 in ?? ()\n#42 0x0000000000505f96 in PyObject_Call ()\n#43 0x00000000004de41a in ?? ()\n#44 0x00000000005039eb in ?? ()\n#45 0x0000000000499be5 in PyEval_EvalFrameEx ()\n#46 0x0000000000499ef2 in PyEval_EvalFrameEx ()\n#47 0x0000000000499ef2 in PyEval_EvalFrameEx ()\n#48 0x0000000000499ef2 in PyEval_EvalFrameEx ()\n#49 0x00000000004a1c9a in ?? ()\n#50 0x00000000004dfe94 in ?? ()\n#51 0x0000000000499be5 in PyEval_EvalFrameEx ()\n#52 0x00000000004a090c in PyEval_EvalCodeEx ()\n---Type <return> to continue, or q <return> to quit---\n#53 0x000000000049ab45 in PyEval_EvalFrameEx ()\n#54 0x00000000004a090c in PyEval_EvalCodeEx ()\n#55 0x000000000049ab45 in PyEval_EvalFrameEx ()\n#56 0x00000000004a1c9a in ?? ()\n#57 0x0000000000505f96 in PyObject_Call ()\n#58 0x000000000049b07a in PyEval_EvalFrameEx ()\n#59 0x00000000004a090c in PyEval_EvalCodeEx ()\n#60 0x0000000000499a52 in PyEval_EvalFrameEx ()\n#61 0x00000000004a1634 in ?? ()\n#62 0x000000000044e4a5 in PyRun_FileExFlags ()\n#63 0x000000000044ec9f in PyRun_SimpleFileExFlags ()\n#64 0x000000000044f904 in Py_Main ()\n#65 0x00002aaaaaf0ff45 in __libc_start_main (main=0x44f9c2 <main>, argc=2, argv=0x7fffffffe678, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>,\n stack_end=0x7fffffffe668) at libc-start.c:287\n\n```\n\nFrom the function call at the top, I decided to up the stack size with `ulimit -s unlimited`, which was not successful. So, I'm now doubting whether its memory. I don't know if its due to the list comprehension or not, I'll try putting the list comprehension in a function and converting it to a for loop, to confirm if it is stack size related. \n", "Its memory related. Ran out of memory while loading the records. Closing\n" ]
2016-10-20T02:46:50
2016-10-20T22:27:20
2016-10-20T12:05:38
NONE
null
Here's the problematic method ``` @app.route('/get_records_by_group', methods=["POST"]) def get_records_by_group(): # try: # session["user"] # except KeyError: # return jsonify(**{"code": "401", "message" : "Unauthorized"}) parameters = request.get_json(force=True) try: group = parameters["group"] order = parameters["order"] except (KeyError, ValueError): return jsonify(**{"code":"400", "message" : "Bad parameters"}) pdb.set_trace() try: if order == "desc": records = Record.select().where( Record.verified_by == "" & Record.customer_name.startswith(group) ).order_by( Record.customer_name.desc() ) else: records = Record.select().where( Record.verified_by == "" & Record.customer_name.startswith(group) ).order_by( Record.customer_name.asc() ) except Record.DoesNotExist: return jsonify(**[]) data = [model_to_dict(x, recurse=False) for x in records] return Response( json.dumps(data, default=Record.date_handler), mimetype='application/json', ) ``` The Segmentation fault occurs at `data = [model_to_dict(x, recurse=False) for x in records]`. I'm assuming its model_to_dict but I could be wrong. To note, `records` variable/query may have a lot of records (at most over 100k, average 10k, but this amount is unlikely). I tried to get the core, but that didn't go well.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1104/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1104/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1103
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1103/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1103/comments
https://api.github.com/repos/coleifer/peewee/issues/1103/events
https://github.com/coleifer/peewee/issues/1103
183,874,618
MDU6SXNzdWUxODM4NzQ2MTg=
1,103
Select from query
{ "login": "ak4nv", "id": 73960, "node_id": "MDQ6VXNlcjczOTYw", "avatar_url": "https://avatars.githubusercontent.com/u/73960?v=4", "gravatar_id": "", "url": "https://api.github.com/users/ak4nv", "html_url": "https://github.com/ak4nv", "followers_url": "https://api.github.com/users/ak4nv/followers", "following_url": "https://api.github.com/users/ak4nv/following{/other_user}", "gists_url": "https://api.github.com/users/ak4nv/gists{/gist_id}", "starred_url": "https://api.github.com/users/ak4nv/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/ak4nv/subscriptions", "organizations_url": "https://api.github.com/users/ak4nv/orgs", "repos_url": "https://api.github.com/users/ak4nv/repos", "events_url": "https://api.github.com/users/ak4nv/events{/privacy}", "received_events_url": "https://api.github.com/users/ak4nv/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Used `from_` keyword.\n\n``` python\n subq = (HistRec\n .select(fn.unnest(fn.string_to_array(HistRec.medserv, ' ')).alias('ms'))\n .where(HistRec.state == 1)\n .alias('subq'))\n\n qs = (HistRec\n .select(subq.c.ms, fn.count(subq.c.ms))\n .from_(subq)\n .group_by(subq.c.ms)\n .order_by(subq.c.ms))\n```\n\n@coleifer thanks for perfect ORM!\n", "Glad you got it sorted out!\n" ]
2016-10-19T06:17:11
2016-10-25T18:37:29
2016-10-25T01:37:43
NONE
null
Hi! Cannot understand how to select from query? ``` sql select ms, count(ms) from (select unnest(string_to_array(medserv,' ')) as ms from hist h where h.state = 1 ) as a group by ms order by ms ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1103/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1103/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1102
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1102/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1102/comments
https://api.github.com/repos/coleifer/peewee/issues/1102/events
https://github.com/coleifer/peewee/issues/1102
183,684,140
MDU6SXNzdWUxODM2ODQxNDA=
1,102
db.create_tables causes exception in MySQLdb
{ "login": "codylandry", "id": 12991706, "node_id": "MDQ6VXNlcjEyOTkxNzA2", "avatar_url": "https://avatars.githubusercontent.com/u/12991706?v=4", "gravatar_id": "", "url": "https://api.github.com/users/codylandry", "html_url": "https://github.com/codylandry", "followers_url": "https://api.github.com/users/codylandry/followers", "following_url": "https://api.github.com/users/codylandry/following{/other_user}", "gists_url": "https://api.github.com/users/codylandry/gists{/gist_id}", "starred_url": "https://api.github.com/users/codylandry/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/codylandry/subscriptions", "organizations_url": "https://api.github.com/users/codylandry/orgs", "repos_url": "https://api.github.com/users/codylandry/repos", "events_url": "https://api.github.com/users/codylandry/events{/privacy}", "received_events_url": "https://api.github.com/users/codylandry/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "You neglected to share the only the thing I really need to debug this: the model definition!\n", "AH, my bad. Here you go!\n\n```\nclass customer(BaseModel):\n entityId = ForeignKeyField(null=True, rel_model=entity, on_delete=\"SET NULL\")\n parent = ForeignKeyField(null=True, rel_model='self', on_delete=\"SET NULL\")\n billingAddressId = ForeignKeyField(null=True, rel_model=address, on_delete=\"SET NULL\")\n customerType = EnumField(null=True, choices=('Customer', 'Lead'))\n accountNumber = CharField(null=True, max_length=16)\n name = CharField(null=True, max_length=32)\n active = BooleanField(null=True, default=True)\n taxable = BooleanField(null=True, default=False)\n membershipId = ForeignKeyField(null=True, rel_model=ACmembership, on_delete=\"SET NULL\")\n taxItem = ForeignKeyField(null=True, rel_model=tax, on_delete=\"SET NULL\")\n laborRateAmount = DecimalField(null=True, max_digits=10, decimal_places=3)\n laborChargeRate = EnumField(null=True, choices=('Flat Rate', 'Hourly'))\n billForDriveTime = BooleanField(null=True, default=False)\n discount = DecimalField(null=True, max_digits=10, decimal_places=3)\n discountType = EnumField(null=True, choices=('%', '$'))\n referralSourceId = ForeignKeyField(null=True, rel_model=ACreferralSource, on_delete=\"SET NULL\")\n paymentTermsId = ForeignKeyField(null=True, rel_model=ACCpaymentTerms, on_delete=\"SET NULL\")\n defaultPaymentMethodId = ForeignKeyField(null=True, rel_model=ACCpaymentMethod, on_delete=\"SET NULL\")\n defaultCurrencyId = ForeignKeyField(null=True, rel_model=ACCcurrency, on_delete=\"SET NULL\")\n lastUpdated = DateTimeField(null=True, default=datetime.utcnow())\n```\n\nAnd here's the EnumField def as well:\n\n```\nclass EnumField(Field):\n db_field = \"enum\"\n\n def coerce(self, value):\n if value not in self.choices:\n raise Exception(\"Invalid Enum Value `%s`\", value)\n return str(value)\n\n def get_column_type(self):\n return \"ENUM\"\n\n def get_modifiers(self):\n return ['\"%s\"' % choice for choice in self.choices]\n```\n", "I believe it's the EnumField which has a \"%\" character. Sqlite gets upset if you explicitly pass in `None`, so that's the inverse of this particular issue (which would be solved by passing in `params or None` instead of `params or ()`). I could move this out into a db-specific parameter, I suppose...but what if you tried passing in a double percent instead of a single percent? Also if you could share the relevant ddl-generation portions of `EnumField` that'd be awesome.\n", "Here's what _query_ looks like at this point:\n\n``` python\n# in MySQLdb/cursor.py/\n def execute(self, query, args=None):\n del self.messages[:]\n db = self._get_db()\n if isinstance(query, unicode):\n query = query.encode(db.unicode_literal.charset)\n if args is not None:\n if isinstance(args, dict):\n query = query % dict((key, db.literal(item))\n for key, item in args.iteritems())\n else:\n # <--- sql below is what query looks like here --->\n query = query % tuple([db.literal(item) for item in args])\n```\n\n``` sql\nCREATE TABLE `customer` (\n `id` INTEGER AUTO_INCREMENT NOT NULL PRIMARY KEY,\n `entityId_id` INTEGER,\n `parent_id` INTEGER,\n `billingAddressId_id` INTEGER,\n `customerType` ENUM (\"Customer\", \"Lead\"),\n `accountNumber` VARCHAR(16),\n `name` VARCHAR(32),\n `active` BOOL,\n `taxable` BOOL,\n `membershipId_id` INTEGER,\n `taxItem_id` INTEGER,\n `laborRateAmount` NUMERIC(10, 3),\n `laborChargeRate` ENUM (\"Flat Rate\", \"Hourly\"),\n `billForDriveTime` BOOL,\n `discount` NUMERIC(10, 3),\n `discountType` ENUM (\"%\", \"$\"),\n `referralSourceId_id` INTEGER,\n `paymentTermsId_id` INTEGER,\n `defaultPaymentMethodId_id` INTEGER,\n `defaultCurrencyId_id` INTEGER,\n `lastUpdated` DATETIME,\n FOREIGN KEY (`entityId_id`) REFERENCES `entity` (`id`)\n ON DELETE SET NULL,\n FOREIGN KEY (`parent_id`) REFERENCES `customer` (`id`)\n ON DELETE SET NULL,\n FOREIGN KEY (`billingAddressId_id`) REFERENCES `address` (`id`)\n ON DELETE SET NULL,\n FOREIGN KEY (`membershipId_id`) REFERENCES `acmembership` (`id`)\n ON DELETE SET NULL,\n FOREIGN KEY (`taxItem_id`) REFERENCES `tax` (`id`)\n ON DELETE SET NULL,\n FOREIGN KEY (`referralSourceId_id`) REFERENCES `acreferralsource` (`id`)\n ON DELETE SET NULL,\n FOREIGN KEY (`paymentTermsId_id`) REFERENCES `accpaymentterms` (`id`)\n ON DELETE SET NULL,\n FOREIGN KEY (`defaultPaymentMethodId_id`) REFERENCES `accpaymentmethod` (`id`)\n ON DELETE SET NULL,\n FOREIGN KEY (`defaultCurrencyId_id`) REFERENCES `acccurrency` (`id`)\n ON DELETE SET NULL\n)\n```\n", "Well, in the implementation of the EnumField, I wonder if it'd be better to parameterize the values it accepts...is this possible? i.e. it would generate DDL like `SQL('ENUM (%s))' % ', '.join('%s' for _ in values), values)`.\n\nWDYT?\n", "How is that different from what it does now? The generated sql is correct and making it all the way to the execute method without issue. If this was an issue, wouldn't it cause problems in generating the field sql instead when trying to execute? By the time the generated sql gets to the db, the string formatting for the fields has been done. \n", "I verified that double % works. Sorry to waste your time. It wasn't obvious to me at first why that would fail. Thanks for looking into it though.\n", "Its completely non obvious! Glad we got it fixed.\n", "I have an application that must support both Sqlite and MySQL. How can I make the above `EnumField` compatible with `SqliteDatabase`? When I use the option `field_types={\"ENUM\": \"TEXT\"}`, the produced DDL is not valid for Sqlite:\r\n\r\n customerType TEXT(\"Customer\", \"LEAD\")\r\n\r\nInstead I want `customerType TEXT`." ]
2016-10-18T13:20:10
2021-12-01T16:06:03
2016-10-18T14:36:44
NONE
null
After creating model classes, I attempted to run db.create_tables and received the following error: ``` Traceback (most recent call last): File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 1580, in <module> globals = debugger.run(setup['file'], None, None, is_module) File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 964, in run pydev_imports.execfile(file, globals, locals) # execute the script File "/Users/codylandry/PycharmProjects/servicefusion/web2py/applications/servicefusion2/modules/create_db.py", line 197, in <module> pw_db.create_tables(tables, safe=True) File "/Users/codylandry/PycharmProjects/servicefusion/venv/lib/python2.7/site-packages/peewee.py", line 3772, in create_tables create_model_tables(models, fail_silently=safe) File "/Users/codylandry/PycharmProjects/servicefusion/venv/lib/python2.7/site-packages/peewee.py", line 5176, in create_model_tables m.create_table(**create_table_kwargs) File "/Users/codylandry/PycharmProjects/servicefusion/venv/lib/python2.7/site-packages/peewee.py", line 4857, in create_table db.create_table(cls) File "/Users/codylandry/PycharmProjects/servicefusion/venv/lib/python2.7/site-packages/peewee.py", line 3769, in create_table return self.execute_sql(*qc.create_table(model_class, safe)) File "/Users/codylandry/PycharmProjects/servicefusion/venv/lib/python2.7/site-packages/peewee.py", line 3683, in execute_sql cursor.execute(sql, params or ()) File "/Users/codylandry/PycharmProjects/servicefusion/venv/lib/python2.7/site-packages/MySQLdb/cursors.py", line 187, in execute query = query % tuple([db.literal(item) for item in args]) TypeError: not enough arguments for format string ``` Tracing this to cursors.py I found that the _args_ keyword argument in the execute function is an empty tuple instead of _None_. ``` def execute(self, query, args=None): """Execute a query. query -- string, query to execute on server args -- optional sequence or mapping, parameters to use with query. Note: If args is a sequence, then %s must be used as the parameter placeholder in the query. If a mapping is used, %(key)s must be used as the placeholder. Returns long integer rows affected, if any """ del self.messages[:] db = self._get_db() if isinstance(query, unicode): query = query.encode(db.unicode_literal.charset) if args is not None: if isinstance(args, dict): query = query % dict((key, db.literal(item)) for key, item in args.iteritems()) else: query = query % tuple([db.literal(item) for item in args]) try: r = None r = self._query(query) except TypeError, m: if m.args[0] in ("not enough arguments for format string", "not all arguments converted"): self.messages.append((ProgrammingError, m.args[0])) self.errorhandler(self, ProgrammingError, m.args[0]) else: self.messages.append((TypeError, m)) self.errorhandler(self, TypeError, m) except (SystemExit, KeyboardInterrupt): raise except: exc, value, tb = sys.exc_info() del tb self.messages.append((exc, value)) self.errorhandler(self, exc, value) self._executed = query if not self._defer_warnings: self._warning_check() return r ``` If this is being caused by my model, I'm unclear as to how. I ran the generated sql and was able to create the table the debugger had broke at, so I believe the model is written correctly. I think this just a matter of passing None if there are no arguments to the execute function. I found this in peewee.py. I'd submit a PR to change it, but I can only test it against mysql. ``` def execute_sql(self, sql, params=None, require_commit=True): logger.debug((sql, params)) with self.exception_wrapper: cursor = self.get_cursor() try: cursor.execute(sql, params or ()) # <== should be params or None ? except Exception: if self.autorollback and self.get_autocommit(): self.rollback() raise else: if require_commit and self.get_autocommit(): self.commit() return cursor ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1102/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1102/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1101
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1101/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1101/comments
https://api.github.com/repos/coleifer/peewee/issues/1101/events
https://github.com/coleifer/peewee/issues/1101
183,649,300
MDU6SXNzdWUxODM2NDkzMDA=
1,101
How to hook long query for debug information
{ "login": "THaGKI9", "id": 14999583, "node_id": "MDQ6VXNlcjE0OTk5NTgz", "avatar_url": "https://avatars.githubusercontent.com/u/14999583?v=4", "gravatar_id": "", "url": "https://api.github.com/users/THaGKI9", "html_url": "https://github.com/THaGKI9", "followers_url": "https://api.github.com/users/THaGKI9/followers", "following_url": "https://api.github.com/users/THaGKI9/following{/other_user}", "gists_url": "https://api.github.com/users/THaGKI9/gists{/gist_id}", "starred_url": "https://api.github.com/users/THaGKI9/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/THaGKI9/subscriptions", "organizations_url": "https://api.github.com/users/THaGKI9/orgs", "repos_url": "https://api.github.com/users/THaGKI9/repos", "events_url": "https://api.github.com/users/THaGKI9/events{/privacy}", "received_events_url": "https://api.github.com/users/THaGKI9/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "This would need to be implemented in the application. You can use `SIGALARM` to do this:\n\n``` python\ndef long_query(signal, frame):\n # handle long running query here\n pass\n\nsignal.signal(signal.SIGALRM, long_query)\nsignal.alarm(number_of_seconds_to_timeout)\ntry:\n execute_some_slow_query()\nfinally:\n signal.alarm(0) # Clear alarm if we succeed before timing out.\n```\n\nYou can, if using SQLite, look into the progress handler: https://docs.python.org/3/library/sqlite3.html#sqlite3.Connection.set_progress_handler\n" ]
2016-10-18T10:35:37
2016-10-18T13:54:14
2016-10-18T13:54:14
NONE
null
I found that the peewee framework doesn't provide any way to intercept any long query and it's necessary to monitor such situation for further performance improvement. Is there any efficient way?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1101/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1101/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1100
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1100/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1100/comments
https://api.github.com/repos/coleifer/peewee/issues/1100/events
https://github.com/coleifer/peewee/issues/1100
183,512,937
MDU6SXNzdWUxODM1MTI5Mzc=
1,100
get of create_or_get does not account for unique indexes
{ "login": "seaneagan", "id": 444270, "node_id": "MDQ6VXNlcjQ0NDI3MA==", "avatar_url": "https://avatars.githubusercontent.com/u/444270?v=4", "gravatar_id": "", "url": "https://api.github.com/users/seaneagan", "html_url": "https://github.com/seaneagan", "followers_url": "https://api.github.com/users/seaneagan/followers", "following_url": "https://api.github.com/users/seaneagan/following{/other_user}", "gists_url": "https://api.github.com/users/seaneagan/gists{/gist_id}", "starred_url": "https://api.github.com/users/seaneagan/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/seaneagan/subscriptions", "organizations_url": "https://api.github.com/users/seaneagan/orgs", "repos_url": "https://api.github.com/users/seaneagan/repos", "events_url": "https://api.github.com/users/seaneagan/events{/privacy}", "received_events_url": "https://api.github.com/users/seaneagan/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Correct, I can see about improving the code to include these types of constraints.\n", "To be honest, there is no piece of code I regret more than get_or_create. It's so easy to write your own version that's specific to your model. But a general purpose one is complicated. Ugh.\n", "I think I'm actually going to remove get_or_create because of all the headaches. So, closing this as won't fix.\n" ]
2016-10-17T20:02:41
2016-11-14T00:54:30
2016-11-14T00:54:30
NONE
null
It accounts for fields that are `unique=True` [here](https://github.com/coleifer/peewee/blob/8dbf04073a0b02490cc8d86ae701523cc7481a4a/peewee.py#L4871), but not (possibly composite) unique indexes set on the meta model.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1100/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1100/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1099
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1099/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1099/comments
https://api.github.com/repos/coleifer/peewee/issues/1099/events
https://github.com/coleifer/peewee/issues/1099
183,251,179
MDU6SXNzdWUxODMyNTExNzk=
1,099
trouble with ".select()" using peewee database
{ "login": "leojacoby", "id": 22846444, "node_id": "MDQ6VXNlcjIyODQ2NDQ0", "avatar_url": "https://avatars.githubusercontent.com/u/22846444?v=4", "gravatar_id": "", "url": "https://api.github.com/users/leojacoby", "html_url": "https://github.com/leojacoby", "followers_url": "https://api.github.com/users/leojacoby/followers", "following_url": "https://api.github.com/users/leojacoby/following{/other_user}", "gists_url": "https://api.github.com/users/leojacoby/gists{/gist_id}", "starred_url": "https://api.github.com/users/leojacoby/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/leojacoby/subscriptions", "organizations_url": "https://api.github.com/users/leojacoby/orgs", "repos_url": "https://api.github.com/users/leojacoby/repos", "events_url": "https://api.github.com/users/leojacoby/events{/privacy}", "received_events_url": "https://api.github.com/users/leojacoby/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "It looks like you're missing assigning your database to your model:\n\n``` python\ndb = SqliteDatabase('my_app.db')\n\nclass Player(Model):\n name = CharField()\n\n class Meta:\n database = db\n\ndb.create_tables([Player], True)\n```\n" ]
2016-10-16T05:57:19
2016-10-16T15:11:53
2016-10-16T15:11:53
NONE
null
I am making a peewee database. In my python code I try to retrieve rows from the model that may be empty: `player_in_db = Player.select().where(Player.name == player.name_display_first_last)` `Player` is the name of the model `name` is a field instance in `Player` defined... ``` class Player(Model): name = CharField() ``` `player.name_display_first_last` is a string I get an error that says `peewee.OperationalError: no such column: t1.name` I've been trying to solve this problem for the bulk of today, but to no avail. Any help would be much appreciated. Let me know if you need any more information to help me. Thanks.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1099/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1099/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1098
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1098/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1098/comments
https://api.github.com/repos/coleifer/peewee/issues/1098/events
https://github.com/coleifer/peewee/issues/1098
183,235,842
MDU6SXNzdWUxODMyMzU4NDI=
1,098
Playhouse extension for asyncpg
{ "login": "kolanos", "id": 17498, "node_id": "MDQ6VXNlcjE3NDk4", "avatar_url": "https://avatars.githubusercontent.com/u/17498?v=4", "gravatar_id": "", "url": "https://api.github.com/users/kolanos", "html_url": "https://github.com/kolanos", "followers_url": "https://api.github.com/users/kolanos/followers", "following_url": "https://api.github.com/users/kolanos/following{/other_user}", "gists_url": "https://api.github.com/users/kolanos/gists{/gist_id}", "starred_url": "https://api.github.com/users/kolanos/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/kolanos/subscriptions", "organizations_url": "https://api.github.com/users/kolanos/orgs", "repos_url": "https://api.github.com/users/kolanos/repos", "events_url": "https://api.github.com/users/kolanos/events{/privacy}", "received_events_url": "https://api.github.com/users/kolanos/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "The built-in async stuff all requires Python 3, and since Peewee supports both 2 and 3, any async will need to be implemented outside Peewee itself. I'd consider merging a `playhouse` extension, but as long as I'm still using Python 2 and `gevent`, I'm going to have trouble maintaining any 3.x-specific async code by myself.\n\nThere are some 3rd party libraries that implement async for Peewee, however:\n- [peewee-async](https://github.com/05bit/peewee-async)\n- [muffin-peewee](https://github.com/klen/muffin-peewee), integration with the async web framework [muffin](https://github.com/klen/muffin)\n\nHope that helps.\n", "Oh, I should add that psycopg2 does support async, so you can do something like this:\n\n``` python\nimport psycopg2\nfrom psycopg2 import extensions\n\nfrom gevent.socket import wait_read, wait_write\n\n\ndef monkey_patch():\n extensions.set_wait_callback(gevent_wait_callback)\n\n\ndef gevent_wait_callback(conn, timeout=None):\n while True:\n state = conn.poll()\n if state == extensions.POLL_OK:\n break\n elif state == extensions.POLL_READ:\n wait_read(conn.fileno(), timeout=timeout)\n elif state == extensions.POLL_WRITE:\n wait_write(conn.fileno(), timeout=timeout)\n else:\n raise psycopg2.OperationalError(\n\"Bad result from poll: %r\" % state)\n```\n", "@coleifer Ok, will make it an external extension for now. I did this with [peewee-momoko](https://github.com/txtadvice/peewee-momoko), but think it can be much improved with asyncpg and async /await.\n" ]
2016-10-15T22:09:19
2016-10-17T01:24:38
2016-10-16T15:15:55
NONE
null
Apologies if this has been asked already, but I would very much be interested in a playhouse extension for asyncpg: https://github.com/MagicStack/asyncpg Is this in the plans? Or better yet, if a PR was submitted to add asyncpg support would it be considered?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1098/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1098/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1097
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1097/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1097/comments
https://api.github.com/repos/coleifer/peewee/issues/1097/events
https://github.com/coleifer/peewee/issues/1097
183,179,309
MDU6SXNzdWUxODMxNzkzMDk=
1,097
Question: how to pass a database in tests?
{ "login": "aellwein", "id": 3179781, "node_id": "MDQ6VXNlcjMxNzk3ODE=", "avatar_url": "https://avatars.githubusercontent.com/u/3179781?v=4", "gravatar_id": "", "url": "https://api.github.com/users/aellwein", "html_url": "https://github.com/aellwein", "followers_url": "https://api.github.com/users/aellwein/followers", "following_url": "https://api.github.com/users/aellwein/following{/other_user}", "gists_url": "https://api.github.com/users/aellwein/gists{/gist_id}", "starred_url": "https://api.github.com/users/aellwein/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/aellwein/subscriptions", "organizations_url": "https://api.github.com/users/aellwein/orgs", "repos_url": "https://api.github.com/users/aellwein/repos", "events_url": "https://api.github.com/users/aellwein/events{/privacy}", "received_events_url": "https://api.github.com/users/aellwein/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "You may find the following helpful: http://docs.peewee-orm.com/en/latest/peewee/playhouse.html#test-utils\n\nBasically, at run-time you can swap out the database by setting `Model1._meta.database = test_db` and doing the same for `Model2`, etc. That's what the above helper takes care of (as well as schema creation).\n" ]
2016-10-15T00:57:59
2016-10-16T15:20:07
2016-10-16T15:20:07
NONE
null
The documentation mentions about best practice of passing the database from the global scope: ``` sqlite_db = SqliteDatabase('my_app.db') class BaseModel(Model): """A base model that will use our Sqlite database.""" class Meta: database = sqlite_db ``` I use exact this pattern in my own "persistence.py" module and i need to use not 'my_app.db' for the integration tests but another (temporary) one, so how i am supposed to pass database instance in an integration test?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1097/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1097/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1096
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1096/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1096/comments
https://api.github.com/repos/coleifer/peewee/issues/1096/events
https://github.com/coleifer/peewee/issues/1096
182,815,363
MDU6SXNzdWUxODI4MTUzNjM=
1,096
`model_to_dict` changes null foreign key fields to empty dicts
{ "login": "seaneagan", "id": 444270, "node_id": "MDQ6VXNlcjQ0NDI3MA==", "avatar_url": "https://avatars.githubusercontent.com/u/444270?v=4", "gravatar_id": "", "url": "https://api.github.com/users/seaneagan", "html_url": "https://github.com/seaneagan", "followers_url": "https://api.github.com/users/seaneagan/followers", "following_url": "https://api.github.com/users/seaneagan/following{/other_user}", "gists_url": "https://api.github.com/users/seaneagan/gists{/gist_id}", "starred_url": "https://api.github.com/users/seaneagan/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/seaneagan/subscriptions", "organizations_url": "https://api.github.com/users/seaneagan/orgs", "repos_url": "https://api.github.com/users/seaneagan/repos", "events_url": "https://api.github.com/users/seaneagan/events{/privacy}", "received_events_url": "https://api.github.com/users/seaneagan/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[]
2016-10-13T15:03:28
2016-10-13T20:00:31
2016-10-13T20:00:31
NONE
null
[This line](https://github.com/coleifer/peewee/blob/dc0ac68f3a596e27e117698393b4ab64d2f92617/playhouse/shortcuts.py#L125) causes a null foreign key field to be encoded as an empty dict, instead of the null that it is. When I try to decode the returned dict back into a model via `dict_to_model`, it chokes on the empty dict [here](https://github.com/coleifer/peewee/blob/bf9591c2d9a11579b7472220f0427e1547b2f539/peewee.py#L1311), since it finds a dict for the related object, but the dict is empty and thus missing a primary key. If it found a null instead, it would correctly decode the foreign key field to a null value. I tested that theory by using a function which walks the dict returned from `model_to_dict` changing all the empty dicts back to nulls: ``` python def nullify_empty_dicts(y): def is_empty_dict(x): return type(x) is dict and not x def handle(x): if type(x) is dict: for index in x: handle_index(x, index) elif type(x) is list: for index in range(len(x)): handle_index(x, index) def handle_index(x, index): v = x[index] if is_empty_dict(v): x[index] = None else: handle(v) if is_empty_dict(y): return None else: handle(y) return y ``` When I pass the result of this to `dict_to_model` it works as expected. Thanks for taking a look!
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1096/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1096/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1095
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1095/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1095/comments
https://api.github.com/repos/coleifer/peewee/issues/1095/events
https://github.com/coleifer/peewee/issues/1095
182,232,215
MDU6SXNzdWUxODIyMzIyMTU=
1,095
join select error
{ "login": "rfyiamcool", "id": 3785409, "node_id": "MDQ6VXNlcjM3ODU0MDk=", "avatar_url": "https://avatars.githubusercontent.com/u/3785409?v=4", "gravatar_id": "", "url": "https://api.github.com/users/rfyiamcool", "html_url": "https://github.com/rfyiamcool", "followers_url": "https://api.github.com/users/rfyiamcool/followers", "following_url": "https://api.github.com/users/rfyiamcool/following{/other_user}", "gists_url": "https://api.github.com/users/rfyiamcool/gists{/gist_id}", "starred_url": "https://api.github.com/users/rfyiamcool/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/rfyiamcool/subscriptions", "organizations_url": "https://api.github.com/users/rfyiamcool/orgs", "repos_url": "https://api.github.com/users/rfyiamcool/repos", "events_url": "https://api.github.com/users/rfyiamcool/events{/privacy}", "received_events_url": "https://api.github.com/users/rfyiamcool/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "i know , thanks ! \n" ]
2016-10-11T10:45:58
2016-10-11T12:04:58
2016-10-11T12:04:58
NONE
null
### this sql syntax is error ? the two table not has fk relation . ``` ProductAndCategory.select(ProductAndCategory.top_name, ProductAndCategory.second_name, ProductAndCategory.third_name, Product.pname, Product.pid).join(Product, on=((Product.pid == ProductAndCategory.pid) & (Product.product_ident != ''))) ``` error: ``` Traceback (most recent call last): File "scripts/write_json.py", line 62, in <module> write_json() File "scripts/write_json.py", line 58, in write_json product_cat_save() File "scripts/write_json.py", line 40, in product_cat_save for p in res: File "/home/ruifengyun/miniconda2/envs/xcf/lib/python2.7/site-packages/peewee.py", line 1462, in next obj = self.iterate() File "/home/ruifengyun/miniconda2/envs/xcf/lib/python2.7/site-packages/peewee.py", line 1448, in iterate self.initialize(self.cursor.description) File "/home/ruifengyun/miniconda2/envs/xcf/lib/python2.7/site-packages/peewee.py", line 1565, in initialize fk_name = join.on._alias or join.on.lhs.name AttributeError: 'Expression' object has no attribute 'name' ``` detail error ``` In [2]: res = ProductAndCategory.select(ProductAndCategory.top_name, ProductAndCategory.second_name, ProductAndCategory.third_name, Product.pname, Product.pid).join(Product, on=((Product.pid == ProductAndCategory.pid) & (Product.product_ident != ''))) In [3]: res.first() --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-3-51088aa74006> in <module>() ----> 1 res.first() /home/ruifengyun/miniconda2/envs/xcf/lib/python2.7/site-packages/peewee.pyc in first(self) 2003 def first(self): 2004 res = self.execute() -> 2005 res.fill_cache(1) 2006 try: 2007 return res._result_cache[0] /home/ruifengyun/miniconda2/envs/xcf/lib/python2.7/site-packages/peewee.pyc in fill_cache(self, n) 1474 while not self._populated and (n > self.__ct): 1475 try: -> 1476 self.next() 1477 except StopIteration: 1478 break /home/ruifengyun/miniconda2/envs/xcf/lib/python2.7/site-packages/peewee.pyc in next(self) 1460 return inst 1461 -> 1462 obj = self.iterate() 1463 self._result_cache.append(obj) 1464 self.__ct += 1 /home/ruifengyun/miniconda2/envs/xcf/lib/python2.7/site-packages/peewee.pyc in iterate(self) 1446 raise StopIteration 1447 elif not self._initialized: -> 1448 self.initialize(self.cursor.description) 1449 self._initialized = True 1450 return self.process_row(row) /home/ruifengyun/miniconda2/envs/xcf/lib/python2.7/site-packages/peewee.pyc in initialize(self, description) 1563 if not fk_field: 1564 if isinstance(join.on, Expression): -> 1565 fk_name = join.on._alias or join.on.lhs.name 1566 else: 1567 # Patch the joined model using the name of the AttributeError: 'Expression' object has no attribute 'name' ``` Thanks U !!!
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1095/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1095/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1094
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1094/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1094/comments
https://api.github.com/repos/coleifer/peewee/issues/1094/events
https://github.com/coleifer/peewee/pull/1094
182,197,898
MDExOlB1bGxSZXF1ZXN0ODg3ODczMDU=
1,094
Easier way to define index type for Postgres custom 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
[ "Not sure what the purpose is for this change, can you explain?\n", "> Not sure what the purpose is for this change, can you explain?\n\nAllow to deal with `index_type` without the need of inheriting from `IndexedFieldMixin`.\nThe simpler, the better :)\n", "I appreciate the simplicity of this... let me think about it. Thanks!\n" ]
2016-10-11T08:04:19
2016-10-16T05:14:54
2016-10-16T05:14:54
CONTRIBUTOR
null
Thanks :)
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1094/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1094/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/1094", "html_url": "https://github.com/coleifer/peewee/pull/1094", "diff_url": "https://github.com/coleifer/peewee/pull/1094.diff", "patch_url": "https://github.com/coleifer/peewee/pull/1094.patch", "merged_at": null }
https://api.github.com/repos/coleifer/peewee/issues/1093
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1093/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1093/comments
https://api.github.com/repos/coleifer/peewee/issues/1093/events
https://github.com/coleifer/peewee/issues/1093
181,828,131
MDU6SXNzdWUxODE4MjgxMzE=
1,093
Unable to except OperationalError / connection trying to be closed after catch block
{ "login": "theotherp", "id": 14368889, "node_id": "MDQ6VXNlcjE0MzY4ODg5", "avatar_url": "https://avatars.githubusercontent.com/u/14368889?v=4", "gravatar_id": "", "url": "https://api.github.com/users/theotherp", "html_url": "https://github.com/theotherp", "followers_url": "https://api.github.com/users/theotherp/followers", "following_url": "https://api.github.com/users/theotherp/following{/other_user}", "gists_url": "https://api.github.com/users/theotherp/gists{/gist_id}", "starred_url": "https://api.github.com/users/theotherp/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/theotherp/subscriptions", "organizations_url": "https://api.github.com/users/theotherp/orgs", "repos_url": "https://api.github.com/users/theotherp/repos", "events_url": "https://api.github.com/users/theotherp/events{/privacy}", "received_events_url": "https://api.github.com/users/theotherp/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "OK, I found a bug in Peewee where the calls to commit and rollback weren't being wrapped in the exception wrapper that converts driver-specific exceptions into peewee exceptions. So that is fixed in 900ed22ee5505fa56565d52dc22cfbce496ec60f\n", "```\nOperationalError: cannot commit - no transaction is active\n```\n\nThis exception, with SqliteQueueDatabase, is what I tried to warn folks about when using this database class. If you try to use transactions in multiple threads at the same time, there is a risk of interleaving that will yield exactly this kind of error. For example:\n- t1: BEGIN\n- t1: INSERT\n- t2: BEGIN -- error, cannot start transaction within a transaction.\n\nOr the opposite:\n- t1: BEGIN;\n- t2: COMMIT;\n- t1: INSERT;\n- t1: COMMIT; -- error no transaction active.\n", "> I managed to get rid of all errors by using a thread lock for the main part of the code that writes to the database. It increases the run time but that's worth it. I leave it up to you to close this or investigate further.\n\nIf you're going to use the SqliteQueueDatabase, then you're responsible for managing your transactions such that these kinds of things don't happen. Because with the way it's designed to work, it's quite easy to shoot yourself in the foot. I strongly suggest reading the code to get an understanding for how it works. I also strongly suggest reading the isolation documentation on sqlite's website:\n\nhttp://sqlite.org/isolation.html\n\nThis will help you understand why things happen the way they do when you have multiple threads operating on a single database.\n", "You wrote in the other thread I shouldn't be using multi-statement transactions. Does that mean that without using db.atomic() this wouldn't happen? I read your code and tried to understand it. I generally try to do some research and experiments before bothering others (although it might seem otherwise ;-)) but I got nowhere. I tried to replicate my problems in an easier program but was unable to do so (probably because I don't understand it correctly).\n\nAnyway, thank you; I will do some reading. I never knew what I got into when I introduced a database in my tool...\n", "So the issue was this, as I understand it.\n\nEach database driver (sqlite3, pymysql, psycopg2, etc) implements all or most of the DB-API 2.0 spec (PEP-249). This PEP outlines a handful of exception types. What Peewee does is it _wraps_ the vendor-specific exception classes so that you only need to worry about catching the exceptions defined in Peewee itself. This allows portability between db implementations, e.g., I can catch `peewee.OperationalError` instead of having to catch `sqlite3.OperationalError` or `psycopg2.OperationalError`. Unfortunately, though, there was no exception wrapping taking place on the methods where Peewee was calling \"commit\" and \"rollback\" directly on the database driver. This meant that if you called commit and it triggered an OperationalError, you would get the \"vendor-specific\" version as opposed to the peewee version. **That** bug is what the above commit, 900ed22, fixes.\n", "Hm. I think I tried to catch the specific OperationalError and it didn't help. But doesn't matter, it seems to be mostly fixed by doing some locking and so on. Thanks for the help.\n", "> You wrote in the other thread I shouldn't be using multi-statement transactions. Does that mean that without using db.atomic() this wouldn't happen?\n\nThe raison d'être for `db.atomic()` is to allow multi-statement transactions. So, it would follow that this isn't going to play nicely with SqliteQueueDatabase. The reasons are described above, but have to do with the fact that behind-the-scenes there is only _one_ connection writing to the database despite there being the appearance of multiple concurrent writers. I feel like I've explained this numerous times, is there something that's unclear about how it works?\n", "No, I wanted to be sure I got it. Thanks for the patience ;-)\n" ]
2016-10-08T14:10:28
2016-10-10T20:12:45
2016-10-09T20:22:12
NONE
null
This is what my code looks like: ``` try: searchResult, _ = tryGetOrCreateSearchResultDbEntry(indexer.indexer.id, result) result.searchResultId = searchResult.id search_results.append(result) except (IntegrityError, OperationalError) as e: logger.error("Error while trying to save search result to database. Skipping it. Error: %s" % e) ``` and this the stacktrace: ``` 2016-10-08 16:05:21,416 - ERROR - web - cannot commit - no transaction is active Traceback (most recent call last): File "/home/snowcrash/nzbhydra/nzbhydra/web.py", line 570, in api_search result = search.search(search_request) File "/home/snowcrash/nzbhydra/nzbhydra/search.py", line 318, in search logger.error("Error while trying to save search result to database. Skipping it. Error: %s" % e) File "/home/snowcrash/nzbhydra/libs/peewee.py", line 4314, in __exit__ return self._helper.__exit__(exc_type, exc_val, exc_tb) File "/home/snowcrash/nzbhydra/libs/peewee.py", line 4348, in __exit__ self.commit(False) File "/home/snowcrash/nzbhydra/libs/peewee.py", line 4325, in commit self.db.commit() File "/home/snowcrash/nzbhydra/libs/peewee.py", line 3711, in commit self.get_conn().commit() OperationalError: cannot commit - no transaction is active ``` So some part of the code magically tries to commit and fails. I'd like to ignore the OperationalError (as I'm unable to completely prevent it) that happens while trying to access the db but can't catch that exception, then it's raised in the catch block. I even tried disabling autocommit before and committing manually but even then the error occurred. Edit: I managed to get rid of all errors by using a thread lock for the main part of the code that writes to the database. It increases the run time but that's worth it. I leave it up to you to close this or investigate further.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1093/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1093/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1092
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1092/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1092/comments
https://api.github.com/repos/coleifer/peewee/issues/1092/events
https://github.com/coleifer/peewee/issues/1092
181,774,359
MDU6SXNzdWUxODE3NzQzNTk=
1,092
Calling db.rollback() instead of tx.rollback()
{ "login": "stenci", "id": 5955495, "node_id": "MDQ6VXNlcjU5NTU0OTU=", "avatar_url": "https://avatars.githubusercontent.com/u/5955495?v=4", "gravatar_id": "", "url": "https://api.github.com/users/stenci", "html_url": "https://github.com/stenci", "followers_url": "https://api.github.com/users/stenci/followers", "following_url": "https://api.github.com/users/stenci/following{/other_user}", "gists_url": "https://api.github.com/users/stenci/gists{/gist_id}", "starred_url": "https://api.github.com/users/stenci/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/stenci/subscriptions", "organizations_url": "https://api.github.com/users/stenci/orgs", "repos_url": "https://api.github.com/users/stenci/repos", "events_url": "https://api.github.com/users/stenci/events{/privacy}", "received_events_url": "https://api.github.com/users/stenci/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "```\n+ if self.transaction_depth():\n+ raise Exception('Database.rollback() called while in a transaction (call transaction.rollback() instead).')\n self.get_conn().rollback()\n```\n\nI see the logic in what you're trying to do here, unfortunately I think this one boils down to user error as the docs are quite clear on showing the correct calling conventions.\n", "I agree, Peewee is well written and documented, and the right place to teach how to use it is the documentation, not raising exceptions.\n\nWhen I write code that I only will re-read, I never write documentation or comments, and if it's small no tests either. Instead I fill it up with `assert`s that will warn me when I will use it in the wrong way.\n\nI opened this issue just to give you some (hopefully constructive) feedback about something that for me wasn't intuitive and led me to a few bugs.\n", "I am playing with `SqliteQueueDatabase`, which doesn't play nice with transactions and which doesn't clearly say it in the documentation. \n\nThis is another case where I would use assert/exceptions to tell the developer that they are using transactions in the wrong way.\n\nWould that improve Peewee? No\n\nWould that help some distracted developer? Yes\n", "For one, there is a big fat warning on the SqliteQueueDatabase stating:\n\n> This is a new module and should be considered alpha-quality software \n\nFurthermore, I haven't even finished documenting the module. Or stabilized the API. \n", "> The db.rollback() from inside a transaction works, but does not automatically begin a new transaction\n\nI think this is as it should be. There is a separate method named `begin()`, so it seems quite confusing that the `Database.rollback` would also magically call `Database.begin()`.\n\nThis changes, however, when you move to using a transaction as a context manager or function decorator. In these cases, you're saying \"I want a transaction for the duration of the wrapped block\" -- if you happen to explicitly call commit or rollback on the transaction object, a new transaction begins to maintain the agreement about keeping the wrapped block atomic.\n" ]
2016-10-07T21:46:26
2016-10-10T20:12:20
2016-10-10T20:12:20
CONTRIBUTOR
null
I found a few errors in my app caused by the incorrect use of `rollback()`: Sometimes I called `db.rollback()` while inside (a function called from) a `with transaction as tx:` block instead of calling `tx.rollback()`. 1. The `db.rollback()` from inside a transaction works, but does not automatically [begin a new transaction](http://docs.peewee-orm.com/en/latest/peewee/api.html?highlight=rollback%28%29#transaction.rollback) 2. The following `tx.rollback()` fails silently The little change shown below in `Database.rollback()` and `transaction.rollback()` raises an exception and prevents from making something that stupid. I'm not even trying to make a pull request because I don't know what type of exception should be risen, how to make a test and, most imporatantly, whether this makes sense or not. ``` python class Database(object): def rollback(self): + if self.transaction_depth(): + raise Exception('Database.rollback() called while in a transaction (call transaction.rollback() instead).') self.get_conn().rollback() class transaction(_callable_context_manager): def rollback(self, begin=True): - self.db.rollback() + self.db.get_conn().rollback() if begin: self._begin() ``` The following code should print only 4 and 8 or should fail. Instead it dangerously prints 4, 7 and 8. ``` python import peewee db = peewee.SqliteDatabase(':memory:') class Table1(peewee.Model): n = peewee.IntegerField() class Meta: database = db with db.transaction(): Table1.create_table(True) with db.transaction() as tx: Table1.create(n=1) tx.rollback() Table1.create(n=2) tx.rollback() Table1.create(n=3) tx.rollback() Table1.create(n=4) with db.transaction() as tx: Table1.create(n=5) tx.rollback() Table1.create(n=6) db.rollback() Table1.create(n=7) tx.rollback() Table1.create(n=8) for rec in Table1.select(): print(rec.n) ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1092/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1092/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1091
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1091/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1091/comments
https://api.github.com/repos/coleifer/peewee/issues/1091/events
https://github.com/coleifer/peewee/issues/1091
181,601,016
MDU6SXNzdWUxODE2MDEwMTY=
1,091
Unable to delete sqlite file after connection was closed
{ "login": "theotherp", "id": 14368889, "node_id": "MDQ6VXNlcjE0MzY4ODg5", "avatar_url": "https://avatars.githubusercontent.com/u/14368889?v=4", "gravatar_id": "", "url": "https://api.github.com/users/theotherp", "html_url": "https://github.com/theotherp", "followers_url": "https://api.github.com/users/theotherp/followers", "following_url": "https://api.github.com/users/theotherp/following{/other_user}", "gists_url": "https://api.github.com/users/theotherp/gists{/gist_id}", "starred_url": "https://api.github.com/users/theotherp/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/theotherp/subscriptions", "organizations_url": "https://api.github.com/users/theotherp/orgs", "repos_url": "https://api.github.com/users/theotherp/repos", "events_url": "https://api.github.com/users/theotherp/events{/privacy}", "received_events_url": "https://api.github.com/users/theotherp/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Looking at the code for the SQLiteQueueDatabase, I think I need to add some logic in there to close the connection. I'll get a patch up in a minute.\n", "Note: I can delete the file on linux but not in windows.\n", "I added the fix for that here: 72c5ea98209241f0fb3e2c1a330644735f803370\n\nBasically, each worker thread needed to be responsible for closing it's own connection, which wasn't happening. This should be fixed now.\n", "Thank you!\n", "Although this was a somewhat obscure problem in my case, if I can help only one developer not spend hours on trying to debug this issue... For future reference:\n\nI'm developing a flask app for which I have an automatic reloader enabled which restarts the web app every time a python file is changed (this is not enabled in production, of course). This forked the process (so that it can close the old one and restart it on change) which created a handle on the database file and locked it. That's why it could not be deleted. I started flask with the reloader disabled and voilà, the file could be deleted after closing the database. It worked on my linux test VM because there I have production code running where the reloader is disabled, but I was misled into thinking it could be an OS issue.\n\nI'll need to check how many of my database issues are caused by this because, as you quoted correctly, sqlite connections shouldn't be taken over into forks but I never thought of this reloader and of course I did all my tests with it enabled...\n\n![panda](https://media.giphy.com/media/14aUO0Mf7dWDXW/giphy.gif)\n" ]
2016-10-07T07:23:13
2016-10-10T20:50:28
2016-10-10T19:59:25
NONE
null
I'm working on a feature that allows restoring data from a backup ZIP. For this I want to replace the existing database file with one from the ZIP. But even after stopping and closing the SqliteQueueDatabase the file is still used by my process. I've tried to write a simple script to reproduce this issue but of course there it works fine. Do you have any ideas what could be the reason that the file is still locked and how to solve that? Thanks.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1091/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1091/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1090
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1090/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1090/comments
https://api.github.com/repos/coleifer/peewee/issues/1090/events
https://github.com/coleifer/peewee/issues/1090
181,600,367
MDU6SXNzdWUxODE2MDAzNjc=
1,090
SqliteQueueDatabase.is_stopped() returns false even after successful stop
{ "login": "theotherp", "id": 14368889, "node_id": "MDQ6VXNlcjE0MzY4ODg5", "avatar_url": "https://avatars.githubusercontent.com/u/14368889?v=4", "gravatar_id": "", "url": "https://api.github.com/users/theotherp", "html_url": "https://github.com/theotherp", "followers_url": "https://api.github.com/users/theotherp/followers", "following_url": "https://api.github.com/users/theotherp/following{/other_user}", "gists_url": "https://api.github.com/users/theotherp/gists{/gist_id}", "starred_url": "https://api.github.com/users/theotherp/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/theotherp/subscriptions", "organizations_url": "https://api.github.com/users/theotherp/orgs", "repos_url": "https://api.github.com/users/theotherp/repos", "events_url": "https://api.github.com/users/theotherp/events{/privacy}", "received_events_url": "https://api.github.com/users/theotherp/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[]
2016-10-07T07:18:17
2016-10-10T19:58:01
2016-10-10T19:58:01
NONE
null
I guess because `self._is_stopped` is never set to true in `stop()`? To reproduce: ``` from playhouse.sqliteq import SqliteQueueDatabase db = SqliteQueueDatabase("reproduce.db") was_started = db.start() print("Database was started: %s" % was_started) was_stopped = db.stop() print("Database was stopped: %s" % was_stopped) print("Database is stopped: %s" % db.is_stopped()) ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1090/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1090/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1089
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1089/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1089/comments
https://api.github.com/repos/coleifer/peewee/issues/1089/events
https://github.com/coleifer/peewee/issues/1089
181,229,688
MDU6SXNzdWUxODEyMjk2ODg=
1,089
Deferring initialization doesn't work with SqliteQueueDatabase
{ "login": "theotherp", "id": 14368889, "node_id": "MDQ6VXNlcjE0MzY4ODg5", "avatar_url": "https://avatars.githubusercontent.com/u/14368889?v=4", "gravatar_id": "", "url": "https://api.github.com/users/theotherp", "html_url": "https://github.com/theotherp", "followers_url": "https://api.github.com/users/theotherp/followers", "following_url": "https://api.github.com/users/theotherp/following{/other_user}", "gists_url": "https://api.github.com/users/theotherp/gists{/gist_id}", "starred_url": "https://api.github.com/users/theotherp/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/theotherp/subscriptions", "organizations_url": "https://api.github.com/users/theotherp/orgs", "repos_url": "https://api.github.com/users/theotherp/repos", "events_url": "https://api.github.com/users/theotherp/events{/privacy}", "received_events_url": "https://api.github.com/users/theotherp/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "You need to call `db.start()` before any queries are going to run.\n", "Doesn't change the outcome.\n", "Oh, your model isn't referencing your database. Duh.\n", "``` python\nclass TestModel(Model):\n test = CharField(null=True)\n\n class Meta:\n database = db\n```\n", "Oops, that what happens when you try to simplify your existing code to reproduce something. Sorry about that.\n" ]
2016-10-05T18:24:17
2016-10-05T18:51:52
2016-10-05T18:38:26
NONE
null
To reproduce: ``` import os from peewee import CharField, Model from playhouse.sqliteq import SqliteQueueDatabase class TestModel(Model): test = CharField(null=True) db = SqliteQueueDatabase(None) db.init("reproduce.db") TestModel.create_table() print("peewee.db was created: %s" % os.path.exists("peewee.db")) print("reproduce.db was created: %s" % os.path.exists("reproduce.db")) ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1089/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1089/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1088
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1088/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1088/comments
https://api.github.com/repos/coleifer/peewee/issues/1088/events
https://github.com/coleifer/peewee/issues/1088
181,217,913
MDU6SXNzdWUxODEyMTc5MTM=
1,088
ResultTimeout when using SqliteQueueDatabase in forked process
{ "login": "theotherp", "id": 14368889, "node_id": "MDQ6VXNlcjE0MzY4ODg5", "avatar_url": "https://avatars.githubusercontent.com/u/14368889?v=4", "gravatar_id": "", "url": "https://api.github.com/users/theotherp", "html_url": "https://github.com/theotherp", "followers_url": "https://api.github.com/users/theotherp/followers", "following_url": "https://api.github.com/users/theotherp/following{/other_user}", "gists_url": "https://api.github.com/users/theotherp/gists{/gist_id}", "starred_url": "https://api.github.com/users/theotherp/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/theotherp/subscriptions", "organizations_url": "https://api.github.com/users/theotherp/orgs", "repos_url": "https://api.github.com/users/theotherp/repos", "events_url": "https://api.github.com/users/theotherp/events{/privacy}", "received_events_url": "https://api.github.com/users/theotherp/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "From the SQLite FAQ:\n\n> Under Unix, you should not carry an open SQLite database across a fork() system call into the child process.\n", "Thanks. But what if I initialize the database in the child process, not the parent process?\n", "Can you show more code, particularly:\n- How are you instantiating the database?\n- What database things happen before fork?\n- What database things happen after fork?\n", "Are you calling `db.start()` in the child process? Are you doing anything like creating tables before the fork? Are any connections (or implicit connections) created before the fork?\n", "You're right, I was not explicitly calling `db.start()` but instead using `autostart=True`. I thought that when initializing the database in the child process that would suffice. But apparently the SQLite instance is opened in the parent process but the database connection only made in the child process or something? You know that better than I do, but after disabling autostart and explicitly calling `db.start()` in the child process everything works fine.\n\nThanks so much! I'd be happy to send you a tip or a postcard or what not\n", "> But apparently the SQLite instance is opened in the parent process but the database connection only made in the child process or something?\n\nNo, that's not correct. I've started adding documentation for this new feature, which explains how all of this works:\n\nhttp://docs.peewee-orm.com/en/latest/peewee/playhouse.html#sqliteq\n\nIf, after reading, you still have questions about how this works feel free to respond on this ticket.\n", "> Thanks so much! I'd be happy to send you a tip or a postcard or what not\n\nThanks for the offer, the best thanks you can give me is to continue creating issues. In this case there wasn't a bug, technically, but I'm sure other people will have the same question and hopefully find our discussion.\n", "Alright, thanks again and I'll definitely open tickets when I have questions or found a bug that's actually one ;-)\n" ]
2016-10-05T17:32:34
2016-10-05T19:37:39
2016-10-05T18:59:44
NONE
null
I tried your new SqliteQueueDatabase which appears to be awesome and exactly what I needed to get rid of some ugly _database is locked_ errors. Unfortunately I can't get it to work inside a forked process. I use [os.fork()](https://github.com/theotherp/nzbhydra/blob/master/nzbhydra.py#L38) to run my program as a daemon process. The next time I try to access to the database I get: ``` Traceback (most recent call last): File "/home/user/app/nzbhydra/libs/flask/app.py", line 1475, in full_dispatch_request rv = self.dispatch_request() File "/home/user/app/nzbhydra/libs/flask/app.py", line 1461, in dispatch_request return self.view_functions[rule.endpoint](**req.view_args) File "/home/user/app/nzbhydra/nzbhydra/web.py", line 338, in wrapped_function return f(*args, **kwargs) File "/home/user/app/nzbhydra/libs/webargs/core.py", line 368, in wrapper return func(*new_args, **kwargs) File "/home/user/app/nzbhydra/nzbhydra/web.py", line 667, in internalapi_search searchResult = startSearch(search_request) File "/home/user/app/nzbhydra/nzbhydra/web.py", line 631, in startSearch results = search.search(search_request) File "/home/user/app/nzbhydra/nzbhydra/search.py", line 225, in search oldSearchResultsCount = SearchResult.select().where(SearchResult.firstFound < (datetime.date.today() - datetime.timedelta(days=keepFor))).count() File "/home/user/app/nzbhydra/libs/peewee.py", line 3086, in count return self.aggregate(convert=False) or 0 File "/home/user/app/nzbhydra/libs/peewee.py", line 3079, in aggregate return self._aggregate(aggregation).scalar(convert=convert) File "/home/user/app/nzbhydra/libs/peewee.py", line 2850, in scalar row = self._execute().fetchone() File "/home/user/app/nzbhydra/libs/playhouse/sqliteq.py", line 92, in fetchone self._wait() File "/home/user/app/nzbhydra/libs/playhouse/sqliteq.py", line 51, in _wait raise ResultTimeout('results not ready, timed out.') ``` I realize this use case / problem is somewhat obscure but would be happy for any help. Thank you. Edit: I'm currently trying to write a script that reproduces this but, of course, haven't been able so far.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1088/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1088/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1087
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1087/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1087/comments
https://api.github.com/repos/coleifer/peewee/issues/1087/events
https://github.com/coleifer/peewee/issues/1087
181,021,286
MDU6SXNzdWUxODEwMjEyODY=
1,087
SqliteQueueDatabase.execute_sql() doesn't work
{ "login": "stenci", "id": 5955495, "node_id": "MDQ6VXNlcjU5NTU0OTU=", "avatar_url": "https://avatars.githubusercontent.com/u/5955495?v=4", "gravatar_id": "", "url": "https://api.github.com/users/stenci", "html_url": "https://github.com/stenci", "followers_url": "https://api.github.com/users/stenci/followers", "following_url": "https://api.github.com/users/stenci/following{/other_user}", "gists_url": "https://api.github.com/users/stenci/gists{/gist_id}", "starred_url": "https://api.github.com/users/stenci/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/stenci/subscriptions", "organizations_url": "https://api.github.com/users/stenci/orgs", "repos_url": "https://api.github.com/users/stenci/repos", "events_url": "https://api.github.com/users/stenci/events{/privacy}", "received_events_url": "https://api.github.com/users/stenci/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Odd...that should work. The call to start() is needed (or initialize with autostart=True) because that sets up the worker threads which actually execute the queries. Also, the SqliteQueueDatabase sets the journal mode to wal automatically, but the query should work regardless. Are you using gevent? And when you say it doesn't work does it block forever without returning, time out, or return nothing? I'm afk otherwise I'd just check.\n", "It returns an `AsyncCursor`, but the `next()` of it returns `TypeError: 'NoneType' object is not subscriptable`.\n\nI don't use `gevent`. The 3 lines of code on my example are all it takes to reproduce in a clean new environment with peewee.\n\nI don't need it to work for me, I just reported because I noticed and it smelled funny.\n", "Aha, I see the issue. The call to `next()` is not forcing the cursor to wait for the worker thread to send back the results and fire off the event. Basically, it's using an API loophole.\n\nTry this:\n\n``` python\ndb.start() # You always need either this, or autostart=True.\nprint('journal mode = ', next(iter(db.execute_sql('pragma journal_mode')))[0]) # Note \"iter\"\n```\n\nFor performance reasons I would like to avoid checking the `Event` state every iteration (every call to next).\n", "I thought I had a solid understanding of python's iterator protocol, but the `next` builtin function kind of threw me off. I guess that it does not call it's argument's `__iter__()` method and directly calls `__next__()` instead. Not sure how to proceed at this point, as calling wait() every time a row is retrieved is going to make this slow as hell for large result sets.\n" ]
2016-10-04T22:27:53
2016-10-06T03:48:34
2016-10-06T03:48:34
CONTRIBUTOR
null
I noticed that this works: ``` python import peewee db = peewee.SqliteDatabase('test.db') print('journal mode = ', next(db.execute_sql('pragma journal_mode'))[0]) ``` but this doesn't (with or without the `db.start()`): ``` python from playhouse.sqliteq import SqliteQueueDatabase db = SqliteQueueDatabase('test.db') # db.start() print('journal mode = ', next(db.execute_sql('pragma journal_mode'))[0]) ``` I don't know if it is supposed to work, but I'm reporting it because I couldn't find any documentation about this limitation and I assume it is supposed to work.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1087/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1087/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1086
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1086/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1086/comments
https://api.github.com/repos/coleifer/peewee/issues/1086/events
https://github.com/coleifer/peewee/issues/1086
180,924,060
MDU6SXNzdWUxODA5MjQwNjA=
1,086
date is None with MySQL
{ "login": "albertz", "id": 59132, "node_id": "MDQ6VXNlcjU5MTMy", "avatar_url": "https://avatars.githubusercontent.com/u/59132?v=4", "gravatar_id": "", "url": "https://api.github.com/users/albertz", "html_url": "https://github.com/albertz", "followers_url": "https://api.github.com/users/albertz/followers", "following_url": "https://api.github.com/users/albertz/following{/other_user}", "gists_url": "https://api.github.com/users/albertz/gists{/gist_id}", "starred_url": "https://api.github.com/users/albertz/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/albertz/subscriptions", "organizations_url": "https://api.github.com/users/albertz/orgs", "repos_url": "https://api.github.com/users/albertz/repos", "events_url": "https://api.github.com/users/albertz/events{/privacy}", "received_events_url": "https://api.github.com/users/albertz/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Peewee is using `pymysql` under-the-hood (or `MySQLdb`, whichever you've got installed), so when you are querying the value using `pymysql` directly and not receiving anything that tells me that the issue is not with Peewee but somewhere else. Perhaps with `pymysql` though I'm not sure.\n", "I reported it to pymysql. I guess you are right, it should be fixed in pymysql, but it might make sense to also provide a work-around in peewee. Or at least, for now when this is not fixed, how would an easy work-around look like to use this in peewee? Basically doing `SELECT CAST(publish_date AS char) FROM pub`.\n", "The problem is that the `datetime` object does not allow something like `(2016, 0, 0)`. That's why pymysql currently failed to convert it and return it. It is possible to disable this conversation in pymysql, but then, I think peewee has the same problem. Currently, peewee will just pass through the string and not convert it properly. As far as I understand, something like `entry.publish_date.year` should normally work, but it does not for my case because `entry.publish_date` is a string. Do you consider that as a bug in peewee?\n", "Not at all a bug in peewee.\n" ]
2016-10-04T15:21:10
2016-10-05T15:40:06
2016-10-04T21:03:42
NONE
null
Via `pwiz` on my MySQL database, I get: ``` class BaseModel(Model): class Meta: database = database class Pub(BaseModel): ... author = TextField(null=True) ... publish_date = DateField(null=True) ... ``` Then, when iterating `entry in Pub.select()`, `entry.publish_date` is always `None`, although all entries in the database have the date set (or at least part of it, such as year, i.e. an entry like `2016-00-00`). Why is that? Maybe `formats` is wrong? How to fix this? I guess that `peewee` will use `pymsql` under the hood. So I tried to do this simple thing: ``` import pymysql conn = pymysql.connect(...) cur = conn.cursor() cur.execute("SELECT publish_date FROM pub") ``` And then iterating `row in cur`, I will only get `row == (None,)`. So, not sure if this is a bug in peewee or in pymysql. When casting the value beforehand to `char`, it works, i.e. I get the value as a string: ``` cur.execute("SELECT CAST(publish_date AS char) FROM pub") ``` So, should peewee automatically do this? How can I do that myself now as a work around? (Also asked on StackOverflow [here](http://stackoverflow.com/questions/39854677/peewee-datefield-property-is-none-with-mysql-database).)
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1086/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1086/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1085
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1085/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1085/comments
https://api.github.com/repos/coleifer/peewee/issues/1085/events
https://github.com/coleifer/peewee/issues/1085
180,868,115
MDU6SXNzdWUxODA4NjgxMTU=
1,085
SQL views
{ "login": "gjask", "id": 3306648, "node_id": "MDQ6VXNlcjMzMDY2NDg=", "avatar_url": "https://avatars.githubusercontent.com/u/3306648?v=4", "gravatar_id": "", "url": "https://api.github.com/users/gjask", "html_url": "https://github.com/gjask", "followers_url": "https://api.github.com/users/gjask/followers", "following_url": "https://api.github.com/users/gjask/following{/other_user}", "gists_url": "https://api.github.com/users/gjask/gists{/gist_id}", "starred_url": "https://api.github.com/users/gjask/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/gjask/subscriptions", "organizations_url": "https://api.github.com/users/gjask/orgs", "repos_url": "https://api.github.com/users/gjask/repos", "events_url": "https://api.github.com/users/gjask/events{/privacy}", "received_events_url": "https://api.github.com/users/gjask/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I find views to be in a bit of a gray area...kind of like triggers. My personal feeling is that there's enough variety in the types of SQL I'd need to support that until now peewee has avoided representing views or providing helpers to create/drop them. I think that for the time being I will continue to leave this unimplemented to focus on implementing and improving other features that may be more useful generally.\n" ]
2016-10-04T11:29:19
2016-10-04T19:37:51
2016-10-04T19:37:51
NONE
null
I think it would be useful to be able create sql views using peewee api, that would be created with other tables from model classes. As things are now it seems I am forced to create views manually using sql and then create related peewee model.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1085/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1085/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1084
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1084/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1084/comments
https://api.github.com/repos/coleifer/peewee/issues/1084/events
https://github.com/coleifer/peewee/issues/1084
180,664,234
MDU6SXNzdWUxODA2NjQyMzQ=
1,084
SQL() replacement char conflicting with Postgresql JSON operator
{ "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
[ "Peewee's JSON fields contain methods that wrap the Postgres operators:\n\nhttp://docs.peewee-orm.com/en/latest/peewee/playhouse.html#BinaryJSONField\n", "Have you tried this?\n\n```\nMyModel.jsonb_field.contains('the key')\n```\n", "I'd suggest that you could also use reduce to generate a list of clauses OR--ed or AND-ed together:\n\n```\nimport operator\nreduce(operator.and_, [MyModel.jsonb_field.contains(key) for key in keys])\n```\n", "Also:\n\nhttp://docs.peewee-orm.com/en/latest/peewee/querying.html#adding-user-defined-operators\n", "Awesome I haven't had a chance to go back through this code again but I think one of these will do the trick. Will reopen if I have any issues, thanks for your help!\n" ]
2016-10-03T15:04:39
2016-10-05T08:22:23
2016-10-05T08:22:23
CONTRIBUTOR
null
I've been trying to query for the existence of a string in a `JSONField` which contains a list of strings. I've resorted to trying to use raw `SQL()` because from what I can glean from reading the code / [this blog post](http://charlesleifer.com/blog/postgresql-hstore-json-data-type-and-arrays-with-peewee-orm/) this sort of operator isn't baked in just yet. Problem is that the operator I need from postgres is `?` :/ https://www.postgresql.org/docs/current/static/functions-json.html#FUNCTIONS-JSONB-OP-TABLE Obviously getting a conflict with the standard operator vs the param replacement token. My only suggestion might be to add in the ability to escape it using `\` potentially, that'd maintain backwards compatibility and be a nice solution. Many thanks, Alex
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1084/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1084/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1083
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1083/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1083/comments
https://api.github.com/repos/coleifer/peewee/issues/1083/events
https://github.com/coleifer/peewee/issues/1083
180,022,008
MDU6SXNzdWUxODAwMjIwMDg=
1,083
AttributeError: 'DatabaseError' object has no attribute 'message'
{ "login": "thacoon", "id": 14902783, "node_id": "MDQ6VXNlcjE0OTAyNzgz", "avatar_url": "https://avatars.githubusercontent.com/u/14902783?v=4", "gravatar_id": "", "url": "https://api.github.com/users/thacoon", "html_url": "https://github.com/thacoon", "followers_url": "https://api.github.com/users/thacoon/followers", "following_url": "https://api.github.com/users/thacoon/following{/other_user}", "gists_url": "https://api.github.com/users/thacoon/gists{/gist_id}", "starred_url": "https://api.github.com/users/thacoon/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/thacoon/subscriptions", "organizations_url": "https://api.github.com/users/thacoon/orgs", "repos_url": "https://api.github.com/users/thacoon/repos", "events_url": "https://api.github.com/users/thacoon/events{/privacy}", "received_events_url": "https://api.github.com/users/thacoon/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "This works in Python 2.x, Python 3.x I guess doesn't work the same way.\n" ]
2016-09-29T11:22:50
2016-09-29T14:05:31
2016-09-29T14:05:31
NONE
null
Hi, I tried this [gist](https://gist.github.com/thedod/11048875) that is referenced to in the [peewee/playhouse/sqlcipher_ext.py](https://github.com/coleifer/peewee/blob/master/playhouse/sqlcipher_ext.py) file, line 51. When running this I get an `AttributeError: 'DatabaseError' object has no attribute 'message'` error message. Using `.message` is also advcied in the [docs](http://docs.peewee-orm.com/en/latest/peewee/playhouse.html?highlight=sqlcipher#sqlcipher-ext). Full traceback: ``` $ python test.py Passphrase: Traceback (most recent call last): File "/home/arch/.environments/passwordmanager_dev/lib/python3.5/site-packages/peewee.py", line 3676, in execute_sql cursor.execute(sql, params or ()) pysqlcipher3.dbapi2.DatabaseError: file is encrypted or is not a database During handling of the above exception, another exception occurred: Traceback (most recent call last): File "test.py", line 54, in <module> db.get_tables() File "/home/arch/.environments/passwordmanager_dev/lib/python3.5/site-packages/peewee.py", line 3893, in get_tables 'type = ? ORDER BY name;', ('table',)) File "/home/arch/.environments/passwordmanager_dev/lib/python3.5/site-packages/peewee.py", line 3683, in execute_sql self.commit() File "/home/arch/.environments/passwordmanager_dev/lib/python3.5/site-packages/peewee.py", line 3507, in __exit__ reraise(new_type, new_type(*exc_args), traceback) File "/home/arch/.environments/passwordmanager_dev/lib/python3.5/site-packages/peewee.py", line 134, in reraise raise value.with_traceback(tb) File "/home/arch/.environments/passwordmanager_dev/lib/python3.5/site-packages/peewee.py", line 3676, in execute_sql cursor.execute(sql, params or ()) peewee.DatabaseError: file is encrypted or is not a database During handling of the above exception, another exception occurred: Traceback (most recent call last): File "test.py", line 58, in <module> if e.message != 'file is encrypted or is not a database': AttributeError: 'DatabaseError' object has no attribute 'message' ``` I am currently using _peewee==2.8.3_ and _pysqlcipher3==1.0.2_.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1083/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1083/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1082
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1082/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1082/comments
https://api.github.com/repos/coleifer/peewee/issues/1082/events
https://github.com/coleifer/peewee/issues/1082
180,019,458
MDU6SXNzdWUxODAwMTk0NTg=
1,082
Please provide a way to easily check NULLness of a foreign key field
{ "login": "maaaks", "id": 3010238, "node_id": "MDQ6VXNlcjMwMTAyMzg=", "avatar_url": "https://avatars.githubusercontent.com/u/3010238?v=4", "gravatar_id": "", "url": "https://api.github.com/users/maaaks", "html_url": "https://github.com/maaaks", "followers_url": "https://api.github.com/users/maaaks/followers", "following_url": "https://api.github.com/users/maaaks/following{/other_user}", "gists_url": "https://api.github.com/users/maaaks/gists{/gist_id}", "starred_url": "https://api.github.com/users/maaaks/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/maaaks/subscriptions", "organizations_url": "https://api.github.com/users/maaaks/orgs", "repos_url": "https://api.github.com/users/maaaks/repos", "events_url": "https://api.github.com/users/maaaks/events{/privacy}", "received_events_url": "https://api.github.com/users/maaaks/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "And — yes, I know about [`suppress()`](https://docs.python.org/3/library/contextlib.html#contextlib.suppress) from standard library, but it still makes impossible to do quick checks inline, like:\n\n``` python\nif obj.other_obj and obj.other_obj.foo == \"bar\":\n # yes, it is \"bar\"\n```\n", "> This looks good and seems to work, but PyCharm highlights this as reference to a non-existing field other_obj_id, so I basically lose a lot of useful IDE features when using this undeclared attribute.\n\nThis is really the de-facto way to do it. I'm sorry that PyCharm complains about it, the field is added dynamically. I would avoid using the foreign key directly as that can cause a query to be issued, which in most cases you don't want.\n", "Oh, you can also try this:\n\n``` python\nobj._data.get('foreign_key_name') is None\n```\n" ]
2016-09-29T11:10:09
2016-09-30T06:27:26
2016-09-29T13:57:03
CONTRIBUTOR
null
Currently I know only two ways to check whether there is a related instance. First way: ``` python try: other_obj = obj.other_obj # yes, there is except OtherObj.DoesNotExist: # no, there isn't ``` This is **too** long for simple checks which I sometimes have to do. Second way: ``` python if obj.other_obj_id: # yes, there is ``` This looks good and seems to work, but PyCharm highlights this as reference to a non-existing field `other_obj_id`, so I basically lose a lot of useful IDE features when using this undeclared attribute. Is there/will there be a third, convinient way to to this? Maybe something like this (I'm not sure how this can be implemented, just an idea): ``` python with dont_throw_doesnotexist_here(): if obj.other_obj: # yes, there is ``` Or, maybe: ``` python if SuppressDne(obj).other_obj: # yes, there is ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1082/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1082/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1081
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1081/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1081/comments
https://api.github.com/repos/coleifer/peewee/issues/1081/events
https://github.com/coleifer/peewee/issues/1081
179,830,565
MDU6SXNzdWUxNzk4MzA1NjU=
1,081
UNION query with limit
{ "login": "jimstjean", "id": 11493131, "node_id": "MDQ6VXNlcjExNDkzMTMx", "avatar_url": "https://avatars.githubusercontent.com/u/11493131?v=4", "gravatar_id": "", "url": "https://api.github.com/users/jimstjean", "html_url": "https://github.com/jimstjean", "followers_url": "https://api.github.com/users/jimstjean/followers", "following_url": "https://api.github.com/users/jimstjean/following{/other_user}", "gists_url": "https://api.github.com/users/jimstjean/gists{/gist_id}", "starred_url": "https://api.github.com/users/jimstjean/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/jimstjean/subscriptions", "organizations_url": "https://api.github.com/users/jimstjean/orgs", "repos_url": "https://api.github.com/users/jimstjean/repos", "events_url": "https://api.github.com/users/jimstjean/events{/privacy}", "received_events_url": "https://api.github.com/users/jimstjean/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[]
2016-09-28T17:05:54
2016-10-02T16:31:01
2016-10-02T16:31:01
NONE
null
Thanks for your work on the peewee library. I have just found an issue closely related to #566, this time on mySQL. The case is: ``` query_1= Object.select().where(SQL(sql_1)).limit(10) query_2= Object.select().where(SQL(sql_2)).limit(10) results = (query_1 | query_2).execute() ``` Even if both query_1 and query_2 return 10 non-overlapping records, this does not return the proper 20 records. It only returns 10. The reason is missing parenthesis around each side of the UNION clause. peewee generates: `SELECT ___ FROM ___ WHERE ___ LIMIT 10 UNION SELECT ___ FROM ___ WHERE ___ LIMIT 10` this returns only 10 records. where it should generate: `(SELECT ___ FROM ___ WHERE ___ LIMIT 10) UNION (SELECT ___ FROM ___ WHERE ___ LIMIT 10)` which will return 20 records as it is supposed to. I cannot determine a way to force the parenthesis around each side of the union, however maybe I have overlooked something. Read more about limit and union behavior here: [http://stackoverflow.com/questions/1415328/combining-union-and-limit-operations-in-mysql-query]
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1081/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1081/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1080
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1080/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1080/comments
https://api.github.com/repos/coleifer/peewee/issues/1080/events
https://github.com/coleifer/peewee/issues/1080
179,735,188
MDU6SXNzdWUxNzk3MzUxODg=
1,080
Detect (and lazy load) columns that were not loaded from DB
{ "login": "tuukkamustonen", "id": 94327, "node_id": "MDQ6VXNlcjk0MzI3", "avatar_url": "https://avatars.githubusercontent.com/u/94327?v=4", "gravatar_id": "", "url": "https://api.github.com/users/tuukkamustonen", "html_url": "https://github.com/tuukkamustonen", "followers_url": "https://api.github.com/users/tuukkamustonen/followers", "following_url": "https://api.github.com/users/tuukkamustonen/following{/other_user}", "gists_url": "https://api.github.com/users/tuukkamustonen/gists{/gist_id}", "starred_url": "https://api.github.com/users/tuukkamustonen/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/tuukkamustonen/subscriptions", "organizations_url": "https://api.github.com/users/tuukkamustonen/orgs", "repos_url": "https://api.github.com/users/tuukkamustonen/repos", "events_url": "https://api.github.com/users/tuukkamustonen/events{/privacy}", "received_events_url": "https://api.github.com/users/tuukkamustonen/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Peewee does not, to the extent that makes sense to me, do things that violate expectations or issue queries. If you think of the model instances as containers for row data, instead of stateful representations of query results, then I think you might be closer to what I intended the library to be. The general idea of issuing queries to get individual column values \"behind-the-scenes\" seems like the kind of magic I would rather avoid, because it can lead to very inefficient applications that appear to work. If you are explicitly selecting a sub-set of columns, presumably your application knows which columns are un-fetched and you could write a helper method to load those from the database yourself. That's the approach I'd take.\n", "@coleifer I understand the skepticism against additional magic. However, doesn't peewee already do behind-the-scenes magic with lazy-loading `ForeignKeys`? Having similar behavior for other fields is not very different from that.\n\nAlso, I wouldn't call it \"magic\" if we required user to call a method (`load_missing ()` and `ensure_fields (...)` in my example) to load up the remaining fields. To clarify, I don't really want lazy loading either, because it would generate unneeded SELECTs to the db. It's better when you have to explicitly call something.\n\nAs this is probably not very popular need, I'm fine with peewee not supporting lazy loading fields. However, would it be possible to allow detecting which fields were not populated from the DB? Yeah, I could attach this info myself during load-time, but it would be cleaner (and better for debugging) if I could just check this from the model instance directly. Is there a specific need why defaults get populated into `_data` while non-loaded fields without default value dont?\n", "Comparing this to the lazy-loading of foreign-keys isn't quite apples-to-apples. You can always add something like this to your base model class in your project:\n\n``` python\nclass BaseModel(Model):\n def refresh(self):\n return type(self).get(self._meta.primary_key == self._get_pk_value())\n```\n\n> would it be possible to allow detecting which fields were not populated from the DB\n\nAs I mentioned, since your application is controlling this, theoretically it should be known to your application which fields need to be reloaded.\n" ]
2016-09-28T10:25:26
2016-10-02T16:07:40
2016-09-28T15:47:14
NONE
null
With: ``` python class Entity(Model): small_field = ... large_field = ... huge_field = ... ``` Large and huge field may contain big chunks of data and are not always needed. Consider: ``` python data = [ Entity.get(id=1), Entity.select(Entity.id, Entity.small_field).where(Entity.id == 2).get(), Entity.select(Entity.id, Entity.small_field, Entity.large_field).where(Entity.id == 3).get(), ] for obj in data: print(len(obj.large_field) + len(obj.huge_field)) # how to lazy load the missing fields here? ``` Is there a property to check or a method to call to check if a field has been populated from the DB? `_data` also contains fields that have `default` defined so I can't use that... Even better, would be nice if peewee could assist in loading these missing fields. However, if the fields were simply lazily loaded, the above example would generate 1 extra SELECT per missing column, which is not very nice. So maybe something like this: ``` python for obj in data: obj.load_missing() # would refresh missing fields, if any, 1 SELECT print(len(obj.large_field) + len(obj.huge_field)) ``` Or maybe: ``` python for obj in data: obj.ensure_fields(Entity.large_field, Entity.huge_field) # would only load if they are really missing, 1 SELECT in total print(len(obj.large_field) + len(obj.huge_field)) ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1080/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1080/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1079
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1079/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1079/comments
https://api.github.com/repos/coleifer/peewee/issues/1079/events
https://github.com/coleifer/peewee/issues/1079
179,722,354
MDU6SXNzdWUxNzk3MjIzNTQ=
1,079
peewee get_or_create default use id field?
{ "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
[ "This ticket is lacking in a lot of detail...What exactly is it that you're asking? The `get_or_create` method does not depend on an \"id\" field, but can work with any constraint. The method itself first attempts a \"get\" using the data provided. If this fails, then an attempt is made to create. If the create fails with an integrity error, then the `get` is retried. That's all there is to it.\n", "@coleifer please, explain why is it necessary to have an integrity check at get_or_create?\r\nMy use case: check an item by key. in case it doesn't exist - create new one. But know I need to provide all the fields, otherwise not null and other constains won't be met.\r\nI would like to provide them only in case there is no matchin by id field.\r\n\r\nBesides, current behavior with integrity check is not documented in API: http://docs.peewee-orm.com/en/latest/peewee/api.html. And I can't get how this integrity check is currently implemented. Please, at least provide some explanation of it at API.\r\n(btw, nice ORM! I am loving its simplicity)" ]
2016-09-28T09:25:10
2017-04-27T09:59:22
2016-09-28T15:42:32
NONE
null
peewee get_or_create default use id field? can peewee use custom diff field ? mysql table not has `id` field ``` In [163]: data Out[163]: {'brand': 'kkkk', 'brand_img': 'b_img', 'extra': '1sdf', 'pid': 5, 'pname': 'panme', 'price': 11, 'product_img': 'xiaorui.cc', 'purl': 'url', 'secound_id': 2, 'third_id': 3, 'top_id': 1} Product.get_or_create(**data) ``` Error: ``` /Library/Python/2.7/site-packages/MySQLdb/connections.pyc in defaulterrorhandler(***failed resolving arguments***) 34 del cursor 35 del connection ---> 36 raise errorclass, errorvalue 37 38 re_numeric_part = re.compile(r"^(\d+)") OperationalError: (1054, "Unknown column 't1.id' in 'field list'") ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1079/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1079/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1078
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1078/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1078/comments
https://api.github.com/repos/coleifer/peewee/issues/1078/events
https://github.com/coleifer/peewee/issues/1078
179,605,579
MDU6SXNzdWUxNzk2MDU1Nzk=
1,078
ModelQueryResultWrapper no longer synthesizes models for joins without FK
{ "login": "jakedt", "id": 2183986, "node_id": "MDQ6VXNlcjIxODM5ODY=", "avatar_url": "https://avatars.githubusercontent.com/u/2183986?v=4", "gravatar_id": "", "url": "https://api.github.com/users/jakedt", "html_url": "https://github.com/jakedt", "followers_url": "https://api.github.com/users/jakedt/followers", "following_url": "https://api.github.com/users/jakedt/following{/other_user}", "gists_url": "https://api.github.com/users/jakedt/gists{/gist_id}", "starred_url": "https://api.github.com/users/jakedt/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/jakedt/subscriptions", "organizations_url": "https://api.github.com/users/jakedt/orgs", "repos_url": "https://api.github.com/users/jakedt/repos", "events_url": "https://api.github.com/users/jakedt/events{/privacy}", "received_events_url": "https://api.github.com/users/jakedt/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Oh yeah, I can see the implementation has a bad unintended consequence if the columns are aliases. Can you tell me a bit more about your use case? Its after lunch and I'm having trouble thinking abstractly. Is there an analogy example using Twitter tables? (user / tweet one to many, users to users many to many)?\n", "``` python\nclass SMS(Model):\n sender = ForeignKey(User)\n\ntweets = Tweet.select().join(User).join(SMS)\n```\n\nNow there should be one row for every tweet and SMS combination. Before I could get both tweets and smses from the query results:\n\n```\ntweet (unique)\ntweet.user (often duplicated)\ntweet.user.sms (often duplicated)\n```\n\nThis isn't a great idea in practice, but we actually have a model where the `SMS` table usually only links to a `User` once.\n", "@coleifer have you had a chance to give this any thought yet?\n", "@jzelinskie -- do you work with @jakedt or has this issue arisen for you independently?\n", "Honestly this feels a bit like a code smell to me. The query you're executing seems very much like a hack. Why not query user and join on both tweet and SMS? Closing as this seems like an edge case that only applies to a particular kind of hack.\n" ]
2016-09-27T20:33:08
2016-11-14T00:58:06
2016-11-14T00:58:06
NONE
null
Due to #1012 we can no longer perform a query we were using and get reasonable results. Previously we were doing a many-to-one and then one-to-many join, and then eliminating duplicate rows on in code on the client side. In the previous behavior we ended up with a synthesized model instance for the incoming FK, and then just deduplicated those. I know we could do this with the `<incoming_fk>_set()` method, but that would be an extra query per result row. What is the recommended way to accomplish this? We could use tuple results, but it was nice having the results parsed into objects for us automatically.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1078/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1078/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1077
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1077/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1077/comments
https://api.github.com/repos/coleifer/peewee/issues/1077/events
https://github.com/coleifer/peewee/issues/1077
179,410,612
MDU6SXNzdWUxNzk0MTA2MTI=
1,077
_prefetch doesn't return results
{ "login": "ghost", "id": 10137, "node_id": "MDQ6VXNlcjEwMTM3", "avatar_url": "https://avatars.githubusercontent.com/u/10137?v=4", "gravatar_id": "", "url": "https://api.github.com/users/ghost", "html_url": "https://github.com/ghost", "followers_url": "https://api.github.com/users/ghost/followers", "following_url": "https://api.github.com/users/ghost/following{/other_user}", "gists_url": "https://api.github.com/users/ghost/gists{/gist_id}", "starred_url": "https://api.github.com/users/ghost/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/ghost/subscriptions", "organizations_url": "https://api.github.com/users/ghost/orgs", "repos_url": "https://api.github.com/users/ghost/repos", "events_url": "https://api.github.com/users/ghost/events{/privacy}", "received_events_url": "https://api.github.com/users/ghost/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Had another query where _prefetch_ didn't return expected results as before.\n", "Can you give me something reproducible?\n", "I don't assume you need anything else from me after @alexlatchford's comment.\nDo you think you'll get to this soon?\n\nThanks heaps! ;-)\n", "Should be fixed in 1c237421eaf6d1ab66218e999baa41c1811c5fc2\n", "Brilliant thanks Charles!\n" ]
2016-09-27T06:51:26
2016-10-03T10:18:14
2016-10-02T16:36:17
NONE
null
I have upgraded from peewee==2.6.4 to 2.8.3 and got some issues with _prefetch_ now. ``` prefetched_users = prefetch(db_users, db_emails, db_interactions) for user in prefetched_users: print user.uuid '9533af75-a176-40eb-9b24-cdd2dc3e7e5d' print user.emails[0].email <email address> print user.uuid '9533af75-a176-40eb-9b24-cdd2dc3e7e5d' print user.emails_prefetch[0].email IndexError: list index out of range ``` Some more debugging: ``` prefetched_users = prefetch(db_users, db_emails, db_interactions) print 'users', db_users.count() 50 print 'emails', db_emails.count() 182 counter = 0 for user in db_users: found = False for email in db_emails: if email.user_id == user.uuid: found = True break if found: print counter, user.uuid, email.email else: print 'NOT FOUND!' counter += 1 ``` Prints 50 uuids + emails but no NOT FOUND. **peewee==2.8.3** Let me know if you need any other info.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1077/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1077/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1076
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1076/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1076/comments
https://api.github.com/repos/coleifer/peewee/issues/1076/events
https://github.com/coleifer/peewee/issues/1076
178,576,297
MDU6SXNzdWUxNzg1NzYyOTc=
1,076
I want to change order of table creation for create_tables()
{ "login": "maaaks", "id": 3010238, "node_id": "MDQ6VXNlcjMwMTAyMzg=", "avatar_url": "https://avatars.githubusercontent.com/u/3010238?v=4", "gravatar_id": "", "url": "https://api.github.com/users/maaaks", "html_url": "https://github.com/maaaks", "followers_url": "https://api.github.com/users/maaaks/followers", "following_url": "https://api.github.com/users/maaaks/following{/other_user}", "gists_url": "https://api.github.com/users/maaaks/gists{/gist_id}", "starred_url": "https://api.github.com/users/maaaks/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/maaaks/subscriptions", "organizations_url": "https://api.github.com/users/maaaks/orgs", "repos_url": "https://api.github.com/users/maaaks/repos", "events_url": "https://api.github.com/users/maaaks/events{/privacy}", "received_events_url": "https://api.github.com/users/maaaks/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "As I can see, you don't want very much to support inheritance: #616\n\nWell, a unified way to override _any_ dependencies would be even better, because I also have some cases where one table depends on existence of another because of a manually-written (via `SQL()`) constraint, which `sort_models_topologically()` also is not aware of.\n", "I'm not sure how sensible it is to provide a way to override such a fundamental algorithm, but it might work to add an optional \"depends_on\" attribute to the model meta options, that would inform the sorting algorithm. What do you think?\n", "Yes, this would be a good solution.\n", "Hmm...the more I'm thinking about this the less it makes sense. If you have a preexisting schema, then it's not like you're going to be creating and dropping peewee tables all over the place. It seems more likely that you'd create your tables once in production, on top of the preexisting schema. Right?\n", "I don't really understand the question. Really.\n\nMy problem is that some tables should be created after other ones are already created. One example is when table B inherits table A. Another one is when table B has a non-trivial foreign key which refers to columns from table A. In both cases, table creation in wrong order will fail, because PostgreSQL won't know what table A is.\n\nIn production, I may already have table A, so yes, sometimes I don't have this problem at all. But when creating a new test environment, I still do need to create all the tables at once, in correct order.\n\nThere is a workaround, though, and I use it now:\n\n``` python\ndb.create_tables(tables1) # tables that don't depend on anything\ndb.create_tables(tables2) # tables that depend on tables from tables1\ndb.create_tables(tables3) # tables that depend on tables from tables1 or tables2\n```\n\nBut I don't like it very much because I have to split list of tables into these «levels» manually.\n", "The nontrivial constraint and test environment are good points. Reopening.\n", "Thank you!\nWhen will this be in the package installable through `pip`? Or, is it already there?\n", "Not on pip yet, but next release will be soon.. I'll shoot for within the next few days\n", "I decided to try it already and installed it:\n\n``` sh\nsudo -H pip3 install git+https://github.com/coleifer/peewee.git@master\n```\n\nBut the order of table creation still looks random and changes from run to run. What is wrong? Should I also somehow uninstall old speedups or something like that?\n", "If it is important, here's override for `create_table()` in my `BaseModel`. It automatically makes the new table inherited from the one referenced in `_meta.parent`.\n\n``` python\nclass BaseModel(Model):\n database = db\n parent = None\n\n @classmethod\n def table(cls) -> str:\n return cls._meta.schema + \".\" + cls._meta.db_table\n\n @classmethod\n def create_table(cls, fail_silently=False):\n with db.transaction() as transaction:\n try:\n super().create_table()\n if cls._meta.parent:\n db.execute_sql(\"alter table \"+cls.table()+\" inherit \"+cls._meta.parent.table())\n\n except peewee.ProgrammingError as e:\n transaction.rollback()\n\n if not fail_silently:\n raise e\n\n if not re.match(r'^relation \"\\S+\" already exists$', str(e).strip()):\n raise e\n```\n", "Sorry, it was a bug in my code.\n", "Mmm... I'm sorry again, but does it really work? The code doesn't make sense to me.\r\n\r\nHere you seem to call `dfs()` on models which _depend on current model_ (am I right?):\r\n\r\n```python\r\nfor foreign_key in model._meta.reverse_rel.values():\r\n dfs(foreign_key.model_class)\r\n```\r\n\r\nAnd then tou seem to call `dfs()` on models which _current model depends on_:\r\n\r\n```python\r\nif model._meta.depends_on:\r\n for dependency in model._meta.depends_on:\r\n dfs(dependency)\r\n```\r\n\r\nAnd it really seems to choose incorrect order of creation for my models.", "@coleifer, any news?", "Are you seeing errors in the ordering that is generated?", "I have seen. I'll try to write a minimal example of what I have in my project some day later, not right now, sorry. :-(\r\n\r\nWill I need to open a new issue then?", "Looks a lot like it's working right... 76eb220f9b1babc5d2cea85c406454b1f73f99d0", "@coleifer, here's what I tried right now:\r\n\r\n```python\r\nclass D(BaseModel):\r\n pass\r\n\r\nclass C(BaseModel):\r\n d = ForeignKeyField(D)\r\n\r\nclass B(BaseModel):\r\n c = ForeignKeyField(C)\r\n\r\nclass A(BaseModel):\r\n class Meta:\r\n depends_on = B,\r\n \r\n c = ForeignKeyField(C)\r\n\r\nmodels = [ D, C, B, A ]\r\n\r\nordered = list(models)\r\nfor pmodels in permutations(models):\r\n ordering = sort_models_topologically(pmodels)\r\n print(\", \".join(m._meta.model_class.__name__ for m in ordering))\r\n assert ordering == ordered\r\n```\r\n\r\nThis code sometimes successfully runs and prints a series of lines `D, C, B, A` but sometimes it crashes and prints `D, C, A, B`. Please try it multiple times, you'll see. At least, I see it with my Linux Mint 17.3 and Python 3.5.\r\n\r\nI am not sure if the anti-alphabetical order or my classes matters, but I couldn't get the fail when they were named alphabetically. Maybe just an accident, I don't know.\r\n\r\nThe relationships between these classes are pretty much relationships between some of real classes in my project, where Peewee is unable to choose correct order for creating tables. Would be cool to have this fixed, thank you in advance!", "I tried that code and it worked every time for me (tried 10K times in a loop) on both python 2.7 and python 3.5.", "Lucky you! :-)\r\n\r\nBack to [this question](https://github.com/coleifer/peewee/issues/1076#issuecomment-265161314), then: do I really understand everything incorrectly, doesn't that fragment of code even look strange?\r\n\r\nBTW, I tried my example not in a loop but by restarting the whole code again and again. Since dictionaries are involved, I suppose some ordering can change on run-to-run basis.", "Here, I added the same code I showed before into the unittest. It sometimes runs ok but sometimes fails. I'm not sure how can I make the test consistently failing since sets are involved in the function, so I think we have to run it multiple times manually before seeing that the ordering does not always work properly. Currently I see that it doesn't but I don't know how you should fix it.", "Please check this, it seems to fix the problem. By the way, I got rid of the `reversed(reversed())` style of the sorting process because it made harder to understand what's going on." ]
2016-09-22T10:45:45
2017-04-10T01:02:49
2017-01-30T22:24:17
CONTRIBUTOR
null
Basically, I need to make Peewee know that some of my tables are [inherited](https://www.postgresql.org/docs/current/static/ddl-inherit.html) from other tables, and this means that the «parents» should be created before «children». Can you please move some logic out from `sort_models_topologically()`, so that I could override it in my classes and customize list of a table's dependencies (which now includes only those tables to which it has foreign keys referencing)? Or, could you make support for inheritance in Peewee natively?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1076/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1076/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1075
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1075/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1075/comments
https://api.github.com/repos/coleifer/peewee/issues/1075/events
https://github.com/coleifer/peewee/pull/1075
178,482,796
MDExOlB1bGxSZXF1ZXN0ODYyNTYwOTc=
1,075
Add connection management documentation for CherryPy
{ "login": "stenci", "id": 5955495, "node_id": "MDQ6VXNlcjU5NTU0OTU=", "avatar_url": "https://avatars.githubusercontent.com/u/5955495?v=4", "gravatar_id": "", "url": "https://api.github.com/users/stenci", "html_url": "https://github.com/stenci", "followers_url": "https://api.github.com/users/stenci/followers", "following_url": "https://api.github.com/users/stenci/following{/other_user}", "gists_url": "https://api.github.com/users/stenci/gists{/gist_id}", "starred_url": "https://api.github.com/users/stenci/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/stenci/subscriptions", "organizations_url": "https://api.github.com/users/stenci/orgs", "repos_url": "https://api.github.com/users/stenci/repos", "events_url": "https://api.github.com/users/stenci/events{/privacy}", "received_events_url": "https://api.github.com/users/stenci/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Thanks! This looks great.\n" ]
2016-09-21T22:58:23
2016-09-22T07:26:16
2016-09-22T07:26:16
CONTRIBUTOR
null
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1075/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1075/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/1075", "html_url": "https://github.com/coleifer/peewee/pull/1075", "diff_url": "https://github.com/coleifer/peewee/pull/1075.diff", "patch_url": "https://github.com/coleifer/peewee/pull/1075.patch", "merged_at": "2016-09-22T07:26:16" }
https://api.github.com/repos/coleifer/peewee/issues/1074
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1074/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1074/comments
https://api.github.com/repos/coleifer/peewee/issues/1074/events
https://github.com/coleifer/peewee/issues/1074
178,285,919
MDU6SXNzdWUxNzgyODU5MTk=
1,074
AUTOINCREMENT on sqlite doesn't work properly
{ "login": "dromer", "id": 1185977, "node_id": "MDQ6VXNlcjExODU5Nzc=", "avatar_url": "https://avatars.githubusercontent.com/u/1185977?v=4", "gravatar_id": "", "url": "https://api.github.com/users/dromer", "html_url": "https://github.com/dromer", "followers_url": "https://api.github.com/users/dromer/followers", "following_url": "https://api.github.com/users/dromer/following{/other_user}", "gists_url": "https://api.github.com/users/dromer/gists{/gist_id}", "starred_url": "https://api.github.com/users/dromer/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/dromer/subscriptions", "organizations_url": "https://api.github.com/users/dromer/orgs", "repos_url": "https://api.github.com/users/dromer/repos", "events_url": "https://api.github.com/users/dromer/events{/privacy}", "received_events_url": "https://api.github.com/users/dromer/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "That's how sqlite auto increment work if it is not a primary key: https://www.sqlite.org/autoinc.html\n", "Except I would assume that 'id' is a primary key.\n", "I agree, but that depends on how the table was created. \n\nWhatever the case I think the problem here is on the sqlite side, not peewee.\n", "The table was created by peewee based on the model:\n\n```\npeewee will automatically add an auto-incrementing integer primary key field named id\n```\n\nhttp://docs.peewee-orm.com/en/latest/peewee/models.html\n", "That's how sqlite work:\n\n```\nsqlite> create table t (id integer primary key, f);\nsqlite> insert into t (f) values (100);\nsqlite> insert into t (f) values (200);\nsqlite> insert into t (f) values (300);\nsqlite> delete from t where f=300;\nsqlite> insert into t (f) values (400);\nsqlite> select * from t;\n1|100\n2|200\n3|400\nsqlite>\n```\n", "The peewee documentation explicitly states it uses an auto-incrementing primary key for the row id.\n\nBut from the sqlite documentation I understand that it depends where the AUTOINCREMENT keyword is used.\nEither way I would expect the same behaviour in sqlite and postgres when peewee creates these tables.\n", "Ok, I found a specific class in peewee's sqlite implementation that should provide this:\nhttps://github.com/coleifer/peewee/blob/master/playhouse/sqlite_ext.py#L92\nSo the id should be overridden to use this class in stead.\n", "As was noted, see the:\n\nhttp://docs.peewee-orm.com/en/latest/peewee/playhouse.html#PrimaryKeyAutoIncrementField\n" ]
2016-09-21T08:56:16
2016-09-21T17:21:20
2016-09-21T17:21:20
NONE
null
It seems that AUTOINCREMENT on sqlite primary keys doesn't actually increment properly. ie.: ``` entries with id 1 and 2 2 is removed new is added -> id = 2 ---- expected -> id = 3 ``` In postgres it uses the proper SERIAL increment as expected.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1074/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1074/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1073
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1073/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1073/comments
https://api.github.com/repos/coleifer/peewee/issues/1073/events
https://github.com/coleifer/peewee/issues/1073
178,083,104
MDU6SXNzdWUxNzgwODMxMDQ=
1,073
Disabling coercion for Func does not work
{ "login": "danygielow", "id": 184562, "node_id": "MDQ6VXNlcjE4NDU2Mg==", "avatar_url": "https://avatars.githubusercontent.com/u/184562?v=4", "gravatar_id": "", "url": "https://api.github.com/users/danygielow", "html_url": "https://github.com/danygielow", "followers_url": "https://api.github.com/users/danygielow/followers", "following_url": "https://api.github.com/users/danygielow/following{/other_user}", "gists_url": "https://api.github.com/users/danygielow/gists{/gist_id}", "starred_url": "https://api.github.com/users/danygielow/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/danygielow/subscriptions", "organizations_url": "https://api.github.com/users/danygielow/orgs", "repos_url": "https://api.github.com/users/danygielow/repos", "events_url": "https://api.github.com/users/danygielow/events{/privacy}", "received_events_url": "https://api.github.com/users/danygielow/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "What database engine are you using?\n", "Just committed a test. I was not able to replicate this issue:\n\n``` diff\ncommit 39531323fd4d24cc4fc0c7039ef83936ec908bc7\nAuthor: Charles Leifer <[email protected]>\nDate: Tue Sep 20 17:31:09 2016 -0500\n\n Add test related to #1073. Unable to replicate.\n\ndiff --git a/playhouse/tests/test_models.py b/playhouse/tests/test_models.py\nindex fc0884b..80a7eac 100644\n--- a/playhouse/tests/test_models.py\n+++ b/playhouse/tests/test_models.py\n@@ -2280,3 +2280,31 @@ class TestDefaultDirtyBehavior(PeeweeTestCase):\n\n dm3_db = DM.get(DM.id == dm3.id)\n self.assertEqual(dm3_db.field, 4)\n+\n+\n+class TestFunctionCoerceRegression(PeeweeTestCase):\n+ def test_function_coerce(self):\n+ class M1(Model):\n+ data = IntegerField()\n+ class Meta:\n+ database = in_memory_db\n+\n+ class M2(Model):\n+ id = IntegerField()\n+ class Meta:\n+ database = in_memory_db\n+\n+ in_memory_db.create_tables([M1, M2])\n+\n+ for i in range(3):\n+ M1.create(data=i)\n+ M2.create(id=i + 1)\n+\n+ qm1 = M1.select(fn.GROUP_CONCAT(M1.data).coerce(False).alias('data'))\n+ qm2 = M2.select(fn.GROUP_CONCAT(M2.id).coerce(False).alias('ids'))\n+\n+ m1 = qm1.get()\n+ self.assertEqual(m1.data, '0,1,2')\n+\n+ m2 = qm2.get()\n+ self.assertEqual(m2.ids, '1,2,3')\n```\n", "Hi, I used SqliteDatabase(':memory:'), but it is the same for MySQLDatabase as well.\n\nI ran your test and it gives me the same error as before:\n\n``` python\n======================================================================\nERROR: test_function_coerce (bla.TestFunctionCoerceRegression)\n----------------------------------------------------------------------\nTraceback (most recent call last):\n File \"/data/d.gielow/projects-python/cronjobs/bla.py\", line 31, in test_function_coerce\n m1 = qm1.get()\n File \"/data/d.gielow/projects-python/cronjobs/env/local/lib/python2.7/site-packages/peewee.py\", line 3090, in get\n return next(clone.execute())\n File \"playhouse/_speedups.pyx\", line 216, in playhouse._speedups._QueryResultWrapper.__next__ (playhouse/_speedups.c:4430)\n File \"playhouse/_speedups.pyx\", line 200, in playhouse._speedups._QueryResultWrapper.iterate (playhouse/_speedups.c:4159)\n File \"playhouse/_speedups.pyx\", line 275, in playhouse._speedups._ModelQueryResultWrapper.process_row (playhouse/_speedups.c:5466)\n File \"playhouse/_speedups.pyx\", line 263, in playhouse._speedups._DictQueryResultWrapper._make_dict (playhouse/_speedups.c:5306)\n File \"/data/d.gielow/projects-python/cronjobs/env/local/lib/python2.7/site-packages/peewee.py\", line 962, in python_value\n return value if value is None else self.coerce(value)\nValueError: invalid literal for int() with base 10: '0,1,2'\n```\n", "Fixed it for real this time, thanks for the traceback.\n" ]
2016-09-20T14:52:20
2016-09-22T07:24:43
2016-09-22T07:17:33
NONE
null
``` python class Foo(Model): id = IntegerField() Foo.create_table() Foo.create(id=1) Foo.create(id=2) print list(Foo.select(fn.GROUP_CONCAT(Foo.id).coerce(False))) >>ValueError: invalid literal for int() with base 10: '1,2' ``` peewee version 2.8.3
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1073/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1073/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1072
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1072/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1072/comments
https://api.github.com/repos/coleifer/peewee/issues/1072/events
https://github.com/coleifer/peewee/issues/1072
178,019,288
MDU6SXNzdWUxNzgwMTkyODg=
1,072
Bug with multiple foreign keys to same table and DeferredRelation
{ "login": "miketheanimal", "id": 5294745, "node_id": "MDQ6VXNlcjUyOTQ3NDU=", "avatar_url": "https://avatars.githubusercontent.com/u/5294745?v=4", "gravatar_id": "", "url": "https://api.github.com/users/miketheanimal", "html_url": "https://github.com/miketheanimal", "followers_url": "https://api.github.com/users/miketheanimal/followers", "following_url": "https://api.github.com/users/miketheanimal/following{/other_user}", "gists_url": "https://api.github.com/users/miketheanimal/gists{/gist_id}", "starred_url": "https://api.github.com/users/miketheanimal/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/miketheanimal/subscriptions", "organizations_url": "https://api.github.com/users/miketheanimal/orgs", "repos_url": "https://api.github.com/users/miketheanimal/repos", "events_url": "https://api.github.com/users/miketheanimal/events{/privacy}", "received_events_url": "https://api.github.com/users/miketheanimal/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Fixed! Thanks for the great ticket.\n", "Glad to be of service :)\n" ]
2016-09-20T10:09:26
2016-09-20T17:07:22
2016-09-20T13:55:41
NONE
null
Python3 with Mysql, peewee from pip3 install --upgrade peewee. Two mysql tables: ``` mysql> desc c ; +-------+---------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------+---------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | +-------+---------+------+-----+---------+----------------+ 1 row in set (0.00 sec) mysql> desc p ; +-------+---------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------+---------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | c1 | int(11) | YES | | NULL | | | c2 | int(11) | YES | | NULL | | +-------+---------+------+-----+---------+----------------+ 3 rows in set (0.01 sec) ``` and the following test code: ``` from peewee import * db = MySQLDatabase('p', user='p', password='p', host='localhost') deferredC = DeferredRelation() class C(Model): id = PrimaryKeyField() class Meta: db_table = 'c' database = db class P(Model): id = PrimaryKeyField() c1 = ForeignKeyField(deferredC, db_column='c1', related_name='c1') c2 = ForeignKeyField(deferredC, db_column='c2', related_name='c2') class Meta: db_table = 'p' database = db deferredC.set_model(C) c1 = C.create() c2 = C.create() p1 = P.get(P.id == 3) p1.c1 = c1 p1.save() p2 = P.get(P.id == 3) p2.c2 = c2 p2.save() db.commit() ``` If I run this on database with table c empty, and one record in p with p.c1=null, p.c2=null, then I get two records in table c (as expected) but only p.c1 links, not p.c2: ``` mysql> select * from c ; +----+ | id | +----+ | 15 | | 16 | +----+ 2 rows in set (0.00 sec) mysql> select * from p ; +----+------+------+ | id | c1 | c2 | +----+------+------+ | 3 | 15 | NULL | +----+------+------+ 1 row in set (0.00 sec) ``` If I remove the DeferredRelation() and use ForeignKeyField(C, ....) then it works as expected, and p.c1 and p.c2 are both correctly set. Thanks Mike
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1072/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1072/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1071
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1071/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1071/comments
https://api.github.com/repos/coleifer/peewee/issues/1071/events
https://github.com/coleifer/peewee/issues/1071
177,825,283
MDU6SXNzdWUxNzc4MjUyODM=
1,071
Sqlite database locked - regression introduced in 2.4.5?
{ "login": "stenci", "id": 5955495, "node_id": "MDQ6VXNlcjU5NTU0OTU=", "avatar_url": "https://avatars.githubusercontent.com/u/5955495?v=4", "gravatar_id": "", "url": "https://api.github.com/users/stenci", "html_url": "https://github.com/stenci", "followers_url": "https://api.github.com/users/stenci/followers", "following_url": "https://api.github.com/users/stenci/following{/other_user}", "gists_url": "https://api.github.com/users/stenci/gists{/gist_id}", "starred_url": "https://api.github.com/users/stenci/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/stenci/subscriptions", "organizations_url": "https://api.github.com/users/stenci/orgs", "repos_url": "https://api.github.com/users/stenci/repos", "events_url": "https://api.github.com/users/stenci/events{/privacy}", "received_events_url": "https://api.github.com/users/stenci/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Relevant commits:\n\nhttps://github.com/coleifer/peewee/compare/2.4.4...2.4.5\n", "Are you calling connect and close at the start and end of every request? Is the busy timeout suitably high to allow retrying queries? I've noticed that die to the way SQLite does its busy timeout, many queries sent at close to the same time will always retry at the same times.\n", "What I've found is that by adding a slight bit of jitter to the default busy handler you'll see a lot less operational errors...I should really submit a patch...\n", "I installed the 2.4.5, removed the method `SqliteDatabase.begin()` and it works.\n\nThe method was added in this [commit](https://github.com/coleifer/peewee/commit/623374855c8c5fe5cf6aa0717b50e2ad77fc877c).\n\nThe logged SQL while executing a burst of two calls shows SQL statements alternating from the two calls. With the `SqliteDatabase.begin()` the `UPDATE` from the first call succeeds, the one from the second call fails. Without it they both succeed.\n\nHere is an excerpt from the log with the 2.4.5. The first two lines of the log disappear after removing the `SqliteDatabase.begin()`.\n\n```\n('BEGIN DEFERRED', None)\n('BEGIN DEFERRED', None)\n('SELECT \"t1\".\"id\", ...\n('SELECT \"t1\".\"id\", ...\n('UPDATE \"cncprogrampart\" SET ...\n('UPDATE \"cncprogrampart\" SET ...\n--- crash ---\n```\n", "Sorry, I was busy doing my tests and didn't notice your questions.\n\nI don't think I am doing anything else than the `db = peewee.SqliteDatabase(path_name + '/doc.db', threadlocals=True)` when the app starts. After that I use CherryPy with its default settings. I think there are 10 threads sharing `db`.\n", "Okay, I think that may be the source of the issue. It is probably wise to connect when the request comes in, then clowhen the response goes out. I imagine cherrypy provides some kinds of hooks as this is common to most all frameworks.\n\nDocs: http://docs.peewee-orm.com/en/latest/peewee/database.html#adding-request-hooks\n", "I tried with the Flask code that you show in the documentation and I tried to do the same thing with CherryPy. Both the version crash with `SqliteDatabase.begin()`, they both work without it.\n\nYou can test both the version with the scripts below. You start the server, then you go to `http://127.0.0.1:8080/` for CherryPy and to `http://127.0.0.1:5000/` for Flask.\n\nOne second after showing the page, a burst of two requests will reach the server and the server will crash on the second request.\n\n**CherryPy**\n\n```\nimport cherrypy\nimport peewee\nimport time\nimport logging\n\nlogger = logging.getLogger('peewee')\nlogger.setLevel(logging.DEBUG)\nlogger.addHandler(logging.StreamHandler())\n\ndb = peewee.SqliteDatabase('test.db')\n\nclass PeeweeModel(peewee.Model):\n class Meta:\n database = db\n\nclass Table1(PeeweeModel):\n n = peewee.IntegerField()\n counter = peewee.IntegerField()\n\nTable1.drop_table(True)\nTable1.create_table(True)\nTable1.create(n=1, counter=0)\nTable1.create(n=2, counter=0)\n\nclass Root:\n\n @cherrypy.expose\n def index(self):\n cherrypy.log('index')\n return \"\"\"<!DOCTYPE HTML>\n<html>\n<head>\n<script>\nsetTimeout(function(){\nxhttp = new XMLHttpRequest();\nxhttp.open(\"GET\", \"increase?n=1\", true);\nxhttp.send();\nxhttp = new XMLHttpRequest();\nxhttp.open(\"GET\", \"increase?n=2\", true);\nxhttp.send();}, 2000);\n</script>\n</head>\n<body>\n<a href=\"result\">See result</a>\n</body>\n</html>\"\"\"\n\n @cherrypy.expose\n def increase(self, n):\n cherrypy.log('increase start')\n with db.transaction():\n record = Table1.get(Table1.n == int(n))\n time.sleep(0.5)\n record.counter += 1\n time.sleep(0.5)\n record.save()\n time.sleep(0.5)\n cherrypy.log('increase end')\n return 'OK'\n\n @cherrypy.expose\n def result(self):\n cherrypy.log('result')\n return '<br>'.join(['n={} counter={}\\n'.format(r.n, r.counter) for r in Table1.select()])\n\ndef connect():\n cherrypy.log('connect')\n db.connect()\n\ndef close():\n cherrypy.log('close')\n if not db.is_closed():\n db.close()\n\ncherrypy.engine.subscribe('before_request', connect)\ncherrypy.engine.subscribe('after_request', close)\ncherrypy.quickstart(Root())\n```\n\n**Flask**\n\n```\nimport flask\nimport peewee\nimport time\nimport logging\n\nlogger = logging.getLogger('peewee')\nlogger.setLevel(logging.DEBUG)\nlogger.addHandler(logging.StreamHandler())\n\ndb = peewee.SqliteDatabase('test.db')\napp = flask.Flask(__name__)\n\[email protected]_request\ndef _db_connect():\n app.logger.debug('connect')\n db.connect()\n\[email protected]_request\ndef _db_close(exc):\n app.logger.debug('close')\n if not db.is_closed():\n db.close()\n\nclass PeeweeModel(peewee.Model):\n class Meta:\n database = db\n\nclass Table1(PeeweeModel):\n n = peewee.IntegerField()\n counter = peewee.IntegerField()\n\nTable1.drop_table(True)\nTable1.create_table(True)\nTable1.create(n=1, counter=0)\nTable1.create(n=2, counter=0)\n\[email protected]('/')\ndef index():\n app.logger.debug('index')\n return \"\"\"<!DOCTYPE HTML>\n<html>\n<head>\n<script>\nsetTimeout(function(){\nxhttp = new XMLHttpRequest();\nxhttp.open(\"GET\", \"increase/1\", true);\nxhttp.send();\nxhttp = new XMLHttpRequest();\nxhttp.open(\"GET\", \"increase/2\", true);\nxhttp.send();}, 2000);\n</script>\n</head>\n<body>\n<a href=\"result\">See result</a>\n</body>\n</html>\"\"\"\n\[email protected]('/increase/<n>')\ndef increase(n):\n app.logger.debug('increase start')\n with db.transaction():\n record = Table1.get(Table1.n == int(n))\n time.sleep(0.5)\n record.counter += 1\n time.sleep(0.5)\n record.save()\n time.sleep(0.5)\n app.logger.debug('increase end')\n return 'OK'\n\[email protected]('/result')\ndef result():\n app.logger.debug('result')\n return '<br>'.join(['n={} counter={}\\n'.format(r.n, r.counter) for r in Table1.select()])\n\napp.run(threaded=True)\n```\n", "I have something awesome you can try...\n\nIt's currently only in master branch, but if you want to try it out it should solve your problem.\n\nIn the `playhouse.sqliteq` module is a class named `SqliteQueueDatabase`. Replace this:\n\n``` python\n\ndb = peewee.SqliteDatabase('test.db')\n```\n\nWith this:\n\n``` python\nfrom playhouse.sqliteq import SqliteQueueDatabase\ndb = SqliteQueueDatabase('t.db', readers=4, autostart=True)\n```\n\nAt the same time, remove all calls to db.connect() and db.close(). \n", "Another thing you should _always_ be doing is specifying `journal_mode='wal'` when you instantiate your Sqlite database. This allows multiple readers to co-exist with a single writer, and I think this may also magically solve your issues:\n\n``` python\ndb = SqliteDatabase('foo.db', pragmas=[('journal_mode', 'wal')])\n```\n", "Oh, and lastly, you can use the `PooledSqliteDatabase` from the `playhouse.pool` module. This will also most likely solve the issues you are encountering. You would write:\n\n``` python\nfrom playhouse.pool import PooledSqliteExtDatabase\n\ndb = PooledSqliteExtDatabase(\n 'foo.db', \n pragmas=[('journal_mode', 'wal')],\n max_connections=30,\n stale_timeout=3600,\n check_same_thread=False)\n```\n", "Thanks for suggesting to use the WAL journal mode.\n\nI tried your second and third suggestions, and unfortunately the magic didn't happen. \n\nI just cloned the Peewee repository. I never used git to clone one library used in another project. How do I tell my app to `import peewee` from the repository folder instead of using the one installed by pip? Do I need to uninstall it with pip and add the new path to the `PYTHONPATH`?\n\n(Going home now, see you tomorrow)\n", "You can run `import peewee` then on the next line just type `peewee` and press `<enter>`. It should print which module you're using. For example:\n\n![s1474437363 4](https://cloud.githubusercontent.com/assets/119974/18699309/25bdfb64-7f96-11e6-9356-b067b23c62da.png)\n", "Even awesome doesn't seem to be enough :(\n\nI did `pip uninstall peewee` and `import peewee` from the cloned repository.\n\nThe test with Flask now fails and the server doesn't start (see the traceback below).\n\nThe test with CherryPy runs, but crashes like the old one when the second call finds the database locked. I tried both with and without the `connect()` and `close()`.\n\n**Flask code**\n\n```\nimport flask\nimport time\nimport logging\nimport peewee\n\nlogger = logging.getLogger('peewee')\nlogger.setLevel(logging.DEBUG)\nlogger.addHandler(logging.StreamHandler())\n\n# db = peewee.SqliteDatabase('test.db', pragmas=[('journal_mode', 'wal')])\n\nfrom playhouse.sqliteq import SqliteQueueDatabase\ndb = SqliteQueueDatabase('test.db', readers=4, autostart=True)\n\napp = flask.Flask(__name__)\n\[email protected]_request\ndef _db_connect():\n app.logger.debug('connect')\n db.connect()\n\[email protected]_request\ndef _db_close(exc):\n app.logger.debug('close')\n if not db.is_closed():\n db.close()\n\nclass PeeweeModel(peewee.Model):\n class Meta:\n database = db\n\nclass Table1(PeeweeModel):\n n = peewee.IntegerField()\n counter = peewee.IntegerField()\n\nTable1.drop_table(True)\nTable1.create_table(True)\nTable1.create(n=1, counter=0)\nTable1.create(n=2, counter=0)\n\[email protected]('/')\ndef index():\n app.logger.debug('index')\n return \"\"\"<!DOCTYPE HTML>\n<html>\n<head>\n<script>\nsetTimeout(function(){\nxhttp = new XMLHttpRequest();\nxhttp.open(\"GET\", \"increase/1\", true);\nxhttp.send();\nxhttp = new XMLHttpRequest();\nxhttp.open(\"GET\", \"increase/2\", true);\nxhttp.send();}, 2000);\n</script>\n</head>\n<body>\n<a href=\"result\">See result</a>\n</body>\n</html>\"\"\"\n\[email protected]('/increase/<n>')\ndef increase(n):\n app.logger.debug('increase start')\n with db.transaction():\n record = Table1.get(Table1.n == int(n))\n time.sleep(0.5)\n record.counter += 1\n time.sleep(0.5)\n record.save()\n time.sleep(0.5)\n app.logger.debug('increase end')\n return 'OK'\n\[email protected]('/result')\ndef result():\n app.logger.debug('result')\n return '<br>'.join(['n={} counter={}\\n'.format(r.n, r.counter) for r in Table1.select()])\n\napp.run(threaded=True)\n```\n\n**Flask traceback**\n\n```\nTraceback (most recent call last):\n File \"C:\\eclipse\\plugins\\org.python.pydev_5.2.0.201608171824\\pysrc\\pydevd.py\", line 1531, in <module>\n globals = debugger.run(setup['file'], None, None, is_module)\n File \"C:\\eclipse\\plugins\\org.python.pydev_5.2.0.201608171824\\pysrc\\pydevd.py\", line 938, in run\n pydev_imports.execfile(file, globals, locals) # execute the script\n File \"C:\\eclipse\\plugins\\org.python.pydev_5.2.0.201608171824\\pysrc\\_pydev_imps\\_pydev_execfile.py\", line 25, in execfile\n exec(compile(contents+\"\\n\", file, 'exec'), glob, loc)\n File \"C:\\workspace\\test\\test_flask_peewee_burst.py\", line 36, in <module>\n Table1.drop_table(True)\n File \"C:\\workspace\\peewee\\peewee.py\", line 4904, in drop_table\n cls._meta.database.drop_table(cls, fail_silently, cascade)\n File \"C:\\workspace\\peewee\\peewee.py\", line 3804, in drop_table\n model_class, fail_silently, cascade))\n File \"C:\\workspace\\peewee\\playhouse\\sqliteq.py\", line 199, in execute_sql\n queue.put(cursor)\n File \"C:\\Anaconda3\\envs\\flask\\lib\\queue.py\", line 127, in put\n if self.maxsize > 0:\nTypeError: unorderable types: NoneType() > int()\n```\n", "What happens if I use the 2.4.4 (or if I delete the `SqliteDatabase.begin() from a more recent version`)?\n\nDo I risk that the statements inside a transaction are not really a transaction, even if I wrap them in a `db.transaction()`?\n\nOr...?\n", "Oh shit, python 3. I'll fix that.\n", "Why is this issue closed?\n\nThe fix mentioned above fixes a problem mentioned on [a comment](https://github.com/coleifer/peewee/issues/1071#issuecomment-248661857), not the original problem.\n\nI think this is an important problem and should be solved. I am just sending two requests faster than they can be processed and the database fails instead of waiting with the second one. I am surprised that nobody ever found this problem. Am I doing something so uncommon? Or am I doing it in the wrong way?\n\nI just realized that I was already using features introduced after the 2.4.4 (like `union_all(()`) and I can't go back to the latest working version. So I upgraded to the 2.8.3, did some (manual) testing and found a few places where the app either locks the database forever and the server needs to be restarted or it crashes complaining that the server is locked.\n\nI added the following monkey patch to both the development and production servers and everything seems to work fine, but... monkey patching?... I'm scared!:\n\n```\nimport peewee\ndel peewee.SqliteDatabase.begin\n```\n", "Whoops!\n", "OK, so I don't believe there is a bug here. In your example flask application I see that you've added calls to `time.sleep()`. I presume this is to force the application into attempting to open a write transaction while another write transaction is open. SQLite only allows one writer at a time, though, so yes -- you will get errors if you try to do this. If the DB comes back saying it's locked by another writer, `pysqlite` will retry the query up to a certain time limit (default is 5 seconds, I believe). Should it fail to get the lock in that time limit, you get an error.\n\nThis is the correct behavior.\n\nI'm not sure how you had your application set up previously, how you were managing connections (it sounds like you weren't), and how you were managing transactions. There are too many variables in there for me to guess as to why this appeared to work for you.\n\nWhen you use SQLite in a multi-threaded environment you need to take care of how you manage your transactions, simple as that. I would not recommend monkeypatching the begin method unless you want a subtly broken app, or an app that works by accident rather than design.\n\nSuggestions:\n- Use the `playhouse.sqliteq.SqliteQueueDatabase`. I've added some preliminary docs [here](http://docs.peewee-orm.com/en/latest/peewee/playhouse.html#sqliteq).\n- Keep your write transactions as small as possible, so that they can run quickly and then get out of the way to allow the next writer to acquire the lock.\n- Avoid keeping a connection to the database open for a long time after writing.\n", "> If the DB comes back saying it's locked by another writer, pysqlite will retry the query up to a certain time limit (default is 5 seconds, I believe). Should it fail to get the lock in that time limit, you get an error.\n> \n> This is the correct behavior.\n\nI agree with you. You describe the behavior I would expect, which was the behavior until 2.4.4. If there was a write transaction in progress, the 2.4.4 would wait (up to the 5 seconds default timeout for sqlite) and then crash.\n\nNow it just crashes, without waiting.\n\nYour advice to make the transactions as small as possible and not to keep a transaction after writing is valid, but I can't shrink the time to zero. I can shorten the time and decrease the chance of crash, but can't get rid of it. The correct behavior would be for peewee to take care of it as it used to up to 2.4.4.\n\nI tried all the solutions you suggested, but no one does what you say.\n\nI cleaned my previous test so that now it's easier to follow. Requesting `localhost:5000` with the code below will send 3 requests at 0.1 seconds distance from each other:\n- The first request will read a record, change some values and write it back to the database\n- The second request will try to do the same and wait for the previous transaction to be finished\n- Same with the third, but will rollback after saving, just to test the rollback\n\nUsing peewee 2.4.4 the result is as expected: the second save will wait for the first transaction to be finished and the third will wait for the second. At the end the value in the database will be 2 because the 3 has been rollbacked.\n\nUsing peewee 2.8.5 with all the combination that I can think of I get one of these 3 wrong results: \n- Immediate crash without waiting for the sqlite timeout\n- Nothing is saved\n- The value 3 is saved (no rollback was performed on the third transaction)\n\nHere are the results of my tests:\n![image](https://cloud.githubusercontent.com/assets/5955495/19086016/1f300340-8a32-11e6-9bba-db64752afe46.png)\n\nHere is the code:\n\n``` Python\nimport flask\nimport time\nimport logging\nimport peewee\nimport threading\nimport datetime\n\nCREATE_CONNECTIONS = 0\nUSE_SqliteDatabase = 0\nUSE_PooledSqliteExtDatabase = 0\nUSE_SqliteQueueDatabase = 1\nDEL_BEGIN = 0\n\nprint('peewee.__version__ =', peewee.__version__)\n\nif DEL_BEGIN:\n del peewee.SqliteDatabase.begin\n\nlogger = logging.getLogger('peewee')\nlogger.setLevel(logging.DEBUG)\nlogger.addHandler(logging.StreamHandler())\n\nif USE_SqliteDatabase:\n if peewee.__version__ == '2.4.4':\n db = peewee.SqliteDatabase('test.db')\n else:\n db = peewee.SqliteDatabase('test.db', pragmas=[('journal_mode', 'wal')])\nif USE_PooledSqliteExtDatabase:\n from playhouse.pool import PooledSqliteExtDatabase\n db = PooledSqliteExtDatabase(\n 'test.db',\n pragmas=[('journal_mode', 'wal')],\n max_connections=30,\n stale_timeout=3600,\n check_same_thread=False)\nelif USE_SqliteQueueDatabase:\n from playhouse.sqliteq import SqliteQueueDatabase\n db = SqliteQueueDatabase(\n 'test.db',\n pragmas=[('journal_mode', 'wal')],\n readers=4,\n autostart=True)\n\nclass PeeweeModel(peewee.Model):\n class Meta:\n database = db\n\nclass Table1(PeeweeModel):\n n = peewee.IntegerField()\n time_stamp = peewee.CharField(null=True)\n\nTable1.drop_table(True)\nTable1.create_table(True)\nTable1.create(n=0)\n\napp = flask.Flask(__name__)\n\[email protected]_request\ndef _db_connect():\n if CREATE_CONNECTIONS:\n log('connect')\n db.connect()\n\[email protected]_request\ndef _db_close(exc):\n if CREATE_CONNECTIONS:\n log('close')\n if not db.is_closed():\n db.close()\n\ndef now():\n return datetime.datetime.now().strftime('%H:%M:%S.%f')\n\ndef log(txt):\n print(' {} {:6d} {}'.format(now(),\n threading.current_thread().ident,\n txt))\n\[email protected]('/')\ndef index():\n log('index')\n return \"\"\"<!DOCTYPE HTML>\n<html>\n<head>\n<script>\nsetTimeout(function(){\n xhttp = new XMLHttpRequest();\n xhttp.open(\"GET\", \"set_time/1\", true);\n xhttp.send();\n}, 100);\n\nsetTimeout(function(){\n xhttp = new XMLHttpRequest();\n xhttp.open(\"GET\", \"set_time/2\", true);\n xhttp.send();\n}, 200);\n\nsetTimeout(function(){\n xhttp = new XMLHttpRequest();\n xhttp.open(\"GET\", \"set_time/3\", true);\n xhttp.send();\n}, 300);\n</script>\n</head>\n<body>\nhello\n</body>\n</html>\"\"\"\n\[email protected]('/set_time/<n>')\ndef set_time(n):\n with db.transaction():\n\n log(' {} set_time{} start transaction'.format(now(), n))\n time.sleep(1)\n\n log(' {} set_time{} get'.format(now(), n))\n rec = Table1.get()\n time.sleep(1)\n\n log(' {} set_time{} save'.format(now(), n))\n rec.n = n\n rec.time_stamp = now()\n rec.save()\n log(' {} set_time{} saved'.format(now(), n))\n time.sleep(1)\n\n if n == '3':\n db.rollback()\n log(' {} set_time{} rollback'.format(now(), n))\n log(' {} set_time{} end transaction'.format(now(), n))\n\n return 'OK'\n\napp.run(threaded=True)\n```\n", "This seems to be the commit that introduced the regression: https://github.com/coleifer/peewee/commit/623374855c8c5fe5cf6aa0717b50e2ad77fc877c\n\nAfter using `pip install -U git+git://github.com/coleifer/peewee@6f01097` it works.\n\nAfter using `pip install -U git+git://github.com/coleifer/peewee@6233748` it fails.\n", "The problem is here:\n\n```\nTable1.drop_table(True)\nTable1.create_table(True)\nTable1.create(n=0)\n```\n\nYou are implicitly creating a write transaction there, along with opening a connection and not closing it.\n\nChange that to read:\n\n``` python\n# If you're using something other than the SqliteQueueDatabase:\nwith db.execution_context():\n Table1.drop_table(True)\n Table1.create_table(True)\n Table1.create(n=0)\n\n# If you're using the SqliteQueueDatabase then just create the\n# tables after calling db.start()\n```\n", "It's also worth mentioning that SQLite's default transactions use `DEFERRED` semantics, so multiple transactions can be opened and reads performed concurrently, but depending on whether or not you're using WAL mode, one of the concurrent writes may fail.\n\nTo simplify your example, consider a view that does a compare-and-swap with a sleep in between. Something like:\n\n``` python\ndef my_view():\n with db.atomic():\n try:\n obj = Register.get(Register.value == 1)\n except Register.DoesNotExist:\n return 'cas failed, obj with value 1 not found'\n time.sleep(1)\n obj.value = 2\n obj.save()\n return 'cas succeeded'\n```\n\nIf you fire off two requests A and B, with B just a millisecond behind A, what you will see will depend on the type of transaction opened, and whether WAL mode is enabled.\n\n| lock type | wal mode? | result |\n| --- | --- | --- |\n| deferred | no | request A reports error because it cannot write due to B's read still being open. B succeeds. |\n| deferred | yes | A succeeds, B reports error when it tries to commit |\n| immediate | yes or no | A succeeds, B blocks until A finishes, then reports record not found |\n\ndeferred and not using WAL:\n- T0 = A opens read transaction. Finds object. Starts sleeping.\n- T1 = B opens read transaction. Finds object. Starts sleeping.\n- T1000 = A sets value and attempts UPDATE. A cannot aquire lock because B is still reading. Error.\n- T1001 = B acquires lock and updates successfully.\n\ndeferred and using WAL:\n- T0 = A opens read transaction. Finds object. Starts sleeping.\n- T1 = B opens read transaction. Finds object. Starts sleeping.\n- T1000 = A acquires write lock and saves successfully.\n- T1001 = B attempts to acquire write lock but cannot because A changed the DB snapshot. Error.\n\nimmediate with or without WAL:\n- T0 = A opens transaction. Finds object. Starts sleeping.\n- T1 = B attempts to open transaction, but A has lock. B waits.\n- T1000 = A saves successfully.\n- T1000.01~ = A released lock, B acquires lock. B cannot find object.\n", "I tried all the combinations of the 3 objects `SqliteDatabase`, `PooledSqliteExtDatabase` and `SqliteQueueDatabase`, with and without creation of the connection, with and without `db.start()`, with and without `with db.transaction():`. The results are the same: crash, no save or save but no rollback.\n\nI was never able to get it to correctly save and rollback when required (well, I was, by installing the good old 2.4.4)\n\nI just saw your last comment popping up. I will investigate the lock type and journal mode.\n\nI started using peewee and sqlite because it was easy and everything worked. Two months ago I started adding features to the old app, I upgraded many of the libraries, used some new feature (like `union_all(()`), then I received a few calls reporting crashes. I spent the last 10 days chasing this problem and trying to reduce it to a manageable test. (Sorry for the little venting, back to work now and thanks for your support.)\n", "The above examples I showed represent the true and correct semantics for a SQLite database, in my opinion. Have a look at https://www.sqlite.org/isolation.html for some more info.\n\nI want to highlight the example of using WAL mode with a DEFERRED transaction (the one where A succeeds and B reports an error). This happens because B is attempting to upgrade it's lock from a READ lock to a WRITE lock, but since A has swooped in and committed changes in the meantime, B's attempt to upgrade fails immediately.\n\nIt is described like this in the Sqlite docs:\n\n> Another example: X starts a read transaction using BEGIN and SELECT, then Y makes a changes to the database using UPDATE. Then X tries to make a change to the database using UPDATE. The attempt by X to escalate its transaction from a read transaction to a write transaction fails with an SQLITE_BUSY_SNAPSHOT error because the snapshot of the database being viewed by X is no longer the latest version of the database. If X were allowed to write, it would fork the history of the database file, which is something SQLite does not support. In order for X to write to the database, it must first release its snapshot (using ROLLBACK for example) then start a new transaction with a subsequent BEGIN.\n\nI hope this convinces you of the correctness of the implementation.\n\nSqliteQueueDatabase is a special-case in that since all queries are interleaved on a single connection, transactional semantics pretty much can be thrown out the window. It's intended for dead-simple or advanced use-cases, but not in-between I guess you might say.\n", "I understand your frustration. I now know more about SQLite than I ever thought I would need to, to write a useful tool. I think I misunderstood the problem you were encountering and offered you bad suggestions as a result, which didn't help you I'm sure, so I apologize for the \"red herrings\".\n", "The frustrating part is not lack of/bad support (which is always good quality and way more than what I pay for, thank you! :) )\n\nThe frustrating part is that I need to change code that has been working for two years. My code is broken now and... there is no regression. I could digest a non backward compatible change between 2.\\* and 3.0, but it's difficult to digest between 2.4.4 and 2.4.5. I guess incompatibility between versions can be part of the game, but this is my first time and it doesn't feel right.\n\nI still don't know why it was working before and I can't use it anymore in the same way, but after looking at my code it looks like I can work around the lack of `rollback()` and switch to `SqliteQueueDatabase`. Back to work now, thanks.\n", "Correct me if I'm wrong, but the fact is you've jumped from 2.4.4 (which is almost 2 years old at this point) to 2.8.5. So there's quite a lot of things that have changed besides just the decision to run SQLite in autocommit mode.\n\nIn the diff of version 2.4.4 to 2.4.5 you can see that [documentation](http://docs.peewee-orm.com/en/latest/peewee/database.html#sqlite-and-autocommit) was updated to reflect the [SQLite \"autocommit mode\" change](http://docs.peewee-orm.com/en/latest/peewee/database.html#sqlite-and-autocommit):\n\nhttps://github.com/coleifer/peewee/compare/2.4.4...2.4.5#diff-1fdd0c1e085be7d7af1cc4f80529eecdL133\n\n> The frustrating part is that I need to change code that has been working for two years\n\nI understand, believe me -- but can you explain to me precisely why the code worked in 2.4.4? What was happening at the connection level? What was happening at the transaction level?\n\nYou see, the thing is, pysqlite (`sqlite3` in the standard library) is sneaky. From the documentation:\n\n> By default, the sqlite3 module opens transactions implicitly before a Data Modification Language (DML) statement (i.e. INSERT/UPDATE/DELETE/REPLACE), and commits transactions implicitly before a non-DML, non-query statement (i. e. anything other than SELECT or the aforementioned).\n\nThis is one of the reasons Roger Binns created [apsw](https://github.com/rogerbinns/apsw). From the documentation to APSW (emphasis his):\n\n> **Nothing** happens behind your back. By default pysqlite tries to manage transactions by parsing your SQL for you, but you can turn it off. This can result in very unexpected behaviour with pysqlite.\n\nPeewee follows the same principles, and manages to use the standard library SQLite driver so users of Peewee don't have to install an additional dependency.\n", "Last week I tried to test the behavior with the different combinations of journal mode and isolation using `sqlite3` without `peewee`, but I noticed that something was added to the SQL statements that I was sending, so I gave up. The next time I will try with `apsw`.\n\nI don't know why my code was working and stopped. It was my first time with SQL, with peewee and with python in general, so I used all the defaults. I recreated a simplified version that reproduces the problem on a new clean environment with only peewee.\n\nThe code below works with the 2.4.4 and fails with the 2.4.5. Changing the value of `autocommit` makes no difference, all the transactions happen in a `with db.transaction()` block. \n\nI really appreciate you spending time on this issue, but I understand if you consider it a waste of time because it is an old problem. \n\n``` python\nimport peewee\nimport time\nimport datetime\nimport threading\nimport os\nimport logging\n\nlogger = logging.getLogger('peewee')\nlogger.setLevel(logging.DEBUG)\nlogger.addHandler(logging.StreamHandler())\n\nif os.path.exists('test.db'):\n os.unlink('test.db')\n\ndb = peewee.SqliteDatabase('test.db', autocommit=True)\n\nclass Table1(peewee.Model):\n n = peewee.IntegerField()\n time_stamp = peewee.CharField()\n class Meta:\n database = db\n\ndef now():\n return datetime.datetime.now().strftime('%H:%M:%S.%f')\n\ndef add_rec(n):\n with db.transaction():\n time.sleep(1)\n\n with db.transaction() as tx:\n rec = Table1.get()\n time.sleep(1)\n\n Table1.create(n=n, time_stamp=now())\n rec.save()\n time.sleep(1)\n\n if n == 3:\n tx.rollback()\n\nwith db.transaction():\n Table1.create_table(True)\n Table1.create(n=0, time_stamp=now())\n\nt1 = threading.Timer(0.3, add_rec, args=[1])\nt2 = threading.Timer(0.4, add_rec, args=[2])\nt3 = threading.Timer(0.5, add_rec, args=[3])\n\nt1.start()\nt2.start()\nt3.start()\n\nt1.join()\nt2.join()\nt3.join()\n\nfor rec in Table1.select():\n print(rec.id, rec.n, rec.time_stamp)\n```\n", "I spent two weeks trying to get it to work as it used to.\n\nMy old code does not specify `autocommit` (it defaults to `True`) and works `with transaction` blocks. So, according to the [documentation](http://docs.peewee-orm.com/en/latest/peewee/database.html#sqlite-and-autocommit), it should still work, but it doesn't.\n\nMy previous comment shows an example working with 2.4.4 and failing with later versions.\n\nI do understand why it fails (thanks for the explanation) and I don't understand why it was working. But it was working and now, after wasting two weeks, I'm still stuck, thinking how far I can go without transactions or if I should abandon either sqlite or peewee and restart with something else. Whatever option I chose will require me to change lots of code.\n\nIf you think that sqlite + multithreading should not allow the use of transactions and rollback, and the only way to go is `SqliteQueueDatabase`, then that's what I will try.\n\nIf you think that I should be able to use transactions with sqlite + multithreading, then I would appreciate an example of how to do it.\n", "I'd just like to clarify: **you can use SQLite with multiple threads in Python, with or without Peewee**. You only need to be aware of the fact that only one connection can write to the database at a time.\n\n> If you think that sqlite + multithreading should not allow the use of transactions and rollback, and the only way to go is SqliteQueueDatabase, then that's what I will try.\n\n**Not at all**.\n\nI **know** you can use transactions with SQLite and multithreading, because I am doing so myself on a handful of websites, services, and scripts.\n\nI had thought that when I was showing examples using \"compare-and-set\" that the solution was clear, but to re-cap: I believe you can get the \"old\" behavior by specifying \"immediate\" as the transaction type. \n\nIn Peewee 2.8.5, the version currently on PyPI, you would write:\n\n``` python\ndb = SqliteExtDatabase('/my/db')\n\nwith db.granular_transaction('immediate') as txn:\n blah blah\n```\n\nI've renamed this method in `master` to plain old \"transaction\", so if you're running on master or a version newer than 2.8.5, just use `transaction`:\n\n``` python\ndb = SqliteExtDatabase(...)\n\nwith db.transaction('immediate') as txn:\n blah blah\n```\n\nThe caveat here is that you need to be using the `playhouse.sqlite_ext.SqliteExtDatabase`, as this database class implements sqlite-specific features including specifying transaction type.\n\nThe other thing to note is that you cannot currently do a similar thing with `atomic()`. This is because only the outer-most transaction can declare a lock type, anything nested below that uses a savepoint.\n\n---\n\n> I don't understand why it was working\n\nI think this piece is crucial to your own feeling of confidence moving forward with whatever solution you end up choosing. I understand that it's complicated to try and figure out what's going on when you have multiple threads, connections, and pysqlite doing it's crazy magic, but it might be worth digging into in your spare time.\n" ]
2016-09-19T16:01:15
2016-10-12T23:23:21
2016-10-02T16:24:19
CONTRIBUTOR
null
Below an excerpt from my CherryPy app. The app receives bursts of ajax calls to `cncprogram_done`. Sometimes just 1 or 2 calls, sometimes up to 10 or 20 at a time (I will eventually optimize it, but for now I'm OK with it). I just upgraded to Peewee 2.8.3 and only the first call of each burst works, the other calls say `peewee.OperationalError: database is locked` while executing `part.save()`. I tried to revert to older versions, and I found out that with Peewee 2.4.4 works well and with the 2.4.5 fails. I reverted back to 2.4.4 on the production server and everything seems to work fine. Any idea whether I am doing something wrong or this is really a regression? Where do I start investigating? Here is (part of) the code: ``` db = peewee.SqliteDatabase(path_name + '/doc.db', threadlocals=True) class PeeweeModel(peewee.Model): class Meta: database = db class CncProgramPart(PeeweeModel): sheet = peewee.ForeignKeyField(CncProgramSheet, related_name='parts') part_number = peewee.CharField() time_finished = peewee.DateTimeField(default=0) remake = peewee.BooleanField(default=False) comment = peewee.CharField(default='') def render(self, settings): return render('cncprogram_edit_part_row.html', {'part': self, 'settings': settings}) class DocFinder: @cherrypy.expose def cncprogram_done(self, rowid, value): with db.transaction(): checked = value == 'true' now = time.time() part = CncProgramPart.get(CncProgramPart.id == rowid[9:]) if checked and not part.remake and not part.comment: part.time_finished = now part.comment = '' part.remake = False part.save() elif part.time_finished: part.time_finished = 0 part.save() return part.render(Settings()) ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1071/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1071/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1070
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1070/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1070/comments
https://api.github.com/repos/coleifer/peewee/issues/1070/events
https://github.com/coleifer/peewee/pull/1070
177,811,750
MDExOlB1bGxSZXF1ZXN0ODU4MTE4NzI=
1,070
fix ignore & replace syntax for mysql
{ "login": "631068264", "id": 8144089, "node_id": "MDQ6VXNlcjgxNDQwODk=", "avatar_url": "https://avatars.githubusercontent.com/u/8144089?v=4", "gravatar_id": "", "url": "https://api.github.com/users/631068264", "html_url": "https://github.com/631068264", "followers_url": "https://api.github.com/users/631068264/followers", "following_url": "https://api.github.com/users/631068264/following{/other_user}", "gists_url": "https://api.github.com/users/631068264/gists{/gist_id}", "starred_url": "https://api.github.com/users/631068264/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/631068264/subscriptions", "organizations_url": "https://api.github.com/users/631068264/orgs", "repos_url": "https://api.github.com/users/631068264/repos", "events_url": "https://api.github.com/users/631068264/events{/privacy}", "received_events_url": "https://api.github.com/users/631068264/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Currently ran into this. Would be awesome to see 1`INSERT IGNORE INTO` added for MySQL", "@coleifer what would need to happen to get this merged in. Would be willing to create new PR if needed.", "This should be working in 3.x. See:\r\n\r\n* http://docs.peewee-orm.com/en/latest/peewee/api.html#Insert\r\n* http://docs.peewee-orm.com/en/latest/peewee/api.html#Model.replace" ]
2016-09-19T15:09:40
2018-01-31T12:42:06
2018-01-31T12:42:06
NONE
null
2 bugs in peewee.py 1. `upsert_sql = 'INSERT OR REPLACE INTO'` will have syntax error for Mysql. So I fix it like `upsert_sql = 'REPLACE INTO'`. 2. add ignore for mysql `INSERT OR IGNORE INTO` will have syntax error for Mysql. Example: Page.insert(data).ignore().execute() Page.insert_many(data).ignore().execute() Generate sql: 'INSERT IGNORE INTO `page` (`manga_id`, `page_num`, `img_url`) VALUES (%s, %s, %s)', [11997, 6, 'http://img.177pic66.com/uploads/2016/05a/00178.jpg'] And you will get mysql warning when you use `ignore` but it can work: ``` /Users/wyx/project/scrap/.env/lib/python3.5/site-packages/pymysql/cursors.py:166: Warning: (1062, "Duplicate entry '6' for key 'page_page_num'") result = self._query(query) ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1070/reactions", "total_count": 1, "+1": 1, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1070/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/1070", "html_url": "https://github.com/coleifer/peewee/pull/1070", "diff_url": "https://github.com/coleifer/peewee/pull/1070.diff", "patch_url": "https://github.com/coleifer/peewee/pull/1070.patch", "merged_at": null }
https://api.github.com/repos/coleifer/peewee/issues/1069
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1069/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1069/comments
https://api.github.com/repos/coleifer/peewee/issues/1069/events
https://github.com/coleifer/peewee/issues/1069
177,798,607
MDU6SXNzdWUxNzc3OTg2MDc=
1,069
Add `upsert_many`
{ "login": "maxnoe", "id": 5488440, "node_id": "MDQ6VXNlcjU0ODg0NDA=", "avatar_url": "https://avatars.githubusercontent.com/u/5488440?v=4", "gravatar_id": "", "url": "https://api.github.com/users/maxnoe", "html_url": "https://github.com/maxnoe", "followers_url": "https://api.github.com/users/maxnoe/followers", "following_url": "https://api.github.com/users/maxnoe/following{/other_user}", "gists_url": "https://api.github.com/users/maxnoe/gists{/gist_id}", "starred_url": "https://api.github.com/users/maxnoe/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/maxnoe/subscriptions", "organizations_url": "https://api.github.com/users/maxnoe/orgs", "repos_url": "https://api.github.com/users/maxnoe/repos", "events_url": "https://api.github.com/users/maxnoe/events{/privacy}", "received_events_url": "https://api.github.com/users/maxnoe/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "What do you get calling insert_many() with .upsert() as well?\n", "You mean `insert_many(stuff).upsert()`?\n", "Yeah, I was just away from my computer and wondered what that would output?\n", "Ah, yes. This works. Thanks a lot.\n" ]
2016-09-19T14:23:00
2016-09-19T18:33:18
2016-09-19T18:33:18
NONE
null
There's `insert_many` but not `upsert_many`
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1069/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1069/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1068
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1068/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1068/comments
https://api.github.com/repos/coleifer/peewee/issues/1068/events
https://github.com/coleifer/peewee/issues/1068
177,696,157
MDU6SXNzdWUxNzc2OTYxNTc=
1,068
primary keys ignored in update queries
{ "login": "phryk", "id": 1021513, "node_id": "MDQ6VXNlcjEwMjE1MTM=", "avatar_url": "https://avatars.githubusercontent.com/u/1021513?v=4", "gravatar_id": "", "url": "https://api.github.com/users/phryk", "html_url": "https://github.com/phryk", "followers_url": "https://api.github.com/users/phryk/followers", "following_url": "https://api.github.com/users/phryk/following{/other_user}", "gists_url": "https://api.github.com/users/phryk/gists{/gist_id}", "starred_url": "https://api.github.com/users/phryk/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/phryk/subscriptions", "organizations_url": "https://api.github.com/users/phryk/orgs", "repos_url": "https://api.github.com/users/phryk/repos", "events_url": "https://api.github.com/users/phryk/events{/privacy}", "received_events_url": "https://api.github.com/users/phryk/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "When it comes to using composite primary keys, things like save() break down a bit because peewee doesn't know what exactly to do since the previous primary key values are gone from the model instance. The way it should work is that it would update, setting the new values and using the old values as the where clause. But when you change them, the old values are gone so peewee freaks out.\n\nBut changing primary keys is kind of a sign that maybe you should consider a different primary key.\n", "I'm not editing for any real use-case, I'm just writing very generic software on top of peewee and noticed this behavior, which seemed weird to me - but it makes total sense now.\nI'll look for a way to either nicely assert from a Model class whether this will happen or simply implement an immutability flag for Models like this.\n\nThanks for the info so early in the morning. :)\n" ]
2016-09-19T02:55:33
2016-09-19T04:42:55
2016-09-19T04:18:28
NONE
null
Primary keys are ignored (at least for `CompositeKeyField`) when `UPDATE`-ing rows. I have a few "linker" tables that are just two `ForeignKeyField` used as `CompositeKeyField`. They are not editable due to this, since any call to `.save()` results in a syntax error in the query. I pasted an example illustrating this behavior here: https://paste.xinu.at/Jz87/ Does peewee just not support updating primary keys due to potential consistency problems when using `ForeignKeyField` or is this a bug? I.e. do I have to work around this in my software or do you consider this something that falls under peewee's responsibility?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1068/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1068/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1067
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1067/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1067/comments
https://api.github.com/repos/coleifer/peewee/issues/1067/events
https://github.com/coleifer/peewee/issues/1067
177,584,562
MDU6SXNzdWUxNzc1ODQ1NjI=
1,067
support insert ignore , on duplicate key update or replace for mysql?
{ "login": "631068264", "id": 8144089, "node_id": "MDQ6VXNlcjgxNDQwODk=", "avatar_url": "https://avatars.githubusercontent.com/u/8144089?v=4", "gravatar_id": "", "url": "https://api.github.com/users/631068264", "html_url": "https://github.com/631068264", "followers_url": "https://api.github.com/users/631068264/followers", "following_url": "https://api.github.com/users/631068264/following{/other_user}", "gists_url": "https://api.github.com/users/631068264/gists{/gist_id}", "starred_url": "https://api.github.com/users/631068264/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/631068264/subscriptions", "organizations_url": "https://api.github.com/users/631068264/orgs", "repos_url": "https://api.github.com/users/631068264/repos", "events_url": "https://api.github.com/users/631068264/events{/privacy}", "received_events_url": "https://api.github.com/users/631068264/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "OK . I find only `ignore` in [InsertQuery.on_conflict](http://docs.peeweeorm.com/en/latest/peewee/api.html#InsertQuery.on_conflict). But what is `INSERT OR IGNORE INTO` ? In Mysql only `INSERT IGNORE INTO` is right( I didn't use PostgreSQL or SQLite ). I think you should divide **peewee** into different versions for different DBMS and it can adapt to some features in different DBMS. \n\nI like **peewee** than **SQLAlchemy** because the former‘s document and api design are much more beautiful than the latter. I hope **peewee** become more perfect.\n", "At the moment the upsert/insert or replace code is a bit fragmented and poorly designed.\n\nHave you tried using the `upsert()` syntax, or could you share the insert statement you're executing along with the generated SQL?\n", "I create a pull request. I hope you can have a look.@coleifer\nhttps://github.com/coleifer/peewee/pull/1070\n", "I would like that upsert behaviour work with all databases. If this is too complex with sql support on specific databases, maybe with a fallback to create_or_get() then save()\r\nI'm getting db type from conf file at runtime. There is also peewee-mssql addition. For compability I'm doing create_or_get() then save(). It would be good to have upsert() work with optimized sql or fallback. Or if you have other advices?", "Hi, I am having the same issue. Any plans to get the PR merged? I am not much experienced with Python, but in case some help is needed to get this done, I can give a shot.\r\nThanks!", "> Have you tried using the `upsert()` syntax, or could you share the insert statement you're executing along with the generated SQL?\r\n\r\nThe big problem with `upsert()` in MySQL is that it generates a `REPLACE INTO` which deletes the matching rows and re-inserts them. If there is a foreign key to that row then those keys are taken into account (either cascading the delete or blocking the delete). However, an `INSERT INTO ... ON DUPLICATE KEY UPDATE` doesn't have this issue.", "As a workaround, I did the following:\r\n\r\n``` python\r\nclass CustomInsertQuery(InsertQuery):\r\n \"\"\" Custom implementation of peewee's InsertQuery that provides\r\n proper syntax for `IGNORE` inserts on MySQL.\r\n\r\n https://github.com/coleifer/peewee/issues/1067\r\n \"\"\"\r\n\r\n def sql(self):\r\n sql, params = super(CustomInsertQuery, self).sql()\r\n if sql.startswith('INSERT OR'):\r\n sql = sql.replace('INSERT OR', 'INSERT')\r\n return sql, params\r\n```\r\n\r\n``` python\r\nclass CustomBaseModel(Model):\r\n\r\n @classmethod\r\n def insert(cls, __data=None, **insert):\r\n fdict = __data or {}\r\n fdict.update([(cls._meta.fields[f], insert[f]) for f in insert])\r\n return CustomInsertQuery(cls, fdict)\r\n\r\n @classmethod\r\n def insert_many(cls, rows, validate_fields=True):\r\n return CustomInsertQuery(cls, rows=rows, validate_fields=validate_fields)\r\n```\r\n", "Please see new discussion thread in #1307 (which consolidates discussion of upsert functionality for sqlite/mysql/postgres)." ]
2016-09-17T15:25:14
2017-07-05T04:23:18
2017-07-05T04:23:18
NONE
null
support insert ignore , on duplicate key update or replace for mysql. I want to use `insert_many` to insert data into mysql. But one of column is a `UNIQUE KEY` so how to solve this. I hope it can like this `execute(ignore=True)`
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1067/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1067/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1066
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1066/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1066/comments
https://api.github.com/repos/coleifer/peewee/issues/1066/events
https://github.com/coleifer/peewee/issues/1066
177,460,723
MDU6SXNzdWUxNzc0NjA3MjM=
1,066
KeyError: '"title" is not a recognized field.'
{ "login": "631068264", "id": 8144089, "node_id": "MDQ6VXNlcjgxNDQwODk=", "avatar_url": "https://avatars.githubusercontent.com/u/8144089?v=4", "gravatar_id": "", "url": "https://api.github.com/users/631068264", "html_url": "https://github.com/631068264", "followers_url": "https://api.github.com/users/631068264/followers", "following_url": "https://api.github.com/users/631068264/following{/other_user}", "gists_url": "https://api.github.com/users/631068264/gists{/gist_id}", "starred_url": "https://api.github.com/users/631068264/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/631068264/subscriptions", "organizations_url": "https://api.github.com/users/631068264/orgs", "repos_url": "https://api.github.com/users/631068264/repos", "events_url": "https://api.github.com/users/631068264/events{/privacy}", "received_events_url": "https://api.github.com/users/631068264/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[]
2016-09-16T15:57:12
2017-03-28T05:34:56
2016-09-16T15:59:11
NONE
null
``` class Manga(BaseModel): manga_id = IntegerField(unique=True, help_text="漫画id") cover_url = CharField(help_text="封面链接") view_page = CharField(help_text="漫画链接") title = CharField(help_text="漫画标题") date = DateField(help_text="发布日期") ``` What I want to save is a list of dict like `{'manga_id': 1233504, 'title': '[中文][天道まさえ] 二つ結び [雙重馬尾][177P]', 'cover_url': 'http://img.177pic66.com/uploads/2016/08a/00012.jpg', 'date': datetime.date(2016, 9, 15), 'view_page': 'http://www.177pic66.com/html/2016/09/1233504.html'}` and I use `Manga.insert_many(items).execute()` so why I can't insert it.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1066/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1066/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1065
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1065/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1065/comments
https://api.github.com/repos/coleifer/peewee/issues/1065/events
https://github.com/coleifer/peewee/issues/1065
177,453,577
MDU6SXNzdWUxNzc0NTM1Nzc=
1,065
{AttributeError}'ModelOptions' object has no attribute 'declared_fields'
{ "login": "smittysmee", "id": 8376011, "node_id": "MDQ6VXNlcjgzNzYwMTE=", "avatar_url": "https://avatars.githubusercontent.com/u/8376011?v=4", "gravatar_id": "", "url": "https://api.github.com/users/smittysmee", "html_url": "https://github.com/smittysmee", "followers_url": "https://api.github.com/users/smittysmee/followers", "following_url": "https://api.github.com/users/smittysmee/following{/other_user}", "gists_url": "https://api.github.com/users/smittysmee/gists{/gist_id}", "starred_url": "https://api.github.com/users/smittysmee/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/smittysmee/subscriptions", "organizations_url": "https://api.github.com/users/smittysmee/orgs", "repos_url": "https://api.github.com/users/smittysmee/repos", "events_url": "https://api.github.com/users/smittysmee/events{/privacy}", "received_events_url": "https://api.github.com/users/smittysmee/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Issue with versions in my systems library and within the project.\n" ]
2016-09-16T15:26:15
2016-09-16T15:57:49
2016-09-16T15:57:49
NONE
null
Attempting a basic command, but it appears that "declared_fields" in the _meta is not a valid field. See line in code [here](https://github.com/coleifer/peewee/blob/master/playhouse/shortcuts.py#L107). **Model:** ``` db = AppEngineDatabase('adb') class CloudSQLModel(Model): create_date = DateField(default=datetime.datetime.now) last_modified = DateField(default=datetime.datetime.now) modified_by = CharField(null=True) #ndb key of the user that modified it class Meta: database = db # This model uses the "agent.db" database # Add the initial items for insertion into our datastore class SourcedModel(CloudSQLModel): # Create the available status of the property STATE_CHOICES = ( (0, 'new'), (1, 'csg_cleaned'), (2, 'third_party_cleaned'), (3, 'ready'), (4, 'released'), (5, 'expired'), (9, 'deleted')) # Source of the location that we found... usually a URL will suffice source = CharField(null=True) # Date of the item last touched upon last_seen_date = DateField(null=True) # Status of the property... we do not delete, just disable state = IntegerField(default=0, choices=STATE_CHOICES) # Return the status of the item def get_status_label(self): return dict(self.STATUS_CHOICES)[self.status] class NationalProducerNumber(SourcedModel): number = CharField() ``` **Create new item and attempt to print model.** ``` npn = NationalProducerNumber.create( number="001193381901" ) print(model_to_dict(non)) ``` When I run the code shown, I receive the following Attribute Error: `'ModelOptions' object has no attribute 'declared_fields` Declared fields does not seem to be an attribute of the _meta object. `fields` is present, but `declared_fields` is not. Am I missing a key step in this?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1065/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1065/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1064
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1064/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1064/comments
https://api.github.com/repos/coleifer/peewee/issues/1064/events
https://github.com/coleifer/peewee/issues/1064
177,435,453
MDU6SXNzdWUxNzc0MzU0NTM=
1,064
Add postgresql network address types plz
{ "login": "Q-Master", "id": 2825907, "node_id": "MDQ6VXNlcjI4MjU5MDc=", "avatar_url": "https://avatars.githubusercontent.com/u/2825907?v=4", "gravatar_id": "", "url": "https://api.github.com/users/Q-Master", "html_url": "https://github.com/Q-Master", "followers_url": "https://api.github.com/users/Q-Master/followers", "following_url": "https://api.github.com/users/Q-Master/following{/other_user}", "gists_url": "https://api.github.com/users/Q-Master/gists{/gist_id}", "starred_url": "https://api.github.com/users/Q-Master/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/Q-Master/subscriptions", "organizations_url": "https://api.github.com/users/Q-Master/orgs", "repos_url": "https://api.github.com/users/Q-Master/repos", "events_url": "https://api.github.com/users/Q-Master/events{/privacy}", "received_events_url": "https://api.github.com/users/Q-Master/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Peewee does not currently support that column type. To add it, see the custom field docs:\n\nhttp://docs.peewee-orm.com/en/latest/peewee/models.html#custom-fields\n\nTo get pwiz to understand the field, you'll first need your field class, then you'll want to modify the `PostgresqlMetadata.column_map` mapping the OID to the new field type.\n" ]
2016-09-16T14:11:20
2016-09-19T03:39:45
2016-09-19T03:39:45
NONE
null
ALTER TABLE info ADD COLUMN ip inet; this column type causes the pwiz.py to generate UnknownField class. https://www.postgresql.org/docs/9.1/static/datatype-net-types.html
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1064/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1064/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1063
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1063/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1063/comments
https://api.github.com/repos/coleifer/peewee/issues/1063/events
https://github.com/coleifer/peewee/pull/1063
177,326,806
MDExOlB1bGxSZXF1ZXN0ODU1MDY1ODM=
1,063
Fix threadlocal pool
{ "login": "alexlatchford", "id": 628146, "node_id": "MDQ6VXNlcjYyODE0Ng==", "avatar_url": "https://avatars.githubusercontent.com/u/628146?v=4", "gravatar_id": "", "url": "https://api.github.com/users/alexlatchford", "html_url": "https://github.com/alexlatchford", "followers_url": "https://api.github.com/users/alexlatchford/followers", "following_url": "https://api.github.com/users/alexlatchford/following{/other_user}", "gists_url": "https://api.github.com/users/alexlatchford/gists{/gist_id}", "starred_url": "https://api.github.com/users/alexlatchford/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/alexlatchford/subscriptions", "organizations_url": "https://api.github.com/users/alexlatchford/orgs", "repos_url": "https://api.github.com/users/alexlatchford/repos", "events_url": "https://api.github.com/users/alexlatchford/events{/privacy}", "received_events_url": "https://api.github.com/users/alexlatchford/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Wait...isn't this the whole point of connection pooling?\n", "Actually hold up, I see what you're talking about -- the issue isn't the pool, but the fact that peewee only holds a connection per thread.\n\nIf you need more than one connection (what is your use-case? I'm genuinely curious and not asking in an attempt to be patronizing), you can use the `ExecutionContext()`:\n\nhttp://docs.peewee-orm.com/en/latest/peewee/database.html#advanced-connection-management\n\n> Execution contexts allow finer-grained control over managing multiple connections to the database. When an execution context is initialized (either as a context manager or as a decorated function), a separate connection will be used for the duration of the wrapped block. You can also choose whether to wrap the block in a transaction.\n\nThere is already a mechanism in place for managing multiple conns per thread, so I will pass on this patch.\n\nLet me know if this is unclear.\n", "I think you've got the wrong end of the stick here. This patch fixes a connection leak which is unrecoverable, because you lose the reference unless you call `db.close_all()`.\n\nWhen you open 2 connections in a nested fashion (which we do accidentally, our fault) I'd assumed that because it was outside of an `ExecutionContext` block it would just do a noop on the second `db.connect()` and reuse the same connection as it's on the same thread. Unfortunately that doesn't happen and instead it draws another connection from the pool, overwriting the reference to the first in the `Database` instance (but it's still referenced in `db._in_use` so it cannot be garbage collected or closed).\n\nIf you repeat this the number of times you've set your `max_connections` to then you've exhausted your pool and your app starts throwing `ValueError(\"Max connections exceeded\")`.\n\nHope that makes some more sense.\n", "This has always been the behavior, though I agree that an accident in your code can have disproportionately bad consequences. I'm reluctant to change it because the method is a verb, and implies an action taking place. If you want to have the \"connect or re-use existing\" behavior, that is what the `Database.get_conn()` method is for.\n\nI can see an argument, however, for modifying the pool such that multiple calls to connect do not leak a connection. Reopening.\n", "Cool I've switched over our code to use `get_conn()`, I hadn't come across that one yet and looks like it'll do the job for what we're after actually. I agree that muddling the actionability isn't ideal so happy to close this and hopefully this PR can serve as documentation for those in the same unlikely situation in the future if they go googling.\n\nJust deployed this and looks like this solved our particular problem, thanks so much for your help!\n", "Maybe the only change I'd suggest out of this would be to change the docs for the Pool to use an example with `get_conn` to highlight this problem.\n" ]
2016-09-16T01:17:51
2016-09-23T18:03:27
2016-09-23T18:02:19
CONTRIBUTOR
null
So, I appreciate there are use cases for multiple connections open per thread but please don't shoot me down straight away! Test code: ``` python from peewee import * from playhouse.pool import PooledPostgresqlExtDatabase db = PooledPostgresqlExtDatabase( 'my_app', user='postgres', threadlocals=True, register_hstore=False ) def num_conn(): return len(db._in_use) print num_conn() db.connect() print num_conn() db.connect() print num_conn() db.close() print num_conn() db.close() print num_conn() ``` This outputs (against master): ``` bash (env) alexlatchford@MacBook-Pro peewee $ python test.py 0 1 2 1 1 ``` Obviously results in an unexpected connection leak under normal user circumstances. I'd like to advocate for the introduction of the nesting flag so you can explicitly choose whether you desire this behaviour. With this patch: ``` bash (env) alexlatchford@MacBook-Pro peewee $ python test.py 0 1 1 0 0 ``` Any comments would be great, this is a bug that's taken me a while to track down and has been affecting us in production so would be great to get a solution in place! (I know ideally we just shouldn't open 2 connections nested, but with several devs, lots of code I'm trying to look for the pragamatic solution to wholly prevent this leaking behaviour) Cheers, Alex
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1063/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1063/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/1063", "html_url": "https://github.com/coleifer/peewee/pull/1063", "diff_url": "https://github.com/coleifer/peewee/pull/1063.diff", "patch_url": "https://github.com/coleifer/peewee/pull/1063.patch", "merged_at": null }
https://api.github.com/repos/coleifer/peewee/issues/1062
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1062/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1062/comments
https://api.github.com/repos/coleifer/peewee/issues/1062/events
https://github.com/coleifer/peewee/issues/1062
177,126,437
MDU6SXNzdWUxNzcxMjY0Mzc=
1,062
Join by field (using)
{ "login": "ak4nv", "id": 73960, "node_id": "MDQ6VXNlcjczOTYw", "avatar_url": "https://avatars.githubusercontent.com/u/73960?v=4", "gravatar_id": "", "url": "https://api.github.com/users/ak4nv", "html_url": "https://github.com/ak4nv", "followers_url": "https://api.github.com/users/ak4nv/followers", "following_url": "https://api.github.com/users/ak4nv/following{/other_user}", "gists_url": "https://api.github.com/users/ak4nv/gists{/gist_id}", "starred_url": "https://api.github.com/users/ak4nv/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/ak4nv/subscriptions", "organizations_url": "https://api.github.com/users/ak4nv/orgs", "repos_url": "https://api.github.com/users/ak4nv/repos", "events_url": "https://api.github.com/users/ak4nv/events{/privacy}", "received_events_url": "https://api.github.com/users/ak4nv/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Joining on a subquery is totally easy in peewee, you just have to use the explicit form of the join predicate:\n\n``` python\nsubq = Service.select(fn.unnest(Service.ms).alias('code'))\nsubq = subq.alias('svc') # Subqueries need an alias.\nqs = (MedServ\n .select(MedServ.code, MedServ.name)\n .join(subq, on=(MedServ.code == subq.c.code)))\n```\n\nTo access a column inside the subquery we use the magical \"subq.c.code\". The \".c\" just allows us to create references to values inside the subquery.\n\nDoes that help?\n\nAnd no, peewee itself will not, but there are already at least one Peewee extension that provide asyncio. This one seems pretty popular:\n\nhttps://github.com/05bit/peewee-async\n", "Also, docs: http://docs.peewee-orm.com/en/latest/peewee/querying.html#using-subqueries\n", "> Does that help?\n\nYes, that's I need! Thanks!\nReally, yesterday I tired and forgot about `.c`\n\nI surprised about progress peewee-asyncio. Last time I saw the project it had 0.0.5 version :)\nWhat is the main difference between 2.8 and 3 branches of peewee?\n", "Closing as the issue seems resolved.\n\nDifferences: mostly around the SQL generation, but generally the goal is to have a more powerful sql generator. Also decoupling the returning of records from model instances\n" ]
2016-09-15T09:12:58
2016-09-20T17:12:25
2016-09-20T17:12:25
NONE
null
I try to write query: ``` sql select code, name from medservices join ( select unnest(ms) as code from services where id = 7 ) u using (code); ``` in peewee. And I can't understand how to do: ``` python qs = (MedServ .select(MedServ.code, MedServ.name) .join( Service.select(fn.unnest(Service.ms).alias('code')).where(Service.id == id), on=(MedServ.code == ???)) ``` I need join table with subquery by named field. Is it possible? P.S. Will the 3'd version of peewee use asyncio? :-)
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1062/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1062/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1061
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1061/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1061/comments
https://api.github.com/repos/coleifer/peewee/issues/1061/events
https://github.com/coleifer/peewee/pull/1061
176,808,649
MDExOlB1bGxSZXF1ZXN0ODUxNjMxODI=
1,061
fixed a problem with TimestampField resolution
{ "login": "akrs", "id": 2895505, "node_id": "MDQ6VXNlcjI4OTU1MDU=", "avatar_url": "https://avatars.githubusercontent.com/u/2895505?v=4", "gravatar_id": "", "url": "https://api.github.com/users/akrs", "html_url": "https://github.com/akrs", "followers_url": "https://api.github.com/users/akrs/followers", "following_url": "https://api.github.com/users/akrs/following{/other_user}", "gists_url": "https://api.github.com/users/akrs/gists{/gist_id}", "starred_url": "https://api.github.com/users/akrs/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/akrs/subscriptions", "organizations_url": "https://api.github.com/users/akrs/orgs", "repos_url": "https://api.github.com/users/akrs/repos", "events_url": "https://api.github.com/users/akrs/events{/privacy}", "received_events_url": "https://api.github.com/users/akrs/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Also had to fix the unit test, as the unit test assumed that `654321` microseconds stored with a millisecond precision would come out as `654` microseconds instead of `654000` microseconds.\n" ]
2016-09-14T03:56:17
2016-09-15T04:44:09
2016-09-15T04:44:09
CONTRIBUTOR
null
When retrieving a value from the database, TimestampField didn't properly scale the microseconds by the resolution. Instead of using the resolution, it would always assume the fractional portion was in microseconds. This fixes that by scaling the fractional second portion as a function of the resolution.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1061/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1061/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/1061", "html_url": "https://github.com/coleifer/peewee/pull/1061", "diff_url": "https://github.com/coleifer/peewee/pull/1061.diff", "patch_url": "https://github.com/coleifer/peewee/pull/1061.patch", "merged_at": "2016-09-15T04:44:09" }
https://api.github.com/repos/coleifer/peewee/issues/1060
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1060/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1060/comments
https://api.github.com/repos/coleifer/peewee/issues/1060/events
https://github.com/coleifer/peewee/issues/1060
176,696,945
MDU6SXNzdWUxNzY2OTY5NDU=
1,060
Variable non-persistent instances?
{ "login": "johaven", "id": 5459596, "node_id": "MDQ6VXNlcjU0NTk1OTY=", "avatar_url": "https://avatars.githubusercontent.com/u/5459596?v=4", "gravatar_id": "", "url": "https://api.github.com/users/johaven", "html_url": "https://github.com/johaven", "followers_url": "https://api.github.com/users/johaven/followers", "following_url": "https://api.github.com/users/johaven/following{/other_user}", "gists_url": "https://api.github.com/users/johaven/gists{/gist_id}", "starred_url": "https://api.github.com/users/johaven/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/johaven/subscriptions", "organizations_url": "https://api.github.com/users/johaven/orgs", "repos_url": "https://api.github.com/users/johaven/repos", "events_url": "https://api.github.com/users/johaven/events{/privacy}", "received_events_url": "https://api.github.com/users/johaven/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "peewee is an activerecord ORM. Once you understand that, though, there are no surprises. An instance is a container for row values, but not a representation of the row itself in the sense that multiple instances with the same ID are somehow linked.\n\nDoes that help? And yes it is standard behavior. Django is the same.\n", "Please add a comment or create a new issue if you feel I haven't answered your question, or you are still not sure how this works.\n", "Ok for me, thank you :)\n" ]
2016-09-13T17:07:43
2016-09-16T13:34:32
2016-09-15T05:13:36
NONE
null
``` python >>> p = db.Paths.select().where(db.Paths.id == 1).get() >>> p.lastsync datetime.datetime(2016, 9, 13, 18, 59, 32, 463395) >>> v = db.Paths.select().where(db.Paths.id == 1).get() >>> id(p), id(v) (4545364304, 4545364496) >>> v.lastsync datetime.datetime(2016, 9, 13, 19, 0, 41, 913038) >>> import datetime >>> v.lastsync = datetime.datetime.now() >>> v.save() 1 >>> v.lastsync datetime.datetime(2016, 9, 13, 19, 1, 28, 755457) >>> p.lastsync datetime.datetime(2016, 9, 13, 18, 59, 32, 463395) >>> v.is_enabled = 0 >>> v.save() 1 >>> v.is_enabled 0 >>> p.is_enabled True ``` Is this a standard behavior?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1060/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1060/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1059
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1059/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1059/comments
https://api.github.com/repos/coleifer/peewee/issues/1059/events
https://github.com/coleifer/peewee/issues/1059
176,291,443
MDU6SXNzdWUxNzYyOTE0NDM=
1,059
test_database uses production database instead of test database
{ "login": "ajpen", "id": 4834786, "node_id": "MDQ6VXNlcjQ4MzQ3ODY=", "avatar_url": "https://avatars.githubusercontent.com/u/4834786?v=4", "gravatar_id": "", "url": "https://api.github.com/users/ajpen", "html_url": "https://github.com/ajpen", "followers_url": "https://api.github.com/users/ajpen/followers", "following_url": "https://api.github.com/users/ajpen/following{/other_user}", "gists_url": "https://api.github.com/users/ajpen/gists{/gist_id}", "starred_url": "https://api.github.com/users/ajpen/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/ajpen/subscriptions", "organizations_url": "https://api.github.com/users/ajpen/orgs", "repos_url": "https://api.github.com/users/ajpen/repos", "events_url": "https://api.github.com/users/ajpen/events{/privacy}", "received_events_url": "https://api.github.com/users/ajpen/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "This is an issue:\n\n(Admin)\n\nA 1-item tuple needs a trailing comma. Try again and let me know.\n", "Have you been able to try your code with the change I suggested? This is the change:\n\n``` python\n def test_Admin(self):\n # v\n with test_database(test_db, (Admin,), create_tables=True):\n```\n", "I just saw your comment. About to try it now.\n", "It works now, thanks. \n", "I think I can make the code a little safer in the event of invalid input, so prod data doesn't get hurt. Very sorry an error wasn't raised.\n", "That's fine. Happy to contribute. \n", "A suggestion for the [docs](http://docs.peewee-orm.com/en/latest/peewee/playhouse.html#test-utils)\n\nMaybe change \n\n> models – a list of Model classes to use with the db\n\nto \n\n> models – a tuple of Model classes to use with the db\n\nOr add a note about the trailing comma for single element tuples. \n", "The trailing comma thing is just a part of Python, really. So beyond the scope of peewee that I'd feel compelled to add it anywhere a tuple is accepted, if I were going to start adding it here or there.\n", "Hopefully, that'll help until you find something safer\n" ]
2016-09-12T04:15:22
2016-09-24T18:50:18
2016-09-15T22:45:01
NONE
null
I've the following code for testing: ``` from db import * import unittest from playhouse.test_utils import test_database test_db = MySQLDatabase('testdb', user='testuser', password='testpass') class DatabaseTestSuite(unittest.TestCase): def test_Admin(self): with test_database(test_db, (Admin), create_tables=True): Admin.create(username="testuser", email="[email protected]") result = Admin.select().where(Admin.user == "testuser") unittest.assertIsNotNone(result) if __name__ == '__main__': unittest.main() ``` Running the test produced this: ``` ====================================================================== ERROR: test_Admin (__main__.DatabaseTestSuite) ---------------------------------------------------------------------- Traceback (most recent call last): File "db/db_test.py", line 14, in test_Admin with test_database(test_db, (Admin), create_tables=True): File "/usr/local/lib/python2.7/dist-packages/playhouse/test_utils.py", line 21, in __enter__ for m in self.models: File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 4723, in __iter__ return iter(self.select()) File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 3149, in __iter__ return iter(self.execute()) File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 3142, in execute self._qr = ResultWrapper(model_class, self._execute(), query_meta) File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 2826, in _execute return self.database.execute_sql(sql, params, self.require_commit) File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 3683, in execute_sql self.commit() File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 3507, in __exit__ reraise(new_type, new_type(*exc_args), traceback) File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 3676, in execute_sql cursor.execute(sql, params or ()) File "/usr/local/lib/python2.7/dist-packages/pymysql/cursors.py", line 166, in execute result = self._query(query) File "/usr/local/lib/python2.7/dist-packages/pymysql/cursors.py", line 322, in _query conn.query(q) File "/usr/local/lib/python2.7/dist-packages/pymysql/connections.py", line 835, in query self._affected_rows = self._read_query_result(unbuffered=unbuffered) File "/usr/local/lib/python2.7/dist-packages/pymysql/connections.py", line 1019, in _read_query_result result.read() File "/usr/local/lib/python2.7/dist-packages/pymysql/connections.py", line 1302, in read first_packet = self.connection._read_packet() File "/usr/local/lib/python2.7/dist-packages/pymysql/connections.py", line 981, in _read_packet packet.check_error() File "/usr/local/lib/python2.7/dist-packages/pymysql/connections.py", line 393, in check_error err.raise_mysql_exception(self._data) File "/usr/local/lib/python2.7/dist-packages/pymysql/err.py", line 107, in raise_mysql_exception raise errorclass(errno, errval) ProgrammingError: (1146, u"Table 'db.admin' doesn't exist") ---------------------------------------------------------------------- ``` The database 'db' refers to the production database and not the test database. The test should not be using the production database and only the test database. Here's my db module: ``` from peewee import * import datetime # Database for the app _Database = MySQLDatabase('db', host="localhost", user='db_user', password='db_pass') # specifies the database all the other models class BaseModel(Model): class Meta: database = _Database # Database Objects class Admin(BaseModel): # Admin unique indentifier field #id = PrimaryKeyField() username = CharField(unique=True, max_length=200) email = CharField(unique=True, max_length=500) created = DateTimeField(default=datetime.datetime.now) ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1059/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1059/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1058
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1058/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1058/comments
https://api.github.com/repos/coleifer/peewee/issues/1058/events
https://github.com/coleifer/peewee/issues/1058
175,730,241
MDU6SXNzdWUxNzU3MzAyNDE=
1,058
Peewee 2.8.3 insert_many problem
{ "login": "MarkSeol", "id": 1631677, "node_id": "MDQ6VXNlcjE2MzE2Nzc=", "avatar_url": "https://avatars.githubusercontent.com/u/1631677?v=4", "gravatar_id": "", "url": "https://api.github.com/users/MarkSeol", "html_url": "https://github.com/MarkSeol", "followers_url": "https://api.github.com/users/MarkSeol/followers", "following_url": "https://api.github.com/users/MarkSeol/following{/other_user}", "gists_url": "https://api.github.com/users/MarkSeol/gists{/gist_id}", "starred_url": "https://api.github.com/users/MarkSeol/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/MarkSeol/subscriptions", "organizations_url": "https://api.github.com/users/MarkSeol/orgs", "repos_url": "https://api.github.com/users/MarkSeol/repos", "events_url": "https://api.github.com/users/MarkSeol/events{/privacy}", "received_events_url": "https://api.github.com/users/MarkSeol/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "By the way, cursor.lastrowid is exactly the first record's id, it's what we want.\nBy using cursor.fetchone() or cursor.fetchall(), nothing is returned.\n", "This is intentional. When you're inserting multiple rows with auto-incrementing primary keys, and only the first ID is returned, it seems like maybe it would be confusing.\n\nPostgres supports `RETURNING`, which can be used to do an `INSERT` and get back the relevant IDs. MySQL and SQLite, however, do not.\n", "Thanks for replying. \nSo I think we should change db to Postgres or we modify a little code to return the cursor.lastrowid.\n", "Could you describe why you need the id when inserting multiple records?\n" ]
2016-09-08T11:31:16
2016-09-09T05:59:18
2016-09-09T03:20:37
NONE
null
Hi Charles: Sorry to trouble you, we are using peewee and mysql, and our model's primary key is auto increase, we found a problem when invoking the insert_many api. The method doesn't return the first inserted record's id, it just return True, but in the early version(like 2.4.5), it does return the first id. So, we checked the peewee.py code. The insert section starts from line 3436: ``` if not self._is_multi_row_insert: if self.database.insert_returning: pk_row = cursor.fetchone() meta = self.model_class._meta clean_data = [ field.python_value(column) for field, column in zip(meta.get_primary_key_fields(), pk_row)] if self.model_class._meta.composite_key: return clean_data return clean_data[0] return self.database.last_insert_id(cursor, self.model_class) elif self._return_id_list: return map(operator.itemgetter(0), cursor.fetchall()) else: return True ``` - If we use Model.insert_many(rows).execute() , it just return True. - If we use Model.insert_many(rows).return_id_list().execute(), it return a empty array []. operator.itemgetter(0), cursor.fetchall() both return empty array. - If we use Model.insert_many(rows).returning(Model).execute(), an exception is threw out says that database is not supported. So we want to ask is the insert_many method's behavior is by design or a bug? And how can we get the inserted id if we still want to use the insert many for sake of good performance? Thanks.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1058/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1058/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1057
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1057/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1057/comments
https://api.github.com/repos/coleifer/peewee/issues/1057/events
https://github.com/coleifer/peewee/issues/1057
175,344,200
MDU6SXNzdWUxNzUzNDQyMDA=
1,057
Model create() and save() behavior
{ "login": "changyuheng", "id": 1842626, "node_id": "MDQ6VXNlcjE4NDI2MjY=", "avatar_url": "https://avatars.githubusercontent.com/u/1842626?v=4", "gravatar_id": "", "url": "https://api.github.com/users/changyuheng", "html_url": "https://github.com/changyuheng", "followers_url": "https://api.github.com/users/changyuheng/followers", "following_url": "https://api.github.com/users/changyuheng/following{/other_user}", "gists_url": "https://api.github.com/users/changyuheng/gists{/gist_id}", "starred_url": "https://api.github.com/users/changyuheng/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/changyuheng/subscriptions", "organizations_url": "https://api.github.com/users/changyuheng/orgs", "repos_url": "https://api.github.com/users/changyuheng/repos", "events_url": "https://api.github.com/users/changyuheng/events{/privacy}", "received_events_url": "https://api.github.com/users/changyuheng/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Using IntegerField(primary _key=True) is not an auto-incrementing id. It happens to work due to the quirks of SQLite, but the semantics as far as peewee is concerned, are not autoincrement. You should use PrimaryKeyField instead.\n", "http://docs.peewee-orm.com/en/latest/peewee/models.html#manually-specifying-primary-keys\n", "You're right. I didn't use the library right. I'll close this issue. Thank you!\n", "Well, I'm not happy about being right, since it means I made a confusing API in this case. I'll try and add some more visible docs around this behavior.\n" ]
2016-09-06T20:31:26
2016-09-07T06:37:29
2016-09-07T06:05:27
NONE
null
Hi guys. I know this has been discussed in #651 but I still have some things want you guys to know. [After inserting a new record by creating, we'll get an instance from return](http://docs.peewee-orm.com/en/latest/peewee/api.html#Model.create). No offense but I think intuitively this instance should be bound to the just created record. But it seemed like not. Say I give some values to create a new record without giving the auto-increment primary key, then get the returned instance. If I modify the value on the instance and `.save()` again. It should update the current record. But it actually tries to create a new one. Here's the test code: ``` py from datetime import datetime from peewee import Model, DateTimeField, ForeignKeyField, IntegerField, TextField, BooleanField, FloatField from playhouse.sqlite_ext import SqliteExtDatabase import json import os class MySqliteExtDatabase(SqliteExtDatabase): def sequence_exists(self, seq): super().sequence_exists(seq) def initialize_connection(self, conn): self.execute_sql('PRAGMA foreign_keys=ON;') def get_pragma(self, pragma): return next(self.execute_sql('PRAGMA ' + pragma + ';'))[0] def set_pragma(self, expression): self.execute_sql('PRAGMA ' + expression + ';') def get_version(self): return self.get_pragma('user_version') def set_version(self, version): self.set_pragma('user_version=' + str(version)) database = MySqliteExtDatabase(None, journal_mode='WAL') class BaseModel(Model): id = IntegerField(primary_key=True) created_date = DateTimeField(index=True, default=datetime.utcnow) class Meta: database = database order_by = ('-created_date',) class Settings(BaseModel): key = TextField(index=True) value = TextField(null=True) class UniqSettings(BaseModel): key = TextField(unique=True) value = TextField(null=True) def main(): database_file = 'example.db' database.init(database_file) database.create_tables([Settings, UniqSettings], safe=True) setting = Settings.create(key='foo', value='bar') print('dumping Settings:') os.system('sqlite3 {} ".dump {}"'.format(database_file, 'settings')) setting.value = 'baz' setting.save() print('dumping Settings:') os.system('sqlite3 {} ".dump {}"'.format(database_file, 'settings')) setting.id = 1 setting.save() print('dumping Settings:') os.system('sqlite3 {} ".dump {}"'.format(database_file, 'settings')) uniq_setting = UniqSettings.create(key='qux', value='quux') print('dumping UniqSettings:') os.system('sqlite3 {} ".dump {}"'.format(database_file, 'uniqsettings')) uniq_setting.value = 'corge' try: uniq_setting.save() except Exception as e: print(str(e)) print('dumping UniqSettings:') os.system('sqlite3 {} ".dump {}"'.format(database_file, 'uniqsettings')) uniq_setting.id = 1 uniq_setting.save() print('dumping UniqSettings:') os.system('sqlite3 {} ".dump {}"'.format(database_file, 'uniqsettings')) if __name__ == '__main__': main() ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1057/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1057/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1056
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1056/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1056/comments
https://api.github.com/repos/coleifer/peewee/issues/1056/events
https://github.com/coleifer/peewee/issues/1056
174,821,368
MDU6SXNzdWUxNzQ4MjEzNjg=
1,056
Set PIPES_AS_CONCAT in MySQL sessions
{ "login": "jakedt", "id": 2183986, "node_id": "MDQ6VXNlcjIxODM5ODY=", "avatar_url": "https://avatars.githubusercontent.com/u/2183986?v=4", "gravatar_id": "", "url": "https://api.github.com/users/jakedt", "html_url": "https://github.com/jakedt", "followers_url": "https://api.github.com/users/jakedt/followers", "following_url": "https://api.github.com/users/jakedt/following{/other_user}", "gists_url": "https://api.github.com/users/jakedt/gists{/gist_id}", "starred_url": "https://api.github.com/users/jakedt/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/jakedt/subscriptions", "organizations_url": "https://api.github.com/users/jakedt/orgs", "repos_url": "https://api.github.com/users/jakedt/repos", "events_url": "https://api.github.com/users/jakedt/events{/privacy}", "received_events_url": "https://api.github.com/users/jakedt/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "For MySQL, I suppose that you will just need to use `fn.CONCAT('string 1', 'string 2', etc)` instead of `Model.some_field.concat()`. Is that reasonable, or do you think that the `concat()` function needs to be a bit smarter?\n", "Due to the design of the `QueryCompiler`, making the parser switch from an expression to a function call, in the event we're dealing with a concat on MySQL, requires some very ugly hacks.\n", "I just set up a proxy to switch between the two when I initialize the database connection. It's a fine workaround (the same as what we do for the random function across drivers) but I wish it were a little more seamless.\n" ]
2016-09-02T18:30:15
2016-09-03T15:36:48
2016-09-03T15:36:48
NONE
null
Default `||` behavior in MySQL is to treat it as logical or. The `.concat` operator in peewee always uses `||`, so for concat to work in MySQL the session must be set to use `PIPES_AS_CONCAT`.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1056/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1056/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1055
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1055/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1055/comments
https://api.github.com/repos/coleifer/peewee/issues/1055/events
https://github.com/coleifer/peewee/issues/1055
174,773,049
MDU6SXNzdWUxNzQ3NzMwNDk=
1,055
Syntax error in query
{ "login": "kennedyshead", "id": 203370, "node_id": "MDQ6VXNlcjIwMzM3MA==", "avatar_url": "https://avatars.githubusercontent.com/u/203370?v=4", "gravatar_id": "", "url": "https://api.github.com/users/kennedyshead", "html_url": "https://github.com/kennedyshead", "followers_url": "https://api.github.com/users/kennedyshead/followers", "following_url": "https://api.github.com/users/kennedyshead/following{/other_user}", "gists_url": "https://api.github.com/users/kennedyshead/gists{/gist_id}", "starred_url": "https://api.github.com/users/kennedyshead/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/kennedyshead/subscriptions", "organizations_url": "https://api.github.com/users/kennedyshead/orgs", "repos_url": "https://api.github.com/users/kennedyshead/repos", "events_url": "https://api.github.com/users/kennedyshead/events{/privacy}", "received_events_url": "https://api.github.com/users/kennedyshead/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Looks like you're passing a tuple in to user id\n", "Hi!\n\nIts resolved, switched to get_or_create and then it told me it was a tuple and not an int as you stated.\n\nIt was just a misleading error ;)\n", "Thank you for your quick reply\n", "Sure thing, I think peewee could stand to get smarter about checking these types of errors, but then there will be an inevitable performance hit. So, trade-off.\n" ]
2016-09-02T14:28:57
2016-09-02T15:17:51
2016-09-02T15:03:30
NONE
null
Python2.7 ``` peewee[20118] DEBUG ('SELECT "t1"."id", "t1"."user_id", "t1"."unique", "t1"."title", "t1"."message", "t1"."created_date" FROM "event" AS t1 WHERE (((("t1"."message" = ?) AND ("t1"."unique" = ?)) AND ("t1"."user_id" = (?, ?))) AND ("t1"."title" = ?)) LIMIT 1 OFFSET 0', [u'Someone created a new project', u'97df91d41dc15590451eade6f1d16de1bb218d1e0d8a21aa2de295f1', 25, 0, u'Ruby']) Exception in thread Thread-2: Traceback (most recent call last): File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 801, in __bootstrap_inner self.run() File "/Users/magnusknutas/git/thefarm/app/services/mqtt_service.py", line 38, in run self.client.loop() File "/usr/local/lib/python2.7/site-packages/paho/mqtt/client.py", line 811, in loop rc = self.loop_read(max_packets) File "/usr/local/lib/python2.7/site-packages/paho/mqtt/client.py", line 1073, in loop_read rc = self._packet_read() File "/usr/local/lib/python2.7/site-packages/paho/mqtt/client.py", line 1475, in _packet_read rc = self._packet_handle() File "/usr/local/lib/python2.7/site-packages/paho/mqtt/client.py", line 1947, in _packet_handle return self._handle_pubrel() File "/usr/local/lib/python2.7/site-packages/paho/mqtt/client.py", line 2152, in _handle_pubrel self._handle_on_message(self._in_messages[i]) File "/usr/local/lib/python2.7/site-packages/paho/mqtt/client.py", line 2274, in _handle_on_message self.on_message(self, self._userdata, message) File "/Users/magnusknutas/git/thefarm/app/services/mqtt_service.py", line 84, in on_message message=text File "/usr/local/lib/python2.7/site-packages/peewee.py", line 4800, in get_or_create return query.get(), False File "/usr/local/lib/python2.7/site-packages/peewee.py", line 3090, in get return next(clone.execute()) File "/usr/local/lib/python2.7/site-packages/peewee.py", line 3142, in execute self._qr = ResultWrapper(model_class, self._execute(), query_meta) File "/usr/local/lib/python2.7/site-packages/peewee.py", line 2826, in _execute return self.database.execute_sql(sql, params, self.require_commit) File "/usr/local/lib/python2.7/site-packages/peewee.py", line 3683, in execute_sql self.commit() File "/usr/local/lib/python2.7/site-packages/peewee.py", line 3507, in __exit__ reraise(new_type, new_type(*exc_args), traceback) File "/usr/local/lib/python2.7/site-packages/peewee.py", line 3676, in execute_sql cursor.execute(sql, params or ()) OperationalError: near ",": syntax error ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1055/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1055/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1054
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1054/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1054/comments
https://api.github.com/repos/coleifer/peewee/issues/1054/events
https://github.com/coleifer/peewee/issues/1054
173,931,003
MDU6SXNzdWUxNzM5MzEwMDM=
1,054
Postgres extension's full text search Match raises KeyError 'T@@'
{ "login": "ephiepark", "id": 590764, "node_id": "MDQ6VXNlcjU5MDc2NA==", "avatar_url": "https://avatars.githubusercontent.com/u/590764?v=4", "gravatar_id": "", "url": "https://api.github.com/users/ephiepark", "html_url": "https://github.com/ephiepark", "followers_url": "https://api.github.com/users/ephiepark/followers", "following_url": "https://api.github.com/users/ephiepark/following{/other_user}", "gists_url": "https://api.github.com/users/ephiepark/gists{/gist_id}", "starred_url": "https://api.github.com/users/ephiepark/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/ephiepark/subscriptions", "organizations_url": "https://api.github.com/users/ephiepark/orgs", "repos_url": "https://api.github.com/users/ephiepark/repos", "events_url": "https://api.github.com/users/ephiepark/events{/privacy}", "received_events_url": "https://api.github.com/users/ephiepark/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "My guess is that you are not using the `PostgresqlExtDatabase` class, which is a subclass of `PostgresqlDatabase` class.\n\nHow are you defining your database?\n", "Thank you for the quick reply!\n\nYes, I think my application is using PostgresqlDatabase not PostgresqlExtDatabase. I am using FlaskDB class setup db connection, and during init_app() call in FlaskDB it reads from config DB url and it automatically instantiate PostgresqlDatabase by looking at the url. \n\nLooking at the playhouse.db_url module, it seems like there is no way to let FlaskDB to create PostgresqlExtDatabase instance. \n\nWhat should I do to make use of PostgresqlExtDatabase? \n\np.s. I have tried the following to force PostgresqlExtDatabase to be used \n`DATABASE = 'postgres://....db_url....'`\n `parsed = urlparse(DATABASE)`\n `connect_kwargs = parseresult_to_dict(parsed)`\n `flask_db = FlaskDB(database=PostgresqlExtDatabase(**connect_kwargs))`\nAnd I got the follow error\n`peewee.ProgrammingError: hstore type not found in the database. please install it from your 'contrib/hstore.sql' file`\n", "> Looking at the playhouse.db_url module, it seems like there is no way to let FlaskDB to create PostgresqlExtDatabase instance.\n\nThe docs show you how to use `db_url` to use the `PostgresqlExtDatabase`:\n\nhttp://docs.peewee-orm.com/en/latest/peewee/playhouse.html#db-url\n\nBy default the hstore extension is enabled, so you can do one of two things:\n1. Disable it\n2. Enable it in postgres\n\nTo disable, pass in `register_hstore=False` when either instantiating the database instance, or as a parameter of the db_url, e.g. `scheme://user:password@host:port/database_name?register_hstore=false`\n\nTo enable it in postgres, open up a postgres shell `psql my_database` and run the following SQL:\n\n``` sql\nCREATE EXTENSION hstore;\n```\n\nDepending on your system, you may need to install additional packages.\n" ]
2016-08-30T05:08:47
2016-08-30T13:46:30
2016-08-30T13:46:30
NONE
null
Hi, I am using peewee with flask and postgresql db, and I would like to use peewee's postgres extension to do full text search (http://docs.peewee-orm.com/en/latest/peewee/playhouse.html#TSVectorField). But when I use Match function from the link, it raises KeyError 'T@@'. I followed the stack trace, and the KeyError is raised in get_op() call in QueryCompiler class. When q, the parameter to get_op() call, equates to 'T@@', self._op_map does not have key 'T@@' and raises KeyError.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1054/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1054/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1053
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1053/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1053/comments
https://api.github.com/repos/coleifer/peewee/issues/1053/events
https://github.com/coleifer/peewee/issues/1053
173,536,220
MDU6SXNzdWUxNzM1MzYyMjA=
1,053
[improvement] Model Definition via JSON
{ "login": "rognoni", "id": 8401602, "node_id": "MDQ6VXNlcjg0MDE2MDI=", "avatar_url": "https://avatars.githubusercontent.com/u/8401602?v=4", "gravatar_id": "", "url": "https://api.github.com/users/rognoni", "html_url": "https://github.com/rognoni", "followers_url": "https://api.github.com/users/rognoni/followers", "following_url": "https://api.github.com/users/rognoni/following{/other_user}", "gists_url": "https://api.github.com/users/rognoni/gists{/gist_id}", "starred_url": "https://api.github.com/users/rognoni/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/rognoni/subscriptions", "organizations_url": "https://api.github.com/users/rognoni/orgs", "repos_url": "https://api.github.com/users/rognoni/repos", "events_url": "https://api.github.com/users/rognoni/events{/privacy}", "received_events_url": "https://api.github.com/users/rognoni/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Ummmm, huh? http://thedailywtf.com/articles/the-inner-json-effect\n\nI'm not going to add anything like this to peewee. It can't be more than 50-60 lines of code to do what you're trying to do.\n\nBesides the familiar declarative syntax, Peewee can introspect an existing database, modify the schema on-the-fly, and provides extensions like [playhouse.dataset](http://docs.peewee-orm.com/en/latest/peewee/playhouse.html#dataset) and apps like [my web-based sqlite manager](https://github.com/coleifer/sqlite-web/).\n" ]
2016-08-26T20:23:59
2016-08-27T07:31:00
2016-08-27T07:31:00
NONE
null
For my project I need the **Model Definition** via JSON, for example: https://github.com/rognoni/adaptable/blob/master/Backend/resources/schemas/info.json ``` javascript { "entities": { "group": { "properties": { "id": {"type": "int", "isPK": true}, "desc": {"type": "str"}, "name": {"type": "str", "isNull": false} } }, "group_user": { "properties": { "id": {"type": "int", "isPK": true}, "group_id": {"type": "ref", "entity": "group", "isNull": false}, "user_id": {"type": "ref", "entity": "user", "isNull": false} } }, "user": { "properties": { "id": {"type": "int", "isPK": true}, "key": {"type": "str", "isNull": false, "isUnique": true}, "password": {"type": "str", "isNull": false}, "username": {"type": "str", "isNull": false} } } } } ``` For the moment, to avoid source-code generation, I am using a dynamic way with `type(name, bases, dict)` https://github.com/rognoni/adaptable/blob/master/Backend/Python-Flask/storage/sqlalchemy_sqlite.py
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1053/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1053/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1052
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1052/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1052/comments
https://api.github.com/repos/coleifer/peewee/issues/1052/events
https://github.com/coleifer/peewee/issues/1052
173,515,772
MDU6SXNzdWUxNzM1MTU3NzI=
1,052
Materialized views?
{ "login": "Resisty", "id": 5331616, "node_id": "MDQ6VXNlcjUzMzE2MTY=", "avatar_url": "https://avatars.githubusercontent.com/u/5331616?v=4", "gravatar_id": "", "url": "https://api.github.com/users/Resisty", "html_url": "https://github.com/Resisty", "followers_url": "https://api.github.com/users/Resisty/followers", "following_url": "https://api.github.com/users/Resisty/following{/other_user}", "gists_url": "https://api.github.com/users/Resisty/gists{/gist_id}", "starred_url": "https://api.github.com/users/Resisty/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/Resisty/subscriptions", "organizations_url": "https://api.github.com/users/Resisty/orgs", "repos_url": "https://api.github.com/users/Resisty/repos", "events_url": "https://api.github.com/users/Resisty/events{/privacy}", "received_events_url": "https://api.github.com/users/Resisty/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Peewee does not generate the DDL for the creation of views, but you can certainly create a model for your view and query it normally. So, the answer is yes and no. Does that answer your question?\n", "I think so. The advice I got from a friend (who doesn't speak Python but only sql) was that having a materialized view would be good so I could have an index instead of, say, running a count across every table in the query every time. As long as I know I have to do it that way, I'm good to go. Thanks!\n", "You could also denormalize, and add the count as a column directly on the table. Might save you some disk space if your materialized view is large, and you can ensure the counts stay up-to-date using simple triggers. Just a thought.\n" ]
2016-08-26T18:34:24
2016-08-27T07:23:46
2016-08-26T20:35:08
NONE
null
Hello, I was just trying to figure out, definitively, if Peewee supports the notion of [materialized views](https://www.postgresql.org/docs/9.3/static/sql-creatematerializedview.html). If so, any tips would be great, but if not, it's just good to know. Thanks!
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1052/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1052/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1051
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1051/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1051/comments
https://api.github.com/repos/coleifer/peewee/issues/1051/events
https://github.com/coleifer/peewee/issues/1051
173,229,961
MDU6SXNzdWUxNzMyMjk5NjE=
1,051
Peewee 2.8.2 regression
{ "login": "mrjoes", "id": 179880, "node_id": "MDQ6VXNlcjE3OTg4MA==", "avatar_url": "https://avatars.githubusercontent.com/u/179880?v=4", "gravatar_id": "", "url": "https://api.github.com/users/mrjoes", "html_url": "https://github.com/mrjoes", "followers_url": "https://api.github.com/users/mrjoes/followers", "following_url": "https://api.github.com/users/mrjoes/following{/other_user}", "gists_url": "https://api.github.com/users/mrjoes/gists{/gist_id}", "starred_url": "https://api.github.com/users/mrjoes/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/mrjoes/subscriptions", "organizations_url": "https://api.github.com/users/mrjoes/orgs", "repos_url": "https://api.github.com/users/mrjoes/repos", "events_url": "https://api.github.com/users/mrjoes/events{/privacy}", "received_events_url": "https://api.github.com/users/mrjoes/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Please ignore - it was already fixed in the master. Thanks!\n", "Can you point me to the commit that fixed this issue? I want to be sure I understand what happened.\n", "I don't know - I installed peewee from the master and it worked, all of a sudden.\n\nEdit: More info\n\n`pip install -e git+https://github.com/coleifer/peewee#egg=peewee` works\n`pip install peewee==2.8.1` works\n`pip install peewee==2.8.2` does not work\n", "Just makes me nervous since that traceback doesn't really ring any bells.\n", "The traceback is internal to flask-admin tests. \n\nHere's the issue:\n\n``` python\ndef test_fn():\n class BaseModel(peewee.Model):\n class Meta:\n database = db\n\n class Model(BaseModel):\n test = peewee.CharField(null=False)\n\n Model.create_table()\n```\n\nproduced this:\n\n``` sql\nCREATE TABLE \"basemodel\" (\"id\" INTEGER NOT NULL PRIMARY KEY)\n```\n\nFor whatever the reason - it ignored the `test` column in the model definition. wtf-peewee didn't generate the field and test crashed with:\n\n```\nAttributeError: 'ModelForm' object has no attribute 'test'\n```\n" ]
2016-08-25T15:10:27
2016-08-25T17:54:05
2016-08-25T15:11:26
NONE
null
Long story short - something in 2.8.2 is causing problem for one of the Flask-Admin tests. Here's the test: https://github.com/flask-admin/flask-admin/blob/master/flask_admin/tests/peeweemodel/test_basic.py#L918 Here's the traceback: ``` ERROR: flask_admin.tests.peeweemodel.test_basic.test_form_args ---------------------------------------------------------------------- Traceback (most recent call last): File "/Users/joes/Work/flask-admin/lib/python2.7/site-packages/nose/case.py", line 197, in runTest self.test(*self.arg) File "/Users/joes/Work/flask-admin/flask-admin/flask_admin/tests/peeweemodel/test_basic.py", line 938, in test_form_args eq_(len(create_form.test.validators), 2) AttributeError: 'ModelForm' object has no attribute 'test' -------------------- >> begin captured logging << -------------------- peewee: DEBUG: ('CREATE TABLE "basemodel" ("id" INTEGER NOT NULL PRIMARY KEY)', []) --------------------- >> end captured logging << --------------------- ``` Basically, `test` is not registering as a column for whatever reason.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1051/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1051/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1050
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1050/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1050/comments
https://api.github.com/repos/coleifer/peewee/issues/1050/events
https://github.com/coleifer/peewee/issues/1050
172,940,679
MDU6SXNzdWUxNzI5NDA2Nzk=
1,050
Why is foreign object's key always accessible as *_id?
{ "login": "maaaks", "id": 3010238, "node_id": "MDQ6VXNlcjMwMTAyMzg=", "avatar_url": "https://avatars.githubusercontent.com/u/3010238?v=4", "gravatar_id": "", "url": "https://api.github.com/users/maaaks", "html_url": "https://github.com/maaaks", "followers_url": "https://api.github.com/users/maaaks/followers", "following_url": "https://api.github.com/users/maaaks/following{/other_user}", "gists_url": "https://api.github.com/users/maaaks/gists{/gist_id}", "starred_url": "https://api.github.com/users/maaaks/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/maaaks/subscriptions", "organizations_url": "https://api.github.com/users/maaaks/orgs", "repos_url": "https://api.github.com/users/maaaks/repos", "events_url": "https://api.github.com/users/maaaks/events{/privacy}", "received_events_url": "https://api.github.com/users/maaaks/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I understand your concerns. When the foreign key's field name is equal to it's db_column, I suppose it would be fine to fall back to just appending \"_id\" -- otherwise the db_column could be used. It's important to have this ID descriptor, as it provides a way to access the foreign key data without forcing resolution of the foreign key.\n\nWould you consider the best fix, then, to use the db_column for the foreign key's ID descriptor except when it is the same as the field name (in which case append \"_id\")?\n", "Yes, I just didn't think of the case without any postfix in column name. In my DB, there is always a postfix, it's just different: `_id` or `_guid`.\n\nSo yes, «use `db_column` if provided and differs from name, else use `name+\"_id\"`» seems to be the correct way to fix it, as far as I understand it all.\n", "+1\n" ]
2016-08-24T12:39:17
2016-08-25T07:48:33
2016-08-25T07:48:33
CONTRIBUTOR
null
In the ForeignKeyField source code, I see this: ``` python obj_id_name = name + '_id' ... setattr(model_class, obj_id_name, self._get_id_descriptor()) ``` This means that no matter what field is foreign key in, the ID of the object is always accessible as user_id, parent_id, etc. Even if the real column name, the `db_column`, is not *_id at all. I noticed this because I made a `ForeignUuidField` for my projects. It is based on the standard `ForeignKeyField` but instead of integer `*_id` uses field `*_guid`. But, surprisingly, Peewee still creates field `*_id` with the GUID that I need to load foreign object. I think the `obj_id_name` from the code above should be equal to `db_column`, at least for this particular situation. (And I think that there is no other possible situations to hardcode it that way, except for default behaviour when `db_column` is not defined by user.)
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1050/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1050/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1049
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1049/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1049/comments
https://api.github.com/repos/coleifer/peewee/issues/1049/events
https://github.com/coleifer/peewee/pull/1049
172,773,750
MDExOlB1bGxSZXF1ZXN0ODI0MTc2ODA=
1,049
Update apsw URL
{ "login": "jberkel", "id": 18891, "node_id": "MDQ6VXNlcjE4ODkx", "avatar_url": "https://avatars.githubusercontent.com/u/18891?v=4", "gravatar_id": "", "url": "https://api.github.com/users/jberkel", "html_url": "https://github.com/jberkel", "followers_url": "https://api.github.com/users/jberkel/followers", "following_url": "https://api.github.com/users/jberkel/following{/other_user}", "gists_url": "https://api.github.com/users/jberkel/gists{/gist_id}", "starred_url": "https://api.github.com/users/jberkel/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/jberkel/subscriptions", "organizations_url": "https://api.github.com/users/jberkel/orgs", "repos_url": "https://api.github.com/users/jberkel/repos", "events_url": "https://api.github.com/users/jberkel/events{/privacy}", "received_events_url": "https://api.github.com/users/jberkel/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[]
2016-08-23T18:36:02
2016-08-23T19:32:36
2016-08-23T19:32:36
CONTRIBUTOR
null
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1049/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1049/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/1049", "html_url": "https://github.com/coleifer/peewee/pull/1049", "diff_url": "https://github.com/coleifer/peewee/pull/1049.diff", "patch_url": "https://github.com/coleifer/peewee/pull/1049.patch", "merged_at": "2016-08-23T19:32:36" }
https://api.github.com/repos/coleifer/peewee/issues/1048
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1048/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1048/comments
https://api.github.com/repos/coleifer/peewee/issues/1048/events
https://github.com/coleifer/peewee/issues/1048
172,707,045
MDU6SXNzdWUxNzI3MDcwNDU=
1,048
Default value weird behavior
{ "login": "staier", "id": 1745233, "node_id": "MDQ6VXNlcjE3NDUyMzM=", "avatar_url": "https://avatars.githubusercontent.com/u/1745233?v=4", "gravatar_id": "", "url": "https://api.github.com/users/staier", "html_url": "https://github.com/staier", "followers_url": "https://api.github.com/users/staier/followers", "following_url": "https://api.github.com/users/staier/following{/other_user}", "gists_url": "https://api.github.com/users/staier/gists{/gist_id}", "starred_url": "https://api.github.com/users/staier/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/staier/subscriptions", "organizations_url": "https://api.github.com/users/staier/orgs", "repos_url": "https://api.github.com/users/staier/repos", "events_url": "https://api.github.com/users/staier/events{/privacy}", "received_events_url": "https://api.github.com/users/staier/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "update:\nsetting \n\n```\n class Meta:\n only_save_dirty = False\n```\n\nFixed the issue , however i do not believe this is a good solution.\nOne more thing i noticed , default values functions calculated every time an object gets populated from database regardless of if it was set already to default value or otherwise.\n\nThis may get expensive quickly\n", "Can you tell me what version you were using previously?\n", "I think I know -- in `Model._prepare_instance` it's clearing the dirty fields a bit too aggressively.\n", "It was 2.6.4.\n", "That's quite a big jump... I was wondering if e28b6e4529176a1dff6b2b6e247658ccab5bcbb4 was the issue but I'm guessing the fact that defaults are excluded from dirty fields on population is the real issue.\n", "I believe I have a fix pushed, just going to let the tests run.\n", "Fixed in c17d3db\n", "Please note , that with IntegerField(default=incrementer()) default only executes once , but if IntegerField(default=incrementer) it will be callable and treated differently . Not sure if it matters .\n", "It's still considered a callable because the return value is a function.\n" ]
2016-08-23T14:00:24
2016-08-23T16:03:18
2016-08-23T15:37:14
NONE
null
After last upgrade something went very wrong . ``` class SomeModel(BaseModel): value=IntegerField() hash= FixedCharFiled(default=utils.some_hash_func) object= SomeModel(value=3) object.save() object2= SomeModel.get(SomeModel.id==object.id) ``` **object1.hash ==object2.hash** returns **False** it looks like field populated with one default value , but insert statement is prepared with another call to default function, even though the value was already generated. this ruined my application completely.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1048/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1048/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1047
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1047/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1047/comments
https://api.github.com/repos/coleifer/peewee/issues/1047/events
https://github.com/coleifer/peewee/issues/1047
172,552,470
MDU6SXNzdWUxNzI1NTI0NzA=
1,047
Document TimestampField
{ "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
[]
2016-08-22T20:55:09
2016-08-23T14:33:45
2016-08-23T14:33:45
OWNER
null
eom
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1047/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1047/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1046
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1046/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1046/comments
https://api.github.com/repos/coleifer/peewee/issues/1046/events
https://github.com/coleifer/peewee/issues/1046
172,166,430
MDU6SXNzdWUxNzIxNjY0MzA=
1,046
Subquery referencing outer table query
{ "login": "jberkel", "id": 18891, "node_id": "MDQ6VXNlcjE4ODkx", "avatar_url": "https://avatars.githubusercontent.com/u/18891?v=4", "gravatar_id": "", "url": "https://api.github.com/users/jberkel", "html_url": "https://github.com/jberkel", "followers_url": "https://api.github.com/users/jberkel/followers", "following_url": "https://api.github.com/users/jberkel/following{/other_user}", "gists_url": "https://api.github.com/users/jberkel/gists{/gist_id}", "starred_url": "https://api.github.com/users/jberkel/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/jberkel/subscriptions", "organizations_url": "https://api.github.com/users/jberkel/orgs", "repos_url": "https://api.github.com/users/jberkel/repos", "events_url": "https://api.github.com/users/jberkel/events{/privacy}", "received_events_url": "https://api.github.com/users/jberkel/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "What have you tried? Can you share a bit of Python code to give me a better idea what you're trying to do?\n", "Alright, while retrying the whole thing I actually got it to work as expected, nevermind! \nNot sure what I did differently this time.\n\nThis is the model:\n\n``` python\nclass Foo(Model):\n\nclass Bar(Model):\n foo = ForeignKeyField(Foo)\n\nclass Category(Model):\n text = TextField()\n\nclass BarCategoryLink(Model): \n bar = ForeignKeyField(Bar)\n category = ForeignKeyField(Category)\n```\n\nNow I want to enumerate all foos together with a count of specific category links all their (child) bars have:\n\nThe raw query I want to generate looks like this:\n\n``` sql\n SELECT foo.id, (SELECT count(bar_category_links.id) \n FROM bar_category_links\n INNER JOIN bar ON bar.foo_id = foo.id\n AND bar.id = bar_category_links.bar_id\n INNER JOIN categories ON\n categories.id = bar_category_links.category_id\n AND categories.text = ?)\n```\n\nNotice that the subquery refers to foo.id, defined in the outer query.\n\nI tried the following:\n\n``` python\nsub_query = lambda foo: BarCategoryLink.select(fn.Count(BarCategoryLink.id))\n .join(Bar, on= (BarCategoryLink.bar == Bar.id) & (Bar.foo == foo))\n .join(Category, on= (BarCategoryLink.category == Category.id) & (Category.text == ?))\n\nquery = Foo.select(Foo.id, sub_query(Foo.id).alias('count'))\n```\n\nMy problem previously was that the `Bar.foo == foo` condition in the subquery had the wrong table alias and therefore did not execute. I think I assigned the subquery to a variable first, like this:\n\n``` python\nsub_q = sub_query(Foo.id)\nquery = Foo.select(Foo.id, sub_q.alias('count'))\n```\n\nLooks like aliases are assigned in order of definition / execution?\n", "I had a feeling that if you tried it you'd notice that it _just worked_.\n\nI'd like to point out that you do not need to make a lambda to simply pass in \"Foo.id\". Just use `Foo.id` directly in the subquery:\n\n``` python\nsubq = (BarCategory\n .select(fn.COUNT(BarCategory.id))\n .join(Bar, on=(\n (Bar.foo == Foo.id) & \n (Bar.id == BarCategory.bar)))\n .switch(BarCategory)\n .join(Category, on=(\n (Category.id == BarCategory.category) &\n (Category.text == 'whatever'))))\nquery = Foo.select(Foo.id, subq.alias('ct'))\n```\n\nThe generated SQL appears about right:\n\n``` sql\nSELECT \"t1\".\"id\", (\n SELECT COUNT(\"t2\".\"id\") \n FROM \"barcategory\" AS t2 \n INNER JOIN \"bar\" AS t3 ON ((\"t3\".\"foo_id\" = \"t1\".\"id\") AND (\"t3\".\"id\" = \"t2\".\"bar_id\")) \n INNER JOIN \"category\" AS t4 ON ((\"t4\".\"id\" = \"t2\".\"category_id\") AND (\"t4\".\"text\" = ?))\n) AS ct FROM \"foo\" AS t1\n```\n\nThe aliases are defined in the order the Python interpreter parses the expressions.\n", "I might be totally missing something important here, but could you write this query as:\n\n``` python\n(Foo\n .select(Foo.id, fn.COUNT(BarCategory.id))\n .join(Bar, JOIN.LEFT_OUTER)\n .join(BarCategory)\n .join(Category)\n .where(Category.text == 'whatever')\n .group_by(Foo.id))\n```\n\nSimilarly, to break down the counts of Bars-per-Category for each Foo, you can write:\n\n``` python\n(Foo\n .select(Foo.id, Category.text, fn.COUNT(BarCategory.id))\n .join(Bar, JOIN.LEFT_OUTER)\n .join(BarCategory)\n .join(Category)\n .where(Category.text == 'whatever')\n .group_by(Foo.id, Category.text))\n```\n", "Thanks for your helpful explanations! Yes, I had initially started with a similar `LEFT JOIN` + `GROUP BY` but I actually need to count more than just one category, and the query got complicated very quickly (several joins + aliases), that's why I decided to move it into a subquery. \n\nI'll try your suggestion though. Maybe a simple `.where(Category.text << ['category_a', 'category_b' ])` would just work.\n" ]
2016-08-19T16:10:42
2016-08-24T09:09:27
2016-08-24T04:07:54
CONTRIBUTOR
null
Not sure if this is possible with peewee, but how would I construct a query like the following with peewee: ``` sql SELECT outer_table.id, outer_table.bar, (SELECT .... FROM inner_table JOIN ... = outer_table.id ) FROM outer_table ``` All the examples I've found use subqueries which are joined to the outer query. I want to to it the other way around.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1046/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1046/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1045
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1045/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1045/comments
https://api.github.com/repos/coleifer/peewee/issues/1045/events
https://github.com/coleifer/peewee/issues/1045
171,995,861
MDU6SXNzdWUxNzE5OTU4NjE=
1,045
column names are stripped their '_id' part
{ "login": "maxdml", "id": 3437048, "node_id": "MDQ6VXNlcjM0MzcwNDg=", "avatar_url": "https://avatars.githubusercontent.com/u/3437048?v=4", "gravatar_id": "", "url": "https://api.github.com/users/maxdml", "html_url": "https://github.com/maxdml", "followers_url": "https://api.github.com/users/maxdml/followers", "following_url": "https://api.github.com/users/maxdml/following{/other_user}", "gists_url": "https://api.github.com/users/maxdml/gists{/gist_id}", "starred_url": "https://api.github.com/users/maxdml/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/maxdml/subscriptions", "organizations_url": "https://api.github.com/users/maxdml/orgs", "repos_url": "https://api.github.com/users/maxdml/repos", "events_url": "https://api.github.com/users/maxdml/events{/privacy}", "received_events_url": "https://api.github.com/users/maxdml/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "After having a look at the code, I found the responsible function, in reflection.py:\n\n```\n425 def make_column_name(self, column):\n426 column = re.sub('_id$', '', column.lower().strip()) or column.lower() \n427 column = re.sub('[^\\w]+', '_', column)\n428 if column in RESERVED_WORDS:\n429 column += '_'\n430 return column\n```\n\nAny reason why '_id' would be removed? Would it be still safe to have it replace such a string by '-id' ?\n", "It is removed because generally \"_id\" is database schema cruft, i.e. an indication that the column is a foreign key or something similar.\n", "Well I actually use it to name foreign keys =) As far as I know, and at least for MySQL, the engine makes no assumption about how FK are named.\n", "Is there any way to keep \"_id\" exist?", "You can name your fields whatever you want, just specify the actual column name using the `column_name` parameter:\r\n\r\n```python\r\n\r\nclass MyModel(Model):\r\n some_field = TextField(column_name='actual_column_name')\r\n another_field = IntegerField(column_name='another_field_id')\r\n```", "Nevertheless, any way to keep '_id' part? I have 150+ tables in db, I don't want to put back all removed '_id's manually. Can it be fixed without changing sources?", "Just to be clear -- the \"_id\" bit is only stripped from foreign-key fields.\r\n\r\nPeewee exposes foreign-keys as model instances.\r\n\r\nHere are some sample models:\r\n\r\n```python\r\nclass User(Model):\r\n username = TextField()\r\n class Meta:\r\n table_name = 'users' # Some databases do not like table named \"user\".\r\n\r\nclass Tweet(Model):\r\n user = ForeignKeyField(User, backref='tweets')\r\n content = TextField()\r\n timestamp = TimestampField()\r\n```\r\n\r\nThe corresponding database schema would look something like:\r\n\r\n```sql\r\ncreate table \"users\" (\"id\" integer not null primary key, \"username\" text not null);\r\ncreate table \"tweet\" (\r\n \"id\" integer not null primary key,\r\n \"user_id\" integer not null,\r\n \"content\" text not null,\r\n \"timestamp\" integer not null,\r\n foreign key (\"user_id\") references \"users\" (\"id\"))\r\n```\r\n\r\nWhen interacting with our models in Python, it makes sense to call the tweet.user_id foreign key \"tweet.user\" since it is exposed as a user instance:\r\n\r\n```python\r\n# Get 20 most recent tweets and also load the associated user.\r\ntweets = Tweet.select(Tweet, User).join(User).order_by(Tweet.timestamp.desc()).limit(20)\r\nfor tweet in tweets:\r\n print(tweet.user.username, '->', tweet.content)\r\n```\r\n\r\nPeewee also does a nice thing with foreign-keys where the actual underlying column-value (in this case the related user's id) is exposed using a special descriptor:\r\n\r\n```python\r\nquery = Tweet.select().join(User).order_by(Tweet.timestamp.desc()).limit(20)\r\nfor tweet in query:\r\n print(tweet.user_id, '->', tweet.content) # Print's the user's ID and the tweet content.\r\n```\r\n\r\nIf the field were named \"user_id\" instead, my own opinion is that is would be confusing. Consider:\r\n\r\n```python\r\nclass Tweet(Model):\r\n user_id = ForeignKeyField(User, column_name='user_id', backref='tweets')\r\n ...\r\n\r\nquery = Tweet.select(Tweet, User).join(User).order_by(Tweet.timestamp.desc()).limit(20)\r\nfor tweet in query:\r\n print(tweet.user_id.username, '->', tweet.content) # Here the related user instance is called user_id?\r\n\r\nquery = Tweet.select().join(User).order_by(Tweet.timestamp.desc()).limit(20)\r\nfor tweet in query:\r\n print(tweet.user_id_id, '->', tweet.content) # And the ID descriptor is called \"user_id_id\" :/\r\n```\r\n\r\nSo by default, that is why pwiz strips the \"_id\" off of foreign-keys when generating models. Of course you are encouraged to edit the generated code, however.", "Well, yes, I see, thanks for the explanation.\r\nBut I encountered an interesting behaviour. I'm developing a script for a XenForo-based forum, so I used pwiz to generate a model based on mysql schema. On my local machine it worked as expected: the script stipped out all \"_id\" parts. But when pwiz was launched on a client's machine, all \"_id\"s were preserved. So I thought, there is some option that can manipulate script's behaviour", "Probably their pre-existing database schema was missing the foreign key constraints. Cuz the story with referential integrity and MySQL...", "Yes, maybe, by the way. XenForo uses an interesting schema without (in some versions, as far as I know) foreign keys.\r\nThank you.", "The MyISAM storage engine, default before 5.5.5, does not handle fk constraints.", "I don't think that this is the problem, but I'll check it. Thanks again" ]
2016-08-18T20:41:52
2019-04-22T14:29:32
2016-08-23T15:39:05
NONE
null
It seems that when a column is named, say "table_id", the generated models is always "table". Command used: python -m pwiz -e mysql -u root database >> models.py edit: I observe the same behavior with names such as "app-id" e.g.: sql schema: DROP TABLE IF EXISTS `Application`; /_!40101 SET @saved_cs_client = @@character_set_client */; /_!40101 SET character_set_client = utf8 _/; CREATE TABLE `Application` ( `id` int(11) NOT NULL AUTO_INCREMENT, `app_id` char(100) NOT NULL, `app_name` char(100) NOT NULL, `app_env` text, `app_submit` text NOT NULL, `app_dag` text, `app_master` char(100) NOT NULL, `app_driver` int(11) DEFAULT NULL, PRIMARY KEY (`id`), KEY `app_driver` (`app_driver`), CONSTRAINT `Application_ibfk_1` FOREIGN KEY (`app_driver`) REFERENCES `Container` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; /_!40101 SET character_set_client = @saved_cs_client */; class Application(BaseModel): app_dag = TextField(null=True) app_driver = ForeignKeyField(db_column='app_driver', null=True, rel_model=Container, to_field='id') app_env = TextField(null=True) **app = CharField(db_column='app_id')** app_master = CharField() app_name = CharField() app_submit = TextField()
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1045/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1045/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1044
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1044/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1044/comments
https://api.github.com/repos/coleifer/peewee/issues/1044/events
https://github.com/coleifer/peewee/issues/1044
171,994,467
MDU6SXNzdWUxNzE5OTQ0Njc=
1,044
Peewee should not import all DB drivers unconditionally
{ "login": "Necoro", "id": 68708, "node_id": "MDQ6VXNlcjY4NzA4", "avatar_url": "https://avatars.githubusercontent.com/u/68708?v=4", "gravatar_id": "", "url": "https://api.github.com/users/Necoro", "html_url": "https://github.com/Necoro", "followers_url": "https://api.github.com/users/Necoro/followers", "following_url": "https://api.github.com/users/Necoro/following{/other_user}", "gists_url": "https://api.github.com/users/Necoro/gists{/gist_id}", "starred_url": "https://api.github.com/users/Necoro/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/Necoro/subscriptions", "organizations_url": "https://api.github.com/users/Necoro/orgs", "repos_url": "https://api.github.com/users/Necoro/repos", "events_url": "https://api.github.com/users/Necoro/events{/privacy}", "received_events_url": "https://api.github.com/users/Necoro/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "> When using some driver from the playground you even get one more.\n\nWhat do you mean?\n\nI hear your concerns, but I'm not convinced the fix is necessary.\n", "For instance, when using apsw or sqlcipher, you have the apsw/sqlcipher driver loaded additonally to the (if you are unlucky) 3 others, even though you don't need them at all.\n\nThough the case even gets more complicated here, as apsw and sqlcipher both explicitly pull in sqlite_ext, which might take more work to get 'clean' and thus is not part of my original request.\n\nMy concern stem from the fact, that I intend to write a CLI application using peewee: loading completely unneeded modules just increases startup time, which is a nuisance for CLIs :)\n", "Can you provide a measure of the amount of time saved by not loading, since that's your concern?\n", "Ok, you win :). I must admit, I hadn't timed it before (it was more of a 'heh - this is superfluous' moment):\npython -c 'from peewee import *'\nun-scientifically times to\n- 0.1s with sqlite only\n- 0.16s with pymysql\n- 0.16s with pymysql + psycopg2\n\nBut the times have to be taken with a grain of salt, as the variance is large (from 0.09 to 0.15s for plain sqlite only). Also, so it turns out, using python2 actually halves the times... well...\n\nSo, you may close this issue.\n", "Believe me, this project is called peewee because I want it to be as small and simple as possible while being useful. When it comes to pythons import system, module caching, dynamic linking, etc, I think I see that as a boundary beyond which python is probably going to fight attempts to optimize. Part of the issue, too, has to do with peewee being a single module. If there were specific modules for the supported backends this wouldn't be an issue, because you'd just import peewees sqlite backends, etc, but I also made a decision to try and keep peewee as a single module.\n", "I have a desktop app that often dynamically reloads data with each change in the search string, a live search. Using python -m pyinstrument …, I notice that peewee takes .105 seconds to load. 0.032 s. for psycopg2 (which I use) and .029 s. for pymysql, That's about 1/3 of loading time taken up by an unneeded driver. Moving it to the beginning of the MySQLDatabase class should cause it to load only when the class is instantiated, yes? For my case, any reduction of total execution time is noticable.", "As I wrote earlier:\r\n\r\n> When it comes to pythons import system, module caching, dynamic linking, etc, I think I see that as a boundary beyond which python is probably going to fight attempts to optimize.\r\n\r\nSome projects import a ton of different modules. Look at Django...how many modules do you think Django imports? Or SQLAlchemy? Peewee is already *very lean*.", "I understand peewee is already lean. It's not unprecedented to place imports within classes so they are performed only when a class is instantiated. Yes Django and SQLAlchemy are even heavier. When I started using Peewee years ago, I chose it because it is much lighter than other ORMs and offers great ease of use without being too complex. Many ORMs are often used for web apps where module load time is less important. In cases of desktop apps or scripts, when one wants to be as lightweight as possible, the loading of unneeded modules is noticable. Please consider it. For now I have modified the copy of Peewee I use and have noticed a dramatic difference in cases when I need to update a desktop UI and total execution time of less than half a second becomes noticible.", "Why don't you just lazily import `peewee` in your desktop app?", "My app constantly uses peewee. It's that the import loads modules for SQLite, mysql, and in my case postgresql. Each one comprises a significant amount of total import time. Sometimes I might perform multiple DB operations in one execution but most of the time, code is executed from the beginning and reloading all modules multiple times per second.", "I don't know why you are paying for the cost of loading Peewee more than once. Or why it would matter outside of the first time it is imported. ", "It's not that Peewee is loading more than once, it's that the entire script is running multiple times per second and thus Peewee is loading as such. My use is for an extension or plugin for a desktop search app. Unlike a true desktop app that might have an event loop, the entire script runs each time with user input, thus with each input, reducing any part of the execution time is greatly helpful. I'm not familiar with Python GUI frameworks, but perhaps in those uses, such a change might be helpful as well.", "So you're shelling out to a Python script on every keypress by a user. This Python script loads up your code, establishes a database connection, and runs some queries. And you have decided to waste both of our time talking about two or three import statements." ]
2016-08-18T20:34:55
2019-03-25T03:07:45
2016-08-23T22:31:43
CONTRIBUTOR
null
Peewee currently imports (or tries to import) all database drivers unconditionally. As a result, you load and link them even when not needed (if you happen to have them installed for any reason). When using some driver from the playground you even get one more. I'd suggest to only load them when needed (for instance as part of initializing the Database objects). If this is not turned down for conceptual reasons, I'd be happy to implement this and open a pull request :)
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1044/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1044/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1043
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1043/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1043/comments
https://api.github.com/repos/coleifer/peewee/issues/1043/events
https://github.com/coleifer/peewee/issues/1043
171,584,415
MDU6SXNzdWUxNzE1ODQ0MTU=
1,043
Entity is dirty after loading from DB (peewee==2.8.2)
{ "login": "tuukkamustonen", "id": 94327, "node_id": "MDQ6VXNlcjk0MzI3", "avatar_url": "https://avatars.githubusercontent.com/u/94327?v=4", "gravatar_id": "", "url": "https://api.github.com/users/tuukkamustonen", "html_url": "https://github.com/tuukkamustonen", "followers_url": "https://api.github.com/users/tuukkamustonen/followers", "following_url": "https://api.github.com/users/tuukkamustonen/following{/other_user}", "gists_url": "https://api.github.com/users/tuukkamustonen/gists{/gist_id}", "starred_url": "https://api.github.com/users/tuukkamustonen/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/tuukkamustonen/subscriptions", "organizations_url": "https://api.github.com/users/tuukkamustonen/orgs", "repos_url": "https://api.github.com/users/tuukkamustonen/repos", "events_url": "https://api.github.com/users/tuukkamustonen/events{/privacy}", "received_events_url": "https://api.github.com/users/tuukkamustonen/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I checked out 2.8.1 and was seeing that the instance from the db was dirty...nonetheless it looks like a bug.\n", "Weird, I tried again (in a clean virtualenv) and with peewee==2.8.1 `_dirty` is indeed an empty `set()`. Sounds a bit weird if the result is different in your sandbox.\n\nWell, thanks for the bugfix anyway.\n", "I did not update PyPI (that would entail pushing a new release, 2.8.2). If you point at master branch on github you should see the fix:\n\n```\npip install -e git+https://github.com/coleifer/peewee#egg=peewee\n```\n", "That doesn't play together with an in-house pypi (devpi) so I'll just wait for 2.8.3 as 2.8.1 works just fine for me.\n" ]
2016-08-17T06:31:38
2016-08-22T19:49:11
2016-08-17T20:33:29
NONE
null
``` python from peewee import Model, SqliteDatabase, CharField db = SqliteDatabase('test.db') class Foobar(Model): field = CharField() class Meta: database = db only_save_dirty = True db.connect() db.create_tables([Foobar]) obj1 = Foobar.create(field='foobar') foo = Foobar.get(id=obj1.id) print(foo._dirty) foo.save() # should do nothing but actually hits db because fields are marked dirty ``` Output: ``` {'id', 'field'} ``` With 2.8.1 `_dirty` is an empty set instead.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1043/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1043/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1042
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1042/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1042/comments
https://api.github.com/repos/coleifer/peewee/issues/1042/events
https://github.com/coleifer/peewee/issues/1042
171,570,874
MDU6SXNzdWUxNzE1NzA4NzQ=
1,042
GFKField with custom field names?
{ "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
[ "Unfortunately, the GFK field was never intended to interact with Rails. Perhaps you can add extra column(s) to the table to support the Peewee version of the data, or write a custom field that uses the names you need.\n", "I figured this was the case. Modifying the table is a great idea and probably the least work.\n\nThanks @coleifer ! \n" ]
2016-08-17T04:15:25
2016-08-17T15:48:28
2016-08-17T04:41:01
NONE
null
I have a legacy Rails database that I'm writing a peewee wrapper around. The Rails db uses a polymorphic/GFK for a "note". I'm trying to use peewee GFKs, but the SQL it's using to find a note is using the lowercase name of the table for the associated model, but the value in the db is the actual class name. For example, "Feature" is in the db resource_type column, but peewee is using a select query with "features". ``` SQL SELECT `t1`.`id`, `t1`.`value`, `t1`.`resource_id`, `t1`.`resource_type` FROM `notes` AS t1 WHERE ((`t1`.`resource_type` = %s) AND (`t1`.`resource_id` = %s)) ['features', 59] ``` Is there a way to customize this? Thanks
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1042/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1042/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1041
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1041/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1041/comments
https://api.github.com/repos/coleifer/peewee/issues/1041/events
https://github.com/coleifer/peewee/issues/1041
171,198,790
MDU6SXNzdWUxNzExOTg3OTA=
1,041
Peewee install is broken on PyPy
{ "login": "scitesy", "id": 45361, "node_id": "MDQ6VXNlcjQ1MzYx", "avatar_url": "https://avatars.githubusercontent.com/u/45361?v=4", "gravatar_id": "", "url": "https://api.github.com/users/scitesy", "html_url": "https://github.com/scitesy", "followers_url": "https://api.github.com/users/scitesy/followers", "following_url": "https://api.github.com/users/scitesy/following{/other_user}", "gists_url": "https://api.github.com/users/scitesy/gists{/gist_id}", "starred_url": "https://api.github.com/users/scitesy/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/scitesy/subscriptions", "organizations_url": "https://api.github.com/users/scitesy/orgs", "repos_url": "https://api.github.com/users/scitesy/repos", "events_url": "https://api.github.com/users/scitesy/events{/privacy}", "received_events_url": "https://api.github.com/users/scitesy/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Interesting. Do you have Cython installed alongside Peewee by chance? If not it's using the C source files bundled with Peewee, which appear not to be compatible.\n", "I've reverted a particular commit and pushed the changes to `master`... Do you mind trying them out?\n\nShould be:\n\n```\npip install -e git+https://github.com/coleifer/peewee.git#egg=peewee\n```\n", "Thank you. I'll try it again later tonight.\n", "That worked! To answer the question from earlier, I am running PyPy with no Cython installed.\nThe terminal output:\nObtaining peewee from git+https://github.com/coleifer/peewee.git#egg=peewee\n Cloning https://github.com/coleifer/peewee.git to ./test_pypy_peewee/src/peewee\nInstalling collected packages: peewee\n Running setup.py develop for peewee\nSuccessfully installed peewee\n\nThank you!\n", "I'll issue a new release to pypi later today.\n", "@coleifer When do you think this will be released? Thanks!\n" ]
2016-08-15T15:50:43
2016-08-25T08:50:32
2016-08-16T11:37:57
NONE
null
Ubuntu 16.04 PyPy pypy2-v5.3.1-linux64 Both pip install peewee and python setup.py install from a virtualenv fail with the following terminal output: https://gist.github.com/scitesy/550fa086870c7d90ae138b8f7e209e1c I believe it has been broken since sometime around July 14th.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1041/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1041/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1040
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1040/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1040/comments
https://api.github.com/repos/coleifer/peewee/issues/1040/events
https://github.com/coleifer/peewee/pull/1040
171,022,066
MDExOlB1bGxSZXF1ZXN0ODEyMjMyMTM=
1,040
Add pool option to db_url.connect
{ "login": "joeyespo", "id": 634573, "node_id": "MDQ6VXNlcjYzNDU3Mw==", "avatar_url": "https://avatars.githubusercontent.com/u/634573?v=4", "gravatar_id": "", "url": "https://api.github.com/users/joeyespo", "html_url": "https://github.com/joeyespo", "followers_url": "https://api.github.com/users/joeyespo/followers", "following_url": "https://api.github.com/users/joeyespo/following{/other_user}", "gists_url": "https://api.github.com/users/joeyespo/gists{/gist_id}", "starred_url": "https://api.github.com/users/joeyespo/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/joeyespo/subscriptions", "organizations_url": "https://api.github.com/users/joeyespo/orgs", "repos_url": "https://api.github.com/users/joeyespo/repos", "events_url": "https://api.github.com/users/joeyespo/events{/privacy}", "received_events_url": "https://api.github.com/users/joeyespo/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I will pass on this feature. The whole point of `db_url` is to allow you to specify things in the URL, and I don't see this as adding any particular value beyond what's already there.\n", "Ok.\n\nSeems odd that when URL comes from an external source, you have to manually inject the Peewee-specific '+pool' argument. Oh well. Thanks for the response.\n" ]
2016-08-13T18:48:31
2016-08-14T00:02:44
2016-08-13T23:48:36
CONTRIBUTOR
null
This separates the URL concern from the pooling concern. This is also backwards-compatible, so you can still use 'scheme+pool' if you want to hardcode the decision to use pooling right in your URL. This lets you write: ``` py db = db_url.connect(app.config['DATABASE_URL'], pool=True) ``` Now, for example, Heroku's raw `DATABASE_URL` can be used as-is _and_ have pooling enabled. I had this logic in my app, but it made sense to me to expose it to `db_url`. Note that you can also ensure pooling is disabled by specifying `pool=False`, which I included for completeness. If you think adding a new parameter is better (`def connect(url, pool=None, **connect_params):`), I'll change it to that. I just didn't want to break anybody. In the far future when Peewee drops Python 2 support, this can be accomplished with `def connect(url, *, pool=None, **connect_params):`.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1040/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1040/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/1040", "html_url": "https://github.com/coleifer/peewee/pull/1040", "diff_url": "https://github.com/coleifer/peewee/pull/1040.diff", "patch_url": "https://github.com/coleifer/peewee/pull/1040.patch", "merged_at": null }
https://api.github.com/repos/coleifer/peewee/issues/1039
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1039/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1039/comments
https://api.github.com/repos/coleifer/peewee/issues/1039/events
https://github.com/coleifer/peewee/issues/1039
170,985,032
MDU6SXNzdWUxNzA5ODUwMzI=
1,039
Documentation error
{ "login": "lyssdod", "id": 2615950, "node_id": "MDQ6VXNlcjI2MTU5NTA=", "avatar_url": "https://avatars.githubusercontent.com/u/2615950?v=4", "gravatar_id": "", "url": "https://api.github.com/users/lyssdod", "html_url": "https://github.com/lyssdod", "followers_url": "https://api.github.com/users/lyssdod/followers", "following_url": "https://api.github.com/users/lyssdod/following{/other_user}", "gists_url": "https://api.github.com/users/lyssdod/gists{/gist_id}", "starred_url": "https://api.github.com/users/lyssdod/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/lyssdod/subscriptions", "organizations_url": "https://api.github.com/users/lyssdod/orgs", "repos_url": "https://api.github.com/users/lyssdod/repos", "events_url": "https://api.github.com/users/lyssdod/events{/privacy}", "received_events_url": "https://api.github.com/users/lyssdod/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "You can specify them as a list or a tuple, so I will update the documentation to that effect.\n\nI'm guessing you ran into the error because you were only specifying one `PRAGMA` and forgot the trailing comma Python requires to differentiate simple parentheses from a tuple declaration.\n", "Exactly, I was specifying one `PRAGMA` and forgot the comma. Thanks!\n" ]
2016-08-13T01:01:25
2016-08-14T00:29:49
2016-08-13T23:52:33
NONE
null
http://docs.peewee-orm.com/en/latest/peewee/database.html?highlight=sqlite#pragma-statements Here it says "To run one or more PRAGMA statements against new connections, you can specify them as a list of 2-tuples... " but the code coming afterwards utilizes a tuple instead of list: ``` pragmas=( ('journal_mode', 'WAL'), ('cache_size', 10000), ('mmap_size', 1024 * 1024 * 32), ) ``` I've just experienced this myself, getting this error: ``` File "/usr/lib64/python2.7/site-packages/peewee.py", line 3627, in _set_pragmas for pragma, value in self._pragmas: ValueError: too many values to unpack ``` unless I tried to substitute `pragmas = (...)` to `pragmas = [...]`
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1039/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1039/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1038
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1038/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1038/comments
https://api.github.com/repos/coleifer/peewee/issues/1038/events
https://github.com/coleifer/peewee/issues/1038
170,905,783
MDU6SXNzdWUxNzA5MDU3ODM=
1,038
Use six library
{ "login": "thomdixon", "id": 461514, "node_id": "MDQ6VXNlcjQ2MTUxNA==", "avatar_url": "https://avatars.githubusercontent.com/u/461514?v=4", "gravatar_id": "", "url": "https://api.github.com/users/thomdixon", "html_url": "https://github.com/thomdixon", "followers_url": "https://api.github.com/users/thomdixon/followers", "following_url": "https://api.github.com/users/thomdixon/following{/other_user}", "gists_url": "https://api.github.com/users/thomdixon/gists{/gist_id}", "starred_url": "https://api.github.com/users/thomdixon/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/thomdixon/subscriptions", "organizations_url": "https://api.github.com/users/thomdixon/orgs", "repos_url": "https://api.github.com/users/thomdixon/repos", "events_url": "https://api.github.com/users/thomdixon/events{/privacy}", "received_events_url": "https://api.github.com/users/thomdixon/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "In my opinion, the `six` library is silly and I don't want to add a useless dependency.\n" ]
2016-08-12T16:09:23
2016-08-13T23:53:33
2016-08-13T23:53:33
NONE
null
You should use the wonderful [`six`](https://pythonhosted.org/six/) library, which would make a lot of [this](https://github.com/coleifer/peewee/blob/master/peewee.py#L118) unnecessary (especially the [`exec` for `reraise`](https://github.com/coleifer/peewee/blob/master/peewee.py#L143)).
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1038/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1038/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1037
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1037/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1037/comments
https://api.github.com/repos/coleifer/peewee/issues/1037/events
https://github.com/coleifer/peewee/issues/1037
170,824,661
MDU6SXNzdWUxNzA4MjQ2NjE=
1,037
FlaskDB and Model with signal support
{ "login": "ak4nv", "id": 73960, "node_id": "MDQ6VXNlcjczOTYw", "avatar_url": "https://avatars.githubusercontent.com/u/73960?v=4", "gravatar_id": "", "url": "https://api.github.com/users/ak4nv", "html_url": "https://github.com/ak4nv", "followers_url": "https://api.github.com/users/ak4nv/followers", "following_url": "https://api.github.com/users/ak4nv/following{/other_user}", "gists_url": "https://api.github.com/users/ak4nv/gists{/gist_id}", "starred_url": "https://api.github.com/users/ak4nv/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/ak4nv/subscriptions", "organizations_url": "https://api.github.com/users/ak4nv/orgs", "repos_url": "https://api.github.com/users/ak4nv/repos", "events_url": "https://api.github.com/users/ak4nv/events{/privacy}", "received_events_url": "https://api.github.com/users/ak4nv/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Just subclass `FlaskDB` and override the `get_model` method to use the `Model` subclass from the `signals` extension:\n\n``` python\nfrom playhouse.signals import Model as SignalModel\n\n\nclass SignalsFlaskDB(FlaskDB):\n def get_model_class(self):\n if self.database is None:\n raise RuntimeError('Database must be initialized.')\n\n class BaseModel(SignalModel):\n class Meta:\n database = self.database\n\n return BaseModel\n```\n\nVoila!\n" ]
2016-08-12T08:41:28
2016-08-13T23:56:09
2016-08-13T23:56:09
NONE
null
Now `BaseModel` [class based on](https://github.com/coleifer/peewee/blob/master/playhouse/flask_utils.py#L153) peewee.Model without signals
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1037/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1037/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1036
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1036/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1036/comments
https://api.github.com/repos/coleifer/peewee/issues/1036/events
https://github.com/coleifer/peewee/issues/1036
170,560,991
MDU6SXNzdWUxNzA1NjA5OTE=
1,036
peewee support multi process mode ?
{ "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
[ "Could you please be specific? What do you mean by \"dynamically\"? Honestly, please try to explain things so I can understand exactly what you're talking about, otherwise you are wasting both of our time.\n", "Database connections are not shared across multiple Python interpreter processes. Peewee, by default, uses thread-locals to manage connection state, so database connections are not even shared across threads (though you can disable this). Using the standard APIs, there will typically be one connection open per thread. If you want to explicitly create a second connection, you can use the \n\nHere are some relevant sections of documentation based on my best guess as to what you were asking:\n- http://docs.peewee-orm.com/en/latest/peewee/database.html#multi-threaded-applications\n- http://docs.peewee-orm.com/en/latest/peewee/database.html#advanced-connection-management\n- http://charlesleifer.com/blog/managing-database-connections-with-peewee/ (a blog post I wrote on connection management with peewee)\n\nTo quote from the second link:\n\n> In some situations, however, you may want to manage your connections more explicitly. Since peewee stores the active connection in a threadlocal, this typically would mean that there could only ever be one connection open per thread. For most applications this is desirable, but if you would like to manually manage multiple connections you can create an ExecutionContext.\n> \n> Execution contexts allow finer-grained control over managing multiple connections to the database. When an execution context is initialized (either as a context manager or as a decorated function), a separate connection will be used for the duration of the wrapped block. You can also choose whether to wrap the block in a transaction.\n\nIf none of this information helped answer your question, please comment with more information.\n" ]
2016-08-11T02:49:34
2016-08-11T07:59:15
2016-08-11T07:59:15
NONE
null
peewee support multi process mode ? How to create a connection dynamically?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1036/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1036/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1035
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1035/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1035/comments
https://api.github.com/repos/coleifer/peewee/issues/1035/events
https://github.com/coleifer/peewee/issues/1035
170,494,660
MDU6SXNzdWUxNzA0OTQ2NjA=
1,035
Can't create a table called `model` in PostgreSQL
{ "login": "bnaul", "id": 903655, "node_id": "MDQ6VXNlcjkwMzY1NQ==", "avatar_url": "https://avatars.githubusercontent.com/u/903655?v=4", "gravatar_id": "", "url": "https://api.github.com/users/bnaul", "html_url": "https://github.com/bnaul", "followers_url": "https://api.github.com/users/bnaul/followers", "following_url": "https://api.github.com/users/bnaul/following{/other_user}", "gists_url": "https://api.github.com/users/bnaul/gists{/gist_id}", "starred_url": "https://api.github.com/users/bnaul/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/bnaul/subscriptions", "organizations_url": "https://api.github.com/users/bnaul/orgs", "repos_url": "https://api.github.com/users/bnaul/repos", "events_url": "https://api.github.com/users/bnaul/events{/privacy}", "received_events_url": "https://api.github.com/users/bnaul/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "In the meantime you can work around by naming your class something else and\nspecifying db_table='model', but I will get this fixed asap.\n\nOn Aug 10, 2016 2:09 PM, \"Brett Naul\" [email protected] wrote:\n\n> Was fine on 2.8.1 but has broken since upgrading to 2.8.2. Example:\n> \n> import peewee as pw\n> \n> db = pw.PostgresqlDatabase(autocommit=True, autorollback=True,\n> database='postgres', host=None, password=None,\n> port=5432)\n> \n> class NotModel(pw.Model):\n> name = pw.CharField()\n> class Meta:\n> database = db\n> \n> class Model(pw.Model):\n> name = pw.CharField()\n> class Meta:\n> database = db\n> \n> if **name** == \"**main**\":\n> db.create_table(NotModel, safe=True)\n> db.create_table(Model, safe=True)\n> \n> notmodel is created but creating model fails:\n> \n> AttributeError Traceback (most recent call last)\n> /Users/brettnaul/Dropbox/Documents/cesium_web/cesium_app/models.py in <module>()\n> 23 if **name** == \"**main**\":\n> 24 db.create_table(NotModel, safe=True)\n> ---> 25 db.create_table(Model, safe=True)\n> 26\n> \n> /Users/brettnaul/miniconda3/envs/cesium/lib/python3.5/site-packages/peewee.py in create_table(self, model_class, safe)\n> 3753 def create_table(self, model_class, safe=False):\n> 3754 qc = self.compiler()\n> -> 3755 return self.execute_sql(*qc.create_table(model_class, safe))\n> 3756\n> 3757 def create_tables(self, models, safe=False):\n> \n> /Users/brettnaul/miniconda3/envs/cesium/lib/python3.5/site-packages/peewee.py in inner(self, _args, *_kwargs)\n> 2071 def inner(self, _args, *_kwargs):\n> 2072 fn = getattr(self, function_name)\n> -> 2073 return self.parse_node(fn(_args, *_kwargs))\n> 2074 return inner\n> 2075\n> \n> /Users/brettnaul/miniconda3/envs/cesium/lib/python3.5/site-packages/peewee.py in _create_table(self, model_class, safe)\n> 2090 def _create_table(self, model_class, safe=False):\n> 2091 statement = 'CREATE TABLE IF NOT EXISTS' if safe else 'CREATE TABLE'\n> -> 2092 meta = model_class._meta\n> 2093\n> 2094 columns, constraints = [], []\n> \n> AttributeError: type object 'Model' has no attribute '_meta'\n> \n> —\n> You are receiving this because you are subscribed to this thread.\n> Reply to this email directly, view it on GitHub\n> https://github.com/coleifer/peewee/issues/1035, or mute the thread\n> https://github.com/notifications/unsubscribe-auth/AAHUplWJ5-QGVfxP3ixcxIrMUlbvNyEBks5qeiH7gaJpZM4JheYy\n> .\n", "Great, thanks! Any chance we can get a quicker bugfix release this time around? 😬 \n", "Yeah let me see if I can round up a couple other small bugs.\n" ]
2016-08-10T19:09:46
2016-08-11T17:23:19
2016-08-11T07:53:05
NONE
null
Was fine on `2.8.1` but has broken since upgrading to `2.8.2`. Example: ``` import peewee as pw db = pw.PostgresqlDatabase(autocommit=True, autorollback=True, database='postgres', host=None, password=None, port=5432) class NotModel(pw.Model): name = pw.CharField() class Meta: database = db class Model(pw.Model): name = pw.CharField() class Meta: database = db if __name__ == "__main__": db.create_table(NotModel, safe=True) db.create_table(Model, safe=True) ``` `notmodel` is created but creating `model` fails: ``` AttributeError Traceback (most recent call last) /Users/brettnaul/Dropbox/Documents/cesium_web/cesium_app/models.py in <module>() 23 if __name__ == "__main__": 24 db.create_table(NotModel, safe=True) ---> 25 db.create_table(Model, safe=True) 26 /Users/brettnaul/miniconda3/envs/cesium/lib/python3.5/site-packages/peewee.py in create_table(self, model_class, safe) 3753 def create_table(self, model_class, safe=False): 3754 qc = self.compiler() -> 3755 return self.execute_sql(*qc.create_table(model_class, safe)) 3756 3757 def create_tables(self, models, safe=False): /Users/brettnaul/miniconda3/envs/cesium/lib/python3.5/site-packages/peewee.py in inner(self, *args, **kwargs) 2071 def inner(self, *args, **kwargs): 2072 fn = getattr(self, function_name) -> 2073 return self.parse_node(fn(*args, **kwargs)) 2074 return inner 2075 /Users/brettnaul/miniconda3/envs/cesium/lib/python3.5/site-packages/peewee.py in _create_table(self, model_class, safe) 2090 def _create_table(self, model_class, safe=False): 2091 statement = 'CREATE TABLE IF NOT EXISTS' if safe else 'CREATE TABLE' -> 2092 meta = model_class._meta 2093 2094 columns, constraints = [], [] AttributeError: type object 'Model' has no attribute '_meta' ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1035/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1035/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1034
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1034/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1034/comments
https://api.github.com/repos/coleifer/peewee/issues/1034/events
https://github.com/coleifer/peewee/issues/1034
170,330,013
MDU6SXNzdWUxNzAzMzAwMTM=
1,034
pwiz not output models.py with Mysql BLOB
{ "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
[ "The mapping in the `playhouse.reflection` module explicitly associates MySQL BLOB columns with `TextField`s. I wish I had left a comment as to why it is that way... There seems to be some odd behavior with the way MySQL / Python handle BLOBs compared to the other database engines Peewee supports out-of-the-box (the blob field test cases are skipped for MySQL). I've made a couple changes and will let the continuous integration run the tests and see what shakes out from there.\n", "If you take a look here, it seems to be a limitation of the Python MySQL drivers:\n\nhttps://github.com/django/django/blob/master/django/db/backends/mysql/introspection.py#L15-L37\n\nNote how all the `BLOB` types get mapped to `TextField` -- this is also the behavior of pymysql:\n\nhttps://github.com/PyMySQL/PyMySQL/blob/master/pymysql/constants/FIELD_TYPE.py\n\nSo rather than assuming BlobField everywhere, peewee does what Django does and assumes TextField. You can go back through the code and make replacements where needed, of course.\n" ]
2016-08-10T05:19:54
2016-08-15T19:42:22
2016-08-15T19:42:22
NONE
null
pwiz not output models.py with Mysql BLOB? parse error, My mysql filed is blob, pwiz output TEXTFIELD . Thanks U.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1034/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1034/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1033
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1033/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1033/comments
https://api.github.com/repos/coleifer/peewee/issues/1033/events
https://github.com/coleifer/peewee/issues/1033
170,153,658
MDU6SXNzdWUxNzAxNTM2NTg=
1,033
Issue with using percent sign
{ "login": "bitnic028", "id": 11515516, "node_id": "MDQ6VXNlcjExNTE1NTE2", "avatar_url": "https://avatars.githubusercontent.com/u/11515516?v=4", "gravatar_id": "", "url": "https://api.github.com/users/bitnic028", "html_url": "https://github.com/bitnic028", "followers_url": "https://api.github.com/users/bitnic028/followers", "following_url": "https://api.github.com/users/bitnic028/following{/other_user}", "gists_url": "https://api.github.com/users/bitnic028/gists{/gist_id}", "starred_url": "https://api.github.com/users/bitnic028/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/bitnic028/subscriptions", "organizations_url": "https://api.github.com/users/bitnic028/orgs", "repos_url": "https://api.github.com/users/bitnic028/repos", "events_url": "https://api.github.com/users/bitnic028/events{/privacy}", "received_events_url": "https://api.github.com/users/bitnic028/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "What database are you using?\n", "Posgtrsql.\n", "This is a quirk of `psycopg2`, which apparently treats \"%\" as placeholders. This StackOverflow question deals with the exact same issue:\n\nhttp://stackoverflow.com/questions/14054920/psycopg2-indexerror-tuple-index-out-of-range-error-when-using-like-operat\n\nTo escape the percent sign, just use \"%%\":\n\n``` python\nIn [5]: db.execute_sql('SELECT 12 %% 5;').fetchall()\nOut[5]: [(2,)]\n```\n" ]
2016-08-09T12:28:49
2016-08-10T14:40:22
2016-08-10T14:40:22
NONE
null
A code like this ``` >>> from application.db.models import db >>> query = 'SELECT 12 % 5;' >>> res = db.execute_sql(query) ``` is crashing ``` Traceback (most recent call last): File "<input>", line 1, in <module> File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 3485, in execute_sql cursor.execute(sql, params or ()) IndexError: tuple index out of range ``` Certainly, in this case percent sign should replace by `mod()` function.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1033/reactions", "total_count": 1, "+1": 1, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1033/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1032
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1032/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1032/comments
https://api.github.com/repos/coleifer/peewee/issues/1032/events
https://github.com/coleifer/peewee/issues/1032
169,936,345
MDU6SXNzdWUxNjk5MzYzNDU=
1,032
Retrieving data through a ManyToManyField fails with ForeignKeyFields as primary keys
{ "login": "bfontaine", "id": 1334295, "node_id": "MDQ6VXNlcjEzMzQyOTU=", "avatar_url": "https://avatars.githubusercontent.com/u/1334295?v=4", "gravatar_id": "", "url": "https://api.github.com/users/bfontaine", "html_url": "https://github.com/bfontaine", "followers_url": "https://api.github.com/users/bfontaine/followers", "following_url": "https://api.github.com/users/bfontaine/following{/other_user}", "gists_url": "https://api.github.com/users/bfontaine/gists{/gist_id}", "starred_url": "https://api.github.com/users/bfontaine/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/bfontaine/subscriptions", "organizations_url": "https://api.github.com/users/bfontaine/orgs", "repos_url": "https://api.github.com/users/bfontaine/repos", "events_url": "https://api.github.com/users/bfontaine/events{/privacy}", "received_events_url": "https://api.github.com/users/bfontaine/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I reported this issue before the 2.8.2 release but I just tried and I can still reproduce it with the same code example and the latest release (2.8.2).\n", "The issue has not been fixed, but I'm now looking into it.\n", "Thanks for the code to repro - you have no idea how much I appreciate it!\n", "Fixed\n", "Thanks!\n" ]
2016-08-08T14:26:08
2016-08-24T07:44:35
2016-08-24T05:20:55
CONTRIBUTOR
null
Here is a simple example: ``` python from playhouse.sqlite_ext import SqliteExtDatabase from playhouse.fields import ManyToManyField from peewee import Model, ForeignKeyField db = SqliteExtDatabase("yo.db") class BaseModel(Model): class Meta: database = db class A(BaseModel): pass class B(BaseModel): pk = ForeignKeyField(A, primary_key=True) class C(BaseModel): bs = ManyToManyField(B, related_name="cs") # Call this method to reproduce the issue def reproduce(): db.create_tables([A, B, C, C.bs.get_through_model()], True) a = A.create() b = B.create(pk=a) print(list(b.cs)) ``` Expected result: it should print an empty list Actual result: ``` Traceback (most recent call last): File "/tmp/x/venv/lib/python3.4/site-packages/peewee.py", line 3485, in execute_sql cursor.execute(sql, params or ()) sqlite3.InterfaceError: Error binding parameter 0 - probably unsupported type. During handling of the above exception, another exception occurred: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/tmp/x/app.py", line 29, in reproduce print(list(b.cs)) File "/tmp/x/venv/lib/python3.4/site-packages/peewee.py", line 2967, in __iter__ return iter(self.execute()) File "/tmp/x/venv/lib/python3.4/site-packages/peewee.py", line 2960, in execute self._qr = ResultWrapper(model_class, self._execute(), query_meta) File "/tmp/x/venv/lib/python3.4/site-packages/peewee.py", line 2656, in _execute return self.database.execute_sql(sql, params, self.require_commit) File "/tmp/x/venv/lib/python3.4/site-packages/peewee.py", line 3492, in execute_sql self.commit() File "/tmp/x/venv/lib/python3.4/site-packages/peewee.py", line 3316, in __exit__ reraise(new_type, new_type(*exc_args), traceback) File "/tmp/x/venv/lib/python3.4/site-packages/peewee.py", line 127, in reraise raise value.with_traceback(tb) File "/tmp/x/venv/lib/python3.4/site-packages/peewee.py", line 3485, in execute_sql cursor.execute(sql, params or ()) peewee.InterfaceError: Error binding parameter 0 - probably unsupported type. ``` Indeed, if we print `b.cs` we can see there’s a bad binding at the end: ``` <class 'app.C'> SELECT "t1"."id" FROM "c" AS t1 INNER JOIN "c_b_through" AS t2 ON ("t1"."id" = "t2"."c_id") INNER JOIN "b" AS t3 ON ("t2"."b_id" = "t3"."pk_id") WHERE ("t2"."b_id" = ?) [<app.A object at 0x7f2c13720d30>] ``` It should probably be using the foreign key directly instead of the model pointed _by_ it. I’m not really sure how to fix this in Peewee.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1032/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1032/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1031
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1031/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1031/comments
https://api.github.com/repos/coleifer/peewee/issues/1031/events
https://github.com/coleifer/peewee/issues/1031
169,885,323
MDU6SXNzdWUxNjk4ODUzMjM=
1,031
Query doesn't work using `&`
{ "login": "Cee", "id": 5436953, "node_id": "MDQ6VXNlcjU0MzY5NTM=", "avatar_url": "https://avatars.githubusercontent.com/u/5436953?v=4", "gravatar_id": "", "url": "https://api.github.com/users/Cee", "html_url": "https://github.com/Cee", "followers_url": "https://api.github.com/users/Cee/followers", "following_url": "https://api.github.com/users/Cee/following{/other_user}", "gists_url": "https://api.github.com/users/Cee/gists{/gist_id}", "starred_url": "https://api.github.com/users/Cee/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/Cee/subscriptions", "organizations_url": "https://api.github.com/users/Cee/orgs", "repos_url": "https://api.github.com/users/Cee/repos", "events_url": "https://api.github.com/users/Cee/events{/privacy}", "received_events_url": "https://api.github.com/users/Cee/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "If I leave off the call to `.count()`, the SQL is:\n\n``` sql\nSELECT \"t1\".\"id\", \"t1\".\"user_id\", \"t1\".\"message\", \"t1\".\"created_date\", \"t1\".\"is_published\" \nFROM \"tweet\" AS t1 \nWHERE ((\"t1\".\"created_date\" >= ?) AND (\"t1\".\"is_published\" = ?))\n```\n\nThe parameters passed into the query are `[datetime.date(2016, 8, 8), True]`.\n\nI believe you are mistaken. And I have _no_ idea what you mean by \"replacing it with AND\" because \"AND\" is not valid Python. The `and` keyword is, but it does logical and (short-cutting), and cannot be overridden. Bitwise and `&` _can_ be overridden, and is required when writing queries with Peewee.\n" ]
2016-08-08T09:58:16
2016-08-08T15:54:57
2016-08-08T15:54:57
NONE
null
``` python tweets_today = (Tweet .select() .where( (Tweet.created_date >= datetime.date.today()) & (Tweet.is_published == True)) .count()) ``` I'm a python beginner and follow the [example](https://github.com/coleifer/peewee/blob/master/README.rst), but I couldn't get a correct answer when I use `&` mentioned above. However, when I replace `&` with `AND`, it works.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1031/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1031/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1030
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1030/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1030/comments
https://api.github.com/repos/coleifer/peewee/issues/1030/events
https://github.com/coleifer/peewee/issues/1030
169,802,318
MDU6SXNzdWUxNjk4MDIzMTg=
1,030
Is Peewee Greenlet-safe?
{ "login": "joeyespo", "id": 634573, "node_id": "MDQ6VXNlcjYzNDU3Mw==", "avatar_url": "https://avatars.githubusercontent.com/u/634573?v=4", "gravatar_id": "", "url": "https://api.github.com/users/joeyespo", "html_url": "https://github.com/joeyespo", "followers_url": "https://api.github.com/users/joeyespo/followers", "following_url": "https://api.github.com/users/joeyespo/following{/other_user}", "gists_url": "https://api.github.com/users/joeyespo/gists{/gist_id}", "starred_url": "https://api.github.com/users/joeyespo/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/joeyespo/subscriptions", "organizations_url": "https://api.github.com/users/joeyespo/orgs", "repos_url": "https://api.github.com/users/joeyespo/repos", "events_url": "https://api.github.com/users/joeyespo/events{/privacy}", "received_events_url": "https://api.github.com/users/joeyespo/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "For questions regarding `werkzeug.LocalProxy`, you'll need to refer to the folks that maintain that project as I am not familiar with that particular class.\n\nI can tell you, however, that peewee works well with gevent (fuck yeah, gevent! asyncio is a heaping pile of turds). If you're using `psycopg2` with `PostgresqlDatabase`, here's a snippet that will green up your connection:\n\n```\n# patch_psycopg2.py\nfrom gevent import monkey\n\nfrom gevent.socket import wait_read, wait_write\nfrom psycopg2 import extensions\n\n\ndef monkeypatch_psycopg2():\n extensions.set_wait_callback(gevent_wait_callback)\n\ndef gevent_wait_callback(conn, timeout=None):\n \"\"\"A wait callback useful to allow gevent to work with Psycopg.\"\"\"\n while 1:\n state = conn.poll()\n if state == extensions.POLL_OK:\n break\n elif state == extensions.POLL_READ:\n wait_read(conn.fileno(), timeout=timeout)\n elif state == extensions.POLL_WRITE:\n wait_write(conn.fileno(), timeout=timeout)\n else:\n raise psycopg2.OperationalError(\n \"Bad result from poll: %r\" % state)\n```\n\nThen, in your WSGI file or wherever you're doing the rest of the gevent monkey-patching, simply call `monkeypatch_psycopg2()` and it will make `psycopg2` greenlet-friendly.\n\nI'm not sure how familiar you are with gevent, but one particular but extremely important quirk is that you need to do your monkey-patching **before** anything else. Like, it has to be basically the first thing you do in your WSGI file.\n\nIf you're using MySQL, God help you. (just kidding: I'm just not familiar with a similar process for MySQL's python drivers).\n\nHope that helps!\n", "Oh, I should add:\n\nPeewee uses thread-locals to maintain connection state. If you plan on using gevent, just be sure the threading module gets patched as well. That way those thread-locals will become greenlet-locals, which is what you want.\n" ]
2016-08-07T15:48:15
2016-08-07T16:33:09
2016-08-07T16:32:02
CONTRIBUTOR
null
My target setup is to use Flask, Peewee, and `LocalProxy` as fixed in #1025 for the development simplicity and power. (Peewee is awesome!) For production, I plan to use Gunicorn with Gevent workers to handle as many simultaneous connections as this stack will allow. (Then scale with more complicated methods _after_ proving the need.) My question is, does Peewee work well with Greenlets? Adding to my example in #1025: ``` import peewee from werkzeug.local import LocalProxy @LocalProxy def db(): _db = getattr(g, '_db', None) if _db is None: _db = g._db = db_url.connect( current_app.config['DATABASE_URL'], threadlocals=False) return _db class BaseModel(peewee.Model): class Meta: database = db class MyModel(BaseModel): ... def init_app(app): @app.teardown_appcontext def teardown_db(exception): _db = getattr(g, '_db', None) if _db and not _db.is_closed(): _db.close() g._db = None ``` From what I understand, the above will lazily create a new connection when a model is accessed. [One per request](http://flask.pocoo.org/docs/0.11/appcontext/#locality-of-the-context). (Or rather, one per application context, so you can access models outside of requests too with [`app.app_context`](http://flask.pocoo.org/docs/0.11/appcontext/#creating-an-application-context). Say, in a migration script.) Since that handles connections [across threads](http://werkzeug.pocoo.org/docs/0.11/local/) too, I turned `threadlocals` off. Is this correct? Or is something missing (say, explicit transaction handling)? Thanks!
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1030/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1030/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1029
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1029/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1029/comments
https://api.github.com/repos/coleifer/peewee/issues/1029/events
https://github.com/coleifer/peewee/pull/1029
169,524,175
MDExOlB1bGxSZXF1ZXN0ODAxODU4MTc=
1,029
Add CROSS JOIN.
{ "login": "paulbooth", "id": 448703, "node_id": "MDQ6VXNlcjQ0ODcwMw==", "avatar_url": "https://avatars.githubusercontent.com/u/448703?v=4", "gravatar_id": "", "url": "https://api.github.com/users/paulbooth", "html_url": "https://github.com/paulbooth", "followers_url": "https://api.github.com/users/paulbooth/followers", "following_url": "https://api.github.com/users/paulbooth/following{/other_user}", "gists_url": "https://api.github.com/users/paulbooth/gists{/gist_id}", "starred_url": "https://api.github.com/users/paulbooth/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/paulbooth/subscriptions", "organizations_url": "https://api.github.com/users/paulbooth/orgs", "repos_url": "https://api.github.com/users/paulbooth/repos", "events_url": "https://api.github.com/users/paulbooth/events{/privacy}", "received_events_url": "https://api.github.com/users/paulbooth/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "merged equivalent patch\n" ]
2016-08-05T04:01:28
2016-10-16T05:38:11
2016-10-16T05:37:56
CONTRIBUTOR
null
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1029/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1029/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/1029", "html_url": "https://github.com/coleifer/peewee/pull/1029", "diff_url": "https://github.com/coleifer/peewee/pull/1029.diff", "patch_url": "https://github.com/coleifer/peewee/pull/1029.patch", "merged_at": null }
https://api.github.com/repos/coleifer/peewee/issues/1028
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1028/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1028/comments
https://api.github.com/repos/coleifer/peewee/issues/1028/events
https://github.com/coleifer/peewee/pull/1028
169,515,721
MDExOlB1bGxSZXF1ZXN0ODAxNzk4NzI=
1,028
Pass kwargs from ensure_join to the join call.
{ "login": "paulbooth", "id": 448703, "node_id": "MDQ6VXNlcjQ0ODcwMw==", "avatar_url": "https://avatars.githubusercontent.com/u/448703?v=4", "gravatar_id": "", "url": "https://api.github.com/users/paulbooth", "html_url": "https://github.com/paulbooth", "followers_url": "https://api.github.com/users/paulbooth/followers", "following_url": "https://api.github.com/users/paulbooth/following{/other_user}", "gists_url": "https://api.github.com/users/paulbooth/gists{/gist_id}", "starred_url": "https://api.github.com/users/paulbooth/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/paulbooth/subscriptions", "organizations_url": "https://api.github.com/users/paulbooth/orgs", "repos_url": "https://api.github.com/users/paulbooth/repos", "events_url": "https://api.github.com/users/paulbooth/events{/privacy}", "received_events_url": "https://api.github.com/users/paulbooth/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Looks pretty good, just hesitating on pressing \"Merge\" because it slightly changes the API in a backwards-incompatible way. Then I thought \"Oh, well, the method is not documented, so nobody's really using it.\" And _then_ I thought, \"well, this guy's using it.\"\n\nSo, since I'm curious, what are you using this method for? It's a pretty obscure little helper function...\n\nSecondly, what do you think about leaving `on=None` and just passing it along with the `**kwargs` to the `join()` method?\n", "We needed something like this for our Customer model with a nullable foreign key to Address. When we pass in a customer query to filter according to our filter language that includes Address, we need to make sure that Address has been joined without doing unnecessary switch and joins. So, we want to ensure_join on Address, but it is nullable and we want to JOIN_LEFT_OUTER, which we can't currently do.\n\nInterestingly, we can actually get around this using the non-private method get_query_meta and inspecting the join_dict, but this is a bit of hack:\n\n```\n_select_fields, join_dict = customers.get_query_meta()\n for join in join_dict[Customer]:\n if join.dest is Address:\n break\n else:\n customers = customers.switch(Customer).join(Address, JOIN.LEFT_OUTER)\n```\n\nre: keeping on=None: Great idea, keep backwards-compatibility and future-proofing against any new join kwargs, sounds like a winner to me. Future code spelunkers might wonder why `on` is provided separately from other kwargs, but this should be obvious to allow for positional invocations. Change inbound\n", "Awesome, thanks for this patch!\n" ]
2016-08-05T02:24:23
2016-08-10T14:34:20
2016-08-10T14:34:07
CONTRIBUTOR
null
Allows join_type to be specified in ensure_join. This will also allow any future arguments to join to automatically be handled through ensure_join.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1028/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1028/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/1028", "html_url": "https://github.com/coleifer/peewee/pull/1028", "diff_url": "https://github.com/coleifer/peewee/pull/1028.diff", "patch_url": "https://github.com/coleifer/peewee/pull/1028.patch", "merged_at": "2016-08-10T14:34:07" }
https://api.github.com/repos/coleifer/peewee/issues/1027
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1027/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1027/comments
https://api.github.com/repos/coleifer/peewee/issues/1027/events
https://github.com/coleifer/peewee/issues/1027
169,502,457
MDU6SXNzdWUxNjk1MDI0NTc=
1,027
New release, please.
{ "login": "kdart", "id": 33999, "node_id": "MDQ6VXNlcjMzOTk5", "avatar_url": "https://avatars.githubusercontent.com/u/33999?v=4", "gravatar_id": "", "url": "https://api.github.com/users/kdart", "html_url": "https://github.com/kdart", "followers_url": "https://api.github.com/users/kdart/followers", "following_url": "https://api.github.com/users/kdart/following{/other_user}", "gists_url": "https://api.github.com/users/kdart/gists{/gist_id}", "starred_url": "https://api.github.com/users/kdart/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/kdart/subscriptions", "organizations_url": "https://api.github.com/users/kdart/orgs", "repos_url": "https://api.github.com/users/kdart/repos", "events_url": "https://api.github.com/users/kdart/events{/privacy}", "received_events_url": "https://api.github.com/users/kdart/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Definitely, can you tell me what commit in particular you're referring to?\n", "The error is this:\n\n```\nTraceback (most recent call last):\n File \"/opt/Cellar/python3/3.5.2_1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/runpy.py\", line 184, in _run_module_as_main\n \"__main__\", mod_spec)\n File \"/opt/Cellar/python3/3.5.2_1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/runpy.py\", line 85, in _run_code\n exec(code, run_globals)\n File \"/Volumes/USER/Users/keith_dart/src/costest/costest/db/models.py\", line 88, in <module>\n class EquipmentModel(BaseModel):\n File \"/opt/lib/python3.5/site-packages/peewee.py\", line 4479, in __new__\n field.add_to_class(cls, name)\n File \"/opt/lib/python3.5/site-packages/peewee.py\", line 1081, in add_to_class\n self._constructor = model_class._meta.database.get_binary_type()\n File \"/opt/lib/python3.5/site-packages/peewee.py\", line 407, in __getattr__\n raise AttributeError('Cannot use uninitialized Proxy.')\nAttributeError: Cannot use uninitialized Proxy.\n```\n\nBecause I'm also using the proxy object.\n\nThis fix is in b2d52ba7\n", "2.8.2 is pushed to PyPI.\n", "a33e8ccbd5b1e49f0a781d38d40eb5e8f344eee5\n" ]
2016-08-05T00:11:23
2016-08-09T05:36:10
2016-08-09T05:36:09
NONE
null
Hello. First of all, thanks for the great ORM. I'm using it in my project. My project defines some custom fields. Now if I use the current distribution from pypi I get an exception thrown and my project basically crashes. But I see the fix for it is already in master. If I install from master everything works fine. It would be really nice, though, if my users could just get it off of pypi like the other packages. It's been like this for quite some time, so I thought I'd ping you to please do a point release to simplify our installation. Thanks!
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1027/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1027/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1026
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1026/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1026/comments
https://api.github.com/repos/coleifer/peewee/issues/1026/events
https://github.com/coleifer/peewee/issues/1026
168,888,967
MDU6SXNzdWUxNjg4ODg5Njc=
1,026
Add support for PostgreSQL geometric types
{ "login": "guidoiaquinti", "id": 4038041, "node_id": "MDQ6VXNlcjQwMzgwNDE=", "avatar_url": "https://avatars.githubusercontent.com/u/4038041?v=4", "gravatar_id": "", "url": "https://api.github.com/users/guidoiaquinti", "html_url": "https://github.com/guidoiaquinti", "followers_url": "https://api.github.com/users/guidoiaquinti/followers", "following_url": "https://api.github.com/users/guidoiaquinti/following{/other_user}", "gists_url": "https://api.github.com/users/guidoiaquinti/gists{/gist_id}", "starred_url": "https://api.github.com/users/guidoiaquinti/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/guidoiaquinti/subscriptions", "organizations_url": "https://api.github.com/users/guidoiaquinti/orgs", "repos_url": "https://api.github.com/users/guidoiaquinti/repos", "events_url": "https://api.github.com/users/guidoiaquinti/events{/privacy}", "received_events_url": "https://api.github.com/users/guidoiaquinti/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "See an example of custom field for that here https://github.com/BaseAdresseNationale/ban/blob/master/ban/db/fields.py#L33\n", "While I personally have no intentions of implementing fields for those data-types, I would merge a pull-request that added support in the `playhouse.postgres_ext` module. On a personal note, I stopped using Postgres about 2 years ago and I haven't looked back, so new features to the `postgres_ext` extension are going to need to have either 1) strong interest from the community, 2) patches submitted by an ambitious contributor, or 3) a feeling that the presence of a particular feature will be important to users in evaluating whether or not to use Peewee. This last one was the case for both `jsonb` and `tsvector` (full-text search). Geometry fields just don't have the same panache, I guess :) .\n\nI'm going to close this for now, but if you have any additional thoughts on the matter please leave a comment. Thanks!\n" ]
2016-08-02T13:46:17
2016-08-03T07:36:31
2016-08-03T07:36:31
NONE
null
I'm opening this issue (as suggested in the [docs](http://docs.peewee-orm.com/en/latest/peewee/playhouse.html#postgresql-extensions)) to keep track of PostgreSQL [geometric type](https://www.postgresql.org/docs/current/static/datatype-geometric.html) support
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1026/reactions", "total_count": 1, "+1": 1, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1026/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1025
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1025/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1025/comments
https://api.github.com/repos/coleifer/peewee/issues/1025/events
https://github.com/coleifer/peewee/pull/1025
168,571,695
MDExOlB1bGxSZXF1ZXN0Nzk1MTYzNjk=
1,025
Explicitly check database for None in ModelOptions
{ "login": "joeyespo", "id": 634573, "node_id": "MDQ6VXNlcjYzNDU3Mw==", "avatar_url": "https://avatars.githubusercontent.com/u/634573?v=4", "gravatar_id": "", "url": "https://api.github.com/users/joeyespo", "html_url": "https://github.com/joeyespo", "followers_url": "https://api.github.com/users/joeyespo/followers", "following_url": "https://api.github.com/users/joeyespo/following{/other_user}", "gists_url": "https://api.github.com/users/joeyespo/gists{/gist_id}", "starred_url": "https://api.github.com/users/joeyespo/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/joeyespo/subscriptions", "organizations_url": "https://api.github.com/users/joeyespo/orgs", "repos_url": "https://api.github.com/users/joeyespo/repos", "events_url": "https://api.github.com/users/joeyespo/events{/privacy}", "received_events_url": "https://api.github.com/users/joeyespo/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Ahh, surprised this one's managed to stay undiscovered until now. Thanks for the patch!\n" ]
2016-08-01T05:50:10
2016-08-02T07:10:27
2016-08-02T07:10:27
CONTRIBUTOR
null
I was trying to use Werkzeug's [`LocalProxy`](http://werkzeug.pocoo.org/docs/0.11/local/) with the [Context Usage approach described in the Flask docs](http://flask.pocoo.org/docs/0.11/appcontext/#context-usage): ``` python import peewee from werkzeug.local import LocalProxy @LocalProxy def db(): _db = getattr(g, '_db', None) if _db is None: _db = g._db = db_url.connect(current_app.config['DATABASE_URL']) return _db class BaseModel(peewee.Model): class Meta: database = db class MyModel(BaseModel): ... def init_app(app): @app.teardown_appcontext def teardown_db(exception): _db = getattr(g, '_db', None) if _db and not _db.is_closed(): _db.close() g._db = None ``` The above fails because `bool(db)` [returns `False`](https://github.com/pallets/werkzeug/blob/0.11.10/werkzeug/local.py#L322-L326) on unbound proxies, which causes Peewee [to use its `peewee.db` default database](https://github.com/coleifer/peewee/blob/2.8.1/peewee.py#L4263). This fixes the problem without changing other existing behavior.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1025/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1025/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/1025", "html_url": "https://github.com/coleifer/peewee/pull/1025", "diff_url": "https://github.com/coleifer/peewee/pull/1025.diff", "patch_url": "https://github.com/coleifer/peewee/pull/1025.patch", "merged_at": "2016-08-02T07:10:27" }
https://api.github.com/repos/coleifer/peewee/issues/1024
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1024/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1024/comments
https://api.github.com/repos/coleifer/peewee/issues/1024/events
https://github.com/coleifer/peewee/pull/1024
168,521,073
MDExOlB1bGxSZXF1ZXN0Nzk0ODY4MjY=
1,024
SqliteMigrator: fix edge case in rename_column
{ "login": "jberkel", "id": 18891, "node_id": "MDQ6VXNlcjE4ODkx", "avatar_url": "https://avatars.githubusercontent.com/u/18891?v=4", "gravatar_id": "", "url": "https://api.github.com/users/jberkel", "html_url": "https://github.com/jberkel", "followers_url": "https://api.github.com/users/jberkel/followers", "following_url": "https://api.github.com/users/jberkel/following{/other_user}", "gists_url": "https://api.github.com/users/jberkel/gists{/gist_id}", "starred_url": "https://api.github.com/users/jberkel/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/jberkel/subscriptions", "organizations_url": "https://api.github.com/users/jberkel/orgs", "repos_url": "https://api.github.com/users/jberkel/repos", "events_url": "https://api.github.com/users/jberkel/events{/privacy}", "received_events_url": "https://api.github.com/users/jberkel/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Actually there are still some cases where this might fail. Maybe there's a better way to recreate the indexes?\n", "Fixed in 5aa587c\n" ]
2016-07-31T14:45:15
2016-08-06T16:00:17
2016-08-06T16:00:08
CONTRIBUTOR
null
When renaming a column with the same name as the table the table name will get accidentally replaced in the “CREATE index” query: ``` sql CREATE INDEX "table_name_first_column_second_column" ON "table_name" ("first_column", "second_column") ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1024/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1024/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/1024", "html_url": "https://github.com/coleifer/peewee/pull/1024", "diff_url": "https://github.com/coleifer/peewee/pull/1024.diff", "patch_url": "https://github.com/coleifer/peewee/pull/1024.patch", "merged_at": null }
https://api.github.com/repos/coleifer/peewee/issues/1023
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1023/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1023/comments
https://api.github.com/repos/coleifer/peewee/issues/1023/events
https://github.com/coleifer/peewee/issues/1023
167,686,809
MDU6SXNzdWUxNjc2ODY4MDk=
1,023
PostgresqlDatabase class does not have `_upsert` statement
{ "login": "cheetah90", "id": 3032091, "node_id": "MDQ6VXNlcjMwMzIwOTE=", "avatar_url": "https://avatars.githubusercontent.com/u/3032091?v=4", "gravatar_id": "", "url": "https://api.github.com/users/cheetah90", "html_url": "https://github.com/cheetah90", "followers_url": "https://api.github.com/users/cheetah90/followers", "following_url": "https://api.github.com/users/cheetah90/following{/other_user}", "gists_url": "https://api.github.com/users/cheetah90/gists{/gist_id}", "starred_url": "https://api.github.com/users/cheetah90/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/cheetah90/subscriptions", "organizations_url": "https://api.github.com/users/cheetah90/orgs", "repos_url": "https://api.github.com/users/cheetah90/repos", "events_url": "https://api.github.com/users/cheetah90/events{/privacy}", "received_events_url": "https://api.github.com/users/cheetah90/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Follow-up, Postgresql has implemented `UPSERT` in version > 9.5. [See here](https://wiki.postgresql.org/wiki/UPSERT)\n", "@cheetah90 -- there are two issues currently open tracking this exact thing:\n- #942 \n- #853\n" ]
2016-07-26T19:10:11
2016-07-26T19:56:01
2016-07-26T19:56:01
NONE
null
Looking at the [PostgresqlDatabase class](https://github.com/coleifer/peewee/blob/b84ca0c8bc724b8cccd0b5bbd557abc04885c478/peewee.py#L3945), it does not specify the statement for `_upsert`, so when [`query._upsert` is called here](https://github.com/coleifer/peewee/blob/b84ca0c8bc724b8cccd0b5bbd557abc04885c478/peewee.py#L1982) , it just return `None`.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1023/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1023/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1022
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1022/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1022/comments
https://api.github.com/repos/coleifer/peewee/issues/1022/events
https://github.com/coleifer/peewee/issues/1022
166,757,384
MDU6SXNzdWUxNjY3NTczODQ=
1,022
pwiz columns invalid names
{ "login": "CosmicAnalogue465", "id": 499021, "node_id": "MDQ6VXNlcjQ5OTAyMQ==", "avatar_url": "https://avatars.githubusercontent.com/u/499021?v=4", "gravatar_id": "", "url": "https://api.github.com/users/CosmicAnalogue465", "html_url": "https://github.com/CosmicAnalogue465", "followers_url": "https://api.github.com/users/CosmicAnalogue465/followers", "following_url": "https://api.github.com/users/CosmicAnalogue465/following{/other_user}", "gists_url": "https://api.github.com/users/CosmicAnalogue465/gists{/gist_id}", "starred_url": "https://api.github.com/users/CosmicAnalogue465/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/CosmicAnalogue465/subscriptions", "organizations_url": "https://api.github.com/users/CosmicAnalogue465/orgs", "repos_url": "https://api.github.com/users/CosmicAnalogue465/repos", "events_url": "https://api.github.com/users/CosmicAnalogue465/events{/privacy}", "received_events_url": "https://api.github.com/users/CosmicAnalogue465/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Hmmm....\n", "Can you explain this in a bit more detail? What exactly is the nature of this bug?\n", "This is a example of generated code from pwiz\n\nclass Flag(BaseModel):\n description = TextField(null=True)\n flag id = CharField(null=True)\n name = CharField(null=True)\n\npython will syntax error:\n\n```\nflag id = CharField(null=True)\n ^\n```\n\nSyntaxError: invalid syntax\n", "Solution could be to escape the fields name and use a db_column property\n\nflag_id = CharField(db_column='flag id', null=True)\n" ]
2016-07-21T07:47:04
2016-07-26T19:53:58
2016-07-26T19:53:58
NONE
null
in mysql fields can be named: "source id" "marketing/position" in this case pwiz creates python model attributes of the same name. Related issue: https://github.com/coleifer/peewee/issues/184
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1022/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1022/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1021
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1021/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1021/comments
https://api.github.com/repos/coleifer/peewee/issues/1021/events
https://github.com/coleifer/peewee/issues/1021
166,729,409
MDU6SXNzdWUxNjY3Mjk0MDk=
1,021
pwiz not generating foreign key fields for postgres
{ "login": "Mak-NOAA", "id": 20570382, "node_id": "MDQ6VXNlcjIwNTcwMzgy", "avatar_url": "https://avatars.githubusercontent.com/u/20570382?v=4", "gravatar_id": "", "url": "https://api.github.com/users/Mak-NOAA", "html_url": "https://github.com/Mak-NOAA", "followers_url": "https://api.github.com/users/Mak-NOAA/followers", "following_url": "https://api.github.com/users/Mak-NOAA/following{/other_user}", "gists_url": "https://api.github.com/users/Mak-NOAA/gists{/gist_id}", "starred_url": "https://api.github.com/users/Mak-NOAA/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/Mak-NOAA/subscriptions", "organizations_url": "https://api.github.com/users/Mak-NOAA/orgs", "repos_url": "https://api.github.com/users/Mak-NOAA/repos", "events_url": "https://api.github.com/users/Mak-NOAA/events{/privacy}", "received_events_url": "https://api.github.com/users/Mak-NOAA/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Can you please tell me a bit more about your schema? How are your foreign keys defined? \n\nIf you're able to create a connection using peewee, e.g.:\n\n``` python\ndb = PostgresqlDatabase('my_db', user='postgres')\ndb.connect()\n```\n\nThen you can try running the following to see what peewee is able to introspect:\n\n``` python\nfor table in db.get_tables():\n print db.get_foreign_keys(table)\n```\n", "I ran the for loop and here's what I see:\n[]\n[]\n[]\n[]\n[]\n[]\n[]\n[]\n[]\n[]\n[]\n[]\n[]\n[]\n\nThe schema was created in Postgres with foreign key constrains not sure how much to add on theh schema.\n", "OK, so that's the issue (the empty lists)... What do you get when you open up a postgres shell and do a describe on the tables?\n\n```\n$ psql your_db\npsql> \\d+ my_table\n```\n", "Here's a sample of our schema with the foreign key definition\n\n``` sql\n-- ----------------------------\n-- Sequence structure for PROJECT_TASK_CODES_LU_PROJECT_TASK_CODE_ID_seq\n-- ----------------------------\nDROP SEQUENCE IF EXISTS \"budget\".\"PROJECT_TASK_CODES_LU_PROJECT_TASK_CODE_ID_seq\";\nCREATE SEQUENCE \"budget\".\"PROJECT_TASK_CODES_LU_PROJECT_TASK_CODE_ID_seq\"\n INCREMENT 1\n MINVALUE 1\n MAXVALUE 9223372036854775807\n START 24\n CACHE 1;\nSELECT setval('\"budget\".\"PROJECT_TASK_CODES_LU_PROJECT_TASK_CODE_ID_seq\"', 24, true);\n\n-- ----------------------------\n-- Sequence structure for PROJECT_TASK_CODES_PROGRAMS_PROJECT_TASK_CODES_PROGRAMS_ID_seq\n-- ----------------------------\nDROP SEQUENCE IF EXISTS \"budget\".\"PROJECT_TASK_CODES_PROGRAMS_PROJECT_TASK_CODES_PROGRAMS_ID_seq\";\nCREATE SEQUENCE \"budget\".\"PROJECT_TASK_CODES_PROGRAMS_PROJECT_TASK_CODES_PROGRAMS_ID_seq\"\n INCREMENT 1\n MINVALUE 1\n MAXVALUE 9223372036854775807\n START 3\n CACHE 1;\nSELECT setval('\"budget\".\"PROJECT_TASK_CODES_PROGRAMS_PROJECT_TASK_CODES_PROGRAMS_ID_seq\"', 3, true);\n\n;\n\n\n-- ----------------------------\n-- Table structure for PROJECT_TASK_CODES_LU\n-- ----------------------------\nDROP TABLE IF EXISTS \"budget\".\"PROJECT_TASK_CODES_LU\";\nCREATE TABLE \"budget\".\"PROJECT_TASK_CODES_LU\" (\n\"PROJECT_TASK_CODE_ID\" int4 DEFAULT nextval('\"budget\".\"PROJECT_TASK_CODES_LU_PROJECT_TASK_CODE_ID_seq\"'::regclass) NOT NULL,\n\"FISCAL_YEAR\" timestamp(6),\n\"PROJECT_CODE_LU_ID\" int4,\n\"TASK_CODE\" varchar(3) COLLATE \"default\",\n\"MONEY_TYPE_LU_ID\" int4\n)\nWITH (OIDS=FALSE)\n\n;\nCOMMENT ON COLUMN \"budget\".\"PROJECT_TASK_CODES_LU\".\"PROJECT_TASK_CODE_ID\" IS 'Get approximately 25 of these codes in a given year';\nCOMMENT ON COLUMN \"budget\".\"PROJECT_TASK_CODES_LU\".\"FISCAL_YEAR\" IS 'Fiscal year of the project task code in YYYY format';\nCOMMENT ON COLUMN \"budget\".\"PROJECT_TASK_CODES_LU\".\"MONEY_TYPE_LU_ID\" IS 'Type of Money - No Year Money, Two Year Money';\n\n-- ----------------------------\n-- Table structure for PROJECT_TASK_CODES_PROGRAMS\n-- ----------------------------\nDROP TABLE IF EXISTS \"budget\".\"PROJECT_TASK_CODES_PROGRAMS\";\nCREATE TABLE \"budget\".\"PROJECT_TASK_CODES_PROGRAMS\" (\n\"PROJECT_TASK_CODES_PROGRAMS_ID\" int4 DEFAULT nextval('\"budget\".\"PROJECT_TASK_CODES_PROGRAMS_PROJECT_TASK_CODES_PROGRAMS_ID_seq\"'::regclass) NOT NULL,\n\"PROJECT_TASK_CODE_ID\" int4,\n\"PROGRAM_ID\" int4,\n\"PROJECT_CODE_DESCRIPTION\" varchar(255) COLLATE \"default\"\n)\nWITH (OIDS=FALSE)\n\n;\n\n-- ----------------------------\n-- Alter Sequences Owned By \n-- ----------------------------\nALTER SEQUENCE \"budget\".\"PROJECT_TASK_CODES_LU_PROJECT_TASK_CODE_ID_seq\" OWNED BY \"PROJECT_TASK_CODES_LU\".\"PROJECT_TASK_CODE_ID\";\nALTER SEQUENCE \"budget\".\"PROJECT_TASK_CODES_PROGRAMS_PROJECT_TASK_CODES_PROGRAMS_ID_seq\" OWNED BY \"PROJECT_TASK_CODES_PROGRAMS\".\"PROJECT_TASK_CODES_PROGRAMS_ID\";\n\n\n-- ----------------------------\n-- Uniques structure for table PROJECT_TASK_CODES_LU\n-- ----------------------------\nALTER TABLE \"budget\".\"PROJECT_TASK_CODES_LU\" ADD UNIQUE (\"FISCAL_YEAR\", \"PROJECT_CODE_LU_ID\", \"TASK_CODE\");\n\n-- ----------------------------\n-- Primary Key structure for table PROJECT_TASK_CODES_LU\n-- ----------------------------\nALTER TABLE \"budget\".\"PROJECT_TASK_CODES_LU\" ADD PRIMARY KEY (\"PROJECT_TASK_CODE_ID\");\n\n-- ----------------------------\n-- Primary Key structure for table PROJECT_TASK_CODES_PROGRAMS\n-- ----------------------------\nALTER TABLE \"budget\".\"PROJECT_TASK_CODES_PROGRAMS\" ADD PRIMARY KEY (\"PROJECT_TASK_CODES_PROGRAMS_ID\");\n\n\n-- ----------------------------\n-- Foreign Key structure for table \"budget\".\"PROJECT_TASK_CODES_PROGRAMS\"\n-- ----------------------------\nALTER TABLE \"budget\".\"PROJECT_TASK_CODES_PROGRAMS\" ADD FOREIGN KEY (\"PROJECT_TASK_CODE_ID\") REFERENCES \"budget\".\"PROJECT_TASK_CODES_LU\" (\"PROJECT_TASK_CODE_ID\") ON DELETE NO ACTION ON UPDATE NO ACTION;\nALTER TABLE \"budget\".\"PROJECT_TASK_CODES_PROGRAMS\" ADD FOREIGN KEY (\"PROGRAM_ID\") REFERENCES \"budget\".\"PROGRAMS_LU\" (\"PROGRAM_ID\") ON DELETE NO ACTION ON UPDATE NO ACTION;\n```\n", "we didn't issue a psql command but rather dumped it via navicat \n", "+1\n", "My best guess at the moment is that perhaps the postgresql schema name is not getting passed to the method that introspects foreign keys. I don't have a postgres server handy at the moment so I cannot test this myself, but if you were to try re-creating your tables in the \"public\" schema and running pwiz, I could quickly determine if my hypothesis is correct.\n", "Yes I think you are right.....but I can't really create tables in my public schema. I'm working w/ an Admin to see if he can try it.\n\nStrangely with peewee, without specifying a schema, queries and the model work great. \n", "@coleifer when hitting the public schema the FKs appeared in the model. Could you please check the methods in pwiz and see if the postgres schema can be passed to the method that introspects FKs? Would definitely help us out here :)\n", "Yes! Thank you so much for testing my hypothesis out. I'll get a patch in today.\n", "Well, now I'm confused...Are you all passing the schema in as a command-line argument when you run `pwiz`?\n\nLocally, I created a schema named \"nuggie\" with two tables, one of which has a foreign key. Here's how they look:\n\n```\npeewee_test=# set search_path='nuggie';\npeewee_test=# \\d\n List of relations\n Schema | Name | Type | Owner \n--------+--------------+----------+----------\n nuggie | notes | table | postgres\n nuggie | notes_id_seq | sequence | postgres\n nuggie | users | table | postgres\n nuggie | users_id_seq | sequence | postgres\n(4 rows)\n\npeewee_test=# \\d notes\n Table \"nuggie.notes\"\n Column | Type | Modifiers \n---------+---------+----------------------------------------------------\n id | integer | not null default nextval('notes_id_seq'::regclass)\n message | text | \n user_id | integer | not null\nIndexes:\n \"notes_pkey\" PRIMARY KEY, btree (id)\nForeign-key constraints:\n \"notes_user_id_fkey\" FOREIGN KEY (user_id) REFERENCES users(id)\n```\n\nWhen I run pwiz like this:\n\n``` console\n$ pwiz -e postgresql -s nuggie peewee_test\n```\n\nThen the output contains the foreign key, even though it is on a different schema than \"public\":\n\n``` python\nclass Users(BaseModel):\n username = CharField()\n\n class Meta:\n db_table = 'users'\n schema = 'nuggie'\n\nclass Notes(BaseModel):\n message = TextField(null=True)\n user = ForeignKeyField(db_column='user_id', rel_model=Users, to_field='id')\n\n class Meta:\n db_table = 'notes'\n schema = 'nuggie'\n```\n\nAre you sure there is a bug here?\n", "Using your above SQL, I created the \"budget\" schema and ran the statements. When I ran pwiz on them, the foreign key was present:\n\n``` console\n$ pwiz -e postgresql -s budget peewee_test\n```\n\n``` python\nclass ProjectTaskCodesPrograms(BaseModel):\n program = IntegerField(db_column='PROGRAM_ID', null=True)\n project_code_description = CharField(db_column='PROJECT_CODE_DESCRIPTION', null=True)\n project_task_codes_programs = PrimaryKeyField(db_column='PROJECT_TASK_CODES_PROGRAMS_ID')\n project_task_code = ForeignKeyField(db_column='PROJECT_TASK_CODE_ID', null=True, rel_model=ProjectTaskCodesLu, to_field='project_task_code')\n\n class Meta:\n db_table = 'PROJECT_TASK_CODES_PROGRAMS'\n schema = 'budget'\n```\n\nI'm closing this, but please re-open if you find that my assessment was incorrect and there is a demonstrable bug.\n", "I just ran \n\"python -m pwiz -e postgresql -u Username -P Database -H Host -p Port -s budget > model.py\"\n\nagain and it still doesn't produce the FKs. Is there something wrong with my statement? The schema is in it\n", "Umm, it looks right assuming you're passing in actual values for the username, password, host, and port...but you might try running it instead like this:\n\n\"pwiz.py -e postgresql -u postgres -P mypassword -s budget > models.py\"\n\nYou don't need to specify the host and port if they are the default / running locally. If you don't need a password, you also don't need to specify that.\n", "Yes I'm passing in actual values for username, password, host and port. I am VPNed and not running postgres locally. I tried removing Port but that didn't help. \n\nI tried running it like \n\n\"pwiz.py -e postgresql -u USERNAME -P DATABASE -H HOST -p PORT-s SCHEMA> model.py\"\nbut that just produces a blank file.\n\nI only get data when I run it with python at the start\n\"python -m pwiz -e postgresql -u USERNAME -P DATABASE -H HOST -p Port -s SCHEMA > model.py\"\n\nNot sure what else could be the problem now\n", "When you are passing \"-P DATABASE\" -- the \"-P\" is for password. Just want to double-check you are aware of that.\n\nCan you try just running it with \"pwiz.py\" and _not_ pipe it to a script, but let it print to stdout in case there's an error or something?\n", "Even with pwiz.py I get nothing, it just doesn't spit out anything.\n\nSo regarding the -P, I moved the DATABASE to the end of the command so ran it like this\npython -m pwiz -e postgresql -u USERNAME -P -H HOST -p PORT -s SCHEMA DATABASE\n\nand that didn't bring back the FKs either. Just wanted to add that whether I enter password after -P or not, I get asked to enter password when I run the command. Meaning\n\npython -m pwiz -e postgresql -u USERNAME -P PASSWORD -H HOST -p PORT -s SCHEMA DATABASE\nresults in being asked for password again.\n", "I had the owner of the schema run the command and it worked for him but still doesn't work for me.\n\nwhat permissions are needed on the schema to properly run pwiz?\n", "I would note that Mak has full permissions on this schema, although he is not the owner (he and I are working together on this effort).\n", "I'm sorry it's been a while since I replied. I am not familiar with Postgres enough to be able to answer your questions. Peewee queries `information_schema`, so I would assume the user running `pwiz` would need to be able to query those tables. Have you taken a look at peewee's `PostgresqlDatabase.get_tables()` and other introspection functions? Those contain the SQL used, which you could try running from a postgres shell.\n", "@coleifer , does pwiz work on a foreign key that references a Postgres table in a **different** schema?\r\nI'm having trouble not only generating a script with pwiz, but even getting the models to work.\r\nHow do you use ForeignKeyField on a table in a different schema in Postgres?", "pwiz may not pick that up. However, fks to tables in different schema should not present a problem. The FK constraint will be created referencing the schema + table name. I've added a test-case: d6087e1effe46d3959be81e869cfab625ba763ac" ]
2016-07-21T03:23:24
2019-07-04T16:34:38
2016-07-27T14:05:47
NONE
null
Hi @coleifer I have the same issue as https://github.com/coleifer/peewee/issues/207 with postgres however I used the command python -m pwiz -e postgresql -u USERNAME -P DATABASE -H HOST-p PORT-s SCHEMA> model.py My model did not contain any "ForeignKeyField" Any thoughts? Does pwiz create foreign key for postgres?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1021/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1021/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1020
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1020/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1020/comments
https://api.github.com/repos/coleifer/peewee/issues/1020/events
https://github.com/coleifer/peewee/issues/1020
166,462,440
MDU6SXNzdWUxNjY0NjI0NDA=
1,020
pwiz returns no such option -1
{ "login": "yanchao7511461", "id": 7982646, "node_id": "MDQ6VXNlcjc5ODI2NDY=", "avatar_url": "https://avatars.githubusercontent.com/u/7982646?v=4", "gravatar_id": "", "url": "https://api.github.com/users/yanchao7511461", "html_url": "https://github.com/yanchao7511461", "followers_url": "https://api.github.com/users/yanchao7511461/followers", "following_url": "https://api.github.com/users/yanchao7511461/following{/other_user}", "gists_url": "https://api.github.com/users/yanchao7511461/gists{/gist_id}", "starred_url": "https://api.github.com/users/yanchao7511461/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/yanchao7511461/subscriptions", "organizations_url": "https://api.github.com/users/yanchao7511461/orgs", "repos_url": "https://api.github.com/users/yanchao7511461/repos", "events_url": "https://api.github.com/users/yanchao7511461/events{/privacy}", "received_events_url": "https://api.github.com/users/yanchao7511461/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "How strange...couple questions:\n1. Is your VPS running linux?\n2. Are you using the exact same invocation on your VPS, or something different?\n3. How did you install Peewee on your computer?\n4. How did you install Peewee on your VPS?\n5. What version of peewee?\n\nNote: I edited your comment to add code formatting around the console output.\n", "I'm able to run the following without issue, for what it's worth:\n\n```\n$ python -m pwiz -esqlite somedb.db\n```\n", "Try the following locally:\n\n```\npython -m pwiz -e mysql -u root -P root wpdb > models.py\n```\n\nI'm not sure how shell redirection works on windows, but I'm assuming the same semantics as bash.\n", "Have you had a chance to look at this?\n", "Closing due to inactivity, my guess is this was user error.\n" ]
2016-07-19T23:31:01
2016-07-26T19:54:19
2016-07-26T19:54:19
NONE
null
``` C:\Users\mypc>python -m pwiz -e mysql -H localhost -p3306 -uroot -Proot wpdb > wpmodel.py Usage: pwiz.py [options] database_name pwiz.py: error: no such option: -1 ``` these texts is from my pc. When I use pwiz on my vps , it returns 'no such option: -c '
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1020/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1020/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1019
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1019/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1019/comments
https://api.github.com/repos/coleifer/peewee/issues/1019/events
https://github.com/coleifer/peewee/pull/1019
166,441,597
MDExOlB1bGxSZXF1ZXN0NzgwNTM1NTc=
1,019
impl new DeferredRelation semantics
{ "login": "c0ldcalamari", "id": 11208820, "node_id": "MDQ6VXNlcjExMjA4ODIw", "avatar_url": "https://avatars.githubusercontent.com/u/11208820?v=4", "gravatar_id": "", "url": "https://api.github.com/users/c0ldcalamari", "html_url": "https://github.com/c0ldcalamari", "followers_url": "https://api.github.com/users/c0ldcalamari/followers", "following_url": "https://api.github.com/users/c0ldcalamari/following{/other_user}", "gists_url": "https://api.github.com/users/c0ldcalamari/gists{/gist_id}", "starred_url": "https://api.github.com/users/c0ldcalamari/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/c0ldcalamari/subscriptions", "organizations_url": "https://api.github.com/users/c0ldcalamari/orgs", "repos_url": "https://api.github.com/users/c0ldcalamari/repos", "events_url": "https://api.github.com/users/c0ldcalamari/events{/privacy}", "received_events_url": "https://api.github.com/users/c0ldcalamari/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Awesome, thanks for the merge! \n" ]
2016-07-19T21:36:24
2016-07-20T17:12:58
2016-07-20T15:49:21
NONE
null
this implements issue #1018
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1019/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1019/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/1019", "html_url": "https://github.com/coleifer/peewee/pull/1019", "diff_url": "https://github.com/coleifer/peewee/pull/1019.diff", "patch_url": "https://github.com/coleifer/peewee/pull/1019.patch", "merged_at": "2016-07-20T15:49:21" }