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/714 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/714/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/714/comments | https://api.github.com/repos/coleifer/peewee/issues/714/events | https://github.com/coleifer/peewee/issues/714 | 106,660,748 | MDU6SXNzdWUxMDY2NjA3NDg= | 714 | Backreference relationship signal | {
"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 do not think that I would merge such functionality into peewee, but if you end up implementing it on you r own I'd love to see the diff. Maybe you could post it to this issue?\n",
"Haven't implemented yet, but I'm imagining this. This is not using the signals architecture as I'm not too well-read on your implementation of it.\n\n```\n# Save method on the base model (from which everyone inherits)\ndef save(self, *args, **kwargs):\n # Check all our ForeignKeyFields...\n for field in self.dirty_fields():\n if isinstance(field, ForeignKeyField):\n # If we're using signals, I think we would look it up and fire it here instead of making a\n # heavy assumption that the rel_model implements the method fk_established(self)\n try:\n field.rel_model.fk_established()\n except AttributeError:\n pass\n```\n"
] | 2015-09-15T22:28:30 | 2015-09-18T14:03:54 | 2015-09-18T01:18:15 | CONTRIBUTOR | null | Hey! I have a suggestion for an addition (and perhaps I could even undertake implementation if you think it's worthwhile and would accept changes!) to the signal support in `playhouse`. It's a little hard to articulate, but I think there might be value in a signal that fires for some model instance, let's call it `Banana`, when any other model establishes a Foreign Key relationship to that instance. I can imagine that in the save handler of a Model, we'd look at the fields for any dirty FKs, and fire a signal at them.
Does that make sense? Do you think that would be useful?
(the other option, of course, is for me to just implement that logic local to _my_ base model class and not make it part of the signal architecture)
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/714/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/714/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/713 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/713/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/713/comments | https://api.github.com/repos/coleifer/peewee/issues/713/events | https://github.com/coleifer/peewee/pull/713 | 106,579,758 | MDExOlB1bGxSZXF1ZXN0NDUwNjMxODM= | 713 | - Fixed column_name_re not working with ` characters. | {
"login": "sroebert",
"id": 81575,
"node_id": "MDQ6VXNlcjgxNTc1",
"avatar_url": "https://avatars.githubusercontent.com/u/81575?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/sroebert",
"html_url": "https://github.com/sroebert",
"followers_url": "https://api.github.com/users/sroebert/followers",
"following_url": "https://api.github.com/users/sroebert/following{/other_user}",
"gists_url": "https://api.github.com/users/sroebert/gists{/gist_id}",
"starred_url": "https://api.github.com/users/sroebert/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/sroebert/subscriptions",
"organizations_url": "https://api.github.com/users/sroebert/orgs",
"repos_url": "https://api.github.com/users/sroebert/repos",
"events_url": "https://api.github.com/users/sroebert/events{/privacy}",
"received_events_url": "https://api.github.com/users/sroebert/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Thank you!\n"
] | 2015-09-15T15:21:37 | 2015-09-17T00:05:39 | 2015-09-17T00:05:37 | CONTRIBUTOR | null | This fixes #712, where migration of a sqlite database is not working when the `CREATE TABLE` query contains newlines or `.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/713/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/713/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/713",
"html_url": "https://github.com/coleifer/peewee/pull/713",
"diff_url": "https://github.com/coleifer/peewee/pull/713.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/713.patch",
"merged_at": "2015-09-17T00:05:37"
} |
https://api.github.com/repos/coleifer/peewee/issues/712 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/712/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/712/comments | https://api.github.com/repos/coleifer/peewee/issues/712/events | https://github.com/coleifer/peewee/issues/712 | 106,579,242 | MDU6SXNzdWUxMDY1NzkyNDI= | 712 | SQLite migration cannot handle all CREATE TABLE queries | {
"login": "sroebert",
"id": 81575,
"node_id": "MDQ6VXNlcjgxNTc1",
"avatar_url": "https://avatars.githubusercontent.com/u/81575?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/sroebert",
"html_url": "https://github.com/sroebert",
"followers_url": "https://api.github.com/users/sroebert/followers",
"following_url": "https://api.github.com/users/sroebert/following{/other_user}",
"gists_url": "https://api.github.com/users/sroebert/gists{/gist_id}",
"starred_url": "https://api.github.com/users/sroebert/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/sroebert/subscriptions",
"organizations_url": "https://api.github.com/users/sroebert/orgs",
"repos_url": "https://api.github.com/users/sroebert/repos",
"events_url": "https://api.github.com/users/sroebert/events{/privacy}",
"received_events_url": "https://api.github.com/users/sroebert/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2015-09-15T15:19:11 | 2015-09-17T00:05:37 | 2015-09-17T00:05:37 | CONTRIBUTOR | null | I was implementing the use of the `drop_column` method in the `SqliteMigrator` when I found a bug.
I tested the result by changing my database model using sqlitebrowser. The `CREATE TABLE` query sqlitebrowser generates, contains newlines and ` characters around the table name. This differs from the peewee `CREATE TABLE` queries and the migration code does not support this.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/712/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/712/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/711 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/711/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/711/comments | https://api.github.com/repos/coleifer/peewee/issues/711/events | https://github.com/coleifer/peewee/issues/711 | 106,567,851 | MDU6SXNzdWUxMDY1Njc4NTE= | 711 | Problem with playhouse.db_url.connect query params | {
"login": "foxx",
"id": 651797,
"node_id": "MDQ6VXNlcjY1MTc5Nw==",
"avatar_url": "https://avatars.githubusercontent.com/u/651797?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/foxx",
"html_url": "https://github.com/foxx",
"followers_url": "https://api.github.com/users/foxx/followers",
"following_url": "https://api.github.com/users/foxx/following{/other_user}",
"gists_url": "https://api.github.com/users/foxx/gists{/gist_id}",
"starred_url": "https://api.github.com/users/foxx/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/foxx/subscriptions",
"organizations_url": "https://api.github.com/users/foxx/orgs",
"repos_url": "https://api.github.com/users/foxx/repos",
"events_url": "https://api.github.com/users/foxx/events{/privacy}",
"received_events_url": "https://api.github.com/users/foxx/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Well, technically I think you can specify those using PRAGMAs, can't you? Or as manual params with `connect()`...\n\nBut isn't the `uri` aspect fairly new to pysqlite, or am I mistaken?\n",
"It looks also like it's a Python3 only thing at the moment, added in 3.4, so I'm going to hold off on supporting that directly.\n",
"Oh I wasn't aware of PRAGMAs, I'll take another look at this, thanks!\n",
"After looking at this deeper, some options cannot be enabled via PRAGMAs, such as \"shared cache\". In this particular example, Python 2.x would have to use `sqlite3.enable_shared_cache(True)` module global, rather than specifying in the URLs. For this feature to have Python 2.x support, the `uri` module functionality would have to be [backported](https://hg.python.org/cpython/rev/f13bb1e40fbc), which is extremely difficult given that it's a `cpython` module. \n\nFor anyone seeing this in future, if you're using Python 2.x then you're mostly outta luck. If you're using Python 3.x, then use `uri=True`.\n"
] | 2015-09-15T14:27:18 | 2015-12-28T13:55:59 | 2015-09-17T00:04:27 | CONTRIBUTOR | null | Due to an outstanding [bug](https://bugs.python.org/issue24887) in sqlite3, some connection flags such as `mode=memory/cache=shared` can only be passed in via URI.
However, `playhouse.db_url.connect()` [converts](https://github.com/coleifer/peewee/blob/master/playhouse/db_url.py#L68) these query string parameters into `kwargs` for the database `connect()` call and are stripped from the URI, meaning that they are never actioned on.
As a temporary workaround for Sqlite3, you can bypass `db_url.connect()` and use `SqliteDatabase` directly with `uri=True`, however it would be nice if it handled this stuff automagically.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/711/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/711/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/710 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/710/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/710/comments | https://api.github.com/repos/coleifer/peewee/issues/710/events | https://github.com/coleifer/peewee/issues/710 | 106,156,441 | MDU6SXNzdWUxMDYxNTY0NDE= | 710 | Output null values for missing dates | {
"login": "aidanheerdegen",
"id": 6063709,
"node_id": "MDQ6VXNlcjYwNjM3MDk=",
"avatar_url": "https://avatars.githubusercontent.com/u/6063709?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/aidanheerdegen",
"html_url": "https://github.com/aidanheerdegen",
"followers_url": "https://api.github.com/users/aidanheerdegen/followers",
"following_url": "https://api.github.com/users/aidanheerdegen/following{/other_user}",
"gists_url": "https://api.github.com/users/aidanheerdegen/gists{/gist_id}",
"starred_url": "https://api.github.com/users/aidanheerdegen/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/aidanheerdegen/subscriptions",
"organizations_url": "https://api.github.com/users/aidanheerdegen/orgs",
"repos_url": "https://api.github.com/users/aidanheerdegen/repos",
"events_url": "https://api.github.com/users/aidanheerdegen/events{/privacy}",
"received_events_url": "https://api.github.com/users/aidanheerdegen/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"If you're using SQLite, then while Peewee supports RIGHT OUTER, SQLite itself does not. Can you simply switch the order of your joins and use a left outer?\n",
"You may need to add clauses to your where or join as well that allow for the date to be NULL. But, basically this is a SQL question not a peewee bug.\n"
] | 2015-09-12T12:59:28 | 2015-09-12T17:54:59 | 2015-09-12T17:54:59 | NONE | null | Hi,
I've tried and I've failed.
I have a table like so
``` python
class ShortUsage(BaseModel):
projid = ForeignKeyField(Project, to_field="projid")
folder = CharField(index=True)
user = ForeignKeyField(User, to_field="username")
# Support only dates. Don't want sub-day timescales, makes it harder to join
# data and snapshots are only taken daily
scandate = DateField(index=True)
inodes = FloatField()
size = FloatField()
class Meta:
# Combination of projid+folder+user+date must be unique
indexes = ( (('projid','folder','user','scandate'), True), )
```
For each projid and user I want to output the sum of size, which I can do no problem. Not all users have entries for all dates in a given range. I want to force the output of a value (zero?) for dates where they have no data. Basically, I need to output the sum of size for a superset of all dates within a given range.
I have succeeded in making a query which produces the dates I need for a given period:
``` python
SUalias = ShortUsage.alias()
q1 = SUalias.select(fn.Distinct(SUalias.scandate).alias('alldate')).where(SUalias.projid == projid & SUalias.scandate >= startdate & SUalias.scandate <= enddate).alias('q1')
```
but when I try and join that to my existing table
``` python
for date, diskusage in ShortUsage.select(ShortUsage.scandate,fn.SUM(ShortUsage.size))\
.where((ShortUsage.user == user) & (ShortUsage.projid == projid))\
.join(q1, JOIN.LEFT_OUTER, on=(q1.c.alldate == ShortUsage.scandate))\
.group_by(ShortUsage.scandate)\
.order_by(ShortUsage.scandate).tuples():
dates.append(date)
usage.append(diskusage/1000.)
```
It does not report values for all the dates in q1. Is this because it is a LEFT_OUTER join? When I try a full join or RIGHT_OUTER I get this:
```
peewee.OperationalError: RIGHT and FULL OUTER JOINs are not currently supported
```
I am using v2.6.3, and the docs seem to suggest full joins are possible
> By default peewee will use an INNER join, but you can use LEFT OUTER or FULL joins as well
Any assistance would be greatly appreciated.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/710/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/710/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/709 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/709/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/709/comments | https://api.github.com/repos/coleifer/peewee/issues/709/events | https://github.com/coleifer/peewee/issues/709 | 105,968,303 | MDU6SXNzdWUxMDU5NjgzMDM= | 709 | Ability to get a bare cursor | {
"login": "alexanderad",
"id": 888394,
"node_id": "MDQ6VXNlcjg4ODM5NA==",
"avatar_url": "https://avatars.githubusercontent.com/u/888394?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/alexanderad",
"html_url": "https://github.com/alexanderad",
"followers_url": "https://api.github.com/users/alexanderad/followers",
"following_url": "https://api.github.com/users/alexanderad/following{/other_user}",
"gists_url": "https://api.github.com/users/alexanderad/gists{/gist_id}",
"starred_url": "https://api.github.com/users/alexanderad/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/alexanderad/subscriptions",
"organizations_url": "https://api.github.com/users/alexanderad/orgs",
"repos_url": "https://api.github.com/users/alexanderad/repos",
"events_url": "https://api.github.com/users/alexanderad/events{/privacy}",
"received_events_url": "https://api.github.com/users/alexanderad/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Peewee does not alter the isolation level of the postgres connection, unfortunately the `autocommit` parameter is poorly named. When True, it means basically: \"pass queries through the DB-API driver normally and call connection.commit() afterwards\". If False, then you need to call commit() yourself.\n\nWorking with the psycopg2 connection seems like the best route, since you need to set the connection's isolation level. I think psycopg2 issues an implicit `BEGIN` when you are not in autocommit mode, so that may be what's causing the trouble.\n",
"For now I think it will suffice to leave the `autocommit` semantics as they are. There's quite a bit that's confusing given that postgres itself specifies AUTOCOMMIT differently than the DB-API 2.0, and peewee having it's own definition certainly adds to the confusion.\n\nThe code you have there looks good to me, so I'm going to close this.\n"
] | 2015-09-11T08:41:35 | 2015-09-30T03:43:17 | 2015-09-30T03:43:17 | NONE | null | Hello.
I'm trying to get a bare, out of transaction context cursor from within peewee, but for some reason this does not work for me.
``` python
from peewee import *
database = PostgresqlDatabase('test')
database.set_autocommit(False)
database.execute_sql('VACUUM FULL', require_commit=False)
database.set_autocommit(True)
```
I get
``` python
Traceback (most recent call last):
File "autocommit.py", line 9, in <module>
database.execute_sql('VACUUM FULL', require_commit=False)
File "/usr/local/lib/python2.7/site-packages/peewee.py", line 3015, in execute_sql
self.commit()
File "/usr/local/lib/python2.7/site-packages/peewee.py", line 2864, in __exit__
reraise(new_type, new_type(*exc_value.args), traceback)
File "/usr/local/lib/python2.7/site-packages/peewee.py", line 3007, in execute_sql
cursor.execute(sql, params or ())
peewee.InternalError: VACUUM cannot run inside a transaction block
```
Any chance I'm doing this wrong (should not `set_autocommit` take care of that)?
The only one way I found to do this type of query is by operating low level cursor like this:
``` python
@contextlib.contextmanager
def get_bare_cursor(db):
"""Gets the bare cursor which has no transaction context."""
connection = db.get_conn()
old_isolation_level = connection.isolation_level
connection.set_isolation_level(
psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
try:
yield db.get_cursor()
finally:
connection.set_isolation_level(old_isolation_level)
with get_bare_cursor(database) as cursor:
cursor.execute('VACUUM FULL')
```
Thanks.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/709/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/709/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/708 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/708/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/708/comments | https://api.github.com/repos/coleifer/peewee/issues/708/events | https://github.com/coleifer/peewee/issues/708 | 105,443,959 | MDU6SXNzdWUxMDU0NDM5NTk= | 708 | Creating relationships using the backref | {
"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 | [
"Good question, no I hadn't thought about a corollary to the many-to-many add, but that seems useful. I will add it.\n",
"Well, I forgot that the reverse fk descriptor exposes a plain old select query. It seems smelly to me to special case the select query returned by the fk descriptor. Similarly, I don't know that I like the idea to expose a wrapper / subclass with an `add()` method.\n\nSo, at the moment, I will say that there is no such method, but that you can do something like:\n\n``` python\ndef add_child(parent, child):\n child.parent = parent.id\n child.save()\n```\n\nOr, generically:\n\n``` python\ndef add_general(source, reverse_rel, child_inst):\n # source = \"father\", reverse_rel = \"father.children\"\n # reverse_rel.field.to_field.name = \"id\"\n target_val = getattr(source, reverse_rel.field.to_field.name)\n setattr(inst, reverse_field.field.name, target_val)\n inst.save()\n```\n",
"Thanks for the response. I ended up with something like this to determine the complimentary relation name.\n\n```\nfather._meta.reverse_rel['children'].name\n```\n\nWhich correctly returns `parent` in this context. But your response has me questioning the use of reverse_rel for this purpose. Any issues there?\n",
"That's totally fine as well.\n"
] | 2015-09-08T18:33:19 | 2015-09-09T22:14:05 | 2015-09-09T02:44:56 | NONE | null | First off, I'd just like to say that peewee is awesome. I'm currently working on a peewee backend for potion, a REST API library for flask. Here's what I have so far:
https://github.com/biosustain/potion/pull/28
But I'm running into an issue (or possible limitation) of peewee when creating relationships between models. I'm hoping there's an obvious way to do this...
Say I have a self-referencing model such as:
```
class User(Model):
parent = ForeignKeyField('self', null=True, related_name='children')
name = CharField()
```
And I'm working with the following instances:
```
father = User.create(name='foo')
son = User.create(name='bar')
```
Potion provides me with the `father` and `son` instances, as well as the
`children` attribute.
The way that the SQLAlchemy backend handles this is to:
```
getattr(father, 'children').append(son)
```
But there doesn't appear to be a way to create a one-to-many relationship
using the backref with peewee. At least I haven't found a way using
`father.children`.
Is there a simple way to do something like what ManyToManyField has like:
```
father.children.add(son)
```
Or is there a way to determine the matching foreign key field on the `son`
instance using only the `father` instance and the `children` attribute?
I would just as well do:
```
son.parent = father
```
But I don't know about the `parent` attribute or that it compliments the
`childlren` attribute. I need a way to determine this.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/708/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/708/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/707 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/707/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/707/comments | https://api.github.com/repos/coleifer/peewee/issues/707/events | https://github.com/coleifer/peewee/issues/707 | 105,149,109 | MDU6SXNzdWUxMDUxNDkxMDk= | 707 | Prefetch problem | {
"login": "anjianshi",
"id": 5005012,
"node_id": "MDQ6VXNlcjUwMDUwMTI=",
"avatar_url": "https://avatars.githubusercontent.com/u/5005012?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/anjianshi",
"html_url": "https://github.com/anjianshi",
"followers_url": "https://api.github.com/users/anjianshi/followers",
"following_url": "https://api.github.com/users/anjianshi/following{/other_user}",
"gists_url": "https://api.github.com/users/anjianshi/gists{/gist_id}",
"starred_url": "https://api.github.com/users/anjianshi/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/anjianshi/subscriptions",
"organizations_url": "https://api.github.com/users/anjianshi/orgs",
"repos_url": "https://api.github.com/users/anjianshi/repos",
"events_url": "https://api.github.com/users/anjianshi/events{/privacy}",
"received_events_url": "https://api.github.com/users/anjianshi/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Unfortunately not right now, though that's a deficiency in the API I've definitely thought about before. I will think about improving it.\n",
"Ok!\n\nI've done some fix, if someone else have this requirement, maybe they can use this as a temporary solution. ^_^\n\n``` python\nimport peewee\nfrom peewee import PrefetchResult, Query, Model, prefetch\n\ndef _prefetch_add_subquery(sq, subqueries):\n fixed_queries = [PrefetchResult(sq)]\n for i, subquery in enumerate(subqueries):\n # === custom ===\n if isinstance(subquery, tuple):\n subquery, target_model = subquery\n else:\n target_model = None\n # === /custom ===\n\n if not isinstance(subquery, Query) and issubclass(subquery, Model):\n subquery = subquery.select()\n subquery_model = subquery.model_class\n fkf = backref = None\n if target_model is None: # custom\n for j in reversed(range(i + 1)):\n last_query = fixed_queries[j][0]\n last_model = last_query.model_class\n foreign_key = subquery_model._meta.rel_for_model(last_model)\n if foreign_key:\n fkf = getattr(subquery_model, foreign_key.name)\n to_field = getattr(last_model, foreign_key.to_field.name)\n else:\n backref = last_model._meta.rel_for_model(subquery_model)\n\n if fkf or backref:\n break\n else:\n # === custom ===\n last_query = first(fixed_queries, lambda q: q.model == target_model).query\n foreign_key = subquery_model._meta.rel_for_model(target_model)\n fkf = getattr(subquery_model, foreign_key.name)\n to_field = getattr(target_model, foreign_key.to_field.name)\n # === /custom ===\n\n if not (fkf or backref):\n raise AttributeError('Error: unable to find foreign key for '\n 'query: %s' % subquery)\n\n if fkf:\n inner_query = last_query.select(to_field)\n fixed_queries.append(\n PrefetchResult(subquery.where(fkf << inner_query), fkf, False))\n elif backref:\n q = subquery.where(backref.to_field << last_query.select(backref))\n fixed_queries.append(PrefetchResult(q, backref, True))\n\n return fixed_queries\n\ndef first(seq, condition):\n for value in seq:\n if condition(value):\n return value\n return None\n\npeewee.prefetch_add_subquery = _prefetch_add_subquery\n```\n\nUsage:\n\n```\nprefetch(School, SchoolClass, Club, (Student, School))\n```\n"
] | 2015-09-07T05:37:16 | 2015-10-02T01:08:47 | 2015-10-02T01:08:47 | NONE | null | Is there a way to manually specify which foreign key to use, if a model has multiple foreign keys?
For example, there's 4 tables:
```
School
id
name
SchoolClass
id
school (foreign key)
name
Club
id
school (foreign key)
name
Student
id
school (foreign key)
school_class (foreign key)
club (foreign key)
name
```
I want got results like this:
``` json
[
{
"name": "school_name",
"classes": [{"name": "class_name"}, ...],
"clubs": [{"name": "club_name"}, ...],
"students": [{"name": "student_name"}, ...],
}
]
```
``` python
# but when I run the code:
school_pf = prefetch(School, SchoolClass, Club, Student)
for school in pf:
# I can't find student_prefetch attribute in school object
hasattr(school, "student_prefetch") # false
# because it's under the club object
for club in school.club_prefetch:
hasattr(club, "student_prefetch") # true
```
If I can manually specify which foreign key to use, may be I can do something like this:
``` python
prefetch(School, SchoolClass, Club, (Student, School))
```
And the problem will resolve.
Thanks!
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/707/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/707/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/706 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/706/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/706/comments | https://api.github.com/repos/coleifer/peewee/issues/706/events | https://github.com/coleifer/peewee/issues/706 | 105,089,314 | MDU6SXNzdWUxMDUwODkzMTQ= | 706 | peewee+MySQL TimeField returns timedelta object | {
"login": "ibushong",
"id": 9298422,
"node_id": "MDQ6VXNlcjkyOTg0MjI=",
"avatar_url": "https://avatars.githubusercontent.com/u/9298422?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/ibushong",
"html_url": "https://github.com/ibushong",
"followers_url": "https://api.github.com/users/ibushong/followers",
"following_url": "https://api.github.com/users/ibushong/following{/other_user}",
"gists_url": "https://api.github.com/users/ibushong/gists{/gist_id}",
"starred_url": "https://api.github.com/users/ibushong/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/ibushong/subscriptions",
"organizations_url": "https://api.github.com/users/ibushong/orgs",
"repos_url": "https://api.github.com/users/ibushong/repos",
"events_url": "https://api.github.com/users/ibushong/events{/privacy}",
"received_events_url": "https://api.github.com/users/ibushong/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"The fix does not work. The `elif` branch is never reached because the timedelta object evaluates to `True`, so the behavior is the same as before.\n"
] | 2015-09-06T11:42:00 | 2015-09-23T10:14:26 | 2015-09-09T02:48:45 | NONE | null | When using MySQL, the `value` that gets passed into `TimeField.python_value(value)` is a `timedelta` object, which doesn't get properly handled (to turn it into a `time` object).
Modifying `TimeField.python_value` to the following fixes the issue (note the `is None`, as `time(0)` (midnight) evaluates to `False`):
``` python
class TimeField(_BaseFormattedField):
...
def python_value(self, value):
if value and isinstance(value, basestring):
pp = lambda x: x.time()
return format_date_time(value, self.formats, pp)
elif value and isinstance(value, datetime.datetime):
return value.time()
elif value is not None and isinstance(value, datetime.timedelta):
return (datetime.datetime.min + value).time()
else:
return value
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/706/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/706/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/705 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/705/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/705/comments | https://api.github.com/repos/coleifer/peewee/issues/705/events | https://github.com/coleifer/peewee/pull/705 | 105,072,434 | MDExOlB1bGxSZXF1ZXN0NDQyOTYwNDE= | 705 | Fix small typo in docs | {
"login": "jnovinger",
"id": 103499,
"node_id": "MDQ6VXNlcjEwMzQ5OQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/103499?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/jnovinger",
"html_url": "https://github.com/jnovinger",
"followers_url": "https://api.github.com/users/jnovinger/followers",
"following_url": "https://api.github.com/users/jnovinger/following{/other_user}",
"gists_url": "https://api.github.com/users/jnovinger/gists{/gist_id}",
"starred_url": "https://api.github.com/users/jnovinger/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/jnovinger/subscriptions",
"organizations_url": "https://api.github.com/users/jnovinger/orgs",
"repos_url": "https://api.github.com/users/jnovinger/repos",
"events_url": "https://api.github.com/users/jnovinger/events{/privacy}",
"received_events_url": "https://api.github.com/users/jnovinger/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Wontfix\n"
] | 2015-09-06T05:32:38 | 2015-09-06T07:04:36 | 2015-09-06T07:04:36 | CONTRIBUTOR | null | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/705/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/705/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/705",
"html_url": "https://github.com/coleifer/peewee/pull/705",
"diff_url": "https://github.com/coleifer/peewee/pull/705.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/705.patch",
"merged_at": "2015-09-06T07:04:36"
} |
|
https://api.github.com/repos/coleifer/peewee/issues/704 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/704/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/704/comments | https://api.github.com/repos/coleifer/peewee/issues/704/events | https://github.com/coleifer/peewee/issues/704 | 105,030,933 | MDU6SXNzdWUxMDUwMzA5MzM= | 704 | db.atomic() select query cache problem | {
"login": "serkandaglioglu",
"id": 1669906,
"node_id": "MDQ6VXNlcjE2Njk5MDY=",
"avatar_url": "https://avatars.githubusercontent.com/u/1669906?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/serkandaglioglu",
"html_url": "https://github.com/serkandaglioglu",
"followers_url": "https://api.github.com/users/serkandaglioglu/followers",
"following_url": "https://api.github.com/users/serkandaglioglu/following{/other_user}",
"gists_url": "https://api.github.com/users/serkandaglioglu/gists{/gist_id}",
"starred_url": "https://api.github.com/users/serkandaglioglu/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/serkandaglioglu/subscriptions",
"organizations_url": "https://api.github.com/users/serkandaglioglu/orgs",
"repos_url": "https://api.github.com/users/serkandaglioglu/repos",
"events_url": "https://api.github.com/users/serkandaglioglu/events{/privacy}",
"received_events_url": "https://api.github.com/users/serkandaglioglu/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Can you provide more information? What database are you using? What is actually failing? You've shown the delete call, but not the select portion.\n\nI added a test-case and it is passing, so I'm confused what might be going wrong:\n\n``` diff\n\n+\n+ def test_atomic_with_delete(self):\n+ for i in range(3):\n+ User.create(username='u%s' % i)\n+\n+ with test_db.atomic():\n+ User.get(User.username == 'u1').delete_instance()\n+\n+ usernames = [u.username for u in User.select()]\n+ self.assertEqual(sorted(usernames), ['u0', 'u2'])\n```\n\nIf you have a query object, perform a delete/update, then re-iterate the query then yes, you will get cached results. Simply call `query.clone()` in that case to blow away the result cache.\n",
"I use mysql, flask and PooledMySQLDatabase.\n\nDatabase Connection\n\n```\nPooledMySQLDatabase(database,**{\n \"passwd\": password, \"user\": user,\n \"max_connections\":None,\"stale_timeout\":None,\n \"threadlocals\" : True\n })\n```\n\nDeleting\n\n```\nclass DeleteController(OAuthApiController, BaseMethodView):\n\n def __init__(self):\n super(DeleteController, self).__init__()\n\n def get(self,id):\n data = {\"error\" : \"no\", \"message\" : g._(\"Deleting tweet from twitter takes a long time\")}\n\n from flask import copy_current_request_context\n @async\n @copy_current_request_context\n def deleteFromTwitter(oAuthItemReply):\n app.preprocess_request()\n time.sleep(random.randint(60,80))\n try:\n try:\n tweepyOauth = tweepy.OAuthHandler(app.config[\"TWITTER\"][\"consumer_key\"], app.config[\"TWITTER\"][\"consumer_secret\"])\n tweepyOauth.set_access_token(oAuthItemReply.send_oauth_account.oauth_token, oAuthItemReply.send_oauth_account.oauth_token_secret)\n twitterApi = tweepy.API(tweepyOauth,parser=tweepy.parsers.JSONParser())\n a = twitterApi.destroy_status(oAuthItemReply.send_item.oauth_item_id)\n print \"deleted >> \" + str(oAuthItemReply.send_item.oauth_item_id)\n except tweepy.error.TweepError, e:\n oauthError = e.message\n print oauthError\n\n with g.db.connection.atomic() as txn:\n oAuthItemReply.delete_instance()\n except Exception, e:\n print e\n\n try:\n g.db.disconnect()\n except Exception, e:\n print e\n\n return \"ok\"\n\n try:\n with g.db.connection.atomic() as txn:\n RepliedOAuthItemAlias = OAuthItem.alias()\n SendOAuthItemAlias = OAuthItem.alias()\n oAuthItemReply = (OAuthItemReply\n .select(OAuthItemReply,RepliedOAuthItemAlias,SendOAuthItemAlias,OAuthAccount,User)\n .join(RepliedOAuthItemAlias,on=(OAuthItemReply.replied_item==RepliedOAuthItemAlias.id) )\n .switch(OAuthItemReply)\n .join(SendOAuthItemAlias,on=(OAuthItemReply.send_item==SendOAuthItemAlias.id) )\n .switch(OAuthItemReply)\n .join(OAuthAccount)\n .switch(OAuthItemReply)\n .join(User) .where(OAuthItemReply.organization==g.auth.getOrganizationId())\n .where(OAuthItemReply.id==id)\n .get()\n )\n oAuthItemReply.send_status_id = OAuthItemSendStatusEnum.DELETING.value\n oAuthItemReply.save(only=oAuthItemReply.dirty_fields)\n\n # call thread\n deleteFromTwitter(oAuthItemReply)\n\n data[\"oauth_item_reply\"] = model_to_dict(oAuthItemReply, exclude = [OAuthItemReply.reply_thread, OAuthItemReply.organization, User.password],recurse = True) \n except Exception, e:\n data[\"error\"] = \"yes\"\n data[\"message\"] = g._(\"An error occured\")\n print e\n return self.response(data)\n```\n\nSelecting\n\n```\nclass ItemsTwitterController(OAuthApiController, BaseMethodView):\n\n def __init__(self):\n super(ItemsTwitterController, self).__init__()\n\n def get(self):\n data = {\"error\" : \"no\", \"message\" : None, \"take\" : request.args.get(\"take\",10), \"skip\" : request.args.get(\"skip\",0) }\n\n RepliedOAuthItemAlias = OAuthItem.alias()\n SendOAuthItemAlias = OAuthItem.alias()\n oAuthItemsReplies = (OAuthItemReply \n .select(OAuthItemReply,RepliedOAuthItemAlias,SendOAuthItemAlias,OAuthAccount,User)\n .join(RepliedOAuthItemAlias,on=(OAuthItemReply.replied_item==RepliedOAuthItemAlias.id) )\n .switch(OAuthItemReply)\n .join(SendOAuthItemAlias,on=(OAuthItemReply.send_item==SendOAuthItemAlias.id) )\n .switch(OAuthItemReply)\n .join(OAuthAccount)\n .switch(OAuthItemReply)\n .join(User)\n .where(OAuthItemReply.organization==g.auth.getOrganizationId())\n .limit(data[\"take\"])\n .offset(data[\"skip\"])\n )\n\n a = list()\n for item in oAuthItemsReplies:\n a.append(model_to_dict(item, exclude = [OAuthItemReply.reply_thread, OAuthItemReply.organization, User.password],recurse = True))\n data[\"oauth_reply_items\"] = a\n\n\n return self.response(data)\n```\n",
"Can you send minimal example?\nOn Sep 5, 2015 10:58 AM, \"serkandaglioglu\" [email protected] wrote:\n\n> I use mysql, flask and PooledMySQLDatabase.\n> \n> Database Connection\n> \n> PooledMySQLDatabase(database,**{\n> \"passwd\": password, \"user\": user,\n> \"max_connections\":None,\"stale_timeout\":None,\n> \"threadlocals\" : True\n> })\n> \n> Deleting\n> \n> class DeleteController(OAuthApiController, BaseMethodView):\n> \n> ```\n> def __init__(self):\n> super(DeleteController, self).__init__()\n> \n> def get(self,id):\n> data = {\"error\" : \"no\", \"message\" : g._(\"Deleting tweet from twitter takes a long time\")}\n> \n> from flask import copy_current_request_context\n> @async\n> @copy_current_request_context\n> def deleteFromTwitter(oAuthItemReply):\n> app.preprocess_request()\n> time.sleep(random.randint(60,80))\n> try:\n> try:\n> tweepyOauth = tweepy.OAuthHandler(app.config[\"TWITTER\"][\"consumer_key\"], app.config[\"TWITTER\"][\"consumer_secret\"])\n> tweepyOauth.set_access_token(oAuthItemReply.send_oauth_account.oauth_token, oAuthItemReply.send_oauth_account.oauth_token_secret)\n> twitterApi = tweepy.API(tweepyOauth,parser=tweepy.parsers.JSONParser())\n> a = twitterApi.destroy_status(oAuthItemReply.send_item.oauth_item_id)\n> print \"deleted >> \" + str(oAuthItemReply.send_item.oauth_item_id)\n> except tweepy.error.TweepError, e:\n> oauthError = e.message\n> print oauthError\n> \n> with g.db.connection.atomic() as txn:\n> oAuthItemReply.delete_instance()\n> except Exception, e:\n> print e\n> \n> try:\n> g.db.disconnect()\n> except Exception, e:\n> print e\n> \n> return \"ok\"\n> \n> try:\n> with g.db.connection.atomic() as txn:\n> RepliedOAuthItemAlias = OAuthItem.alias()\n> SendOAuthItemAlias = OAuthItem.alias()\n> oAuthItemReply = (OAuthItemReply\n> .select(OAuthItemReply,RepliedOAuthItemAlias,SendOAuthItemAlias,OAuthAccount,User)\n> .join(RepliedOAuthItemAlias,on=(OAuthItemReply.replied_item==RepliedOAuthItemAlias.id) )\n> .switch(OAuthItemReply)\n> .join(SendOAuthItemAlias,on=(OAuthItemReply.send_item==SendOAuthItemAlias.id) )\n> .switch(OAuthItemReply)\n> .join(OAuthAccount)\n> .switch(OAuthItemReply)\n> .join(User) .where(OAuthItemReply.organization==g.auth.getOrganizationId())\n> .where(OAuthItemReply.id==id)\n> .get()\n> )\n> oAuthItemReply.send_status_id = OAuthItemSendStatusEnum.DELETING.value\n> oAuthItemReply.save(only=oAuthItemReply.dirty_fields)\n> \n> # call thread\n> deleteFromTwitter(oAuthItemReply)\n> \n> data[\"oauth_item_reply\"] = model_to_dict(oAuthItemReply, exclude = [OAuthItemReply.reply_thread, OAuthItemReply.organization, User.password],recurse = True)\n> except Exception, e:\n> data[\"error\"] = \"yes\"\n> data[\"message\"] = g._(\"An error occured\")\n> print e\n> return self.response(data)\n> ```\n> \n> Selecting\n> \n> class ItemsTwitterController(OAuthApiController, BaseMethodView):\n> \n> ```\n> def __init__(self):\n> super(ItemsTwitterController, self).__init__()\n> \n> def get(self):\n> data = {\"error\" : \"no\", \"message\" : None, \"take\" : request.args.get(\"take\",10), \"skip\" : request.args.get(\"skip\",0) }\n> \n> RepliedOAuthItemAlias = OAuthItem.alias()\n> SendOAuthItemAlias = OAuthItem.alias()\n> oAuthItemsReplies = (OAuthItemReply\n> .select(OAuthItemReply,RepliedOAuthItemAlias,SendOAuthItemAlias,OAuthAccount,User)\n> .join(RepliedOAuthItemAlias,on=(OAuthItemReply.replied_item==RepliedOAuthItemAlias.id) )\n> .switch(OAuthItemReply)\n> .join(SendOAuthItemAlias,on=(OAuthItemReply.send_item==SendOAuthItemAlias.id) )\n> .switch(OAuthItemReply)\n> .join(OAuthAccount)\n> .switch(OAuthItemReply)\n> .join(User)\n> .where(OAuthItemReply.organization==g.auth.getOrganizationId())\n> .limit(data[\"take\"])\n> .offset(data[\"skip\"])\n> )\n> \n> a = list()\n> for item in oAuthItemsReplies:\n> a.append(model_to_dict(item, exclude = [OAuthItemReply.reply_thread, OAuthItemReply.organization, User.password],recurse = True))\n> data[\"oauth_reply_items\"] = a\n> \n> \n> return self.response(data)\n> ```\n> \n> —\n> Reply to this email directly or view it on GitHub\n> https://github.com/coleifer/peewee/issues/704#issuecomment-137970652.\n",
"@coleifer Ok I am coding a minimal example and after finish I will send example url\n",
"I did a lot of tests and finally found the my mistake. \n\nIn my database class there is this code\n\n```\ndb.set_autocommit(False)\n```\n\nI changed and the problem is solved.\n\n```\ndb.set_autocommit(True)\n```\n\nBut when I set db.set_autocommit(False), this error exists only when I use thread. You can see the usage above.\n\n```\ndef async(f):\n def wrapper(*args, **kwargs):\n thr = Thread(target=f, args=args, kwargs=kwargs)\n thr.start()\n return wrapper\n\nfrom flask import copy_current_request_context\n@async\n@copy_current_request_context\ndef deleteFromTwitter(oAuthItemReply):\n ...\n```\n",
"This appears not to be an issue with peewee, but with your usage. Consult the code and documentation.\n\nIn particular I'm not sure what exactly the nature of the issue is with your code. If you want to take the time to explain it very clearly and simply I might be able to offer guidance.\n",
"Thank you for your offer I fixed for now, it seems there is no problem.\n"
] | 2015-09-05T14:56:26 | 2015-09-06T09:47:04 | 2015-09-05T15:12:05 | NONE | null | When i use transaction with with db.atomic() after delete or update queries, selecting from database still get same results.
For example, deleting a user.
```
with db.atomic() as txn:
User.get(User.user_id==3).delete_instance()
```
After delete query `User.select()` still include user (user_id=3). If I use transaction with `db.begin()` `db.commit()` there is no problem, `User.select()` doesn't include deleted user(user_id=3)
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/704/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/704/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/703 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/703/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/703/comments | https://api.github.com/repos/coleifer/peewee/issues/703/events | https://github.com/coleifer/peewee/issues/703 | 104,907,081 | MDU6SXNzdWUxMDQ5MDcwODE= | 703 | Model.update() not firing pre_save signal | {
"login": "rvindas-gap",
"id": 8330613,
"node_id": "MDQ6VXNlcjgzMzA2MTM=",
"avatar_url": "https://avatars.githubusercontent.com/u/8330613?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/rvindas-gap",
"html_url": "https://github.com/rvindas-gap",
"followers_url": "https://api.github.com/users/rvindas-gap/followers",
"following_url": "https://api.github.com/users/rvindas-gap/following{/other_user}",
"gists_url": "https://api.github.com/users/rvindas-gap/gists{/gist_id}",
"starred_url": "https://api.github.com/users/rvindas-gap/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/rvindas-gap/subscriptions",
"organizations_url": "https://api.github.com/users/rvindas-gap/orgs",
"repos_url": "https://api.github.com/users/rvindas-gap/repos",
"events_url": "https://api.github.com/users/rvindas-gap/events{/privacy}",
"received_events_url": "https://api.github.com/users/rvindas-gap/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Yes this is a known (and obvious) limitation. You'll want to look into triggers.\n",
"Not looking to resurrect the dead here, but could there perhaps be a docs update to reflect this? It says:\n\n> Provides an additional keyword argument created, indicating whether the model is being saved for the first time or updated.\n\nwhich to me made me expect it would work, and thus chase my tail until I came here. :)\n\nThanks!\n",
"See 590ccac3044e13988270017b85ec85dd76161c8b\n",
"Thanks!\n"
] | 2015-09-04T14:57:49 | 2016-04-13T19:59:04 | 2015-09-04T15:02:20 | NONE | null | I have this import in my models: `from playhouse.signals import Model, pre_save` and have a model that inherits from that 'Model' class. I also added the pre_save signal implementation which gets fired when I execute Model.create() or Model.save().
But executing a Model.update().execute() updates the record correctly but it doesn't fire the pre_save signal.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/703/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/703/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/702 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/702/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/702/comments | https://api.github.com/repos/coleifer/peewee/issues/702/events | https://github.com/coleifer/peewee/issues/702 | 104,900,472 | MDU6SXNzdWUxMDQ5MDA0NzI= | 702 | AttributeError: 'Database' object has no attribute 'compiler' | {
"login": "kramer65",
"id": 596581,
"node_id": "MDQ6VXNlcjU5NjU4MQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/596581?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/kramer65",
"html_url": "https://github.com/kramer65",
"followers_url": "https://api.github.com/users/kramer65/followers",
"following_url": "https://api.github.com/users/kramer65/following{/other_user}",
"gists_url": "https://api.github.com/users/kramer65/gists{/gist_id}",
"starred_url": "https://api.github.com/users/kramer65/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/kramer65/subscriptions",
"organizations_url": "https://api.github.com/users/kramer65/orgs",
"repos_url": "https://api.github.com/users/kramer65/repos",
"events_url": "https://api.github.com/users/kramer65/events{/privacy}",
"received_events_url": "https://api.github.com/users/kramer65/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Is database the flask peewee wrapper? Have you tried database.database in that case?\n",
"Awesome! That was indeed the problem!\n\nThanks a million. Both for solving this, and for creating Peewee. We're already using it in several websites now. Big thumbs up!\n"
] | 2015-09-04T14:25:27 | 2015-09-08T15:36:34 | 2015-09-08T15:36:34 | NONE | null | I'm trying to use the peewee migration [described here](http://peewee.readthedocs.org/en/latest/peewee/playhouse.html#schema-migrations). But when running the migrate command I get the error below this message.
I'm on Ubuntu 14.04 with Python 2.7 with the regular MySQL from the apt repos.
Anybody any idea what could be wrong here? All tips are welcome!
```
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/playhouse/migrate.py", line 575, in migrate
operation.run()
File "/usr/local/lib/python2.7/dist-packages/playhouse/migrate.py", line 144, in run
getattr(self.migrator, self.method)(*self.args, **kwargs))
File "/usr/local/lib/python2.7/dist-packages/playhouse/migrate.py", line 138, in _handle_result
self._handle_result(item)
File "/usr/local/lib/python2.7/dist-packages/playhouse/migrate.py", line 135, in _handle_result
result.run()
File "/usr/local/lib/python2.7/dist-packages/playhouse/migrate.py", line 144, in run
getattr(self.migrator, self.method)(*self.args, **kwargs))
File "/usr/local/lib/python2.7/dist-packages/playhouse/migrate.py", line 152, in inner
return fn(self, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/playhouse/migrate.py", line 190, in alter_add_column
field_clause = self.database.compiler().field_definition(field)
AttributeError: 'Database' object has no attribute 'compiler'
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/702/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/702/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/701 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/701/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/701/comments | https://api.github.com/repos/coleifer/peewee/issues/701/events | https://github.com/coleifer/peewee/issues/701 | 104,893,641 | MDU6SXNzdWUxMDQ4OTM2NDE= | 701 | Better support for database routing | {
"login": "foxx",
"id": 651797,
"node_id": "MDQ6VXNlcjY1MTc5Nw==",
"avatar_url": "https://avatars.githubusercontent.com/u/651797?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/foxx",
"html_url": "https://github.com/foxx",
"followers_url": "https://api.github.com/users/foxx/followers",
"following_url": "https://api.github.com/users/foxx/following{/other_user}",
"gists_url": "https://api.github.com/users/foxx/gists{/gist_id}",
"starred_url": "https://api.github.com/users/foxx/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/foxx/subscriptions",
"organizations_url": "https://api.github.com/users/foxx/orgs",
"repos_url": "https://api.github.com/users/foxx/repos",
"events_url": "https://api.github.com/users/foxx/events{/privacy}",
"received_events_url": "https://api.github.com/users/foxx/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Relevant https://github.com/coleifer/peewee/issues/689#issuecomment-133063492\n",
"> - Add two new methods on Model called get_read_db() and get_write_db(). Both of which return cls._meta.database by default, ensuring backwards compatibility\n> - Modify anywhere which uses cls._meta.database to use these methods instead (e.g. select() uses get_read_db() and create_or_get() uses get_write_db() etc).\n\nGood ideas, I will put this together.\n",
"Well, as I was getting into this, it looks to me like `get_read_database()` will be called a bit. I noticed in the \"read slave\" tests that the actual read-slave used was not predictable. This is because there may be multiple calls to `get_read_database()` over the course of a select query, each one of which performs the 'round robin' logic in the ReadSlaveModel. Having the calls isolated to the query classes was a way to work around this, but had other issues as you mentioned.\n\nI'm not positive where this will end up, but I do agree it could be better.\n",
"I don't think this should be handled at the model level. This is a database adapter concern. In our case, we patched the `SelectQuery._execute()` to overcome this issue.\n\nAs I said previously, all our problems are related to the way connections are handled right now (and specifically because we're trying to keep them in a state per model). I think we should all take a fresh look at this and come up with a better API to handle all the use-cases.\n",
"> I don't think this should be handled at the model level. This is a database adapter concern.\n\n@stas, the more I was looking at what the changes would look like, the more I agree with you. Specifically, the scope of the chosen db should be a transaction, in my mind.\n",
"@coleifer I would be happy to help with the postgres parts. Including the read replicas support. I could draft something so you can take a look, just let me know.\n",
"After consideration (and several reply rewrites!), I would agree that the query database persistency should probably be via a transaction, as this is more explicit. Am I correct in saying that `get_read_database/get_write_database` on the model are still required? \n\nAlso happy to assist with testing/review.\n",
"Just for what its worth,you can use `Using` to specify a database to use\nfor a list of models, optionally within a transaction.\n\nScroll down a bit:\n\nhttp://peewee.readthedocs.org/en/latest/peewee/database.html#using-multiple-databases\nOn Sep 14, 2015 5:35 AM, \"Cal Leeming\" [email protected] wrote:\n\n> After consideration (and several reply rewrites!), I would agree that the\n> query database persistency should probably be via a transaction, as this is\n> more explicit. Am I correct in saying that\n> get_read_database/get_write_database on the model are still required?\n> \n> Also happy to assist with testing/review.\n> \n> —\n> Reply to this email directly or view it on GitHub\n> https://github.com/coleifer/peewee/issues/701#issuecomment-140031569.\n",
"> @stas, the more I was looking at what the changes would look like, the more I agree with you. Specifically, the scope of the chosen db should be a transaction, in my mind.\n\nI can add another finding which should be taken into consideration while moving db out of model level.\nImagine you use server side cursor on one model and operate related one:\n\n``` python\nfrom playhouse import postgres_ext\n\nfor user in postgres_ext.ServerSide(User.select()):\n user.do_something_on_related_model(user.posts)\n user.number_of_posts = x\n user.save() \n```\n\nPeewee will not be able to save changes to user instance as User's db is occupied by server side iteration and any changes to User model are \"postponed\" until for loop is actually finished.\n",
"That's another good point @alexanderad, and one I had not considered.\n",
"> Peewee will not be able to save changes to user instance as User's db is occupied by server side iteration and any changes to User model are \"postponed\" until for loop is actually finished.\n\nThe reason they are postponed may be because `ServerSide` runs in a transaction. I don't see anywhere in the code (been a while since I wrote it) that would modify the db itself for server-side cursors.\n",
"@stas -- have you tried the `Using` helper?\n",
"@coleifer nope, in our context we are working with a bunch of models for read-replicas. `Using` would just complicate things. We ended up patching and handling database routing around `SelectQuery._execute`. It sort of works, but it is still a pain because of the way pool handles the connections.\n",
"Not sure there's anything actionable here. Closing.\n",
"@coleifer From what I can see, the original proposal for `get_read_database` and `get_write_database` are still both outstanding and valid, and was waiting on you to either accept or reject. The other comments don't seem to give a clear conclusion, could you give your thoughts/findings please?\n\nPS) Fwiw, I'm still willing to invest time into submitting a PR based on my original post\n",
"@foxx is right. The problems with the way peewee handles connection management is still a major headache.\n",
"Well, to my thinking, I figured that the `Using` context manager took care of most issues ([see docs](http://peewee.readthedocs.org/en/latest/peewee/api.html#Using)).\n\nYou could build higher-level APIs on top of it if that was your preference.\n\nRegarding connection management, again I'm not sure what to do here.\n",
"@coleifer Ah okay, I'll have a try with `Using` and will update this issue if I run into any blockers. Thanks!\n"
] | 2015-09-04T13:42:34 | 2015-12-04T13:08:41 | 2015-12-02T04:54:18 | CONTRIBUTOR | null | As an extension from the discussions in #582 and #583, I'd like to propose a few changes. The implementation of #583 was rejected on the basis of design, as it would have required a connection manager, something which `peewee` does not handle by design (and rightly so).
Playhouse module [ReadSlave](https://github.com/coleifer/peewee/blob/master/playhouse/read_slave.py) implements routing by overloading `select()` and injecting the correct database as determined from `_get_read_database()`, which allows for basic routing of read queries.
However, implementing write queries is significantly harder because methods such as `create_or_get()` reference `cls._meta` directly. I've been able to work around this by extending `ReadSlaveModel` with a custom metaclass, which I've included in this post for future ref, but it's a dirty hack at best.
As such, I would like to propose an extension to `Model`;
- Add two new methods on `Model` called `get_read_db()` and `get_write_db()`. Both of which return `cls._meta.database` by default, ensuring backwards compatibility
- Modify anywhere which uses `cls._meta.database` to use these methods instead (e.g. `select()` uses `get_read_db()` and `create_or_get()` uses `get_write_db()` etc).
I've looked over the source and can't see any problems with implementing the above. It will ensure backwards compatibility whilst allowing developers to implemented true read/write routing.
I would be happy to contribute time putting together a PR for this.
Thoughts?
``` python
class MetaOptionsMixin(object):
"""Late mix-in to provide simple database routing"""
@property
def database(self):
"""Return write db here"""
return your.custom.db.stuff.here
class BaseModelMetaClass(peewee.BaseModel):
"""Add support for database routing"""
# XXX: add proper database router support
def __new__(cls, name, bases, attrs):
"""Add support for automatically registering models with app"""
new_cls = super().__new__(cls, name, bases, attrs)
new_cls._meta.db_name = new_cls._meta.database
extend_instance(new_cls._meta, MetaOptionsMixin)
return new_cls
def selct
class Model(ReadSlaveModel, metaclass=BaseModelMetaClass):
pass
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/701/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/701/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/700 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/700/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/700/comments | https://api.github.com/repos/coleifer/peewee/issues/700/events | https://github.com/coleifer/peewee/pull/700 | 104,803,584 | MDExOlB1bGxSZXF1ZXN0NDQxNzEwNTk= | 700 | Add sensible default from Field if Database() wasn't initialized with fields argument | {
"login": "bdpdx",
"id": 3167275,
"node_id": "MDQ6VXNlcjMxNjcyNzU=",
"avatar_url": "https://avatars.githubusercontent.com/u/3167275?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/bdpdx",
"html_url": "https://github.com/bdpdx",
"followers_url": "https://api.github.com/users/bdpdx/followers",
"following_url": "https://api.github.com/users/bdpdx/following{/other_user}",
"gists_url": "https://api.github.com/users/bdpdx/gists{/gist_id}",
"starred_url": "https://api.github.com/users/bdpdx/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/bdpdx/subscriptions",
"organizations_url": "https://api.github.com/users/bdpdx/orgs",
"repos_url": "https://api.github.com/users/bdpdx/repos",
"events_url": "https://api.github.com/users/bdpdx/events{/privacy}",
"received_events_url": "https://api.github.com/users/bdpdx/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Cool, let's try it out!\n"
] | 2015-09-03T23:53:46 | 2015-09-04T01:37:00 | 2015-09-04T01:36:56 | CONTRIBUTOR | null | Modified QueryCompiler.get_column_type to return an uppercase version of the f argument if the field type doesn't exist in _field_map.
This enables a sensible default if a Field subclass defines a type supported by the underlying database that isn't passed into the Database() constructor via its fields initializer.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/700/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/700/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/700",
"html_url": "https://github.com/coleifer/peewee/pull/700",
"diff_url": "https://github.com/coleifer/peewee/pull/700.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/700.patch",
"merged_at": "2015-09-04T01:36:56"
} |
https://api.github.com/repos/coleifer/peewee/issues/699 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/699/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/699/comments | https://api.github.com/repos/coleifer/peewee/issues/699/events | https://github.com/coleifer/peewee/pull/699 | 104,470,225 | MDExOlB1bGxSZXF1ZXN0NDM5ODU3Nzg= | 699 | djpeewee: Use `model_field.column` instead of `get_attname()` | {
"login": "simonpercivall",
"id": 153659,
"node_id": "MDQ6VXNlcjE1MzY1OQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/153659?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/simonpercivall",
"html_url": "https://github.com/simonpercivall",
"followers_url": "https://api.github.com/users/simonpercivall/followers",
"following_url": "https://api.github.com/users/simonpercivall/following{/other_user}",
"gists_url": "https://api.github.com/users/simonpercivall/gists{/gist_id}",
"starred_url": "https://api.github.com/users/simonpercivall/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/simonpercivall/subscriptions",
"organizations_url": "https://api.github.com/users/simonpercivall/orgs",
"repos_url": "https://api.github.com/users/simonpercivall/repos",
"events_url": "https://api.github.com/users/simonpercivall/events{/privacy}",
"received_events_url": "https://api.github.com/users/simonpercivall/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Nice, thanks!\n"
] | 2015-09-02T12:32:02 | 2015-09-06T17:30:58 | 2015-09-02T13:14:15 | CONTRIBUTOR | null | This bacame an issue when the column was named differently than the
standard "<thing>_id".
Fixes #698
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/699/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/699/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/699",
"html_url": "https://github.com/coleifer/peewee/pull/699",
"diff_url": "https://github.com/coleifer/peewee/pull/699.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/699.patch",
"merged_at": "2015-09-02T13:14:15"
} |
https://api.github.com/repos/coleifer/peewee/issues/698 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/698/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/698/comments | https://api.github.com/repos/coleifer/peewee/issues/698/events | https://github.com/coleifer/peewee/issues/698 | 104,468,312 | MDU6SXNzdWUxMDQ0NjgzMTI= | 698 | djpeewee: ForeignKeys with non-standard column names doesn't work | {
"login": "simonpercivall",
"id": 153659,
"node_id": "MDQ6VXNlcjE1MzY1OQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/153659?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/simonpercivall",
"html_url": "https://github.com/simonpercivall",
"followers_url": "https://api.github.com/users/simonpercivall/followers",
"following_url": "https://api.github.com/users/simonpercivall/following{/other_user}",
"gists_url": "https://api.github.com/users/simonpercivall/gists{/gist_id}",
"starred_url": "https://api.github.com/users/simonpercivall/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/simonpercivall/subscriptions",
"organizations_url": "https://api.github.com/users/simonpercivall/orgs",
"repos_url": "https://api.github.com/users/simonpercivall/repos",
"events_url": "https://api.github.com/users/simonpercivall/events{/privacy}",
"received_events_url": "https://api.github.com/users/simonpercivall/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2015-09-02T12:23:25 | 2015-09-02T13:14:15 | 2015-09-02T13:14:15 | CONTRIBUTOR | null | Having a ref that doesn't match the "<thing>_id" works badly when translating Django models to Peewee.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/698/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/698/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/697 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/697/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/697/comments | https://api.github.com/repos/coleifer/peewee/issues/697/events | https://github.com/coleifer/peewee/issues/697 | 104,463,078 | MDU6SXNzdWUxMDQ0NjMwNzg= | 697 | auto_increment differrent in create and create_or_get | {
"login": "tablecell",
"id": 6591466,
"node_id": "MDQ6VXNlcjY1OTE0NjY=",
"avatar_url": "https://avatars.githubusercontent.com/u/6591466?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/tablecell",
"html_url": "https://github.com/tablecell",
"followers_url": "https://api.github.com/users/tablecell/followers",
"following_url": "https://api.github.com/users/tablecell/following{/other_user}",
"gists_url": "https://api.github.com/users/tablecell/gists{/gist_id}",
"starred_url": "https://api.github.com/users/tablecell/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/tablecell/subscriptions",
"organizations_url": "https://api.github.com/users/tablecell/orgs",
"repos_url": "https://api.github.com/users/tablecell/repos",
"events_url": "https://api.github.com/users/tablecell/events{/privacy}",
"received_events_url": "https://api.github.com/users/tablecell/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"You should be using `PrimaryKeyField` instead of `IntegerField`. The former is auto increment, while the latter is just an arbitrary int field.\n"
] | 2015-09-02T11:49:03 | 2015-09-02T12:34:48 | 2015-09-02T12:34:48 | NONE | null | ``` python
from peewee import *
from pprint import pprint
db = SqliteDatabase('people.db')
class User(Model):
uid = IntegerField(primary_key=True)
name = CharField()
password = FixedCharField()
class Meta:
database = db # This model uses the "people.db" database.
#db.create_tables([User])
username='xx'
try:
user = User.get(name=username)
#user = User.get_or_create(name=username)
pprint(user.uid)
except:
user=User.create(name=username,password='xx')
print(user.uid)
```
the result is None
by get_or_create the result is 1
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/697/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/697/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/696 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/696/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/696/comments | https://api.github.com/repos/coleifer/peewee/issues/696/events | https://github.com/coleifer/peewee/issues/696 | 104,460,080 | MDU6SXNzdWUxMDQ0NjAwODA= | 696 | model_to_dict ForeignKeyField problem | {
"login": "serkandaglioglu",
"id": 1669906,
"node_id": "MDQ6VXNlcjE2Njk5MDY=",
"avatar_url": "https://avatars.githubusercontent.com/u/1669906?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/serkandaglioglu",
"html_url": "https://github.com/serkandaglioglu",
"followers_url": "https://api.github.com/users/serkandaglioglu/followers",
"following_url": "https://api.github.com/users/serkandaglioglu/following{/other_user}",
"gists_url": "https://api.github.com/users/serkandaglioglu/gists{/gist_id}",
"starred_url": "https://api.github.com/users/serkandaglioglu/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/serkandaglioglu/subscriptions",
"organizations_url": "https://api.github.com/users/serkandaglioglu/orgs",
"repos_url": "https://api.github.com/users/serkandaglioglu/repos",
"events_url": "https://api.github.com/users/serkandaglioglu/events{/privacy}",
"received_events_url": "https://api.github.com/users/serkandaglioglu/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"In the current master branch there is a new param for `model_to_dict` called `extra_attrs`. You can use that parameter to indicate you want to include the `updater_id`:\n\n``` python\nmodel_to_dict(User, exclude=[User.updater], extra_attrs=['updater_id'])\n```\n",
"@coleifer \nCould you add an argument for `model_to_dict` like include_only_sql_seleted_fields=False? If we send `include_only_sql_seleted_fields=True` the dict has only field which selected in sql query. \n\nFor example:\n\n```\nInserter = User.alias()\nuser = (User\n .select(User, Inserter )\n .join(Inserter, JOIN.LEFT_OUTER, on=(User.inserter==Inserter.user_id))\n .where(User.user_id=userId )\n .get()\n )\n\ndata[\"user\"] = model_to_dict(user, include_only_sql_seleted_fields=True)\n```\n\nThe output will be like this : \n\n```\n{\n \"user_id\" : 1,\n \"full_name\" : \"Test\",\n \"email\" : \"[email protected]\",\n \"user_status_id\" : 1,\n \"activation_key\" : None,\n \"mobile\" : \"0555\",\n \"insert_date\" : datetime,\n \"update_date\" : datetime,\n \"updater_id\" : 2,\n \"inserter\" : {\n \"user_id\" : 2,\n \"full_name\" : \"Test 2\",\n \"email\" : \"[email protected]\",\n \"user_status_id\" : 1,\n \"activation_key\" : None,\n \"mobile\" : \"05553\",\n \"insert_date\" : datetime,\n \"update_date\" : datetime,\n \"updater_id\" : 2,\n \"inserter_id\" : 5\n }\n}\n```\n",
"Well, I'd need the actual query in that case so I could know which fields were selected. Something like:\n\n``` python\nmodel_to_dict(user, fields_from_query=query)\n```\n",
"Don't you keep the query in model object(user) ?\n",
"Added `fields_from_query` a93b6268a77039856d0c8ea70e5ded9996c00719.\n\n> Don't you keep the query in model object(user) ?\n\nNo.\n",
"@coleifer Thanks.\n"
] | 2015-09-02T11:33:59 | 2015-09-04T14:13:59 | 2015-09-02T13:11:41 | NONE | null | The Model
```
class User(BaseModel):
user_id = PrimaryKeyField( db_column="user_id")
inserter = ForeignKeyField("self",db_column="inserter_id",to_field="user_id")
updater = ForeignKeyField("self",db_column="updater_id",to_field="user_id", related_name="updated_users")
email = CharField()
password = CharField()
full_name = CharField()
user_status_id = IntegerField(null=False, default=UserStatusEnum.ACTIVE.value)
activation_key = CharField()
mobile = CharField()
insert_date = DateTimeField(null=True,default=fn.NOW())
update_date = DateTimeField(null=True)
```
```
Inserter = User.alias()
user = (User
.select(User, Inserter )
.join(Inserter, JOIN.LEFT_OUTER, on=(User.inserter==Inserter.user_id))
.where(User.user_id=userId )
.get()
)
data["user"] = model_to_dict(user )
```
When I call `model_to_dict(user )` peewee run sql query for getting updater. I don't want to get updater from database i just only need updater_id. When i call model_to_dict(user , exclude[User.updater]) the dict doesn't have updater field, but i need updater_id not instance of model. When I call `model_to_dict(user, recurse=False )` the dict has updater field(its value is updater_id) but it has another problem. Because of `recurse=False` it doesn't include inserter. There is no way that i want to do.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/696/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/696/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/695 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/695/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/695/comments | https://api.github.com/repos/coleifer/peewee/issues/695/events | https://github.com/coleifer/peewee/issues/695 | 104,201,125 | MDU6SXNzdWUxMDQyMDExMjU= | 695 | Attribute Error during exception handling | {
"login": "conqp",
"id": 3766192,
"node_id": "MDQ6VXNlcjM3NjYxOTI=",
"avatar_url": "https://avatars.githubusercontent.com/u/3766192?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/conqp",
"html_url": "https://github.com/conqp",
"followers_url": "https://api.github.com/users/conqp/followers",
"following_url": "https://api.github.com/users/conqp/following{/other_user}",
"gists_url": "https://api.github.com/users/conqp/gists{/gist_id}",
"starred_url": "https://api.github.com/users/conqp/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/conqp/subscriptions",
"organizations_url": "https://api.github.com/users/conqp/orgs",
"repos_url": "https://api.github.com/users/conqp/repos",
"events_url": "https://api.github.com/users/conqp/events{/privacy}",
"received_events_url": "https://api.github.com/users/conqp/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Thank you, this should be fixed.\n"
] | 2015-09-01T07:08:05 | 2015-09-01T18:31:27 | 2015-09-01T18:31:27 | CONTRIBUTOR | null | Hi, this is probably a bug:
```
Traceback (most recent call last):
File "/usr/local/lib/python3.4/dist-packages/PyMySQL-0.6.3-py3.4.egg/pymysql/connections.py", line 823, in _connect
(self.host, self.port), self.connect_timeout)
File "/usr/lib/python3.4/socket.py", line 491, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
File "/usr/lib/python3.4/socket.py", line 530, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -2] Name or service not known
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.4/dist-packages/homeinfo/peewee/__init__.py", line 36, in execute_sql
return super().execute_sql(*args, **kwargs)
File "/usr/local/lib/python3.4/dist-packages/peewee-2.6.3-py3.4-linux-x86_64.egg/peewee.py", line 3442, in execute_sql
with self.execution_context():
File "/usr/local/lib/python3.4/dist-packages/peewee-2.6.3-py3.4-linux-x86_64.egg/peewee.py", line 3916, in __enter__
**self.database.connect_kwargs)
File "/usr/local/lib/python3.4/dist-packages/peewee-2.6.3-py3.4-linux-x86_64.egg/peewee.py", line 3841, in _connect
return mysql.connect(db=database, **conn_kwargs)
File "/usr/local/lib/python3.4/dist-packages/PyMySQL-0.6.3-py3.4.egg/pymysql/__init__.py", line 88, in Connect
return Connection(*args, **kwargs)
File "/usr/local/lib/python3.4/dist-packages/PyMySQL-0.6.3-py3.4.egg/pymysql/connections.py", line 647, in __init__
self._connect()
File "/usr/local/lib/python3.4/dist-packages/PyMySQL-0.6.3-py3.4.egg/pymysql/connections.py", line 862, in _connect
"Can't connect to MySQL server on %r (%s)" % (self.host, e))
pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on 'alt.homeinfo.de' ([Errno -2] Name or service not known)")
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.4/dist-packages/homie/retard.py", line 258, in _export
exporter.openimmo = data
File "/usr/local/lib/python3.4/dist-packages/homie/api/interface.py", line 403, in openimmo
for delete_id in delete_ids:
File "/usr/local/lib/python3.4/dist-packages/homie/api/interface.py", line 350, in _extr_idents
for real_estate in real_estates:
File "/usr/local/lib/python3.4/dist-packages/homie/mods/openimmodb/interface.py", line 93, in _retrieve
for record in self._related_records(immobilie.openimmo_obid):
File "/usr/local/lib/python3.4/dist-packages/homie/mods/openimmodb/interface.py", line 122, in _related_records
yield from model.select().where(model.openimmo_obid == ident)
File "/usr/local/lib/python3.4/dist-packages/peewee-2.6.3-py3.4-linux-x86_64.egg/peewee.py", line 2944, in __iter__
return iter(self.execute())
File "/usr/local/lib/python3.4/dist-packages/peewee-2.6.3-py3.4-linux-x86_64.egg/peewee.py", line 2937, in execute
self._qr = ResultWrapper(model_class, self._execute(), query_meta)
File "/usr/local/lib/python3.4/dist-packages/peewee-2.6.3-py3.4-linux-x86_64.egg/peewee.py", line 2631, in _execute
return self.database.execute_sql(sql, params, self.require_commit)
File "/usr/local/lib/python3.4/dist-packages/homeinfo/peewee/__init__.py", line 36, in execute_sql
return super().execute_sql(*args, **kwargs)
File "/usr/local/lib/python3.4/dist-packages/peewee-2.6.3-py3.4-linux-x86_64.egg/peewee.py", line 3928, in __exit__
self.txn.__exit__(exc_type, exc_val, exc_tb)
File "/usr/local/lib/python3.4/dist-packages/peewee-2.6.3-py3.4-linux-x86_64.egg/peewee.py", line 3995, in __exit__
self.rollback(False)
File "/usr/local/lib/python3.4/dist-packages/peewee-2.6.3-py3.4-linux-x86_64.egg/peewee.py", line 3980, in rollback
self.db.rollback()
File "/usr/local/lib/python3.4/dist-packages/peewee-2.6.3-py3.4-linux-x86_64.egg/peewee.py", line 3456, in rollback
self.get_conn().rollback()
File "/usr/local/lib/python3.4/dist-packages/peewee-2.6.3-py3.4-linux-x86_64.egg/peewee.py", line 3384, in get_conn
return self.__local.context_stack[-1].connection
AttributeError: 'ExecutionContext' object has no attribute 'connection'
```
- peewee version: a646d3e4608c866a8442e4f7b0c5694587bba9d4
- PyMySQL version: 7fec4a21efb43cec5f3ae6af11ca7eff373e44be
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/695/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/695/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/694 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/694/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/694/comments | https://api.github.com/repos/coleifer/peewee/issues/694/events | https://github.com/coleifer/peewee/issues/694 | 103,874,720 | MDU6SXNzdWUxMDM4NzQ3MjA= | 694 | Discerning what fields "were dirty" in post_save signal | {
"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 | [
"Why not just add a `pre_save` signal handler that sets an additional attribute on the class:\n\n``` python\n@pre_save(sender=SomeModel)\ndef pre_save_handler(sender, instance, created):\n instance._dirty_field_cache = instance.dirty_fields\n\n@post_save(sender=SomeModel)\ndef post_save_handler(sender, instance, created):\n # do something with instance._dirty_field_cache\n pass\n```\n"
] | 2015-08-29T19:55:18 | 2015-09-01T18:33:56 | 2015-09-01T18:33:56 | CONTRIBUTOR | null | Hi! I'm trying to figure out what might be the cleanest way to know what model fields "were dirty" (or, more specifically, if a given field changed) in a signal-supporting model.
I'm thinking adding some kind of field on the signal base `Model` that gets set during the `save` method which is set to the contents of `instance.dirty_fields` just before the superclass `save` method is invoked. Do you think it would be possible to subclass the signal-support `Model` and override the `save` logic to do that? Any red flags come up in your mind? Maybe just have an additional parameter that can go into a connected signal handler, `modified`, which is those values.
Model and save method in question:
https://github.com/coleifer/peewee/blob/master/playhouse/signals.py#L65
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/694/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/694/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/693 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/693/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/693/comments | https://api.github.com/repos/coleifer/peewee/issues/693/events | https://github.com/coleifer/peewee/issues/693 | 103,418,855 | MDU6SXNzdWUxMDM0MTg4NTU= | 693 | How can I control retry times when I use sql_error_handler to retry SQL execution? | {
"login": "messense",
"id": 1556054,
"node_id": "MDQ6VXNlcjE1NTYwNTQ=",
"avatar_url": "https://avatars.githubusercontent.com/u/1556054?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/messense",
"html_url": "https://github.com/messense",
"followers_url": "https://api.github.com/users/messense/followers",
"following_url": "https://api.github.com/users/messense/following{/other_user}",
"gists_url": "https://api.github.com/users/messense/gists{/gist_id}",
"starred_url": "https://api.github.com/users/messense/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/messense/subscriptions",
"organizations_url": "https://api.github.com/users/messense/orgs",
"repos_url": "https://api.github.com/users/messense/repos",
"events_url": "https://api.github.com/users/messense/events{/privacy}",
"received_events_url": "https://api.github.com/users/messense/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Figure out a way myself. Sample codes:\n\n``` python\nimport logging\n\nfrom playhouse.pool import PooledMySQLDatabase\nfrom peewee import OperationalError\n\n\nlogger = logging.getLogger(__name__)\n\n\nclass RetryPooledMySQLDatabase(PooledMySQLDatabase):\n\n def sql_error_handler(self, exception, sql, params, require_commit):\n if isinstance(exception, OperationalError):\n self.close()\n self.connect()\n return True\n\n def execute_sql(self, sql, params=None, require_commit=True):\n retry_times = 0\n max_retry_times = 3\n while True:\n try:\n return super(RetryPooledMySQLDatabase, self).execute_sql(\n sql, params, require_commit\n )\n except OperationalError:\n if retry_times >= max_retry_times:\n logger.warning(\n 'Maximum retry times(%s) exceeded, give up retrying.',\n max_retry_times,\n )\n raise\n\n retry_times += 1\n logger.warning(\n 'Executing SQL(%s), params(%s) error, retrying %s/%s time',\n sql,\n params,\n retry_times,\n max_retry_times,\n )\n```\n"
] | 2015-08-27T03:27:39 | 2015-08-27T05:10:12 | 2015-08-27T05:10:12 | CONTRIBUTOR | null | I am using the RetryDatabase example code I found in peewee test cases.
https://github.com/coleifer/peewee/blob/db328731034e45fb4f8a1a2a4a562da1dc0d1f23/playhouse/tests/test_database.py#L183
The problem is that I want to control retry times manually. How can I do that in a nice way?
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/693/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/693/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/692 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/692/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/692/comments | https://api.github.com/repos/coleifer/peewee/issues/692/events | https://github.com/coleifer/peewee/issues/692 | 103,171,169 | MDU6SXNzdWUxMDMxNzExNjk= | 692 | Multiple joins to same table | {
"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 | [
"If you add an alias to the second join specifying which attribute to use, peewee will do the right thing:\n\n``` python\nOpponent = User.alias()\nquery = (GameResult\n .select(GameResult, User, Opponent)\n .join(User, on=(GameResult.user == User.id))\n .switch(GameResult)\n .join(Opponent, on=(GameResult.opponent == Opponent.id).alias('opponent'))\n .order_by(Game.id))\n```\n\nI think peewee has enough info here, though, to perhaps determine that the `opponent` field is what we want. I will look into a fix.\n",
"I've added some changes to the join logic and this should now be a bit smarter about assigning the joined instance to the correct attribute without requiring an explicit alias.\n",
"Hey Charles, I'm just trying this out with the latest copy of master and doesn't seem to be working for me, have you pushed the commit or am I doing something wrong?\n\n```\nclass User(Model):\n uuid = UUIDField(primary_key=True)\n name = CharField()\n\nclass Brief(Model):\n uuid = UUIDField(primary_key=True)\n user = ForeignKeyField(User, null=False)\n assignee = ForeignKeyField(User, null=True)\n ...\n\nAssignee = User.alias()\nquery = Brief.select(Brief, User, Assignee)\n .join(User, on=(User.uuid == Brief.user))\n .switch(Brief)\n .join(Assignee, on=(Assignee.uuid == Brief.assignee).alias(\"assignee\"))\n .order_by(...)\n```\n\nIt's not applying the node alias properly by the looks of it because I get:\n\n```\nSELECT\n \"t1\".\"uuid\", \"t1\".\"user_id\", \"t1\".\"state\", \"t1\".\"sent\", \"t1\".\"assignee_id\",\n \"t2\".\"uuid\", \"t2\".\"name\",\n \"t3\".\"uuid\", \"t3\".\"name\"\n\nFROM \"brief\" AS t1\n INNER JOIN \"user\" AS t2 ON (\"t2\".\"uuid\" = \"t1\".\"user_id\")\n INNER JOIN \"user\" AS t2 ON (\"t3\".\"uuid\" = \"t1\".\"assignee_id\")\n\nORDER BY \"t1\".\"sent\", \"t1\".\"created\"\n```\n\nIt correctly applies it inside the node but not to the table alias, I therefore get.\n\n```\nProgrammingError: table name \"t2\" specified more than once\n```\n\nSorry for reopening a closed issue, let me know if you want a separate issue.\n",
"Using your code I get the right SQL:\n\n``` python\nfrom peewee import *\n\ndb = SqliteDatabase(':memory:')\n\nclass User(Model):\n uuid = CharField(primary_key=True)\n name = CharField()\n\n class Meta:\n database = db\n\nclass Brief(Model):\n uuid = CharField(primary_key=True)\n user = ForeignKeyField(User)\n assignee = ForeignKeyField(User, null=True, related_name='_xxx')\n\n class Meta:\n database = db\n\ndb.create_tables([User, Brief])\n\nAssignee = User.alias()\nquery = (Brief\n .select(Brief, User, Assignee)\n .join(User, on=(User.uuid == Brief.user))\n .switch(Brief)\n .join(Assignee, on=(Assignee.uuid == Brief.assignee).alias('assignee'))\n .order_by(User.name))\nprint query\n```\n\nResult:\n\n``` sql\nSELECT \"t1\".\"uuid\", \"t1\".\"user_id\", \"t1\".\"assignee_id\", \"t2\".\"uuid\", \"t2\".\"name\", \"t3\".\"uuid\", \"t3\".\"name\" \nFROM \"brief\" AS t1 \nINNER JOIN \"user\" AS t2 ON (\"t2\".\"uuid\" = \"t1\".\"user_id\") \nINNER JOIN \"user\" AS t3 ON (\"t3\".\"uuid\" = \"t1\".\"assignee_id\") \nORDER BY \"t2\".\"name\"\n```\n\nWhat am I missing?\n",
"I'm experiencing a similar issue. (also sorry for posting in old issue).\n\nI've written a script to demonstrate. If not a bug , hopefully can demonstrate\n\nEDIT - updating to remove a join\n\n```\nfrom __future__ import division\nfrom peewee import Model, JOIN_LEFT_OUTER\nfrom playhouse.shortcuts import model_to_dict\nfrom peewee import fn, SQL, JOIN\nfrom peewee import CharField, DateTimeField, BigIntegerField, BooleanField, IntegerField, ForeignKeyField, Proxy, TextField, PrimaryKeyField,DoubleField\nfrom playhouse.postgres_ext import PostgresqlExtDatabase\nfrom playhouse.postgres_ext import BinaryJSONField, ArrayField, TSVectorField\n\n\ndef dbfactory(dbname=\"hai\"):\n # https://github.com/coleifer/peewee/issues/410\n host = \"/tmp/\"\n user = \"hendler\"\n # user = \"root\"\n password = \"rootroot\"\n # max_connections = 350\n # stale_timeout = 3000\n # connection = PooledMySQLDatabase(dbname, host=host, user=user, passwd=password, charset='utf8', use_unicode=True, max_connections=max_connections, stale_timeout=stale_timeout )\n connection = PostgresqlExtDatabase(dbname, host=host, user=user, password=password, autocommit=True, autorollback=True)\n # connection.connect()\n return connection\n\n\nclass BaseModel(Model):\n \"\"\"Simple table with prevs and an integer.\"\"\"\n\n class Meta:\n \"\"\"Standard meta field.\"\"\"\n\n database = dbfactory()\n\n\n# https://github.com/coleifer/peewee/issues/692\n\n\nclass User(BaseModel):\n id = PrimaryKeyField()\n\n\nclass Question(BaseModel):\n id = PrimaryKeyField()\n\n\nclass Answer(BaseModel):\n id = PrimaryKeyField()\n user = ForeignKeyField(User, related_name='answerusers')\n question = ForeignKeyField(Question, related_name='answerquestions')\n\n\nclass Page(BaseModel):\n id = PrimaryKeyField()\n user = ForeignKeyField(User, related_name='pageusers')\n question = ForeignKeyField(Question, related_name='pagequestions')\n\n\nclass Comment(BaseModel):\n id = PrimaryKeyField()\n user = ForeignKeyField(User, related_name='commentusers')\n question = ForeignKeyField(Question, related_name='commentquestions')\n\n\ndef setup():\n print \"creating table\"\n print \"\\tuser -> 1:n -> pages -> 1:1 -> questions -> 1:n -> answers\"\n print \"\\tuser -> 1:n -> comments -> 1:1 -> questions -> 1:n -> answers\"\n # drop tables every time\n if Commment.table_exists():\n Commment.drop_table()\n if Page.table_exists():\n Page.drop_table()\n if Answer.table_exists():\n Answer.drop_table()\n if Question.table_exists():\n Question.drop_table()\n if User.table_exists():\n User.drop_table()\n\n User.create_table()\n Question.create_table()\n Answer.create_table()\n Page.create_table()\n Commment.create_table()\n\n user1 = User.create()\n user2 = User.create()\n\n question1 = Question.create()\n question2 = Question.create()\n question3 = Question.create()\n\n answer1 = Answer.create(question=question1, user=user1)\n answer2 = Answer.create(question=question2, user=user1)\n answer3 = Answer.create(question=question3, user=user1)\n answer4 = Answer.create(question=question3, user=user2)\n answer5 = Answer.create(question=question3, user=user2)\n\n page1 = Page.create(user=user1, question=question1)\n page2 = Page.create(user=user2, question=question3)\n comment1 = Comment.create(user=user2, question=question3)\n comment2 = Comment.create(user=user1, question=question2)\n\ndef runtest1():\n results = User.select(User, Page, Comment, Question, Answer)\n results = results.join(Page).join(Answer, on=(Answer.question_id == Page.question_id))\n results = results.switch(User).join(Comment).join(Answer, on=(Answer.question_id == Comment.question_id))\n print results.sql()\n for result in results:\n print result\n\ndef runtest2():\n # , on=(ActionTemplate.id == Action.actiontemplate)).alias('at')\n results = User.select(User, Page, Commment, Question, Answer)\n results = results.join(Page, on=(Page.user_id == User.id))\n results = results.join(Question, on=(Question.id ==Page.question_id).alias(\"page_question\"))\n results = results.join(Answer, on=(Answer.question_id == Page.question_id))\n results = results.switch(User)\n results = results.join(Comment, on=(Comment.user_id == User.id))\n results = results.join(Question, on=(Question.id == Comment.question_id).alias(\"comment_question\"))\n results = results.join(Answer, on=(Answer.question_id == Comment.question_id))\n\n print results.sql()\n for result in results:\n print result\n\nif __name__ == \"__main__\":\n import traceback\n setup()\n try:\n runtest1()\n except Exception as e:\n print e.message\n # print traceback.format_exc()\n try:\n runtest2()\n except Exception as e:\n print e.message\n # print traceback.format_exc()\n\n\n\n```\n\n The output\n\n```\ncreating table\n user -> 1:n -> pages -> 1:1 -> questions -> 1:n -> answers\n user -> 1:n -> comments -> 1:1 -> questions -> 1:n -> answers\nMissing required join predicate.\n('SELECT \"t1\".\"id\", \"t4\".\"id\", \"t4\".\"user_id\", \"t4\".\"question_id\", \"t5\".\"id\", \"t5\".\"user_id\", \"t5\".\"question_id\", \"t2\".\"id\", \"t3\".\"id\", \"t3\".\"user_id\", \"t3\".\"question_id\" FROM \"user\" AS t1 INNER JOIN \"page\" AS t4 ON (\"t1\".\"id\" IS %s) INNER JOIN \"comment\" AS t5 ON (\"t1\".\"id\" IS %s) INNER JOIN \"question\" AS t2 ON (\"t2\".\"id\" IS %s) INNER JOIN \"answer\" AS t3 ON (\"t2\".\"id\" = \"t3\".\"question_id\") INNER JOIN \"answer\" AS t3 ON (\"t2\".\"id\" = \"t3\".\"question_id\") INNER JOIN \"question\" AS t2 ON (\"t2\".\"id\" IS %s)', [None, None, None, None])\ntable name \"t3\" specified more than once\n```\n",
"I don't get the error with aliasing, AND enforcing left outer joins. BUT the params values look off \n`[None, None, None, None]`\nWithout the left outer, the joins don't work. \n\n```\n AnswerAlias = Answer.alias()\n QuestionAlias = Question.alias()\n\n results = User.select(User, Page, Comment, Question, Answer, QuestionAlias, AnswerAlias)\n results = results.join(Page, JOIN.LEFT_OUTER, on=(Page.user_id == User.id))\n results = results.join(Question, JOIN.LEFT_OUTER, on=(Question.id == Page.question_id))\n results = results.join(Answer, JOIN.LEFT_OUTER, on=(Answer.question_id == Page.question_id))\n results = results.switch(User)\n results = results.join(Comment, JOIN.LEFT_OUTER, on=(Comment.user_id == User.id))\n results = results.join(QuestionAlias, JOIN.LEFT_OUTER, on=(QuestionAlias.id == Comment.question_id) )\n results = results.join(AnswerAlias, JOIN.LEFT_OUTER, on=(AnswerAlias.question_id == Comment.question_id))\n\n print results.sql()\n print results.count()\n\n```\n\n`('SELECT \"t1\".\"id\", \"t2\".\"id\", \"t2\".\"user_id\", \"t2\".\"question_id\", \"t3\".\"id\", \"t3\".\"user_id\", \"t3\".\"question_id\", \"t6\".\"id\", \"t7\".\"id\", \"t7\".\"user_id\", \"t7\".\"question_id\", \"t4\".\"id\", \"t5\".\"id\", \"t5\".\"user_id\", \"t5\".\"question_id\" FROM \"user\" AS t1 LEFT OUTER JOIN \"page\" AS t2 ON (\"t1\".\"id\" IS %s) LEFT OUTER JOIN \"comment\" AS t3 ON (\"t1\".\"id\" IS %s) LEFT OUTER JOIN \"question\" AS t4 ON (\"t4\".\"id\" IS %s) LEFT OUTER JOIN \"answer\" AS t5 ON (\"t4\".\"id\" = \"t5\".\"question_id\") LEFT OUTER JOIN \"question\" AS t6 ON (\"t6\".\"id\" IS %s) LEFT OUTER JOIN \"answer\" AS t7 ON (\"t6\".\"id\" = \"t7\".\"question_id\")', [None, None, None, None])`\n",
"For fuck's sake did you have to put \"Bug\" in front of every class?\n"
] | 2015-08-26T04:21:24 | 2016-02-24T07:18:31 | 2015-08-27T01:58:46 | OWNER | null | Hello,
Following the example you've given, I constructed a query for my models, which are like the models below:
``` python
class User(db.Model):
username = CharField()
class GameResult(db.Model):
user = ForeignKeyField(User)
opponent = ForeignKeyField(User, related_name='opponent_gameresult_set', null=True)
```
And the query...
``` python
OpponentUser = User.alias()
result = GameResult.select(GameResult, User, OpponentUser)\
.switch(GameResult).join(User, on=GameResult.user)\
.switch(GameResult).join(OpponentUser, JOIN.LEFT_OUTER,
on=(GameResult.opponent==OpponentUser.id))\
.where(GameResult.id==id).get()
```
The problem is that result.user and result.opponent are always the same (but they shouldn't be). It seems like result.user get overwritten by whatever the value is for result.opponent. Even when result.opponent is None, result.user will contain a model instance but all the fields (except for the id) are set to None. Is this a bug or is there something wrong with my query?
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/692/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/692/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/691 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/691/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/691/comments | https://api.github.com/repos/coleifer/peewee/issues/691/events | https://github.com/coleifer/peewee/issues/691 | 102,791,483 | MDU6SXNzdWUxMDI3OTE0ODM= | 691 | Allow arbitrary model attrs and methods to be serialized in model_to_dict() | {
"login": "coleifer",
"id": 119974,
"node_id": "MDQ6VXNlcjExOTk3NA==",
"avatar_url": "https://avatars.githubusercontent.com/u/119974?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/coleifer",
"html_url": "https://github.com/coleifer",
"followers_url": "https://api.github.com/users/coleifer/followers",
"following_url": "https://api.github.com/users/coleifer/following{/other_user}",
"gists_url": "https://api.github.com/users/coleifer/gists{/gist_id}",
"starred_url": "https://api.github.com/users/coleifer/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/coleifer/subscriptions",
"organizations_url": "https://api.github.com/users/coleifer/orgs",
"repos_url": "https://api.github.com/users/coleifer/repos",
"events_url": "https://api.github.com/users/coleifer/events{/privacy}",
"received_events_url": "https://api.github.com/users/coleifer/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2015-08-24T13:18:52 | 2015-08-24T16:08:12 | 2015-08-24T16:08:12 | OWNER | null | see subj.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/691/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/691/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/690 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/690/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/690/comments | https://api.github.com/repos/coleifer/peewee/issues/690/events | https://github.com/coleifer/peewee/issues/690 | 102,470,531 | MDU6SXNzdWUxMDI0NzA1MzE= | 690 | ascii codec error while running execute_sql | {
"login": "roozbehid",
"id": 7875383,
"node_id": "MDQ6VXNlcjc4NzUzODM=",
"avatar_url": "https://avatars.githubusercontent.com/u/7875383?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/roozbehid",
"html_url": "https://github.com/roozbehid",
"followers_url": "https://api.github.com/users/roozbehid/followers",
"following_url": "https://api.github.com/users/roozbehid/following{/other_user}",
"gists_url": "https://api.github.com/users/roozbehid/gists{/gist_id}",
"starred_url": "https://api.github.com/users/roozbehid/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/roozbehid/subscriptions",
"organizations_url": "https://api.github.com/users/roozbehid/orgs",
"repos_url": "https://api.github.com/users/roozbehid/repos",
"events_url": "https://api.github.com/users/roozbehid/events{/privacy}",
"received_events_url": "https://api.github.com/users/roozbehid/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Using an interactive debugger, are you able to examine the message of the warning that is failing to be displayed? My feeling is that this is not an issue with Peewee, but I'd like to be sure before closing.\n",
"``` python\nfile.write(formatwarning(message, category, filename, lineno, line)\n```\n\nThat is the line that I think is problematic. Something in the warning message, maybe?\n",
"warning is about having duplicate values I guess, that is why I used INSERT IGNORE. but anyway this throws an exception which should not happen.\nThe name of column I am using is unicode and somethimes it is ascii I guess...I am myself having problem printing it out....so I used two different lines of code to check if it is unicode or it is ascii!\n\nBut all subsequent enquires and everything works as far as I can tell! warning displaying causes problem\n",
"> The name of column I am using is unicode and somethimes it is ascii I guess...I am myself having problem printing it out....so I used two different lines of code to check if it is unicode or it is ascii!\n\nOK, then that sounds like the issue. You might've mentioned that in the issue description. This isn't a peewee issue, but an issue with the MySQLdb library.\n"
] | 2015-08-21T22:00:35 | 2015-08-22T02:26:38 | 2015-08-22T02:26:38 | NONE | null | I have a simple execute_sql command like this
```
self.db.execute_sql("""
INSERT IGNORE INTO artists (name,alias_name)
select name,alias_name
from my_actors""")
```
The first time I run it (which I mean there are no duplicates...) it runs fine.
But second times it give me
```
File "c:\WinPython\python-2.7.6.amd64\lib\site-packages\peewee.py", line 3191, in execute_sql
cursor.execute(sql, params or ())
File "c:\WinPython\python-2.7.6.amd64\lib\site-packages\MySQLdb\cursors.py", line 207, in execute
if not self._defer_warnings: self._warning_check()
File "c:\WinPython\python-2.7.6.amd64\lib\site-packages\MySQLdb\cursors.py", line 117, in _warning_check
warn(w[-1], self.Warning, 3)
File "c:\WinPython\python-2.7.6.amd64\lib\warnings.py", line 29, in _show_warning
file.write(formatwarning(message, category, filename, lineno, line))
File "c:\WinPython\python-2.7.6.amd64\lib\warnings.py", line 38, in formatwarning
s = "%s:%s: %s: %s\n" % (filename, lineno, category.__name__, message)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 17-20: ordinal not in range(128)
```
Running this command on MySQL works fine and I think this has to do something with peewee trying to check for warning and .....
I am using peewee 2.6.3 and MySQL charachter sets for all tables are set to utf-8.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/690/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/690/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/689 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/689/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/689/comments | https://api.github.com/repos/coleifer/peewee/issues/689/events | https://github.com/coleifer/peewee/issues/689 | 101,439,740 | MDU6SXNzdWUxMDE0Mzk3NDA= | 689 | Read-only slave connections are not closed | {
"login": "stas",
"id": 112147,
"node_id": "MDQ6VXNlcjExMjE0Nw==",
"avatar_url": "https://avatars.githubusercontent.com/u/112147?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/stas",
"html_url": "https://github.com/stas",
"followers_url": "https://api.github.com/users/stas/followers",
"following_url": "https://api.github.com/users/stas/following{/other_user}",
"gists_url": "https://api.github.com/users/stas/gists{/gist_id}",
"starred_url": "https://api.github.com/users/stas/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/stas/subscriptions",
"organizations_url": "https://api.github.com/users/stas/orgs",
"repos_url": "https://api.github.com/users/stas/repos",
"events_url": "https://api.github.com/users/stas/events{/privacy}",
"received_events_url": "https://api.github.com/users/stas/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"@stas -- what do you mean by read-only? You mean the `ReadSlaveModel` from `playhouse.read_slave`?\n\nCan you share some code so I can get a better idea of your configuration, as well as the problem you're experiencing?\n",
"> @stas -- what do you mean by read-only? You mean the ReadSlaveModel from playhouse.read_slave?\n\nYes, sorry I forgot to mention the exact module.\n\n> Can you share some code so I can get a better idea of your configuration, as well as the problem you're experiencing?\n\nThere's nothing custom, we just extended our models with the `ReadSlaveModel` and we started getting `ValueError`s with: Exceeded maximum connections.\nI started tracking this down and it is generated by the `playhouse.pool._connect` which we use. Going deeper I discovered that the `max_connections` limit is reached because the connections are not returning back to the pool (aka closed). Honestly this makes sense since I couldn't find anywhere where those connections are managed to return back to pool/close.\n",
"I'm assuming this is in a web app and that you've got some middleware or something opening connections (or checking them out) at the beginning of the request/response cycle, and closing them (returning them) at the end...\n\nIf that's the case, perhaps it would be sufficient in the \"close\" code (when you're done with a request) to iterate through all databases and do something like:\n\n``` python\ndatabases = [master] + read_slaves\nfor database in databases:\n if database.is_open():\n database.close()\n```\n",
"> I'm assuming this is in a web app and that you've got some middleware or something opening connections (or checking them out) at the beginning of the request/response cycle, and closing them (returning them) at the end...\n\nNope, this is a heavily threaded application.\n\n> If that's the case, perhaps it would be sufficient in the \"close\" code (when you're done with a request) to iterate through all databases and do something like:\n\nWe explored this approach, in fact we were using it until we started adding read-only servers. We found that closing of the database connections performs strange (you really need to be handling this in the same thread and so on...).\n\nLast couple of days I started reading the way database and pooled database classes work and I could not understand some of the aspects. One of the main question is related to the fact that we actually need to manually close all the connections. By looking at the database API, I can see that an implementation where the connections are automatically picked, used and closed/put back is possible, still you decided a manual approach is better. Can I ask you why?\n",
"> We found that closing of the database connections performs strange (you really need to be handling this in the same thread and so on...).\n\nCan you explain that more? What database engine are you using?\n\nActually now that you describe that, I can see how that might arise... Thread1 opens connection, does work, puts it back in pool and goes away. Thread2 checks out connection, does work, puts it back in pool. Pool decides connection is stale, so it closes it...Perhaps that's what happened?\n\n> One of the main question is related to the fact that we actually need to manually close all the connections.\n\nThat is the case whether you use a pool or just a regular `Database` subclass. It's written all over the docs, but you need to open the conn when you want to start work, then close it when you're done. For web apps this happens typically in the request/response cycle.\n\nIf you're using a pool, the only difference is that the pool manages the connections for you. It's transparent to the application -- the `connect()` and `close()` APIs are the same.\n\n> By looking at the database API, I can see that an implementation where the connections are automatically picked, used and closed/put back is possible, still you decided a manual approach is better. Can I ask you why?\n\nIt's true that a connection will be automatically opened if you try to execute a query and no conn has been opened yet. This is for backwards compatibility and to reduce boilerplate when writing simple scripts. There is no way, as far as I know, to automatically close or \"put back\" connections.\n",
"Just out of curiosity, what database are you using? And do you have any more info regarding the error your received when closing connections (the error about \"threads\")?\n",
"Following the docs, we managed to manually close opened connections, so I'm closing this.\n\n> It's true that a connection will be automatically opened if you try to execute a query and no conn has been opened yet. This is for backwards compatibility and to reduce boilerplate when writing simple scripts. There is no way, as far as I know, to automatically close or \"put back\" connections.\n\nIn regards to the question about automatic management of the connections, after looking at the query classes, maybe it's worth exploring the approach where connections are handled inside context managers and are automatically open and closed after the query is done. I tried patching the `Query._execute()` but the way query wrappers handle results (lazily), it didn't work properly.\n\n> Just out of curiosity, what database are you using? And do you have any more info regarding the error your received when closing connections (the error about \"threads\")?\n\nWe're using an extended postgres adapter, and the problem with that is, especially in a threaded environment, is that having a similar to the request/response approach is not necessarily a common case. Every-time we need to make changes to connection management or integrate our peewee models, we need to find a way how we are going to handle the connections management. You can imagine it is pretty frustrating :(\n\nThere's a lot of complexity required to provide the current connection state (`thread.local` and the whole execution context stack), so I started asking myself if there's no better way to handle this. Previously I had experience with working with the psycopg2 modules, and there are a couple of things that might help with this (consider using psycopg2.pool and it's API for managing cursors). I'm seriously thinking to take a shot on making the database adapter use coroutines or at least leverage the `psycopg2.pool` API.\n\nThanks a lot for helping with answers.\n",
"I am not sure about using a connection-per-query. If you wanted to be very granular you could do a connection per transaction, that is not too uncommon, and in fact peewee's [ExecutionContext](http://docs.peewee-orm.com/en/latest/peewee/database.html#advanced-connection-management) ([api](http://docs.peewee-orm.com/en/latest/peewee/api.html#ExecutionContext)) does just this.\n\nI've used huey in a multi-threaded, long-running script -- managing the connections wasn't too difficult since peewee stores a connection-per-thread by default.\n\nThe postgresql pool is implemented very similar to the peewee pool as far as I can tell. Peewee goes a step further and adds the concept of an expiration time, but other than that they are quite similar. Peewee simply abstracts away the pool implementation details from the Database API so apps can go on using `connect()` and `close()` without being aware the conns are being pooled.\n",
"> I am not sure about using a connection-per-query. If you wanted to be very granular you could do a connection per transaction, that is not too uncommon, and in fact peewee's ExecutionContext (api) does just this.\n\nThe issue is a little bit more complex. I can't speak for other databases, but postgres adapter doesn't provide an API to tell if the connection is still open or closed (see psycopg/psycopg2#263). The approach with keeping a connection around in the hope it will stay alive by the time a thread is done using it will not work unless you set a very low `stale_timeout`, and it will still not guarantee if the connection is still alive.\n\nWe're having issues with this exact aspect of the psycopg2 and peewee in some long-running multi threaded application (I'm talking about weeks of run-time here, ideally we would like to have it running for months like that, but it doesn't) and using the Redshift database (a postgres flavor). If we lower the `stale_timeout`, it will pretty-much work as a connection-per-query set-up.\n\nIf we look at the bigger picture here, the situation with the read-write queries split across different servers is another case where this doesn't fit well in the current approach the connections are handled (we have some workers running for hours, it might be that the read-only queries are just happening 10% of the time, why keeping the connection around all the time?).\n\nWhat I'm trying to say, is that the current adapter (talking about postgres here) could use some improvements to handle the connections in a better way and, why not, auto-close them without having the users to figure out when a connection is stalled and when it should be closed.\n\n> The postgresql pool is implemented very similar to the peewee pool as far as I can tell. Peewee goes a step further and adds the concept of an expiration time, but other than that they are quite similar. Peewee simply abstracts away the pool implementation details from the Database API so apps can go on using connect() and close() without being aware the conns are being pooled.\n\nThat is why I wonder why it was not just extended in peewee. Btw, looking at the persistent connection pool from psycogp2, I can spot the similarities with the current peewee's pool. It is also deprecated now.\nhttp://initd.org/psycopg/docs/pool.html#psycopg2.pool.PersistentConnectionPool\n",
"I'm pretty sure that `psycopg2` provides a `closed` boolean attribute on the `Connection` object:\n\nhttp://initd.org/psycopg/docs/connection.html#connection.closed\n\nThe peewee connection pool uses this attribute to check whether a connection is closed when the application checks it out. So the pool will:\n1. Check that the conn wasn't open more than `stale_timeout` seconds ago.\n2. Check that `conn.closed` is not True.\n3. Release the connection to your app\n\n> we have some workers running for hours, it might be that the read-only queries are just happening 10% of the time, why keeping the connection around all the time?\n\nThen could you use a pool for the writers and a simple `PostgresqlDatabase` for the readers?\n\nRegarding the psycopg2 pool, I actually did not look at it's code until you mentioned it, as I didn't know it existed...I guess there's only so many ways to implement a simple pool, haha.\n"
] | 2015-08-17T14:53:19 | 2015-08-21T23:19:28 | 2015-08-20T14:22:41 | NONE | null | Using a read-only pooled database as a slave won't close its connections.
I also found it is pretty hard to manually manage these as it is now suggested in case of connection pools. This is mainly because the read queries are randomly picking connections so it is really hard to track those. We're still exploring some solutions, I will try to report back when we have something working.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/689/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/689/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/688 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/688/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/688/comments | https://api.github.com/repos/coleifer/peewee/issues/688/events | https://github.com/coleifer/peewee/issues/688 | 101,036,168 | MDU6SXNzdWUxMDEwMzYxNjg= | 688 | Behavior of << differs from .in_() method for 2+ item lists | {
"login": "chrisinmtown",
"id": 10234212,
"node_id": "MDQ6VXNlcjEwMjM0MjEy",
"avatar_url": "https://avatars.githubusercontent.com/u/10234212?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/chrisinmtown",
"html_url": "https://github.com/chrisinmtown",
"followers_url": "https://api.github.com/users/chrisinmtown/followers",
"following_url": "https://api.github.com/users/chrisinmtown/following{/other_user}",
"gists_url": "https://api.github.com/users/chrisinmtown/gists{/gist_id}",
"starred_url": "https://api.github.com/users/chrisinmtown/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/chrisinmtown/subscriptions",
"organizations_url": "https://api.github.com/users/chrisinmtown/orgs",
"repos_url": "https://api.github.com/users/chrisinmtown/repos",
"events_url": "https://api.github.com/users/chrisinmtown/events{/privacy}",
"received_events_url": "https://api.github.com/users/chrisinmtown/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Weird, thanks for reporting.\n",
"Are you using an older version of peewee? I think the issue was that in older versions there was a bug where `in_()` took `*args` rather than a single list.\n\nThe bug was fixed in fcfd914f, part of the 2.5.1 release.\n",
"Omitted the version in my initial report, sorry, I was using 2.4.5. I upgraded to 2.6.3 and the problem is gone. Thanks for the very quick response.\n"
] | 2015-08-14T15:31:41 | 2015-08-14T16:37:35 | 2015-08-14T16:37:34 | NONE | null | I have a query that checks whether a 1-character column value is a member of a 4-element list. If I write the query in Peewee using the << operator it works fine (I'm using constants):
```
& (Doc2.doctype << [Doc2.DOCTYPE_A, Doc2.DOCTYPE_B, Doc2.DOCTYPE_C, Doc2.DOCTYPE_D])
```
However if I write the query using the .in_() method:
```
& (Doc2.doctype.in_([Doc2.DOCTYPE_A, Doc2.DOCTYPE_B, Doc2.DOCTYPE_C, Doc2.DOCTYPE_D]))
```
It blows up with internal error 'Operand should contain 1 column(s)'.
I found that << is equivalent to .in() if the list has exactly 1 item, but differs when the list has 2+ items. In other words, this works:
```
& (Doc2.doctype.in_([Doc2.DOCTYPE_A]))
```
Please see below. Thanks for listening
##
Traceback (most recent call last):
... (name of my file omitted)
for doc_row in doc_and_path_query:
File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 2514, in **iter**
return iter(self.execute())
File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 2507, in execute
self._qr = ResultWrapper(model_class, self._execute(), query_meta)
File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 2203, in _execute
return self.database.execute_sql(sql, params, self.require_commit)
File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 2833, in execute_sql
self.commit()
File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 2688, in __exit__
reraise(new_type, new_type(*exc_value.args), traceback)
File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 2825, in execute_sql
cursor.execute(sql, params or ())
File "/usr/local/lib/python2.7/dist-packages/pymysql/cursors.py", line 135, in execute
result = self._query(query)
File "/usr/local/lib/python2.7/dist-packages/pymysql/cursors.py", line 274, in _query
conn.query(q)
File "/usr/local/lib/python2.7/dist-packages/pymysql/connections.py", line 714, in query
self._affected_rows = self._read_query_result(unbuffered=unbuffered)
File "/usr/local/lib/python2.7/dist-packages/pymysql/connections.py", line 865, in _read_query_result
result.read()
File "/usr/local/lib/python2.7/dist-packages/pymysql/connections.py", line 1062, in read
first_packet = self.connection._read_packet()
File "/usr/local/lib/python2.7/dist-packages/pymysql/connections.py", line 830, in _read_packet
packet.check_error()
File "/usr/local/lib/python2.7/dist-packages/pymysql/connections.py", line 348, in check_error
raise_mysql_exception(self._data)
File "/usr/local/lib/python2.7/dist-packages/pymysql/err.py", line 116, in raise_mysql_exception
_check_mysql_exception(errinfo)
File "/usr/local/lib/python2.7/dist-packages/pymysql/err.py", line 112, in _check_mysql_exception
raise InternalError(errno, errorvalue)
peewee.InternalError: (1241, u'Operand should contain 1 column(s)')
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/688/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/688/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/687 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/687/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/687/comments | https://api.github.com/repos/coleifer/peewee/issues/687/events | https://github.com/coleifer/peewee/pull/687 | 100,941,060 | MDExOlB1bGxSZXF1ZXN0NDI0MjYxOTY= | 687 | Make it possible to use ``upsert`` and ``on_conflict`` on MySQL | {
"login": "messense",
"id": 1556054,
"node_id": "MDQ6VXNlcjE1NTYwNTQ=",
"avatar_url": "https://avatars.githubusercontent.com/u/1556054?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/messense",
"html_url": "https://github.com/messense",
"followers_url": "https://api.github.com/users/messense/followers",
"following_url": "https://api.github.com/users/messense/following{/other_user}",
"gists_url": "https://api.github.com/users/messense/gists{/gist_id}",
"starred_url": "https://api.github.com/users/messense/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/messense/subscriptions",
"organizations_url": "https://api.github.com/users/messense/orgs",
"repos_url": "https://api.github.com/users/messense/repos",
"events_url": "https://api.github.com/users/messense/events{/privacy}",
"received_events_url": "https://api.github.com/users/messense/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Cool, this is a nice start.\n",
"This behavior was added in #753.\n"
] | 2015-08-14T05:56:05 | 2015-11-19T22:55:24 | 2015-11-19T22:55:24 | CONTRIBUTOR | null | Ref #684
I am not sure how to write a corresponding test case for now.
And I don't know if it is ok to use `isintance(meta.database, MySQLDatabase` here. What do you think?
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/687/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/687/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/687",
"html_url": "https://github.com/coleifer/peewee/pull/687",
"diff_url": "https://github.com/coleifer/peewee/pull/687.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/687.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/686 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/686/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/686/comments | https://api.github.com/repos/coleifer/peewee/issues/686/events | https://github.com/coleifer/peewee/issues/686 | 100,578,334 | MDU6SXNzdWUxMDA1NzgzMzQ= | 686 | Curiosity: how would I go about implementing a refresh() method on Model? | {
"login": "josefdlange",
"id": 1062835,
"node_id": "MDQ6VXNlcjEwNjI4MzU=",
"avatar_url": "https://avatars.githubusercontent.com/u/1062835?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/josefdlange",
"html_url": "https://github.com/josefdlange",
"followers_url": "https://api.github.com/users/josefdlange/followers",
"following_url": "https://api.github.com/users/josefdlange/following{/other_user}",
"gists_url": "https://api.github.com/users/josefdlange/gists{/gist_id}",
"starred_url": "https://api.github.com/users/josefdlange/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/josefdlange/subscriptions",
"organizations_url": "https://api.github.com/users/josefdlange/orgs",
"repos_url": "https://api.github.com/users/josefdlange/repos",
"events_url": "https://api.github.com/users/josefdlange/events{/privacy}",
"received_events_url": "https://api.github.com/users/josefdlange/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I think what you have in your first snippet is good.\n\n``` python\ninstance = Model.get(...)\n\n...\n\ninstance = instance.refresh()\n```\n\nThe `refresh()` method could be:\n\n``` python\ndef refresh(self):\n return type(self).get(self._pk_expr())\n```\n",
"How about adding this to core? I too would find it useful is some cases.\n",
"We are also using this snippet, although I personally would expect a `refresh` method (terminology-wise) to update the instance in place, instead of returning a fresh copy.\n",
"I defer to @coleifer of course since I'm just a barely-familiar user of `peewee`, but here's my $0.02:\n\nI'd buy you a beer if you could get that to work cleanly -- it's not as trivial as it would seem given my experience trying to work it out on my end. It's one thing to set the data on the Model subclass object, but once you start considering things like dirty fields, object caches, etc., it starts unraveling.\n\n`thing = thing.refresh()` is really not that much more of a headache IMO. If that's losing any kind of locally-set data, my guess is you're probably Doing It Wrong™.\n\nMaybe it's a semantics issue then -- perhaps it'd be better off called `inflate()` or `regenerate()` or `evolve()` or `reincarnate()`... actually, I kind of like `reincarnate()`...\n",
"If you want to get into a really hairy territory, you could go so far as to write some kind of code that takes in the remote updated version and _merges_ it with the local object, and if it's trying to clobber a locally-dirty field, raise some kind of exception, etc, but then again this is becoming more not-very-Pythonic the more we explore the possibilities.\n",
"I think something like this should be nice, but I in fact just wrote it now and haven't yet tested enough. This works «in place» by loading another instance of the same class and copying all its fields. Seems to work as planned, but I am pretty sure there are some unwanted side effects somewhere. Maybe somebody has a better implementation?\n\n``` python\ndef reload(self):\n newer_self = self.get(self._meta.primary_key == self._get_pk_value())\n for field_name in self._meta.fields.keys():\n val = getattr(newer_self, field_name)\n setattr(self, field_name, val)\n self._dirty.clear()\n```\n"
] | 2015-08-12T16:04:53 | 2016-10-19T09:26:53 | 2015-08-13T05:57:43 | CONTRIBUTOR | null | Here's the scoop:
The project I'm working on creates the scenario where I have local variables holding instances of a variety of Models. Changes to some have side-effects on the others (intentional ones, via signals). Right now I'm using the following to "refresh" a model instance when I want to ensure the data is up-to-date:
```
instance = Model.get(Model.something = something)
# ...
# .. do work
# ...
# .. need to "refresh"
instance = Model.get(Model.id == instance.id)
# .. continue
```
I don't mind the additional get, but I thought it might be fun to implement a `refresh()` method on my base Model subclass. At my first crack, I caught myself trying this boneheaded implementation:
```
def refresh(self):
self = self.__class__.get(self.__class__.id == self.id)
```
Obviously that's stupid. I don't want to change `self`. Anybody holding reference to that object won't see the updates, as far as I can tell. There might be a nuance I'm missing in the Python runtime, but I'm pretty sure it wouldn't work.
Have any ideas as to what I could try? I'd be glad to write it in such a way that it could make a PR to the project, if you think it'll be useful for the general audience.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/686/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/686/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/685 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/685/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/685/comments | https://api.github.com/repos/coleifer/peewee/issues/685/events | https://github.com/coleifer/peewee/issues/685 | 100,356,150 | MDU6SXNzdWUxMDAzNTYxNTA= | 685 | Examples of how to add request hooks in wheezy.web | {
"login": "thirashima",
"id": 12535,
"node_id": "MDQ6VXNlcjEyNTM1",
"avatar_url": "https://avatars.githubusercontent.com/u/12535?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/thirashima",
"html_url": "https://github.com/thirashima",
"followers_url": "https://api.github.com/users/thirashima/followers",
"following_url": "https://api.github.com/users/thirashima/following{/other_user}",
"gists_url": "https://api.github.com/users/thirashima/gists{/gist_id}",
"starred_url": "https://api.github.com/users/thirashima/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/thirashima/subscriptions",
"organizations_url": "https://api.github.com/users/thirashima/orgs",
"repos_url": "https://api.github.com/users/thirashima/repos",
"events_url": "https://api.github.com/users/thirashima/events{/privacy}",
"received_events_url": "https://api.github.com/users/thirashima/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Don't know the framework, but you should probably use [middleware](https://pythonhosted.org/wheezy.http/userguide.html#middleware). Assuming `peewee_middleware` is never the last one:\n\n```\ndef peewee_middleware(request, following):\n db.connect()\n try:\n response = following(request)\n finally:\n if not db.is_closed():\n db.close()\nreturn response\n\napp = WSGIApplication(middleware=[\n lambda x: peewee_middleware,\n path_routing_middleware_factory\n])\n```\n\nI would think this question belongs more to wheezy.web project than to peewee, though.\n",
"Thanks. I added this here because the peewee documentation specifically asks you to open a ticket if there are any other frameworks you'd like to see examples for. http://docs.peewee-orm.com/en/latest/peewee/database.html#other-frameworks\n",
"Oh, I stand corrected. Did you have luck with the suggestion?\n",
"@thirashima -- If you come up with some working code, please comment on this issue and I will add it to the docs. For now I am closing this.\n",
"the code that tuukkamustonen provided does seem to be working. thank you everyone for the help.\n",
"Cool, I will update the docs, thanks d00dz.\n",
"http://docs.peewee-orm.com/en/latest/peewee/database.html#wheezy-web\n"
] | 2015-08-11T16:45:23 | 2015-08-14T01:27:53 | 2015-08-13T06:20:36 | NONE | null | I'd like to see an example of how to add request hooks for db connection management to the wheezy.web framework. I've tried to figure it out myself, but it is non-obvious to me. Thanks!
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/685/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/685/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/684 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/684/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/684/comments | https://api.github.com/repos/coleifer/peewee/issues/684/events | https://github.com/coleifer/peewee/issues/684 | 99,769,966 | MDU6SXNzdWU5OTc2OTk2Ng== | 684 | Does peewee support MySQL REPLACE INTO syntax? | {
"login": "messense",
"id": 1556054,
"node_id": "MDQ6VXNlcjE1NTYwNTQ=",
"avatar_url": "https://avatars.githubusercontent.com/u/1556054?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/messense",
"html_url": "https://github.com/messense",
"followers_url": "https://api.github.com/users/messense/followers",
"following_url": "https://api.github.com/users/messense/following{/other_user}",
"gists_url": "https://api.github.com/users/messense/gists{/gist_id}",
"starred_url": "https://api.github.com/users/messense/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/messense/subscriptions",
"organizations_url": "https://api.github.com/users/messense/orgs",
"repos_url": "https://api.github.com/users/messense/repos",
"events_url": "https://api.github.com/users/messense/events{/privacy}",
"received_events_url": "https://api.github.com/users/messense/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Not at present, but I would consider a pull request and would work with you on getting the code into good shape. For now I'd suggest using hand-written SQL queries if you want upserts with MySQL.\n"
] | 2015-08-08T04:23:26 | 2015-08-13T06:22:55 | 2015-08-13T06:22:55 | CONTRIBUTOR | null | I only see upsert support for SQLite in documentation.
And another question, does peewee support MySQL `INSERT IGNORE` or `INSERT...ON DUPLICATE KEY UPDATE` syntax?
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/684/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/684/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/683 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/683/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/683/comments | https://api.github.com/repos/coleifer/peewee/issues/683/events | https://github.com/coleifer/peewee/issues/683 | 99,153,944 | MDU6SXNzdWU5OTE1Mzk0NA== | 683 | Support for the MySQL BIT data type | {
"login": "jmenglund",
"id": 6959349,
"node_id": "MDQ6VXNlcjY5NTkzNDk=",
"avatar_url": "https://avatars.githubusercontent.com/u/6959349?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/jmenglund",
"html_url": "https://github.com/jmenglund",
"followers_url": "https://api.github.com/users/jmenglund/followers",
"following_url": "https://api.github.com/users/jmenglund/following{/other_user}",
"gists_url": "https://api.github.com/users/jmenglund/gists{/gist_id}",
"starred_url": "https://api.github.com/users/jmenglund/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/jmenglund/subscriptions",
"organizations_url": "https://api.github.com/users/jmenglund/orgs",
"repos_url": "https://api.github.com/users/jmenglund/repos",
"events_url": "https://api.github.com/users/jmenglund/events{/privacy}",
"received_events_url": "https://api.github.com/users/jmenglund/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"At present Peewee uses the `bool` data-type, which is also what Django uses for BooleanField in Django.\n\nIf you want `Bit` specifically you can either create a custom field, or specify a field override:\n- http://docs.peewee-orm.com/en/latest/peewee/models.html#creating-a-custom-field\n- http://docs.peewee-orm.com/en/latest/peewee/api.html#Database\n",
"Thank you very much! My problem was easily solved.\n\nI'm sorry I didn't read the docs more carefully. Perhaps a link to the section \"Creating a custom field\" directly after the field types table could prevent others from making the same mistake.\n",
"Added the links, thanks!\n",
"@jmenglund Hello, I am trying to do the same but I have troubles converting the string of hex characters retrieved to booleans. I am a beginner in Python, could you share some snippet"
] | 2015-08-05T08:45:31 | 2017-01-06T11:24:13 | 2015-08-05T15:44:27 | NONE | null | http://dev.mysql.com/doc/refman/5.7/en/bit-type.html
http://stackoverflow.com/questions/289727/which-mysql-datatype-to-use-for-storing-boolean-values
For my own databases I would probably not use the BIT data type at all (see for example http://www.xaprb.com/blog/2006/04/11/bit-values-in-mysql/) but I need it in order to work with a database not created by me.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/683/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/683/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/682 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/682/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/682/comments | https://api.github.com/repos/coleifer/peewee/issues/682/events | https://github.com/coleifer/peewee/issues/682 | 99,020,232 | MDU6SXNzdWU5OTAyMDIzMg== | 682 | Unexpected behavior doing nested iteration on a SelectQuery | {
"login": "martinburch",
"id": 2335284,
"node_id": "MDQ6VXNlcjIzMzUyODQ=",
"avatar_url": "https://avatars.githubusercontent.com/u/2335284?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/martinburch",
"html_url": "https://github.com/martinburch",
"followers_url": "https://api.github.com/users/martinburch/followers",
"following_url": "https://api.github.com/users/martinburch/following{/other_user}",
"gists_url": "https://api.github.com/users/martinburch/gists{/gist_id}",
"starred_url": "https://api.github.com/users/martinburch/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/martinburch/subscriptions",
"organizations_url": "https://api.github.com/users/martinburch/orgs",
"repos_url": "https://api.github.com/users/martinburch/repos",
"events_url": "https://api.github.com/users/martinburch/events{/privacy}",
"received_events_url": "https://api.github.com/users/martinburch/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Here is a description of the problem:\n\n``` python\n# create 5 users, named user0-user4\nquery = User.select()\nfor o in query:\n print 'o ->', o.username\n for i in query:\n print ' i ->', i.username\n```\n\nThis will print:\n\n```\no -> u0\n i -> u0\n i -> u1\n i -> u2\n i -> u3\n i -> u4\n```\n",
"So when you iterate over a `SelectQuery` it creates a `QueryResultWrapper` which allows for efficient iteration and indexing. The problem is that the iterator is stateful.\n\nThe workaround I'd suggest is just to coerce to a `list` beforehand. You can also call `QueryResultWrapper.fill_cache()`.\n\nI'll see about a better fix.\n",
"This should now be fixed in master.\n",
"Great, thanks!\n"
] | 2015-08-04T17:36:50 | 2015-09-04T03:09:32 | 2015-09-04T03:08:44 | NONE | null | Hi, I wanted to bring an issue to your attention: nested iteration of SelectQuery results doesn't work as expected. You can see an example, and a workaround, on my StackOverflow question:
http://stackoverflow.com/questions/31815235/python-peewee-iterate-over-selectquery
Is there an iterator that needs to be reset somewhere? Maybe at the end of the inner loop?
Thanks!
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/682/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/682/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/681 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/681/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/681/comments | https://api.github.com/repos/coleifer/peewee/issues/681/events | https://github.com/coleifer/peewee/pull/681 | 98,694,875 | MDExOlB1bGxSZXF1ZXN0NDE0NDM5MzU= | 681 | Add multi-column unique constraints support for Model.create_or_get | {
"login": "messense",
"id": 1556054,
"node_id": "MDQ6VXNlcjE1NTYwNTQ=",
"avatar_url": "https://avatars.githubusercontent.com/u/1556054?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/messense",
"html_url": "https://github.com/messense",
"followers_url": "https://api.github.com/users/messense/followers",
"following_url": "https://api.github.com/users/messense/following{/other_user}",
"gists_url": "https://api.github.com/users/messense/gists{/gist_id}",
"starred_url": "https://api.github.com/users/messense/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/messense/subscriptions",
"organizations_url": "https://api.github.com/users/messense/orgs",
"repos_url": "https://api.github.com/users/messense/repos",
"events_url": "https://api.github.com/users/messense/events{/privacy}",
"received_events_url": "https://api.github.com/users/messense/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Could probably tidy up the code a little, and we'll need sign off from @coleifer on the `query` conditional, but assuming those two things are signed off, then LGTM.\n",
"@messense Has this already been merged into master?",
"I don't know. I haven't used peewee for a long time and I think I won't be working on this so I closed it.",
"@coleifer Any thoughts on whether you'd like this in master?",
"No, get or create is evil. One of my biggest regrets"
] | 2015-08-03T08:17:28 | 2017-07-05T16:08:49 | 2017-07-05T10:32:29 | CONTRIBUTOR | null | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/681/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/681/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/681",
"html_url": "https://github.com/coleifer/peewee/pull/681",
"diff_url": "https://github.com/coleifer/peewee/pull/681.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/681.patch",
"merged_at": null
} |
|
https://api.github.com/repos/coleifer/peewee/issues/680 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/680/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/680/comments | https://api.github.com/repos/coleifer/peewee/issues/680/events | https://github.com/coleifer/peewee/issues/680 | 98,423,986 | MDU6SXNzdWU5ODQyMzk4Ng== | 680 | reflection module is using a not convenient import statement | {
"login": "aliubchenko",
"id": 3506595,
"node_id": "MDQ6VXNlcjM1MDY1OTU=",
"avatar_url": "https://avatars.githubusercontent.com/u/3506595?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/aliubchenko",
"html_url": "https://github.com/aliubchenko",
"followers_url": "https://api.github.com/users/aliubchenko/followers",
"following_url": "https://api.github.com/users/aliubchenko/following{/other_user}",
"gists_url": "https://api.github.com/users/aliubchenko/gists{/gist_id}",
"starred_url": "https://api.github.com/users/aliubchenko/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/aliubchenko/subscriptions",
"organizations_url": "https://api.github.com/users/aliubchenko/orgs",
"repos_url": "https://api.github.com/users/aliubchenko/repos",
"events_url": "https://api.github.com/users/aliubchenko/events{/privacy}",
"received_events_url": "https://api.github.com/users/aliubchenko/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I don't really think this is a use-case I had intended to cover.\n"
] | 2015-07-31T16:26:05 | 2015-07-31T18:01:03 | 2015-07-31T18:01:03 | NONE | null | Reflection.py has this as the import statement:
from peewee import *
When you include peewee in your own package of libraries and use it, all classes from peewee become <your_package>.peewee.*
However, for models that were created using Introspection, peewee classes are still peewee.\* because of that import statement.
Consequently if you want to do a select query on the generated models, in this function:
```
def parse_node(self, node, alias_map=None, conv=None):
sql, params, unknown = self._parse(node, alias_map, conv)
if unknown and conv and params:
params = [conv.db_value(i) for i in params]
if isinstance(node, Node):
```
The last check fails. Because it is comparing node (peewee.Entity, created by Introspection) with <your_package>.peewee.Node
This fails and leads to queries missing the "as t1" statement right after "from <table>" clause.
Leading to the database complaining about missing column names t1.<column>.
The fix that worked for me is changing the import statement to use relative import:
from ..peewee import *
This allowed everything to reside in my package and the check worked and proper query was generated.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/680/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/680/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/679 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/679/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/679/comments | https://api.github.com/repos/coleifer/peewee/issues/679/events | https://github.com/coleifer/peewee/issues/679 | 98,202,022 | MDU6SXNzdWU5ODIwMjAyMg== | 679 | [Question] Why can't I assign a new model instance to a model's foreign-key field | {
"login": "EPadronU",
"id": 829947,
"node_id": "MDQ6VXNlcjgyOTk0Nw==",
"avatar_url": "https://avatars.githubusercontent.com/u/829947?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/EPadronU",
"html_url": "https://github.com/EPadronU",
"followers_url": "https://api.github.com/users/EPadronU/followers",
"following_url": "https://api.github.com/users/EPadronU/following{/other_user}",
"gists_url": "https://api.github.com/users/EPadronU/gists{/gist_id}",
"starred_url": "https://api.github.com/users/EPadronU/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/EPadronU/subscriptions",
"organizations_url": "https://api.github.com/users/EPadronU/orgs",
"repos_url": "https://api.github.com/users/EPadronU/repos",
"events_url": "https://api.github.com/users/EPadronU/events{/privacy}",
"received_events_url": "https://api.github.com/users/EPadronU/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"That's an interesting point and has to do with the implementation of the descriptor. When the value is set (you assign the `File()` obj), the file has no primary key so peewee records `None` as the related object ID. The fact that the `File` later gets an ID is not caught by the field.\n\nI think this warrants some investigation, thanks for bringing it up.\n"
] | 2015-07-30T15:50:28 | 2015-09-02T16:56:06 | 2015-09-02T16:56:06 | NONE | null | ## Sample layout
``` python
class File(database.Model):
pass
class User(database.Model):
file = ForeignKeyField(File)
pass
```
## The code that reproduces the _odd_ behavior
``` python
>> user = User.get(id=1)
>> user.file = File()
>> user.file.save()
>> user.save()
>> user = User.get(id=1)
>> user.file
None
```
## The behavior with an existing instance
``` python
>> file = File.get(id=1)
>> user = User.get(id=1)
>> user.file = file
>> user.save()
>> user = User.get(id=1)
>> user.file.id
1
```
## Observations
- The behavior in the first situation should be similar to that of the second.
- Could the lack of an ID in the first situation be the cause of the _odd_ behavior?
## Pip freeze
```
blinker==1.3
Flask==0.10.1
Flask-Login==0.2.11
Flask-Mail==0.9.1
Flask-Markdown==0.3
Flask-Principal==0.4.0
Flask-Security==1.7.4
Flask-WTF==0.12
ipython==3.2.1
itsdangerous==0.24
Jinja2==2.7.3
Markdown==2.6.2
MarkupSafe==0.23
passlib==1.6.2
peewee==2.6.3
Werkzeug==0.10.4
wheel==0.24.0
wtf-peewee==0.2.3
WTForms==2.0.2
```
---
## Update - Thu Jul 30 15:55:24 UTC 2015
I just put under test my first observation and it looks like I was right (maybe):
``` python
>> file = File()
>> file.save()
1
>> user = User.get(id=1)
>> user.file = file
>> user.save()
>> user = User.get(id=1)
>> assert user.file is not None
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/679/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/679/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/678 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/678/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/678/comments | https://api.github.com/repos/coleifer/peewee/issues/678/events | https://github.com/coleifer/peewee/pull/678 | 98,196,302 | MDExOlB1bGxSZXF1ZXN0NDEyNDY1Njc= | 678 | Added default values of None to fix pylint complaining | {
"login": "danthedeckie",
"id": 1070206,
"node_id": "MDQ6VXNlcjEwNzAyMDY=",
"avatar_url": "https://avatars.githubusercontent.com/u/1070206?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/danthedeckie",
"html_url": "https://github.com/danthedeckie",
"followers_url": "https://api.github.com/users/danthedeckie/followers",
"following_url": "https://api.github.com/users/danthedeckie/following{/other_user}",
"gists_url": "https://api.github.com/users/danthedeckie/gists{/gist_id}",
"starred_url": "https://api.github.com/users/danthedeckie/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/danthedeckie/subscriptions",
"organizations_url": "https://api.github.com/users/danthedeckie/orgs",
"repos_url": "https://api.github.com/users/danthedeckie/repos",
"events_url": "https://api.github.com/users/danthedeckie/events{/privacy}",
"received_events_url": "https://api.github.com/users/danthedeckie/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2015-07-30T15:22:38 | 2015-07-30T15:52:41 | 2015-07-30T15:52:41 | NONE | null | Fixes #677, but not elegantly.
A better solution should somehow allow for parameters as well...
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/678/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/678/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/678",
"html_url": "https://github.com/coleifer/peewee/pull/678",
"diff_url": "https://github.com/coleifer/peewee/pull/678.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/678.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/677 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/677/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/677/comments | https://api.github.com/repos/coleifer/peewee/issues/677/events | https://github.com/coleifer/peewee/issues/677 | 98,195,723 | MDU6SXNzdWU5ODE5NTcyMw== | 677 | pylint complains no-value-for-parameter on Object instatiation... | {
"login": "danthedeckie",
"id": 1070206,
"node_id": "MDQ6VXNlcjEwNzAyMDY=",
"avatar_url": "https://avatars.githubusercontent.com/u/1070206?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/danthedeckie",
"html_url": "https://github.com/danthedeckie",
"followers_url": "https://api.github.com/users/danthedeckie/followers",
"following_url": "https://api.github.com/users/danthedeckie/following{/other_user}",
"gists_url": "https://api.github.com/users/danthedeckie/gists{/gist_id}",
"starred_url": "https://api.github.com/users/danthedeckie/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/danthedeckie/subscriptions",
"organizations_url": "https://api.github.com/users/danthedeckie/orgs",
"repos_url": "https://api.github.com/users/danthedeckie/repos",
"events_url": "https://api.github.com/users/danthedeckie/events{/privacy}",
"received_events_url": "https://api.github.com/users/danthedeckie/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"wontfix\n"
] | 2015-07-30T15:19:34 | 2015-07-30T15:52:34 | 2015-07-30T15:52:34 | NONE | null | Python 2.7, creating objects e.g.:
``` python
mike = Person()
```
results in pylint complaining with `no-value-for-parameter`, missing `names`, `bases`, `attrs`.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/677/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/677/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/676 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/676/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/676/comments | https://api.github.com/repos/coleifer/peewee/issues/676/events | https://github.com/coleifer/peewee/issues/676 | 97,875,232 | MDU6SXNzdWU5Nzg3NTIzMg== | 676 | ArrayField does not accept tuples | {
"login": "bdoms",
"id": 126839,
"node_id": "MDQ6VXNlcjEyNjgzOQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/126839?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/bdoms",
"html_url": "https://github.com/bdoms",
"followers_url": "https://api.github.com/users/bdoms/followers",
"following_url": "https://api.github.com/users/bdoms/following{/other_user}",
"gists_url": "https://api.github.com/users/bdoms/gists{/gist_id}",
"starred_url": "https://api.github.com/users/bdoms/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/bdoms/subscriptions",
"organizations_url": "https://api.github.com/users/bdoms/orgs",
"repos_url": "https://api.github.com/users/bdoms/repos",
"events_url": "https://api.github.com/users/bdoms/events{/privacy}",
"received_events_url": "https://api.github.com/users/bdoms/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2015-07-29T07:02:18 | 2015-07-29T15:26:20 | 2015-07-29T15:26:20 | NONE | null | So I love peewee. It's great. No problems so far, but I did just run into this strange behavior. Using an ArrayField for postgres from the playhouse (which is an awesome extension) and I had a function that output several values and I tried to use those directly. Something like:
``` python
def foo():
return a, b, c
BarModel.create(array_field=foo())
```
In Python I generally expect that all iterables are treated more or less the same, but clearly that's not happening here because I then got this error:
``` bash
peewee.ProgrammingError: column "array_field" is of type integer[] but expression is of type record
LINE 1: INSERT INTO "barmodel" ("array_field") VALUES ((1, 2, 3)) RE...
HINT: You will need to rewrite or cast the expression.
```
I understand the workaround: just cast it. But it's inconvenient and error prone for me to have to remember to do that every time. I realize that this may be more of a feature than a bug, but having to write `list()` around every function that returns what's already essentially a list seems super un-Pythonic to me. I suspect that this error appears for more non-list iterable types than just tuple as well, but I didn't test anything else.
Anyway, it would be really nice if we could use tuples and custom iterators to generate values for an array field. Here's a full test case (assuming an equivalent database and user set up, obviously):
``` python
from peewee import PostgresqlDatabase, Model, IntegerField
from playhouse.postgres_ext import ArrayField
DB = PostgresqlDatabase('test', user='test_user', password='test_password', port=5433)
class BarModel(Model):
class Meta:
database = DB
array_field = ArrayField(IntegerField, default='{}', null=True)
def run_test():
if BarModel.table_exists():
BarModel.drop_table()
BarModel.create_table()
# this works just fine
array_field = [1, 2, 3]
BarModel.create(array_field=array_field)
# this causes an error
array_field = (1, 2, 3)
BarModel.create(array_field=array_field)
if __name__ == '__main__':
run_test()
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/676/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/676/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/675 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/675/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/675/comments | https://api.github.com/repos/coleifer/peewee/issues/675/events | https://github.com/coleifer/peewee/issues/675 | 97,850,572 | MDU6SXNzdWU5Nzg1MDU3Mg== | 675 | Prefetch syntax | {
"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 | [
"This is to differentiate pre-fetched \"static\" results from the descriptor that exposes related objects as a `SelectQuery`.\n\nI do not plan on changing this, but you can modify your code:\n\n``` python\ndef format_messages(user):\n messages = getattr(user, 'messages_prefetch', user.messages)\n return [message.data for message in messages]\n```\n"
] | 2015-07-29T03:25:15 | 2015-07-29T15:43:12 | 2015-07-29T15:43:11 | CONTRIBUTOR | null | Hey Charles,
I've been writing a few methods with prefetch and find it incredibly useful but I wondered why the syntax is different to the regular, non-prefetch solution and whether it's possible to merge the two approaches.
For example:
``` python
class User(Model):
name = CharField()
class Message(Model):
user = ForeignKeyField(User)
data = TextField()
# Create models and populate data ...
```
Existing (contrived to simplify) prefetch selection solution.
``` python
users = User.select()
messages = Message.select()
data = []
for user in prefetch(users, messages):
data.extend(format_messages(user))
else:
print data
def format_messages(user):
return [message.data for message in user.messages_prefetch]
```
This works great but my dilemma is that now I want to do this:
``` python
user = User.get(User.id == user_id)
data = format_messages(user)
```
And this results in an `AttributeError` on `messages_prefetch` :(
The question I have is how come the prefetch and non-prefetch syntax differ? Surely it's lazy evaluation so either the data is there or it needs to be fulfilled. Is this just an oversight or am I missing something more fundamental? I'm guessing the latter.
What I'm envisaging is that prefetch just uses the regular syntax.
``` python
def format_messages(user):
return [message.data for message in user.messages]
```
Sorry for the annoying question, but it's been bugging me a little while. We use this pattern a fair amount for RESTful GET calls in both single/multiple and I'd like to be able to reuse the same formatting functions.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/675/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/675/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/674 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/674/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/674/comments | https://api.github.com/repos/coleifer/peewee/issues/674/events | https://github.com/coleifer/peewee/issues/674 | 97,821,940 | MDU6SXNzdWU5NzgyMTk0MA== | 674 | [Bug?] Relationships involving a one-to-one relationship throw an exception | {
"login": "EPadronU",
"id": 829947,
"node_id": "MDQ6VXNlcjgyOTk0Nw==",
"avatar_url": "https://avatars.githubusercontent.com/u/829947?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/EPadronU",
"html_url": "https://github.com/EPadronU",
"followers_url": "https://api.github.com/users/EPadronU/followers",
"following_url": "https://api.github.com/users/EPadronU/following{/other_user}",
"gists_url": "https://api.github.com/users/EPadronU/gists{/gist_id}",
"starred_url": "https://api.github.com/users/EPadronU/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/EPadronU/subscriptions",
"organizations_url": "https://api.github.com/users/EPadronU/orgs",
"repos_url": "https://api.github.com/users/EPadronU/repos",
"events_url": "https://api.github.com/users/EPadronU/events{/privacy}",
"received_events_url": "https://api.github.com/users/EPadronU/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Thanks for reporting, fixed in c1030f58c0df67b28fefa75182d6a93698921e01\n",
"Thanks for fixing it so quickly. Cheers.\n"
] | 2015-07-28T23:19:38 | 2015-07-29T18:40:08 | 2015-07-29T16:20:26 | NONE | null | ## Sample layout
```
class User(database.Model):
pass
class Patient(database.Model):
user = ForeignKeyField(User, primary_key=True)
class Disease(database.Model):
pass
class PatientDisease(database.Model):
patient = ForeignKeyField(Patient)
disease = ForeignKeyField(Disease)
```
## The code that throws the exception
```
>> patient = Patient.get(user=1)
>> patient.patientdisease_set
```
## Output | head -n 6
```
$PWD/.venv/lib/python2.7/site-packages/peewee.pyc in _parse(self, node, alias_map, conv)
1546 if conv and isinstance(conv, ForeignKeyField):
1547 params = [
-> 1548 conv.to_field.db_value(getattr(node, conv.to_field.name))]
1549 else:
1550 params = [node._get_pk_value()]
AttributeError: 'User' object has no attribute 'user'
```
## Observations
- This also happens with one-to-many relationships
- This not happens in the other way. For example: `patient_disease.patient`
## Pip freeze
```
blinker==1.3
Flask==0.10.1
Flask-Login==0.2.11
Flask-Mail==0.9.1
Flask-Markdown==0.3
Flask-Principal==0.4.0
Flask-Security==1.7.4
Flask-WTF==0.12
ipython==3.2.1
itsdangerous==0.24
Jinja2==2.7.3
Markdown==2.6.2
MarkupSafe==0.23
passlib==1.6.2
peewee==2.6.3
Werkzeug==0.10.4
wheel==0.24.0
wtf-peewee==0.2.3
WTForms==2.0.2
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/674/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/674/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/673 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/673/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/673/comments | https://api.github.com/repos/coleifer/peewee/issues/673/events | https://github.com/coleifer/peewee/issues/673 | 97,793,429 | MDU6SXNzdWU5Nzc5MzQyOQ== | 673 | Allow specifying MySQL Index Sizes for large columns | {
"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 | [
"IIRC, the newer versions are throwing this error, because they default to having `STRICT_TRANS_TABLES` on.\n",
"@jakedt -- I'm not quite sure I understand. What exactly is going on here?\n",
"When we define a large column that is to be indexed, e.g.:\n\n``` python\nbig_col = CharField(index=True, max_length=1024)\n```\n\nand the version of MySQL defaults to `STRICT_TRANS_TABLES`, subsequent calls to `create_model_tables([ModelWithBigCol])` will cause MySQL to spit out the error from above. We can't change the size of the columns, but we can tell MySQL that we're ok with using a smaller prefix for the index.\n\nHere is an SO post talking about the issue: http://stackoverflow.com/questions/1814532/1071-specified-key-was-too-long-max-key-length-is-767-bytes\n",
"Gotcha -- I think this is a wontfix from my point-of-view. The issue is an implementation detail of MySQL's storage engines, and I don't think Peewee has an opinion on that.\n",
"Is there not something salvageable across DBMSs whereby we can specify the index prefix length though? This would be enough to allow us to work around the MySQL issues, and may prove helpful when other people are defining their indices with peewee, since they know what's best for their data model.\n",
"I ran into this problem myself, and my (admittedly partial) workaround for it was a custom field type:\n\n```\nclass EnforcedCharField(CharField):\n def __init__(self, max_length=255, *args, **kwargs):\n self.max_length = max_length\n super(CharField, self).__init__(*args, **kwargs)\n\n def db_value(self, value):\n if value is None:\n length = 0\n else:\n try:\n length = len(str.encode(value))\n except TypeError:\n length = len(value)\n\n if length > ENFORCED_CHARFIELD_CONSTRAINT:\n from core.error import DatabaseError\n raise DatabaseError(\"The field '{}' cannot be longer than {} bytes. ({})\".format(\n self.name,\n ENFORCED_CHARFIELD_CONSTRAINT,\n request.url))\n return super(CharField, self).db_value(value) \n```\n\n(`ENFORCED_CHARFIELD_CONSTRAINT` is set elsewhere; in this cases it's 767.)\n\nI ran into this problem mainly because of fields where Unicode data was present.\n",
"@jakedt -- what would you propose peewee do if a user defines a `CharField` with an index length exceeding what the storage engine supported? I don't think peewee should silently truncate the index -- instead it should raise an error. Well, MySQL is already raising the error for you, so in my mind there's nothing to do.\n",
"The problem for me is that the column length and the index length are inextricably tied together. If I could add a keyword to my column definition, e.g. `index_prefix_length=128`, and if this worked across providers, that would increase the expressiveness of the peewee model definitions and let me work around my MySQL issue.\n\nRight now, facing this error, I have only one option, reduce the length of my column. If I can't do that because my data model requires a column of that length, I have zero options.\n",
"@jakedt -- could you create the index by hand?\n\n``` python\nclass MyModel(Model):\n big_col = CharField(max_length=1024)\n\n @classmethod\n def create_table(cls, fail_silently=False):\n super(MyModel, cls).create_table(fail_silently=fail_silently)\n cls._meta.database.execute_sql('CREATE INDEX mymodel_big_col ON mymodel (big_col(255))\n```\n",
"@coleifer What you just posted for @jakedt would actually solve my problem quite nicely from the look of it. I never liked the idea of enforcing length constraints for the sake of the underlying index, but I was also reluctant to pass explicit index creations (for the sake of maximum compatibility). Come to think of it, I might be able to set things up so that depending on what database is attached, the appropriate index-creation instructions are passed. (I don't think the example listed would have any ill effects when used in SQLite for instance, but I'd like to ensure it doesn't.)\n",
"We can't do that because then our migration generator tool will assume that we don't want an index. We can extend that to read additional keywords and work around that too, but I think the idea of having a smaller index than the column length is more general than just working around problems. If we take a stab at modifying peewee to allow for specifying an index_length, would you consider merging it?\n\nI don't actually know how to extend the compound index syntax to allow for this yet.\n",
"@jakedt -- so you are proposing silently shortening the index length in Peewee? I don't think it's the ORM's business to do that. As I said,\n\n> The issue is an implementation detail of MySQL's storage engines, and I don't think Peewee has an opinion on that.\n\nI feel like I've proposed a reasonable solution (create the index explicitly), and @syegulalp has proposed another reasonable solution (create a custom field). At this point I feel like you're just complaining.\n"
] | 2015-07-28T20:20:23 | 2015-07-31T03:57:33 | 2015-07-30T14:58:44 | NONE | null | InternalError: (1071, u'Specified key was too long; max key length is 767 bytes')
We get this when we use peewee to `create_table`s, and we have an index constraint on a column larger than 767. Apparently in the past MySQL has just truncated these indices to 767 silently, but newer versions are throwing errors when attempting to create these tables. It would be helpful if we could specify the index size separately to make these errors go away.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/673/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/673/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/672 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/672/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/672/comments | https://api.github.com/repos/coleifer/peewee/issues/672/events | https://github.com/coleifer/peewee/pull/672 | 97,770,686 | MDExOlB1bGxSZXF1ZXN0NDEwNDQ1ODc= | 672 | PasswordField | {
"login": "ronyb29",
"id": 1606872,
"node_id": "MDQ6VXNlcjE2MDY4NzI=",
"avatar_url": "https://avatars.githubusercontent.com/u/1606872?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/ronyb29",
"html_url": "https://github.com/ronyb29",
"followers_url": "https://api.github.com/users/ronyb29/followers",
"following_url": "https://api.github.com/users/ronyb29/following{/other_user}",
"gists_url": "https://api.github.com/users/ronyb29/gists{/gist_id}",
"starred_url": "https://api.github.com/users/ronyb29/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/ronyb29/subscriptions",
"organizations_url": "https://api.github.com/users/ronyb29/orgs",
"repos_url": "https://api.github.com/users/ronyb29/repos",
"events_url": "https://api.github.com/users/ronyb29/events{/privacy}",
"received_events_url": "https://api.github.com/users/ronyb29/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"This looks good, I'm sorry for not responding sooner, completely fell off my radar.\n\nI'd like to merge. Looks like the only issue is the lack of the unicode literal in the earlier python 3 build. If that can be fixed, I'd be happy to merge this.\n",
"Nice! :)\n@coleifer any rough idea when this will be released? \n",
"Hopefully the next week or so. Thank you!\nOn Nov 12, 2015 9:46 AM, \"Yohan Boniface\" [email protected] wrote:\n\n> Nice! :)\n> @coleifer https://github.com/coleifer any rough idea when this will get\n> released?\n> \n> —\n> Reply to this email directly or view it on GitHub\n> https://github.com/coleifer/peewee/pull/672#issuecomment-156142700.\n"
] | 2015-07-28T18:33:25 | 2015-11-12T16:41:42 | 2015-11-06T18:50:23 | CONTRIBUTOR | null | I think i got something going on,
but please see comments on files
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/672/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/672/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/672",
"html_url": "https://github.com/coleifer/peewee/pull/672",
"diff_url": "https://github.com/coleifer/peewee/pull/672.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/672.patch",
"merged_at": "2015-11-06T18:50:23"
} |
https://api.github.com/repos/coleifer/peewee/issues/671 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/671/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/671/comments | https://api.github.com/repos/coleifer/peewee/issues/671/events | https://github.com/coleifer/peewee/issues/671 | 97,305,991 | MDU6SXNzdWU5NzMwNTk5MQ== | 671 | Unable to make custom Field as inner class of an Enum | {
"login": "fluffy-critter",
"id": 347162,
"node_id": "MDQ6VXNlcjM0NzE2Mg==",
"avatar_url": "https://avatars.githubusercontent.com/u/347162?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/fluffy-critter",
"html_url": "https://github.com/fluffy-critter",
"followers_url": "https://api.github.com/users/fluffy-critter/followers",
"following_url": "https://api.github.com/users/fluffy-critter/following{/other_user}",
"gists_url": "https://api.github.com/users/fluffy-critter/gists{/gist_id}",
"starred_url": "https://api.github.com/users/fluffy-critter/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/fluffy-critter/subscriptions",
"organizations_url": "https://api.github.com/users/fluffy-critter/orgs",
"repos_url": "https://api.github.com/users/fluffy-critter/repos",
"events_url": "https://api.github.com/users/fluffy-critter/events{/privacy}",
"received_events_url": "https://api.github.com/users/fluffy-critter/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"This has nothing to do with Peewee as far as I can tell, but is an implementation detail of the `Enum` class.\n",
"Okay, thanks.\n\nDo you have any suggestions for a more Pythonic solution than the (somewhat confusing) `@staticmethod` decorator, or am I just overthinking this? I'm still learning Python and want to establish good habits. :)\n",
"Use @staticmethod.\n",
"Thanks!\n\n## \n\nSent from my tin cans and a piece of string. \n\n> On Jul 27, 2015, at 9:34 AM, Charles Leifer [email protected] wrote:\n> \n> Use @staticmethod.\n> \n> ―\n> Reply to this email directly or view it on GitHub.\n"
] | 2015-07-26T10:35:14 | 2015-07-27T16:35:46 | 2015-07-27T16:10:15 | NONE | null | This might be a peculiar use case, but for better encapsulation I tried doing this:
```
from peewee import *
from enum import Enum
class Foo(Enum):
foobar = 0
qazquux = 1
bleck = 2
class Field(IntegerField):
def db_value(self,value):
return value.value
def python_value(self,value):
return Foo(value)
class TableWithFoo(BaseModel):
stored_foo = Foo.Field()
```
which generates a `TypeError: 'Foo' object is not callable` error. However, if I add a `@staticmethod` decorator to the declaration of `class Field`, it works just fine (and behaves correctly).
The `@staticmethod` decorator is a suitable workaround but it seems inelegant. In other testing I've found that `Enum` base classes allow inner classes without that hack, so I'm guessing the problem lies with subclassing `IntegerField` although I haven't tried creating a custom class with a custom `Field` class inside of it to verify that.
Granted this is all a silly thing to just avoid having FooField as a top-level class, which makes no difference to the functionality or the readability of the code, but it just feels like it should be possible. :)
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/671/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/671/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/670 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/670/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/670/comments | https://api.github.com/repos/coleifer/peewee/issues/670/events | https://github.com/coleifer/peewee/pull/670 | 97,229,468 | MDExOlB1bGxSZXF1ZXN0NDA4Mzc1MTg= | 670 | Minor docs fix regarding Django middleware | {
"login": "messense",
"id": 1556054,
"node_id": "MDQ6VXNlcjE1NTYwNTQ=",
"avatar_url": "https://avatars.githubusercontent.com/u/1556054?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/messense",
"html_url": "https://github.com/messense",
"followers_url": "https://api.github.com/users/messense/followers",
"following_url": "https://api.github.com/users/messense/following{/other_user}",
"gists_url": "https://api.github.com/users/messense/gists{/gist_id}",
"starred_url": "https://api.github.com/users/messense/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/messense/subscriptions",
"organizations_url": "https://api.github.com/users/messense/orgs",
"repos_url": "https://api.github.com/users/messense/repos",
"events_url": "https://api.github.com/users/messense/events{/privacy}",
"received_events_url": "https://api.github.com/users/messense/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Thanks!\n"
] | 2015-07-25T14:17:55 | 2015-07-26T01:51:26 | 2015-07-25T17:23:19 | CONTRIBUTOR | null | Django middleware `process_response` method must return an `HttpResponse` or `StreamingHttpResponse` object as its documentation denotes.
https://docs.djangoproject.com/en/1.8/topics/http/middleware/#process-response
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/670/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/670/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/670",
"html_url": "https://github.com/coleifer/peewee/pull/670",
"diff_url": "https://github.com/coleifer/peewee/pull/670.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/670.patch",
"merged_at": "2015-07-25T17:23:19"
} |
https://api.github.com/repos/coleifer/peewee/issues/669 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/669/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/669/comments | https://api.github.com/repos/coleifer/peewee/issues/669/events | https://github.com/coleifer/peewee/issues/669 | 97,046,640 | MDU6SXNzdWU5NzA0NjY0MA== | 669 | create_or_get sqlite3.InterfaceError with cursor because of commit/rollback | {
"login": "bsuire",
"id": 5952888,
"node_id": "MDQ6VXNlcjU5NTI4ODg=",
"avatar_url": "https://avatars.githubusercontent.com/u/5952888?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/bsuire",
"html_url": "https://github.com/bsuire",
"followers_url": "https://api.github.com/users/bsuire/followers",
"following_url": "https://api.github.com/users/bsuire/following{/other_user}",
"gists_url": "https://api.github.com/users/bsuire/gists{/gist_id}",
"starred_url": "https://api.github.com/users/bsuire/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/bsuire/subscriptions",
"organizations_url": "https://api.github.com/users/bsuire/orgs",
"repos_url": "https://api.github.com/users/bsuire/repos",
"events_url": "https://api.github.com/users/bsuire/events{/privacy}",
"received_events_url": "https://api.github.com/users/bsuire/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Here's my init code:\n\n```\nclass SqliteFKDatabase(SqliteDatabase): \n def initialize_connection(self, conn): \n self.execute_sql('PRAGMA foreign_keys=ON;`)\n```\n\n```\ndb = SqliteFKDatabase(None)\n\ndef init_db(DB): \n db.init(DB) \n\n init_db(TEST_SQL) \n```\n",
"Well, your cursor for the outer `SELECT` statement is still open, so by consuming the outer `SELECT` you should get your code working:\n\n``` python\nfor i in range(1, nb_rows // CHUNK_SIZE + 2): \n rows = (Source.select(Source.name,Source.country) \n .where(Source.status == 'new').paginate(i, CHUNK_SIZE).tuples()) \n\n # CONSUME SELECT\n rows = list(rows)\n\n for name,country in rows: \n person, created = Person.create_or_get(name = name, new = True) \n\n if country: \n country, created = Countries.create_or_get(name = country) \n Person_Country(person_id = person.id, country_id = country.id).save() \n```\n\n`create_or_get` will use a transaction (or savepoint if you're already in a transaction). When this is committed or rolled back, the cursor for the `SELECT` can no longer be used.\n"
] | 2015-07-24T12:56:06 | 2015-07-24T18:34:47 | 2015-07-24T18:34:47 | NONE | null | The create_or_get method yields a pretty weird error for me:
```
File "./script.py", line 137, in load_data
for name,country in rows:
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/peewee.py", line 1957, in next
obj = self.iterate()
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/peewee.py", line 1934, in iterate
row = self.cursor.fetchone()
sqlite3.InterfaceError: Cursor needed to be reset because of commit/rollback and can no longer be fetched from.
```
Here is the offending code:
```
for i in range(1, nb_rows // CHUNK_SIZE + 2):
rows = (Source.select(Source.name,Source.country)
.where(Source.status == 'new').paginate(i, CHUNK_SIZE).tuples())
for name,country in rows:
person, created = Person.create_or_get(name = name, new = True)
if country:
country, created = Countries.create_or_get(name = country)
Person_Country(person_id = person.id, country_id = country.id).save()
```
I replaced the create_or_get statements with try: create(), except get(), and now it works just fine...
Note: using Sqlite3 3.8.9
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/669/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/669/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/668 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/668/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/668/comments | https://api.github.com/repos/coleifer/peewee/issues/668/events | https://github.com/coleifer/peewee/issues/668 | 96,673,436 | MDU6SXNzdWU5NjY3MzQzNg== | 668 | Add support for citext columns in postgres | {
"login": "esafak",
"id": 3928300,
"node_id": "MDQ6VXNlcjM5MjgzMDA=",
"avatar_url": "https://avatars.githubusercontent.com/u/3928300?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/esafak",
"html_url": "https://github.com/esafak",
"followers_url": "https://api.github.com/users/esafak/followers",
"following_url": "https://api.github.com/users/esafak/following{/other_user}",
"gists_url": "https://api.github.com/users/esafak/gists{/gist_id}",
"starred_url": "https://api.github.com/users/esafak/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/esafak/subscriptions",
"organizations_url": "https://api.github.com/users/esafak/orgs",
"repos_url": "https://api.github.com/users/esafak/repos",
"events_url": "https://api.github.com/users/esafak/events{/privacy}",
"received_events_url": "https://api.github.com/users/esafak/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I wouldn't say \"incorrectly\" -- Peewee does not have any field comparable to a case-insensitive text field. Pwiz is designed to cover the most common data-types but it cannot hope to cover them all. Hence, `UnknownField`. You can go through and replace them with `TextField` if you like.\n",
"Aren't `text` and `citext` different, though? Isn't the real problem that peewee doesn't have a case-insensitive field?\n",
"They are different, and yes, the issue is that peewee does not have a case-insensitive text field. That said, I don't plan on adding one. If you'd like you can add one yourself quite easily, though:\n\nhttp://docs.peewee-orm.com/en/latest/peewee/models.html#creating-a-custom-field\n",
"Is it as simple as,\r\n\r\n class CITextField(TextField):\r\n field_type = 'citext'",
"That's all you need."
] | 2015-07-22T21:51:11 | 2018-10-11T18:24:48 | 2015-07-22T22:08:15 | NONE | null | `pwiz` incorrectly translates `citext` columns to `UnknownField`.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/668/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/668/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/667 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/667/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/667/comments | https://api.github.com/repos/coleifer/peewee/issues/667/events | https://github.com/coleifer/peewee/issues/667 | 96,635,597 | MDU6SXNzdWU5NjYzNTU5Nw== | 667 | peewee tries to hard to connect to a data store | {
"login": "dmead",
"id": 176946,
"node_id": "MDQ6VXNlcjE3Njk0Ng==",
"avatar_url": "https://avatars.githubusercontent.com/u/176946?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/dmead",
"html_url": "https://github.com/dmead",
"followers_url": "https://api.github.com/users/dmead/followers",
"following_url": "https://api.github.com/users/dmead/following{/other_user}",
"gists_url": "https://api.github.com/users/dmead/gists{/gist_id}",
"starred_url": "https://api.github.com/users/dmead/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/dmead/subscriptions",
"organizations_url": "https://api.github.com/users/dmead/orgs",
"repos_url": "https://api.github.com/users/dmead/repos",
"events_url": "https://api.github.com/users/dmead/events{/privacy}",
"received_events_url": "https://api.github.com/users/dmead/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Where are you using sqlite3 been mentioned in your code example?\nOn Jul 22, 2015 11:08 PM, \"Daniel Mead\" [email protected] wrote:\n\n> I've just had a problem were i didn't have MySQLdb installed, so peewee\n> failed over to sqlite3\n> \n> this was really annoying because it happened silently and without warning.\n> \n> im using a statement like this to connect\n> \n> db = MySQLDatabase('somedatabase', host='127.0.0.1', port=3306,\n> user='user', passwd='pass')\n> \n> —\n> Reply to this email directly or view it on GitHub\n> https://github.com/coleifer/peewee/issues/667.\n",
"thats the point. i'm not. peewee is defaulting to write to a file called \"peewee.db\" every time.\n",
"Peewee will not do this silently. Can you share your model definitions? I'm wondering if you neglected to set the db for your models.\n",
"``` python\nfrom myproject import database\n\nclass BaseModel(Model):\n class Meta:\n db = database\n```\n\ni'm also using arnold to run table creation stuff, if that matters to you\n",
"Peewee raises an exception on not installing pymysql and MySQLdb! Which\nversion are you using?\nOn Jul 22, 2015 11:13 PM, \"Daniel Mead\" [email protected] wrote:\n\n> thats the point. i'm not. peewee is defaulting to write to a file called\n> \"peewee.db\" every time.\n> \n> —\n> Reply to this email directly or view it on GitHub\n> https://github.com/coleifer/peewee/issues/667#issuecomment-123822485.\n",
"i have both installed. actually.\n",
"Pay attention, is your code running correctly? Any old edition of code\ncached and run? Can you paste your file content and describe a little about\nyour process of run code?\nOn Jul 22, 2015 11:32 PM, \"Daniel Mead\" [email protected] wrote:\n\n> i have both installed. actually.\n> \n> —\n> Reply to this email directly or view it on GitHub\n> https://github.com/coleifer/peewee/issues/667#issuecomment-123828265.\n",
"Yeah, basically this doesn't add up. Peewee won't silently \"fall back\" to SQLite if you're trying to use MySQL. And if you don't have a mysql driver installed and try to use MySQLDatabase, it will raise an error.\n",
"my bad.\n\nthe ref i had inside the base model was bad. it was actually falling back to sqlite but it was my fault.\n"
] | 2015-07-22T18:38:15 | 2015-07-22T21:01:42 | 2015-07-22T20:14:07 | NONE | null | I've just had a problem were i didn't have MySQLdb installed, so peewee failed over to sqlite3
this was really annoying because it happened silently and without warning.
im using a statement like this to connect
`db = MySQLDatabase('somedatabase', host='127.0.0.1', port=3306, user='user', passwd='pass')`
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/667/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/667/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/666 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/666/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/666/comments | https://api.github.com/repos/coleifer/peewee/issues/666/events | https://github.com/coleifer/peewee/issues/666 | 96,592,623 | MDU6SXNzdWU5NjU5MjYyMw== | 666 | why does peewee default to it's own file? | {
"login": "dmead",
"id": 176946,
"node_id": "MDQ6VXNlcjE3Njk0Ng==",
"avatar_url": "https://avatars.githubusercontent.com/u/176946?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/dmead",
"html_url": "https://github.com/dmead",
"followers_url": "https://api.github.com/users/dmead/followers",
"following_url": "https://api.github.com/users/dmead/following{/other_user}",
"gists_url": "https://api.github.com/users/dmead/gists{/gist_id}",
"starred_url": "https://api.github.com/users/dmead/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/dmead/subscriptions",
"organizations_url": "https://api.github.com/users/dmead/orgs",
"repos_url": "https://api.github.com/users/dmead/repos",
"events_url": "https://api.github.com/users/dmead/events{/privacy}",
"received_events_url": "https://api.github.com/users/dmead/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"That line of code is there to allow you to quickly create models that point to a SQLite database named `peewee.db`. So if you just imported `Model` and did not define your own database, it would use the `default_database`.\n\nMost everyone will define their own db, though, so this is not an issue in practice, e.g.\n\n``` python\nfrom peewee import *\n\ndb = SqliteDatabase('my_database.db')\n\nclass BaseModel(Model):\n class Meta:\n database = db\n\n# application models extend `BaseModel`.\n```\n"
] | 2015-07-22T15:18:15 | 2015-07-22T16:32:30 | 2015-07-22T16:32:30 | NONE | null | https://github.com/coleifer/peewee/blob/master/peewee.py#L3955
maybe i lack contact about sqlite? why is this hard coded to it's own filename?
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/666/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/666/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/665 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/665/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/665/comments | https://api.github.com/repos/coleifer/peewee/issues/665/events | https://github.com/coleifer/peewee/issues/665 | 96,537,423 | MDU6SXNzdWU5NjUzNzQyMw== | 665 | Inner query problem | {
"login": "dneyirp",
"id": 13450224,
"node_id": "MDQ6VXNlcjEzNDUwMjI0",
"avatar_url": "https://avatars.githubusercontent.com/u/13450224?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/dneyirp",
"html_url": "https://github.com/dneyirp",
"followers_url": "https://api.github.com/users/dneyirp/followers",
"following_url": "https://api.github.com/users/dneyirp/following{/other_user}",
"gists_url": "https://api.github.com/users/dneyirp/gists{/gist_id}",
"starred_url": "https://api.github.com/users/dneyirp/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/dneyirp/subscriptions",
"organizations_url": "https://api.github.com/users/dneyirp/orgs",
"repos_url": "https://api.github.com/users/dneyirp/repos",
"events_url": "https://api.github.com/users/dneyirp/events{/privacy}",
"received_events_url": "https://api.github.com/users/dneyirp/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Change:\n\n``` python\ninner_query = Log.select().order_by(Log.DateTimeUTC.desc()).limit(20)\n```\n\nTo:\n\n``` python\ninner_query = Log.select(Log).order_by(Log.DateTimeUTC.desc()).limit(20)\n```\n\nIf a subquery does not have an explicit selection, peewee assumes you just want the primary key, hence the missing column.\n"
] | 2015-07-22T11:03:07 | 2015-07-22T16:30:18 | 2015-07-22T16:30:17 | NONE | null | Hi. I need to execute the following SQL statement but use Peewee's library to do it and prefer not to use raw sql.
Table "Log" has has this structure:
``` sql
CREATE TABLE "Log" ("Id" INTEGER NOT NULL PRIMARY KEY, "DateTimeUTC" DATETIME NOT NULL, "Value" INTEGER NOT NULL)
```
SQL query needing translation:
``` sql
select * from
(select * from Log
order by DateTimeUTC desc
limit 20
)
order by DateTimeUTC
```
I have been helped by the author of Peewee ORM, Charles, with the following code:
``` python
inner_query = Log.select().order_by(Log.DateTimeUTC.desc()).limit(20)
query = Log.select().from_(inner_query).order_by(Log.DateTimeUTC)
```
This generates an error:
`OperationalError: no such column: t1.Id`
I was then given a modification to try:
``` python
inner_query = Log.select().order_by(Log.DateTimeUTC.desc()).limit(20)
inner_query = inner_query.alias('t1')
query = Log.select().from_(inner_query).order_by(Log.DateTimeUTC)
```
However I get another error:
`OperationalError: no such column: t1.DateTimeUTC`
Looking at the debug code Peewee provides:
`[2015-07-22 12:04:23,822] [peewee] DEBUG]: ('SELECT "t1"."Id", "t1"."DateTimeUTC", "t1"."Value" FROM (SELECT "t2"."Id" FROM "Log" AS t2 ORDER BY "t2"."DateTimeUTC" DESC LIMIT 20) AS t1 ORDER BY "t1"."DateTimeUTC" ASC', [])`
It seems that when Peewee is executing the first line of the last snippet `inner_query = Log.select()...`, the conversion to SQL is incorrect and only using the `".Id"` field instead of all fields in the select() and result in the "no such column" error.
Firstly it seems that the need to add the line `inner_query = inner_query.alias('t1')` looks like a bug as "t1" is not used in my query.
Secondly there seems to be a bug somewhere in translating `select()` to SQL when you have an inner query as only one field is being used when all should be used.
Many thanks
P
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/665/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/665/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/664 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/664/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/664/comments | https://api.github.com/repos/coleifer/peewee/issues/664/events | https://github.com/coleifer/peewee/issues/664 | 96,420,607 | MDU6SXNzdWU5NjQyMDYwNw== | 664 | Fractional DateTimeField values | {
"login": "ParthGandhi",
"id": 819237,
"node_id": "MDQ6VXNlcjgxOTIzNw==",
"avatar_url": "https://avatars.githubusercontent.com/u/819237?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/ParthGandhi",
"html_url": "https://github.com/ParthGandhi",
"followers_url": "https://api.github.com/users/ParthGandhi/followers",
"following_url": "https://api.github.com/users/ParthGandhi/following{/other_user}",
"gists_url": "https://api.github.com/users/ParthGandhi/gists{/gist_id}",
"starred_url": "https://api.github.com/users/ParthGandhi/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/ParthGandhi/subscriptions",
"organizations_url": "https://api.github.com/users/ParthGandhi/orgs",
"repos_url": "https://api.github.com/users/ParthGandhi/repos",
"events_url": "https://api.github.com/users/ParthGandhi/events{/privacy}",
"received_events_url": "https://api.github.com/users/ParthGandhi/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"What database are you using? The code you've referenced is not relevant to your question as far as I understand what you're asking. The code you want is probably here:\n\nhttps://github.com/coleifer/peewee/blob/1b021602a222485d5f28857a363cd378dc874df0/peewee.py#L1050-L1068\n\nBasically, peewee will just pass the `datetime` object back to the database driver (psycopg2, sqlite3, pymysql, etc). From there, it's up to the database driver what to do with the Python `datetime` object. When Peewee reads the value _back_ from the database, some dbs (SQLite) may return it as a string, so there is logic to convert the string into a `datetime` object. As you can see in the `formats` list, peewee will attempt to parse out microseconds.\n",
"Yeah, you're right. Though I still can't get it to work, so maybe i'm missing something.\n\nI'm using MySQL 5.7.\n\nAn example (mostly copied from the docs) is:\n\n```\nclass Person(Model):\n name = CharField()\n birthday = DateTimeField()\n\n class Meta:\n database = db\n\np = Person(name='Bob', birthday=datetime.datetime.now())\np.save()\n\nPerson.get(Person.name == 'Bob').birthday # output: datetime.datetime(2015, 7, 21, 14, 57, 26)\n```\n\nBut... looking at the SQL table directly shows that it isn't stored entirely (i.e. the value is stored as \"2015-07-21 14:57:26\"). So its a problem during storage, not retrieval. Note that the default fractional part for a `DATETIME` column in MySQL (>= 5.6.4) is 0 (https://dev.mysql.com/doc/refman/5.7/en/fractional-seconds.html).\n",
"I'd suggest checking out your python driver, as Peewee really should just be passing back the `datetime` object directly to it.\n",
"Aren't the drivers a part of peewee? Unless I misunderstand what you mean.\n",
"No, pymysql and mysql-python, etc are separate packages.\n",
"D'oh. Thanks, i'll look into those.\n",
"FYI, the problem wasn't on PyMySQLs end.\n\nWhat happens is that the default `QueryCompiler` (https://github.com/coleifer/peewee/blob/master/peewee.py#L1350) datetime conversion results in columns being created as \"DATETIME\". But MySQL defaults fractional parts to 0 so any saves resulted in the datetime being truncated. The solution is to override the `field_map` when creating the `Database` instance: `db = MySQLDatabase(..., fields={'datetime': 'DATETIME(6)'})`. This forces all `DATETIME` columns to have fsp 6.\n",
"You can create a custom field type or specify one or more `field_overrides` when instantiating your database.\n- http://docs.peewee-orm.com/en/latest/peewee/models.html#creating-a-custom-field\n- http://docs.peewee-orm.com/en/latest/peewee/api.html#Database\n",
"After read the information you provided, I got this, and it seems work:\n\n```\ndatabase = MySQLDatabase(dbname, fields={'datetime_fsp6': 'DATETIME(6)'})\n```\n\n```\nclass DateTimeFsp6Field(DateTimeField):\n db_field = 'datetime_fsp6'\n```\n\n```\nclass FooModel(Model):\n ctime = DateTimeFsp6Field(default=datetime.datetime.now)\n```\n",
"Thanks for sharing your solution @binderclip!\n",
"Shouldn't @binderclip be the default for Mysql ?",
"@luisulloa IIUC, not all MySql versions support this"
] | 2015-07-21T21:29:06 | 2017-11-30T12:13:50 | 2015-07-21T21:38:50 | NONE | null | The fractional part of a `datetime` object seems to be always truncated. Looking through the code a bit, I also see that it doesn't expect there to be one: https://github.com/coleifer/peewee/blob/master/peewee.py#L204
I assume this is primarily cause not all databases support fractional seconds (older versions of MySQL, for instance). Is there a way to optionally support it if the database underneath supports it?
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/664/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/664/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/663 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/663/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/663/comments | https://api.github.com/repos/coleifer/peewee/issues/663/events | https://github.com/coleifer/peewee/issues/663 | 96,238,708 | MDU6SXNzdWU5NjIzODcwOA== | 663 | How to select() the fields I need | {
"login": "AlexHeKa",
"id": 9191522,
"node_id": "MDQ6VXNlcjkxOTE1MjI=",
"avatar_url": "https://avatars.githubusercontent.com/u/9191522?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/AlexHeKa",
"html_url": "https://github.com/AlexHeKa",
"followers_url": "https://api.github.com/users/AlexHeKa/followers",
"following_url": "https://api.github.com/users/AlexHeKa/following{/other_user}",
"gists_url": "https://api.github.com/users/AlexHeKa/gists{/gist_id}",
"starred_url": "https://api.github.com/users/AlexHeKa/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/AlexHeKa/subscriptions",
"organizations_url": "https://api.github.com/users/AlexHeKa/orgs",
"repos_url": "https://api.github.com/users/AlexHeKa/repos",
"events_url": "https://api.github.com/users/AlexHeKa/events{/privacy}",
"received_events_url": "https://api.github.com/users/AlexHeKa/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Cool models bro, what's your question?\n",
"Maybe `query.tuples()` or `query.dicts()` are exactly what you looking for?\n",
"You want something like:\n\n``` python\nPost.select(Post.post_title, Post.post_content, User.username).join(User)\n```\n\nThen you can iterate through the results of the query and access `post.post_title`, `post.post_content`, and `post.user.username`.\n",
"For future reference, questions like this belong on StackOverflow rather than the peewee bug tracker.\n",
"When I used\n\n``` python\nquery = Post.select(Post.post_title, Post.post_content).join(Act).where(Act.id == actId).paginate(actPage, 15)\nquery_dataList = []\nfor query_line in query:\n query_data = model_to_dict(query_line)\n query_dataList.append(query_data) \n json_data = json.dumps(query_dataList)\n```\n\nthen converted it to json,I got this\n\n``` json\n[{\"post_views_count\": null, \"post_title\": \"\\u4e0d\\u9519\", \"post_comments_count\": null, \"post_likes_count\": null...\n```\n\nIt seems like the fields I didn't include in the \"select()\" return null,and I only want the selected fields.I'm not sure is't something wrong with my code or it is designed like this and I will ask in StackOverflow next time,Thanks.\n",
"function `model_to_dict` serialises **all** fields from model (wholly). You should use `model_to_dict(query_line, only=(Post.post_title, Post.post_content))`.\n\nOr as I said before use `query.dicts()`\n",
"Yes, you should read the documentation on `model_to_dict`: http://docs.peewee-orm.com/en/latest/peewee/playhouse.html#model_to_dict\n\nIt will serialize everything unless you specify `only`, which in your case seems to be what you want.\n",
"@klen @coleifer Thanks bro.\n"
] | 2015-07-21T06:23:04 | 2015-07-22T11:38:14 | 2015-07-21T14:17:00 | NONE | null | I wanna get Post.post_title,Post.post_content...and also try to get User.user_name which its id == Post.user
I try
``` python
query = Post.select().join(Act).where(Act.id == actId).paginate(actPage, 10) or
query = Post.select(Post.post_title,Post.post_content).join(Act).where(Act.id == actId).paginate(actPage, 10)
```
But it returns all the fields in User,Act,Post,so how to select() the fields I need? Thanks
Here is my model
``` python
class User(BaseModel):
user_name = CharField(max_length=30,unique=True)
user_email = CharField(max_length=60,unique=True)
user_pass = CharField(max_length=60)
user_salt = CharField(max_length=128)
user_registeredTime = DateTimeField()
user_portrait_url = CharField(max_length=400,default="http:/xxx.com")
user_point = IntegerField(default=0)
user_message = CharField(max_length=60,null=True)
class Act(BaseModel):
user = ForeignKeyField(User, related_name='users_id')
act_title = CharField(max_length=30)
act_content = CharField(max_length=420)
act_thumb_url = CharField(max_length=400)
act_type = IntegerField(default=0)
act_star = IntegerField(default=0)
act_status = IntegerField(default=0)
act_alias = CharField(max_length=30)
act_url = CharField(max_length=400)
act_date_gmt = DateTimeField()
class Post(BaseModel):
act = ForeignKeyField(Act, related_name='acts_id')
user = ForeignKeyField(User, related_name='users_id2')
post_title = CharField(max_length=30)
post_content = CharField(max_length=180)
post_thumb_url = CharField(max_length=400)
post_date_gmt = DoubleField()
post_likes_count = IntegerField()
post_comments_count = IntegerField()
post_views_count = IntegerField()
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/663/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/663/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/662 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/662/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/662/comments | https://api.github.com/repos/coleifer/peewee/issues/662/events | https://github.com/coleifer/peewee/issues/662 | 96,236,825 | MDU6SXNzdWU5NjIzNjgyNQ== | 662 | How to select() | {
"login": "AlexHeKa",
"id": 9191522,
"node_id": "MDQ6VXNlcjkxOTE1MjI=",
"avatar_url": "https://avatars.githubusercontent.com/u/9191522?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/AlexHeKa",
"html_url": "https://github.com/AlexHeKa",
"followers_url": "https://api.github.com/users/AlexHeKa/followers",
"following_url": "https://api.github.com/users/AlexHeKa/following{/other_user}",
"gists_url": "https://api.github.com/users/AlexHeKa/gists{/gist_id}",
"starred_url": "https://api.github.com/users/AlexHeKa/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/AlexHeKa/subscriptions",
"organizations_url": "https://api.github.com/users/AlexHeKa/orgs",
"repos_url": "https://api.github.com/users/AlexHeKa/repos",
"events_url": "https://api.github.com/users/AlexHeKa/events{/privacy}",
"received_events_url": "https://api.github.com/users/AlexHeKa/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2015-07-21T06:07:07 | 2015-07-21T06:07:35 | 2015-07-21T06:07:35 | NONE | null | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/662/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/662/timeline | null | completed | null | null |
|
https://api.github.com/repos/coleifer/peewee/issues/661 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/661/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/661/comments | https://api.github.com/repos/coleifer/peewee/issues/661/events | https://github.com/coleifer/peewee/issues/661 | 95,970,470 | MDU6SXNzdWU5NTk3MDQ3MA== | 661 | Property getters/setters don't work with `get_or_create` | {
"login": "fluffy-critter",
"id": 347162,
"node_id": "MDQ6VXNlcjM0NzE2Mg==",
"avatar_url": "https://avatars.githubusercontent.com/u/347162?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/fluffy-critter",
"html_url": "https://github.com/fluffy-critter",
"followers_url": "https://api.github.com/users/fluffy-critter/followers",
"following_url": "https://api.github.com/users/fluffy-critter/following{/other_user}",
"gists_url": "https://api.github.com/users/fluffy-critter/gists{/gist_id}",
"starred_url": "https://api.github.com/users/fluffy-critter/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/fluffy-critter/subscriptions",
"organizations_url": "https://api.github.com/users/fluffy-critter/orgs",
"repos_url": "https://api.github.com/users/fluffy-critter/repos",
"events_url": "https://api.github.com/users/fluffy-critter/events{/privacy}",
"received_events_url": "https://api.github.com/users/fluffy-critter/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Closing, because I realized that the underlying problem is with `get` and that trying to do a `get` on a derived key like this makes no dang sense.\n"
] | 2015-07-20T02:26:08 | 2015-07-20T02:36:51 | 2015-07-20T02:36:24 | NONE | null | This is on version 2.6.3, as installed via OSX's `easy_install` function.
I have a project in which I'd like to automatically derive a human-readable sorting key from a title (or in this case, a band name). I have this code for it (simplified):
```
def to_key(name):
return re.sub(r'^(a|the) (.*)$', r'\2, \1', name.lower())
class Band(BaseModel):
@property
def name(self):
return self.display_name
@name.setter
def name(self, value):
self.display_name = value
self.sort_key = to_key(value)
sort_key = CharField(unique=True)
display_name = CharField(unique=True)
```
This works fine with the model constructor:
```
>>> band = Band(name='The stupidest band name ever')
>>> band.sort_key
'stupidest band name ever, the'
>>> band.display_name
'The stupidest band name ever'
>>> band.save()
1
```
but if I try to use it through `get_or_create` I get an error:
```
>>> band,created = Band.get_or_create(name="The Terrible Trio")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "build/bdist.macosx-10.10-intel/egg/peewee.py", line 4145, in get_or_create
File "build/bdist.macosx-10.10-intel/egg/peewee.py", line 2740, in get
File "build/bdist.macosx-10.10-intel/egg/peewee.py", line 2787, in execute
File "build/bdist.macosx-10.10-intel/egg/peewee.py", line 2470, in _execute
File "build/bdist.macosx-10.10-intel/egg/peewee.py", line 3199, in execute_sql
File "build/bdist.macosx-10.10-intel/egg/peewee.py", line 3048, in __exit__
File "build/bdist.macosx-10.10-intel/egg/peewee.py", line 3191, in execute_sql
peewee.InterfaceError: Error binding parameter 0 - probably unsupported type.
```
although if I explicitly set the individual properties it's fine:
```
>>> band,created = Band.get_or_create(display_name="Harry",sort_key="Larry")
>>> created
True
>>> band.name
'Harry'
>>> band.display_name
'Harry'
>>> band.sort_key
'Larry'
```
Supporting this isn't a particularly big deal for this project, but it'd be a nice to have.
The obvious question would be how to support ambiguous things like:
```
Band.get_or_create(name="The Sugar Shock")
Band.get_or_create(name="Sugar Shock, The")
```
In this case I'd expect the first one to create a new entry with `display_name='The Sugar Shock'` and the second one to throw an exception because it'd try to create a new entry that violates the uniqueness constraint on `sort_key`, but I'm not sure if that's generally the correct thing to expect (or if this even makes a lick of sense in general).
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/661/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/661/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/660 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/660/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/660/comments | https://api.github.com/repos/coleifer/peewee/issues/660/events | https://github.com/coleifer/peewee/issues/660 | 95,860,329 | MDU6SXNzdWU5NTg2MDMyOQ== | 660 | Simple question on multiple Model instances from single Join query | {
"login": "jessepeterson",
"id": 694298,
"node_id": "MDQ6VXNlcjY5NDI5OA==",
"avatar_url": "https://avatars.githubusercontent.com/u/694298?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/jessepeterson",
"html_url": "https://github.com/jessepeterson",
"followers_url": "https://api.github.com/users/jessepeterson/followers",
"following_url": "https://api.github.com/users/jessepeterson/following{/other_user}",
"gists_url": "https://api.github.com/users/jessepeterson/gists{/gist_id}",
"starred_url": "https://api.github.com/users/jessepeterson/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/jessepeterson/subscriptions",
"organizations_url": "https://api.github.com/users/jessepeterson/orgs",
"repos_url": "https://api.github.com/users/jessepeterson/repos",
"events_url": "https://api.github.com/users/jessepeterson/events{/privacy}",
"received_events_url": "https://api.github.com/users/jessepeterson/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I should add that if I access the `related_name` references of my M:N table I can get to the associated data — but at the cost of multiple queries (hence the join is sort of useless). I _should_ be able to get two instances from a single query, no? `aggregate_rows()` and `prefetch()` don't seem to apply to this very simple case. Any help is appreciated!\n",
"You need to also select the junction table:\n\n``` python\nq = Student.select(Student, StudentTeacher, Teacher).join(StudentTeacher).join(Teacher).where(Student.name == 'Bob')\n```\n\nThen you can access it via:\n\n``` python\nrow.studentteacher.teacher\n```\n"
] | 2015-07-18T21:15:02 | 2015-07-20T16:29:37 | 2015-07-20T16:29:37 | NONE | null | First: thanks for Peewee: it's great! Sorry to litter the bug tracker with a simple question, but I'm not able to figure out how to get multiple model instances from a single joined row. For example:
``` python
q = Student.select(Student, Teacher).join(StudentTeacher).join(Teacher).where(Student.name == 'Bob')
for row in q:
print row # is only a Student instance, where is Teacher?
```
When I iterate over `q` I only get a Student instance. How do I get the associated Teacher model instance out of a simple join query like above? When I turn on query logging it's clearly querying for the relevant fields.
I could use `.dict()` to get the raw values and rebuild each model instance separately I suppose but that seems overly laborious.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/660/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/660/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/659 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/659/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/659/comments | https://api.github.com/repos/coleifer/peewee/issues/659/events | https://github.com/coleifer/peewee/issues/659 | 95,300,220 | MDU6SXNzdWU5NTMwMDIyMA== | 659 | Syntax Error whilst inserting model where model has only primary key or ManyToManyField column | {
"login": "MrJohz",
"id": 4059026,
"node_id": "MDQ6VXNlcjQwNTkwMjY=",
"avatar_url": "https://avatars.githubusercontent.com/u/4059026?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/MrJohz",
"html_url": "https://github.com/MrJohz",
"followers_url": "https://api.github.com/users/MrJohz/followers",
"following_url": "https://api.github.com/users/MrJohz/following{/other_user}",
"gists_url": "https://api.github.com/users/MrJohz/gists{/gist_id}",
"starred_url": "https://api.github.com/users/MrJohz/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/MrJohz/subscriptions",
"organizations_url": "https://api.github.com/users/MrJohz/orgs",
"repos_url": "https://api.github.com/users/MrJohz/repos",
"events_url": "https://api.github.com/users/MrJohz/events{/privacy}",
"received_events_url": "https://api.github.com/users/MrJohz/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"What benefit do you get from having a model that only many-to-many's to another model?\n",
"Not to say your issue isn't valid, but just curious as it seems strange.\n",
"Well, testing with SQLite, I'm not sure that there's a way to actually `INSERT` \"nothing\" into a table that has only an auto-incrementing primary key.\n\nHere's what Peewee is trying:\n\n``` sql\nINSERT INTO \"failuremodel\"\n```\n\nBut it also fails if I try:\n\n``` sql\nINSERT INTO \"failuremodel\" ()\n```\n\nI think that you might be out of luck on this one.\n",
"It does seem a bit weird, but (apart from the syntax errors...) it works quite well - there are a bunch of values stored, and each request to a certain endpoint needs to be stored and connected to those values. Normally I'd just make each value a column, but I'm trying to set the system up so that more values can be added at a later date without having to migrate the database.\n\nAccording to the sqlite docs (https://www.sqlite.org/lang_insert.html), the third form of insert allows you to just write \"DEFAULT VALUES\" instead of specifying them. (According to Google, SQL Server also has the same issue and solution). I don't think this is necessary for mysql or pgsql, although I didn't really look to much into it. Is it possible for peewee to do that?\n\nThanks for replying so quickly!\n",
"Having looked a bit further, sqlite and postgreSQL both allow the \"DEFAULT VALUES\" syntax, which replaces the \"VALUES (expr*)\" part of an insert query ([sqlite](https://www.sqlite.org/lang_insert.html), [pg](http://www.postgresql.org/docs/8.2/static/sql-insert.html)). MySQL doesn't allow this, but does allow the \"expr\" part to be replaced by the keyword \"DEFAULT\" ([mysql](http://dev.mysql.com/doc/refman/5.6/en/insert.html)), which does essentially the same thing assuming you know how many columns there are.\n\nI guess the question is whether the default row case (regardless of the number of columns) is a special enough case for peewee to treat it separately and call out to the default value syntaxes for the different DBs. What do you reckon?\n",
"Thanks for looking into this, I'll see about updating peewee accordingly.\n",
"Thanks!\n"
] | 2015-07-15T22:02:38 | 2015-07-27T20:47:08 | 2015-07-27T17:34:04 | NONE | null | Test script: https://gist.github.com/MrJohz/863042d7d9abb80a35f9
``` console
$ python --version
Python 3.4.3
$ pip freeze
peewee==2.6.3
$ python test.py
(F) FailureModel instantiation failed: OperationalError('near ""failuremodel"": syntax error',)
(F) ManyToManyFailureModel instantiation (via create) failed: OperationalError('near ""manytomanyfailuremodel"": syntax error',)
(F) ManyToManyFailureModel instantiation (via __init__) failed: OperationalError('near ""manytomanyfailuremodel"": syntax error',)
(F) ManyToManyFailureModel instantiation (via insert) failed: OperationalError('near ""manytomanyfailuremodel"": syntax error',)
(S) SuccessfulModel instantiation succeeded
```
I have a model that only contains a single ManyToManyField. I want to create a row, insert it into the table, and start adding links using the `ManyToManyField.add()` method, but I keep on getting an OperationalError syntax error. Is this a bug, or am I doing something very bad and wrong?
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/659/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/659/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/658 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/658/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/658/comments | https://api.github.com/repos/coleifer/peewee/issues/658/events | https://github.com/coleifer/peewee/issues/658 | 95,127,572 | MDU6SXNzdWU5NTEyNzU3Mg== | 658 | Optimistic locking | {
"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 | [
"The typical way to handle this is to select the record you're modifying `FOR UPDATE` (see [docs](http://docs.peewee-orm.com/en/latest/peewee/api.html#SelectQuery.for_update)). Here's a [blog post](http://blog.2ndquadrant.com/postgresql-anti-patterns-read-modify-write-cycles/) you might also find useful. Note that this only works with Postgresql.\n",
"@coleifer `FOR UPDATE` is for pessimistic locking, while I explicitly need optimistic locking here. A user who opens up data for modification might think for a long time (while modifying a form) and even vanish without never submitting the changes. So, optimistic locking suits my use case better.\n\nIt sounds like there's no builtin support for this. Would you implement it as I sketched above or do you have a more sophisticated approach?\n",
"I don't have any plans on adding this to Peewee itself, so you can choose the implementation that best suits your use-case.\n",
"@coleifer I finally have to implement this. If I made a PR for it, would consider merging it into peewee? It could work like:\n\n```\nclass MyModel(peewee.Model):\n version = IntegerVersionField()\n\nm = MyModel()\nm.save()\nm1 = MyModel.get()\nm2 = MyModel.get()\nm1.save()\nm2.save() # would throw error\n\nm2.save(optimistic=False) # temporarily disable locking\n```\n\nOr it could be:\n\n```\nclass MyModel(peewee.Model):\n version = IntegerField(default=1)\n\n class Meta:\n version_field = 'version'\n```\n\nI don't have strong opinion on the API, I just wish it was included in peewee and would not break during version upgrades. This touches part of core functionalities (`save()`) so I'm not sure if this could go into playhouse?\n\nIt shouldn't need too many modifications to `Model.save()`, the core idea would be something like:\n\n```\n if self._meta.version_field:\n field_dict[self._meta.version_field] += 1\n rows = self.update(**field_dict).where(self._pk_expr() & (self._meta.fields[self._meta.version_field] == getattr(self, self._meta.version_field))).execute()\n if rows != 1:\n raise Exception(\"Something to indicate that update did not succeed. The cause is probably in version mismatch, but it could be that object with PK was no longer there :|\")\n else:\n rows = self.update(**field_dict).where(self._pk_expr()).execute()\n```\n\nMaybe something more sophisticated than `getattr` etc.\n\nI am personally doing locking based on integer version field, but it could be timestamp, hash, or anything.\n\nWhat do you think?\n",
"That's pretty cool, but honestly I think that is just enough beyond the\nscope that I'd rather it live as its own project. By all means you can\ncreate your own base middle class that overrides save.\n\nThere is enough complexity there that I think I could get bogged down\nsupporting exotic edge cases or who knows, and really I want to focus on\npeewee.\nOn Dec 7, 2015 2:39 AM, \"Tuukka Mustonen\" [email protected] wrote:\n\n> @coleifer https://github.com/coleifer I finally have to implement this.\n> If I made a PR for it, would consider merging it into peewee? It could work\n> like:\n> \n> class MyModel(peewee.Model):\n> version = IntegerVersionField()\n> \n> m = MyModel()\n> m.save()\n> m1 = MyModel.get()\n> m2 = MyModel.get()\n> m1.save()\n> m2.save() # would throw error\n> \n> m2.save(optimistic=False) # temporarily disable locking\n> \n> Or it could be:\n> \n> class MyModel(peewee.Model):\n> version = IntegerField(default=1)\n> \n> ```\n> class Meta:\n> version_field = 'version'\n> ```\n> \n> I don't have strong opinion on the API, I just wish it was included in\n> peewee and would not break during version upgrades. This touches part of\n> core functionalities (save()) so I'm not sure if this could go into\n> playhouse?\n> \n> It shouldn't need too many modifications to Model.save(), the core idea\n> would be something like:\n> \n> ```\n> if self._meta.version_field:\n> field_dict[self._meta.version_field] += 1\n> rows = self.update(**field_dict).where(self._pk_expr() & (self._meta.fields[self._meta.version_field] == getattr(self, self._meta.version_field))).execute()\n> if rows != 1:\n> raise Exception(\"Something to indicate that update did not succeed. The cause is probably in version mismatch, but it could be that object with PK was no longer there :|\")\n> else:\n> rows = self.update(**field_dict).where(self._pk_expr()).execute()\n> ```\n> \n> Maybe something more sophisticated than getattr etc.\n> \n> I am personally doing locking based on integer version field, but it could\n> be timestamp, hash, or anything.\n> \n> What do you think?\n> \n> —\n> Reply to this email directly or view it on GitHub\n> https://github.com/coleifer/peewee/issues/658#issuecomment-162448760.\n",
"Personally I would love to see this as part of peewee, as it's something I found useful when I was using Ruby's ActiveRecord. Until now I wasn't doing optimistic locking in my peewee based projects, just because I was lazy to implement it myself...\n\n@tuukkamustonen if you end up implementing it in a separate lib, please post the link here. \nAnd about your suggested implementation - I suggest using a dedicated exception, so it can be properly handled by using code.\n",
"@tuukkamustonen: just throwing a +1 here - if this is something you've already written, I'd love to see the code!\n",
"@arikfr @tconkling Well, I am just pasting here the code I'm running atm. Maybe @coleifer wants to sanity check it, too.\n\nI am not running it in production, nor do I have extensive test suite for it. It's just something I threw in for now, and I actually had it back in my head to ask for comments at some point.\n\nThe big drawback is that this code is pretty much bound to a specific peewee version, because it re-writes the whole `save` method. Of course, one could rename it differently, but, well.\n\nA model is defined by:\n\n```\nclass MyModel(LockableModel):\n\n class Meta(object):\n version_field = 'version'\n\n version = IntegerField(default=1)\n```\n\nIt only supports numeric locking field.\n\nAnd the actual implementation (my only additions are the two blocks with `# Comments`):\n\n```\nclass ConcurrentModification(PeeweeException):\n \"\"\"Indicates that entity has been changed in the database between loading and saving.\"\"\"\n\nclass LockableModel(peewee.Model):\n\n # The base was copied from peewee 2.7.4\n def save(self, force_insert=False, only=None, optimistic=True):\n field_dict = dict(self._data)\n if self._meta.primary_key is not False:\n pk_field = self._meta.primary_key\n pk_value = self._get_pk_value()\n else:\n pk_field = pk_value = None\n if only:\n field_dict = self._prune_fields(field_dict, only)\n elif getattr(self._meta, 'only_save_dirty', False) and not force_insert:\n field_dict = self._prune_fields(\n field_dict,\n self.dirty_fields)\n # Empty dict is ok with optimistic locking (to simply increment version)\n # XXX: Is this really needed? There is no use case for this!\n if not field_dict and (\n not getattr(self._meta, 'version_field', None) or (\n getattr(self._meta, 'version_field', None) and not optimistic\n )\n ):\n self._dirty.clear()\n return False\n\n self._populate_unsaved_relations(field_dict)\n if pk_value is not None and not force_insert:\n if self._meta.composite_key:\n for pk_part_name in pk_field.field_names:\n field_dict.pop(pk_part_name, None)\n else:\n field_dict.pop(pk_field.name, None)\n\n # Locking\n if optimistic and getattr(self._meta, 'version_field', None):\n # Add and increment version field, if it was not manually given. This is the normal behavior\n if self._meta.version_field in field_dict:\n raise ValueError('You must not modify version field manually while using locking!')\n field_dict[self._meta.version_field] = self._data[self._meta.version_field] + 1\n rows = self.update(**field_dict).where(\n self._pk_expr() &\n (\n self._meta.fields[self._meta.version_field] ==\n getattr(self, self._meta.version_field)\n )\n ).execute()\n if rows == 0:\n entity = self.select().where(self._pk_expr()).get() # throws DoesNotExist if not found, but it should...\n raise ConcurrentModification(\n 'Tried to save entity with version of `{}` but database contains entry with version of `{}`!'\n .format(field_dict[self._meta.version_field], getattr(entity, self._meta.version_field))\n )\n # Also set correct version on this instance, if update succeeded\n setattr(self, self._meta.version_field, field_dict[self._meta.version_field])\n\n else:\n rows = self.update(**field_dict).where(self._pk_expr()).execute()\n elif pk_field is None:\n self.insert(**field_dict).execute()\n rows = 1\n else:\n pk_from_cursor = self.insert(**field_dict).execute()\n if pk_from_cursor is not None:\n pk_value = pk_from_cursor\n self._set_pk_value(pk_value)\n rows = 1\n self._dirty.clear()\n return rows\n```\n\nSo, calling `save()` does the usual optimistic locking stuff, and calling `save(optimistic=False)` disables the feature.\n",
"Cool, I'll play with this myself!\n\nIt seems like something @coleifer could possibly support by breaking out some of the `save()` functionality out into several other functions that custom subclasses, like your optimistic-locking model, could override?\n"
] | 2015-07-15T07:42:37 | 2016-03-07T20:43:10 | 2015-07-16T01:16:48 | NONE | null | I'm not sure what is the correct way to implement support [optimistic locking](http://martinfowler.com/eaaCatalog/optimisticOfflineLock.html). As usual, I want to hold a version column that I increment on updates, while also ensuring that I am updating the row with the current version.
I assume I could implement this with something like:
``` python
Layer.update(name=self.name, label=self.label, version=self.version + 1).where((id=self.id) & (version=self.version))
```
But here, I need to explicitly list all the fields/values in `update(...)`. Is there some shortcut?
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/658/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/658/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/657 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/657/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/657/comments | https://api.github.com/repos/coleifer/peewee/issues/657/events | https://github.com/coleifer/peewee/issues/657 | 94,853,829 | MDU6SXNzdWU5NDg1MzgyOQ== | 657 | Is there a way to connect to a database not in the same folder? | {
"login": "jacobbieker",
"id": 7170359,
"node_id": "MDQ6VXNlcjcxNzAzNTk=",
"avatar_url": "https://avatars.githubusercontent.com/u/7170359?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/jacobbieker",
"html_url": "https://github.com/jacobbieker",
"followers_url": "https://api.github.com/users/jacobbieker/followers",
"following_url": "https://api.github.com/users/jacobbieker/following{/other_user}",
"gists_url": "https://api.github.com/users/jacobbieker/gists{/gist_id}",
"starred_url": "https://api.github.com/users/jacobbieker/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/jacobbieker/subscriptions",
"organizations_url": "https://api.github.com/users/jacobbieker/orgs",
"repos_url": "https://api.github.com/users/jacobbieker/repos",
"events_url": "https://api.github.com/users/jacobbieker/events{/privacy}",
"received_events_url": "https://api.github.com/users/jacobbieker/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Are all of your models explicitly referencing your db?\n\n``` python\ndb = SqliteDatabase('mydb')\nclass SomeModel(Model):\n data = CharField()\n class Meta:\n database = db # do you have this?\n```\n",
"Yes, they are. I followed the examples and have a BaseModel that references the database, and that all the other models extend. For when I am trying to connect form a different folder, I use the absolute path to the database for the <code>db = SqliteDatabase('absolute-path-to-database')</code> \n\nIf it helps, the script that I am using to create and connect to the database is located here: \nhttps://github.com/jacobbieker/Insights/blob/dev/databaseSetup.py\n\nI import that file into the other scripts to access the database, unless there is a better way to do it?\n",
"Can you share your code?\n",
"Yes, here is where I connect to a database that is run whenever databaseSetup is imported, the whole file is here: https://github.com/jacobbieker/Insights/blob/dev/databaseSetup.py:\n\n```\nif __name__ != \"__main__\":\n with open(os.path.join(\"..\", \"constants.yaml\"), 'r') as ymlfile:\n config = yaml.load(ymlfile)\nelse:\n with open(\"constants.yaml\", 'r') as ymlfile:\n config = yaml.load(ymlfile)\nclass BaseModel(peewee.Model):\n class Meta:\n database = SqliteDatabase(config.get('databaseLoc')).connect()\n\n class Locations(BaseModel):\n date = DateTimeField(null=True)\n time = TimeField(null=True)\n longitude = DoubleField(null=True)\n latitude = DoubleField(null=True)\n continent = CharField(null=True)\n country = CharField(null=True)\n state = CharField(null=True)\n zip = IntegerField(null=True)\n city = CharField(null=True)\n street = TextField(null=True)\n name = TextField(null=True)\n```\n\nWhere 'databaseLoc' is the absolute path to the desired database\n\nAnd here is the relevant code in a script that imports \n\nLocations2SQLite.py, located here: https://github.com/jacobbieker/Insights/blob/dev/GoogleTakeoutScripts/Location2SQLite.py\n\n```\nfrom databaseSetup import Locations\n\n Locations.insert(date=converted_time_stamp,time=time_stamp, longitude=longitude, latitude=latitude,\n continent=continent, country=country, state=state, zip=zipcode, city=city, street=street,\n name=building).execute()\n```\n\nWhen Locations2SQLite.py exits, it creates a peewee.db in its directory, and does not connect to the database created in databaseSetup.py \n",
"The problem is you're calling `database.connect()` in the `Meta` inner class -- not sure why you're doing that there, since the return value of `connect` would not be a database instance.\n\nChange it to the following and you should be fixed:\n\n``` python\nclass BaseModel(peewee.Model):\n class Meta:\n database = SqliteDatabase(config.get('databaseLoc'))\n```\n",
"That worked! Thanks for the help.\n"
] | 2015-07-14T02:28:33 | 2015-07-14T17:43:13 | 2015-07-14T08:51:56 | NONE | null | I am tyring to connect to a local SQLite database to store output from multiple scripts in one place. The problem is that when I try to connect to the database from a different folder, it just creates a peewee.db in the current directory. Does Database URLs allow for me to connect to a local database correctly? From the docs, it sounded like the connect() call cimply created a new datanase for those URLs. Any help would be appreciated, I quite possibly just didn't see it in the docs. Thanks!
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/657/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/657/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/656 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/656/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/656/comments | https://api.github.com/repos/coleifer/peewee/issues/656/events | https://github.com/coleifer/peewee/issues/656 | 94,690,386 | MDU6SXNzdWU5NDY5MDM4Ng== | 656 | Possible support for connection retry? | {
"login": "josephschorr",
"id": 4073002,
"node_id": "MDQ6VXNlcjQwNzMwMDI=",
"avatar_url": "https://avatars.githubusercontent.com/u/4073002?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/josephschorr",
"html_url": "https://github.com/josephschorr",
"followers_url": "https://api.github.com/users/josephschorr/followers",
"following_url": "https://api.github.com/users/josephschorr/following{/other_user}",
"gists_url": "https://api.github.com/users/josephschorr/gists{/gist_id}",
"starred_url": "https://api.github.com/users/josephschorr/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/josephschorr/subscriptions",
"organizations_url": "https://api.github.com/users/josephschorr/orgs",
"repos_url": "https://api.github.com/users/josephschorr/repos",
"events_url": "https://api.github.com/users/josephschorr/events{/privacy}",
"received_events_url": "https://api.github.com/users/josephschorr/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Rather than adding this to Peewee itself, I'd suggest you write your own wrapper that does what you want:\n\n``` python\nfrom peewee import *\nimport time\n\ndb = PostgresqlDatabase('whatever')\n\ndef connect_db(retries=3, delay=5):\n while True:\n retries -= 1\n try:\n db.connect()\n except OperationalError:\n if retries == 0:\n raise\n time.sleep(delay)\n else:\n return True\n```\n",
"Since we're using a `Proxy`, how would we override the `connect` call (or would we have to just make sure to call our own connect first everytime)?\n",
"Using the function from above, I imagine you would just write:\n\n``` python\ndef connect_db(db, retries=3, delay=5):\n while True:\n retries -= 1\n try:\n db.connect()\n except OperationalError:\n if retries == 0:\n raise\n time.sleep(delay)\n else:\n return True\n\nclass ReconnectingProxy(Proxy):\n def connect(self):\n return connect_db(self.obj)\n\ndatabase = ReconnectingProxy()\ndatabase.initialize(some_other_db)\n```\n"
] | 2015-07-13T10:26:20 | 2015-07-13T23:47:51 | 2015-07-13T23:47:29 | NONE | null | We occasionally have servers failing to connect to the database due to sporadic networking issues with our service provider. Our service provider is currently investigating these issues, but until solved this leaves us having a few DB connections here and there fail.
I'm curious on thoughts about adding the ability to retry connecting to the database a specified number of times (probably 3 and with some form of backoff?), after which the exception would be bubbled up out of the call as it currently does. This would be user-configurable, perhaps on the `initialize` call of the `Proxy`.
Admittedly, not a great solution, but it would help in the short term and for software working in areas with less than stable networks.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/656/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/656/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/655 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/655/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/655/comments | https://api.github.com/repos/coleifer/peewee/issues/655/events | https://github.com/coleifer/peewee/issues/655 | 94,323,828 | MDU6SXNzdWU5NDMyMzgyOA== | 655 | If custom primary_key is used, .save() with no PK doesn't work properly | {
"login": "foxx",
"id": 651797,
"node_id": "MDQ6VXNlcjY1MTc5Nw==",
"avatar_url": "https://avatars.githubusercontent.com/u/651797?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/foxx",
"html_url": "https://github.com/foxx",
"followers_url": "https://api.github.com/users/foxx/followers",
"following_url": "https://api.github.com/users/foxx/following{/other_user}",
"gists_url": "https://api.github.com/users/foxx/gists{/gist_id}",
"starred_url": "https://api.github.com/users/foxx/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/foxx/subscriptions",
"organizations_url": "https://api.github.com/users/foxx/orgs",
"repos_url": "https://api.github.com/users/foxx/repos",
"events_url": "https://api.github.com/users/foxx/events{/privacy}",
"received_events_url": "https://api.github.com/users/foxx/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"You need to save with `force_insert=True`.\n\nhttp://docs.peewee-orm.com/en/latest/peewee/models.html#id3\n",
"I can't believe I missed that in the docs, my bad :( Thanks for the reply!\n",
"Fwiw, do you think it's worth patching so that an exception is raised if this situation is ever encountered? Although it's documented, it would be nice to have an exception raised in the event of human error maybe.\n",
"This definitely needs exception or some kind of logging, failing silently is not cool.",
"It *does* work, Peewee just assumes if the PK is present that it should do an update instead. Peewee is an active-record ORM. This is fundamental stuff."
] | 2015-07-10T15:00:15 | 2020-01-20T16:46:55 | 2015-07-10T22:57:46 | CONTRIBUTOR | null | The following code does not raise any exceptions, but it doesn't save to the database either.
``` py
import peewee
import random
db = peewee.SqliteDatabase(':memory:')
class Message(peewee.Model):
class Meta:
database = db
content = peewee.TextField()
class MessageCustomPrimaryKey(peewee.Model):
class Meta:
database = db
id = peewee.TextField(default=1, primary_key=True, unique=True)
content = peewee.TextField()
db.create_table(Message)
db.create_table(MessageCustomPrimaryKey)
# this works as expected
m = Message()
m.content = 'hello'
m.save()
assert m.id == 1
assert Message.select().count() == 1
# this does not
m = MessageCustomPrimaryKey()
m.content = 'hello'
m.save()
assert m.id == 1
assert MessageCustomPrimaryKey.select().count() == 1
```
Although creating objects in this pattern isn't very clean, it was a surprising result, because if the record was not saved to the backend then I would expect some sort of exception to be raised.
If I remove the custom `id` primary_key field, the problem goes away. I've trawled through the code and documentation, but cannot find anything to explain why this is happening.
Thoughts?
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/655/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/655/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/654 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/654/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/654/comments | https://api.github.com/repos/coleifer/peewee/issues/654/events | https://github.com/coleifer/peewee/issues/654 | 94,169,272 | MDU6SXNzdWU5NDE2OTI3Mg== | 654 | Model with no primary key | {
"login": "ballan91",
"id": 1587844,
"node_id": "MDQ6VXNlcjE1ODc4NDQ=",
"avatar_url": "https://avatars.githubusercontent.com/u/1587844?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/ballan91",
"html_url": "https://github.com/ballan91",
"followers_url": "https://api.github.com/users/ballan91/followers",
"following_url": "https://api.github.com/users/ballan91/following{/other_user}",
"gists_url": "https://api.github.com/users/ballan91/gists{/gist_id}",
"starred_url": "https://api.github.com/users/ballan91/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/ballan91/subscriptions",
"organizations_url": "https://api.github.com/users/ballan91/orgs",
"repos_url": "https://api.github.com/users/ballan91/repos",
"events_url": "https://api.github.com/users/ballan91/events{/privacy}",
"received_events_url": "https://api.github.com/users/ballan91/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Bug confirmed, curiously I just came across this issue myself and was about to report it, weird coincidence? Or perhaps a recent change?\n\nAlso, specifying `primary_key = None` doesn't actually disable the PK, as seen here;\n\n``` py\nclass Audit(Model):\n class Meta:\n primary_key = False\n data = TextField()\n\n>>> a = Audit(data=\"lol\")\n>>> a.save()\n>>> a.id\n1\n```\n",
"Setting `primary_key = None` will cause peewee to auto-generate an `id` primary key field, so the docs are correct regarding `False`.\n\nUnfortunately some APIs just don't work when you don't have any primary key at all, `save()` being one of them. You need to use the `.insert()` and `.update()` APIs instead.\n",
"Added some docs to that effect. \n",
"Ah yeah, makes sense now, thanks for the quick reply!\n"
] | 2015-07-09T22:45:25 | 2015-07-10T00:17:37 | 2015-07-10T00:12:25 | NONE | null | It looks like while this is supported the documentation might be incorrect, I believe what the documentation actual intends is:
``` python
class MyData(BaseModel):
timestamp = DateTimeField()
value = IntegerField()
class Meta:
primary_key = None
```
While:
``` python
primary_key = False
```
Seems to cause issues when trying to issue a .save() command.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/654/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/654/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/653 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/653/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/653/comments | https://api.github.com/repos/coleifer/peewee/issues/653/events | https://github.com/coleifer/peewee/issues/653 | 94,168,279 | MDU6SXNzdWU5NDE2ODI3OQ== | 653 | updating peewee on windows | {
"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 | [
"please close this issue found the solution in here\n\nhttps://msdn.microsoft.com/en-us/library/x4d2c09s.aspx\n\nI am using 64 bit python so I did\n\nvcvarsall amd64 then pip install --upgrade pewee using VS 12.0 worked\n",
"Thanks @hgabe !\n"
] | 2015-07-09T22:39:21 | 2015-07-10T00:00:48 | 2015-07-09T23:57:16 | NONE | null | running build_ext
building 'playhouse.speedups' extension
Traceback (most recent call last):
File "setup.py", line 38, in <module>
scripts = ['pwiz.py'],
File "C:\Python34\lib\distutils\core.py", line 148, in setup
dist.run_commands()
File "C:\Python34\lib\distutils\dist.py", line 955, in run_commands
self.run_command(cmd)
File "C:\Python34\lib\distutils\dist.py", line 974, in run_command
cmd_obj.run()
File "C:\Python34\lib\site-packages\setuptools\command\install.py", line 67,
n run
self.do_egg_install()
File "C:\Python34\lib\site-packages\setuptools\command\install.py", line 109,
in do_egg_install
self.run_command('bdist_egg')
File "C:\Python34\lib\distutils\cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "C:\Python34\lib\distutils\dist.py", line 974, in run_command
cmd_obj.run()
File "C:\Python34\lib\site-packages\setuptools\command\bdist_egg.py", line 16
, in run
cmd = self.call_command('install_lib', warn_dir=0)
File "C:\Python34\lib\site-packages\setuptools\command\bdist_egg.py", line 14
, in call_command
self.run_command(cmdname)
File "C:\Python34\lib\distutils\cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "C:\Python34\lib\distutils\dist.py", line 974, in run_command
cmd_obj.run()
File "C:\Python34\lib\site-packages\setuptools\command\install_lib.py", line
0, in run
self.build()
File "C:\Python34\lib\distutils\command\install_lib.py", line 107, in build
self.run_command('build_ext')
File "C:\Python34\lib\distutils\cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "C:\Python34\lib\distutils\dist.py", line 974, in run_command
cmd_obj.run()
File "C:\Python34\lib\site-packages\setuptools\command\build_ext.py", line 50
in run
_build_ext.run(self)
File "C:\Python34\lib\distutils\command\build_ext.py", line 339, in run
self.build_extensions()
File "C:\Python34\lib\distutils\command\build_ext.py", line 448, in build_ext
nsions
self.build_extension(ext)
File "C:\Python34\lib\site-packages\setuptools\command\build_ext.py", line 18
, in build_extension
_build_ext.build_extension(self, ext)
File "C:\Python34\lib\distutils\command\build_ext.py", line 503, in build_ext
nsion
depends=ext.depends)
File "C:\Python34\lib\distutils\msvc9compiler.py", line 460, in compile
self.initialize()
File "C:\Python34\lib\distutils\msvc9compiler.py", line 371, in initialize
vc_env = query_vcvarsall(VERSION, plat_spec)
File "C:\Python34\lib\site-packages\setuptools\msvc9_support.py", line 52, in
query_vcvarsall
return unpatched['query_vcvarsall'](version, *args, **kwargs)
File "C:\Python34\lib\distutils\msvc9compiler.py", line 287, in query_vcvarsa
l
raise ValueError(str(list(result.keys())))
ValueError: ['path']
I have VS2010, 2012 and VS2013 community install
I tried to upgrade it with both git and pip using python 3.4.3
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/653/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/653/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/652 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/652/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/652/comments | https://api.github.com/repos/coleifer/peewee/issues/652/events | https://github.com/coleifer/peewee/issues/652 | 93,947,420 | MDU6SXNzdWU5Mzk0NzQyMA== | 652 | Weird double exception while testing | {
"login": "brendanWeb",
"id": 11618748,
"node_id": "MDQ6VXNlcjExNjE4NzQ4",
"avatar_url": "https://avatars.githubusercontent.com/u/11618748?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/brendanWeb",
"html_url": "https://github.com/brendanWeb",
"followers_url": "https://api.github.com/users/brendanWeb/followers",
"following_url": "https://api.github.com/users/brendanWeb/following{/other_user}",
"gists_url": "https://api.github.com/users/brendanWeb/gists{/gist_id}",
"starred_url": "https://api.github.com/users/brendanWeb/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/brendanWeb/subscriptions",
"organizations_url": "https://api.github.com/users/brendanWeb/orgs",
"repos_url": "https://api.github.com/users/brendanWeb/repos",
"events_url": "https://api.github.com/users/brendanWeb/events{/privacy}",
"received_events_url": "https://api.github.com/users/brendanWeb/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"The problem is your call to `assertRaises`. It should be written:\n\n``` python\nself.assertRaises(IntegrityError, Post.create, description=\"hello world\")\n```\n\nOr\n\n``` python\nself.assertRaises(IntegrityError, lambda: Post.create(description=\"hello world\"))\n```\n",
"Thanks!\n"
] | 2015-07-09T03:57:17 | 2015-07-09T04:36:47 | 2015-07-09T04:26:21 | NONE | null | I am getting both a sqlite3.IntegrityError as well as the peewee.IntegrityError that I am asserting for in my tests. Is this normal? It's causing my tests to error out.
Gist of the issue:
https://gist.github.com/brendanWeb/584d62ba5e7fb9c7338f
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/652/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/652/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/651 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/651/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/651/comments | https://api.github.com/repos/coleifer/peewee/issues/651/events | https://github.com/coleifer/peewee/issues/651 | 93,756,070 | MDU6SXNzdWU5Mzc1NjA3MA== | 651 | Model select() and save() behavior | {
"login": "stas",
"id": 112147,
"node_id": "MDQ6VXNlcjExMjE0Nw==",
"avatar_url": "https://avatars.githubusercontent.com/u/112147?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/stas",
"html_url": "https://github.com/stas",
"followers_url": "https://api.github.com/users/stas/followers",
"following_url": "https://api.github.com/users/stas/following{/other_user}",
"gists_url": "https://api.github.com/users/stas/gists{/gist_id}",
"starred_url": "https://api.github.com/users/stas/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/stas/subscriptions",
"organizations_url": "https://api.github.com/users/stas/orgs",
"repos_url": "https://api.github.com/users/stas/repos",
"events_url": "https://api.github.com/users/stas/events{/privacy}",
"received_events_url": "https://api.github.com/users/stas/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Adding @alexanderad to this discussion too.\n",
"I've prepared a script with steps to reproduce here: https://gist.github.com/alexanderad/c4cb1befe576fc987b67\n",
"This is not really an issue per-se. If you are explicitly selecting columns, then it's on you to explicitly select the primary key as well if you intend to be calling `save()`.\n",
"Oh, and to your second point, that is how peewee works and will not change for historical reasons. It is also how Django works. If you want to only save the \"dirty fields\" you can call `user.save(only=user.dirty_fields)`.\n",
"With all respect, I find your response oblivious.\n\nBasically what you say is that it is user's concern to make sure the exposed API is not duplicating the data in the database. And that you are not going to address this in any way, although this is exactly what and ORM should do.\n\nIn regards to Django, it provides users with automatic fields when calling `save()` on specific columns, as pointed out in their docs:\nhttps://docs.djangoproject.com/en/1.8/ref/models/instances/#specifying-which-fields-to-save\n\nI'm sorry you took this hostile position about the raised concerns, but I feel even worse for myself and for other users that will have to continue dealing with this kind of attitude.\n",
"What would you propose as a fix? I think that when a user explicitly selects particular columns, it is bad to magically insert the primary key in addition. I can see this causing a lot of confusion.\n\nWhen calling `save()` with a partially-populated model instance, I agree that it's troublesome to just blindly try saving all fields, but changing that now could probably break a lot of people's code. Since there's an API for saving specific fields (just like Django), I don't see the problem. Django's `save()` takes a list named `update_fields` while peewee takes a list named `only`.\n\nPeewee even gives you a helper property `self.dirty_fields` which tells you which fields were modified, so you can call `.save(only=model.dirty_fields)`.\n",
"There are a couple of options:\n1. raise an exception on `.save()` if a partial model was loaded by a `.select()` call and `only` is not provided, this should be the easiest fix. I don't think a lot of code will break, since this means those users were happy with peewee overwriting their models with empty/default values or, like in our case, duplicating records. We can also do some more research on this.\n2. do not allow partial calls except on `.dicts()` or `.tuples()`, anyway this is now broken (read explanation below) and might be worth a separate discussion.\n3. follow Django's model, and provide a consistent API when working with partial models. By searching existing closed issues, lots of people expected peewee will correctly work with just _dirty_ fields upon `.save()`. This doesn't necessarily require providing the primary key, it can leverage some private API. This is also probably the safest option in terms of backwards compatibility.\n\nAs I tried to explain, in the description, this behavior is not an expected one, if you believe things should work this way, at least `.save()` should inform the user that he is going to create a new record out of the partial model it works with. Silently duplicating rows in the database is the least thing somebody expects to happen.\n\nWhy 2. is broken: suppose you explicitly query some columns of two models through a join, you will end up with a partial model and not the other model fields you were selecting. You will have to use either `.dicts()` or `.tuples()` to achieve the desired behavior. For example, we patched our codebase to provide an `.objects()` call that will return read-only objects build out of selected column values.\n",
"I hear your concerns, but as I said, this is and has always been the way peewee works (or does not work, in your case). Partial selects work the same as full selects and are not a special case. Calling save() will try to save all fields, and if no PK is present an INSERT will be issued.\n\nThere is an API for saving only the dirty fields and it would be easy to add a wrapper:\n\n``` python\ndef save_changes(self):\n return self.save(only=self.dirty_fields)\n```\n\nI know you disagree here, but in my experience maintaining this project the existing behavior seems to work well for most people.\n",
"> I hear your concerns\n\nApparently you don't, and it seems that I'm wasting my time trying to convince you to change a bad API that you accept as broken, but refuse to improve it.\n\nAs I said in the initial description, feel free to ping me if you changed your mind and can use some help improving this.\n",
"I'm sorry you feel you're wasting your time, I certainly don't feel that way. These are good questions and concerns you've raised. I am just of a different opinion than you on what to do about it.\n\nRegarding the select+save question: I definitely think automagically selecting the primary key is bad. If you did _not_ select the PK and try to call `save()`, then I think the best Peewee could do is raise an Exception. I am loth to do that, and would prefer to just document clearly what the actual behavior is.\n\nRegarding the question about saving empty fields, I've [answered this before](https://github.com/coleifer/peewee/issues/643#issuecomment-118117290), so it's not like I haven't thought about it. I just feel like simplicity is best. To me that means that there are minimal special cases and minimal magics. Calling `save()` will save everything. Calling `save(only=inst.dirty_fields)` can easily be used if you want it.\n",
"@stas I'm simply following peewee closely now that I am using it in production (no other bindings). In my opinion, you went quite harsh here. coleifer's response time to tickets and his attitude to resolving them has been simply outstanding. He tries to keep peewee small and simple, which is understandable considering the scope of the project and him being really the only guy maintaining it.\n\nImo, the whole debate here is about the amount of magic we expect from an ORM. If you consider peewee's goal (to be simple and easy to understand), less magic is better. I personally would not expect PK to be returned when I explicitly told peewee to only fetch a single field. If I needed also PK, it's not that bad writing it into select().\n\nThe suggested changes would change behavior in a backwards-incompatible manner. Wouldn't that break people's implementations? That is the key problem here - not that he was against improving the library. Maybe coleifer could consider this for 3.x, but it doesn't really feel that big of an issue (if an issue at all, as peewee already provides API to do what you are after here). For 3.x or such, it is simply a matter of taste.\n",
"@tuukkamustonen certainly my experience is different. I've had previous experience where @coleifer would refuse any help and later work on his own to provide the same functionality without any arguments. I would suggest we stop right here trying to prove somebody is being personal against @coleifer. All I care is the future and the quality of this project simply because people depend on it.\n\n> Imo, the whole debate here is about the amount of magic we expect from an ORM.\n\nMagic has nothing to do with the fact that the exposed API is not consistent.\n\n> The suggested changes would change behavior in a backwards-incompatible manner. Wouldn't that break people's implementations? That is the key problem here - not that he was against improving the library. Maybe coleifer could consider this for 3.x, but it doesn't really feel that big of an issue (if an issue at all, as peewee already provides API to do what you are after here). For 3.x or such, it is simply a matter of taste.\n\nYou're just being nice. The author simply refused all the suggestions and you are trying to speak on his behalf. In the end, this issue is still closed.\n",
"I am certainly not speaking on his behalf. Now that would be weird...\n"
] | 2015-07-08T10:23:16 | 2015-07-09T13:20:31 | 2015-07-08T16:04:44 | NONE | null | The model `select()` behavior acts strange on the results where specific columns were requested and afterwards the `save()` is called. This is concerning since it leads to the insertion of duplicated rows.
Here's an example:
``` bash
In [5]: from app.models import UserModel
In [6]: UserModel.select().count()
Out[6]: 1L
In [7]: u1 = UserModel.select(UserModel.settings).first()
In [8]: u1.settings
Out[8]: {}
In [9]: u1.settings['editor'] = 'vim'
In [10]: u1.save()
Out[10]: 1
In [11]: UserModel.select().count()
Out[11]: 2L
```
There are two issues I see here, the first one is the fact that a partial `select()` returns results with no primary key attached to it (or at least a flag that this result belongs to a row in the database).
The second issue is related to the fact that `save()` on a model with partial results will still generate a full update/insert including all the columns, where it should be isolated to updating just the selected columns.
Please advise here, I will be happy to help with this if you agree with the concerns from above.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/651/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/651/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/650 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/650/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/650/comments | https://api.github.com/repos/coleifer/peewee/issues/650/events | https://github.com/coleifer/peewee/pull/650 | 93,574,219 | MDExOlB1bGxSZXF1ZXN0MzkzOTAzMzQ= | 650 | Work in progress | {
"login": "IxDay",
"id": 2128384,
"node_id": "MDQ6VXNlcjIxMjgzODQ=",
"avatar_url": "https://avatars.githubusercontent.com/u/2128384?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/IxDay",
"html_url": "https://github.com/IxDay",
"followers_url": "https://api.github.com/users/IxDay/followers",
"following_url": "https://api.github.com/users/IxDay/following{/other_user}",
"gists_url": "https://api.github.com/users/IxDay/gists{/gist_id}",
"starred_url": "https://api.github.com/users/IxDay/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/IxDay/subscriptions",
"organizations_url": "https://api.github.com/users/IxDay/orgs",
"repos_url": "https://api.github.com/users/IxDay/repos",
"events_url": "https://api.github.com/users/IxDay/events{/privacy}",
"received_events_url": "https://api.github.com/users/IxDay/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Just before continuing do you think that I should continue implementing a custom Model class or you have a better idea on how to implement this?\n\nI will also look at the implementation of the InsertQuery and avoid code duplication.\n",
"I'll take a look soon. One thing, you can probably just modify the existing `UpdateQuery` rather than putting this in `postgres_ext`. That's how I handled `INSERT...RETURNING` in the existing code.\n",
"I might try my hand at an implementation -- by doing so I'd like to explore some other ways of implementing this.\n",
"This is what I've come up with: https://github.com/coleifer/peewee/compare/HEAD...feature/update-returning\n",
"I noticed that you put all this code in the `postgresql_ext` module. My preference, since I imagine _some_ DBs besides postgres have this feature, is to use database feature flags to allow/disallow access to the `returning` APIs.\n\nMy thoughts on the implementation can be found here: https://github.com/coleifer/peewee/compare/HEAD...feature/update-returning\n",
"You know, looking around it seems like `DELETE` and `INSERT` both support `returning` as well. I think I'll update my patch to allow `returning` on delete and insert.\n",
"I've added support for `RETURNING` with `UPDATE`, `INSERT` and `DELETE` in my branch `feature/update-returning`:\n\nhttps://github.com/coleifer/peewee/compare/HEAD...feature/update-returning\n\nI think I'm going to go ahead and merge it today.\n",
"Just saw your patch (was on holidays), seems really cool, thanks for the quick implementation :)\n",
"Cool, thanks for sharing your code, really helpful!\n"
] | 2015-07-07T16:36:01 | 2015-07-16T08:22:51 | 2015-07-13T19:51:06 | NONE | null | Here is a first implementation just showing part of the code.
I have to fix the ability to iter through results
I also have an issue with the model class, If you have a better idea than creating a dedicated model class...
It breaks the tests but this is a work in progress ;)
linked to #647
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/650/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/650/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/650",
"html_url": "https://github.com/coleifer/peewee/pull/650",
"diff_url": "https://github.com/coleifer/peewee/pull/650.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/650.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/649 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/649/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/649/comments | https://api.github.com/repos/coleifer/peewee/issues/649/events | https://github.com/coleifer/peewee/pull/649 | 93,573,270 | MDExOlB1bGxSZXF1ZXN0MzkzODk4NDM= | 649 | Work in progress | {
"login": "IxDay",
"id": 2128384,
"node_id": "MDQ6VXNlcjIxMjgzODQ=",
"avatar_url": "https://avatars.githubusercontent.com/u/2128384?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/IxDay",
"html_url": "https://github.com/IxDay",
"followers_url": "https://api.github.com/users/IxDay/followers",
"following_url": "https://api.github.com/users/IxDay/following{/other_user}",
"gists_url": "https://api.github.com/users/IxDay/gists{/gist_id}",
"starred_url": "https://api.github.com/users/IxDay/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/IxDay/subscriptions",
"organizations_url": "https://api.github.com/users/IxDay/orgs",
"repos_url": "https://api.github.com/users/IxDay/repos",
"events_url": "https://api.github.com/users/IxDay/events{/privacy}",
"received_events_url": "https://api.github.com/users/IxDay/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Wrong repository\n"
] | 2015-07-07T16:30:57 | 2015-07-07T16:35:07 | 2015-07-07T16:34:52 | NONE | null | Here is a first implementation just showing part of the code.
I have to fix the ability to **iter** through results
I also have an issue with the model class, If you have a better idea than creating a dedicated model class...
It breaks the tests but this is a work in progress ;)
linked to #647
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/649/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/649/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/649",
"html_url": "https://github.com/coleifer/peewee/pull/649",
"diff_url": "https://github.com/coleifer/peewee/pull/649.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/649.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/648 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/648/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/648/comments | https://api.github.com/repos/coleifer/peewee/issues/648/events | https://github.com/coleifer/peewee/pull/648 | 93,559,382 | MDExOlB1bGxSZXF1ZXN0MzkzODM2NjM= | 648 | fixed encooding error on login and sign up | {
"login": "snitz70",
"id": 5569765,
"node_id": "MDQ6VXNlcjU1Njk3NjU=",
"avatar_url": "https://avatars.githubusercontent.com/u/5569765?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/snitz70",
"html_url": "https://github.com/snitz70",
"followers_url": "https://api.github.com/users/snitz70/followers",
"following_url": "https://api.github.com/users/snitz70/following{/other_user}",
"gists_url": "https://api.github.com/users/snitz70/gists{/gist_id}",
"starred_url": "https://api.github.com/users/snitz70/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/snitz70/subscriptions",
"organizations_url": "https://api.github.com/users/snitz70/orgs",
"repos_url": "https://api.github.com/users/snitz70/repos",
"events_url": "https://api.github.com/users/snitz70/events{/privacy}",
"received_events_url": "https://api.github.com/users/snitz70/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Thanks!\n"
] | 2015-07-07T15:34:34 | 2015-07-07T15:37:48 | 2015-07-07T15:37:45 | CONTRIBUTOR | null | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/648/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/648/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/648",
"html_url": "https://github.com/coleifer/peewee/pull/648",
"diff_url": "https://github.com/coleifer/peewee/pull/648.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/648.patch",
"merged_at": "2015-07-07T15:37:45"
} |
|
https://api.github.com/repos/coleifer/peewee/issues/647 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/647/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/647/comments | https://api.github.com/repos/coleifer/peewee/issues/647/events | https://github.com/coleifer/peewee/issues/647 | 93,480,107 | MDU6SXNzdWU5MzQ4MDEwNw== | 647 | Introducing returning for postgres | {
"login": "IxDay",
"id": 2128384,
"node_id": "MDQ6VXNlcjIxMjgzODQ=",
"avatar_url": "https://avatars.githubusercontent.com/u/2128384?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/IxDay",
"html_url": "https://github.com/IxDay",
"followers_url": "https://api.github.com/users/IxDay/followers",
"following_url": "https://api.github.com/users/IxDay/following{/other_user}",
"gists_url": "https://api.github.com/users/IxDay/gists{/gist_id}",
"starred_url": "https://api.github.com/users/IxDay/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/IxDay/subscriptions",
"organizations_url": "https://api.github.com/users/IxDay/orgs",
"repos_url": "https://api.github.com/users/IxDay/repos",
"events_url": "https://api.github.com/users/IxDay/events{/privacy}",
"received_events_url": "https://api.github.com/users/IxDay/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Interesting, how is this implemented at the SQL level?\n",
"http://www.postgresql.org/docs/9.1/static/sql-update.html\n\n`If the UPDATE command contains a RETURNING clause, the result will be similar to that of a SELECT statement containing the columns and values defined in the RETURNING list, computed over the row(s) updated by the command` (the last statement is false, every row can be accessed I tested it) .\n\nThe sql statement will look like this\n\n``` sql\nUPDATE users SET active = FALSE WHERE registration_expired = TRUE RETURNING username; \n```\n",
"Gotcha, cool! Can you share your code?\n",
"I will make a first pull request in order to see if the implementation looks good for you, with a simple test case.\n",
"I've gone ahead and merged support for `RETURNING` clauses on `UPDATE`, `INSERT` and `DELETE` queries. These only work with Postgresql, and are protected using a database config attribute, `returning_clause`. I will be adding documentation as well today, then I think it's good to go!\n"
] | 2015-07-07T09:09:33 | 2015-07-13T19:52:06 | 2015-07-13T19:52:06 | NONE | null | Hello, I am currently using peewee for managing a postgresql and I have started implementing a returning function on the update and select queries.
I am interested in contributing the results.
Here is an example:
``` python
user = User.update(active=False).where(User.registration_expired == True).returning()
```
The returning method will be a SelectQuery and support the selection arguments
``` python
sq = (User.update(active=False)
.where(User.registration_expired == True)
.returning(User.username))
for user in sq:
print user.username
```
And also support the `tuples` and `dicts` chaining:
``` python
sq = (User.update(active=False)
.where(User.registration_expired == True)
.returning(User.username)
.dicts())
for user in sq:
print user.get('username')
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/647/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/647/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/646 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/646/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/646/comments | https://api.github.com/repos/coleifer/peewee/issues/646/events | https://github.com/coleifer/peewee/issues/646 | 93,405,484 | MDU6SXNzdWU5MzQwNTQ4NA== | 646 | 2.6.2 install error | {
"login": "pitchforks",
"id": 4378791,
"node_id": "MDQ6VXNlcjQzNzg3OTE=",
"avatar_url": "https://avatars.githubusercontent.com/u/4378791?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/pitchforks",
"html_url": "https://github.com/pitchforks",
"followers_url": "https://api.github.com/users/pitchforks/followers",
"following_url": "https://api.github.com/users/pitchforks/following{/other_user}",
"gists_url": "https://api.github.com/users/pitchforks/gists{/gist_id}",
"starred_url": "https://api.github.com/users/pitchforks/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/pitchforks/subscriptions",
"organizations_url": "https://api.github.com/users/pitchforks/orgs",
"repos_url": "https://api.github.com/users/pitchforks/repos",
"events_url": "https://api.github.com/users/pitchforks/events{/privacy}",
"received_events_url": "https://api.github.com/users/pitchforks/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I just added that, maybe I needed to add it to `MANIFEST.in`... I pushed a new release, 2.6.3. Will you let me know if that fixes it?\n",
"2.6.3 builds fine, thank you.\n\nThe build also succeeded when I temporary uninstalled Cython. Since you did not modify the install instructions in the documentation, I assume that Cython did not become a mandatory build dependency for this new peewee version?\n",
"Cython is an optional dependency, but I had forgotten to include the cython module in the package data I believe. I can add info to the docs though, that's a good idea. Thanks for reporitng this!\n"
] | 2015-07-07T00:11:41 | 2015-07-07T14:03:00 | 2015-07-07T14:03:00 | NONE | null | I do setup.py install because I am packaging the source code tarball into a personal package for the Linux distribution that I'm using (it's Slackware64-14.1 with Python 2.7.5) and I'm getting this traceback for peewee-2.6.2:
```
Traceback (most recent call last):
File "setup.py", line 14, in <module>
ext_modules = cythonize('playhouse/speedups.pyx')
File "/usr/lib64/python2.7/site-packages/Cython/Build/Dependencies.py", line 754, in cythonize
aliases=aliases)
File "/usr/lib64/python2.7/site-packages/Cython/Build/Dependencies.py", line 649, in create_extension_list
for file in nonempty(extended_iglob(filepattern), "'%s' doesn't match any files" % filepattern):
File "/usr/lib64/python2.7/site-packages/Cython/Build/Dependencies.py", line 103, in nonempty
raise ValueError(error_msg)
ValueError: 'playhouse/speedups.pyx' doesn't match any files
```
It did not happen before, for 2.6.1 and earlier versions.
I have Cython-0.22 installed, but I'm pretty sure I installed that as dependency for something else, not for peewee.
I have also skimmed through the README and had a look at http://docs.peewee-orm.com/en/latest/peewee/installation.html, but could not find any useful hints.
What additional steps should I take for peewee-2.6.2 so setup.py build/install succeeds?
Thanks.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/646/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/646/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/645 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/645/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/645/comments | https://api.github.com/repos/coleifer/peewee/issues/645/events | https://github.com/coleifer/peewee/pull/645 | 93,049,282 | MDExOlB1bGxSZXF1ZXN0MzkyMTMwMzk= | 645 | Make filter work when there are multiple joins to the same table | {
"login": "rammie",
"id": 554792,
"node_id": "MDQ6VXNlcjU1NDc5Mg==",
"avatar_url": "https://avatars.githubusercontent.com/u/554792?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/rammie",
"html_url": "https://github.com/rammie",
"followers_url": "https://api.github.com/users/rammie/followers",
"following_url": "https://api.github.com/users/rammie/following{/other_user}",
"gists_url": "https://api.github.com/users/rammie/gists{/gist_id}",
"starred_url": "https://api.github.com/users/rammie/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/rammie/subscriptions",
"organizations_url": "https://api.github.com/users/rammie/orgs",
"repos_url": "https://api.github.com/users/rammie/repos",
"events_url": "https://api.github.com/users/rammie/events{/privacy}",
"received_events_url": "https://api.github.com/users/rammie/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"This is some pretty dense code... Can you summarize the changes? I'm not sure I'm going to merge it in yet, but some test-cases would also be helpful for my understanding of these changes.\n",
"Actually...man, this code is very difficult to parse in my head. Might be the 3 hours of sleep I'm running on, but since `filter()` is deprecated anyways I'm not too excited about adding this much complexity and then having to maintain it.\n",
"Let me take a stab at cleaning it up, and I'll add some tests as well. As I mentioned before, I like the way that the flask-peewee REST API processes the query string to generate a query, which relies on `filter()`. Maybe this could be moved to the playhouse instead?\n",
"On second thought, I decided to move this to the REST base classes itself API. Seems more logical if you're deprecating `filter()` anyway.\n"
] | 2015-07-04T21:14:31 | 2015-07-05T15:14:26 | 2015-07-05T15:14:25 | NONE | null | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/645/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/645/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/645",
"html_url": "https://github.com/coleifer/peewee/pull/645",
"diff_url": "https://github.com/coleifer/peewee/pull/645.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/645.patch",
"merged_at": null
} |
|
https://api.github.com/repos/coleifer/peewee/issues/644 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/644/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/644/comments | https://api.github.com/repos/coleifer/peewee/issues/644/events | https://github.com/coleifer/peewee/issues/644 | 92,919,025 | MDU6SXNzdWU5MjkxOTAyNQ== | 644 | Query filtering does not work as expected with multiple foreign keys to the same table. | {
"login": "rammie",
"id": 554792,
"node_id": "MDQ6VXNlcjU1NDc5Mg==",
"avatar_url": "https://avatars.githubusercontent.com/u/554792?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/rammie",
"html_url": "https://github.com/rammie",
"followers_url": "https://api.github.com/users/rammie/followers",
"following_url": "https://api.github.com/users/rammie/following{/other_user}",
"gists_url": "https://api.github.com/users/rammie/gists{/gist_id}",
"starred_url": "https://api.github.com/users/rammie/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/rammie/subscriptions",
"organizations_url": "https://api.github.com/users/rammie/orgs",
"repos_url": "https://api.github.com/users/rammie/repos",
"events_url": "https://api.github.com/users/rammie/events{/privacy}",
"received_events_url": "https://api.github.com/users/rammie/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"This is a limitation of the `filter()` API. To get the correct semantics (and avoid extra queries when looking up associated usernames), you would need to write:\n\n``` python\nUA = User.alias()\nq = (Tweet\n .select(Tweet, User, UA)\n .join(User, on=(Tweet.user1 == User.id))\n .switch(Tweet)\n .join(UA, on=(Tweet.user2 == UA.id).alias('user2'))\n .where(\n (User.username == 'foo') &\n (UA.username == 'bar')))\ntweet = q.get()\nprint tweet.user1.username\nprint tweet.user2.username\n```\n\nUnfortunately, `filter()` does not do well with multiple joins to the same table.\n",
"Hi again, and sorry to keep bothering with this. I investigated a little further and it seemed possible to make this work using aliases. I put together a pull request for this and was hoping you could take a look. I also hope that you think that the approach is reasonable.\n"
] | 2015-07-03T18:20:47 | 2015-07-04T21:12:40 | 2015-07-04T03:32:42 | NONE | null | Thanks as always for this amazing package.
Here is a small example to recreate this issue. I'm really hoping that you don't decide to deprecate the the filter API as I frequently use the REST API's from the retired flask-peewee module that relies on it.
I think the issue is that ensure_join does not care about the on clause of the join which causes the second join to be skipped.
``` python
from peewee import *
database = SqliteDatabase(':memory:')
class Model(Model):
class Meta:
database = database
class User(Model):
username = CharField(unique=True)
class Tweet(Model):
user1 = ForeignKeyField(User, related_name='tweets1')
user2 = ForeignKeyField(User, related_name='tweets2')
message = CharField()
User.create_table()
Tweet.create_table()
u1 = User.create(username="foo")
u2 = User.create(username="bar")
t1 = Tweet.create(user1=u1, user2=u2, message="boo")
# Following line prints "foo" as expected
print Tweet.filter(user1__username="foo", message="boo").get().user1.username
# Following line should print "foo" as well,
# but instead it raises an DoesNotExist exception.
print Tweet.filter(user1__username="foo", user2__username="bar").get().user1.username
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/644/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/644/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/643 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/643/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/643/comments | https://api.github.com/repos/coleifer/peewee/issues/643/events | https://github.com/coleifer/peewee/issues/643 | 92,566,356 | MDU6SXNzdWU5MjU2NjM1Ng== | 643 | Curious on why model.save(only=model.dirty_fields) isn't default behavior | {
"login": "ibushong",
"id": 9298422,
"node_id": "MDQ6VXNlcjkyOTg0MjI=",
"avatar_url": "https://avatars.githubusercontent.com/u/9298422?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/ibushong",
"html_url": "https://github.com/ibushong",
"followers_url": "https://api.github.com/users/ibushong/followers",
"following_url": "https://api.github.com/users/ibushong/following{/other_user}",
"gists_url": "https://api.github.com/users/ibushong/gists{/gist_id}",
"starred_url": "https://api.github.com/users/ibushong/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/ibushong/subscriptions",
"organizations_url": "https://api.github.com/users/ibushong/orgs",
"repos_url": "https://api.github.com/users/ibushong/repos",
"events_url": "https://api.github.com/users/ibushong/events{/privacy}",
"received_events_url": "https://api.github.com/users/ibushong/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Peewee is active record, the behavior is Django-like, so save() will save everything by default. Changing that now would probably break existing implementations anyways.\n\nYou can always subclass `Model` and add your own `save()` implementation that does what you want.\n\nBut to answer your question, mostly it is this way because that is how Django's ORM behaves and I originally based peewee off of that. I can't change it now because I'd worry about breaking people's code.\n",
"Yeah I wasn't suggesting it be changed, just curious on why. Thanks for the explanation! That clears it up.\n",
"I am bitten by this a couple of times as well. I use peewee in production.\n\n@coleifer Peewee's API for most cases very obvious and simple and perhaps that's why it's loved by so many (including me). But I feel that \"because django orm does thing certain way\" isn't a very good explanation. Peewee is peewee and it should do what's best and more obvious for users.\n\nHaving said that this may break existing code probably a valid argument (still not 100% convinced that it will break). But I wonder is it possible to have some setting like \n\n``` python\npeewee.on_save_always_use_dirty_fields = T/F # default being False\n```\n\nI think most of us would not expect below code to wipe out data in non selected columns\n\n``` python\nclass Profile(Model):\n \"\"\"\n has lot of fields because of various reasons\n \"\"\"\n\na_profile = Profile.select(Profile.id, Profile.registered).where(..).first()\na_profile.registered = True\n# You have a cleaner profile now :)\n```\n",
"@shon, the reason is looks like your Profile object has been \"cleared\" is because you're only selecting the `id` and `registered` fields. Remove the arguments to `select()` and you should see the behavior I think you're expecting. In general, you shouldn't really need to select specific fields. It's just gonna make your code harder to maintain.\n",
"Just pushed 376a467, which adds a new Meta option: `only_save_dirty` (default is `False`). You can now mark you profile:\n\n``` python\nclass Profile(Model):\n fields = WhateverFields()\n\n class Meta:\n only_save_dirty = True\n```\n\nWhen you call `Model.create()` all fields will stll be saved, it is only when you call `.save()` by itself. You can explicitly save non-dirty fields by specifying them using `.save(only=[whatever])`.\n",
"Thanks for the suggestion, @shon, I like options.\n",
"Awesome. Thank you so much @coleifer \n"
] | 2015-07-02T07:05:58 | 2015-10-16T04:24:18 | 2015-07-02T18:30:08 | NONE | null | This definitely isn't an issue, I was just curious on this design decision.
Why isn't the default behavior to only update modified fields? (i.e. the behavior we get when using `model.save(only=model.dirty_fields)`
When viewing SQL logs, it's much easier to see what's being updated. If I update a single field, then the `UPDATE` query reflects that. But if all fields are persisted then it's more difficult to see what changed. Though as a counterpoint. it's easer to see what the exact value of a row is after any given `UPDATE` query if we explicitly re-set all fields.
Also, for extremely large rows, you'd be transferring less data if only updating modified fields.
Obviously it's easy to implement this behavior, but just wondering why it's not the default case.
Thanks! peewee is excellent
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/643/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/643/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/642 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/642/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/642/comments | https://api.github.com/repos/coleifer/peewee/issues/642/events | https://github.com/coleifer/peewee/issues/642 | 92,319,140 | MDU6SXNzdWU5MjMxOTE0MA== | 642 | Using bitwise and / or in a query | {
"login": "josefdlange",
"id": 1062835,
"node_id": "MDQ6VXNlcjEwNjI4MzU=",
"avatar_url": "https://avatars.githubusercontent.com/u/1062835?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/josefdlange",
"html_url": "https://github.com/josefdlange",
"followers_url": "https://api.github.com/users/josefdlange/followers",
"following_url": "https://api.github.com/users/josefdlange/following{/other_user}",
"gists_url": "https://api.github.com/users/josefdlange/gists{/gist_id}",
"starred_url": "https://api.github.com/users/josefdlange/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/josefdlange/subscriptions",
"organizations_url": "https://api.github.com/users/josefdlange/orgs",
"repos_url": "https://api.github.com/users/josefdlange/repos",
"events_url": "https://api.github.com/users/josefdlange/events{/privacy}",
"received_events_url": "https://api.github.com/users/josefdlange/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Yes, you can use `.bin_and`, `.bin_or`, `^` (xor).\n",
"If they are not mapped to the correct operator for your database please let me know.\n",
"It looks like I may need a bitwise `NOT`, though, now that I look at it.\n",
"Awesome, thanks. My usage is like this, am I doing it right? I'm trying to select any `Thing` for which its `field` (an `IntegerField`, representing a bit mask) when ANDed with `other_integer` (also a bit mask), is a match (or better, which is why I'm not doing just integer equality comparison).\n\nSo if the binary of `Thing.field` is 11111111 and `other_integer`'s binary is 10101011, that `Thing` would be selected.\n\nSo, in essence, am I correct in the use of the `bin_and` method in the where clause?\n\n```\nthings = (\n Thing\n .select()\n .where(Thing.field.bin_and(other_integer) == other_integer)\n)\n```\n",
"Yeah, I think that should be right.\n"
] | 2015-07-01T08:50:28 | 2015-07-01T18:20:35 | 2015-07-01T18:20:35 | CONTRIBUTOR | null | Is it possible to use bitwise operations (&, |, #, ~) in a query and have them translate to the (flavor)SQL keywords to _actually_ do the bitwise operation?
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/642/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/642/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/641 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/641/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/641/comments | https://api.github.com/repos/coleifer/peewee/issues/641/events | https://github.com/coleifer/peewee/issues/641 | 92,024,708 | MDU6SXNzdWU5MjAyNDcwOA== | 641 | pwiz AttributeError: 'tuple' object has no attribute 'args' | {
"login": "shaotianchi",
"id": 2035693,
"node_id": "MDQ6VXNlcjIwMzU2OTM=",
"avatar_url": "https://avatars.githubusercontent.com/u/2035693?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/shaotianchi",
"html_url": "https://github.com/shaotianchi",
"followers_url": "https://api.github.com/users/shaotianchi/followers",
"following_url": "https://api.github.com/users/shaotianchi/following{/other_user}",
"gists_url": "https://api.github.com/users/shaotianchi/gists{/gist_id}",
"starred_url": "https://api.github.com/users/shaotianchi/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/shaotianchi/subscriptions",
"organizations_url": "https://api.github.com/users/shaotianchi/orgs",
"repos_url": "https://api.github.com/users/shaotianchi/repos",
"events_url": "https://api.github.com/users/shaotianchi/events{/privacy}",
"received_events_url": "https://api.github.com/users/shaotianchi/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Can you paste the entire traceback?\n"
] | 2015-06-30T08:31:53 | 2015-07-02T22:25:10 | 2015-07-02T22:25:10 | NONE | null | I'm using python 2.6
when I use pwiz to generator my model, this error come
```
python -m pwiz -e mysql -H myhost -p 3306 -u user -P psw app_trends_food > mymodels.py
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/641/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/641/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/640 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/640/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/640/comments | https://api.github.com/repos/coleifer/peewee/issues/640/events | https://github.com/coleifer/peewee/issues/640 | 91,011,453 | MDU6SXNzdWU5MTAxMTQ1Mw== | 640 | unsigned integer and auto_incresing | {
"login": "AlexHeKa",
"id": 9191522,
"node_id": "MDQ6VXNlcjkxOTE1MjI=",
"avatar_url": "https://avatars.githubusercontent.com/u/9191522?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/AlexHeKa",
"html_url": "https://github.com/AlexHeKa",
"followers_url": "https://api.github.com/users/AlexHeKa/followers",
"following_url": "https://api.github.com/users/AlexHeKa/following{/other_user}",
"gists_url": "https://api.github.com/users/AlexHeKa/gists{/gist_id}",
"starred_url": "https://api.github.com/users/AlexHeKa/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/AlexHeKa/subscriptions",
"organizations_url": "https://api.github.com/users/AlexHeKa/orgs",
"repos_url": "https://api.github.com/users/AlexHeKa/repos",
"events_url": "https://api.github.com/users/AlexHeKa/events{/privacy}",
"received_events_url": "https://api.github.com/users/AlexHeKa/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I'm not sure I understand the question completely but yes, you can write custom fields. Check the docs:\n\nhttp://docs.peewee-orm.com/en/latest/peewee/models.html#creating-a-custom-field\n"
] | 2015-06-25T16:31:10 | 2015-06-25T22:47:47 | 2015-06-25T22:47:47 | NONE | null | It seems custom field only support Postgresql now,is't possible to custom an unsigned or auto_incresing field in mysql db? Thanks
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/640/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/640/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/639 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/639/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/639/comments | https://api.github.com/repos/coleifer/peewee/issues/639/events | https://github.com/coleifer/peewee/issues/639 | 91,005,652 | MDU6SXNzdWU5MTAwNTY1Mg== | 639 | Proposal to extend IntegrityError | {
"login": "foxx",
"id": 651797,
"node_id": "MDQ6VXNlcjY1MTc5Nw==",
"avatar_url": "https://avatars.githubusercontent.com/u/651797?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/foxx",
"html_url": "https://github.com/foxx",
"followers_url": "https://api.github.com/users/foxx/followers",
"following_url": "https://api.github.com/users/foxx/following{/other_user}",
"gists_url": "https://api.github.com/users/foxx/gists{/gist_id}",
"starred_url": "https://api.github.com/users/foxx/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/foxx/subscriptions",
"organizations_url": "https://api.github.com/users/foxx/orgs",
"repos_url": "https://api.github.com/users/foxx/repos",
"events_url": "https://api.github.com/users/foxx/events{/privacy}",
"received_events_url": "https://api.github.com/users/foxx/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Eeee, yeah, this seems like a can of worms I'd rather not open. I'm going to stick with the ones specified by the DB-API 2.0 spec.\n\nhttps://www.python.org/dev/peps/pep-0249/#exceptions\n",
"Agreed, makes sense to stick by DB-API 2.0. For all other engines/versions, we can just inspect `exc.args[0]` to get the error code, but for Sqlite3 on Python 3.4 we'll just have to wait heh.\n"
] | 2015-06-25T16:06:02 | 2015-06-25T23:06:24 | 2015-06-25T22:46:40 | CONTRIBUTOR | null | As a follow up to #443, I'm proposing that IntegrityError should expose some information about the error its representing. For example, if the error was related to a unique constraint failure, perhaps we could have a subclass representing this (`UniqueConstraintError`?).
It seems this is detectable inside `exc.args`, e.g;
```
('UNIQUE constraint failed: useremail.user_id, useremail.email_address',)
```
It seems that most databases will return an error code, rather than having to do a string comparison.
```
SQLITE_CONSTRAINT_UNIQUE (2067)
MySQL: ERROR 1062 (23000): Duplicate entry '2147483647' for key 'PRIMARY'
```
I think that unique constraint failure is a good candidate for this, at the very least to reliably implement `create_or_get()` type functionality.
On a side note - it seems that there is a [bug](http://bugs.python.org/issue16379) with Python 3.4 that prevents Sqlite error codes from reaching Python
Thoughts?
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/639/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/639/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/638 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/638/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/638/comments | https://api.github.com/repos/coleifer/peewee/issues/638/events | https://github.com/coleifer/peewee/issues/638 | 90,994,540 | MDU6SXNzdWU5MDk5NDU0MA== | 638 | Proposal for Model.refetch() | {
"login": "foxx",
"id": 651797,
"node_id": "MDQ6VXNlcjY1MTc5Nw==",
"avatar_url": "https://avatars.githubusercontent.com/u/651797?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/foxx",
"html_url": "https://github.com/foxx",
"followers_url": "https://api.github.com/users/foxx/followers",
"following_url": "https://api.github.com/users/foxx/following{/other_user}",
"gists_url": "https://api.github.com/users/foxx/gists{/gist_id}",
"starred_url": "https://api.github.com/users/foxx/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/foxx/subscriptions",
"organizations_url": "https://api.github.com/users/foxx/orgs",
"repos_url": "https://api.github.com/users/foxx/repos",
"events_url": "https://api.github.com/users/foxx/events{/privacy}",
"received_events_url": "https://api.github.com/users/foxx/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I think I will leave this as an application-type API. Re-fetching seems to me to be complex (do you just go bby primary key, or as you have, by values)?\n",
"So far I've only tried this by using the primary or compound key, which has worked well so far, but will fall over when used with a model that doesn't have this. I also need to raise an exception if there is no primary key fields, and add some unit tests. At the very least, this recipe is here for Google. \n\nJust so I can be sure, do you see any glaring flaws in the approved I've used above, or does it look sane enough to leave here for future? (ty for the feedback btw, appreciated)\n",
"The way I have always done it is just `model_inst = ModelClass.get(model_inst._pk_expr())` (undocumented API).\n",
"Yours is better though because it handles composite keys, so no, no flaws!\n"
] | 2015-06-25T15:23:40 | 2015-06-26T01:38:41 | 2015-06-25T22:45:28 | CONTRIBUTOR | null | One common pattern is to "refetch" a model instance, returning a new instance of the model with updated database values. It's also possible to use `refresh()`, but this could result in surprising behaviour when overwriting class attributes etc. This pattern is applicable to any model with a primary or compound key.
I've been able to get this working by using;
``` py
class BaseModel(Model):
def refetch(self):
fields = self._meta.get_primary_key_fields()
filters = [ field == self._data[field.name] for field in fields]
results = list(self.__class__.select().where(*filters).execute())
if len(results) == 0:
raise IntegrityError("No such row")
elif len(results) > 1:
raise IntegrityError("Too many rows")
return results[0]
```
``` py
>>> u = User.get(id=1234)
>>> u = u.refetch()
>>> print u.id
1234
```
If I presented this as a clean PR with tests and documentation, would it be accepted?
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/638/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/638/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/637 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/637/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/637/comments | https://api.github.com/repos/coleifer/peewee/issues/637/events | https://github.com/coleifer/peewee/pull/637 | 90,776,072 | MDExOlB1bGxSZXF1ZXN0Mzg0ODU0NjE= | 637 | Added small bit in documentation about ForeignKeyField's related_name | {
"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 | [
"Sick, I'll take the gitignore too!\n"
] | 2015-06-24T20:44:40 | 2015-06-25T22:40:32 | 2015-06-25T22:40:32 | CONTRIBUTOR | null | I had a lengthy argument with a co-worker about the implicit `related_name` backreference created by peewee when declaring a `ForeignKeyField`. He was convinced it didn't exist, since it wasn't in the documentation. Only after walking him through the source code and demonstrating it did he believe me. So, for the future, I added a small section in the `ForeignKeyField` docs explaining.
I do not know how to build/test `peewee`'s documentation but would be glad to if I had some direction. Also accepting changes to what I wrote, if it doesn't match up with the original intent or design.
Also added a `.gitignore` to ignore `.pyc` files and the `build` directory. We can trim that out of here if you feel it doesn't belong, though.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/637/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/637/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/637",
"html_url": "https://github.com/coleifer/peewee/pull/637",
"diff_url": "https://github.com/coleifer/peewee/pull/637.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/637.patch",
"merged_at": "2015-06-25T22:40:32"
} |
https://api.github.com/repos/coleifer/peewee/issues/636 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/636/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/636/comments | https://api.github.com/repos/coleifer/peewee/issues/636/events | https://github.com/coleifer/peewee/issues/636 | 90,563,675 | MDU6SXNzdWU5MDU2MzY3NQ== | 636 | get next value for pk | {
"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 | [
"Not coleifer, but I would have to say probably not. To prevent race conditions, the only reliable way to know the next id is to have it assigned to you by the DBMS, and each DBMS handles passing that information back in a different way after an ID is assigned.\n\nhttps://github.com/coleifer/peewee/blob/master/peewee.py#L3389\nhttps://github.com/coleifer/peewee/blob/master/peewee.py#L3418\nhttps://github.com/coleifer/peewee/blob/master/peewee.py#L3132\n\nMaybe your app is going to be single threaded forever? If so, and you're also running on Postgres you could copy and modify the Postgres implementation of last_insert_id and switch curval for nextval.\n",
"Thanks @jakedt for the quick answer, probably I'll not change my code — it runs very rarely.\nI thought I can run postgres function `nextval` for sequence and get the next id guaranteed.\nIt's not a problem to save the object twice for me.\n\nI use nginx+uwsgi with four processes. Anyway — modify the Postgres implementation is too expensive :smiley: \n",
"I thought for some reason calling `nextval()` would increment the counter, at any rate @jakedt is correct that it's dicey to try and predict.\n"
] | 2015-06-24T04:45:21 | 2015-06-25T22:42:19 | 2015-06-25T22:42:19 | NONE | null | Is there an easy way to get the next value for the primary key (ID) of a sequence?
Needs to use id in one field of model.
I have to save the object twice now.
``` python
def save(self, *args, **kwargs):
rows = super().save(*args, **kwargs)
self.code = '.'.join((self.branch.code, self.type, str(self.id)))
return super().save(only=[Dep.code])
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/636/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/636/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/635 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/635/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/635/comments | https://api.github.com/repos/coleifer/peewee/issues/635/events | https://github.com/coleifer/peewee/issues/635 | 90,469,024 | MDU6SXNzdWU5MDQ2OTAyNA== | 635 | Regression: using a column alias breaks ModelQueryResultWrapper for nested joined objects | {
"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 | [
"Actually the behavior in master is now correct:\n\n``` python\nIn [2]: generate_data()\n\nIn [3]: found = (Tweet.select(Tweet.message, User.username.alias('uname'))\n ...: .join(User).where(Tweet.id == 1).get())\n\nIn [4]: found.user\nOut[4]: <__main__.User at 0x7f35f01a54d0>\n\nIn [5]: found.user.uname\nOut[5]: u'1'\n```\n\nSo by using an alias, Peewee will assume you want the alias to be attribute on the object. Instead of `user.username` it is `user.uname` because of the alias.\n\nPS thanks for the test code!\n"
] | 2015-06-23T19:18:25 | 2015-06-25T22:37:33 | 2015-06-25T22:37:33 | NONE | null | Repro:
``` python
import logging
import datetime
from peewee import *
logger = logging.getLogger(__name__)
database = SqliteDatabase(':memory:')
class User(Model):
username = CharField(unique=True)
class Meta:
database = database
class Tweet(Model):
user = ForeignKeyField(User, related_name='tweets')
message = TextField()
created_date = DateTimeField(default=datetime.datetime.now)
is_published = BooleanField(default=True)
class Meta:
database = database
def generate_data():
database.create_tables([User, Tweet])
for username in ['1', '2', '3']:
new_user = User.create(username=username)
for msg in ['hi', 'hello', 'test']:
Tweet.create(user=new_user, message=msg)
def test_query():
found = (Tweet.select(Tweet.message, User.username.alias('uname'))
.join(User).where(Tweet.id == 1).get())
logger.debug(found.user.username)
if __name__ == '__main__':
generate_data()
logging.basicConfig(level=logging.DEBUG)
test_query()
```
output 2.6.1
```
DEBUG:peewee:('SELECT "t1"."message", "t2"."username" AS uname FROM "tweet" AS t1 INNER JOIN "user" AS t2 ON ("t1"."user_id" = "t2"."id") WHERE ("t1"."id" = ?) LIMIT 1', [1])
DEBUG:__main__:1
```
output master
```
DEBUG:peewee:('SELECT "t1"."message", "t2"."username" AS uname FROM "tweet" AS t1 INNER JOIN "user" AS t2 ON ("t1"."user_id" = "t2"."id") WHERE ("t1"."id" = ?) LIMIT 1', [1])
DEBUG:__main__:None
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/635/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/635/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/634 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/634/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/634/comments | https://api.github.com/repos/coleifer/peewee/issues/634/events | https://github.com/coleifer/peewee/issues/634 | 90,422,540 | MDU6SXNzdWU5MDQyMjU0MA== | 634 | UNION query breaks table mapping for selected joined objects | {
"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 | [
"Possible solution? I can't think through the edge cases the way you can.\n\n``` python\ndiff --git i/peewee.py w/peewee.py\nindex c3e2a5f..192e177 100644\n--- i/peewee.py\n+++ w/peewee.py\n@@ -2756,11 +2756,16 @@ class SelectQuery(Query):\n if self._dirty or not self._qr:\n model_class = self.model_class\n query_meta = self.get_query_meta()\n+\n+ naive_meta = self\n+ if isinstance(self, CompoundSelect):\n+ naive_meta = self.lhs\n+\n if self._tuples:\n ResultWrapper = TuplesQueryResultWrapper\n elif self._dicts:\n ResultWrapper = DictQueryResultWrapper\n- elif self._naive or not self._joins or self.verify_naive():\n+ elif naive_meta._naive or not naive_meta._joins or naive_meta.verify_naive():\n ResultWrapper = NaiveQueryResultWrapper\n elif self._aggregate_rows:\n ResultWrapper = AggregateQueryResultWrapper\n```\n",
"Hey, thanks for submitting this. My wife and I just had a baby (yay!) but I'm quite busy with being a new Dad. I'd like to fix this, though, and will hopefully be able to get to it in a few weeks.\n",
"The fix works great! Thanks and congrats!\n"
] | 2015-06-23T15:41:06 | 2015-06-29T17:30:18 | 2015-06-28T01:07:49 | NONE | null | I am finding that even though the parameters come out in the same order, and the aliases are the same, union queries break the creating of children objects from multi-table selects.
repro:
``` python
import logging
import datetime
from peewee import *
logger = logging.getLogger(__name__)
database = SqliteDatabase(':memory:')
class User(Model):
username = CharField(unique=True)
class Meta:
database = database
class Tweet(Model):
user = ForeignKeyField(User, related_name='tweets')
message = TextField()
created_date = DateTimeField(default=datetime.datetime.now)
is_published = BooleanField(default=True)
class Meta:
database = database
def generate_data():
database.create_tables([User, Tweet])
for username in ['1', '2', '3']:
new_user = User.create(username=username)
for msg in ['hi', 'hello', 'test']:
Tweet.create(user=new_user, message=msg)
def test_subqueries():
logger.debug('Without union')
for t in Tweet.select(Tweet, User).join(User).where(Tweet.message == 'hi'):
logger.debug('Username: %s', t.user.username)
logger.debug('With union')
q1 = Tweet.select(Tweet, User).join(User).where(Tweet.message == 'hi')
q2 = Tweet.select(Tweet, User).join(User).where(Tweet.message == 'hello')
for t in q1 | q2:
logger.debug('Username: %s', t.user.username)
if __name__ == '__main__':
generate_data()
logging.basicConfig(level=logging.DEBUG)
test_subqueries()
```
output:
```
DEBUG:__main__:Without union
DEBUG:peewee:('SELECT "t1"."id", "t1"."user_id", "t1"."message", "t1"."created_date", "t1"."is_published", "t2"."id", "t2"."username" FROM "tweet" AS t1 INNER JOIN "user" AS t2 ON ("t1"."user_id" = "t2"."id") WHERE ("t1"."message" = ?)', [u'hi'])
DEBUG:__main__:Username: 1
DEBUG:__main__:Username: 2
DEBUG:__main__:Username: 3
DEBUG:__main__:With union
DEBUG:peewee:('SELECT "t1"."id", "t1"."user_id", "t1"."message", "t1"."created_date", "t1"."is_published", "t2"."id", "t2"."username" FROM "tweet" AS t1 INNER JOIN "user" AS t2 ON ("t1"."user_id" = "t2"."id") WHERE ("t1"."message" = ?) UNION SELECT "t3"."id", "t3"."user_id", "t3"."message", "t3"."created_date", "t3"."is_published", "t4"."id", "t4"."username" FROM "tweet" AS t3 INNER JOIN "user" AS t4 ON ("t3"."user_id" = "t4"."id") WHERE ("t3"."message" = ?)', [u'hi', u'hello'])
DEBUG:peewee:('SELECT "t1"."id", "t1"."username" FROM "user" AS t1 WHERE ("t1"."id" = ?) LIMIT 1', [1])
DEBUG:__main__:Username: 1
DEBUG:peewee:('SELECT "t1"."id", "t1"."username" FROM "user" AS t1 WHERE ("t1"."id" = ?) LIMIT 1', [1])
DEBUG:__main__:Username: 1
DEBUG:peewee:('SELECT "t1"."id", "t1"."username" FROM "user" AS t1 WHERE ("t1"."id" = ?) LIMIT 1', [2])
DEBUG:__main__:Username: 2
DEBUG:peewee:('SELECT "t1"."id", "t1"."username" FROM "user" AS t1 WHERE ("t1"."id" = ?) LIMIT 1', [2])
DEBUG:__main__:Username: 2
DEBUG:peewee:('SELECT "t1"."id", "t1"."username" FROM "user" AS t1 WHERE ("t1"."id" = ?) LIMIT 1', [3])
DEBUG:__main__:Username: 3
DEBUG:peewee:('SELECT "t1"."id", "t1"."username" FROM "user" AS t1 WHERE ("t1"."id" = ?) LIMIT 1', [3])
DEBUG:__main__:Username: 3
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/634/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/634/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/633 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/633/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/633/comments | https://api.github.com/repos/coleifer/peewee/issues/633/events | https://github.com/coleifer/peewee/issues/633 | 90,384,895 | MDU6SXNzdWU5MDM4NDg5NQ== | 633 | int field with max length set to 1 | {
"login": "emamirazavi",
"id": 3804866,
"node_id": "MDQ6VXNlcjM4MDQ4NjY=",
"avatar_url": "https://avatars.githubusercontent.com/u/3804866?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/emamirazavi",
"html_url": "https://github.com/emamirazavi",
"followers_url": "https://api.github.com/users/emamirazavi/followers",
"following_url": "https://api.github.com/users/emamirazavi/following{/other_user}",
"gists_url": "https://api.github.com/users/emamirazavi/gists{/gist_id}",
"starred_url": "https://api.github.com/users/emamirazavi/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/emamirazavi/subscriptions",
"organizations_url": "https://api.github.com/users/emamirazavi/orgs",
"repos_url": "https://api.github.com/users/emamirazavi/repos",
"events_url": "https://api.github.com/users/emamirazavi/events{/privacy}",
"received_events_url": "https://api.github.com/users/emamirazavi/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Unfortunately peewee doesn't support int with max length natively. You can write a custom field class though if you want to. Check the docs on adding a custom field.\n"
] | 2015-06-23T13:09:30 | 2015-06-25T22:33:22 | 2015-06-25T22:33:22 | NONE | null | As i knew i could not set max length of integer field to 1 for MySQL. We can not have this feature yet?!
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/633/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/633/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/632 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/632/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/632/comments | https://api.github.com/repos/coleifer/peewee/issues/632/events | https://github.com/coleifer/peewee/issues/632 | 90,192,417 | MDU6SXNzdWU5MDE5MjQxNw== | 632 | Playhouse proposal for optimised MySQL UUIDField | {
"login": "foxx",
"id": 651797,
"node_id": "MDQ6VXNlcjY1MTc5Nw==",
"avatar_url": "https://avatars.githubusercontent.com/u/651797?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/foxx",
"html_url": "https://github.com/foxx",
"followers_url": "https://api.github.com/users/foxx/followers",
"following_url": "https://api.github.com/users/foxx/following{/other_user}",
"gists_url": "https://api.github.com/users/foxx/gists{/gist_id}",
"starred_url": "https://api.github.com/users/foxx/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/foxx/subscriptions",
"organizations_url": "https://api.github.com/users/foxx/orgs",
"repos_url": "https://api.github.com/users/foxx/repos",
"events_url": "https://api.github.com/users/foxx/events{/privacy}",
"received_events_url": "https://api.github.com/users/foxx/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"This is quite neat! I will pass but hopefully Google will help anyone else find this who may be interested.\n"
] | 2015-06-22T19:44:13 | 2015-06-25T22:32:39 | 2015-06-25T22:32:39 | CONTRIBUTOR | null | I spent the day putting together the most optimised method of storing UUIDs in MySQL/MariaDB, and ended up implementing some research by Percona in which bits are shifted around to give better index performance.
I've since decided to switch over to ObjectIDs instead, but thought I'd share this code. If it doesn't get included in the playhouse then at least it's here for others in future.
The only remaining performance tweak might be storing it as a BINARY rather than BLOB, as this _may_ perform better under MySQL/Maria (tbc).
I'm not particularly happy about this approach, as it feels quite dirty and inelegant, but it does give the raw performance for those that need it. Also, this has only been tested on Python 3.
``` py
class UUIDField(BlobField):
"""
Optimized storage for UUID fields in MySQL, based on research by Percona
https://www.percona.com/blog/2014/12/19/store-uuid-optimized-way/
XXX: Should storage use BINARY instead of BLOB? Needs benchmark
"""
def db_value(self, value):
"""
Convert UUID to binary blob
>>> db_value('12345678-1234-5678-1234-567812345678')
>>> db_value(uuid.uuid4())
>>> db_value('lsjfhgjg')
Exception: ValueError
"""
# ensure we have a valid UUID
if not isinstance(value, UUID):
value = UUID(value)
# reconstruct for optimal indexing
parts = str(value).split("-")
reordered = ''.join([parts[2], parts[1], parts[0], parts[3], parts[4]])
value = binascii.unhexlify(reordered)
return super(UUIDField, self).db_value(value)
def python_value(self, value):
"""
Convert binary blob to UUID instance
"""
u = binascii.b2a_hex(value)
value = u[8:16] + u[4:8] + u[0:4] + u[16:22] + u[22:32]
return UUID(value)
class UUIDFieldTestCase(unittest.TestCase):
def test_random(self):
uuids = [ uuid4() for x in range(100) ]
for value in uuids:
a = UUIDField()
as_binary = a.db_value(value)
as_result = a.python_value(as_binary)
self.assertEquals(value, as_result)
self.assertEquals(str(value), str(as_result))
def test_single(self):
value = UUID('AAAAAAAA-BBBB-CCCC-DDDD-EEEEEEEEEEEE')
a = UUIDField()
as_binary = a.db_value(value)
as_result = a.python_value(as_binary)
self.assertEquals(value, as_result)
self.assertEquals(str(value), str(as_result))
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/632/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/632/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/631 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/631/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/631/comments | https://api.github.com/repos/coleifer/peewee/issues/631/events | https://github.com/coleifer/peewee/issues/631 | 90,119,409 | MDU6SXNzdWU5MDExOTQwOQ== | 631 | Proposal for FixedCharField? | {
"login": "foxx",
"id": 651797,
"node_id": "MDQ6VXNlcjY1MTc5Nw==",
"avatar_url": "https://avatars.githubusercontent.com/u/651797?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/foxx",
"html_url": "https://github.com/foxx",
"followers_url": "https://api.github.com/users/foxx/followers",
"following_url": "https://api.github.com/users/foxx/following{/other_user}",
"gists_url": "https://api.github.com/users/foxx/gists{/gist_id}",
"starred_url": "https://api.github.com/users/foxx/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/foxx/subscriptions",
"organizations_url": "https://api.github.com/users/foxx/orgs",
"repos_url": "https://api.github.com/users/foxx/repos",
"events_url": "https://api.github.com/users/foxx/events{/privacy}",
"received_events_url": "https://api.github.com/users/foxx/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I think I will leave this alone, but if you wanted to add it to `playhouse` you could create a new `fields` module I suppose? (and maybe move the `AESEncryptedField` and `CompressedField` from `shortcuts` I believe).\n",
"That's a neat idea, it would be a good place for other common fields too. I have some spare time coming up next week for contributions, I'll get this done then.\n",
"I've refactored the code, so there is now a `fields` module in `playhouse.fields`. This module contains the encrypted, compressed and many-to-many fields.\n",
"Damn you are too fast. LGTM, thank you!\n"
] | 2015-06-22T14:39:14 | 2015-07-06T11:35:36 | 2015-07-05T18:08:35 | CONTRIBUTOR | null | Although Postgres apparently does not experience any performance difference between `char/varchar` [[1]](http://www.postgresql.org/message-id/C11A06F4.4B7B8%[email protected]), other databases such as MySQL do have a noticeable impact [[2]](http://dba.stackexchange.com/questions/424/performance-implications-of-mysql-varchar-sizes). Also, `char` will use slightly less space than a `varchar`, which seems to be consistent across all databases.
Do you think Peewee would benefit from having `FixedCharField` in the Playhouse? Admittedly this probably isn't something that should go into the core. I'm also not entirely happy with the name `FixedCharField`.
Thoughts?
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/631/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/631/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/630 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/630/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/630/comments | https://api.github.com/repos/coleifer/peewee/issues/630/events | https://github.com/coleifer/peewee/issues/630 | 89,304,698 | MDU6SXNzdWU4OTMwNDY5OA== | 630 | Enum field support | {
"login": "foxx",
"id": 651797,
"node_id": "MDQ6VXNlcjY1MTc5Nw==",
"avatar_url": "https://avatars.githubusercontent.com/u/651797?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/foxx",
"html_url": "https://github.com/foxx",
"followers_url": "https://api.github.com/users/foxx/followers",
"following_url": "https://api.github.com/users/foxx/following{/other_user}",
"gists_url": "https://api.github.com/users/foxx/gists{/gist_id}",
"starred_url": "https://api.github.com/users/foxx/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/foxx/subscriptions",
"organizations_url": "https://api.github.com/users/foxx/orgs",
"repos_url": "https://api.github.com/users/foxx/repos",
"events_url": "https://api.github.com/users/foxx/events{/privacy}",
"received_events_url": "https://api.github.com/users/foxx/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I have not added enums because I personally have always used an `IntegerField` with a set of defined values. My blog, for instance, stores an entry's status as an integer such that 1=published, 2=draft, 9=deleted.\n\nPython does not natively support an enum data-type until 3.4, either, so there is another reason against it. For Python versions 2.x and less than 3.4, how would Peewee users represent enums in their application code?\n\nLastly, adding a custom field is pretty trivial and [there are docs describing how](http://docs.peewee-orm.com/en/latest/peewee/models.html#creating-a-custom-field).\n\n> All the supported Peewee databases have support for enum fields, and a quick look at the source indicates it would be trivial to add it in.\n\nSQLite does not natively support enums as far as I know. Yeah you can use a convention, or create a special table and use foreign keys, but I wouldn't go so far as to say SQLite supports enums.\n\n> Would you consider accepting a PR for this?\n\nHow would you go about implementing this? What would the Python side look like?\n",
"I'll just repeat:\n\n> Would you consider accepting a PR for this?\n\nHow would you go about implementing this? What would the Python side look like?\n",
"I have to admit, normally I opt for the same `IntegerField` approach. The only real advantage to enum seems to be string representation and value enforcement, however I'd argue that the majority of applications _should_ be doing validation in the app code rather than the database (with the exception being applications which enforce everything in the DB directly via stored procedures etc).\n\nGiven that even sqlite3 doesn't support enum, and the additional code complexity involved, I think it can be argued that there is little value in peewee supporting it either. I'll close this issue out for now, but at least there is some discussion and reasoning behind not adding it, for anyone who comes up against this in future.\n\nThank you again for your input, much appreciated\n",
"A bit late on this - but here is one option that will convert the values on their way into the db, and back on their way out.\r\n\r\n```\r\n# Define a mapping of database values : output \r\nFRUIT_CHOICES = [(1, \"apple\"),\r\n (2, \"orange\"),\r\n (3, \"banana\")]\r\n\r\n\r\nclass enum_like_field(IntegerField):\r\n def __init__(self, choices, *args, **kwargs):\r\n self.to_db = {v:k for k, v in choices}\r\n self.from_db = {k:v for k, v in choices}\r\n super(IntegerField, self).__init__(*args, **kwargs)\r\n\r\n def db_value(self, value):\r\n return self.to_db[value]\r\n\r\n def python_value(self, value):\r\n return self.from_db[value]\r\n\r\nclass my_table(Model):\r\n fruit = enum_like_field(null=False, choices=FRUIT_CHOICES)\r\n```",
"This code works good for Python 3.4+ enum for MySQL\r\n\r\n```\r\nclass enum_field(CharField):\r\n \"\"\"\r\n This class enable a Enum like field for Peewee\r\n \"\"\"\r\n def __init__(self, choices, *args, **kwargs):\r\n self.choices = choices\r\n super(CharField, self).__init__(*args, **kwargs)\r\n\r\n def db_value(self, value):\r\n return value.name\r\n\r\n def python_value(self, value):\r\n return self.choices(value)\r\n\r\nclass my_table(Model):\r\n class StatusChoices(Enum):\r\n WAITING = 1\r\n READY_TO_SEND = 2\r\n UPLOADING = 3\r\n OCR = 4\r\n DONE = 5\r\n\r\n status = enum_like_field(null=False, choices=StatusChoices)\r\n\r\n```\r\n\r\n",
"I think there is a mistake in the above snippet, this:\r\n\r\n```python\r\n def db_value(self, value):\r\n return value.name\r\n```\r\n\r\nShould be:\r\n\r\n```python\r\n def db_value(self, value):\r\n return value.value\r\n```",
"I also found some mistake. \r\nThe Problem is that the top base class `Field` has in `__init__` set default value for the `choices=None` so calling the super after setting the instance self to some value will because of this base class reset it to None. \r\n\r\nOne of the solution can be calling the super before setting the `choices` or using another member name. \r\n\r\n\r\n ",
"Hey sorry for the silly question but is this available in peewee 3.8.0? I can't find the class `EnumField` and there is no reference of it inside the Changelog nor the official documentation.",
"No, `EnumField` is currently something you'll need to implement.",
"the above code has some bugs and I created this and this works properly:\r\n\r\n```\r\nclass EnumField(IntegerField):\r\n\t\"\"\"\r\n\tThis class enable an Enum like field for Peewee\r\n\t\"\"\"\r\n\tdef __init__(self, choices, *args, **kwargs):\r\n\t\tsuper(IntegerField, self).__init__(*args, **kwargs)\r\n\t\tself.choices = choices\r\n\r\n\tdef db_value(self, value):\r\n\t\treturn value.value\r\n\r\n\tdef python_value(self, value):\r\n\t\treturn self.choices(value)\r\n```",
"@alistvt which kind of issues? What if my Enum is using strings instead of integers, like this?\r\n\r\n```python\r\nclass OverclockProfileType(Enum):\r\n DEFAULT = 'default'\r\n OFFSET = 'offset'\r\n```",
"Yet another version of the `EnumField`. This version stores the enum value as `CharField` but restores the correct Enum type when reading it:\r\n\r\n```python\r\nclass EnumField(CharField):\r\n \"\"\"\r\n This class enable an Enum like field for Peewee\r\n \"\"\"\r\n\r\n def __init__(self, choices: Callable, *args: Any, **kwargs: Any) -> None:\r\n super(CharField, self).__init__(*args, **kwargs)\r\n self.choices = choices\r\n self.max_length = 255\r\n\r\n def db_value(self, value: Any) -> Any:\r\n return value.value\r\n\r\n def python_value(self, value: Any) -> Any:\r\n return self.choices(type(list(self.choices)[0].value)(value))\r\n``` ",
"Here is my solution for peewee 3 Postgres https://gist.github.com/novaleksey/187e43660c4e2e56f7b972cf982751e1",
"@leinardi Thank you for your implementation. What do you think about even simpler version?\r\n```\r\nclass EnumField(peewee.CharField):\r\n \"\"\"\r\n This class enable an Enum like field for Peewee\r\n \"\"\"\r\n\r\n def __init__(self, enum: type[Enum], *args: Any, **kwargs: Any) -> None:\r\n super().__init__(*args, **kwargs)\r\n self.enum = enum\r\n\r\n def db_value(self, value: Any) -> Any:\r\n return value.value\r\n\r\n def python_value(self, value: Any) -> Any:\r\n return self.enum(value)\r\n```"
] | 2015-06-18T14:12:43 | 2022-02-18T14:20:36 | 2015-06-19T10:27:14 | CONTRIBUTOR | null | I've had a look around but can't seem to find any reference to Peewee supporting `enum` fields, other than a short mailing list [thread](https://groups.google.com/forum/#!topic/peewee-orm/jev6II7sN4Q) with no outcome, and a user contributed [recipe](https://gist.github.com/b1naryth1ef/607e92dc8c1748a06b5d) for Postgres which is untested. There are also [arguments](http://komlenic.com/244/8-reasons-why-mysqls-enum-data-type-is-evil/) for _not_ using enum.
All the supported Peewee databases have support for enum fields, and a quick look at the source indicates it would be trivial to add it in.
Is there any reason why enum fields have not been added yet? Would you consider accepting a PR for this?
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/630/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/630/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/629 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/629/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/629/comments | https://api.github.com/repos/coleifer/peewee/issues/629/events | https://github.com/coleifer/peewee/issues/629 | 89,191,236 | MDU6SXNzdWU4OTE5MTIzNg== | 629 | Support modification tracking by supply an event api? | {
"login": "galeo",
"id": 1025559,
"node_id": "MDQ6VXNlcjEwMjU1NTk=",
"avatar_url": "https://avatars.githubusercontent.com/u/1025559?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/galeo",
"html_url": "https://github.com/galeo",
"followers_url": "https://api.github.com/users/galeo/followers",
"following_url": "https://api.github.com/users/galeo/following{/other_user}",
"gists_url": "https://api.github.com/users/galeo/gists{/gist_id}",
"starred_url": "https://api.github.com/users/galeo/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/galeo/subscriptions",
"organizations_url": "https://api.github.com/users/galeo/orgs",
"repos_url": "https://api.github.com/users/galeo/repos",
"events_url": "https://api.github.com/users/galeo/events{/privacy}",
"received_events_url": "https://api.github.com/users/galeo/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"The limitations in Peewee are really the maximum possible. Anything more should be implemented in the database as triggers.\n",
"I'm trying to integrate Whoosh with Peewee just as the way [Flask-WhooshAlchemy](https://github.com/gyllstromk/Flask-WhooshAlchemy) uses [Flask-SQLAlchemy](https://github.com/mitsuhiko/flask-sqlalchemy/) to implement the so-called real-time indexing by tracking **CUD** actions. Maybe this is not a feasible idea.\n",
"Well, if you use the `post_save` and `post_delete` hooks, you should be fine. This will not catch bulk inserts, updates or deletes, however.\n",
"Without catching bulk operations may lead to confusion. Perhaps as you said above,\n\n> The limitations in Peewee are really the maximum possible. \n"
] | 2015-06-18T03:59:22 | 2015-06-28T02:54:09 | 2015-06-18T04:03:38 | NONE | null | Peewee has very limited signal support in `playhouse.signals` currently. Does it have any plan to supply a variety of hooks or an event api that could support modification tracking in the future?
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/629/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/629/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/628 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/628/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/628/comments | https://api.github.com/repos/coleifer/peewee/issues/628/events | https://github.com/coleifer/peewee/issues/628 | 88,672,103 | MDU6SXNzdWU4ODY3MjEwMw== | 628 | Adding Request Hooks with tornado | {
"login": "AlexHeKa",
"id": 9191522,
"node_id": "MDQ6VXNlcjkxOTE1MjI=",
"avatar_url": "https://avatars.githubusercontent.com/u/9191522?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/AlexHeKa",
"html_url": "https://github.com/AlexHeKa",
"followers_url": "https://api.github.com/users/AlexHeKa/followers",
"following_url": "https://api.github.com/users/AlexHeKa/following{/other_user}",
"gists_url": "https://api.github.com/users/AlexHeKa/gists{/gist_id}",
"starred_url": "https://api.github.com/users/AlexHeKa/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/AlexHeKa/subscriptions",
"organizations_url": "https://api.github.com/users/AlexHeKa/orgs",
"repos_url": "https://api.github.com/users/AlexHeKa/repos",
"events_url": "https://api.github.com/users/AlexHeKa/events{/privacy}",
"received_events_url": "https://api.github.com/users/AlexHeKa/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Fixed in c9785a21359b4c0b4bd3e76a326b9a7f240ddc86\n",
"http://docs.peewee-orm.com/en/latest/peewee/database.html#tornado\n"
] | 2015-06-16T09:23:30 | 2015-06-17T20:09:06 | 2015-06-17T20:08:45 | NONE | null | Thanks for help!
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/628/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/628/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/627 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/627/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/627/comments | https://api.github.com/repos/coleifer/peewee/issues/627/events | https://github.com/coleifer/peewee/pull/627 | 88,422,614 | MDExOlB1bGxSZXF1ZXN0Mzc2ODkxOTM= | 627 | Migrations: change column | {
"login": "klen",
"id": 90699,
"node_id": "MDQ6VXNlcjkwNjk5",
"avatar_url": "https://avatars.githubusercontent.com/u/90699?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/klen",
"html_url": "https://github.com/klen",
"followers_url": "https://api.github.com/users/klen/followers",
"following_url": "https://api.github.com/users/klen/following{/other_user}",
"gists_url": "https://api.github.com/users/klen/gists{/gist_id}",
"starred_url": "https://api.github.com/users/klen/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/klen/subscriptions",
"organizations_url": "https://api.github.com/users/klen/orgs",
"repos_url": "https://api.github.com/users/klen/repos",
"events_url": "https://api.github.com/users/klen/events{/privacy}",
"received_events_url": "https://api.github.com/users/klen/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I think I will pass on this, but thank you.\n",
"What wrong?\n",
"Well, I think `ALTER TABLE / ALTER COLUMN` is just complicated enough that I'm not sure this implementation will suffice. Additionally, the MySQL syntax is quite a bit different IIRC, and is not added as part of this PR.\n",
"That the reason why I didn't include the functionality in docs and chosen such word as `beta`. But the code (uncompleted of course) already helped me with postgres and sqlite.\n\nBut it up to you, coz. Thank you for the project!\n",
"Thanks for the PR and for taking the time to submit the code. If I should decide to add this functionality in the future I will definitely use this PR as the starting place.\n"
] | 2015-06-15T13:08:03 | 2015-06-15T15:25:23 | 2015-06-15T14:42:49 | CONTRIBUTOR | null | I've used the functionality in my project with Postgres and it works for me. So I thought it could be useful for other people. The request provides beta support for `change_column` functionality in migrator. I've tested this with Postgres and SQLite.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/627/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/627/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/627",
"html_url": "https://github.com/coleifer/peewee/pull/627",
"diff_url": "https://github.com/coleifer/peewee/pull/627.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/627.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/626 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/626/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/626/comments | https://api.github.com/repos/coleifer/peewee/issues/626/events | https://github.com/coleifer/peewee/issues/626 | 88,295,364 | MDU6SXNzdWU4ODI5NTM2NA== | 626 | [Support request] No primary key for a model | {
"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 | [
"For models with no primary key, simply specify `primary_key=False` in the inner `Meta` class:\n\n``` python\nclass Keyword(Model):\n name = CharField(null=False)\n created = DateTimeField(null=False, default=datetime.utcnow)\n\n class Meta:\n primary_key = False\n```\n\nIf you want a multi-column primary key you can write:\n\n``` python\nclass Keyword(Model):\n name = CharField(null=False)\n created = DateTimeField(null=False, default=datetime.utcnow)\n\n class Meta:\n primary_key = CompositeKey('name', 'created')\n```\n",
"Hmm, but surely this will imply a unique constraint which isn't what I'm after because the dataset can contain duplicate values. Is there any plans for peewee to support no primary key set ups?\n",
"Oh wait my mistake I forgot that this _is_ possible!\n\nEdited my comment above.\n",
"I've also updated the docs to make this more clear.\n",
"Awesome thanks Charles :)\n",
"Thanks @coleifer for this answer of yours - it helped me greatly now, three years later. :+1: (I was struggling with peewee trying to retrieve data from a non-existing sequence as below)\r\n\r\n```\r\npsycopg2.ProgrammingError: relation \"issue_assignees_id_seq\" does not exist\r\nLINE 1: SELECT CURRVAL('\"issue_assignees_id_seq\"')\r\n```\r\n\r\nApplying the `primary_key = False` to the inner class fixed the issue."
] | 2015-06-15T02:42:10 | 2018-09-25T07:02:38 | 2015-06-15T03:11:43 | CONTRIBUTOR | null | Hi Charles,
I've got a table which logs keywords, schema is:
```
class Keyword(Model):
name = CharField(null=False)
created = DateTimeField(null=False, default=datetime.utcnow)
class Meta:
indexes = (
(('created', 'name'), False)
)
```
In short, I want to drop the auto-generated primary key column (id). How do I prevent it from being readded in subsequent db creations? I've taken a look into the manual and not found the syntax.
---
In long, in the database however it has added an id column and associated pkey index. This table now has 35 million rows and that pkey index taking up 10gb in ram. I've taken a look into the code and it looks safe to drop the column, we only perform an aggregate query on the table in any case:
`Keyword.select(Keyword.created, Keyword.name).where(Keyword.created > 3_days)` OR `Keyword.select().where(Keyword.created > 3_days).count()`
Neither of these should need a primary key as we can get exact duplicates (35mil rows are for 3 days of data).
Many thanks,
Alex
PS. It would also be awesome to be able to name index constraints, getting a few problems when running schema migrations because of name mismatches between environments.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/626/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/626/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/625 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/625/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/625/comments | https://api.github.com/repos/coleifer/peewee/issues/625/events | https://github.com/coleifer/peewee/issues/625 | 88,032,515 | MDU6SXNzdWU4ODAzMjUxNQ== | 625 | Small issue with get_object_list() method | {
"login": "PiJoules",
"id": 6019989,
"node_id": "MDQ6VXNlcjYwMTk5ODk=",
"avatar_url": "https://avatars.githubusercontent.com/u/6019989?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/PiJoules",
"html_url": "https://github.com/PiJoules",
"followers_url": "https://api.github.com/users/PiJoules/followers",
"following_url": "https://api.github.com/users/PiJoules/following{/other_user}",
"gists_url": "https://api.github.com/users/PiJoules/gists{/gist_id}",
"starred_url": "https://api.github.com/users/PiJoules/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/PiJoules/subscriptions",
"organizations_url": "https://api.github.com/users/PiJoules/orgs",
"repos_url": "https://api.github.com/users/PiJoules/repos",
"events_url": "https://api.github.com/users/PiJoules/events{/privacy}",
"received_events_url": "https://api.github.com/users/PiJoules/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2015-06-13T16:50:00 | 2015-06-13T21:59:48 | 2015-06-13T21:59:48 | NONE | null | I was trying out the blog example and whenever I went on the dev server (127.0.0.1:5000), the 404 page would always get displayed. I was able to get around this by creating and publishing a post, but whenever I went to the drafts page (127.0.0.1:5000/drafts/), I would also get redirected to the same 404 page. I was able to trace the problem down to this line in the get_object_list() method in the `flask_utils.py` file:
``` py
if self.check_bounds and self.get_page() > self.get_page_count():
abort(404)
```
If I understand the overall code correctly, if no matches are found that match the query, then the page is redirected to the 404 page. I'm not sure if this was an intended feature (if this was intended, please ignore this issue), but when I first launched the app, I was expecting the same template provided in `index.html` just without posts instead of a 404 page.
I don't mean to nitpick or anything. I just wanted to point this out.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/625/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/625/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/624 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/624/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/624/comments | https://api.github.com/repos/coleifer/peewee/issues/624/events | https://github.com/coleifer/peewee/issues/624 | 87,621,777 | MDU6SXNzdWU4NzYyMTc3Nw== | 624 | A problem with connection pool | {
"login": "emamirazavi",
"id": 3804866,
"node_id": "MDQ6VXNlcjM4MDQ4NjY=",
"avatar_url": "https://avatars.githubusercontent.com/u/3804866?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/emamirazavi",
"html_url": "https://github.com/emamirazavi",
"followers_url": "https://api.github.com/users/emamirazavi/followers",
"following_url": "https://api.github.com/users/emamirazavi/following{/other_user}",
"gists_url": "https://api.github.com/users/emamirazavi/gists{/gist_id}",
"starred_url": "https://api.github.com/users/emamirazavi/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/emamirazavi/subscriptions",
"organizations_url": "https://api.github.com/users/emamirazavi/orgs",
"repos_url": "https://api.github.com/users/emamirazavi/repos",
"events_url": "https://api.github.com/users/emamirazavi/events{/privacy}",
"received_events_url": "https://api.github.com/users/emamirazavi/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I'm confused, what is the error and why is it an error in the connection pool? Seems to me to be an error in gunicorn/gevent.\n",
"Peewee is using pymysql and it's connection pooling(playhouse.pool) wants\nto create new connection. Python socket and threading replaced by gevent\nmonkey because of workers of gunicorn being Gevent. Isn't it?!\nOn Jun 12, 2015 9:14 PM, \"Charles Leifer\" [email protected] wrote:\n\n> I'm confused, what is the error and why is it an error in the connection\n> pool? Seems to me to be an error in gunicorn/gevent.\n> \n> —\n> Reply to this email directly or view it on GitHub\n> https://github.com/coleifer/peewee/issues/624#issuecomment-111552678.\n",
"This error raised at web requesting, there we have new connection and at\ntearing down that new will be closed.\nOn Jun 13, 2015 12:48 AM, \"S.Mohammad Emami Razavi\" [email protected]\nwrote:\n\n> Peewee is using pymysql and it's connection pooling(playhouse.pool) wants\n> to create new connection. Python socket and threading replaced by gevent\n> monkey because of workers of gunicorn being Gevent. Isn't it?!\n> On Jun 12, 2015 9:14 PM, \"Charles Leifer\" [email protected]\n> wrote:\n> \n> > I'm confused, what is the error and why is it an error in the connection\n> > pool? Seems to me to be an error in gunicorn/gevent.\n> > \n> > —\n> > Reply to this email directly or view it on GitHub\n> > https://github.com/coleifer/peewee/issues/624#issuecomment-111552678.\n",
"I am still not sure how this is a peewee issue.\n",
"@coleifer If it's possible keep this issue open for now. I will send it to the gevent on github and i wait for feedback. https://github.com/gevent/gevent/issues/573\n",
"See https://github.com/gevent/gevent/issues/573 again\nI think(based on traceback) this problem belongs to pymysql+gevent or my code not peewee.\nPlease close it if you are conviced.\n",
"Feel free to comment if you have new info indicating peewee as the cause.\n"
] | 2015-06-12T06:10:56 | 2015-06-13T22:02:22 | 2015-06-13T22:01:59 | NONE | null | ```
Jun 12 10:23:52 www.example.com gunicorn[4763]: [2015-06-12 10:23:52 +0000] [4763] [DEBUG] 3 workers
Jun 12 10:23:53 www.example.com gunicorn[4763]: [2015-06-12 10:23:53 +0000] [4763] [DEBUG] 3 workers
Jun 12 10:23:54 www.example.com gunicorn[4763]: [2015-06-12 10:23:53 +0000] [2876] [DEBUG] GET /inbound
Jun 12 10:23:54 www.example.com gunicorn[4763]: [2015-06-12 10:23:53 +0000] [2876] [ERROR] Error handling request
Jun 12 10:23:54 www.example.com gunicorn[4763]: Traceback (most recent call last):
Jun 12 10:23:54 www.example.com gunicorn[4763]: File "/usr/lib/python2.7/site-packages/gunicorn/workers/async.py", line 52, in handle
Jun 12 10:23:54 www.example.com gunicorn[4763]: self.handle_request(listener_name, req, client, addr)
Jun 12 10:23:54 www.example.com gunicorn[4763]: File "/usr/lib/python2.7/site-packages/gunicorn/workers/ggevent.py", line 159, in handle_request
Jun 12 10:23:54 www.example.com gunicorn[4763]: super(GeventWorker, self).handle_request(*args)
Jun 12 10:23:54 www.example.com gunicorn[4763]: File "/usr/lib/python2.7/site-packages/gunicorn/workers/async.py", line 105, in handle_request
Jun 12 10:23:54 www.example.com gunicorn[4763]: respiter = self.wsgi(environ, resp.start_response)
Jun 12 10:23:54 www.example.com gunicorn[4763]: File "/usr/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__
Jun 12 10:23:54 www.example.com gunicorn[4763]: return self.wsgi_app(environ, start_response)
Jun 12 10:23:54 www.example.com gunicorn[4763]: File "/usr/lib/python2.7/site-packages/flask/app.py", line 1820, in wsgi_app
Jun 12 10:23:54 www.example.com gunicorn[4763]: response = self.make_response(self.handle_exception(e))
Jun 12 10:23:54 www.example.com gunicorn[4763]: File "/usr/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exception
Jun 12 10:23:54 www.example.com gunicorn[4763]: reraise(exc_type, exc_value, tb)
Jun 12 10:23:54 www.example.com gunicorn[4763]: File "/usr/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
Jun 12 10:23:54 www.example.com gunicorn[4763]: response = self.full_dispatch_request()
Jun 12 10:23:54 www.example.com gunicorn[4763]: File "/usr/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
Jun 12 10:23:54 www.example.com gunicorn[4763]: rv = self.handle_user_exception(e)
Jun 12 10:23:54 www.example.com gunicorn[4763]: File "/usr/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
Jun 12 10:23:54 www.example.com gunicorn[4763]: reraise(exc_type, exc_value, tb)
Jun 12 10:23:54 www.example.com gunicorn[4763]: File "/usr/lib/python2.7/site-packages/flask/app.py", line 1473, in full_dispatch_request
Jun 12 10:23:54 www.example.com gunicorn[4763]: rv = self.preprocess_request()
Jun 12 10:23:54 www.example.com gunicorn[4763]: File "/usr/lib/python2.7/site-packages/flask/app.py", line 1666, in preprocess_request
Jun 12 10:23:54 www.example.com gunicorn[4763]: rv = func()
Jun 12 10:23:54 www.example.com gunicorn[4763]: File "/usr/local/src/aaron/lib/myapp/webserver.py", line 96, in before_request
Jun 12 10:23:54 www.example.com gunicorn[4763]: g.db.connect()
Jun 12 10:23:54 www.example.com gunicorn[4763]: File "/usr/local/src/aaron/lib/myapp/database.py", line 77, in connect
Jun 12 10:23:54 www.example.com gunicorn[4763]: super(MyPooledMySQLDatabase, self).connect()
Jun 12 10:23:54 www.example.com gunicorn[4763]: File "/usr/lib/python2.7/site-packages/peewee.py", line 2944, in connect
Jun 12 10:23:54 www.example.com gunicorn[4763]: **self.connect_kwargs)
Jun 12 10:23:54 www.example.com gunicorn[4763]: File "/usr/lib/python2.7/site-packages/playhouse/pool.py", line 108, in _connect
Jun 12 10:23:54 www.example.com gunicorn[4763]: conn = super(PooledDatabase, self)._connect(*args, **kwargs)
Jun 12 10:23:54 www.example.com gunicorn[4763]: File "/usr/lib/python2.7/site-packages/peewee.py", line 3399, in _connect
Jun 12 10:23:54 www.example.com gunicorn[4763]: return mysql.connect(db=database, **conn_kwargs)
Jun 12 10:23:54 www.example.com gunicorn[4763]: File "/usr/lib/python2.7/site-packages/pymysql/__init__.py", line 88, in Connect
Jun 12 10:23:54 www.example.com gunicorn[4763]: return Connection(*args, **kwargs)
Jun 12 10:23:54 www.example.com gunicorn[4763]: File "/usr/lib/python2.7/site-packages/pymysql/connections.py", line 644, in __init__
Jun 12 10:23:54 www.example.com gunicorn[4763]: self._connect()
Jun 12 10:23:54 www.example.com gunicorn[4763]: File "/usr/lib/python2.7/site-packages/pymysql/connections.py", line 823, in _connect
Jun 12 10:23:54 www.example.com gunicorn[4763]: (self.host, self.port), self.connect_timeout)
Jun 12 10:23:54 www.example.com gunicorn[4763]: File "/usr/lib64/python2.7/site-packages/gevent/socket.py", line 570, in create_connection
Jun 12 10:23:54 www.example.com gunicorn[4763]: for res in getaddrinfo(host, port, 0 if has_ipv6 else AF_INET, SOCK_STREAM):
Jun 12 10:23:54 www.example.com gunicorn[4763]: File "/usr/lib64/python2.7/site-packages/gevent/socket.py", line 621, in getaddrinfo
Jun 12 10:23:54 www.example.com gunicorn[4763]: return get_hub().resolver.getaddrinfo(host, port, family, socktype, proto, flags)
Jun 12 10:23:54 www.example.com gunicorn[4763]: File "/usr/lib64/python2.7/site-packages/gevent/resolver_thread.py", line 34, in getaddrinfo
Jun 12 10:23:54 www.example.com gunicorn[4763]: return self.pool.apply_e(self.expected_errors, _socket.getaddrinfo, args, kwargs)
Jun 12 10:23:54 www.example.com gunicorn[4763]: File "/usr/lib64/python2.7/site-packages/gevent/threadpool.py", line 222, in apply_e
Jun 12 10:23:54 www.example.com gunicorn[4763]: success, result = self.spawn(wrap_errors, expected_errors, function, args, kwargs).get()
Jun 12 10:23:54 www.example.com gunicorn[4763]: File "/usr/lib64/python2.7/site-packages/gevent/threadpool.py", line 159, in spawn
Jun 12 10:23:54 www.example.com gunicorn[4763]: self.adjust()
Jun 12 10:23:54 www.example.com gunicorn[4763]: File "/usr/lib64/python2.7/site-packages/gevent/threadpool.py", line 133, in adjust
Jun 12 10:23:54 www.example.com gunicorn[4763]: self._adjust_step()
Jun 12 10:23:54 www.example.com gunicorn[4763]: File "/usr/lib64/python2.7/site-packages/gevent/threadpool.py", line 113, in _adjust_step
Jun 12 10:23:54 www.example.com gunicorn[4763]: self._add_thread()
Jun 12 10:23:54 www.example.com gunicorn[4763]: File "/usr/lib64/python2.7/site-packages/gevent/threadpool.py", line 142, in _add_thread
Jun 12 10:23:54 www.example.com gunicorn[4763]: start_new_thread(self._worker, ())
Jun 12 10:23:54 www.example.com gunicorn[4763]: error: can't start new thread
Jun 12 10:23:54 www.example.com gunicorn[4763]: [2015-06-12 10:23:54 +0000] [4763] [DEBUG] 3 workers
Jun 12 10:23:55 www.example.com gunicorn[4763]: [2015-06-12 10:23:55 +0000] [4763] [DEBUG] 3 workers
Jun 12 10:23:56 www.example.com gunicorn[4763]: [2015-06-12 10:23:56 +0000] [4763] [DEBUG] 3 workers
Jun 12 10:23:57 www.example.com gunicorn[4763]: [2015-06-12 10:23:57 +0000] [4763] [DEBUG] 3 workers
Jun 12 10:23:58 www.example.com gunicorn[4763]: [2015-06-12 10:23:58 +0000] [4763] [DEBUG] 3 workers
Jun 12 10:23:59 www.example.com gunicorn[4763]: [2015-06-12 10:23:59 +0000] [4763] [DEBUG] 3 workers
Jun 12 10:24:00 www.example.com gunicorn[4763]: [2015-06-12 10:24:00 +0000] [4763] [DEBUG] 3 workers
```
After some days this error raised. What is your view?
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/624/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/624/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/623 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/623/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/623/comments | https://api.github.com/repos/coleifer/peewee/issues/623/events | https://github.com/coleifer/peewee/issues/623 | 87,224,424 | MDU6SXNzdWU4NzIyNDQyNA== | 623 | Debian package | {
"login": "fliiiix",
"id": 1682954,
"node_id": "MDQ6VXNlcjE2ODI5NTQ=",
"avatar_url": "https://avatars.githubusercontent.com/u/1682954?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/fliiiix",
"html_url": "https://github.com/fliiiix",
"followers_url": "https://api.github.com/users/fliiiix/followers",
"following_url": "https://api.github.com/users/fliiiix/following{/other_user}",
"gists_url": "https://api.github.com/users/fliiiix/gists{/gist_id}",
"starred_url": "https://api.github.com/users/fliiiix/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/fliiiix/subscriptions",
"organizations_url": "https://api.github.com/users/fliiiix/orgs",
"repos_url": "https://api.github.com/users/fliiiix/repos",
"events_url": "https://api.github.com/users/fliiiix/events{/privacy}",
"received_events_url": "https://api.github.com/users/fliiiix/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I've started something https://github.com/fliiiix/python-peewee but like most times I have not really a clue if I'm doing this the right way. \n",
"I do not have plans to make a debian package, nor make that part of the peewee source code. `pip` is seen as the primary way for managing python packages these days, anyways.\n",
"Okey cool thanks for your fast response. \nJust to get this right: you're not doing it and it won't be part of this repository, but there is no problem if someone else does it? \n",
"Correct. No problem at all if someone else wanted to maintain a debian package.\n",
":+1: \n"
] | 2015-06-11T06:04:47 | 2015-06-11T17:49:11 | 2015-06-11T15:56:10 | NONE | null | Are there any plans to pack peewee for Debian?
Or are there any reasons this is not gonna happen?
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/623/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/623/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/622 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/622/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/622/comments | https://api.github.com/repos/coleifer/peewee/issues/622/events | https://github.com/coleifer/peewee/pull/622 | 86,569,454 | MDExOlB1bGxSZXF1ZXN0MzcyNDQ2NDY= | 622 | Support connect params in db_url | {
"login": "klen",
"id": 90699,
"node_id": "MDQ6VXNlcjkwNjk5",
"avatar_url": "https://avatars.githubusercontent.com/u/90699?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/klen",
"html_url": "https://github.com/klen",
"followers_url": "https://api.github.com/users/klen/followers",
"following_url": "https://api.github.com/users/klen/following{/other_user}",
"gists_url": "https://api.github.com/users/klen/gists{/gist_id}",
"starred_url": "https://api.github.com/users/klen/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/klen/subscriptions",
"organizations_url": "https://api.github.com/users/klen/orgs",
"repos_url": "https://api.github.com/users/klen/repos",
"events_url": "https://api.github.com/users/klen/events{/privacy}",
"received_events_url": "https://api.github.com/users/klen/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Beautiful!\n"
] | 2015-06-09T11:46:26 | 2015-06-09T13:10:36 | 2015-06-09T13:10:36 | CONTRIBUTOR | null | Hello!
The PR provides a way to set additional connection params when db_url.connect is used. Such as `encoding` for postgresql and etc.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/622/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/622/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/622",
"html_url": "https://github.com/coleifer/peewee/pull/622",
"diff_url": "https://github.com/coleifer/peewee/pull/622.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/622.patch",
"merged_at": "2015-06-09T13:10:36"
} |
https://api.github.com/repos/coleifer/peewee/issues/621 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/621/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/621/comments | https://api.github.com/repos/coleifer/peewee/issues/621/events | https://github.com/coleifer/peewee/issues/621 | 86,468,396 | MDU6SXNzdWU4NjQ2ODM5Ng== | 621 | Tornado | {
"login": "AlexHeKa",
"id": 9191522,
"node_id": "MDQ6VXNlcjkxOTE1MjI=",
"avatar_url": "https://avatars.githubusercontent.com/u/9191522?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/AlexHeKa",
"html_url": "https://github.com/AlexHeKa",
"followers_url": "https://api.github.com/users/AlexHeKa/followers",
"following_url": "https://api.github.com/users/AlexHeKa/following{/other_user}",
"gists_url": "https://api.github.com/users/AlexHeKa/gists{/gist_id}",
"starred_url": "https://api.github.com/users/AlexHeKa/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/AlexHeKa/subscriptions",
"organizations_url": "https://api.github.com/users/AlexHeKa/orgs",
"repos_url": "https://api.github.com/users/AlexHeKa/repos",
"events_url": "https://api.github.com/users/AlexHeKa/events{/privacy}",
"received_events_url": "https://api.github.com/users/AlexHeKa/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2015-06-09T06:15:09 | 2015-06-09T13:10:49 | 2015-06-09T13:10:49 | NONE | null | Please help make tornado handle the connections correctly by using peewee
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/621/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/621/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/620 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/620/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/620/comments | https://api.github.com/repos/coleifer/peewee/issues/620/events | https://github.com/coleifer/peewee/issues/620 | 86,233,299 | MDU6SXNzdWU4NjIzMzI5OQ== | 620 | issue when field name is _data | {
"login": "xinming90",
"id": 5674271,
"node_id": "MDQ6VXNlcjU2NzQyNzE=",
"avatar_url": "https://avatars.githubusercontent.com/u/5674271?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/xinming90",
"html_url": "https://github.com/xinming90",
"followers_url": "https://api.github.com/users/xinming90/followers",
"following_url": "https://api.github.com/users/xinming90/following{/other_user}",
"gists_url": "https://api.github.com/users/xinming90/gists{/gist_id}",
"starred_url": "https://api.github.com/users/xinming90/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/xinming90/subscriptions",
"organizations_url": "https://api.github.com/users/xinming90/orgs",
"repos_url": "https://api.github.com/users/xinming90/repos",
"events_url": "https://api.github.com/users/xinming90/events{/privacy}",
"received_events_url": "https://api.github.com/users/xinming90/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Unfortunately I do not plan on merging your fix, as it changes some major underlying assumptions about peewee models. For now this is just a limitation of peewee. If your column is named `_data`, you can do this instead:\n\n``` python\nclass User(Model):\n data = CharField(db_column='_data')\n```\n"
] | 2015-06-08T15:58:32 | 2015-06-08T16:22:32 | 2015-06-08T16:22:32 | NONE | null | For example
``` python
from peewee import *
class User(Model):
id = IntegerField()
_data = CharField()
u = User(id=1, _data='eleme')
print u.id, u._data
```
got error
```
(virtualenv)➜ peewee git:(master) ✗ python t.py
Traceback (most recent call last):
File "t.py", line 7, in <module>
u = User(id=1, _data='eleme')
File "/Users/ming/github/peewee/peewee.py", line 3971, in __init__
setattr(self, k, v)
File "/Users/ming/github/peewee/peewee.py", line 705, in __set__
instance._data[self.att_name] = value
TypeError: 'str' object does not support item assignment
(virtualenv)➜ peewee git:(master) ✗
```
### just inheritance dict to resovle this bug
### please see my pr [#619](https://github.com/coleifer/peewee/pull/619) for detail
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/620/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/620/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/619 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/619/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/619/comments | https://api.github.com/repos/coleifer/peewee/issues/619/events | https://github.com/coleifer/peewee/pull/619 | 86,231,805 | MDExOlB1bGxSZXF1ZXN0MzcxNjc5MDY= | 619 | fix field named '_data' | {
"login": "xinming90",
"id": 5674271,
"node_id": "MDQ6VXNlcjU2NzQyNzE=",
"avatar_url": "https://avatars.githubusercontent.com/u/5674271?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/xinming90",
"html_url": "https://github.com/xinming90",
"followers_url": "https://api.github.com/users/xinming90/followers",
"following_url": "https://api.github.com/users/xinming90/following{/other_user}",
"gists_url": "https://api.github.com/users/xinming90/gists{/gist_id}",
"starred_url": "https://api.github.com/users/xinming90/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/xinming90/subscriptions",
"organizations_url": "https://api.github.com/users/xinming90/orgs",
"repos_url": "https://api.github.com/users/xinming90/repos",
"events_url": "https://api.github.com/users/xinming90/events{/privacy}",
"received_events_url": "https://api.github.com/users/xinming90/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2015-06-08T15:53:16 | 2015-06-08T16:23:24 | 2015-06-08T16:23:24 | NONE | null | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/619/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/619/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/619",
"html_url": "https://github.com/coleifer/peewee/pull/619",
"diff_url": "https://github.com/coleifer/peewee/pull/619.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/619.patch",
"merged_at": null
} |
|
https://api.github.com/repos/coleifer/peewee/issues/618 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/618/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/618/comments | https://api.github.com/repos/coleifer/peewee/issues/618/events | https://github.com/coleifer/peewee/issues/618 | 85,804,363 | MDU6SXNzdWU4NTgwNDM2Mw== | 618 | Implicit add Primary Key for id field | {
"login": "horpto",
"id": 7109350,
"node_id": "MDQ6VXNlcjcxMDkzNTA=",
"avatar_url": "https://avatars.githubusercontent.com/u/7109350?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/horpto",
"html_url": "https://github.com/horpto",
"followers_url": "https://api.github.com/users/horpto/followers",
"following_url": "https://api.github.com/users/horpto/following{/other_user}",
"gists_url": "https://api.github.com/users/horpto/gists{/gist_id}",
"starred_url": "https://api.github.com/users/horpto/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/horpto/subscriptions",
"organizations_url": "https://api.github.com/users/horpto/orgs",
"repos_url": "https://api.github.com/users/horpto/repos",
"events_url": "https://api.github.com/users/horpto/events{/privacy}",
"received_events_url": "https://api.github.com/users/horpto/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"This is just the standard peewee behavior. If you want a different field to be primary key, declare a different one.\n"
] | 2015-06-06T19:26:07 | 2015-06-06T23:53:45 | 2015-06-06T23:53:45 | NONE | null | ```
class Model(BaseModel):
id = TextField()
field = TextField()
```
Field id implicitly is primary key now. TextField, for example, is not really suitable to be a primary key, but unexpectedly it is. Maybe this situation need report warning or even error.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/618/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/618/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/617 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/617/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/617/comments | https://api.github.com/repos/coleifer/peewee/issues/617/events | https://github.com/coleifer/peewee/issues/617 | 85,471,753 | MDU6SXNzdWU4NTQ3MTc1Mw== | 617 | How to create bigint field? | {
"login": "emamirazavi",
"id": 3804866,
"node_id": "MDQ6VXNlcjM4MDQ4NjY=",
"avatar_url": "https://avatars.githubusercontent.com/u/3804866?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/emamirazavi",
"html_url": "https://github.com/emamirazavi",
"followers_url": "https://api.github.com/users/emamirazavi/followers",
"following_url": "https://api.github.com/users/emamirazavi/following{/other_user}",
"gists_url": "https://api.github.com/users/emamirazavi/gists{/gist_id}",
"starred_url": "https://api.github.com/users/emamirazavi/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/emamirazavi/subscriptions",
"organizations_url": "https://api.github.com/users/emamirazavi/orgs",
"repos_url": "https://api.github.com/users/emamirazavi/repos",
"events_url": "https://api.github.com/users/emamirazavi/events{/privacy}",
"received_events_url": "https://api.github.com/users/emamirazavi/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"use BigIntegerField\n"
] | 2015-06-05T08:30:08 | 2015-06-05T08:51:09 | 2015-06-05T08:51:09 | NONE | null | Can i create bigint field in integer type of fields?
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/617/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/617/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/616 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/616/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/616/comments | https://api.github.com/repos/coleifer/peewee/issues/616/events | https://github.com/coleifer/peewee/issues/616 | 85,331,742 | MDU6SXNzdWU4NTMzMTc0Mg== | 616 | Support PostgreSql table inheritance | {
"login": "horpto",
"id": 7109350,
"node_id": "MDQ6VXNlcjcxMDkzNTA=",
"avatar_url": "https://avatars.githubusercontent.com/u/7109350?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/horpto",
"html_url": "https://github.com/horpto",
"followers_url": "https://api.github.com/users/horpto/followers",
"following_url": "https://api.github.com/users/horpto/following{/other_user}",
"gists_url": "https://api.github.com/users/horpto/gists{/gist_id}",
"starred_url": "https://api.github.com/users/horpto/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/horpto/subscriptions",
"organizations_url": "https://api.github.com/users/horpto/orgs",
"repos_url": "https://api.github.com/users/horpto/repos",
"events_url": "https://api.github.com/users/horpto/events{/privacy}",
"received_events_url": "https://api.github.com/users/horpto/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I don't know very much about that particular feature, so I can't really say that I have any plans on implementing it. I think I will defer on this one, but if you'd like to discuss making a pull-request let me know.\n"
] | 2015-06-04T23:44:26 | 2015-06-05T00:59:20 | 2015-06-05T00:59:20 | NONE | null | PostgreSql has cool feature like [Table inheritance](http://www.postgresql.org/docs/9.0/static/ddl-inherit.html). It'd be good to implement this feature using inheritance field in Meta class of model.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/616/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/616/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/615 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/615/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/615/comments | https://api.github.com/repos/coleifer/peewee/issues/615/events | https://github.com/coleifer/peewee/issues/615 | 84,918,815 | MDU6SXNzdWU4NDkxODgxNQ== | 615 | Support set timezone | {
"login": "rodumani",
"id": 4019016,
"node_id": "MDQ6VXNlcjQwMTkwMTY=",
"avatar_url": "https://avatars.githubusercontent.com/u/4019016?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/rodumani",
"html_url": "https://github.com/rodumani",
"followers_url": "https://api.github.com/users/rodumani/followers",
"following_url": "https://api.github.com/users/rodumani/following{/other_user}",
"gists_url": "https://api.github.com/users/rodumani/gists{/gist_id}",
"starred_url": "https://api.github.com/users/rodumani/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/rodumani/subscriptions",
"organizations_url": "https://api.github.com/users/rodumani/orgs",
"repos_url": "https://api.github.com/users/rodumani/repos",
"events_url": "https://api.github.com/users/rodumani/events{/privacy}",
"received_events_url": "https://api.github.com/users/rodumani/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Just call `db.execute_sql('set timezone=\"+09:00\"')`. You can also check your mysql driver's docs to see if it accepts a `time_zone` parameter. If not, you can subclass `MySQLDatabase`, override the `_connect` method, and run `set time_zone` on the newly-created connection.\n"
] | 2015-06-04T05:15:29 | 2015-06-04T23:22:20 | 2015-06-04T23:22:06 | NONE | null | Hello!
I'm making query like following which filter TIMESTAMP field between two dates.
However, the problem is that our MySQL's default timezone is UTC and I want to query in KST timezone.
``` python
Log
.select(fn.Sum(Log.cnt))
.where(Log.insert_dt.between(start_date, end_date))
.scalar()
```
When using SQL, I can set timezone by `set timezone="+09:00"`. I cannot find option to set timezone on Peewee.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/615/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/615/timeline | null | completed | null | null |
Subsets and Splits