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/214 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/214/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/214/comments | https://api.github.com/repos/coleifer/peewee/issues/214/events | https://github.com/coleifer/peewee/issues/214 | 16,728,423 | MDU6SXNzdWUxNjcyODQyMw== | 214 | Usage of wildcards corrupted with Field coerce | {
"login": "johnmave126",
"id": 1661662,
"node_id": "MDQ6VXNlcjE2NjE2NjI=",
"avatar_url": "https://avatars.githubusercontent.com/u/1661662?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/johnmave126",
"html_url": "https://github.com/johnmave126",
"followers_url": "https://api.github.com/users/johnmave126/followers",
"following_url": "https://api.github.com/users/johnmave126/following{/other_user}",
"gists_url": "https://api.github.com/users/johnmave126/gists{/gist_id}",
"starred_url": "https://api.github.com/users/johnmave126/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/johnmave126/subscriptions",
"organizations_url": "https://api.github.com/users/johnmave126/orgs",
"repos_url": "https://api.github.com/users/johnmave126/repos",
"events_url": "https://api.github.com/users/johnmave126/events{/privacy}",
"received_events_url": "https://api.github.com/users/johnmave126/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Please close this issue\nI found it duplicate to #212 \n"
] | 2013-07-14T14:22:10 | 2013-07-14T16:20:29 | 2013-07-14T16:20:29 | NONE | null | Reproduction
``` python
class Sample(Model):
test = CharField(max_length=3)
Sample.create(test='123')
sq = Sample.select().filter(test__ilike='%123%')
assert sq.count() != 0
```
Root Cause:
Digg into the source code I found following lines:
peewee.py:775
``` python
if isinstance(expr.lhs, Field):
conv = expr.lhs
lhs, lparams = self.parse_expr(expr.lhs, alias_map, conv)
rhs, rparams = self.parse_expr(expr.rhs, alias_map, conv)
```
peewee.py:830
``` python
elif conv and p:
p = [conv.db_value(i) for i in p]
```
peewee.py:487
``` python
def coerce(self, value):
value = format_unicode(value or '')
return value[:self.attributes['max_length']]
```
Since calling db_value of a CharField will call coerce to return a value for database, a CharField with max_length will discard the ending wildcard. Thus the sq in the sample code will compile to a clause like
``` sql
`test` LIKE '%12'
```
where it should be
``` sql
`test` LIKE '%123%'
```
I have no idea how to fix this in a right way. I personally write an alternative of parse_expr to avoid this problem for now.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/214/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/214/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/213 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/213/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/213/comments | https://api.github.com/repos/coleifer/peewee/issues/213/events | https://github.com/coleifer/peewee/issues/213 | 16,694,475 | MDU6SXNzdWUxNjY5NDQ3NQ== | 213 | Unable to retrieve columns from joined table (PostgreSQL) | {
"login": "SecurityForUs",
"id": 1146703,
"node_id": "MDQ6VXNlcjExNDY3MDM=",
"avatar_url": "https://avatars.githubusercontent.com/u/1146703?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/SecurityForUs",
"html_url": "https://github.com/SecurityForUs",
"followers_url": "https://api.github.com/users/SecurityForUs/followers",
"following_url": "https://api.github.com/users/SecurityForUs/following{/other_user}",
"gists_url": "https://api.github.com/users/SecurityForUs/gists{/gist_id}",
"starred_url": "https://api.github.com/users/SecurityForUs/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/SecurityForUs/subscriptions",
"organizations_url": "https://api.github.com/users/SecurityForUs/orgs",
"repos_url": "https://api.github.com/users/SecurityForUs/repos",
"events_url": "https://api.github.com/users/SecurityForUs/events{/privacy}",
"received_events_url": "https://api.github.com/users/SecurityForUs/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Nevermind, I forgot in a join the joined table is in its own attribute. Closing.\n"
] | 2013-07-12T18:09:44 | 2013-07-12T18:12:41 | 2013-07-12T18:12:41 | NONE | null | I have two PgSQL tables (servers and api) where api.servers_id = servers.id. Here are my models:
``` python
class Servers(BaseModel):
id = BigIntegerField(primary_key=True)
user = ForeignKeyField(Users, cascade=True)
ipv4 = CharField(max_length=17)
ipv6 = CharField(max_length=45)
hostname = CharField(max_length=256)
class Api(BaseModel):
id = BigIntegerField(primary_key=True)
private = CharField(max_length=212)
public = CharField(max_length=31)
server = ForeignKeyField(Servers, cascade=True)
servers = Servers
api = Api
```
What I'm wanting to do is get API information based on the server id, so I set up my query like this:
``` python
s = servers
a = api
server_info = s.select(
s.id.alias("sid"),s.ipv6.alias("ipv6"),s.hostname.alias("hostname"),s.ipv4.alias("ipv4"),
a.id.alias("aid"),a.private.alias("private"),a.public.alias("public")
).join(a, self.db.JOIN_FULL).where(s.user==self.uid)
```
The problem is server_info records only have the items of the server itself, not of the api fields as well. This generates this query:
```
SELECT t1."id" AS sid, t1."ipv6" AS ipv6, t1."hostname" AS hostname, t1."ipv4" AS ipv4, t2."id" AS aid, t2."private" AS private, t2."public" AS public FROM "servers" AS t1 FULL JOIN "api" AS t2 ON (t1."id" = t2."server_id") WHERE (t1."user_id" = 1)
```
Which when ran in PgAdmin gives me the results I want, but not here. None of the a.\* fields are in the results, just the s.*.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/213/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/213/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/212 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/212/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/212/comments | https://api.github.com/repos/coleifer/peewee/issues/212/events | https://github.com/coleifer/peewee/issues/212 | 16,534,635 | MDU6SXNzdWUxNjUzNDYzNQ== | 212 | Wildcard * does not act as "none or some characters", but as "some characters" | {
"login": "arnuschky",
"id": 179920,
"node_id": "MDQ6VXNlcjE3OTkyMA==",
"avatar_url": "https://avatars.githubusercontent.com/u/179920?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/arnuschky",
"html_url": "https://github.com/arnuschky",
"followers_url": "https://api.github.com/users/arnuschky/followers",
"following_url": "https://api.github.com/users/arnuschky/following{/other_user}",
"gists_url": "https://api.github.com/users/arnuschky/gists{/gist_id}",
"starred_url": "https://api.github.com/users/arnuschky/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/arnuschky/subscriptions",
"organizations_url": "https://api.github.com/users/arnuschky/orgs",
"repos_url": "https://api.github.com/users/arnuschky/repos",
"events_url": "https://api.github.com/users/arnuschky/events{/privacy}",
"received_events_url": "https://api.github.com/users/arnuschky/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"With SQLite the `%` operator (case-sensitive like) actually uses the `GLOB` operation which is why it requires you use `*` as the wildcard. The `**` operator (case-insensitive like) uses `LIKE`. Confusing, right?\n\nBased on this script, I believe the \"*\" character is matching zero or more. Does it work for you?\n\n``` python\nfrom peewee import *\n\ndb = SqliteDatabase(':memory:')\n\nclass TestModel(Model):\n name = CharField()\n\nnames = ['foo', 'bar', 'baz']\n\nTestModel.create_table()\nfor name in names:\n TestModel.create(name=name)\n\nassert TestModel.get(TestModel.name % '*foo*').name == 'foo'\nassert TestModel.get(TestModel.name % 'foo*').name == 'foo'\nassert TestModel.get(TestModel.name % '*ba*').name in ('bar', 'baz')\n```\n",
"Try:\n\n```\n name = CharField(max_length=3)\n```\n\nPeeWee seems to strip the search string for (including the wildcard) according to the max_length attribute\n",
"@arnuschky -- Ahhh, good catch.\n"
] | 2013-07-09T16:37:45 | 2013-07-14T15:12:20 | 2013-07-10T13:11:42 | NONE | null | The following select (on SQLite):
User.select().where(User.name % "_joe_")
does not work if user name is exactly "joe". The wildcard does not act as "none or some characters", but as "some characters". (And thus behaves just like the '+' of regular expressions.)
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/212/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/212/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/211 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/211/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/211/comments | https://api.github.com/repos/coleifer/peewee/issues/211/events | https://github.com/coleifer/peewee/issues/211 | 16,427,397 | MDU6SXNzdWUxNjQyNzM5Nw== | 211 | field unique=True doesn't work? | {
"login": "jfmatth",
"id": 289202,
"node_id": "MDQ6VXNlcjI4OTIwMg==",
"avatar_url": "https://avatars.githubusercontent.com/u/289202?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/jfmatth",
"html_url": "https://github.com/jfmatth",
"followers_url": "https://api.github.com/users/jfmatth/followers",
"following_url": "https://api.github.com/users/jfmatth/following{/other_user}",
"gists_url": "https://api.github.com/users/jfmatth/gists{/gist_id}",
"starred_url": "https://api.github.com/users/jfmatth/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/jfmatth/subscriptions",
"organizations_url": "https://api.github.com/users/jfmatth/orgs",
"repos_url": "https://api.github.com/users/jfmatth/repos",
"events_url": "https://api.github.com/users/jfmatth/events{/privacy}",
"received_events_url": "https://api.github.com/users/jfmatth/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Call model.create_table instead. Db method just creates the table while model method creates indexes as well.\n",
"thanks, worked great!\n"
] | 2013-07-06T06:16:57 | 2013-07-06T23:47:27 | 2013-07-06T22:43:34 | NONE | null | Running the latest branch, and the following model doesn't create what I think it does, a unique constraint on the field.
```
import peewee
db = peewee.SqliteDatabase("test.db")
class table1(peewee.Model):
field1 = peewee.CharField(unique=True)
field2 = peewee.CharField(null=True)
class Meta:
database = db
db.create_table(table1)
(vPython27) C:\Users\jmatthew\Development\settingsmgr>sqlite3 test.db
SQLite version 3.7.17 2013-05-20 00:56:22
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> .sch
CREATE TABLE "table1" ("id" INTEGER NOT NULL PRIMARY KEY, "field1" VARCHAR(255) NOT NULL, "field2" V
ARCHAR(255));
sqlite>
```
Am i missing anything? I looked in the source but didn't see anywhere that that field uniqueness was referenced while generating the table create.
Love the library, let me know how i can help
J
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/211/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/211/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/210 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/210/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/210/comments | https://api.github.com/repos/coleifer/peewee/issues/210/events | https://github.com/coleifer/peewee/issues/210 | 16,136,447 | MDU6SXNzdWUxNjEzNjQ0Nw== | 210 | Extend deferred initialization to database kind | {
"login": "panta",
"id": 238501,
"node_id": "MDQ6VXNlcjIzODUwMQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/238501?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/panta",
"html_url": "https://github.com/panta",
"followers_url": "https://api.github.com/users/panta/followers",
"following_url": "https://api.github.com/users/panta/following{/other_user}",
"gists_url": "https://api.github.com/users/panta/gists{/gist_id}",
"starred_url": "https://api.github.com/users/panta/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/panta/subscriptions",
"organizations_url": "https://api.github.com/users/panta/orgs",
"repos_url": "https://api.github.com/users/panta/repos",
"events_url": "https://api.github.com/users/panta/events{/privacy}",
"received_events_url": "https://api.github.com/users/panta/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"From docstring:\n\n``` python\n from peewee import *\n from playhouse.proxy import Proxy\n\n database_proxy = Proxy() # Create a proxy for our db.\n\n class BaseModel(Model):\n class Meta:\n database = database_proxy # Use proxy for our DB.\n\n class User(BaseModel):\n username = CharField()\n\n # Based on configuration, use a different database.\n if app.config['DEBUG']:\n database = SqliteDatabase('local.db')\n elif app.config['TESTING']:\n database = SqliteDatabase(':memory:')\n else:\n database = PostgresqlDatabase('mega_production_db')\n\n # Configure our proxy to use the db we specified in config.\n database_proxy.initialize(database)\n```\n",
"> From docstring:\r\n> \r\n> ```python\r\n> from peewee import *\r\n> from playhouse.proxy import Proxy\r\n> \r\n> database_proxy = Proxy() # Create a proxy for our db.\r\n> \r\n> class BaseModel(Model):\r\n> class Meta:\r\n> database = database_proxy # Use proxy for our DB.\r\n> \r\n> class User(BaseModel):\r\n> username = CharField()\r\n> \r\n> # Based on configuration, use a different database.\r\n> if app.config['DEBUG']:\r\n> database = SqliteDatabase('local.db')\r\n> elif app.config['TESTING']:\r\n> database = SqliteDatabase(':memory:')\r\n> else:\r\n> database = PostgresqlDatabase('mega_production_db')\r\n> \r\n> # Configure our proxy to use the db we specified in config.\r\n> database_proxy.initialize(database)\r\n> ```\r\n\r\n`from playhouse.proxy import Proxy` not found any more...",
"It's moved into the peewee module: http://docs.peewee-orm.com/en/latest/peewee/api.html#Proxy\r\n\r\n```python\r\nfrom peewee import Proxy\r\n```\r\n\r\nAlthough you probably want to use instead the `DatabaseProxy`:\r\n\r\n```python\r\nfrom peewee import DatabaseProxy\r\n```"
] | 2013-06-28T10:45:45 | 2019-03-22T14:55:12 | 2013-06-29T00:47:55 | NONE | null | It would be useful in many circumstances to use different database flavors (Sqlite, MySQL, ...) depending on a configuration parameter.
Extending the mechanism of deferred initialization described in:
http://peewee.readthedocs.org/en/latest/peewee/cookbook.html#deferring-initialization
it would be nice to have something like:
```
deferred_db = GenericDatabase()
class SomeModel(Model):
class Meta:
database = deferred_db
...
# read config
if config.DB_KIND == 'sqlite':
deferred_db.setup('sqlite')
deferred_db.init(config.DB_NAME)
elif config.DB_KIND == 'mysql':
deferred_db.setup('mysql')
deferred_db.init(config.DB_NAME, host=config.DB_HOST, port=config.DB_PORT, ...)
else:
...
```
or even merge the functionality in the init() method, with a kind keyword argument (which would work when using the GenericDatabase).
Would it be possible or are there any workarounds at this time?
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/210/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/210/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/209 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/209/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/209/comments | https://api.github.com/repos/coleifer/peewee/issues/209/events | https://github.com/coleifer/peewee/issues/209 | 16,080,666 | MDU6SXNzdWUxNjA4MDY2Ng== | 209 | delete() doesn't handle order_by() | {
"login": "panta",
"id": 238501,
"node_id": "MDQ6VXNlcjIzODUwMQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/238501?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/panta",
"html_url": "https://github.com/panta",
"followers_url": "https://api.github.com/users/panta/followers",
"following_url": "https://api.github.com/users/panta/following{/other_user}",
"gists_url": "https://api.github.com/users/panta/gists{/gist_id}",
"starred_url": "https://api.github.com/users/panta/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/panta/subscriptions",
"organizations_url": "https://api.github.com/users/panta/orgs",
"repos_url": "https://api.github.com/users/panta/repos",
"events_url": "https://api.github.com/users/panta/events{/privacy}",
"received_events_url": "https://api.github.com/users/panta/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Postgresql does not support this, and Sqlite does but only if compiled with `SQLITE_ENABLE_UPDATE_DELETE_LIMIT`. Because it is only MySQL that supports this feature, I am going to pass on fixing it for now.\n\nThere have been similar features requests, from which you might be able to get some ideas:\n- #146 , adds limit / order by to update queries\n- #153 , adds support for limit to update queries\n\nIn the future I may attempt to add a compatibility layer, but for now I am going to close this.\n",
"Thank you, in the meantime I arrived at the same conclusions too.\nI've found multiple other ways to solve the same problem, thanks to peewee flexibility. In case anyone ends here with the same problem, they are:\n\nselect() + delete():\n\n``` python\nto_delete = Log.select().order_by(Log.when.asc()).limit(n_to_delete)\nn_deleted = Log.delete().where(Log.id << to_delete).execute()\n```\n\nselect() + DeleteQuery():\n\n``` python\ndq = DeleteQuery(Log).where(\n Log.id << Log.select().order_by(Log.when.asc()).limit(n_to_delete)\n)\nn_deleted = dq.execute()\n```\n\nraw SQL:\n\n``` python\ndb.execute_sql(\"DELETE FROM log WHERE `id` in ( SELECT `id` FROM log ORDER BY `when` DESC LIMIT ? OFFSET ? )\", (n_to_delete, max_logs))\n```\n"
] | 2013-06-27T11:03:32 | 2013-06-27T13:49:07 | 2013-06-27T13:12:21 | NONE | null | ``` python
n_deleted = Log.delete().order_by(Log.when.asc()).limit(n_to_delete)
```
raises the following exception:
```
AttributeError: 'DeleteQuery' object has no attribute 'order_by'
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/209/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/209/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/208 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/208/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/208/comments | https://api.github.com/repos/coleifer/peewee/issues/208/events | https://github.com/coleifer/peewee/issues/208 | 16,053,943 | MDU6SXNzdWUxNjA1Mzk0Mw== | 208 | Aggregate(...) and fn.Max for DateTimeField should return datetime objects | {
"login": "passiomatic",
"id": 56371,
"node_id": "MDQ6VXNlcjU2Mzcx",
"avatar_url": "https://avatars.githubusercontent.com/u/56371?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/passiomatic",
"html_url": "https://github.com/passiomatic",
"followers_url": "https://api.github.com/users/passiomatic/followers",
"following_url": "https://api.github.com/users/passiomatic/following{/other_user}",
"gists_url": "https://api.github.com/users/passiomatic/gists{/gist_id}",
"starred_url": "https://api.github.com/users/passiomatic/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/passiomatic/subscriptions",
"organizations_url": "https://api.github.com/users/passiomatic/orgs",
"repos_url": "https://api.github.com/users/passiomatic/repos",
"events_url": "https://api.github.com/users/passiomatic/events{/privacy}",
"received_events_url": "https://api.github.com/users/passiomatic/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Unfortunately, I'm not sure there's a great solution for this without resorting to hacks. It would be possible to special-case flat aggregation / annotations by introspecting the field type and then passing the value from the cursor through the field's `python_value` method, but I'm not sure how clean the implementation would be and it might be fragile. The other thing I want to avoid is a performance penalty.\n\nFor now I am going to leave this open, but I'm not sure that I will be able to resolve it.\n\nNote: This problem only appears in Sqlite and not mysql / postgres.\n",
"Partially fixed in d23619abeb0f78d46284658d012970a30c7e3186 . `annotate` works now, just `aggregate` / `scalar` fail.\n",
"That's great, thank you. Do you plan to do a dot release soon?\n",
"Within the next day or two.\n"
] | 2013-06-26T20:23:13 | 2013-06-27T22:21:20 | 2013-06-27T21:39:08 | NONE | null | I'm using Peewee 2.1.2, Python 2.6.1 with bundled sqlite3, see versions below:
```
>>> sqlite3.sqlite_version_info
(3, 6, 12)
>>> sqlite3.version_info
(2, 4, 1)
```
Test case to reproduce the problem:
``` python
from datetime import datetime
from peewee import *
the_db = SqliteDatabase(':memory:')
class MyModel(Model):
dt = DateTimeField(null=True)
class Meta:
database = the_db
if __name__ == '__main__':
the_db.connect()
MyModel.create_table()
# Fill
now = datetime.now()
for _ in range(50):
m = MyModel()
m.dt = now
m.save()
# This works
q = MyModel.select()
for i in q:
assert type(i.dt) is datetime
# These both fails
r = MyModel.select().aggregate(fn.Max(MyModel.dt))
print type(r)
assert type(r) is datetime
q = MyModel.select(fn.Max(MyModel.dt).alias('max_dt'))
for i in q:
print type(i.max_dt)
assert type(i.max_dt) is datetime
```
Output:
```
Underworld:$ python testcase.py
<type 'unicode'>
Traceback (most recent call last):
File "testcase.py", line 32, in <module>
assert type(r) is datetime
AssertionError
```
Thank you.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/208/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/208/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/207 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/207/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/207/comments | https://api.github.com/repos/coleifer/peewee/issues/207/events | https://github.com/coleifer/peewee/issues/207 | 15,708,103 | MDU6SXNzdWUxNTcwODEwMw== | 207 | pwiz not generating foreign key fields? | {
"login": "jfmatth",
"id": 289202,
"node_id": "MDQ6VXNlcjI4OTIwMg==",
"avatar_url": "https://avatars.githubusercontent.com/u/289202?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/jfmatth",
"html_url": "https://github.com/jfmatth",
"followers_url": "https://api.github.com/users/jfmatth/followers",
"following_url": "https://api.github.com/users/jfmatth/following{/other_user}",
"gists_url": "https://api.github.com/users/jfmatth/gists{/gist_id}",
"starred_url": "https://api.github.com/users/jfmatth/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/jfmatth/subscriptions",
"organizations_url": "https://api.github.com/users/jfmatth/orgs",
"repos_url": "https://api.github.com/users/jfmatth/repos",
"events_url": "https://api.github.com/users/jfmatth/events{/privacy}",
"received_events_url": "https://api.github.com/users/jfmatth/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"edit: fixed formatting.\n",
"Are you using MySQL?\n",
"If you're using MySQL you might test out using this query, which is how pwiz finds foreign keys:\n\n``` sql\nSELECT column_name, referenced_table_name, referenced_column_name\nFROM information_schema.key_column_usage\nWHERE table_name = \"your table name here\"\n AND table_schema = DATABASE()\n AND referenced_table_name IS NOT NULL\n AND referenced_column_name IS NOT NULL\n```\n",
"Yes we are.\n\nI'll run the query and show results. Thanks for the quick feedback\n\nJ\n---------- Forwarded message ----------\nFrom: \"Charles Leifer\" [email protected]\nDate: Jun 21, 2013 7:58 AM\nSubject: Re: [peewee] pwiz not generating foreign key fields? (#207)\nTo: \"coleifer/peewee\" [email protected]\nCc: \"John Matthew\" [email protected]\n\nAre you using MySQL?\n\n—\nReply to this email directly or view it on\nGitHubhttps://github.com/coleifer/peewee/issues/207#issuecomment-19820920\n.\n",
"My associate at work says it may be the type of DB we are running, MyISAM, which doesn't understand true FK's.\n\nSee below:\n\n```\nmysql> SELECT column_name, referenced_table_name, referenced_column_name FROM information_schema.key_column_usage WHERE table_name = \"Tickets\" AND table_schema = DATABASE() AND referenced_table_name IS NOT NULL AND referenced_column_name IS NOT NULL;\nEmpty set (0.00 sec)\n\nmysql> show create table Tickets ;\n+---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+\n| Table | Create Table |\n+---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+\n| Tickets | CREATE TABLE `Tickets` (\n `id` int(11) NOT NULL auto_increment,\n `EffectiveId` int(11) NOT NULL default '0',\n `Queue` int(11) NOT NULL default '0',\n `Type` varchar(16) default NULL,\n `IssueStatement` int(11) NOT NULL default '0',\n `Resolution` int(11) NOT NULL default '0',\n `Owner` int(11) NOT NULL default '0',\n `Subject` varchar(200) default '[no subject]',\n `InitialPriority` int(11) NOT NULL default '0',\n `FinalPriority` int(11) NOT NULL default '0',\n `Priority` int(11) NOT NULL default '0',\n `TimeEstimated` int(11) NOT NULL default '0',\n `TimeWorked` int(11) NOT NULL default '0',\n `Status` varchar(10) default NULL,\n `TimeLeft` int(11) NOT NULL default '0',\n `Told` datetime default NULL,\n `Starts` datetime default NULL,\n `Started` datetime default NULL,\n `Due` datetime default NULL,\n `Resolved` datetime default NULL,\n `LastUpdatedBy` int(11) NOT NULL default '0',\n `LastUpdated` datetime default NULL,\n `Creator` int(11) NOT NULL default '0',\n `Created` datetime default NULL,\n `Disabled` smallint(6) NOT NULL default '0',\n PRIMARY KEY (`id`),\n KEY `Tickets1` (`Queue`,`Status`),\n KEY `Tickets2` (`Owner`),\n KEY `Tickets6` (`EffectiveId`,`Type`),\n KEY `Creator` (`Creator`),\n KEY `Subject` (`Subject`)\n) ENGINE=MyISAM AUTO_INCREMENT=73183 DEFAULT CHARSET=latin1 |\n+---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+\n1 row in set (0.00 sec)\n\nmysql>\n```\n\nI hope this helps. \n\nJ\n",
"Unfortunately, pwiz does not understand how to work with MyISAM. Currently I have no plans for adding this support.\n",
"Charles, thank you for taking the time to look at this. I figured that would be the case.\n\nKeep up the excellent work on peewee, it's a great \"little\" product.\n\nJ\n"
] | 2013-06-18T19:47:50 | 2013-06-24T15:09:03 | 2013-06-24T15:09:03 | NONE | null | First off, love this project, keep it up!
I have a DB with lots of tables, but it's not 'connecting' the FK's.
Here's a sample:
```
describe Tickets
--------------
+-----------------+--------------+------+-----+--------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+--------------+------+-----+--------------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| EffectiveId | int(11) | NO | MUL | 0 | |
| Queue | int(11) | NO | MUL | 0 | |
| Type | varchar(16) | YES | | NULL | |
| IssueStatement | int(11) | NO | | 0 | |
| Resolution | int(11) | NO | | 0 | |
| Owner | int(11) | NO | MUL | 0 | |
| Subject | varchar(200) | YES | MUL | [no subject] | |
| InitialPriority | int(11) | NO | | 0 | |
| FinalPriority | int(11) | NO | | 0 | |
| Priority | int(11) | NO | | 0 | |
| TimeEstimated | int(11) | NO | | 0 | |
| TimeWorked | int(11) | NO | | 0 | |
| Status | varchar(10) | YES | | NULL | |
| TimeLeft | int(11) | NO | | 0 | |
| Told | datetime | YES | | NULL | |
| Starts | datetime | YES | | NULL | |
| Started | datetime | YES | | NULL | |
| Due | datetime | YES | | NULL | |
| Resolved | datetime | YES | | NULL | |
| LastUpdatedBy | int(11) | NO | | 0 | |
| LastUpdated | datetime | YES | | NULL | |
| Creator | int(11) | NO | MUL | 0 | |
| Created | datetime | YES | | NULL | |
| Disabled | smallint(6) | NO | | 0 | |
+-----------------+--------------+------+-----+--------------+----------------+
25 rows in set (0.00 sec)
```
with pwiz's output:
``` python
class Tickets(BaseModel):
created = DateTimeField(null=True, db_column='Created')
creator = IntegerField(db_column='Creator')
disabled = IntegerField(db_column='Disabled')
due = DateTimeField(null=True, db_column='Due')
effectiveid = IntegerField(db_column='EffectiveId')
finalpriority = IntegerField(db_column='FinalPriority')
initialpriority = IntegerField(db_column='InitialPriority')
issuestatement = IntegerField(db_column='IssueStatement')
lastupdated = DateTimeField(null=True, db_column='LastUpdated')
lastupdatedby = IntegerField(db_column='LastUpdatedBy')
owner = IntegerField(db_column='Owner')
priority = IntegerField(db_column='Priority')
queue = IntegerField(db_column='Queue')
resolution = IntegerField(db_column='Resolution')
resolved = DateTimeField(null=True, db_column='Resolved')
started = DateTimeField(null=True, db_column='Started')
starts = DateTimeField(null=True, db_column='Starts')
status = CharField(null=True, db_column='Status')
subject = CharField(null=True, db_column='Subject')
timeestimated = IntegerField(db_column='TimeEstimated')
timeleft = IntegerField(db_column='TimeLeft')
timeworked = IntegerField(db_column='TimeWorked')
told = DateTimeField(null=True, db_column='Told')
type = CharField(null=True, db_column='Type')
class Meta:
db_table = 'Tickets'
```
Any idea how i can get them to match up so I don't have to do the FK's by hand?
thanks
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/207/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/207/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/206 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/206/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/206/comments | https://api.github.com/repos/coleifer/peewee/issues/206/events | https://github.com/coleifer/peewee/issues/206 | 15,615,233 | MDU6SXNzdWUxNTYxNTIzMw== | 206 | Selecting multiple models / naive query | {
"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 | [] | 2013-06-17T03:17:46 | 2013-06-17T03:21:55 | 2013-06-17T03:21:55 | OWNER | null | It appears peewee is not correctly assigning attributes from a related model:
``` python
from peewee import SqliteDatabase, Model, PrimaryKeyField, CharField, \
IntegerField, ForeignKeyField
from playhouse.test_utils import test_database
test_db = SqliteDatabase(':memory:')
class Model1(Model):
id = PrimaryKeyField()
another_id = IntegerField()
field = CharField()
def __str__(self):
return self.__class__.__name__ + '[' + ', '.join(["%s: %s" % (k, v) for k, v in self._data.items()]) + "]"
class Model2(Model):
some_id = IntegerField() # PK
another_id = IntegerField() # PK
field2 = CharField()
def __str__(self):
return self.__class__.__name__ + '[' + ', '.join(["%s: %s" % (k, v) for k, v in self._data.items()]) + "]"
class Meta():
indexes = ((('some_id', 'another_id'), True),)
if __name__ == '__main__':
with test_database(test_db, (Model1, Model2)):
Model1.\
create(id=1, another_id=1, field="example").\
create(id=2, another_id=3, field="example")
Model2.\
create(some_id=1, another_id=1, field2="example2").\
create(some_id=1, another_id=2, field2="example2").\
create(some_id=2, another_id=3, field2="example2")
res = (Model1
.select(Model1, Model2)
.join(Model2, on=(
(Model1.id == Model2.some_id) &
(Model1.another_id == Model2.another_id)
))
.naive())
print res.sql
for a in res:
print a
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/206/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/206/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/205 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/205/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/205/comments | https://api.github.com/repos/coleifer/peewee/issues/205/events | https://github.com/coleifer/peewee/pull/205 | 15,606,271 | MDExOlB1bGxSZXF1ZXN0NjM0NzMxOQ== | 205 | Choices attribute according to documentation | {
"login": "niedbalski",
"id": 821670,
"node_id": "MDQ6VXNlcjgyMTY3MA==",
"avatar_url": "https://avatars.githubusercontent.com/u/821670?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/niedbalski",
"html_url": "https://github.com/niedbalski",
"followers_url": "https://api.github.com/users/niedbalski/followers",
"following_url": "https://api.github.com/users/niedbalski/following{/other_user}",
"gists_url": "https://api.github.com/users/niedbalski/gists{/gist_id}",
"starred_url": "https://api.github.com/users/niedbalski/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/niedbalski/subscriptions",
"organizations_url": "https://api.github.com/users/niedbalski/orgs",
"repos_url": "https://api.github.com/users/niedbalski/repos",
"events_url": "https://api.github.com/users/niedbalski/events{/privacy}",
"received_events_url": "https://api.github.com/users/niedbalski/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I think I will pass on merging this as it consumes the choices iterable once upon field initialization. Rather, I will rely on the documentation.\n",
"OK, perfect.I always prefer the code that dies descriptively\n"
] | 2013-06-16T15:10:06 | 2014-07-06T01:50:58 | 2013-06-17T02:53:00 | CONTRIBUTOR | null | Hello!,
Added a validation for the choices field attribute. I started looking at this issue because WTForms-peewee raised an 'unpack error' using a field declared as Charfield(choices=('OPTION', 'OPTION')) , according to the peewee documentation this must be specified as (value, label) so i added a ValueError exception is the iterable don't follow this specification.
Also i added a test for this field attribute.
Regards
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/205/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/205/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/205",
"html_url": "https://github.com/coleifer/peewee/pull/205",
"diff_url": "https://github.com/coleifer/peewee/pull/205.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/205.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/204 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/204/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/204/comments | https://api.github.com/repos/coleifer/peewee/issues/204/events | https://github.com/coleifer/peewee/issues/204 | 15,497,427 | MDU6SXNzdWUxNTQ5NzQyNw== | 204 | Add NOT IN operator. | {
"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 | [
"If you would like to negate an expression and are using the \"django-style\" lookups, you will need to wrap it in a `DQ` object and use unary negation:\n\n``` python\n\n# this query\n.where(~DQ(foo__in=[list of stuff]))\n\n# translates into this\n-- where NOT foo IN [list of stuff]\n```\n\nUnfortunately, I don't think this helps with your use-case of the flask-peewee rest api. I'm not sure I like the idea of adding NOT IN, but I see your point about the difficulty. Will think about it.\n",
"One possibility is to make the rest operators a superset of the django ones. This seems somewhat principaled. More so than adding it to the DJANGO_MAP.\n",
"Out of interest, why doesn't peewee use Python's `in` operator (i.e., overload `__contains__`) to represent SQL \"x in (1, 2, 3)\" instead of the weird-looking `<<`? This would also work for SQL's NOT IN -- same as Python. Relatedly, it'd be nice if `x == None` (can't use `x is None` fo this) translated to SQL `x IS NULL` to avoid the extra `>>` operator.\n",
"Using `in` and `__contains__` won't work (unfortunately) because python will always convert the return value of contains to a boolean. I'd rather not special-case `==` to handle `NULL` because semantically `IS NULL` is distinct.\n",
"Huh, I didn't know that about `__contains__` -- pity. Fair enough about not special-case `==` -- seems a shame to use a whole operator for this though.\n",
"Just an FYI: I asked about why `__contains__` was like that on Python-Dev, and got [this helpful answer](http://mail.python.org/pipermail/python-dev/2013-July/127297.html) from Nick Coghlan, a Python core dev.\n",
"Thanks @benhoyt I was not aware of the rationale for this behavior.\n",
"@rammie, if you pull the latest peewee and flask-peewee, I have added support for negating expressions in the REST api by prefixing the left-hand lookup with \"-\", so:\n\n```\n/api/user/?username=foo -- users named \"foo\"\n/api/user/?-username=foo -- users *not* named \"foo\"\n```\n\nGive it a try and let me know how it works for you.\n",
"Thanks a lot. I really like the solution. Is legit. I'll play with it a\nlittle and let you know tomorrow. I hope a version bump follows soon.\nOn Jul 21, 2013 7:46 PM, \"Charles Leifer\" [email protected] wrote:\n\n> @rammie https://github.com/rammie, if you pull the latest peewee and\n> flask-peewee, I have added support for negating expressions in the REST api\n> by prefixing the left-hand lookup with \"-\", so:\n> \n> /api/user/?username=foo -- users named \"foo\"\n> /api/user/?-username=foo -- users _not_ named \"foo\"\n> \n> Give it a try and let me know how it works for you.\n> \n> —\n> Reply to this email directly or view it on GitHubhttps://github.com/coleifer/peewee/issues/204#issuecomment-21319460\n> .\n",
"Tried it, works well for my use cases. Thanks!\n\nOn Sun, Jul 21, 2013 at 10:27 PM, Ram Mehta [email protected] wrote:\n\n> Thanks a lot. I really like the solution. Is legit. I'll play with it a\n> little and let you know tomorrow. I hope a version bump follows soon.\n> On Jul 21, 2013 7:46 PM, \"Charles Leifer\" [email protected]\n> wrote:\n> \n> > @rammie https://github.com/rammie, if you pull the latest peewee and\n> > flask-peewee, I have added support for negating expressions in the REST api\n> > by prefixing the left-hand lookup with \"-\", so:\n> > \n> > /api/user/?username=foo -- users named \"foo\"\n> > /api/user/?-username=foo -- users _not_ named \"foo\"\n> > \n> > Give it a try and let me know how it works for you.\n> > \n> > —\n> > Reply to this email directly or view it on GitHubhttps://github.com/coleifer/peewee/issues/204#issuecomment-21319460\n> > .\n"
] | 2013-06-13T10:05:15 | 2013-07-22T15:43:29 | 2013-07-22T02:23:13 | NONE | null | I'm not sure whether to file this in flask_peewee or peewee. But the lack of a not in operator in the DJANGO map prevents such queries from the rest api. Django allows this by using exclude. Adding NOT IN as an operator probably isn't the most elegant fix. But it would mitigate my problem.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/204/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/204/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/203 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/203/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/203/comments | https://api.github.com/repos/coleifer/peewee/issues/203/events | https://github.com/coleifer/peewee/pull/203 | 15,406,685 | MDExOlB1bGxSZXF1ZXN0NjI0OTU0Ng== | 203 | Add sample encoding setting | {
"login": "rcarmo",
"id": 392683,
"node_id": "MDQ6VXNlcjM5MjY4Mw==",
"avatar_url": "https://avatars.githubusercontent.com/u/392683?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/rcarmo",
"html_url": "https://github.com/rcarmo",
"followers_url": "https://api.github.com/users/rcarmo/followers",
"following_url": "https://api.github.com/users/rcarmo/following{/other_user}",
"gists_url": "https://api.github.com/users/rcarmo/gists{/gist_id}",
"starred_url": "https://api.github.com/users/rcarmo/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/rcarmo/subscriptions",
"organizations_url": "https://api.github.com/users/rcarmo/orgs",
"repos_url": "https://api.github.com/users/rcarmo/repos",
"events_url": "https://api.github.com/users/rcarmo/events{/privacy}",
"received_events_url": "https://api.github.com/users/rcarmo/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Thanks @rcarmo!\n",
"Don't mention it. Tell you what, I'll see if I can add more surgical samples like this - I'm using Peewee for a lot of stuff lately, and have all sorts of little recipes... \n\nOn Jun 11, 2013, at 17:04 , Charles Leifer [email protected] wrote:\n\n> Thanks @rcarmo!\n> \n> —\n> Reply to this email directly or view it on GitHub.\n"
] | 2013-06-11T16:02:25 | 2014-07-06T01:51:00 | 2013-06-11T16:04:29 | CONTRIBUTOR | null | This will save non-English speakers hours of puttering around.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/203/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/203/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/203",
"html_url": "https://github.com/coleifer/peewee/pull/203",
"diff_url": "https://github.com/coleifer/peewee/pull/203.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/203.patch",
"merged_at": "2013-06-11T16:04:29"
} |
https://api.github.com/repos/coleifer/peewee/issues/202 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/202/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/202/comments | https://api.github.com/repos/coleifer/peewee/issues/202/events | https://github.com/coleifer/peewee/issues/202 | 15,281,162 | MDU6SXNzdWUxNTI4MTE2Mg== | 202 | Possible unicode issue | {
"login": "rcarmo",
"id": 392683,
"node_id": "MDQ6VXNlcjM5MjY4Mw==",
"avatar_url": "https://avatars.githubusercontent.com/u/392683?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/rcarmo",
"html_url": "https://github.com/rcarmo",
"followers_url": "https://api.github.com/users/rcarmo/followers",
"following_url": "https://api.github.com/users/rcarmo/following{/other_user}",
"gists_url": "https://api.github.com/users/rcarmo/gists{/gist_id}",
"starred_url": "https://api.github.com/users/rcarmo/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/rcarmo/subscriptions",
"organizations_url": "https://api.github.com/users/rcarmo/orgs",
"repos_url": "https://api.github.com/users/rcarmo/repos",
"events_url": "https://api.github.com/users/rcarmo/events{/privacy}",
"received_events_url": "https://api.github.com/users/rcarmo/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"That's interesting... I know that there are some tests that cover unicode functionality. Can you create a testcase to reproduce this bug?\n",
"Erm.. the snippet of code I posted reproduces it on all my machines. That is my testcase, so to speak :)\n\nOn Jun 11, 2013, at 03:48 , Charles Leifer [email protected] wrote:\n\n> That's interesting... I know that there are some tests that cover unicode functionality. Can you create a testcase to reproduce this bug?\n> \n> —\n> Reply to this email directly or view it on GitHub.\n",
"I pushed a testcase and was unable to reproduce. From the traceback it looks like the issue might be happening inside psycopg2. What is the encoding of your connection?\n\n``` python\n\n# here is the encoding I have when running the tests\n>>> test_db.get_conn().encoding\n'UTF8'\n```\n",
"Mine returns 'SQLASCII', which doesn't make sense - I've tried running my code with the psycopg2 unicode extensions enabled (like jokull added a year back in https://github.com/coleifer/peewee/commit/4a2ba5bd528c1ddd40d79cdd10438f3a5c270c4b) and it still fails.\n\nOn Jun 11, 2013, at 15:11 , Charles Leifer [email protected] wrote:\n\n> I pushed a testcase and was unable to reproduce. From the traceback it looks like the issue might be happening inside psycopg2. What is the encoding of your connection?\n> \n> # here is the encoding I have when running the tests\n> \n> > > > test_db.get_conn().encoding\n> > > > 'UTF8'\n> > > > —\n> > > > Reply to this email directly or view it on GitHub.\n",
"Cool, take a look here: http://www.postgresql.org/docs/9.2/static/multibyte.html -- there are a couple solutions:\n- `initdb` when setting up your cluster\n- `createdb` when creating your database\n- `set client encoding`\n",
"Hmm. Perhaps this should be added to the docs? The defaults in Ubuntu and Debian are to start with SQL_ASCII.\n\nAnd your tests probably ought to reflect that, since you're testing against a UTF8 cluster - and hence won't spot the general case... :)\n\nOn Jun 11, 2013, at 16:26 , Charles Leifer [email protected] wrote:\n\n> Cool, take a look here: http://www.postgresql.org/docs/9.2/static/multibyte.html -- there are a couple solutions:\n> \n> initdb when setting up your cluster\n> createdb when creating your database\n> set client encoding\n> —\n> Reply to this email directly or view it on GitHub.\n"
] | 2013-06-07T16:46:10 | 2013-06-11T15:30:43 | 2013-06-11T15:26:04 | CONTRIBUTOR | null | Hello there,
I've been trying to get the following to work right:
<pre>
import os, sys
sys.path.append('../lib')
from peewee import Model, PostgresqlDatabase, CharField
db = PostgresqlDatabase("test")
class Test(Model):
name = CharField(null=False)
class Meta:
database = db
Test.create_table(True)
t = Test.create(name=u'M\u00f6rk Gryning')
</pre>
However, regardless of what I try to do with that unicode string, I always get a traceback similar to this:
<pre>
Traceback (most recent call last):
File "unicode.py", line 15, in <module>
t = Test.create(name=u'M\u00f6rk Gryning')
File "../lib/peewee.py", line 2294, in create
inst.save(force_insert=True)
File "../lib/peewee.py", line 2383, in save
new_pk = insert.execute()
File "../lib/peewee.py", line 1712, in execute
return self.database.last_insert_id(self._execute(), self.model_class)
File "../lib/peewee.py", line 1400, in _execute
return self.database.execute_sql(sql, params, self.require_commit)
File "../lib/peewee.py", line 1811, in execute_sql
res = cursor.execute(sql, params or ())
UnicodeEncodeError: 'ascii' codec can't encode character u'\xf6' in position 1: ordinal not in range(128)
</pre>
This doesn't make much sense to me, since from what I can understand the named argument should still be a Unicode string when it gets to `cursor.execute` - so I'm stumped as to the actual cause.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/202/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/202/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/201 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/201/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/201/comments | https://api.github.com/repos/coleifer/peewee/issues/201/events | https://github.com/coleifer/peewee/issues/201 | 15,269,661 | MDU6SXNzdWUxNTI2OTY2MQ== | 201 | Uppercase table names not parsed correctly | {
"login": "ThomDietrich",
"id": 2870104,
"node_id": "MDQ6VXNlcjI4NzAxMDQ=",
"avatar_url": "https://avatars.githubusercontent.com/u/2870104?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/ThomDietrich",
"html_url": "https://github.com/ThomDietrich",
"followers_url": "https://api.github.com/users/ThomDietrich/followers",
"following_url": "https://api.github.com/users/ThomDietrich/following{/other_user}",
"gists_url": "https://api.github.com/users/ThomDietrich/gists{/gist_id}",
"starred_url": "https://api.github.com/users/ThomDietrich/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/ThomDietrich/subscriptions",
"organizations_url": "https://api.github.com/users/ThomDietrich/orgs",
"repos_url": "https://api.github.com/users/ThomDietrich/repos",
"events_url": "https://api.github.com/users/ThomDietrich/events{/privacy}",
"received_events_url": "https://api.github.com/users/ThomDietrich/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"You can explicitly set the database table name to use:\n\nclass trafficRemaining(MySQLModel):\n customerID = IntegerField(primary_key=True)\n abc = IntegerField()\n\n```\nclass Meta:\n db_table = 'trafficRemaining'\n```\n\nOn Fri, Jun 7, 2013 at 7:24 AM, ThomDietrich [email protected]:\n\n> Hey there,\n> I'm fresh to peewee and am trying to access existing mysql tables of mine.\n> It seems to me as peewee has problems with uppercase letters in table\n> names...\n> \n> My system: Ubuntu 12.04.2, mysql 14.14, python 2.7, peewee 2.1.2\n> \n> class ratelist(MySQLModel):\n> prefix = CharField(primary_key=True)\n> name = CharField()\n> \n> class trafficRemaining(MySQLModel):\n> customerID = IntegerField(primary_key=True)\n> abc = IntegerField()\n> \n> print ratelist.get()\n> <**main**.ratelist object at 0x8a1a56c>\n> \n> print trafficRemaining.get()\n> File \"/usr/local/lib/python2.7/dist-packages/peewee.py\", line 2299, in get\n> return sq.get()\n> File \"/usr/local/lib/python2.7/dist-packages/peewee.py\", line 1602, in get\n> return clone.execute().next()\n> File \"/usr/local/lib/python2.7/dist-packages/peewee.py\", line 1637, in execute\n> self._qr = ResultWrapper(self.model_class, self._execute(), query_meta)\n> File \"/usr/local/lib/python2.7/dist-packages/peewee.py\", line 1395, in _execute\n> return self.database.execute_sql(sql, params, self.require_commit)\n> File \"/usr/local/lib/python2.7/dist-packages/peewee.py\", line 1805, in execute_sql\n> res = cursor.execute(sql, params or ())\n> File \"/usr/lib/python2.7/dist-packages/MySQLdb/cursors.py\", line 174, in execute\n> self.errorhandler(self, exc, value)\n> File \"/usr/lib/python2.7/dist-packages/MySQLdb/connections.py\", line 36, in defaulterrorhandler\n> raise errorclass, errorvalue\n> _mysql_exceptions.ProgrammingError: (1146, \"Table 'mydatabase.trafficremaining' doesn't exist\")\n> \n> As you can see, \"ratelist\" is accessable but \"trafficRemaining\" is\n> converted to lowercase and not found by mysql.\n> \n> Thanks for your work! Greetings\n> \n> —\n> Reply to this email directly or view it on GitHubhttps://github.com/coleifer/peewee/issues/201\n> .\n",
"Hey, thanks for your response.\nI think you understood me wrong. The database name is set correctly (in my case \"mydatabase\") and works with table \"ratelist\" but not with \"trafficRemaining\"...\nIn my previous message, pay attention to the last errorline: \"Table 'mydatabase.trafficremaining' doesn't exist\" - this seems to me like a uppercase/lowercase problem...\n-Thomas\n",
"Try the code. It sets the db_table not the database.\nOn Jun 10, 2013 7:43 AM, \"ThomDietrich\" [email protected] wrote:\n\n> Hey, thanks for your response.\n> I think you understood me wrong. The database name is set correctly (in my\n> case \"mydatabase\") and works with table \"ratelist\" but not with\n> \"trafficRemaining\"...\n> In my previous message, pay attention to the last errorline: \"Table\n> 'mydatabase.trafficremaining' doesn't exist\" - this seems to me like a\n> uppercase/lowercase problem...\n> -Thomas\n> \n> —\n> Reply to this email directly or view it on GitHubhttps://github.com/coleifer/peewee/issues/201#issuecomment-19196087\n> .\n",
"Ah now I see what you did there. Thanks! It works.\nHowever, this does seem like a workaround but not like a the real solution and should be fixed, right?\n\nBest wishes and thanks for your work, Thomas\n",
"> However, this does seem like a workaround but not like a the real solution and should be fixed, right?\n\nI'm not sure what you mean \"the real solution\". Did you use `pwiz` to auto-generate your models and it did not create the correct models?\n"
] | 2013-06-07T12:24:57 | 2013-06-11T02:43:16 | 2013-06-11T02:43:16 | NONE | null | Hey there,
I'm fresh to peewee and am trying to access existing mysql tables of mine.
It seems to me as peewee has problems with uppercase letters in table names...
My system: Ubuntu 12.04.2, mysql 14.14, python 2.7, peewee 2.1.2
```
class ratelist(MySQLModel):
prefix = CharField(primary_key=True)
name = CharField()
class trafficRemaining(MySQLModel):
customerID = IntegerField(primary_key=True)
abc = IntegerField()
print ratelist.get()
<__main__.ratelist object at 0x8a1a56c>
print trafficRemaining.get()
File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 2299, in get
return sq.get()
File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 1602, in get
return clone.execute().next()
File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 1637, in execute
self._qr = ResultWrapper(self.model_class, self._execute(), query_meta)
File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 1395, in _execute
return self.database.execute_sql(sql, params, self.require_commit)
File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 1805, in execute_sql
res = cursor.execute(sql, params or ())
File "/usr/lib/python2.7/dist-packages/MySQLdb/cursors.py", line 174, in execute
self.errorhandler(self, exc, value)
File "/usr/lib/python2.7/dist-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
raise errorclass, errorvalue
_mysql_exceptions.ProgrammingError: (1146, "Table 'mydatabase.trafficremaining' doesn't exist")
```
As you can see, "ratelist" is accessable but "trafficRemaining" is converted to lowercase and not found by mysql.
Thanks for your work! Greetings
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/201/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/201/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/200 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/200/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/200/comments | https://api.github.com/repos/coleifer/peewee/issues/200/events | https://github.com/coleifer/peewee/issues/200 | 15,135,887 | MDU6SXNzdWUxNTEzNTg4Nw== | 200 | Log sql command before it is executed instead of after | {
"login": "kwellman",
"id": 279549,
"node_id": "MDQ6VXNlcjI3OTU0OQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/279549?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/kwellman",
"html_url": "https://github.com/kwellman",
"followers_url": "https://api.github.com/users/kwellman/followers",
"following_url": "https://api.github.com/users/kwellman/following{/other_user}",
"gists_url": "https://api.github.com/users/kwellman/gists{/gist_id}",
"starred_url": "https://api.github.com/users/kwellman/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/kwellman/subscriptions",
"organizations_url": "https://api.github.com/users/kwellman/orgs",
"repos_url": "https://api.github.com/users/kwellman/repos",
"events_url": "https://api.github.com/users/kwellman/events{/privacy}",
"received_events_url": "https://api.github.com/users/kwellman/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2013-06-04T19:15:08 | 2013-06-05T03:19:21 | 2013-06-05T03:19:21 | NONE | null | In the execute_sql function, logger.debug((sql, params)) is called after the sql command is executed.
Why not call it before so that if the sql command raises an exception the exact command that was executed has already been logged? This makes things easier to debug.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/200/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/200/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/199 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/199/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/199/comments | https://api.github.com/repos/coleifer/peewee/issues/199/events | https://github.com/coleifer/peewee/issues/199 | 15,051,806 | MDU6SXNzdWUxNTA1MTgwNg== | 199 | MySQL support for Python 3 | {
"login": "davidak",
"id": 91113,
"node_id": "MDQ6VXNlcjkxMTEz",
"avatar_url": "https://avatars.githubusercontent.com/u/91113?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/davidak",
"html_url": "https://github.com/davidak",
"followers_url": "https://api.github.com/users/davidak/followers",
"following_url": "https://api.github.com/users/davidak/following{/other_user}",
"gists_url": "https://api.github.com/users/davidak/gists{/gist_id}",
"starred_url": "https://api.github.com/users/davidak/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/davidak/subscriptions",
"organizations_url": "https://api.github.com/users/davidak/orgs",
"repos_url": "https://api.github.com/users/davidak/repos",
"events_url": "https://api.github.com/users/davidak/events{/privacy}",
"received_events_url": "https://api.github.com/users/davidak/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Sorry to hear you had trouble with mysqldb. I'm not familiar with the Oracle driver, but there is a python-3 compatible pure python driver which will work automatically with peewee:\n\nhttps://github.com/petehunt/PyMySQL\n\nThe MySQLdb project does not yet support python 3, and in fact peewee just got py3k support a month or two ago. I will add a note to the mysql section of the docs indicating this. To fix your error, uninstall the mysqldb package and try pymysql. Good luck!\n",
"Ok, i tested it with pymysql, but get also an error.\nhttps://github.com/petehunt/PyMySQL/issues/151\n\ni have reported it to the developer, but don't get a reaction.\nin his blog he announced, that he will not maintain PyMySQL further.\nhttp://www.petehunt.net/blog/?p=49\n\ni tested SQLAlchemy with the MySQL Connector and it works.\ntheir SQL Expression Language is nice to write and i don't see the advantage of an orm in my small project.\n\nso im using that now and next time i test it on my server before programming 2 nights and it don't work.\nmaybe you can support MySQL Connector if you have the time, but i don't need it anymore.\n",
"PyMySQL is under active development again and it supports Python 3:\n\nhttps://github.com/PyMySQL/PyMySQL\n\nI'm using it along with peewee and had no problems so far.\n",
"@lecram great to hear and thanks for fixing that bug.\n"
] | 2013-06-03T05:19:34 | 2013-09-22T00:02:48 | 2013-06-03T12:25:24 | NONE | null | the last release of MySQLdb is from 02.11.2012 (MySQLdb-1.2.4 release candidate 1) and it doesn't support python 3.
maybe you or someone else have the time to let peewee support another MySQL Driver?
This one supports Python 3 already and is developed by Oracle:
https://pypi.python.org/pypi/mysql-connector-python
its very bad for me. i coded the whole night and now if i want to deploy my great app i get lots of errors.
you say that peewee supports python3 and mysql. too bad not at the same time.
so i will switch to sqlalchemy with mysql-connector driver.
or is there a quick solution to get it work for me?
```
File "./import.py", line 34, in erstelle_tabellen
mysql.connect()
File "/home/davidak/websites/satzgenerator/lib/python3.2/site-packages/peewee.py", line 1756, in connect
self.__local.conn = self._connect(self.database, **self.connect_kwargs)
File "/home/davidak/websites/satzgenerator/lib/python3.2/site-packages/peewee.py", line 2011, in _connect
return mysql.connect(db=database, **conn_kwargs)
File "/home/davidak/websites/satzgenerator/lib/python3.2/site-packages/MySQLdb/__init__.py", line 80, in Connect
from MySQLdb.connections import Connection
File "/home/davidak/websites/satzgenerator/lib/python3.2/site-packages/MySQLdb/connections.py", line 36
raise errorclass, errorvalue
^
SyntaxError: invalid syntax
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/199/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/199/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/198 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/198/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/198/comments | https://api.github.com/repos/coleifer/peewee/issues/198/events | https://github.com/coleifer/peewee/issues/198 | 15,030,007 | MDU6SXNzdWUxNTAzMDAwNw== | 198 | Datetime fields with timezone | {
"login": "rcarmo",
"id": 392683,
"node_id": "MDQ6VXNlcjM5MjY4Mw==",
"avatar_url": "https://avatars.githubusercontent.com/u/392683?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/rcarmo",
"html_url": "https://github.com/rcarmo",
"followers_url": "https://api.github.com/users/rcarmo/followers",
"following_url": "https://api.github.com/users/rcarmo/following{/other_user}",
"gists_url": "https://api.github.com/users/rcarmo/gists{/gist_id}",
"starred_url": "https://api.github.com/users/rcarmo/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/rcarmo/subscriptions",
"organizations_url": "https://api.github.com/users/rcarmo/orgs",
"repos_url": "https://api.github.com/users/rcarmo/repos",
"events_url": "https://api.github.com/users/rcarmo/events{/privacy}",
"received_events_url": "https://api.github.com/users/rcarmo/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"It is fairly straightforward to add support for custom fields: http://peewee.readthedocs.org/en/latest/peewee/models.html#creating-a-custom-field\n\nI also added a `DateTimeTZField` to the `playhouse.postgres_ext` module.\n",
"Awesome, thanks!\n"
] | 2013-06-01T17:31:44 | 2013-06-05T15:40:20 | 2013-06-03T00:43:47 | CONTRIBUTOR | null | This might be just me, but I cannot seem to be able to create DateTime fields with a timezone under Postgres. The [docs](http://www.postgresql.org/docs/9.1/static/datatype-datetime.html) state tacking on "with time zone" to the field spec should do it, but I haven't been able to figure out how to specify that in a Peewee model successfully.
Could you please check if that is possible and, if so, add an example for that to ReadTheDocs?
Thanks!
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/198/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/198/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/197 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/197/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/197/comments | https://api.github.com/repos/coleifer/peewee/issues/197/events | https://github.com/coleifer/peewee/issues/197 | 14,983,802 | MDU6SXNzdWUxNDk4MzgwMg== | 197 | Field type CharField limited to 255 characters. | {
"login": "dstruck",
"id": 2195318,
"node_id": "MDQ6VXNlcjIxOTUzMTg=",
"avatar_url": "https://avatars.githubusercontent.com/u/2195318?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/dstruck",
"html_url": "https://github.com/dstruck",
"followers_url": "https://api.github.com/users/dstruck/followers",
"following_url": "https://api.github.com/users/dstruck/following{/other_user}",
"gists_url": "https://api.github.com/users/dstruck/gists{/gist_id}",
"starred_url": "https://api.github.com/users/dstruck/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/dstruck/subscriptions",
"organizations_url": "https://api.github.com/users/dstruck/orgs",
"repos_url": "https://api.github.com/users/dstruck/repos",
"events_url": "https://api.github.com/users/dstruck/events{/privacy}",
"received_events_url": "https://api.github.com/users/dstruck/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Unfortunately, Pwiz does not introspect the size the a VARCHAR field.\n\nAdditionally, in order to not break compatibility with older versions of peewee, the `max_length` attribute defaults to `255`. So the following are equivalent:\n\n``` python\n\nfoo = CharField()\nbar = CharField(max_length=255)\n```\n\nIf you would like to use 3000 characters:\n\n``` python\nbaz = CharField(max_length=3000)\n```\n\nOr even better,\n\n``` python\nbaz = TextField()\n```\n",
"Yes, that's what I did finally (CharField to TextField).\n\nIt might be an idea to avert the user that the values have been cut off. Maybe raise an exception?\n",
"> Maybe raise an exception?\n\nThat seems like a good plan. Thanks, and sorry for the confusion.\n"
] | 2013-05-31T08:42:56 | 2013-06-03T12:29:56 | 2013-06-02T20:57:28 | NONE | null | The field type "CharField" gets truncated to 255 characters. You can define VARCHAR fields in PostgreSQL of size bigger then 255.
Maybe one could raise an exception if a value gets cut off?
Test case:
``` python
'''
-- create test table in postgresql
CREATE TABLE sample(
id SERIAL PRIMARY KEY
,data VARCHAR(3000)
);
'''
################################################################################
# classes generated by pwiz.py
# pwiz.py -e postgresql test > model.txt
from peewee import *
database = PostgresqlDatabase('test', **{})
class UnknownFieldType(object):
pass
class BaseModel(Model):
class Meta:
database = database
class Sample(BaseModel):
data = CharField(null=True)
class Meta:
db_table = 'sample'
################################################################################
# test
sequence = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."
print "string length before submission:",len(sequence)
# save data in database
entry = Sample.create(data=sequence)
# retrieve data back from database
entry_db = Sample.get(Sample.id == entry.id)
print "string length in database after submission:",len(entry_db.data)
'''
Output:
string length before submission: 574
string length in database after submission: 255
'''
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/197/reactions",
"total_count": 1,
"+1": 1,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/197/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/196 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/196/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/196/comments | https://api.github.com/repos/coleifer/peewee/issues/196/events | https://github.com/coleifer/peewee/issues/196 | 14,968,158 | MDU6SXNzdWUxNDk2ODE1OA== | 196 | Restore SQLite Full Text Search Support | {
"login": "wearpants",
"id": 505344,
"node_id": "MDQ6VXNlcjUwNTM0NA==",
"avatar_url": "https://avatars.githubusercontent.com/u/505344?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/wearpants",
"html_url": "https://github.com/wearpants",
"followers_url": "https://api.github.com/users/wearpants/followers",
"following_url": "https://api.github.com/users/wearpants/following{/other_user}",
"gists_url": "https://api.github.com/users/wearpants/gists{/gist_id}",
"starred_url": "https://api.github.com/users/wearpants/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/wearpants/subscriptions",
"organizations_url": "https://api.github.com/users/wearpants/orgs",
"repos_url": "https://api.github.com/users/wearpants/repos",
"events_url": "https://api.github.com/users/wearpants/events{/privacy}",
"received_events_url": "https://api.github.com/users/wearpants/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"It's back! 0519ac68246a3a73aca9e653c1841183642061fd\n\nI mostly upgraded this from the old code, and still have some cleanups planned so be warned, the API may change a bit!\n"
] | 2013-05-30T23:58:51 | 2013-06-04T13:51:03 | 2013-06-04T13:51:03 | NONE | null | There [used to be](http://charlesleifer.com/blog/using-advanced-database-features-with-peewee-a-python-orm/) support for FTS3/4 in SQlite, but it went away some time.
Bring it back, for great justice!
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/196/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/196/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/195 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/195/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/195/comments | https://api.github.com/repos/coleifer/peewee/issues/195/events | https://github.com/coleifer/peewee/pull/195 | 14,755,717 | MDExOlB1bGxSZXF1ZXN0NTkzMDI4Nw== | 195 | add connections pool support | {
"login": "beanyoung",
"id": 973789,
"node_id": "MDQ6VXNlcjk3Mzc4OQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/973789?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/beanyoung",
"html_url": "https://github.com/beanyoung",
"followers_url": "https://api.github.com/users/beanyoung/followers",
"following_url": "https://api.github.com/users/beanyoung/following{/other_user}",
"gists_url": "https://api.github.com/users/beanyoung/gists{/gist_id}",
"starred_url": "https://api.github.com/users/beanyoung/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/beanyoung/subscriptions",
"organizations_url": "https://api.github.com/users/beanyoung/orgs",
"repos_url": "https://api.github.com/users/beanyoung/repos",
"events_url": "https://api.github.com/users/beanyoung/events{/privacy}",
"received_events_url": "https://api.github.com/users/beanyoung/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Interesting, I had not heard of dbutils. Thanks for sharing this!\n\nRegarding merging this, a third-party library dependency is not something I want to add to peewee. It might work better as a module in `playhouse`, though -- this is where I've been buliding little extensions to peewee. Another note, if you're wanting to merge in new functionality for peewee, I also like there to be tests and documentation.\n\nThanks again!\n"
] | 2013-05-25T09:31:02 | 2014-07-05T13:10:26 | 2013-05-31T04:49:36 | NONE | null | The connections pool is based on DBUtils and it works fine for me except that count() method of SelectQuery always return 0. But I can get the count with
``` python
Foo.select(fn.Count(Foo.id).alias('count')).get().count
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/195/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/195/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/195",
"html_url": "https://github.com/coleifer/peewee/pull/195",
"diff_url": "https://github.com/coleifer/peewee/pull/195.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/195.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/194 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/194/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/194/comments | https://api.github.com/repos/coleifer/peewee/issues/194/events | https://github.com/coleifer/peewee/issues/194 | 14,639,281 | MDU6SXNzdWUxNDYzOTI4MQ== | 194 | Model.create() doesn't set id field for BigIntegerField primary key | {
"login": "rudyryk",
"id": 4500,
"node_id": "MDQ6VXNlcjQ1MDA=",
"avatar_url": "https://avatars.githubusercontent.com/u/4500?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/rudyryk",
"html_url": "https://github.com/rudyryk",
"followers_url": "https://api.github.com/users/rudyryk/followers",
"following_url": "https://api.github.com/users/rudyryk/following{/other_user}",
"gists_url": "https://api.github.com/users/rudyryk/gists{/gist_id}",
"starred_url": "https://api.github.com/users/rudyryk/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/rudyryk/subscriptions",
"organizations_url": "https://api.github.com/users/rudyryk/orgs",
"repos_url": "https://api.github.com/users/rudyryk/repos",
"events_url": "https://api.github.com/users/rudyryk/events{/privacy}",
"received_events_url": "https://api.github.com/users/rudyryk/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Thanks glad you like the library!\n\nUnfortunately, peewee's `PrimaryKeyField` is the only field that will handle auto-incrementing primary keys. If you want to use the BigIntegerField as an auto-incrementing primary key you will need to create a custom field type (probably by subclassing `PrimaryKeyField`):\n\nhttp://peewee.readthedocs.org/en/latest/peewee/models.html#creating-a-custom-field\n\nHowever this technique will not work with SQLite, which looks for columns typed \"INTEGER PRIMARY KEY\" and will use these columns to replace the native `rowid`: http://www.sqlite.org/autoinc.html -- Since the column we'd be adding would be BIGINT PRIMARY KEY Sqlite does not seem to auto-generate the ID (tested this locally).\n\nAlso, I'm also pretty sure that SQLite does not actually treat bigint any different than a regular integer.\n\nThis looks like it has some info on the topic: http://sqlite.1065341.n5.nabble.com/Impossible-to-declare-field-type-BIGINT-PRIMARY-KEY-td44651.html\n\nIf you are using something like Postgresql, you _can_ use a bigint, but you will need to create and specify a sequence to use to auto-generate the IDs. Postgres will auto-create the sequence for `serial` columns, but if you use a bigint you will need to create the sequence by hand.\n"
] | 2013-05-22T18:56:54 | 2013-05-23T14:59:55 | 2013-05-23T14:59:55 | NONE | null | Hi! Peewee is awesome lib! :)
It sees there's an issue with BigIntegerField as primary key.
I define my model like that:
```
import peewee
db = peewee.SqliteDatabase('test.db')
class User(peewee.Model):
id = peewee.BigIntegerField(primary_key=True)
token = peewee.CharField(max_length=100, default='')
class Meta:
database = db
```
Then I test create method:
```
>>> User.create_table()
>>> user = User.create(token="123")
>>> user.id
>>>
>>> user = User.get(token="123")
>>> user.id
1
```
Instantiating `User(token="123")` and then `save()` results the same.
If I remove line `id = peewee.BigIntegerField(primary_key=True)` everything works fine. I've used Python 3.3.1, may be it's only py3 issue, not sure about that.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/194/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/194/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/193 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/193/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/193/comments | https://api.github.com/repos/coleifer/peewee/issues/193/events | https://github.com/coleifer/peewee/issues/193 | 14,250,763 | MDU6SXNzdWUxNDI1MDc2Mw== | 193 | db.connect() resets everything for in-memory sqlite | {
"login": "hasenj",
"id": 31078,
"node_id": "MDQ6VXNlcjMxMDc4",
"avatar_url": "https://avatars.githubusercontent.com/u/31078?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/hasenj",
"html_url": "https://github.com/hasenj",
"followers_url": "https://api.github.com/users/hasenj/followers",
"following_url": "https://api.github.com/users/hasenj/following{/other_user}",
"gists_url": "https://api.github.com/users/hasenj/gists{/gist_id}",
"starred_url": "https://api.github.com/users/hasenj/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/hasenj/subscriptions",
"organizations_url": "https://api.github.com/users/hasenj/orgs",
"repos_url": "https://api.github.com/users/hasenj/repos",
"events_url": "https://api.github.com/users/hasenj/events{/privacy}",
"received_events_url": "https://api.github.com/users/hasenj/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"The logic to open and close connections to the database does exactly that -- opens or closes a connection. That is a library operation and one that will not change or be special-cased. If in your application's request setup/teardown you are opening and closing connections, but would like to no-op while testing with an in-memory db, that seems to me like an application operation. It also sounds like your solution is clean, obvious and works well.\n\nLet me know if I'm not fully understanding the issue.\n",
"> Let me know if I'm not fully understanding the issue.\n\nHm, well perhaps I'm the one not understanding the issue.\n\nI was expecting `db.connect` to _renew_ connection if it was lost/gone, but not really do anything if the connection is already active. With sqlite's in-memory db, the 'connection' so to speak is probably already active (I'm not sure if I really understand what a connection actually means in this case), hence I wasn't expecting it to restart anything.\n",
"@hasenj -- `connect` will explicitly open a connection. If you want to check the state, call `db.is_closed`. Sqlite's in-memory database is unusual in that all data is stored per-connection, so if you want to use it you have to be careful w/your connection handling. I think that falls more under the scope of your application than the scope of peewee itself. Apologies if this was confusing.\n",
"Thanks! That clears it up!\n\n> Apologies if this was confusing.\n\nNot at all!\n",
"I've just run into this issue. I'm not explicitly calling connect() anywhere so I can't figure out why it's happening\n",
"> I've just run into this issue. I'm not explicitly calling connect() anywhere so I can't figure out why it's happening\n\nA connection is opened the first time a query is run, if a connection is not opened already.\n"
] | 2013-05-13T08:47:39 | 2014-10-06T00:17:04 | 2013-05-13T13:25:21 | NONE | null | This is problematic for unit tests.
I usually have something like:
``` python
@app.before_request
def before_request():
db.connect()
```
because mysql connection dies out after a while and needs to be renewed all the time.
I also have `db.connect()` for the code the initializes the db and creates tables
But if the db is `Sqlite(':memory:')`, then db.connect() resets it, clears it out; all the data that's been written is erased. Tables don't exist anymore.
Typical pattern in unit testing:
- setup the app with `app.testing = True`
- setup the db to use sqlite's in-memory db
- initialize db (create tables, etc)
- make requests
Requests will fail because `db.connect()` erases all the tables.
Also, worse, in my case I have an unorthodox setup where I have several models spread out across several python modules, each module has its own `db_init()` function which calls `db.connect()` at the top.
My workaround is to use a function call `db_connect()` instead, and make it no-op in testing:
``` python
def db_connect():
db.connect()
if app.testing:
# calling db.connect() on an in-memory sqlite database
# resets everything!
def db_connect():
pass
```
But I think peewee should do this itself. I think `db.connect()` should be a no-op for sqlite's in-memory db.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/193/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/193/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/192 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/192/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/192/comments | https://api.github.com/repos/coleifer/peewee/issues/192/events | https://github.com/coleifer/peewee/issues/192 | 14,231,281 | MDU6SXNzdWUxNDIzMTI4MQ== | 192 | Incorrect SQL params in order_by expression | {
"login": "jamorton",
"id": 18852,
"node_id": "MDQ6VXNlcjE4ODUy",
"avatar_url": "https://avatars.githubusercontent.com/u/18852?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/jamorton",
"html_url": "https://github.com/jamorton",
"followers_url": "https://api.github.com/users/jamorton/followers",
"following_url": "https://api.github.com/users/jamorton/following{/other_user}",
"gists_url": "https://api.github.com/users/jamorton/gists{/gist_id}",
"starred_url": "https://api.github.com/users/jamorton/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/jamorton/subscriptions",
"organizations_url": "https://api.github.com/users/jamorton/orgs",
"repos_url": "https://api.github.com/users/jamorton/repos",
"events_url": "https://api.github.com/users/jamorton/events{/privacy}",
"received_events_url": "https://api.github.com/users/jamorton/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Thanks!\n"
] | 2013-05-12T06:20:12 | 2013-05-12T16:20:28 | 2013-05-12T15:57:18 | NONE | null | ```
Player.select().order_by(Player.elo * 5)
```
printing the SQL:
```
('SELECT t1."id", t1."created_at", t1."last_modified", t1."wins_t", t1."wins_z", t1."wins_p", t1."losses_t", t1."losses_z", t1."losses_p", t1."username", t1."race", t1."elo" FROM "player" AS t1 ORDER BY (t1."elo" * ?)', [])
```
error:
```
Traceback (most recent call last):
File "manage.py", line 43, in <module>
func(sys.argv[2:])
File "manage.py", line 25, in cmd_test
for k in Player.winrate_order():
File "/Users/jonanin/dev/sc2site/env/lib/python2.7/site-packages/peewee.py", line 1563, in __iter__
return iter(self.execute())
File "/Users/jonanin/dev/sc2site/env/lib/python2.7/site-packages/peewee.py", line 1556, in execute
self._qr = ResultWrapper(self.model_class, self._execute(), query_meta)
File "/Users/jonanin/dev/sc2site/env/lib/python2.7/site-packages/peewee.py", line 1314, in _execute
return self.database.execute_sql(sql, params, self.require_commit)
File "/Users/jonanin/dev/sc2site/env/lib/python2.7/site-packages/peewee.py", line 1721, in execute_sql
res = cursor.execute(sql, params or ())
sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 1, and there are 0 supplied.
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/192/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/192/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/191 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/191/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/191/comments | https://api.github.com/repos/coleifer/peewee/issues/191/events | https://github.com/coleifer/peewee/issues/191 | 13,991,362 | MDU6SXNzdWUxMzk5MTM2Mg== | 191 | No transactions support for MySQL | {
"login": "haykinson",
"id": 31075,
"node_id": "MDQ6VXNlcjMxMDc1",
"avatar_url": "https://avatars.githubusercontent.com/u/31075?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/haykinson",
"html_url": "https://github.com/haykinson",
"followers_url": "https://api.github.com/users/haykinson/followers",
"following_url": "https://api.github.com/users/haykinson/following{/other_user}",
"gists_url": "https://api.github.com/users/haykinson/gists{/gist_id}",
"starred_url": "https://api.github.com/users/haykinson/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/haykinson/subscriptions",
"organizations_url": "https://api.github.com/users/haykinson/orgs",
"repos_url": "https://api.github.com/users/haykinson/repos",
"events_url": "https://api.github.com/users/haykinson/events{/privacy}",
"received_events_url": "https://api.github.com/users/haykinson/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"If you are using MySQL first be sure you are using InnoDB, as MyISAM does not support transactions:\n\nhttp://dev.mysql.com/doc/refman/5.0/en/ansi-diff-transactions.html\n\nSecondly, peewee will not explicitly execute 'begin', 'commit' SQL -- rather it will call the appropriate methods on the db driver. For example `database.commit()`, `database.rollback()`.\n",
"which is much better for peewee transaction:\ndatabase.begin, database.commit()\nvs\nwith database.transaction:\n",
"It doesn't matter, whichever you prefer.\n",
"Thanks! \nAnother question:\ndid peewee place objects into cache for later use?\nthat means get a object from database at the first time and put it into cache, later will get from cache if it exists in cache. \n",
"Peewee will cache the results of select queries so that multiple iterations do not cause multiple queries, but other than that there is no caching.\n\n@bakerchen -- if you have questions, for future reference, please use either the [google group](http://groups.google.com/group/peewee-orm) or the #peewee channel on freenode.\n"
] | 2013-05-06T07:42:34 | 2014-10-27T15:56:11 | 2013-05-06T14:34:26 | NONE | null | As far as I can tell, peewee just toggles autocommit on and off for transaction support. This is not really enough -- you need the START TRANSACTION / COMMIT / ROLLBACK commands issued too.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/191/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/191/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/190 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/190/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/190/comments | https://api.github.com/repos/coleifer/peewee/issues/190/events | https://github.com/coleifer/peewee/pull/190 | 13,963,963 | MDExOlB1bGxSZXF1ZXN0NTUzMTE1MA== | 190 | Added an example for postgresql array type custom field in model docs | {
"login": "diffused",
"id": 32428,
"node_id": "MDQ6VXNlcjMyNDI4",
"avatar_url": "https://avatars.githubusercontent.com/u/32428?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/diffused",
"html_url": "https://github.com/diffused",
"followers_url": "https://api.github.com/users/diffused/followers",
"following_url": "https://api.github.com/users/diffused/following{/other_user}",
"gists_url": "https://api.github.com/users/diffused/gists{/gist_id}",
"starred_url": "https://api.github.com/users/diffused/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/diffused/subscriptions",
"organizations_url": "https://api.github.com/users/diffused/orgs",
"repos_url": "https://api.github.com/users/diffused/repos",
"events_url": "https://api.github.com/users/diffused/events{/privacy}",
"received_events_url": "https://api.github.com/users/diffused/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Dang, does that \"just work\" ?\n",
"So you are missing code to register the field with the database class -- db_field should be \"textarray\" and then you register the type \"textarray\" with \"Text[]\".\n\nI tested this myself and got it working, but because peewee doesn't support (yet) any interesting array operations, I am not going to include this example for now as it might lead people to believe that peewee supports PG array operations.\n",
"Cheers for the tip. Yeah was pretty neat it just worked. \nLooking forward to the updates. \n"
] | 2013-05-04T12:56:04 | 2014-07-06T01:51:03 | 2013-05-04T13:39:24 | NONE | null | Thought this might help in the docs.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/190/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/190/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/190",
"html_url": "https://github.com/coleifer/peewee/pull/190",
"diff_url": "https://github.com/coleifer/peewee/pull/190.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/190.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/189 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/189/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/189/comments | https://api.github.com/repos/coleifer/peewee/issues/189/events | https://github.com/coleifer/peewee/issues/189 | 13,956,863 | MDU6SXNzdWUxMzk1Njg2Mw== | 189 | TypeError when inspecting a MySQL DB | {
"login": "erkurita",
"id": 240697,
"node_id": "MDQ6VXNlcjI0MDY5Nw==",
"avatar_url": "https://avatars.githubusercontent.com/u/240697?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/erkurita",
"html_url": "https://github.com/erkurita",
"followers_url": "https://api.github.com/users/erkurita/followers",
"following_url": "https://api.github.com/users/erkurita/following{/other_user}",
"gists_url": "https://api.github.com/users/erkurita/gists{/gist_id}",
"starred_url": "https://api.github.com/users/erkurita/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/erkurita/subscriptions",
"organizations_url": "https://api.github.com/users/erkurita/orgs",
"repos_url": "https://api.github.com/users/erkurita/repos",
"events_url": "https://api.github.com/users/erkurita/events{/privacy}",
"received_events_url": "https://api.github.com/users/erkurita/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Thanks for reporting!\n",
"@coleifer, I guess that's more elegant (and solves the problem too):\n\n```\ndiff --git a/pwiz.py b/pwiz.py\nindex d20ebf5..5c61d21 100755\n--- a/pwiz.py\n+++ b/pwiz.py\n@@ -308,8 +308,8 @@ def introspect(db, schema=None):\n for table in tables:\n col_meta[table] = {}\n for column, rel_table, rel_pk in table_fks[table]:\n- models[table][column][0] = ForeignKeyField\n- models[rel_table][rel_pk][0] = PrimaryKeyField\n+ models[table][column] = (ForeignKeyField, models[table][column][1])\n+ models[rel_table][rel_pk] = (PrimaryKeyField, models[rel_table][rel_pk][1])\n if rel_table == table:\n ttm = \"'self'\"\n else:\n```\n"
] | 2013-05-03T23:31:43 | 2013-05-04T13:32:34 | 2013-05-04T00:16:03 | NONE | null | I'm getting the following error when executing this command:
```
python pwiz.py -u root --password="<password>" -e mysql elecciones_2013 > ~/schema_elecciones.py
```
The error is:
```
Traceback (most recent call last):
File "pwiz.py", line 417, in <module>
print_models(options.engine, database, tables, **connect)
File "pwiz.py", line 332, in print_models
models, table_to_model, table_fks, col_meta = introspect(db, schema)
File "pwiz.py", line 311, in introspect
models[table][column][0] = ForeignKeyField
TypeError: 'tuple' object does not support item assignment
```
I changed the following line and it worked just fine. Here it is in diff:
```
diff --git i/pwiz.py w/pwiz.py
index d20ebf5..1ff2db7 100755
--- i/pwiz.py
+++ w/pwiz.py
@@ -171,7 +171,7 @@ class MySQLDB(DB):
def get_columns(self, table):
curs = self.conn.execute_sql('select * from `%s` limit 1' % table)
return dict(
- [r[0], (self.reverse_mapping.get(r[1], UnknownFieldType), r[6])]
+ [r[0], [self.reverse_mapping.get(r[1], UnknownFieldType), r[6]]]
for r in curs.description)
def get_foreign_keys(self, table):
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/189/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/189/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/188 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/188/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/188/comments | https://api.github.com/repos/coleifer/peewee/issues/188/events | https://github.com/coleifer/peewee/issues/188 | 13,885,085 | MDU6SXNzdWUxMzg4NTA4NQ== | 188 | TypeError when running a 'COPY' command on Postgres | {
"login": "bwghughes",
"id": 7694,
"node_id": "MDQ6VXNlcjc2OTQ=",
"avatar_url": "https://avatars.githubusercontent.com/u/7694?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/bwghughes",
"html_url": "https://github.com/bwghughes",
"followers_url": "https://api.github.com/users/bwghughes/followers",
"following_url": "https://api.github.com/users/bwghughes/following{/other_user}",
"gists_url": "https://api.github.com/users/bwghughes/gists{/gist_id}",
"starred_url": "https://api.github.com/users/bwghughes/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/bwghughes/subscriptions",
"organizations_url": "https://api.github.com/users/bwghughes/orgs",
"repos_url": "https://api.github.com/users/bwghughes/repos",
"events_url": "https://api.github.com/users/bwghughes/events{/privacy}",
"received_events_url": "https://api.github.com/users/bwghughes/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Thanks for the excellent bug report. I think I need to clarify the docs a bit -- `RawQuery` was meant to be used for expressing `SELECT` statements. RawQuery is there to give you a way to specify any select statement and _return model instances_.\n\nIf you just want to execute some plain old SQL, try:\n\n``` python\n\n# assume somewhere you have a db defined\ndatabase = PostgresqlDatabase('something')\n\n# ... later ...\nsql = \"COPY uk_towns FROM '{}' DELIMITERS ',' CSV HEADER\".format(towns_file)\nres = database.execute_sql(sql)\n```\n",
"Grand - thanks for the clarification - its abit if an edge case. As I said before I lurrrrve Peewee Thanks !! :)) \n",
"Thanks! So glad to hear that. I'm pushing an update to the docs in a few moments that should hopefully clear this up for the next person who runs into it.\n"
] | 2013-05-02T10:24:19 | 2013-05-02T13:49:26 | 2013-05-02T13:48:52 | NONE | null | I'm loading a CSV file on Postgres using the COPY command, and get a TypeError (I think its because the COPY command returns None).
Here's the code:
``` python
def seed_towns():
print "Seeding Towns tables..."
towns_file = os.path.join(os.path.abspath(os.curdir), 'data/uk-towns-list/uk-towns.csv')
Town.drop_table(fail_silently=True)
Town.create_table(fail_silently=True)
print "Loading data..."
rq = RawQuery(Town, "COPY uk_towns FROM '{}' DELIMITERS ',' CSV HEADER".format(towns_file))
try:
rq.execute()
# Wierdness here
except TypeError, e:
assert Town.select().count() == 43143
finally:
print 'Done.'
```
And here's the trace:
``` python
Traceback (most recent call last):
File "./manage.py", line 45, in <module>
manager.run()
File "/Users/ben/repos/badbatch/lib/python2.7/site-packages/flask_script/__init__.py", line 351, in run
result = self.handle(sys.argv[0], command, sys.argv[2:])
File "/Users/ben/repos/badbatch/lib/python2.7/site-packages/flask_script/__init__.py", line 324, in handle
return command.handle(app, *positional_args, **command_namespace.__dict__)
File "/Users/ben/repos/badbatch/lib/python2.7/site-packages/flask_script/commands.py", line 143, in handle
return self.run(*args, **kwargs)
File "./manage.py", line 31, in seed_towns
for obj in rq.execute():
File "/Users/ben/repos/badbatch/lib/python2.7/site-packages/peewee.py", line 1365, in execute
self._qr = ResultWrapper(self.model_class, self._execute(), None)
File "/Users/ben/repos/badbatch/lib/python2.7/site-packages/peewee.py", line 1090, in __init__
for i in range(len(self.cursor.description)):
TypeError: object of type 'NoneType' has no len()
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/188/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/188/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/187 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/187/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/187/comments | https://api.github.com/repos/coleifer/peewee/issues/187/events | https://github.com/coleifer/peewee/issues/187 | 13,858,977 | MDU6SXNzdWUxMzg1ODk3Nw== | 187 | Unexpected LIKE operations | {
"login": "dmwyatt",
"id": 163359,
"node_id": "MDQ6VXNlcjE2MzM1OQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/163359?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/dmwyatt",
"html_url": "https://github.com/dmwyatt",
"followers_url": "https://api.github.com/users/dmwyatt/followers",
"following_url": "https://api.github.com/users/dmwyatt/following{/other_user}",
"gists_url": "https://api.github.com/users/dmwyatt/gists{/gist_id}",
"starred_url": "https://api.github.com/users/dmwyatt/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/dmwyatt/subscriptions",
"organizations_url": "https://api.github.com/users/dmwyatt/orgs",
"repos_url": "https://api.github.com/users/dmwyatt/repos",
"events_url": "https://api.github.com/users/dmwyatt/events{/privacy}",
"received_events_url": "https://api.github.com/users/dmwyatt/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I don't blame you for being a bit confused... SQLite's `LIKE` operator is case-insensitive by default. To get case-sensitive matching, peewee uses the SQLite `GLOB` operator instead, which uses \"*\" as wildcards.\n\nSo -- if you want case-insensitive matching, use ILIKE (peewee expresses this as `**`) with \"%\" wildcards. If you want case-sensitive, use LIKE (peewee expresses this as `%`) with \"*\" wildcards. Confusing, right?\n\nHopefully this will clarify things:\n\n```\nsqlite> create table movie (title varchar(255));\nsqlite> insert into movie (title) values ('Iron Man');\nsqlite> insert into movie (title) values ('Wreck-It Ralph');\nsqlite> select * from movie where title like '%i%';\nIron Man\nWreck-It Ralph\nsqlite> select * from movie where title like '%I%';\nIron Man\nWreck-It Ralph\nsqlite> select * from movie where title glob '*i*';\nsqlite> select * from movie where title glob '*I*';\nIron Man\nWreck-It Ralph\n```\n\nI will add a note to the documentation on this.\n",
"Added note: http://peewee.readthedocs.org/en/latest/peewee/querying.html#column-lookups\n",
"This behavior got me too (before I looked at the output, noticed it was using GLOB with SQLite, then saw the note in the docs). It seems quite surprising, and would mean if you change your code to use `field % 'whatever*'` to work with SQLite, then if you switch to PostgreSQL it'll break.\n\nI think it'd be more cross-database compatible and less surprising if the `%` operator on SQLite changed the `%`'s in your match string to `*` as well as using `GLOB`, so you didn't have to worry about which database you were on. Thoughts?\n"
] | 2013-05-01T18:10:20 | 2016-01-01T22:15:38 | 2013-05-02T02:56:59 | NONE | null | The following LIKE query gets me nothing:
```
In [22]: movies =models.Movie.select().where(models.Movie.name % '%I%')
In [23]: for m in movies:
....: print m
....:
```
Using ILIKE works:
```
In [26]: movies =models.Movie.select().where(models.Movie.name ** '%i%')
In [27]: for m in movies:
print m
....:
<Movie: 'Iron Man'>
<Movie: 'Wreck-It Ralph'>
```
Using the command line sqlite3 tool:
```
sqlite> SELECT * FROM movie WHERE name LIKE '%I%';
1|Iron Man
2|Wreck-It Ralph
sqlite>
```
This is more likely my idiocy than a bug in peewee, but I can't see where I'm going wrong.
I just pip installed peewee a couple hours ago, so I'm using whatever version is most recent.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/187/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/187/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/186 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/186/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/186/comments | https://api.github.com/repos/coleifer/peewee/issues/186/events | https://github.com/coleifer/peewee/pull/186 | 13,767,731 | MDExOlB1bGxSZXF1ZXN0NTQyNzk0Nw== | 186 | OR operator in multiple where conditions | {
"login": "niedbalski",
"id": 821670,
"node_id": "MDQ6VXNlcjgyMTY3MA==",
"avatar_url": "https://avatars.githubusercontent.com/u/821670?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/niedbalski",
"html_url": "https://github.com/niedbalski",
"followers_url": "https://api.github.com/users/niedbalski/followers",
"following_url": "https://api.github.com/users/niedbalski/following{/other_user}",
"gists_url": "https://api.github.com/users/niedbalski/gists{/gist_id}",
"starred_url": "https://api.github.com/users/niedbalski/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/niedbalski/subscriptions",
"organizations_url": "https://api.github.com/users/niedbalski/orgs",
"repos_url": "https://api.github.com/users/niedbalski/repos",
"events_url": "https://api.github.com/users/niedbalski/events{/privacy}",
"received_events_url": "https://api.github.com/users/niedbalski/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"You can actually use python's `reduce` function to generate dynamic lists of OR-ed together clauses.\n\n``` python\n\nimport operator\nor_conditions = reduce(operator.or_, conditions)\nq = q.where(or_conditions)\n```\n",
"OK, But now you are forcing the AND operator on WHERE conditions. Why you cannot expose this as a parameter?\n",
"Yes, this was a design decision that I made early on that multiple calls to `.where()` would be `AND-ed` together. That does not mean you cannot dynamically generate query trees that will `OR` things together, it just means you will use a different API than multiple calls to `.where()`.\n",
"I can see that your solution looks more compact but less self explanatory . Maybe is a good idea to reflect on the documentation that multiple .where() conditions will be AND-ed by default. I had to debug the code before to understand why this happened. \n\nThanks you for your time!\n",
"Cheers, yeah I did document this but it's buried in a note: http://peewee.readthedocs.org/en/latest/peewee/api.html#Query.where\n\nI will make it more clear and also present a way to \"OR\" parts together dynamically.\n"
] | 2013-04-29T16:08:32 | 2014-06-30T15:13:52 | 2013-04-29T16:11:06 | CONTRIBUTOR | null | Currently is not possible to specify the operator kind between multiple WHERE conditions, AND condition is assumed:
``` sql
WHERE ((((t2."kind" = ?) AND (t2."value" <= ?)) *OR* ((t2."kind" = ?) AND (t2."value" <= ?))) AND (t1."state" = ?))
```
Now is possible to specify the operator for each WHERE condition, using the op=(peewee.OP_OR, peewee.OP_AND)
``` python
q = Foo.select()
for i, val in conditions:
q = q.where((Foo.i == val), op=peewee.OP_OR)
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/186/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/186/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/186",
"html_url": "https://github.com/coleifer/peewee/pull/186",
"diff_url": "https://github.com/coleifer/peewee/pull/186.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/186.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/185 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/185/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/185/comments | https://api.github.com/repos/coleifer/peewee/issues/185/events | https://github.com/coleifer/peewee/issues/185 | 13,671,557 | MDU6SXNzdWUxMzY3MTU1Nw== | 185 | Integer primary keys are expected to become AUTO_INCREMENT? | {
"login": "moraes",
"id": 3164,
"node_id": "MDQ6VXNlcjMxNjQ=",
"avatar_url": "https://avatars.githubusercontent.com/u/3164?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/moraes",
"html_url": "https://github.com/moraes",
"followers_url": "https://api.github.com/users/moraes/followers",
"following_url": "https://api.github.com/users/moraes/following{/other_user}",
"gists_url": "https://api.github.com/users/moraes/gists{/gist_id}",
"starred_url": "https://api.github.com/users/moraes/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/moraes/subscriptions",
"organizations_url": "https://api.github.com/users/moraes/orgs",
"repos_url": "https://api.github.com/users/moraes/repos",
"events_url": "https://api.github.com/users/moraes/events{/privacy}",
"received_events_url": "https://api.github.com/users/moraes/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I must use PrimaryKeyField. Dooh. Sorry for being so stupid.\n"
] | 2013-04-26T02:47:35 | 2013-04-26T10:00:41 | 2013-04-26T10:00:17 | NONE | null | For the snippet:
```
class foo(peewee.Model):
id = peewee.IntegerField(primary_key=True)
db.compiler().create_table(foo, False)
```
The SQL generated for a MySQL database was:
```
CREATE TABLE `foo` (`id` INTEGER NOT NULL PRIMARY KEY)
```
Should I expect `AUTO_INCREMENT` to be added to `id`? I may have misunderstood the docs.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/185/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/185/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/184 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/184/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/184/comments | https://api.github.com/repos/coleifer/peewee/issues/184/events | https://github.com/coleifer/peewee/issues/184 | 13,670,284 | MDU6SXNzdWUxMzY3MDI4NA== | 184 | Pwiz invalid names | {
"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 | [
"I believe this is fixed in 525f1ee884155d\n"
] | 2013-04-26T01:47:44 | 2013-04-26T01:58:43 | 2013-04-26T01:58:43 | OWNER | null | Pwiz can generate bad names for tables, e.g. table named "Foo/Bar"
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/184/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/184/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/183 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/183/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/183/comments | https://api.github.com/repos/coleifer/peewee/issues/183/events | https://github.com/coleifer/peewee/issues/183 | 13,670,208 | MDU6SXNzdWUxMzY3MDIwOA== | 183 | Peewee with Google Cloud SQL | {
"login": "moraes",
"id": 3164,
"node_id": "MDQ6VXNlcjMxNjQ=",
"avatar_url": "https://avatars.githubusercontent.com/u/3164?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/moraes",
"html_url": "https://github.com/moraes",
"followers_url": "https://api.github.com/users/moraes/followers",
"following_url": "https://api.github.com/users/moraes/following{/other_user}",
"gists_url": "https://api.github.com/users/moraes/gists{/gist_id}",
"starred_url": "https://api.github.com/users/moraes/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/moraes/subscriptions",
"organizations_url": "https://api.github.com/users/moraes/orgs",
"repos_url": "https://api.github.com/users/moraes/repos",
"events_url": "https://api.github.com/users/moraes/events{/privacy}",
"received_events_url": "https://api.github.com/users/moraes/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Hmm...I wonder where a good place would be to put this information? Having not tested cloud sql myself I'm reluctant to add something like this to \"playhouse\", but it does seem like useful information to put somewhere...Maybe I'll add a new section to the docs.\n",
"http://peewee.readthedocs.org/en/latest/peewee/database.html#peewee-and-other-databases\n\nThanks @moraes \n",
"Google recommends using MySQLdb over their rdms driver whenever possible. See this page of their documentation: https://developers.google.com/appengine/docs/python/cloud-sql/ Below is what I ended up doing to get peewee to work in both development and production. Along with the changes in my fork of peewee.\n\n```\nif (os.getenv('SERVER_SOFTWARE') and\n os.getenv('SERVER_SOFTWARE').startswith('Google App Engine/')):\n db = MySQLDatabase('<db_name>', unix_socket='/cloudsql/<instance_name>', user='root')\nelse:\n db = MySQLDatabase('<db_name>', user='user', passwd='password')\n```\n"
] | 2013-04-26T01:44:30 | 2014-06-07T21:51:15 | 2013-04-26T02:14:30 | NONE | null | For the record, here's a recipe to use Peewee with Google Cloud SQL on App Engine Python SDK. Cloud SQL uses MySql, so the only difference is the connection:
```
from google.appengine.api import rdbms
import peewee
class AppEngineDatabase(peewee.MySQLDatabase):
def _connect(self, database, **kwargs):
if 'instance' not in kwargs:
raise peewee.ImproperlyConfigured('Missing "instance" keyword to connect to database')
return rdbms.connect(database=database, **kwargs)
```
It works like a charm.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/183/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/183/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/182 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/182/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/182/comments | https://api.github.com/repos/coleifer/peewee/issues/182/events | https://github.com/coleifer/peewee/pull/182 | 13,603,016 | MDExOlB1bGxSZXF1ZXN0NTM0OTk1Mw== | 182 | save field_dict len validation. | {
"login": "niedbalski",
"id": 821670,
"node_id": "MDQ6VXNlcjgyMTY3MA==",
"avatar_url": "https://avatars.githubusercontent.com/u/821670?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/niedbalski",
"html_url": "https://github.com/niedbalski",
"followers_url": "https://api.github.com/users/niedbalski/followers",
"following_url": "https://api.github.com/users/niedbalski/following{/other_user}",
"gists_url": "https://api.github.com/users/niedbalski/gists{/gist_id}",
"starred_url": "https://api.github.com/users/niedbalski/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/niedbalski/subscriptions",
"organizations_url": "https://api.github.com/users/niedbalski/orgs",
"repos_url": "https://api.github.com/users/niedbalski/repos",
"events_url": "https://api.github.com/users/niedbalski/events{/privacy}",
"received_events_url": "https://api.github.com/users/niedbalski/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I think the correct fix is to make the INSERT generation smarter, I've been aware of this issue for a while but it only crops up with models consisting of a single auto-incrementing primary key. I'm not sure why anyone would have a model like that, so I haven't bothered to fix it yet.\n",
"Hello Coleifer,\n\nMy impression is that to have a forced incremental ID is not a good idea because you can have tables without primary keys.\n\nMy patch is just a cosmetic change that guarantees that an AttributeError is raised just in the case of no fields are modified before save the entity.\n",
"To clarify, the autoincrement id is not forced but is just the default.\n\nI fixed the issue by making the insert statement generation a bit smarter, thanks for bringing this issue to my attention.\n",
"Super, thanks you for your work!.\n"
] | 2013-04-24T18:43:14 | 2014-07-06T01:51:05 | 2013-04-25T14:32:58 | CONTRIBUTOR | null | Running this code:
> > > x = ModelInstance()
> > > x.save()
Trigger this:
```
1719 def execute_sql(self, sql, params=None, require_commit=True):
1720 cursor = self.get_cursor()
-> 1721 res = cursor.execute(sql, params or ())
1722 if require_commit and self.get_autocommit():
1723 self.commit()
OperationalError: near ")": syntax error
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/182/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/182/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/182",
"html_url": "https://github.com/coleifer/peewee/pull/182",
"diff_url": "https://github.com/coleifer/peewee/pull/182.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/182.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/181 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/181/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/181/comments | https://api.github.com/repos/coleifer/peewee/issues/181/events | https://github.com/coleifer/peewee/pull/181 | 13,593,581 | MDExOlB1bGxSZXF1ZXN0NTM0NTE1MQ== | 181 | Readme modified for table creation/drop on multiple models. | {
"login": "niedbalski",
"id": 821670,
"node_id": "MDQ6VXNlcjgyMTY3MA==",
"avatar_url": "https://avatars.githubusercontent.com/u/821670?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/niedbalski",
"html_url": "https://github.com/niedbalski",
"followers_url": "https://api.github.com/users/niedbalski/followers",
"following_url": "https://api.github.com/users/niedbalski/following{/other_user}",
"gists_url": "https://api.github.com/users/niedbalski/gists{/gist_id}",
"starred_url": "https://api.github.com/users/niedbalski/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/niedbalski/subscriptions",
"organizations_url": "https://api.github.com/users/niedbalski/orgs",
"repos_url": "https://api.github.com/users/niedbalski/repos",
"events_url": "https://api.github.com/users/niedbalski/events{/privacy}",
"received_events_url": "https://api.github.com/users/niedbalski/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2013-04-24T15:27:29 | 2014-07-06T01:51:07 | 2013-04-24T16:10:39 | CONTRIBUTOR | null | Modified readme to exemplify the use of create_model_tables and drop_model_tables
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/181/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/181/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/181",
"html_url": "https://github.com/coleifer/peewee/pull/181",
"diff_url": "https://github.com/coleifer/peewee/pull/181.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/181.patch",
"merged_at": "2013-04-24T16:10:39"
} |
https://api.github.com/repos/coleifer/peewee/issues/180 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/180/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/180/comments | https://api.github.com/repos/coleifer/peewee/issues/180/events | https://github.com/coleifer/peewee/pull/180 | 12,840,607 | MDExOlB1bGxSZXF1ZXN0NDk5ODI0NQ== | 180 | Only use valid kwargs for update and insert | {
"login": "tax",
"id": 97768,
"node_id": "MDQ6VXNlcjk3NzY4",
"avatar_url": "https://avatars.githubusercontent.com/u/97768?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/tax",
"html_url": "https://github.com/tax",
"followers_url": "https://api.github.com/users/tax/followers",
"following_url": "https://api.github.com/users/tax/following{/other_user}",
"gists_url": "https://api.github.com/users/tax/gists{/gist_id}",
"starred_url": "https://api.github.com/users/tax/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/tax/subscriptions",
"organizations_url": "https://api.github.com/users/tax/orgs",
"repos_url": "https://api.github.com/users/tax/repos",
"events_url": "https://api.github.com/users/tax/events{/privacy}",
"received_events_url": "https://api.github.com/users/tax/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"@tax, thank you for your message and the PR, I'm glad you're liking using \"peewee\".\n\nThe KeyError is intentional -- I think its better to raise an exception than not insert/update something because the user made a typo.\n"
] | 2013-04-05T10:49:16 | 2014-07-06T01:51:08 | 2013-04-05T13:54:39 | NONE | null | Hi Charles, thanks for creating this excellent lightweight project, it is super simple and fun to work with.
I ran in to a problem in a project when passing on a dict to the update query of a model this raised a KeyError because one of the keys in the dict was not a field in the model.
This could be by design, if not I hope you will merge this pull request.
Again thanks for all the hard work on this project.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/180/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/180/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/180",
"html_url": "https://github.com/coleifer/peewee/pull/180",
"diff_url": "https://github.com/coleifer/peewee/pull/180.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/180.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/179 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/179/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/179/comments | https://api.github.com/repos/coleifer/peewee/issues/179/events | https://github.com/coleifer/peewee/issues/179 | 12,633,859 | MDU6SXNzdWUxMjYzMzg1OQ== | 179 | Updating peewee class fields via dictionary | {
"login": "henrikstroem",
"id": 907338,
"node_id": "MDQ6VXNlcjkwNzMzOA==",
"avatar_url": "https://avatars.githubusercontent.com/u/907338?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/henrikstroem",
"html_url": "https://github.com/henrikstroem",
"followers_url": "https://api.github.com/users/henrikstroem/followers",
"following_url": "https://api.github.com/users/henrikstroem/following{/other_user}",
"gists_url": "https://api.github.com/users/henrikstroem/gists{/gist_id}",
"starred_url": "https://api.github.com/users/henrikstroem/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/henrikstroem/subscriptions",
"organizations_url": "https://api.github.com/users/henrikstroem/orgs",
"repos_url": "https://api.github.com/users/henrikstroem/repos",
"events_url": "https://api.github.com/users/henrikstroem/events{/privacy}",
"received_events_url": "https://api.github.com/users/henrikstroem/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Rather than implementing this as a part of peewee, feel free to subclass `Model` and implement it yourself.\n"
] | 2013-03-30T19:00:40 | 2013-03-31T04:56:22 | 2013-03-31T04:56:22 | NONE | null | Feature request.
In Python, you can update object fields via `self.__dict__.update(dictionary)` - this saves a lot of code when reading in data from text files.
Peewee object fields can't be updated in this way, so it would be nice with a convenience method that let you hand a dictionary to a Model object, and have the object fields updated accordingly.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/179/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/179/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/178 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/178/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/178/comments | https://api.github.com/repos/coleifer/peewee/issues/178/events | https://github.com/coleifer/peewee/issues/178 | 12,616,910 | MDU6SXNzdWUxMjYxNjkxMA== | 178 | Change default charset in MySql's create table statements | {
"login": "ibraaaa",
"id": 4008455,
"node_id": "MDQ6VXNlcjQwMDg0NTU=",
"avatar_url": "https://avatars.githubusercontent.com/u/4008455?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/ibraaaa",
"html_url": "https://github.com/ibraaaa",
"followers_url": "https://api.github.com/users/ibraaaa/followers",
"following_url": "https://api.github.com/users/ibraaaa/following{/other_user}",
"gists_url": "https://api.github.com/users/ibraaaa/gists{/gist_id}",
"starred_url": "https://api.github.com/users/ibraaaa/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/ibraaaa/subscriptions",
"organizations_url": "https://api.github.com/users/ibraaaa/orgs",
"repos_url": "https://api.github.com/users/ibraaaa/repos",
"events_url": "https://api.github.com/users/ibraaaa/events{/privacy}",
"received_events_url": "https://api.github.com/users/ibraaaa/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I can appreciate the confusion this problem may cause, but this is not within the scope of peewee which is just an ORM.\n\nCheck out http://dev.mysql.com/doc/refman/5.0/en/charset-database.html if you want to set the charset for your database.\n",
"When the peewee create table it sets the charset as latin1_swedish_ci. so when data insert to table it scramble the data.\nso it need a way to change column charset\n",
"You can also:\n\n```\ndb = MySQLDatabase(...)\ndb.execute_sql(\"SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci;\")\n```\n\nBeyond that I'm not familiar enough with MySQL to be able to advise you what parameters or settings to modify. Consult the docs or try stackoverflow if you are still stuck.\n"
] | 2013-03-29T19:58:13 | 2016-07-15T13:47:53 | 2013-03-30T03:03:11 | NONE | null | For MySql, when I try to insert text encoded in utf8 into a table, the text is scrambled. The issue is that the default charset for tables is latin1, to fix this I need to ALTER a table after its creation to change the charset. Providing such option from inside peewee will be helpful.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/178/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/178/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/177 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/177/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/177/comments | https://api.github.com/repos/coleifer/peewee/issues/177/events | https://github.com/coleifer/peewee/issues/177 | 12,454,609 | MDU6SXNzdWUxMjQ1NDYwOQ== | 177 | Mod function or escape | {
"login": "andmart",
"id": 303252,
"node_id": "MDQ6VXNlcjMwMzI1Mg==",
"avatar_url": "https://avatars.githubusercontent.com/u/303252?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/andmart",
"html_url": "https://github.com/andmart",
"followers_url": "https://api.github.com/users/andmart/followers",
"following_url": "https://api.github.com/users/andmart/following{/other_user}",
"gists_url": "https://api.github.com/users/andmart/gists{/gist_id}",
"starred_url": "https://api.github.com/users/andmart/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/andmart/subscriptions",
"organizations_url": "https://api.github.com/users/andmart/orgs",
"repos_url": "https://api.github.com/users/andmart/repos",
"events_url": "https://api.github.com/users/andmart/events{/privacy}",
"received_events_url": "https://api.github.com/users/andmart/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Unfortunately, peewee does not support modulo out of the box (because I ran out of operators to overload).\n\nYou can create your own operators, though...perhaps I should add this to the docs. There are some cool examples in `playhouse.postgresql_ext` where I add operators for various hstore functions. Here's how you do modulo and regexp:\n\n``` python\n\nfrom peewee import *\nfrom peewee import Expr\n\ndef mod(lhs, rhs):\n return Expr(lhs, 'mod', rhs)\n\ndef regexp(lhs, rhs):\n return Expr(lhs, 're', rhs)\n\n# tell sqlite what to do with these expressions\nSqliteDatabase.register_ops({'mod': '%', 're': 'REGEXP'})\n\nclass User(Model):\n username = CharField()\n\n# users whose username is all numbers\nUser.select().where(regexp(User.username, '[0-9]+')\n\n# users with even ids\nUser.select().where(mod(User.id, 2) == 0)\n```\n",
"Docs: http://peewee.readthedocs.org/en/latest/peewee/querying.html#adding-user-defined-operators\n"
] | 2013-03-26T15:38:29 | 2013-03-29T01:20:11 | 2013-03-29T01:08:28 | NONE | null | I can't do a query where have to recover only even numbers.
Something like that:
Number.select().where(Number.number % 2 == 0)
This way, peewee 'translates' % for GLOB.
So, is there a way to escape % operator or a peewee.fn.Mod function?
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/177/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/177/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/176 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/176/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/176/comments | https://api.github.com/repos/coleifer/peewee/issues/176/events | https://github.com/coleifer/peewee/issues/176 | 12,445,169 | MDU6SXNzdWUxMjQ0NTE2OQ== | 176 | can't create a model that inherits from "dict" | {
"login": "farialima",
"id": 1914172,
"node_id": "MDQ6VXNlcjE5MTQxNzI=",
"avatar_url": "https://avatars.githubusercontent.com/u/1914172?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/farialima",
"html_url": "https://github.com/farialima",
"followers_url": "https://api.github.com/users/farialima/followers",
"following_url": "https://api.github.com/users/farialima/following{/other_user}",
"gists_url": "https://api.github.com/users/farialima/gists{/gist_id}",
"starred_url": "https://api.github.com/users/farialima/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/farialima/subscriptions",
"organizations_url": "https://api.github.com/users/farialima/orgs",
"repos_url": "https://api.github.com/users/farialima/repos",
"events_url": "https://api.github.com/users/farialima/events{/privacy}",
"received_events_url": "https://api.github.com/users/farialima/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Ah, thanks -- I will clarify that if statement!\n",
"aren't there a few other places where a similar fix would be needed ?\n",
"Curious, how would you use peewee to inherit from dict, and then use it as a dict?\n\nI tried farialima's model but standard dict features didn't work.\n\nI have a need to use the DB as a dict, and am not seeing it :)\n",
"http://peewee.readthedocs.org/en/latest/peewee/playhouse.html#key-value-store\n"
] | 2013-03-26T11:52:44 | 2013-07-06T22:40:07 | 2013-03-26T15:39:04 | NONE | null | the following code:
```
class MyModel(Model, dict):
class Meta:
database = SqliteDatabase(':memory:')
id = CharField(primary_key=True)
o = MyModel()
print repr(o.id)
```
will show:
`<peewee.CharField object at 0x1079ca5d0>`
instead of the expected:
`None`
The problem is that o is an empty dictionary "{}", which is a boolean false.
Workaround is to ensure that the object never evaluate to false, eg.:
```
class MyModel(Model, dict):
def __init__(self, *k, **v):
super(MyModel, self).__init__(*k, **v)
self['default'] = ''
class Meta:
database = SqliteDatabase(':memory:')
id = CharField(primary_key=True)
```
The correct solution is to replace
```
class FieldDescriptor
(...)
def __get__(self, instance, instance_type=None):
(...)
if instance:
return instance._data.get(self.att_name)
```
with:
```
if instance != None:
return instance._data.get(self.att_name)
```
and possibly in a few other places (I haven't checked).
It took me time to debug it -- the fact that many objects evaluate to boolean False is really a pain in Python (the only one ?)
Thanks for this great library, in any case.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/176/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/176/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/175 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/175/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/175/comments | https://api.github.com/repos/coleifer/peewee/issues/175/events | https://github.com/coleifer/peewee/issues/175 | 12,370,762 | MDU6SXNzdWUxMjM3MDc2Mg== | 175 | Primary key reset on save | {
"login": "henrikstroem",
"id": 907338,
"node_id": "MDQ6VXNlcjkwNzMzOA==",
"avatar_url": "https://avatars.githubusercontent.com/u/907338?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/henrikstroem",
"html_url": "https://github.com/henrikstroem",
"followers_url": "https://api.github.com/users/henrikstroem/followers",
"following_url": "https://api.github.com/users/henrikstroem/following{/other_user}",
"gists_url": "https://api.github.com/users/henrikstroem/gists{/gist_id}",
"starred_url": "https://api.github.com/users/henrikstroem/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/henrikstroem/subscriptions",
"organizations_url": "https://api.github.com/users/henrikstroem/orgs",
"repos_url": "https://api.github.com/users/henrikstroem/repos",
"events_url": "https://api.github.com/users/henrikstroem/events{/privacy}",
"received_events_url": "https://api.github.com/users/henrikstroem/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Primary keys are not being inherited correctly -- I will look into it and thank you for the excellent bug report!\n"
] | 2013-03-24T08:02:43 | 2013-03-24T17:21:03 | 2013-03-24T17:21:03 | NONE | null | In some situations, the Peewee will reset the (non-integer) primary key when saving an object. I have constructed this example to clarify:
```
#!/usr/bin/python
from peewee import *
import uuid
db = SqliteDatabase('./db/' + str(uuid.uuid4()) + '.db')
class A(Model):
id = CharField(primary_key=True)
def __init__(self):
super(A, self).__init__()
self.id = str(uuid.uuid4())
class Meta:
database = db
class B(A):
name = CharField()
def __init__(self, name):
super(B, self).__init__()
self.name = name
A.create_table()
a = A()
print a.id
a.save(force_insert=True)
print a.id
print "--"
B.create_table()
b = B(name='Test')
print b.id
b.save(force_insert=True)
print b.id
```
An example output:
```
$ ./pkey.py
0bd49fa9-c5cc-40e7-aff7-24e0b17247cb
0bd49fa9-c5cc-40e7-aff7-24e0b17247cb
--
2fe23bac-4cb2-46a2-827a-8a1c6395e665
1
```
Now, the last line should not be 1, but rather 2fe... as the line above. The funny thing is, this, as the example shows, only happens to the child object, and only after the save operation.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/175/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/175/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/174 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/174/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/174/comments | https://api.github.com/repos/coleifer/peewee/issues/174/events | https://github.com/coleifer/peewee/issues/174 | 12,300,308 | MDU6SXNzdWUxMjMwMDMwOA== | 174 | Order of expressions matters when doing IN subqueries | {
"login": "coryalder",
"id": 135608,
"node_id": "MDQ6VXNlcjEzNTYwOA==",
"avatar_url": "https://avatars.githubusercontent.com/u/135608?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/coryalder",
"html_url": "https://github.com/coryalder",
"followers_url": "https://api.github.com/users/coryalder/followers",
"following_url": "https://api.github.com/users/coryalder/following{/other_user}",
"gists_url": "https://api.github.com/users/coryalder/gists{/gist_id}",
"starred_url": "https://api.github.com/users/coryalder/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/coryalder/subscriptions",
"organizations_url": "https://api.github.com/users/coryalder/orgs",
"repos_url": "https://api.github.com/users/coryalder/repos",
"events_url": "https://api.github.com/users/coryalder/events{/privacy}",
"received_events_url": "https://api.github.com/users/coryalder/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Wow, thanks for reporting. I'll try and get a look at this tonight.\n",
"Should be fixed in 92aec9da99f4fe8bf23ffed4cf9dc8b5971e4b4a\n",
"Confirmed!\n\nThanks so much\n"
] | 2013-03-21T23:23:19 | 2013-03-28T18:00:30 | 2013-03-23T18:56:13 | NONE | null | Hey, I've found an odd little edge case
```
device = get_object_or_404(Device, Device.id == identifier)
my_messages = Message.select().join(Notification).join(Device).where(Device.id == device.id)
messages = Message.select().where((Message.id << my_messages) | (Message.query == "*"))
```
This query fails with the error `sqlite3.OperationalError: no such column: t2.query` but if you _swap_ the order of the expressions:
```
messages = Message.select().where((Message.query == "*") | (Message.id << my_messages))
```
That query works fine.
Similarly, if you try to write it as two separate queries:
```
my_messages = Message.select().join(Notification).join(Device).where(Device.id == device.id)
everyone_messages = Message.select().where(Message.query == "*")
messages = Message.select().where((Message.id << my_messages) | (Message.id << everyone_messages))
```
That'll also fail, with the similar error `sqlite3.OperationalError: no such column: t2.id`. Switching the order of expressions doesn't do anything in this case.
p.s. forgive me if this is the most newb-y way to write this type of query. I'm learnin' :) Can't seem to find a way to do a UNION in peewee, which would be my first choice.
---
In short form, my models are:
```
class Device(db.Model):
class Message(db.Model):
query = CharField()
class Notification(db.Model):
device = ForeignKeyField(Device, related_name="notifications", cascade = True)
message = ForeignKeyField(Message, related_name='notifications', cascade = True)
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/174/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/174/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/173 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/173/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/173/comments | https://api.github.com/repos/coleifer/peewee/issues/173/events | https://github.com/coleifer/peewee/issues/173 | 12,287,735 | MDU6SXNzdWUxMjI4NzczNQ== | 173 | Support for multiprocessing connection or sessions handlers similar to SQL Alchemy Engine | {
"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 | [
"Can you get into more detail? What kind of issues are you seeing.\n",
"We were creating the DB connection object in the model.py class and then\nimporting it the same in the parent and child process. So it wasn't a\nconnection issue but rather a shared object/namespace issue in Python with\nmultiprocessing. We were hitting a 'commands out of sync' error from MySQL.\nWe ended up just making a model for the parent and a model for the child\nprocess. This is messy and not the proper way for a fix but it works.\nIdeally we would like to instantiate the model class instead of importing\nit and move the connection to the main class within model. For instance:\n\n#####\nImport model as dbm\n\nmodel_obj = dbm.MasterModel()\n#MasterModel would contain the connection obj\nuser = model_obj.User.get()\n#####\n\nHowever we had limited success building that. It's likely an issue with my\nunderstanding of class construction rather than an issue with Peewee.\n\nOn Friday, March 22, 2013, Charles Leifer wrote:\n\n> Can you get into more detail? What kind of issues are you seeing.\n> \n> —\n> Reply to this email directly or view it on GitHubhttps://github.com/coleifer/peewee/issues/173#issuecomment-15281333\n> .\n",
"Unfortunately I still am not clear on what exactly happens. Can you give me some code to replicate it? Are you using the multiprocessing library and passing model instances around, or are you just calling fork?\n\nThe way that peewee handles the DB connection is pretty straightforward. It is stored in a threadlocal (or a dummy threadlocal) on the database instance. You can open a connection explicitly by calling `db.connect()` or you can open one implicitly when you execute a query.\n",
"@zahlenofzahlen -- please update so I can resolve or close.\n",
"Closing -- please reopen if you can provide me a bit more info!\n"
] | 2013-03-21T18:14:38 | 2013-03-31T04:56:58 | 2013-03-31T04:56:58 | NONE | null | Looking for an easy way to implement multiprocessing with peewee. I'm running into locking issues because the Pwiz generated model or basemodel class does not support closing the database connection after each call. Any ideas?
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/173/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/173/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/172 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/172/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/172/comments | https://api.github.com/repos/coleifer/peewee/issues/172/events | https://github.com/coleifer/peewee/pull/172 | 12,270,994 | MDExOlB1bGxSZXF1ZXN0NDczNzg0Ng== | 172 | Changed the test_suite thingy in setup.py | {
"login": "sYnfo",
"id": 1011548,
"node_id": "MDQ6VXNlcjEwMTE1NDg=",
"avatar_url": "https://avatars.githubusercontent.com/u/1011548?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/sYnfo",
"html_url": "https://github.com/sYnfo",
"followers_url": "https://api.github.com/users/sYnfo/followers",
"following_url": "https://api.github.com/users/sYnfo/following{/other_user}",
"gists_url": "https://api.github.com/users/sYnfo/gists{/gist_id}",
"starred_url": "https://api.github.com/users/sYnfo/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/sYnfo/subscriptions",
"organizations_url": "https://api.github.com/users/sYnfo/orgs",
"repos_url": "https://api.github.com/users/sYnfo/repos",
"events_url": "https://api.github.com/users/sYnfo/events{/privacy}",
"received_events_url": "https://api.github.com/users/sYnfo/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Thank you! I was wondering, could you please update the pypi package with these? I would like to make a rpm package out of this and that would greatly simplify things for me.\n",
"v2.0.9 pushed!\n",
"Thank you :)\n"
] | 2013-03-21T12:05:33 | 2014-06-25T22:58:55 | 2013-03-22T04:56:10 | CONTRIBUTOR | null | ...which makes 'python setup.py test' work.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/172/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/172/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/172",
"html_url": "https://github.com/coleifer/peewee/pull/172",
"diff_url": "https://github.com/coleifer/peewee/pull/172.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/172.patch",
"merged_at": "2013-03-22T04:56:10"
} |
https://api.github.com/repos/coleifer/peewee/issues/171 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/171/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/171/comments | https://api.github.com/repos/coleifer/peewee/issues/171/events | https://github.com/coleifer/peewee/pull/171 | 12,270,695 | MDExOlB1bGxSZXF1ZXN0NDczNzY3MA== | 171 | No tests in source distribution -- MANIFEST.in fix | {
"login": "sYnfo",
"id": 1011548,
"node_id": "MDQ6VXNlcjEwMTE1NDg=",
"avatar_url": "https://avatars.githubusercontent.com/u/1011548?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/sYnfo",
"html_url": "https://github.com/sYnfo",
"followers_url": "https://api.github.com/users/sYnfo/followers",
"following_url": "https://api.github.com/users/sYnfo/following{/other_user}",
"gists_url": "https://api.github.com/users/sYnfo/gists{/gist_id}",
"starred_url": "https://api.github.com/users/sYnfo/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/sYnfo/subscriptions",
"organizations_url": "https://api.github.com/users/sYnfo/orgs",
"repos_url": "https://api.github.com/users/sYnfo/repos",
"events_url": "https://api.github.com/users/sYnfo/events{/privacy}",
"received_events_url": "https://api.github.com/users/sYnfo/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2013-03-21T11:55:36 | 2014-07-06T01:51:14 | 2013-03-22T04:55:59 | CONTRIBUTOR | null | Hi there,
currently the tests are not included in the source distribution and I figured it may be good to put them in.
Also, I'm fairly new to this Pull Request business, so please let me know if I'm doing something wrong. ^^
Regards,
Matt
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/171/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/171/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/171",
"html_url": "https://github.com/coleifer/peewee/pull/171",
"diff_url": "https://github.com/coleifer/peewee/pull/171.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/171.patch",
"merged_at": "2013-03-22T04:55:59"
} |
https://api.github.com/repos/coleifer/peewee/issues/170 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/170/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/170/comments | https://api.github.com/repos/coleifer/peewee/issues/170/events | https://github.com/coleifer/peewee/issues/170 | 12,075,176 | MDU6SXNzdWUxMjA3NTE3Ng== | 170 | Better null detection in pwiz | {
"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 | [
"Fixed\n"
] | 2013-03-15T18:23:37 | 2013-03-19T04:41:32 | 2013-03-19T04:41:32 | OWNER | null | See https://github.com/django/django/commit/ccc0e122d4 for inspiration
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/170/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/170/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/169 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/169/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/169/comments | https://api.github.com/repos/coleifer/peewee/issues/169/events | https://github.com/coleifer/peewee/issues/169 | 11,850,404 | MDU6SXNzdWUxMTg1MDQwNA== | 169 | connections pool support | {
"login": "beanyoung",
"id": 973789,
"node_id": "MDQ6VXNlcjk3Mzc4OQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/973789?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/beanyoung",
"html_url": "https://github.com/beanyoung",
"followers_url": "https://api.github.com/users/beanyoung/followers",
"following_url": "https://api.github.com/users/beanyoung/following{/other_user}",
"gists_url": "https://api.github.com/users/beanyoung/gists{/gist_id}",
"starred_url": "https://api.github.com/users/beanyoung/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/beanyoung/subscriptions",
"organizations_url": "https://api.github.com/users/beanyoung/orgs",
"repos_url": "https://api.github.com/users/beanyoung/repos",
"events_url": "https://api.github.com/users/beanyoung/events{/privacy}",
"received_events_url": "https://api.github.com/users/beanyoung/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Thanks for your question -- at this time I have no plans to include this as part of peewee. Typically I've seen connection pooling done upstream, e.g. pgpool/pgbouncer. To be completely honest, I have not done the research necessary to build a robust connection pool -- if at some point i did add this i'd probably put it in the playhouse module, though.\n"
] | 2013-03-10T09:55:07 | 2013-03-10T16:30:32 | 2013-03-10T16:30:32 | NONE | null | Is peewee going to support connections pool in the future?
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/169/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/169/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/168 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/168/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/168/comments | https://api.github.com/repos/coleifer/peewee/issues/168/events | https://github.com/coleifer/peewee/issues/168 | 11,732,316 | MDU6SXNzdWUxMTczMjMxNg== | 168 | Model.prepared not called for side loaded .join records | {
"login": "jhorman",
"id": 323697,
"node_id": "MDQ6VXNlcjMyMzY5Nw==",
"avatar_url": "https://avatars.githubusercontent.com/u/323697?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/jhorman",
"html_url": "https://github.com/jhorman",
"followers_url": "https://api.github.com/users/jhorman/followers",
"following_url": "https://api.github.com/users/jhorman/following{/other_user}",
"gists_url": "https://api.github.com/users/jhorman/gists{/gist_id}",
"starred_url": "https://api.github.com/users/jhorman/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/jhorman/subscriptions",
"organizations_url": "https://api.github.com/users/jhorman/orgs",
"repos_url": "https://api.github.com/users/jhorman/repos",
"events_url": "https://api.github.com/users/jhorman/events{/privacy}",
"received_events_url": "https://api.github.com/users/jhorman/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I believe this is correct, if somewhat odd, behavior. I'm going to mark this as wontfix for now.\n",
"To my understanding, the contract is that if you are going to populate a model, you will call \"prepared\" on it. The idea that sometimes a model I use will have prepared called, and sometimes not, sort of makes prepared broken/untrustworthy to use.\n",
"Yeah... you're right. I'll look into it.\n"
] | 2013-03-06T20:57:19 | 2013-03-18T04:10:49 | 2013-03-18T04:10:49 | CONTRIBUTOR | null | I am using query.join(User) to enhance the performance of a set of queries. My model also defines a Model.prepared so I can preinitialize some virtual fields. It seems that when a record is loaded via the .join, .prepared isn't called. I ended up doing
```
def prepared(self):
super(MyObject, self).prepared()
self.user.prepared()
```
to account for it.
(hopefully not another non-issue)
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/168/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/168/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/167 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/167/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/167/comments | https://api.github.com/repos/coleifer/peewee/issues/167/events | https://github.com/coleifer/peewee/issues/167 | 11,563,424 | MDU6SXNzdWUxMTU2MzQyNA== | 167 | ORDER BY with multiple DESC fields broken for Postgres | {
"login": "jhorman",
"id": 323697,
"node_id": "MDQ6VXNlcjMyMzY5Nw==",
"avatar_url": "https://avatars.githubusercontent.com/u/323697?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/jhorman",
"html_url": "https://github.com/jhorman",
"followers_url": "https://api.github.com/users/jhorman/followers",
"following_url": "https://api.github.com/users/jhorman/following{/other_user}",
"gists_url": "https://api.github.com/users/jhorman/gists{/gist_id}",
"starred_url": "https://api.github.com/users/jhorman/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/jhorman/subscriptions",
"organizations_url": "https://api.github.com/users/jhorman/orgs",
"repos_url": "https://api.github.com/users/jhorman/repos",
"events_url": "https://api.github.com/users/jhorman/events{/privacy}",
"received_events_url": "https://api.github.com/users/jhorman/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Thank you for pointing this out, I will address this\n",
"You know, I tried to replicate this issue and was not seeing the same problem... can you give any more specifics?\n\n``` python\n\nusers = User.select().order_by(User.username.desc(), User.id.desc())\nipdb> users\n<class 'tests.User'> SELECT t1.\"id\", t1.\"username\" FROM \"users\" AS t1 ORDER BY t1.\"username\" DESC, t1.\"id\" DESC []\n```\n\nIf you have an example that is failing that might help me figure out where the problem is.\n",
"You're right. My example wasn't exactly what I was doing but I assumed it was the same. I am doing\n\n```\nusers = User.select().order_by([User.username.desc(), User.id.desc()])\n```\n\nI am doing it this way b/c in my use case I am assembling a list of order bys.\n",
"I could do \n\n```\nUser.select().order_by(*[User.username.desc(), User.id.desc()])\n```\n\nto expand the array into the parameter list I guess.\n",
"FYI, I also in my journey tried\n\n```\nUser.select().order_by(User.username.desc() & User.id.desc())\n```\n\nWhich results in parens as well. \n\nThis is the wrong way to do it anyway since it is joined with an AND.\n\n```\nORDER BY (t1.\"username\" DESC AND t1.\"id\" DESC)\n```\n",
"Yes, the examples you've provided can result in invalid SQL - peewee won't stop you from doing this, however I think the documentation is pretty clear:\n\nhttp://peewee.readthedocs.org/en/latest/peewee/api.html#SelectQuery.order_by\n\nI'm gonna go ahead and close this as it is working as I intended\n"
] | 2013-03-01T21:43:46 | 2013-03-02T23:38:22 | 2013-03-02T23:38:22 | CONTRIBUTOR | null | If I try to do a
```
query.order_by(Model.field.desc(), Model.field2.desc())
```
with a Postgres DB the generated SQL will look like
```
ORDER BY (t1.field DESC, t1.field2 DESC)
```
which is invalid SQL for Postgres (not sure on other DBs). Postgres (I think) treats that as the creation of a tuple to sort on, and then complains you can't have DESC in the creation of a tuple.
Removing the parens would fix this issue.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/167/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/167/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/166 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/166/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/166/comments | https://api.github.com/repos/coleifer/peewee/issues/166/events | https://github.com/coleifer/peewee/issues/166 | 11,304,705 | MDU6SXNzdWUxMTMwNDcwNQ== | 166 | transaction context manager does not raise the exception. | {
"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 | [
"Thank you :)\n"
] | 2013-02-22T20:44:52 | 2013-02-23T01:52:50 | 2013-02-22T21:45:59 | NONE | null | The **exit** function in the context manager should reraise the exception so that it may be caught outside of the with statement rather than being eaten up.
```
def __exit__(self, exc_type, exc_val, exc_tb):
if exc_type:
self.db.rollback()
self.db.set_autocommit(self._orig)
return False # This is necessary for python to reraise the exception (it must be false not the implicit None). Otherwise, python will eat up the exception.
else:
self.db.commit()
self.db.set_autocommit(self._orig)
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/166/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/166/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/165 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/165/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/165/comments | https://api.github.com/repos/coleifer/peewee/issues/165/events | https://github.com/coleifer/peewee/pull/165 | 11,230,073 | MDExOlB1bGxSZXF1ZXN0NDI0Nzc5Mw== | 165 | Launch example app with env | {
"login": "mgalgs",
"id": 152014,
"node_id": "MDQ6VXNlcjE1MjAxNA==",
"avatar_url": "https://avatars.githubusercontent.com/u/152014?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/mgalgs",
"html_url": "https://github.com/mgalgs",
"followers_url": "https://api.github.com/users/mgalgs/followers",
"following_url": "https://api.github.com/users/mgalgs/following{/other_user}",
"gists_url": "https://api.github.com/users/mgalgs/gists{/gist_id}",
"starred_url": "https://api.github.com/users/mgalgs/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/mgalgs/subscriptions",
"organizations_url": "https://api.github.com/users/mgalgs/orgs",
"repos_url": "https://api.github.com/users/mgalgs/repos",
"events_url": "https://api.github.com/users/mgalgs/events{/privacy}",
"received_events_url": "https://api.github.com/users/mgalgs/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Thank you for catching this!\n"
] | 2013-02-21T06:53:51 | 2014-07-06T01:51:15 | 2013-02-21T15:05:56 | CONTRIBUTOR | null | Using env rather than launching python directly facilitates
the use of virtualenv.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/165/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/165/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/165",
"html_url": "https://github.com/coleifer/peewee/pull/165",
"diff_url": "https://github.com/coleifer/peewee/pull/165.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/165.patch",
"merged_at": "2013-02-21T15:05:56"
} |
https://api.github.com/repos/coleifer/peewee/issues/164 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/164/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/164/comments | https://api.github.com/repos/coleifer/peewee/issues/164/events | https://github.com/coleifer/peewee/issues/164 | 11,196,744 | MDU6SXNzdWUxMTE5Njc0NA== | 164 | Add support for ordering by list of IDs | {
"login": "Pacek",
"id": 234758,
"node_id": "MDQ6VXNlcjIzNDc1OA==",
"avatar_url": "https://avatars.githubusercontent.com/u/234758?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/Pacek",
"html_url": "https://github.com/Pacek",
"followers_url": "https://api.github.com/users/Pacek/followers",
"following_url": "https://api.github.com/users/Pacek/following{/other_user}",
"gists_url": "https://api.github.com/users/Pacek/gists{/gist_id}",
"starred_url": "https://api.github.com/users/Pacek/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/Pacek/subscriptions",
"organizations_url": "https://api.github.com/users/Pacek/orgs",
"repos_url": "https://api.github.com/users/Pacek/repos",
"events_url": "https://api.github.com/users/Pacek/events{/privacy}",
"received_events_url": "https://api.github.com/users/Pacek/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"If the list of ids is ordered, then you can simply do:\n\n``` python\n\nMyModel.select().where(MyModel.id << list_of_ids).order_by(MyModel.id)\n```\n\nIf the ordering is arbitrary, then you could write a helper like this:\n\n``` python\n\ndef sort_by_id(query, id_list):\n # create a mapping\n mapping = dict((model.id, model) for model in query)\n\n for id in id_list:\n yield mapping[id]\n```\n",
"Thanks for this. I found dirty but DB driven solution that works in MySQL:\n\n```\nlist_of_ids = [1,2,3,4,5,6]\nresult = MyModel.select().where(MyModel.id << list_of_ids).order_by(R(\"FIELD(t1.id, %s)\" % \", \".join(map(str, list_of_ids))))\n```\n",
"interesting. another way you can do that is:\n\n``` python\n\nMyModel.select().where(MyModel.id << list_of_ids).order_by(\n fn.Field(MyModel.id, *[R(str(id)) for id in list_of_ids])\n)\n```\n"
] | 2013-02-20T13:26:31 | 2013-02-21T15:26:07 | 2013-02-20T23:18:27 | NONE | null | Would by nice if this worked:
```
list_of_ids = [1,2,3,4,5,6]
result = MyModel.select().where(MyModel.id << list_of_ids)
# result is now is same order as list_of_ids
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/164/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/164/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/163 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/163/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/163/comments | https://api.github.com/repos/coleifer/peewee/issues/163/events | https://github.com/coleifer/peewee/issues/163 | 10,884,848 | MDU6SXNzdWUxMDg4NDg0OA== | 163 | Easy Python 3 compatibility | {
"login": "zielmicha",
"id": 364357,
"node_id": "MDQ6VXNlcjM2NDM1Nw==",
"avatar_url": "https://avatars.githubusercontent.com/u/364357?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/zielmicha",
"html_url": "https://github.com/zielmicha",
"followers_url": "https://api.github.com/users/zielmicha/followers",
"following_url": "https://api.github.com/users/zielmicha/following{/other_user}",
"gists_url": "https://api.github.com/users/zielmicha/gists{/gist_id}",
"starred_url": "https://api.github.com/users/zielmicha/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/zielmicha/subscriptions",
"organizations_url": "https://api.github.com/users/zielmicha/orgs",
"repos_url": "https://api.github.com/users/zielmicha/repos",
"events_url": "https://api.github.com/users/zielmicha/events{/privacy}",
"received_events_url": "https://api.github.com/users/zielmicha/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"No, there is _much_ more needed to make Peewee Python 3 compatible. `Model` uses a metaclass, and Python 3 changed how those were defined. Some judicious application of the `six` library would help there.\n",
"I think I'm finally serious about py3 compatibility... I'll start a fix.\n",
"With the release of 2.1.0, peewee's test suite and extra modules are working with 3.2 and 3.3!\n"
] | 2013-02-11T21:46:53 | 2013-04-02T02:50:17 | 2013-04-02T02:50:17 | NONE | null | This library is nearly compatible with Python 3. Just add:
```
def __hash__(self):
return id(self)
```
to Leaf and run 2to3. Only FieldTypeTestCase test fails. It may be worth mentioning in README.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/163/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/163/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/162 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/162/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/162/comments | https://api.github.com/repos/coleifer/peewee/issues/162/events | https://github.com/coleifer/peewee/issues/162 | 10,790,157 | MDU6SXNzdWUxMDc5MDE1Nw== | 162 | Add support for database modifications | {
"login": "hobeone",
"id": 3444588,
"node_id": "MDQ6VXNlcjM0NDQ1ODg=",
"avatar_url": "https://avatars.githubusercontent.com/u/3444588?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/hobeone",
"html_url": "https://github.com/hobeone",
"followers_url": "https://api.github.com/users/hobeone/followers",
"following_url": "https://api.github.com/users/hobeone/following{/other_user}",
"gists_url": "https://api.github.com/users/hobeone/gists{/gist_id}",
"starred_url": "https://api.github.com/users/hobeone/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/hobeone/subscriptions",
"organizations_url": "https://api.github.com/users/hobeone/orgs",
"repos_url": "https://api.github.com/users/hobeone/repos",
"events_url": "https://api.github.com/users/hobeone/events{/privacy}",
"received_events_url": "https://api.github.com/users/hobeone/received_events",
"type": "User",
"site_admin": false
} | [
{
"id": 191751,
"node_id": "MDU6TGFiZWwxOTE3NTE=",
"url": "https://api.github.com/repos/coleifer/peewee/labels/Feature",
"name": "Feature",
"color": "02e10c",
"default": false,
"description": null
}
] | closed | false | null | [] | null | [
"Yep, I agree that would be nice. I'm working on refactoring the way DDL is generated currently -- would like to get that in place and probably build any schema changing stuff on top of it.\n",
"Sweet.\n\nThanks for making peewee awesome!\n\nOn Fri, Feb 8, 2013 at 3:15 PM, Charles Leifer [email protected]:\n\n> Yep, I agree that would be nice. I'm working on refactoring the way DDL is\n> generated currently -- would like to get that in place and probably build\n> any schema changing stuff on top of it.\n> \n> —\n> Reply to this email directly or view it on GitHubhttps://github.com/coleifer/peewee/issues/162#issuecomment-13319239..\n\n## \n\nDaniel Hobe [email protected]\n",
"I try! I will update this ticket with progress\n",
"So I have made two or three attempts at creating a nice API for representing DDL and every time it feels more cumbersome and clunky than just writing the `create` statements by hand. I may have to scale back my goal and just try to provide a nice api for doing basic schema changes. Proposals are welcome\n",
"Added some stuff in 180bf0b8e0dd22e87b216c59de4da68aa2ed1683 with some basic postgresql support.\n\nSQLite doesn't handle much more than adding columns, and MySQL uses a completely different syntax than Postgresql. Maybe this code could be refactored or retooled into something usable on different backends. For sqlite it will be necessary to create temp tables and rename rather than altering or dropping columns, since this is not supported.\n",
"Cool, I'll take a look.\n\nI've looked into how a few other orms deal with this and it does seem like\neach db driver has to support their own thing.\n\nOn Sun, Mar 17, 2013 at 8:46 PM, Charles Leifer [email protected]:\n\n> Added some stuff in 180bf0bhttps://github.com/coleifer/peewee/commit/180bf0b8e0dd22e87b216c59de4da68aa2ed1683with some basic postgresql support.\n> \n> SQLite doesn't handle much more than adding columns, and MySQL uses a\n> completely different syntax than Postgresql. Maybe this code could be\n> refactored or retooled into something usable on different backends. For\n> sqlite it will be necessary to create temp tables and rename rather than\n> altering or dropping columns, since this is not supported.\n> \n> —\n> Reply to this email directly or view it on GitHubhttps://github.com/coleifer/peewee/issues/162#issuecomment-15037985\n> .\n\n## \n\nDaniel Hobe [email protected]\n"
] | 2013-02-08T18:31:23 | 2013-03-23T04:43:57 | 2013-03-23T04:43:57 | NONE | null | I'd like to implement some sort of schema migration support for the app I'm working on. It would be awesome if Peewee could support some of the basic modifications people would want to do.
Things like:
- add, rename and remove columns
- add and remove indexes (it already supports add I think)
- alter column defaults, NOT NULL etc
My pony request would be to have a standard peewee way of doing this ala the ruby ActiveRecord migrations or something like that.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/162/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/162/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/161 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/161/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/161/comments | https://api.github.com/repos/coleifer/peewee/issues/161/events | https://github.com/coleifer/peewee/issues/161 | 10,753,537 | MDU6SXNzdWUxMDc1MzUzNw== | 161 | save() doesn't remember the INSERT/UPDATE state correctly | {
"login": "koblas",
"id": 219934,
"node_id": "MDQ6VXNlcjIxOTkzNA==",
"avatar_url": "https://avatars.githubusercontent.com/u/219934?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/koblas",
"html_url": "https://github.com/koblas",
"followers_url": "https://api.github.com/users/koblas/followers",
"following_url": "https://api.github.com/users/koblas/following{/other_user}",
"gists_url": "https://api.github.com/users/koblas/gists{/gist_id}",
"starred_url": "https://api.github.com/users/koblas/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/koblas/subscriptions",
"organizations_url": "https://api.github.com/users/koblas/orgs",
"repos_url": "https://api.github.com/users/koblas/repos",
"events_url": "https://api.github.com/users/koblas/events{/privacy}",
"received_events_url": "https://api.github.com/users/koblas/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"This is documented: http://peewee.readthedocs.org/en/latest/peewee/models.html#non-integer-primary-keys\n\nThe reason a model behaves this way is that it is much more simple and straightforward to simply look for a primary key than to try and track the state of a model.\n",
"This bug would also apply if you sharded your ID space and used Snowflake to generate the IDs - which we are doing on some other tables. So it's not just limited to non-integer keys.\n",
"Yes, this is somewhat discussed: http://peewee.readthedocs.org/en/latest/peewee/cookbook.html#bulk-loading-data-or-manually-specifying-primary-keys\n"
] | 2013-02-07T20:11:50 | 2013-02-07T21:56:33 | 2013-02-07T20:32:23 | NONE | null | If you have an assigned ID to a primary key Peewee doesn't remember the get_or_create state of the Model.
```
class GoogleThing(BaseModel):
google_id = peewee.CharField(max_length=40, primary_key=True)
name = peewee.CharField(max_length=32, null=False)
```
Workaround is to write code this - note the "force" boolean that's being tracked around.
```
try:
model = GoogleThing.get(GoogleThing.google_id==google_id)
except Channel.DoesNotExist:
force = True
model = GoogleThing(google_id=google_id)
model.name = "Some Interesting String"
# random other statements... Then
model.save(force_insert=force)
```
The problem is that save() only looks for the presense of the ID field to determine INSERT/UPDATE rather than knowing how the model was created.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/161/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/161/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/160 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/160/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/160/comments | https://api.github.com/repos/coleifer/peewee/issues/160/events | https://github.com/coleifer/peewee/issues/160 | 10,665,077 | MDU6SXNzdWUxMDY2NTA3Nw== | 160 | Problems using order_by | {
"login": "andmart",
"id": 303252,
"node_id": "MDQ6VXNlcjMwMzI1Mg==",
"avatar_url": "https://avatars.githubusercontent.com/u/303252?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/andmart",
"html_url": "https://github.com/andmart",
"followers_url": "https://api.github.com/users/andmart/followers",
"following_url": "https://api.github.com/users/andmart/following{/other_user}",
"gists_url": "https://api.github.com/users/andmart/gists{/gist_id}",
"starred_url": "https://api.github.com/users/andmart/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/andmart/subscriptions",
"organizations_url": "https://api.github.com/users/andmart/orgs",
"repos_url": "https://api.github.com/users/andmart/repos",
"events_url": "https://api.github.com/users/andmart/events{/privacy}",
"received_events_url": "https://api.github.com/users/andmart/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I replaced the line 786 by \n\n```\nparts.append('ORDER BY %s' % tuple(_)) \n```\n",
"I can understnad your confusion. Peewee uses \"-<field name>\" to specify ordering in a models \"Meta\" attributes.\n\nHowever, when querying you will use a different syntax:\n\n``` python\n\nM.select().order_by(M.number.desc())\n```\n\nThis is covered in the docs: \n- http://peewee.readthedocs.org/en/latest/peewee/cookbook.html#sorting-records\n- http://peewee.readthedocs.org/en/latest/peewee/api.html#SelectQuery.order_by\n",
"Thanks, man. Sorry about the false issue.\n"
] | 2013-02-05T20:03:17 | 2013-02-06T15:28:25 | 2013-02-06T14:33:15 | NONE | null | When running the script below, I got
sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 1, and there are 0 supplied.
It seems that orm is not filling the resultant sql with fields to order.
When debugging, printing Ms of line 27 outputs :
<class '__main__.M'> SELECT t1."id", t1."number" FROM "m" AS t1 ORDER BY ? []
###### ######## Script to reproduce error
```
from peewee import IntegerField, Model, SqliteDatabase
import os
DBNAME = 'test.db'
db = SqliteDatabase(DBNAME)
class M(Model):
number = IntegerField()
class Meta:
database = db
def init():
# create table
if not os.path.exists(DBNAME):
M.create_table()
#populate
m1 = M()
m1.number = 1
m1.save()
m2 = M()
m2.number = 2
m2.save()
def query():
Ms = M.select().order_by('-number',)
for m in Ms:
print m
if __name__ == '__main__':
init()
query()
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/160/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/160/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/159 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/159/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/159/comments | https://api.github.com/repos/coleifer/peewee/issues/159/events | https://github.com/coleifer/peewee/pull/159 | 10,575,792 | MDExOlB1bGxSZXF1ZXN0Mzk2MTMyNQ== | 159 | Makes script useable with legacy sqlite dbs which have no foreign keys | {
"login": "jharmn",
"id": 1305160,
"node_id": "MDQ6VXNlcjEzMDUxNjA=",
"avatar_url": "https://avatars.githubusercontent.com/u/1305160?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/jharmn",
"html_url": "https://github.com/jharmn",
"followers_url": "https://api.github.com/users/jharmn/followers",
"following_url": "https://api.github.com/users/jharmn/following{/other_user}",
"gists_url": "https://api.github.com/users/jharmn/gists{/gist_id}",
"starred_url": "https://api.github.com/users/jharmn/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/jharmn/subscriptions",
"organizations_url": "https://api.github.com/users/jharmn/orgs",
"repos_url": "https://api.github.com/users/jharmn/repos",
"events_url": "https://api.github.com/users/jharmn/events{/privacy}",
"received_events_url": "https://api.github.com/users/jharmn/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2013-02-02T19:31:03 | 2014-06-15T11:27:22 | 2013-02-03T01:55:57 | NONE | null | I had this issue specifically on this db: https://github.com/jasonh-n-austin/WheelsREST/blob/master/wheels.db
This is an export from an older MS Sql Server db, which did not have any foreign keys on tables etc. This error handling for foreign keys made it instantly quit with 'Unable to read table definition for "rides"'.
Handling this quietly doesn't seem to hurt anything, as it generated models for all of the tables, it just didn't apply any treatment for fks.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/159/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/159/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/159",
"html_url": "https://github.com/coleifer/peewee/pull/159",
"diff_url": "https://github.com/coleifer/peewee/pull/159.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/159.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/158 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/158/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/158/comments | https://api.github.com/repos/coleifer/peewee/issues/158/events | https://github.com/coleifer/peewee/pull/158 | 10,563,085 | MDExOlB1bGxSZXF1ZXN0Mzk1NjY4MA== | 158 | Alled for old style mysql no FK relation | {
"login": "rosscdh",
"id": 397106,
"node_id": "MDQ6VXNlcjM5NzEwNg==",
"avatar_url": "https://avatars.githubusercontent.com/u/397106?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/rosscdh",
"html_url": "https://github.com/rosscdh",
"followers_url": "https://api.github.com/users/rosscdh/followers",
"following_url": "https://api.github.com/users/rosscdh/following{/other_user}",
"gists_url": "https://api.github.com/users/rosscdh/gists{/gist_id}",
"starred_url": "https://api.github.com/users/rosscdh/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/rosscdh/subscriptions",
"organizations_url": "https://api.github.com/users/rosscdh/orgs",
"repos_url": "https://api.github.com/users/rosscdh/repos",
"events_url": "https://api.github.com/users/rosscdh/events{/privacy}",
"received_events_url": "https://api.github.com/users/rosscdh/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Even though your db may not use foreign key constraints, you can (and should) still use the `ForeignKeyField` to access them, unless I misunderstand the issue.\n\nPerhaps you could send me some models that you are using, or how you use this patch.\n",
"HI Charles, Thanks for the Feedback.. let me try the FKField and Ill let\nyou know how it goes.. Apologies I dont know how, but I did miss this in\nthe documentation.\n\nAll the best\nRoss\n\nOn Sat, Feb 2, 2013 at 1:52 AM, Charles Leifer [email protected]:\n\n> Even though your db may not use foreign key constraints, you can (and\n> should) still use the ForeignKeyField to access them, unless I\n> misunderstand the issue.\n> \n> Perhaps you could send me some models that you are using, or how you use\n> this patch.\n> \n> —\n> Reply to this email directly or view it on GitHubhttps://github.com/coleifer/peewee/pull/158#issuecomment-13021749.\n",
"I rewrote some of the join code to be a little more flexible in case you want to join on something that may not be a foreignkeyfield. Commit d1e5a4845383b4\n\nThe way you might do it is:\n\n``` python\n\nclass User(Model):\n username= CharField()\n\nclass Comment(Model):\n username = CharField()\n message = CharField()\n\n# Say you want to join comments with their user\nComment.select(Comment, User).join(User, on=(Comment.username == User.username))\n```\n",
"Hi there!\n\nThat is perfect! and also more intuitive! Thank you very much.\n\nI must say Im quite enjoying using peewee. It feels a little ungainly on\nlarger queries but that is a symptom all ORMs suffer from I think.\n\nAll the best!\n\nRoss\n\nOn Sun, Feb 3, 2013 at 4:06 AM, Charles Leifer [email protected]:\n\n> I rewrote some of the join code to be a little more flexible in case you\n> want to join on something that may not be a foreignkeyfield. Commit\n> d1e5a48 https://github.com/coleifer/peewee/commit/d1e5a4845383b4\n> \n> The way you might do it is:\n> \n> class User(Model):\n> username= CharField()\n> class Comment(Model):\n> username = CharField()\n> message = CharField()\n> \n> # Say you want to join comments with their userComment.select(Comment, User).join(User, on=(Comment.username == User.username))\n> \n> —\n> Reply to this email directly or view it on GitHubhttps://github.com/coleifer/peewee/pull/158#issuecomment-13041552.\n"
] | 2013-02-01T23:11:45 | 2014-07-06T01:51:21 | 2013-02-03T03:06:57 | NONE | null | Hi there, we have a very old db that has no FKs defined.
Currently its not possible (or seems not) to perform joins on elements that have no FK
This is a minor patch for it..
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/158/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/158/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/158",
"html_url": "https://github.com/coleifer/peewee/pull/158",
"diff_url": "https://github.com/coleifer/peewee/pull/158.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/158.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/157 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/157/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/157/comments | https://api.github.com/repos/coleifer/peewee/issues/157/events | https://github.com/coleifer/peewee/issues/157 | 10,535,274 | MDU6SXNzdWUxMDUzNTI3NA== | 157 | 2 issues at once | {
"login": "ivan-kleshnin",
"id": 2128182,
"node_id": "MDQ6VXNlcjIxMjgxODI=",
"avatar_url": "https://avatars.githubusercontent.com/u/2128182?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/ivan-kleshnin",
"html_url": "https://github.com/ivan-kleshnin",
"followers_url": "https://api.github.com/users/ivan-kleshnin/followers",
"following_url": "https://api.github.com/users/ivan-kleshnin/following{/other_user}",
"gists_url": "https://api.github.com/users/ivan-kleshnin/gists{/gist_id}",
"starred_url": "https://api.github.com/users/ivan-kleshnin/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/ivan-kleshnin/subscriptions",
"organizations_url": "https://api.github.com/users/ivan-kleshnin/orgs",
"repos_url": "https://api.github.com/users/ivan-kleshnin/repos",
"events_url": "https://api.github.com/users/ivan-kleshnin/events{/privacy}",
"received_events_url": "https://api.github.com/users/ivan-kleshnin/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Do you mind putting an example of #1 -- particularly what you expect vs what you get.\n",
"I also see that Postgresql does not support limit/order by on delete and update queries, and SQLite only supports them if it was compiled with `SQLITE_ENABLE_UPDATE_DELETE_LIMIT` -- what db do you use out of curiosity?\n\nAnother option is to do the delete and select the ids to remove in a subquery where you apply the limit and ordering.\n",
"#1 nevermind, sorry. I forgot that peewee can preload with join only master-models.\n#2 I use MySQL. I didn't know that PgSQL does not support that. I'ts kinda disappointing when you DELETE without LIMIT and with mistyped WHERE clause\n\nThus close this thread, pls.\n"
] | 2013-02-01T10:33:05 | 2013-02-03T04:09:09 | 2013-02-03T04:09:09 | NONE | null | Issue #1
`get()` adds `limit(1)` to `SelectQuery`.
When we `join()` something 1-to-n, `get()` breaks selection by limiting those joined items
Issue #2
`DeleteQuery` doesn't have `limit()` method
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/157/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/157/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/156 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/156/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/156/comments | https://api.github.com/repos/coleifer/peewee/issues/156/events | https://github.com/coleifer/peewee/issues/156 | 10,468,825 | MDU6SXNzdWUxMDQ2ODgyNQ== | 156 | sub query in select | {
"login": "nesizer",
"id": 62032,
"node_id": "MDQ6VXNlcjYyMDMy",
"avatar_url": "https://avatars.githubusercontent.com/u/62032?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/nesizer",
"html_url": "https://github.com/nesizer",
"followers_url": "https://api.github.com/users/nesizer/followers",
"following_url": "https://api.github.com/users/nesizer/following{/other_user}",
"gists_url": "https://api.github.com/users/nesizer/gists{/gist_id}",
"starred_url": "https://api.github.com/users/nesizer/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/nesizer/subscriptions",
"organizations_url": "https://api.github.com/users/nesizer/orgs",
"repos_url": "https://api.github.com/users/nesizer/repos",
"events_url": "https://api.github.com/users/nesizer/events{/privacy}",
"received_events_url": "https://api.github.com/users/nesizer/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"a workaround for now is\n\n```\nGame.select(Game, fn.Sum(Stat.viewers).alias('viewers')).join(Stat, JOIN_LEFT_OUTER).group_by(Game).order_by(R('viewers DESC')).limit(5) \n```\n\nbut that runs up to 10 times slower then the sub queries on\n"
] | 2013-01-30T18:03:25 | 2013-12-05T17:34:32 | 2013-01-31T04:53:44 | NONE | null | is there a way for peewee to support sub queries like this one
SELECT g.*,
(SELECT SUM(s.viewers) FROM stats s WHERE s.game_id = g.id) AS viewers
FROM games AS g
WHERE g.id != 96
ORDER BY viewers DESC
LIMIT 5
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/156/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/156/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/155 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/155/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/155/comments | https://api.github.com/repos/coleifer/peewee/issues/155/events | https://github.com/coleifer/peewee/pull/155 | 10,298,056 | MDExOlB1bGxSZXF1ZXN0MzgzMzI5MA== | 155 | SelectQuery.first() | {
"login": "maebert",
"id": 1047165,
"node_id": "MDQ6VXNlcjEwNDcxNjU=",
"avatar_url": "https://avatars.githubusercontent.com/u/1047165?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/maebert",
"html_url": "https://github.com/maebert",
"followers_url": "https://api.github.com/users/maebert/followers",
"following_url": "https://api.github.com/users/maebert/following{/other_user}",
"gists_url": "https://api.github.com/users/maebert/gists{/gist_id}",
"starred_url": "https://api.github.com/users/maebert/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/maebert/subscriptions",
"organizations_url": "https://api.github.com/users/maebert/orgs",
"repos_url": "https://api.github.com/users/maebert/repos",
"events_url": "https://api.github.com/users/maebert/events{/privacy}",
"received_events_url": "https://api.github.com/users/maebert/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"This is similar to what the `.get()` method does [link](http://peewee.readthedocs.org/en/latest/peewee/api.html#Model.get) / [src](https://github.com/coleifer/peewee/blob/master/peewee.py#L1328) except instead of raising an exception it returns `None`. I don't see how this is any better -- i assume you still have an if statement somewhere to see if you have a model or `None`.\n",
"Sorry Charles, I wasn't very clear about this. This is not any better or worse than `.get()`, it's just an alternative that improves compatibility to and portability from SQLAlchemy based modules such as `flask-security`. So basically, when porting code that works with SQLAlchemy to work with peewee, whenever the code sats\n\n``` python\nreturn User.query.filter_by(name=\"admin\").first()\n```\n\nthe Peewee equivalent is \n\n``` python\ntry:\n return User.filter(name=\"admin\").get()\nexcept User.DoesNotExist:\n return None\n```\n\nor rather, since `filter` is deprecated in 2.0,\n\n``` python\ntry:\n return User.filter(User.name == \"admin\").get()\nexcept User.DoesNotExist:\n return None\n```\n\nworsening code ports in cases like this:\n\n``` python\n# code excerpt from flask-security working with SQLAlchemy\ndef find_role(self, **kwargs):\n return self.user_role.query.filter_by(**kwargs).first()\n```\n\nIntroducing short-hands like `.first()` (and maybe not deprecating the for shorter queries incredibly useful `filter` syntax) simply improves portability and thus greater support for peewee.\n",
"OK, you convinced me on `first`: 486a08ce6c1592653fba196cee8f7cb523d28d19\n",
"Cool, thanks a lot! After a quick and dirty test though I think the query is slightly faster if limiting to one result before executing (doing `res = self.limit(1).execute()`). My [test setup](https://gist.github.com/4638612) was a local SQLite db, 10000 rows, query matched 100 rows, I timed creating one object after the DB was set up and connected. It's not big, about 10ns per query (based on 1mio repetitions), but that's using a local DB already, so for requests over a network it might yield a little improvement.\n",
"Yes .first() is not implemented as efficiently as .get() -- but that is on purpose. It's name is .first(), implying there might be a second. Additionally, multiple calls to first() will not result in the query being evaluated multiple times, which is _not_ the case with .get(). If you want, you can always put the limit before the call to first:\n\n``` python\n\nSomething.select().limit(1).first()\n```\n\nor just write a wrapper\n\n``` python\n\ndef first(query):\n return query.limit(1).first()\n```\n\nAs to filter(), yes I agree it is easy to use but it is not flexible. We have to add hacks like django's double-underscore to specify operations other than `eq`, and trying to biuld a query tree results in hacks like `DQ`.\n\nFor a bit more of my rationale, see http://charlesleifer.com/blog/shortcomings-in-the-django-orm-and-a-look-at-peewee-a-lightweight-alternative/\n",
"Fair call. Thanks for implementing this!\n"
] | 2013-01-25T02:17:25 | 2014-07-06T01:51:22 | 2013-01-25T04:15:38 | NONE | null | Return the first result of a Query or `None` if the result doesn't contain any row. This is analogous to SQLAlchemy and python-mongodb and eases portability for third-party modules wanting to support peewee.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/155/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/155/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/155",
"html_url": "https://github.com/coleifer/peewee/pull/155",
"diff_url": "https://github.com/coleifer/peewee/pull/155.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/155.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/154 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/154/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/154/comments | https://api.github.com/repos/coleifer/peewee/issues/154/events | https://github.com/coleifer/peewee/issues/154 | 10,296,324 | MDU6SXNzdWUxMDI5NjMyNA== | 154 | Database is locked, can't be opened again | {
"login": "Miserlou",
"id": 139987,
"node_id": "MDQ6VXNlcjEzOTk4Nw==",
"avatar_url": "https://avatars.githubusercontent.com/u/139987?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/Miserlou",
"html_url": "https://github.com/Miserlou",
"followers_url": "https://api.github.com/users/Miserlou/followers",
"following_url": "https://api.github.com/users/Miserlou/following{/other_user}",
"gists_url": "https://api.github.com/users/Miserlou/gists{/gist_id}",
"starred_url": "https://api.github.com/users/Miserlou/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/Miserlou/subscriptions",
"organizations_url": "https://api.github.com/users/Miserlou/orgs",
"repos_url": "https://api.github.com/users/Miserlou/repos",
"events_url": "https://api.github.com/users/Miserlou/events{/privacy}",
"received_events_url": "https://api.github.com/users/Miserlou/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Not sure exactly what happened -- take a look here:\n\nhttp://stackoverflow.com/questions/151026/how-do-i-unlock-a-sqlite-database\n",
"I love you. Sorry for bringing this up on GitHub, I couldn't get a response on IRC. This data is pretty important to me and I was having a mini panic attack. \n"
] | 2013-01-25T00:57:00 | 2013-01-25T01:01:05 | 2013-01-25T00:58:17 | NONE | null | Help!
I've been using peewee as the DB for a scraper job that's been running for about 3 months now.
I tried copying the database file to make a backup. This may have happened while the process was still running, and now it's stuck in a locked state.
new_pk = insert.execute()
File "/usr/local/lib/python2.6/dist-packages/peewee.py", line 1355, in execute
result = self.database.execute(self)
File "/usr/local/lib/python2.6/dist-packages/peewee.py", line 1446, in execute
return self.execute_sql(sql, params, commit)
File "/usr/local/lib/python2.6/dist-packages/peewee.py", line 1452, in execute_sql
self.commit()
File "/usr/local/lib/python2.6/dist-packages/peewee.py", line 1460, in commit
self.get_conn().commit()
sqlite3.OperationalError: database is locked
I can neither load the backup nor continue the job. What should I do? Halp!
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/154/reactions",
"total_count": 1,
"+1": 1,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/154/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/153 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/153/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/153/comments | https://api.github.com/repos/coleifer/peewee/issues/153/events | https://github.com/coleifer/peewee/pull/153 | 10,261,335 | MDExOlB1bGxSZXF1ZXN0MzgxNDUzMQ== | 153 | Add support for LIMIT clause to UPDATE | {
"login": "djt",
"id": 145617,
"node_id": "MDQ6VXNlcjE0NTYxNw==",
"avatar_url": "https://avatars.githubusercontent.com/u/145617?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/djt",
"html_url": "https://github.com/djt",
"followers_url": "https://api.github.com/users/djt/followers",
"following_url": "https://api.github.com/users/djt/following{/other_user}",
"gists_url": "https://api.github.com/users/djt/gists{/gist_id}",
"starred_url": "https://api.github.com/users/djt/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/djt/subscriptions",
"organizations_url": "https://api.github.com/users/djt/orgs",
"repos_url": "https://api.github.com/users/djt/repos",
"events_url": "https://api.github.com/users/djt/events{/privacy}",
"received_events_url": "https://api.github.com/users/djt/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2013-01-24T04:26:32 | 2014-07-06T01:51:24 | 2013-01-24T04:29:37 | NONE | null | First of all, this is a great library. I have only just started using it but already am loving the implementation and direction.
I had a requirement of restricting the amount of items modified by an update so went ahead and added LIMIT support. This has only been tested on MySQL in my case so I'm not sure if it will impact the other DBs that you support.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/153/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/153/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/153",
"html_url": "https://github.com/coleifer/peewee/pull/153",
"diff_url": "https://github.com/coleifer/peewee/pull/153.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/153.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/152 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/152/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/152/comments | https://api.github.com/repos/coleifer/peewee/issues/152/events | https://github.com/coleifer/peewee/issues/152 | 10,115,327 | MDU6SXNzdWUxMDExNTMyNw== | 152 | Defer loading and saving certain columns | {
"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 | [
"Fixed 821146b24b3e2c9376\n"
] | 2013-01-18T22:07:36 | 2013-01-31T05:17:32 | 2013-01-31T05:17:32 | OWNER | null | Would like a nicer API for deferring loading and saving particular columns
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/152/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/152/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/151 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/151/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/151/comments | https://api.github.com/repos/coleifer/peewee/issues/151/events | https://github.com/coleifer/peewee/issues/151 | 10,093,966 | MDU6SXNzdWUxMDA5Mzk2Ng== | 151 | peewee + dbslayer | {
"login": "rosscdh",
"id": 397106,
"node_id": "MDQ6VXNlcjM5NzEwNg==",
"avatar_url": "https://avatars.githubusercontent.com/u/397106?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/rosscdh",
"html_url": "https://github.com/rosscdh",
"followers_url": "https://api.github.com/users/rosscdh/followers",
"following_url": "https://api.github.com/users/rosscdh/following{/other_user}",
"gists_url": "https://api.github.com/users/rosscdh/gists{/gist_id}",
"starred_url": "https://api.github.com/users/rosscdh/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/rosscdh/subscriptions",
"organizations_url": "https://api.github.com/users/rosscdh/orgs",
"repos_url": "https://api.github.com/users/rosscdh/repos",
"events_url": "https://api.github.com/users/rosscdh/events{/privacy}",
"received_events_url": "https://api.github.com/users/rosscdh/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Thank you, I'm glad you're enjoying peewee!\n\nI hadn't heard of dbslayer so I took a look at it... I am pretty sure i would never recommend anyone use dbslayer... but of course if you wanted to build an adapter I think it would be possible.\n\nThis is a good place to start: http://peewee.readthedocs.org/en/latest/peewee/database.html#writing-a-database-driver\n\nYou would need to implement a subclass of database, probably `MySqlDatabase`. Since you're working with http you will need to implement or work around the various db-api 2.0 calls that peewee uses.\n\nThe apsw driver in \"playhouse\" has to wrap a number of db-api 2.0 functions, so that's a good place to look as well:\nhttps://github.com/coleifer/peewee/blob/master/playhouse/apsw_ext.py\n\nGood luck, let me know if you have any more questions.\n\n:monkey_face: :bear: :rabbit:\n",
"Hi there,\n\nThanks for the great feedback. Id be interested in hearing your opinion on\nwhy not to use dbslayer? aside from the obvious security issues (which in\nour case are partially solved by a closed network and specific access\nroutes). Our main attraction for it being clean simply load-balancing\n(using cherokee).\n\nall the best\nRoss\n\nOn Fri, Jan 18, 2013 at 3:45 PM, Charles Leifer [email protected]:\n\n> Thank you, I'm glad you're enjoying peewee!\n> \n> I hadn't heard of dbslayer so I took a look at it... I am pretty sure i\n> would never recommend anyone use dbslayer... but of course if you wanted to\n> build an adapter I think it would be possible.\n> \n> This is a good place to start:\n> http://peewee.readthedocs.org/en/latest/peewee/database.html#writing-a-database-driver\n> \n> You would need to implement a subclass of database, probably MySqlDatabase.\n> Since you're working with http you will need to implement or work around\n> the various db-api 2.0 calls that peewee uses.\n> \n> The apsw driver in \"playhouse\" has to wrap a number of db-api 2.0\n> functions, so that's a good place to look as well:\n> https://github.com/coleifer/peewee/blob/master/playhouse/apsw_ext.py\n> \n> Good luck, let me know if you have any more questions.\n> \n> —\n> Reply to this email directly or view it on GitHubhttps://github.com/coleifer/peewee/issues/151#issuecomment-12424613.\n",
"Sure thing! And i'm happy to provide help when you start implementing.\n\nThe biggest detractors i see are:\n- overhead of HTTP versus socket connections\n- overhead of serialization to JSON and having to implement conversion between json & native python types\n- limitations on response size or problems with large queries or responses\n\nIf it were me i would write a connection pool that also did load balancing. This would get rid of the Http request/response cycle overhead and serialization overhead.\n"
] | 2013-01-18T10:30:03 | 2013-01-18T15:56:55 | 2013-01-18T14:45:32 | NONE | null | Hey there,
Firstly well done on this neat little orm.
I'm considering writing a peewee Database type to interface with dbslayer (JSON response interface) (would implement using "requests")
I was wondering if you are aware of anything like this? or if you had any pointers?
Best
Ross
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/151/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/151/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/150 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/150/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/150/comments | https://api.github.com/repos/coleifer/peewee/issues/150/events | https://github.com/coleifer/peewee/issues/150 | 9,980,438 | MDU6SXNzdWU5OTgwNDM4 | 150 | Certain operations not respecting the db_value() | {
"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 | [
"This error was reported via google groups. The issue is on line 776 in `_parse_field_dictionary` which parses things like updates and inserts. It iterates the dictinary and hands off the value to `parse_expr` before sending it to db_value() and this is where the lists are getting mangled.\n",
"Fixed in 1d4290784a1ae183c -- see commit message for details, the tl;dr is that we don't know if we should call db_value or parse_expr first -- we call parse_expr because it is more general and powerful, but there is special logic for handling lists (which are used primarily to build up IN clauses). This doesn't play nice w/the behavior we wanted for the csv field for instance. The fix was basically, if the expression is not a \"rich\" object, to pass it thru the parse_expr.\n",
"Is this still fixed in the latest version?\r\n\r\nI have made a ListField, which is pretty much the same as here:\r\n\r\n```\r\nclass ListField(Field): \r\n \r\n def db_value(self, value):\r\n out = \"\"\r\n for val in value:\r\n out += val\r\n out += \" \"\r\n return out[:-1]\r\n\r\n def python_value(self, value):\r\n return value.split(\" \")\r\n```\r\n\r\nI get the same error: peewee.OperationalError: near \",\": syntax error\r\ndb_value doesnt get a list, but gets called for each item in the list",
"Workaround:\r\n\r\nMade a class that contains the list. Made a ClassField for this class, that uses the list to create the output."
] | 2013-01-15T14:45:22 | 2017-06-30T11:55:41 | 2013-01-16T03:33:39 | OWNER | null | I want to create a custom field that will be a list in python and is converted to text for database storage, but my custom field is generating invalid SQL. Here's an example to illustrate the problem I'm having.
```
from peewee import *
db = SqliteDatabase('test.db')
class CSVField(TextField):
def db_value(self, value):
if value:
value = ','.join(value)
return value
def python_value(self, value):
return value.split(',') if value else []
class Row(Model):
values = CSVField()
class Meta:
database = db
Row.create_table(fail_silently=True)
row = Row(values=['first', 'second', 'third', 'fourth'])
row.save()
```
This will raise an exception with the message: sqlite3.OperationalError: near ",": syntax error
When I investigate, I find that the following SQL and params are being executed:
```
INSERT INTO "row" ("values") VALUES ((?,?,?,?)
['f,i,r,s,t', 's,e,c,o,n,d', 't,h,i,r,d', 'f,o,u,r,t,h']
```
Am I using this wrong? The db_value method of my custom field gets called for each item of the list separately, but I'd like to process the list as a whole. Is there a way to do this? Using a set instead of a list works fine.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/150/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/150/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/149 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/149/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/149/comments | https://api.github.com/repos/coleifer/peewee/issues/149/events | https://github.com/coleifer/peewee/pull/149 | 9,945,211 | MDExOlB1bGxSZXF1ZXN0MzY2NDcxNg== | 149 | Update docs/peewee/quickstart.rst | {
"login": "rotated8",
"id": 638392,
"node_id": "MDQ6VXNlcjYzODM5Mg==",
"avatar_url": "https://avatars.githubusercontent.com/u/638392?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/rotated8",
"html_url": "https://github.com/rotated8",
"followers_url": "https://api.github.com/users/rotated8/followers",
"following_url": "https://api.github.com/users/rotated8/following{/other_user}",
"gists_url": "https://api.github.com/users/rotated8/gists{/gist_id}",
"starred_url": "https://api.github.com/users/rotated8/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/rotated8/subscriptions",
"organizations_url": "https://api.github.com/users/rotated8/orgs",
"repos_url": "https://api.github.com/users/rotated8/repos",
"events_url": "https://api.github.com/users/rotated8/events{/privacy}",
"received_events_url": "https://api.github.com/users/rotated8/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2013-01-14T15:24:25 | 2014-07-06T01:51:25 | 2013-01-14T15:26:00 | CONTRIBUTOR | null | Claimed the expected return value was 'herb' when it is 'bob' (code is correct).
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/149/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/149/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/149",
"html_url": "https://github.com/coleifer/peewee/pull/149",
"diff_url": "https://github.com/coleifer/peewee/pull/149.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/149.patch",
"merged_at": "2013-01-14T15:26:00"
} |
https://api.github.com/repos/coleifer/peewee/issues/148 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/148/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/148/comments | https://api.github.com/repos/coleifer/peewee/issues/148/events | https://github.com/coleifer/peewee/issues/148 | 9,941,242 | MDU6SXNzdWU5OTQxMjQy | 148 | pwiz: reserved python keywords | {
"login": "Pacek",
"id": 234758,
"node_id": "MDQ6VXNlcjIzNDc1OA==",
"avatar_url": "https://avatars.githubusercontent.com/u/234758?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/Pacek",
"html_url": "https://github.com/Pacek",
"followers_url": "https://api.github.com/users/Pacek/followers",
"following_url": "https://api.github.com/users/Pacek/following{/other_user}",
"gists_url": "https://api.github.com/users/Pacek/gists{/gist_id}",
"starred_url": "https://api.github.com/users/Pacek/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/Pacek/subscriptions",
"organizations_url": "https://api.github.com/users/Pacek/orgs",
"repos_url": "https://api.github.com/users/Pacek/repos",
"events_url": "https://api.github.com/users/Pacek/events{/privacy}",
"received_events_url": "https://api.github.com/users/Pacek/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"hmm...yeah it probably should...though its not really supposed to be \"perfect\" ya know? you will still probably want to edit it...but maybe it can drop a warning in there or something\n"
] | 2013-01-14T13:19:31 | 2013-01-15T20:20:31 | 2013-01-15T20:20:31 | NONE | null | Pwiz script should keep in mind python reserved keywords like "import", "str", ... and generate alternative field name.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/148/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/148/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/147 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/147/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/147/comments | https://api.github.com/repos/coleifer/peewee/issues/147/events | https://github.com/coleifer/peewee/issues/147 | 9,810,837 | MDU6SXNzdWU5ODEwODM3 | 147 | auto-incrementing primary keys in Sqlite | {
"login": "markschl",
"id": 783293,
"node_id": "MDQ6VXNlcjc4MzI5Mw==",
"avatar_url": "https://avatars.githubusercontent.com/u/783293?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/markschl",
"html_url": "https://github.com/markschl",
"followers_url": "https://api.github.com/users/markschl/followers",
"following_url": "https://api.github.com/users/markschl/following{/other_user}",
"gists_url": "https://api.github.com/users/markschl/gists{/gist_id}",
"starred_url": "https://api.github.com/users/markschl/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/markschl/subscriptions",
"organizations_url": "https://api.github.com/users/markschl/orgs",
"repos_url": "https://api.github.com/users/markschl/repos",
"events_url": "https://api.github.com/users/markschl/events{/privacy}",
"received_events_url": "https://api.github.com/users/markschl/received_events",
"type": "User",
"site_admin": false
} | [
{
"id": 191750,
"node_id": "MDU6TGFiZWwxOTE3NTA=",
"url": "https://api.github.com/repos/coleifer/peewee/labels/Bug",
"name": "Bug",
"color": "e10c02",
"default": false,
"description": null
}
] | closed | false | null | [] | null | [
"http://www.sqlite.org/autoinc.html - i will see about a fix\n",
"Because SQLite incurs additional overhead to guarantee monotonically incrementing PKs, I will keep the default behavior which simply guarantees they are unique.\n\nIf you would like to use an autoincrementing primary key, try this in your code:\n\n``` python\n\ndb = SqliteDatabase('mydb.db', fields={'primary_key': 'INTEGER AUTOINCREMENT'})\n```\n\nOr\n\n``` python\n\ndb.register_fields({'primary_key': 'INTEGER AUTOINCREMENT'})\n```\n",
"I thought about that, too; unfortunately Sqlite complains about a syntax error. The \"invalid\" SQL looks like this:\n\nCREATE TABLE \"test\" (\"id\" INTEGER AUTOINCREMENT NOT NULL PRIMARY KEY, ...)\nI believe, the AUTOINCREMENT should be positioned after PRIMARY KEY.\n",
"I'm thinking about trying to refactor all the DDL stuff. Hopefully that might make something like this change easier...currently the ordering of the clauses is somewhat hardcoded :goberserk: \n",
"Still not work.\n\n1 `db = SqliteDatabase('mydb.db', fields={'primary_key': 'INTEGER AUTOINCREMENT'})` got below error:\n\n`peewee.OperationalError: near \"AUTOINCREMENT\": syntax error`\n\nSQL is:\n`u'CREATE TABLE \"customer\" (\"id\" INTEGER AUTOINCREMENT NOT NULL PRIMARY KEY, \"name\" VARCHAR(255) NOT NULL, \"upper_name\" VARCHAR(255) NOT NULL, \"remark\" VARCHAR(255) NOT NULL)'`\n\n2 `db.register_fields({'primary_key': 'INTEGER AUTOINCREMENT'})` has no effect at all\n",
"This is for a much older version of Peewee. Check out http://docs.peewee-orm.com/en/latest/peewee/playhouse.html#PrimaryKeyAutoIncrementField\n",
"So, I have to define id manually? And, `PrimaryKeyAutoIncrementField` is only for Sqlite, right?\n\n```\nClass User(Model):\n id = PrimaryKeyAutoIncrementField()\n name = CharField()\n```\n",
"Peewee includes an autoincrement pk by default for all databases. For sqlite, there are different types, rowid and a special autoincrement type. See:\n\nhttp://www.sqlite.org/autoinc.html\n"
] | 2013-01-09T16:33:31 | 2016-05-07T14:39:48 | 2013-09-04T18:46:18 | NONE | null | I have a question regarding auto-incrementing primary keys. As far as I can see from tests, in MySQL, primary key columns are created with AUTO_INCREMENT by default, whereas in Sqlite databases the primary key of an insert may not be unique forever if some rows are deleted. As far as I understand, the equivalent of AUTO_INCREMENT (MySQL) is AUTOINCREMENT in Sqlite.
I haven't yet been able to figure out how to use this feature with Sqlite without modifying peewee itself (model._meta.auto_increment doesn't seem to have an effect).
Thank you
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/147/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/147/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/146 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/146/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/146/comments | https://api.github.com/repos/coleifer/peewee/issues/146/events | https://github.com/coleifer/peewee/pull/146 | 9,793,146 | MDExOlB1bGxSZXF1ZXN0MzU5NzQ1Nw== | 146 | add limit and orderby support to update | {
"login": "beanyoung",
"id": 973789,
"node_id": "MDQ6VXNlcjk3Mzc4OQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/973789?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/beanyoung",
"html_url": "https://github.com/beanyoung",
"followers_url": "https://api.github.com/users/beanyoung/followers",
"following_url": "https://api.github.com/users/beanyoung/following{/other_user}",
"gists_url": "https://api.github.com/users/beanyoung/gists{/gist_id}",
"starred_url": "https://api.github.com/users/beanyoung/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/beanyoung/subscriptions",
"organizations_url": "https://api.github.com/users/beanyoung/orgs",
"repos_url": "https://api.github.com/users/beanyoung/repos",
"events_url": "https://api.github.com/users/beanyoung/events{/privacy}",
"received_events_url": "https://api.github.com/users/beanyoung/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I do not plan on merging this, however I am glad you were able to extend the mysql apis.\n"
] | 2013-01-09T04:17:28 | 2014-07-06T01:51:27 | 2013-01-09T15:17:12 | NONE | null | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/146/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/146/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/146",
"html_url": "https://github.com/coleifer/peewee/pull/146",
"diff_url": "https://github.com/coleifer/peewee/pull/146.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/146.patch",
"merged_at": null
} |
|
https://api.github.com/repos/coleifer/peewee/issues/145 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/145/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/145/comments | https://api.github.com/repos/coleifer/peewee/issues/145/events | https://github.com/coleifer/peewee/pull/145 | 9,520,827 | MDExOlB1bGxSZXF1ZXN0MzQ4MjkyNQ== | 145 | Remove unused imports | {
"login": "methane",
"id": 199592,
"node_id": "MDQ6VXNlcjE5OTU5Mg==",
"avatar_url": "https://avatars.githubusercontent.com/u/199592?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/methane",
"html_url": "https://github.com/methane",
"followers_url": "https://api.github.com/users/methane/followers",
"following_url": "https://api.github.com/users/methane/following{/other_user}",
"gists_url": "https://api.github.com/users/methane/gists{/gist_id}",
"starred_url": "https://api.github.com/users/methane/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/methane/subscriptions",
"organizations_url": "https://api.github.com/users/methane/orgs",
"repos_url": "https://api.github.com/users/methane/repos",
"events_url": "https://api.github.com/users/methane/events{/privacy}",
"received_events_url": "https://api.github.com/users/methane/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2012-12-26T13:20:06 | 2014-07-06T01:51:29 | 2013-01-04T23:06:35 | CONTRIBUTOR | null | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/145/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/145/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/145",
"html_url": "https://github.com/coleifer/peewee/pull/145",
"diff_url": "https://github.com/coleifer/peewee/pull/145.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/145.patch",
"merged_at": null
} |
|
https://api.github.com/repos/coleifer/peewee/issues/144 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/144/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/144/comments | https://api.github.com/repos/coleifer/peewee/issues/144/events | https://github.com/coleifer/peewee/pull/144 | 9,520,722 | MDExOlB1bGxSZXF1ZXN0MzQ4Mjg2OQ== | 144 | Fix for_update support for MySQL | {
"login": "methane",
"id": 199592,
"node_id": "MDQ6VXNlcjE5OTU5Mg==",
"avatar_url": "https://avatars.githubusercontent.com/u/199592?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/methane",
"html_url": "https://github.com/methane",
"followers_url": "https://api.github.com/users/methane/followers",
"following_url": "https://api.github.com/users/methane/following{/other_user}",
"gists_url": "https://api.github.com/users/methane/gists{/gist_id}",
"starred_url": "https://api.github.com/users/methane/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/methane/subscriptions",
"organizations_url": "https://api.github.com/users/methane/orgs",
"repos_url": "https://api.github.com/users/methane/repos",
"events_url": "https://api.github.com/users/methane/events{/privacy}",
"received_events_url": "https://api.github.com/users/methane/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2012-12-26T13:11:02 | 2014-06-28T22:43:51 | 2012-12-26T15:13:26 | CONTRIBUTOR | null | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/144/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/144/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/144",
"html_url": "https://github.com/coleifer/peewee/pull/144",
"diff_url": "https://github.com/coleifer/peewee/pull/144.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/144.patch",
"merged_at": "2012-12-26T15:13:26"
} |
|
https://api.github.com/repos/coleifer/peewee/issues/143 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/143/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/143/comments | https://api.github.com/repos/coleifer/peewee/issues/143/events | https://github.com/coleifer/peewee/pull/143 | 9,520,706 | MDExOlB1bGxSZXF1ZXN0MzQ4Mjg2Mw== | 143 | Support pymysql. | {
"login": "methane",
"id": 199592,
"node_id": "MDQ6VXNlcjE5OTU5Mg==",
"avatar_url": "https://avatars.githubusercontent.com/u/199592?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/methane",
"html_url": "https://github.com/methane",
"followers_url": "https://api.github.com/users/methane/followers",
"following_url": "https://api.github.com/users/methane/following{/other_user}",
"gists_url": "https://api.github.com/users/methane/gists{/gist_id}",
"starred_url": "https://api.github.com/users/methane/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/methane/subscriptions",
"organizations_url": "https://api.github.com/users/methane/orgs",
"repos_url": "https://api.github.com/users/methane/repos",
"events_url": "https://api.github.com/users/methane/events{/privacy}",
"received_events_url": "https://api.github.com/users/methane/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2012-12-26T13:09:51 | 2014-07-06T01:51:31 | 2012-12-26T15:14:36 | CONTRIBUTOR | null | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/143/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/143/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/143",
"html_url": "https://github.com/coleifer/peewee/pull/143",
"diff_url": "https://github.com/coleifer/peewee/pull/143.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/143.patch",
"merged_at": "2012-12-26T15:14:36"
} |
|
https://api.github.com/repos/coleifer/peewee/issues/142 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/142/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/142/comments | https://api.github.com/repos/coleifer/peewee/issues/142/events | https://github.com/coleifer/peewee/pull/142 | 9,450,214 | MDExOlB1bGxSZXF1ZXN0MzQ1MjYwNw== | 142 | Primary key value 0 | {
"login": "arielrossanigo",
"id": 2752109,
"node_id": "MDQ6VXNlcjI3NTIxMDk=",
"avatar_url": "https://avatars.githubusercontent.com/u/2752109?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/arielrossanigo",
"html_url": "https://github.com/arielrossanigo",
"followers_url": "https://api.github.com/users/arielrossanigo/followers",
"following_url": "https://api.github.com/users/arielrossanigo/following{/other_user}",
"gists_url": "https://api.github.com/users/arielrossanigo/gists{/gist_id}",
"starred_url": "https://api.github.com/users/arielrossanigo/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/arielrossanigo/subscriptions",
"organizations_url": "https://api.github.com/users/arielrossanigo/orgs",
"repos_url": "https://api.github.com/users/arielrossanigo/repos",
"events_url": "https://api.github.com/users/arielrossanigo/events{/privacy}",
"received_events_url": "https://api.github.com/users/arielrossanigo/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I decided to fix this everywhere that a \"false-y\" value was used: 51328066c4c7b1d7c043c5e37fc06c519e9f168a\n",
"Great! thanks\n"
] | 2012-12-20T22:37:35 | 2014-07-06T01:51:33 | 2012-12-20T23:00:10 | CONTRIBUTOR | null | In an escenario where two tables are related and the value of the foreign key is 0, it raises an DoesNotExist exception. That's because 0 evaluates to False even when it's a real value.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/142/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/142/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/142",
"html_url": "https://github.com/coleifer/peewee/pull/142",
"diff_url": "https://github.com/coleifer/peewee/pull/142.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/142.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/141 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/141/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/141/comments | https://api.github.com/repos/coleifer/peewee/issues/141/events | https://github.com/coleifer/peewee/pull/141 | 9,415,188 | MDExOlB1bGxSZXF1ZXN0MzQzNTAwMQ== | 141 | IN operator and subqueries | {
"login": "arielrossanigo",
"id": 2752109,
"node_id": "MDQ6VXNlcjI3NTIxMDk=",
"avatar_url": "https://avatars.githubusercontent.com/u/2752109?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/arielrossanigo",
"html_url": "https://github.com/arielrossanigo",
"followers_url": "https://api.github.com/users/arielrossanigo/followers",
"following_url": "https://api.github.com/users/arielrossanigo/following{/other_user}",
"gists_url": "https://api.github.com/users/arielrossanigo/gists{/gist_id}",
"starred_url": "https://api.github.com/users/arielrossanigo/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/arielrossanigo/subscriptions",
"organizations_url": "https://api.github.com/users/arielrossanigo/orgs",
"repos_url": "https://api.github.com/users/arielrossanigo/repos",
"events_url": "https://api.github.com/users/arielrossanigo/events{/privacy}",
"received_events_url": "https://api.github.com/users/arielrossanigo/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Cool, i think we definitely need this. I think the extra state might be avoidable if we bind the selection a little later. I will look into that approach.\n"
] | 2012-12-19T21:18:39 | 2014-07-06T01:51:34 | 2012-12-19T22:19:32 | CONTRIBUTOR | null | This patch allows you to make a query with an IN operator where the subquery return another field than the "id".
For example, I have this two models:
``` python
class Customer(Model):
cust_number = IntegerField()
name = CharField()
....
class AccountLog(Model):
name = CharField()
internal_number = IntegerField() # this number is filled with the cust_number
.....
```
and I want to obtain all the Customers who doesn't have an account created.
This query resolve the problem
``` python
created_accounts = AccountLog.select(AccountLog.internal_number)
q = Customer.select().where(~(Customer.cust_number << created_accounts))
```
With this patch, the resulting SQL is:
``` SQL
SELECT t1."id", t1."cust_number", t1."name"
FROM "customer" AS t1
WHERE NOT (t1."cust_number" IN (
SELECT t2."internal_number"
FROM "accountlog" AS t2))
```
Sorry for my English....
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/141/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/141/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/141",
"html_url": "https://github.com/coleifer/peewee/pull/141",
"diff_url": "https://github.com/coleifer/peewee/pull/141.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/141.patch",
"merged_at": "2012-12-19T22:19:32"
} |
https://api.github.com/repos/coleifer/peewee/issues/140 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/140/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/140/comments | https://api.github.com/repos/coleifer/peewee/issues/140/events | https://github.com/coleifer/peewee/issues/140 | 9,410,037 | MDU6SXNzdWU5NDEwMDM3 | 140 | ImportError: cannot import name BinaryExpr | {
"login": "chrispaolini",
"id": 1413619,
"node_id": "MDQ6VXNlcjE0MTM2MTk=",
"avatar_url": "https://avatars.githubusercontent.com/u/1413619?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/chrispaolini",
"html_url": "https://github.com/chrispaolini",
"followers_url": "https://api.github.com/users/chrispaolini/followers",
"following_url": "https://api.github.com/users/chrispaolini/following{/other_user}",
"gists_url": "https://api.github.com/users/chrispaolini/gists{/gist_id}",
"starred_url": "https://api.github.com/users/chrispaolini/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/chrispaolini/subscriptions",
"organizations_url": "https://api.github.com/users/chrispaolini/orgs",
"repos_url": "https://api.github.com/users/chrispaolini/repos",
"events_url": "https://api.github.com/users/chrispaolini/events{/privacy}",
"received_events_url": "https://api.github.com/users/chrispaolini/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Yeah, binaryexpr is replaced with \"Expr\" - I did a refactor recently of those pieces in the commit you referenced.\n"
] | 2012-12-19T18:31:07 | 2012-12-19T20:53:36 | 2012-12-19T20:53:36 | NONE | null | It seems that there is a call to "BinaryExpr", but that doesn't exist.
Looks like it was removed in: 8f8e195480932a274cb3f9921538dfacb47d0bc7
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/140/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/140/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/139 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/139/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/139/comments | https://api.github.com/repos/coleifer/peewee/issues/139/events | https://github.com/coleifer/peewee/issues/139 | 9,402,240 | MDU6SXNzdWU5NDAyMjQw | 139 | R() objects and cloning | {
"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 | [
"Based on the testcases I committed, I can't replicate this error: 624a0e19ab085f3cd0d7\n"
] | 2012-12-19T14:44:30 | 2012-12-19T20:54:59 | 2012-12-19T20:54:59 | OWNER | null | <MikeSeth> [07:57:26] how do I do INTERVAL?
<MikeSeth> [07:57:56] e.g. I have an expression like NOW() - INTERVAL 1 HOUR
<MikeSeth> [08:15:55] nevermind, R()
<MikeSeth> [08:17:47] AttributeError: 'R' object has no attribute 'clone'
<MikeSeth> [08:17:49] hm.
<MikeSeth> [08:20:17] R isn't Expr?
<MikeSeth> [08:30:02] nevermind, RawQuery () :P
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/139/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/139/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/138 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/138/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/138/comments | https://api.github.com/repos/coleifer/peewee/issues/138/events | https://github.com/coleifer/peewee/issues/138 | 9,372,257 | MDU6SXNzdWU5MzcyMjU3 | 138 | Raise an exception when a reverse relation clobbers a field | {
"login": "coleifer",
"id": 119974,
"node_id": "MDQ6VXNlcjExOTk3NA==",
"avatar_url": "https://avatars.githubusercontent.com/u/119974?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/coleifer",
"html_url": "https://github.com/coleifer",
"followers_url": "https://api.github.com/users/coleifer/followers",
"following_url": "https://api.github.com/users/coleifer/following{/other_user}",
"gists_url": "https://api.github.com/users/coleifer/gists{/gist_id}",
"starred_url": "https://api.github.com/users/coleifer/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/coleifer/subscriptions",
"organizations_url": "https://api.github.com/users/coleifer/orgs",
"repos_url": "https://api.github.com/users/coleifer/repos",
"events_url": "https://api.github.com/users/coleifer/events{/privacy}",
"received_events_url": "https://api.github.com/users/coleifer/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2012-12-18T16:09:07 | 2012-12-19T21:06:21 | 2012-12-19T21:06:21 | OWNER | null | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/138/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/138/timeline | null | completed | null | null |
|
https://api.github.com/repos/coleifer/peewee/issues/137 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/137/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/137/comments | https://api.github.com/repos/coleifer/peewee/issues/137/events | https://github.com/coleifer/peewee/pull/137 | 9,360,526 | MDExOlB1bGxSZXF1ZXN0MzQwNjc2MA== | 137 | use backticks around table name, for inspect some specified table name | {
"login": "wayhome",
"id": 83735,
"node_id": "MDQ6VXNlcjgzNzM1",
"avatar_url": "https://avatars.githubusercontent.com/u/83735?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/wayhome",
"html_url": "https://github.com/wayhome",
"followers_url": "https://api.github.com/users/wayhome/followers",
"following_url": "https://api.github.com/users/wayhome/following{/other_user}",
"gists_url": "https://api.github.com/users/wayhome/gists{/gist_id}",
"starred_url": "https://api.github.com/users/wayhome/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/wayhome/subscriptions",
"organizations_url": "https://api.github.com/users/wayhome/orgs",
"repos_url": "https://api.github.com/users/wayhome/repos",
"events_url": "https://api.github.com/users/wayhome/events{/privacy}",
"received_events_url": "https://api.github.com/users/wayhome/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2012-12-18T08:36:36 | 2014-07-06T01:51:36 | 2012-12-18T15:27:29 | CONTRIBUTOR | null | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/137/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/137/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/137",
"html_url": "https://github.com/coleifer/peewee/pull/137",
"diff_url": "https://github.com/coleifer/peewee/pull/137.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/137.patch",
"merged_at": "2012-12-18T15:27:29"
} |
|
https://api.github.com/repos/coleifer/peewee/issues/136 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/136/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/136/comments | https://api.github.com/repos/coleifer/peewee/issues/136/events | https://github.com/coleifer/peewee/pull/136 | 9,334,869 | MDExOlB1bGxSZXF1ZXN0MzM5NDA0Ng== | 136 | Support for same-name tables in multi-schema dbs | {
"login": "irumiha",
"id": 100465,
"node_id": "MDQ6VXNlcjEwMDQ2NQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/100465?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/irumiha",
"html_url": "https://github.com/irumiha",
"followers_url": "https://api.github.com/users/irumiha/followers",
"following_url": "https://api.github.com/users/irumiha/following{/other_user}",
"gists_url": "https://api.github.com/users/irumiha/gists{/gist_id}",
"starred_url": "https://api.github.com/users/irumiha/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/irumiha/subscriptions",
"organizations_url": "https://api.github.com/users/irumiha/orgs",
"repos_url": "https://api.github.com/users/irumiha/repos",
"events_url": "https://api.github.com/users/irumiha/events{/privacy}",
"received_events_url": "https://api.github.com/users/irumiha/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Hey, thanks a ton for this! I will look into merging it this week.\n"
] | 2012-12-17T14:46:03 | 2014-07-06T01:51:37 | 2012-12-17T14:53:30 | CONTRIBUTOR | null | I have a scenario with a Postgres multi-schema database with tables with identical names in different schemas. This patch fixes the foreign-key resolution for such tables.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/136/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/136/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/136",
"html_url": "https://github.com/coleifer/peewee/pull/136",
"diff_url": "https://github.com/coleifer/peewee/pull/136.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/136.patch",
"merged_at": "2012-12-17T14:53:30"
} |
https://api.github.com/repos/coleifer/peewee/issues/135 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/135/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/135/comments | https://api.github.com/repos/coleifer/peewee/issues/135/events | https://github.com/coleifer/peewee/issues/135 | 9,006,330 | MDU6SXNzdWU5MDA2MzMw | 135 | Select a random record from db peewee 2.04 | {
"login": "hernantz",
"id": 613512,
"node_id": "MDQ6VXNlcjYxMzUxMg==",
"avatar_url": "https://avatars.githubusercontent.com/u/613512?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/hernantz",
"html_url": "https://github.com/hernantz",
"followers_url": "https://api.github.com/users/hernantz/followers",
"following_url": "https://api.github.com/users/hernantz/following{/other_user}",
"gists_url": "https://api.github.com/users/hernantz/gists{/gist_id}",
"starred_url": "https://api.github.com/users/hernantz/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/hernantz/subscriptions",
"organizations_url": "https://api.github.com/users/hernantz/orgs",
"repos_url": "https://api.github.com/users/hernantz/repos",
"events_url": "https://api.github.com/users/hernantz/events{/privacy}",
"received_events_url": "https://api.github.com/users/hernantz/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"You probably want something like this:\n\n``` python\n\nfrom peewee import *\n\nrandom_query = SomeModel.select().order_by(fn.Random())\none_obj = random_query.get()\n```\n",
"Thanks! worked.\nIs this in the docs?\n",
"Nah, i'll add it maybe but its standard 'sql' practice.\n"
] | 2012-12-05T02:06:58 | 2012-12-10T15:03:56 | 2012-12-05T02:49:07 | NONE | null | Any example of how to get a random object from a model?
Thanks in advance.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/135/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/135/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/134 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/134/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/134/comments | https://api.github.com/repos/coleifer/peewee/issues/134/events | https://github.com/coleifer/peewee/issues/134 | 9,003,371 | MDU6SXNzdWU5MDAzMzcx | 134 | Results as dict/array of dict? | {
"login": "rcarmo",
"id": 392683,
"node_id": "MDQ6VXNlcjM5MjY4Mw==",
"avatar_url": "https://avatars.githubusercontent.com/u/392683?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/rcarmo",
"html_url": "https://github.com/rcarmo",
"followers_url": "https://api.github.com/users/rcarmo/followers",
"following_url": "https://api.github.com/users/rcarmo/following{/other_user}",
"gists_url": "https://api.github.com/users/rcarmo/gists{/gist_id}",
"starred_url": "https://api.github.com/users/rcarmo/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/rcarmo/subscriptions",
"organizations_url": "https://api.github.com/users/rcarmo/orgs",
"repos_url": "https://api.github.com/users/rcarmo/repos",
"events_url": "https://api.github.com/users/rcarmo/events{/privacy}",
"received_events_url": "https://api.github.com/users/rcarmo/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"### Edit\r\n\r\nThis issue was 8 years old when it was brought to my attention again. Here are the methods you would want to use:\r\n\r\n* [dicts()](http://docs.peewee-orm.com/en/latest/peewee/api.html#BaseQuery.dicts)\r\n* [tuples()](http://docs.peewee-orm.com/en/latest/peewee/api.html#BaseQuery.tuples)\r\n* [namedtuples()](http://docs.peewee-orm.com/en/latest/peewee/api.html#BaseQuery.namedtuples)\r\n\r\n```python\r\nquery = SomeModel.select().dicts()\r\nfor row in query: # Each row is a dict.\r\n print(row['id'])\r\n```\r\n\r\nThe information further down is no longer correct.\r\n\r\nSee comment:\r\n\r\nhttps://github.com/coleifer/peewee/issues/134#issuecomment-704935841\r\n\r\n----------------------------\r\n\r\nI'm not sure why this should be a part of peewee itself, unless for performance reasons you're concerned about the overhead of class creation. You can see in flask-peewee some helpers already exist:\r\n- https://github.com/coleifer/flask-peewee/blob/master/flask_peewee/serializer.py\r\n- https://github.com/coleifer/flask-peewee/blob/master/flask_peewee/utils.py#L65\r\n\r\nYou can save by not creating model instances by iterating over the cursor:\r\n\r\n``` python\r\n\r\ndb = SqliteDatabase(...)\r\n\r\nquery = SomeModel.select()\r\ncursor = db.execute(query)\r\n\r\nncols = len(cursor.description)\r\ncolnames = [cursor.description[i][0] for i in range(ncols)]\r\nresults = []\r\n\r\nfor row in cursor.fetchall():\r\n res = {}\r\n for i in range(ncols):\r\n res[colnames[i]] = row[i]\r\n results.append(res)\r\n```\r\n\r\nIf you want to get even more low-level, you can take the sql generated by peewee and use a row factory:\r\n- http://docs.python.org/2/library/sqlite3.html#row-objects\r\n",
"Well, actually, because it's cumbersome to do that even for single rows - getting a dict out of a row makes it much easier to do functional coding than iterating through the column names, and even though I usually do use row factories when using SQL directly, that's the kind of thing I expect a model to do for me.\n\nSo please consider doing this, at least for single rows.\n\n(also, I'm not using flask)\n\nOn Dec 5, 2012, at 03:00 , Charles Leifer [email protected] wrote:\n\n> I'm not sure why this should be a part of peewee itself, unless for performance reasons you're concerned about the overhead of class creation. You can see in flask-peewee some helpers already exist:\n> \n> https://github.com/coleifer/flask-peewee/blob/master/flask_peewee/serializer.py\n> https://github.com/coleifer/flask-peewee/blob/master/flask_peewee/utils.py#L65\n> You can save by not creating model instances by iterating over the cursor:\n> \n> db = SqliteDatabase(...)\n> \n> query = SomeModel.select()\n> cursor = db.execute(query)\n> \n> ncols = len(cursor.description)\n> colnames = [cursor.description[i][0] for i in range(ncols)]\n> results = []\n> \n> for row in cursor.fetchall():\n> res = {}\n> for i in range(ncols):\n> res[colnames[i]] = row[i]\n> results.append(res)\n> If you want to get even more low-level, you can take the sql generated by peewee and use a row factory:\n> \n> http://docs.python.org/2/library/sqlite3.html#row-objects\n> —\n> Reply to this email directly or view it on GitHub.\n",
"If it's not for performance reasons, you could probably just use a helper @coleifer linked to and so something like that. I haven't tested this though.\n\n``` python\n\nfrom itertools import imap\nfrom flask_peewee.utils import get_dictionary_from_model\n\nfor dct in imap(get_dictionary_from_model, model.select()):\n print dct\n```\n\nOr if that's too much code to write everytime, define your own BaseModel and wrap `select`.\n",
"Yeah, as @squiddy said -- there are a lot of ways to do this, and if it is not for performance reasons just wrap select(), or give your model instances an \"to_dict()\" method or something.\n",
":japanese_ogre: \n",
"As I do In MySQL (as I didn't check others):\r\n\r\n1. `select().execute()` in one step\r\n2. iterate through cursorwrapper\r\n3. getting values by literal column names through Model attributes instead of numeric indexing, as former is more straightforward for me\r\n\r\n```\r\ncursorwrapper = SomeModel.select().execute()\r\n\r\ncolnames = [name[0] for name in cursorwrapper.cursor.description]\r\nresults = []\r\n\r\nfor row in cursorwrapper:\r\n res = {}\r\n for cname in colnames:\r\n res[cname] = getattr(row, cname)\r\n results.append(res)\r\n```",
"This is 8 years old. For quite a long time, Peewee has supported this out-of-the-box with the following query methods:\r\n\r\n* [dicts()](http://docs.peewee-orm.com/en/latest/peewee/api.html#BaseQuery.dicts)\r\n* [tuples()](http://docs.peewee-orm.com/en/latest/peewee/api.html#BaseQuery.tuples)\r\n* [namedtuples()](http://docs.peewee-orm.com/en/latest/peewee/api.html#BaseQuery.namedtuples)",
"@coleifer Thank you for your info and your work.",
"Though as @coleifer pointed out that this is a 8 years old post, but as this github issue is among the top finds of search engines regarding this topic and I didn't find a good example code for usage of the pretty useful `dicts()` method (thank to @coleifer of course), I decided to post one for future readers:\r\n\r\n```\r\nquery = SomeModel.select().dicts()\r\n\r\nfor row in query:\r\n print(type(row))\r\n```\r\n**Out:**\r\n```\r\n<class 'dict'>\r\n<class 'dict'>\r\n.\r\n.\r\n<class 'dict'>\r\n```",
"More concisely retaining the query:\r\n```python\r\nquery = SomeModel.select()\r\nprint(list(query.dicts()))\r\n```\r\nOne liner:\r\n```python\r\nprint(list(SomeModel.select().dicts))\r\n```"
] | 2012-12-04T23:45:05 | 2022-11-08T16:44:31 | 2012-12-05T03:00:18 | CONTRIBUTOR | null | It would be grand if one could do something like this:
```
>>> m = Model()
>>> print m.select()
[{'id':1, 'name':'foo'},{'id':2, 'name':'bar'}]
```
i.e., returning each row as a dict. This would be especially handy for returning JSON result sets, and could probably be done using **iter** to return self._data for the model.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/134/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/134/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/133 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/133/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/133/comments | https://api.github.com/repos/coleifer/peewee/issues/133/events | https://github.com/coleifer/peewee/issues/133 | 8,970,186 | MDU6SXNzdWU4OTcwMTg2 | 133 | Ordering in 2.0.4 | {
"login": "dkadish",
"id": 181041,
"node_id": "MDQ6VXNlcjE4MTA0MQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/181041?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/dkadish",
"html_url": "https://github.com/dkadish",
"followers_url": "https://api.github.com/users/dkadish/followers",
"following_url": "https://api.github.com/users/dkadish/following{/other_user}",
"gists_url": "https://api.github.com/users/dkadish/gists{/gist_id}",
"starred_url": "https://api.github.com/users/dkadish/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/dkadish/subscriptions",
"organizations_url": "https://api.github.com/users/dkadish/orgs",
"repos_url": "https://api.github.com/users/dkadish/repos",
"events_url": "https://api.github.com/users/dkadish/events{/privacy}",
"received_events_url": "https://api.github.com/users/dkadish/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2012-12-04T01:03:06 | 2012-12-04T01:17:46 | 2012-12-04T01:17:46 | NONE | null | In the Meta class in v1, ordering is done by
``` python
class Meta:
ordering = (('col1', 'desc'), ('col2', 'asc')
```
In version 2, this has changed to:
``` python
class Meta:
order_by = ('-col1', 'col2') # I think I have my signs right here...
```
That's not reflected in the docs in https://peewee.readthedocs.org/en/latest/peewee/upgrading.html.
https://peewee.readthedocs.org/en/latest/peewee/models.html hints at it, but the example still shows the old `ordering` instead of `order_by` which throws an error.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/133/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/133/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/132 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/132/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/132/comments | https://api.github.com/repos/coleifer/peewee/issues/132/events | https://github.com/coleifer/peewee/issues/132 | 8,628,835 | MDU6SXNzdWU4NjI4ODM1 | 132 | Integer Primary Key won't save the data | {
"login": "coderbuzz",
"id": 1284811,
"node_id": "MDQ6VXNlcjEyODQ4MTE=",
"avatar_url": "https://avatars.githubusercontent.com/u/1284811?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/coderbuzz",
"html_url": "https://github.com/coderbuzz",
"followers_url": "https://api.github.com/users/coderbuzz/followers",
"following_url": "https://api.github.com/users/coderbuzz/following{/other_user}",
"gists_url": "https://api.github.com/users/coderbuzz/gists{/gist_id}",
"starred_url": "https://api.github.com/users/coderbuzz/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/coderbuzz/subscriptions",
"organizations_url": "https://api.github.com/users/coderbuzz/orgs",
"repos_url": "https://api.github.com/users/coderbuzz/repos",
"events_url": "https://api.github.com/users/coderbuzz/events{/privacy}",
"received_events_url": "https://api.github.com/users/coderbuzz/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"So...you want periode to be the primary key _and_ you want it to be the values from 1 -> 60. Explicitly setting the primary key can be accomplished in a couple of ways... I'd suggest reading the code for the save() method.\n\nYou can `save(force_insert=True)`. You can manually create and execute an InsertQuery (recommended way).\n\niq = TableMargin.insert(periode=x, margin=y)\niq.execute()\n",
"OK, so I changed the code and now works as expected (auto insert/update):\n\n``` python\ndef set_margin(periode, margin):\n query = TabelMargin.select().where(TabelMargin.periode==periode)\n\n with db_transaction():\n item = first_record(query) or TabelMargin()\n force_insert = item.periode == None\n item.periode = periode\n item.margin = margin\n item.save(force_insert=force_insert)\n return item\n```\n"
] | 2012-11-24T13:00:49 | 2012-11-24T23:13:41 | 2012-11-24T15:50:33 | NONE | null | ``` python
class TableMargin(BaseModel):
class Meta:
db_table = 'tabel_margin'
periode = IntegerField(primary_key=True)
margin = FloatField()
def set_margin(periode, margin):
query = TabelMargin.select().where(TabelMargin.periode==periode)
with db_transaction():
item = first_record(query) or TabelMargin()
item.periode = periode
item.margin = margin
item.save()
return item
margin = 0.5000
for n in xrange(1, 61):
margin += 0.0016
set_margin(n, margin)
```
Code above won't save the data to database.
Changed to the following structure the results works-well; but I DON'T need the ID field because PERIODE field already unique (it should be a PrimaryKey)
``` python
class TableMargin(BaseModel):
class Meta:
db_table = 'tabel_margin'
periode = IntegerField(unique=True)
margin = FloatField()
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/132/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/132/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/131 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/131/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/131/comments | https://api.github.com/repos/coleifer/peewee/issues/131/events | https://github.com/coleifer/peewee/issues/131 | 8,563,021 | MDU6SXNzdWU4NTYzMDIx | 131 | unique index creation breaks on mysql innodb + utf8mb4 + charfield | {
"login": "jamesonjlee",
"id": 698668,
"node_id": "MDQ6VXNlcjY5ODY2OA==",
"avatar_url": "https://avatars.githubusercontent.com/u/698668?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/jamesonjlee",
"html_url": "https://github.com/jamesonjlee",
"followers_url": "https://api.github.com/users/jamesonjlee/followers",
"following_url": "https://api.github.com/users/jamesonjlee/following{/other_user}",
"gists_url": "https://api.github.com/users/jamesonjlee/gists{/gist_id}",
"starred_url": "https://api.github.com/users/jamesonjlee/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/jamesonjlee/subscriptions",
"organizations_url": "https://api.github.com/users/jamesonjlee/orgs",
"repos_url": "https://api.github.com/users/jamesonjlee/repos",
"events_url": "https://api.github.com/users/jamesonjlee/events{/privacy}",
"received_events_url": "https://api.github.com/users/jamesonjlee/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Dude...\n\nJust subclass charfield and provide a default maxlength and use that.\n"
] | 2012-11-22T00:06:12 | 2012-11-22T00:16:14 | 2012-11-22T00:16:13 | NONE | null | hi,
I found that the default CharField() is a varchar of length 255, this makes mysql throw error 1071 because in innodb the maximum length of a index is 767 bytes (~190 utf8mb4). default utf8 will fit 255 chars.
Would it be possible to have peewee detect that the database is using utf8mb4 and adjust it accordingly? or should I be creating a UTF8MB4CharField() and make it do CharFIeld(max_length=190) ?
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/131/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/131/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/130 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/130/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/130/comments | https://api.github.com/repos/coleifer/peewee/issues/130/events | https://github.com/coleifer/peewee/issues/130 | 8,491,122 | MDU6SXNzdWU4NDkxMTIy | 130 | TypeError: 'NoneType' object does not support item assignment when trying to select from tables after 0.9.2 to 2.0.4 upgrade | {
"login": "skruger",
"id": 201151,
"node_id": "MDQ6VXNlcjIwMTE1MQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/201151?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/skruger",
"html_url": "https://github.com/skruger",
"followers_url": "https://api.github.com/users/skruger/followers",
"following_url": "https://api.github.com/users/skruger/following{/other_user}",
"gists_url": "https://api.github.com/users/skruger/gists{/gist_id}",
"starred_url": "https://api.github.com/users/skruger/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/skruger/subscriptions",
"organizations_url": "https://api.github.com/users/skruger/orgs",
"repos_url": "https://api.github.com/users/skruger/repos",
"events_url": "https://api.github.com/users/skruger/events{/privacy}",
"received_events_url": "https://api.github.com/users/skruger/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Are you overriding **init** on the model class? Also, Xmpp! Cool!\n",
"I wasn't implementing init in my models directly so I didn't think the solution from issue #118 was applicable until I checked my BaseSql class. I added the fix from #118 to BaseSql and that resolved my problem.\n\n``` python\nclass BaseSql(peewee.Model):\n\n class Meta:\n database = database\n def __init__(self, *args, **kwargs):\n super(BaseSql, self).__init__()\n ... etc ...\n\nclass XmppDomain(BaseSql):\n .... etc ....\n```\n\nIt sounds like you like XMPP. The app I'm working on is the chatmongers.com management portal. We picked peewee when we decided to port the app out of Google App Engine.\n",
"Awesome glad that fixed it! Very cool site, i'm flattered you picked peewee!\n",
"just ran in to a similar issue, fixed by calling super at the top of my model's **init** as referenced in #118\n"
] | 2012-11-20T02:46:27 | 2016-10-22T15:25:47 | 2012-11-20T06:29:53 | NONE | null | I'm upgrading my application to the current version of peewee and many of my models are failing the same way when I try to query them. Most of my accesses happen within @classmethod calls so I did one manually from the command line and I get the same error. I'm not sure what I'm doing wrong or what other details might help with this, but I thought I'd see if this was a known problem and I'm just messing up something simple. Nothing has changed about the definition of this table in my upgrade process. However, I did define a new model, called create_table(), and it seems to work.
Here is the stack trace. I'm running python2.7 and installed peewee 2.0.4 using pip.
``` python
>>> XmppDomain.select().where(XmppDomain.fqdn == "kxgx.chatwith.it").get()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/site-packages/peewee.py", line 1285, in get
return clone.execute().next()
File "/usr/local/lib/python2.7/site-packages/peewee.py", line 979, in next
instance = self.iterate()
File "/usr/local/lib/python2.7/site-packages/peewee.py", line 965, in iterate
return self.simple_iter(row)
File "/usr/local/lib/python2.7/site-packages/peewee.py", line 899, in simple_iter
setattr(instance, f.name, f.python_value(row[i]))
File "/usr/local/lib/python2.7/site-packages/peewee.py", line 218, in __set__
instance._data[self.att_name] = value
TypeError: 'NoneType' object does not support item assignment
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/130/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/130/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/129 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/129/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/129/comments | https://api.github.com/repos/coleifer/peewee/issues/129/events | https://github.com/coleifer/peewee/issues/129 | 8,450,947 | MDU6SXNzdWU4NDUwOTQ3 | 129 | "Offline" support for ForeignKeyField (related_name) | {
"login": "kr2",
"id": 1094983,
"node_id": "MDQ6VXNlcjEwOTQ5ODM=",
"avatar_url": "https://avatars.githubusercontent.com/u/1094983?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/kr2",
"html_url": "https://github.com/kr2",
"followers_url": "https://api.github.com/users/kr2/followers",
"following_url": "https://api.github.com/users/kr2/following{/other_user}",
"gists_url": "https://api.github.com/users/kr2/gists{/gist_id}",
"starred_url": "https://api.github.com/users/kr2/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/kr2/subscriptions",
"organizations_url": "https://api.github.com/users/kr2/orgs",
"repos_url": "https://api.github.com/users/kr2/repos",
"events_url": "https://api.github.com/users/kr2/events{/privacy}",
"received_events_url": "https://api.github.com/users/kr2/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"The implementation of reverse relations is a SelectQuery, which requires a database call.\n"
] | 2012-11-18T15:30:25 | 2012-11-18T15:34:30 | 2012-11-18T15:34:30 | NONE | null | I think it would be nice if one could do something like below. So stepping though the "children" before saving them.
``` python
import peewee as pw
class Parent(pw.Model):
name = pw.TextField()
class Child(pw.Model):
parent = pw.ForeignKeyField(Parent, related_name='children')
name = pw.TextField()
p1 = Parent(name = 'p1')
c1 = Child(parent = p1, name = 'c1')
c2 = Child(parent = p1, name = 'c2')
for child in p1.children:
print child.name
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/129/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/129/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/128 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/128/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/128/comments | https://api.github.com/repos/coleifer/peewee/issues/128/events | https://github.com/coleifer/peewee/issues/128 | 8,447,594 | MDU6SXNzdWU4NDQ3NTk0 | 128 | Create Table Failed | {
"login": "coderbuzz",
"id": 1284811,
"node_id": "MDQ6VXNlcjEyODQ4MTE=",
"avatar_url": "https://avatars.githubusercontent.com/u/1284811?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/coderbuzz",
"html_url": "https://github.com/coderbuzz",
"followers_url": "https://api.github.com/users/coderbuzz/followers",
"following_url": "https://api.github.com/users/coderbuzz/following{/other_user}",
"gists_url": "https://api.github.com/users/coderbuzz/gists{/gist_id}",
"starred_url": "https://api.github.com/users/coderbuzz/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/coderbuzz/subscriptions",
"organizations_url": "https://api.github.com/users/coderbuzz/orgs",
"repos_url": "https://api.github.com/users/coderbuzz/repos",
"events_url": "https://api.github.com/users/coderbuzz/events{/privacy}",
"received_events_url": "https://api.github.com/users/coderbuzz/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I wasn't able to replicate this locally. What commit/version of peewee do you use and what database backend are you using? Was there any more information in that traceback?\n\nPart of why I'm confused: https://github.com/coleifer/peewee/blob/master/peewee.py#L1968 --- blank?\n",
"Wow I'm using Unstable\\2.0 version,\n\n``` python\n 1967 if cls._meta.indexes:\n 1968 for fields, unique in cls._meta.indexes:\n 1969 db.create_index(cls, fields, unique)\n```\n\nOK trying pull the master branch, it is 2.0 version rights?\n",
"Pulled from master branch, no problem here. Sorry for this, case closed.\n"
] | 2012-11-18T04:39:58 | 2012-11-18T06:05:42 | 2012-11-18T06:05:42 | NONE | null | ``` python
class SomeModel(BaseModel):
nama = CharField(max_length=30, index=True)
kategori = CharField(max_length=30, index=True)
value = CharField(max_length=255, null=True)
keterangan = CharField(max_length=255, null=True)
SomeModel.create_table()
```
_Traceback (most recent call last):
File "D:\Codes\Python\Kisel-SIMPIN\main.py", line 3, in <module> from app import app
File "D:\Codes\Python\Kisel-SIMPIN\app.py", line 54, in <module> import imports
File "D:\Codes\Python\Kisel-SIMPIN\imports.py", line 6, in <module> import model
File "D:\Codes\Python\Kisel-SIMPIN\model.py", line 478, in <module> SomeModel.create_table()
File "build\bdist.win32\egg\peewee.py", line 1968, in create_table ValueError: too many values to unpack_
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/128/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/128/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/127 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/127/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/127/comments | https://api.github.com/repos/coleifer/peewee/issues/127/events | https://github.com/coleifer/peewee/issues/127 | 8,227,913 | MDU6SXNzdWU4MjI3OTEz | 127 | update query overwrites id with single value | {
"login": "davidthewatson",
"id": 150892,
"node_id": "MDQ6VXNlcjE1MDg5Mg==",
"avatar_url": "https://avatars.githubusercontent.com/u/150892?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/davidthewatson",
"html_url": "https://github.com/davidthewatson",
"followers_url": "https://api.github.com/users/davidthewatson/followers",
"following_url": "https://api.github.com/users/davidthewatson/following{/other_user}",
"gists_url": "https://api.github.com/users/davidthewatson/gists{/gist_id}",
"starred_url": "https://api.github.com/users/davidthewatson/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/davidthewatson/subscriptions",
"organizations_url": "https://api.github.com/users/davidthewatson/orgs",
"repos_url": "https://api.github.com/users/davidthewatson/repos",
"events_url": "https://api.github.com/users/davidthewatson/events{/privacy}",
"received_events_url": "https://api.github.com/users/davidthewatson/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Updates follow the sql update query syntax, so in your example the queries executed are:\n\n``` sql\nupdate ornaments set id=%s, likes=%s\n```\n\nWhat you want is:\n\n``` sql\nupdate ornametns set likes=%s where id = %s\n```\n\nSo:\n\n``` python\nfor id, like in zip(ids, likes):\n o = Ornaments.update(likes=like).where(Ornaments.id == id)\n o.execute()\n```\n\nPlease let me know if this fixes the issue!\n",
"Yep, thanks.\n"
] | 2012-11-09T05:15:55 | 2012-11-15T13:17:15 | 2012-11-14T14:18:37 | NONE | null | I have the following models, mostly generated from pwiz. I'm using peewee 2.0.3 on linux with mysql.
```
class Users(BaseModel):
"""The users database model."""
fbid = BigIntegerField()
fbname = CharField()
lastsession = CharField()
playedts = IntegerField()
class Meta:
db_table = 'users'
class Ornaments(BaseModel):
"""The ornaments database model."""
dedicatedto = CharField()
likes = IntegerField()
message = CharField()
userid = ForeignKeyField(Users, db_column='fbid')
x = IntegerField()
y = IntegerField()
```
I have the following code:
```
print ids, likes
assert(len(likes) == len(ids))
with database.transaction():
for id, like in zip(ids, likes):
print id, like
o = Ornaments.update(id=id, likes=like)
o.execute()
print len(likes), 'records updated at', datetime.now()
```
which outputs:
```
[1, 2, 3] [0, 0, 0]
1 0
2 0
3 0
3 records updated.
[3, 3, 3] [0]
```
and then fails on the following assert because the ids and likes lists aren't parallel. I don't understand why the id is getting updated with the constant 3 instead of the 1,2,3 sequence indicated by the print output?
Thanks!
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/127/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/127/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/126 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/126/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/126/comments | https://api.github.com/repos/coleifer/peewee/issues/126/events | https://github.com/coleifer/peewee/issues/126 | 7,992,687 | MDU6SXNzdWU3OTkyNjg3 | 126 | Select with outer changes | {
"login": "efreeze",
"id": 473909,
"node_id": "MDQ6VXNlcjQ3MzkwOQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/473909?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/efreeze",
"html_url": "https://github.com/efreeze",
"followers_url": "https://api.github.com/users/efreeze/followers",
"following_url": "https://api.github.com/users/efreeze/following{/other_user}",
"gists_url": "https://api.github.com/users/efreeze/gists{/gist_id}",
"starred_url": "https://api.github.com/users/efreeze/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/efreeze/subscriptions",
"organizations_url": "https://api.github.com/users/efreeze/orgs",
"repos_url": "https://api.github.com/users/efreeze/repos",
"events_url": "https://api.github.com/users/efreeze/events{/privacy}",
"received_events_url": "https://api.github.com/users/efreeze/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Thanks for reporting. I believe the problem is your connection isolation level is \"read committed\", meaning once your transaction begins (implicitly with the first select), it will only read rows committed before that transaction was initiated. When you `commit()` on the connection and a new transaction begins, it picks up the new rows.\n\nI think the solution here will be, like you say, to simply commit after select() queries.\n"
] | 2012-10-31T08:58:15 | 2012-10-31T14:00:55 | 2012-10-31T14:00:55 | NONE | null | Model:
``` python
database = MySQLDatabase('blah', **{...})
class BaseModel(Model):
class Meta:
database = database
class Zone(BaseModel):
field = IntegerField()
Query on empty table:
Zone.select().where(Zone.field == 1).count()
```
It returns 0 items.
The application is running.
I'm insert into table new record (using phpMyAdmin):
INSERT INTO `zone` (`field`) VALUES (1)
Carry out a query for a non-empty table:
Zone.select().where(Zone.field == 1).count()
It returns 0 items too.
It's wrong, in table 1 record exists.
The application must be restarted.
If I make Database implement MySQLDatabase with property commit_select = True:
class Database(MySQLDatabase):
commit_select = True
database = Database('blah', **{...})
Query returns 1 item. It's right.
Maybe you should make commit_select property changeable?
P.S. Sorry, I speak English bad :-)
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/126/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/126/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/125 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/125/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/125/comments | https://api.github.com/repos/coleifer/peewee/issues/125/events | https://github.com/coleifer/peewee/issues/125 | 7,945,306 | MDU6SXNzdWU3OTQ1MzA2 | 125 | AttributeError: 'MySQLDatabase' object has no attribute 'quote' | {
"login": "kr2",
"id": 1094983,
"node_id": "MDQ6VXNlcjEwOTQ5ODM=",
"avatar_url": "https://avatars.githubusercontent.com/u/1094983?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/kr2",
"html_url": "https://github.com/kr2",
"followers_url": "https://api.github.com/users/kr2/followers",
"following_url": "https://api.github.com/users/kr2/following{/other_user}",
"gists_url": "https://api.github.com/users/kr2/gists{/gist_id}",
"starred_url": "https://api.github.com/users/kr2/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/kr2/subscriptions",
"organizations_url": "https://api.github.com/users/kr2/orgs",
"repos_url": "https://api.github.com/users/kr2/repos",
"events_url": "https://api.github.com/users/kr2/events{/privacy}",
"received_events_url": "https://api.github.com/users/kr2/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"This has actually been fixed for a while, I just need to push a new release. Will do so now.\n"
] | 2012-10-29T17:41:16 | 2012-10-30T03:14:56 | 2012-10-30T03:14:56 | NONE | null | C:\Python27\lib\site-packages\peewee-2.0.2-py2.7.egg\peewee.py in create_table(cls, fail_silently)
2003 for field_name, field_obj in cls._meta.fields.items():
2004 if isinstance(field_obj, ForeignKeyField):
-> 2005 db.create_foreign_key(cls, field_obj)
2006 elif field_obj.index or field_obj.unique:
2007 db.create_index(cls, [field_obj], field_obj.unique)
C:\Python27\lib\site-packages\peewee-2.0.2-py2.7.egg\peewee.py in create_foreign_key(self, model_class, field)
1744
1745 query = framing % {
-> 1746 'table': self.quote(db_table),
1747 'constraint': self.quote(constraint),
1748 'field': self.quote(field.db_column),
AttributeError: 'MySQLDatabase' object has no attribute 'quote'
######
diry hack (copy and paste from the QueryCompiler class):
--- peewee.py Mon Oct 29 17:34:38 2012
+++ peewee_OK.py Mon Oct 29 17:32:29 2012
@@ -1730,6 +1730,9 @@ class MySQLDatabase(Database):
conn_kwargs.update(kwargs)
return mysql.connect(db=database, **conn_kwargs)
- def quote(self, s):
- return ''.join((self.quote_char, s, self.quote_char))
+
def create_foreign_key(self, model_class, field):
framing = """
ALTER TABLE %(table)s ADD CONSTRAINT %(constraint)s
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/125/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/125/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/124 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/124/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/124/comments | https://api.github.com/repos/coleifer/peewee/issues/124/events | https://github.com/coleifer/peewee/issues/124 | 7,934,039 | MDU6SXNzdWU3OTM0MDM5 | 124 | logger name should be 'peewee' or __name__ | {
"login": "vsajip",
"id": 130553,
"node_id": "MDQ6VXNlcjEzMDU1Mw==",
"avatar_url": "https://avatars.githubusercontent.com/u/130553?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/vsajip",
"html_url": "https://github.com/vsajip",
"followers_url": "https://api.github.com/users/vsajip/followers",
"following_url": "https://api.github.com/users/vsajip/following{/other_user}",
"gists_url": "https://api.github.com/users/vsajip/gists{/gist_id}",
"starred_url": "https://api.github.com/users/vsajip/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/vsajip/subscriptions",
"organizations_url": "https://api.github.com/users/vsajip/orgs",
"repos_url": "https://api.github.com/users/vsajip/repos",
"events_url": "https://api.github.com/users/vsajip/events{/privacy}",
"received_events_url": "https://api.github.com/users/vsajip/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2012-10-29T12:22:43 | 2012-10-30T03:12:57 | 2012-10-30T03:12:57 | NONE | null | NBD, but it would be better if the logger name you used were either 'peewee' or **name**. This would be more important if peewee ever became a package as opposed to a single module.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/124/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/124/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/123 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/123/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/123/comments | https://api.github.com/repos/coleifer/peewee/issues/123/events | https://github.com/coleifer/peewee/issues/123 | 7,929,740 | MDU6SXNzdWU3OTI5NzQw | 123 | Create Unique index fails | {
"login": "skid",
"id": 240319,
"node_id": "MDQ6VXNlcjI0MDMxOQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/240319?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/skid",
"html_url": "https://github.com/skid",
"followers_url": "https://api.github.com/users/skid/followers",
"following_url": "https://api.github.com/users/skid/following{/other_user}",
"gists_url": "https://api.github.com/users/skid/gists{/gist_id}",
"starred_url": "https://api.github.com/users/skid/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/skid/subscriptions",
"organizations_url": "https://api.github.com/users/skid/orgs",
"repos_url": "https://api.github.com/users/skid/repos",
"events_url": "https://api.github.com/users/skid/events{/privacy}",
"received_events_url": "https://api.github.com/users/skid/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Oh, I see this is fixed in the Github version... Sorry.\n",
"I'll push an update today or tomorrow\n"
] | 2012-10-29T09:08:06 | 2012-10-29T14:55:41 | 2012-10-29T09:20:01 | NONE | null | I'm using Peewee 2.0.2 (installed with pip), my model looks like this:
```
class Settings(Model):
key = CharField(max_length=25, index=True, unique=True)
value = CharField()
vtype = CharField(max_length=6)
class Meta:
db_table = 'settings'
```
When I run `Settings.create_table()` the following error happens:
```
File "......./peewee.py", line 2008, in create_table
for fields, unique in cls._meta.indexes:
ValueError: too many values to unpack
```
When I check Settings._meta.indexes, it has the following value: `['key']` - hence the error.
If I comment these lines out - everything works fine since the field indexes are added immediately before this code is executed:
```
if cls._meta.indexes:
for fields, unique in cls._meta.indexes:
db.create_index(cls, fields, unique)
```
I know that these code should add the indexes defined in the `Meta` class - but in that case the indexes defined in the model field definitions should not be appended to self._meta.indexes.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/123/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/123/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/122 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/122/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/122/comments | https://api.github.com/repos/coleifer/peewee/issues/122/events | https://github.com/coleifer/peewee/issues/122 | 7,705,421 | MDU6SXNzdWU3NzA1NDIx | 122 | Support Microsoft SQL Servrr? | {
"login": "YCF",
"id": 65446,
"node_id": "MDQ6VXNlcjY1NDQ2",
"avatar_url": "https://avatars.githubusercontent.com/u/65446?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/YCF",
"html_url": "https://github.com/YCF",
"followers_url": "https://api.github.com/users/YCF/followers",
"following_url": "https://api.github.com/users/YCF/following{/other_user}",
"gists_url": "https://api.github.com/users/YCF/gists{/gist_id}",
"starred_url": "https://api.github.com/users/YCF/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/YCF/subscriptions",
"organizations_url": "https://api.github.com/users/YCF/orgs",
"repos_url": "https://api.github.com/users/YCF/repos",
"events_url": "https://api.github.com/users/YCF/events{/privacy}",
"received_events_url": "https://api.github.com/users/YCF/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Not as a part of peewee, but if you're interested in writing support it should not be too hard.\n\nMight check out:\nhttp://code.google.com/p/pyodbc/\n",
"http://peewee.readthedocs.org/en/latest/peewee/database.html\n"
] | 2012-10-19T02:53:50 | 2012-10-19T15:22:02 | 2012-10-19T15:20:27 | NONE | null | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/122/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/122/timeline | null | completed | null | null |
|
https://api.github.com/repos/coleifer/peewee/issues/121 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/121/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/121/comments | https://api.github.com/repos/coleifer/peewee/issues/121/events | https://github.com/coleifer/peewee/issues/121 | 7,657,355 | MDU6SXNzdWU3NjU3MzU1 | 121 | Any plans for supporting generic foreign keys? | {
"login": "sigurdga",
"id": 114134,
"node_id": "MDQ6VXNlcjExNDEzNA==",
"avatar_url": "https://avatars.githubusercontent.com/u/114134?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/sigurdga",
"html_url": "https://github.com/sigurdga",
"followers_url": "https://api.github.com/users/sigurdga/followers",
"following_url": "https://api.github.com/users/sigurdga/following{/other_user}",
"gists_url": "https://api.github.com/users/sigurdga/gists{/gist_id}",
"starred_url": "https://api.github.com/users/sigurdga/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/sigurdga/subscriptions",
"organizations_url": "https://api.github.com/users/sigurdga/orgs",
"repos_url": "https://api.github.com/users/sigurdga/repos",
"events_url": "https://api.github.com/users/sigurdga/events{/privacy}",
"received_events_url": "https://api.github.com/users/sigurdga/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"If you want generic foreign keys, I would consider adding them as a part of the \"playhouse\" package. You're right, they hinge on having some sort of additional framework that maps database entries to model classes (or other tables, if you prefer). I'll take a look at this, as I have (ab)used django's GFKs a bit.\n",
"What do you think about an API like this:\n\n``` python\nclass Tag(Model):\n tag = CharField()\n object_type = CharField(null=True)\n object_id = IntegerField(null=True)\n object = GFKField('object_type', 'object_id')\n\nclass Blog(Model):\n tags = ReverseGFK(Tag, 'object_type', 'object_id')\n\ntag.object -> should be a blog\nblog.tags -> select query of tags for ``blog`` instance\nBlog.tags -> select query of all tags for Blog instances\n```\n\nCode: https://github.com/coleifer/peewee/blob/feature/gfk/playhouse/gfk.py\n\nBranch: https://github.com/coleifer/peewee/tree/feature/gfk\n",
"Wow! I'm eager to try this out tomorrow. It looks like this approach should work, and I hope it will when testing it. I'll let you know how it works for me.\n\nThanks a million!\n",
"merged into master\n",
"Great! I have just checked it out and it works perfect with the rest of my code. Peewee query syntax is very self explaining and easy to remember. And it is a lot easier to understand your little example code above than the corresponding Django documentation.\n",
"I've made a simple generic foreign key implementation: https://gist.github.com/wonderbeyond/0e1f402b7595e0b4f9f653260fed029c#file-index-md",
"Thanks for sharing @wonderbeyond -- this module was removed in 3.0.",
"Why was this removed? Is there some other \"official\" way to handle the use case that @wonderbeyond's code solves?",
">Why was this removed?\r\n\r\nIn my opinion, it's a gross hack and really does not belong in production-worthy code. It cannot be optimized in a generic way. It's only helpful for the simplest use-cases, but is very easy to have a footgun moment. A well-designed schema will obviate the need for this.\r\n\r\nImplementation-wise, it requires a centralized registry of sorts to indicate the \"content-type\" that an arbitrary identifier references.\r\n\r\nAlso muddies the water in terms of introspection.",
"Thanks for the reply!"
] | 2012-10-17T14:26:51 | 2019-11-11T23:12:12 | 2012-10-17T22:32:59 | NONE | null | After spending a day to see if peewee is suitable for my project(s), I cannot see any way to use generic foreign keys, or any way to do a query that will join on explicit column names and values.
Tags would be a natural case for this, when you want to refer to "content type" and "object id" to be able to use tags all over without creating a lot of tables.
Django describes it as content types: https://docs.djangoproject.com/en/dev/ref/contrib/contenttypes/
The way I tried to do it was to have a CharField and an IntegerField, where the CharField contains the table name and the IntegerField the id. But I cannot figure out how to do the queries, as I am not able to join two tables without a foreign key.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/121/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/121/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/120 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/120/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/120/comments | https://api.github.com/repos/coleifer/peewee/issues/120/events | https://github.com/coleifer/peewee/issues/120 | 7,643,401 | MDU6SXNzdWU3NjQzNDAx | 120 | AttributeError: 'ForeignKeyField' object has no attribute 'to' | {
"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 | [
"Thanks for fixing this one so quickly! When is the next release planned? Right now I'm using the master branch to get around this bug.\n"
] | 2012-10-17T00:20:48 | 2012-10-29T16:44:34 | 2012-10-17T01:58:42 | NONE | null | The create_foreign_key() function appears to be referencing an attribute that doesn't exist:
```
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "env/local/lib/python2.7/site-packages/peewee.py", line 2003, in create_table
db.create_foreign_key(cls, field_obj)
File "env/local/lib/python2.7/site-packages/peewee.py", line 1739, in create_foreign_key
field.to._meta.db_table,
AttributeError: 'ForeignKeyField' object has no attribute 'to'
```
This occurs while running create_table() on a model that has a ForeignKeyField().
Running peewee version 2.0.2.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/120/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/120/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/119 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/119/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/119/comments | https://api.github.com/repos/coleifer/peewee/issues/119/events | https://github.com/coleifer/peewee/issues/119 | 7,623,912 | MDU6SXNzdWU3NjIzOTEy | 119 | Indexing and ordering troubles | {
"login": "rcarmo",
"id": 392683,
"node_id": "MDQ6VXNlcjM5MjY4Mw==",
"avatar_url": "https://avatars.githubusercontent.com/u/392683?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/rcarmo",
"html_url": "https://github.com/rcarmo",
"followers_url": "https://api.github.com/users/rcarmo/followers",
"following_url": "https://api.github.com/users/rcarmo/following{/other_user}",
"gists_url": "https://api.github.com/users/rcarmo/gists{/gist_id}",
"starred_url": "https://api.github.com/users/rcarmo/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/rcarmo/subscriptions",
"organizations_url": "https://api.github.com/users/rcarmo/orgs",
"repos_url": "https://api.github.com/users/rcarmo/repos",
"events_url": "https://api.github.com/users/rcarmo/events{/privacy}",
"received_events_url": "https://api.github.com/users/rcarmo/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"It's just a little thing:\n\n``` python\n(('mac_address'), False),\n```\n\nshould be:\n\n``` python\n(('mac_address',), False), # <-- missing comma inside parentheses makes act like a string, not tuple\n```\n",
"Thanks.\n\nMaybe you should raise a custom exception when that happens, to avoid confusion?\n\nOn 16/10/2012, at 16:06, Charles Leifer [email protected] wrote:\n\n> It's just a little thing:\n> \n> (('mac_address'), False),\n> should be:\n> \n> (('mac_address',), False), # <-- missing comma inside parentheses makes act like a string, not tuple\n> —\n> Reply to this email directly or view it on GitHub.\n"
] | 2012-10-16T13:21:47 | 2012-10-22T10:25:37 | 2012-10-16T15:06:39 | CONTRIBUTOR | null | While trying to create an index on a table, I've come across an error that I can't fathom, but which appears to be due to some mismatch between what I can see on ReadTheDocs and currently working code.
Here's my sample model:
``` python
#!/usr/bin/env python
"""
Test Case
"""
import os, sys, logging, datetime, platform
logging.basicConfig(format='localhost - - [%(asctime)s] %(message)s', level=logging.DEBUG)
log = logging.getLogger(__name__)
from peewee import *
log = logging.getLogger()
db = SqliteDatabase('app.db')
db.connect()
class CustomModel(Model):
class Meta:
database = db
class Queue(CustomModel):
"""Represents queued instructions for a client device"""
scheduled = DateTimeField(primary_key=True,unique=True,default=datetime.datetime.now)
mac_address = CharField(null=False)
action = CharField(null=False)
data = CharField(null=True)
sent = BooleanField(default=False)
class Meta:
indexes = (
(('mac_address'), False),
)
order_by = ('-scheduled',)
Queue.create_table()
```
When I run the script above, I get:
```
localhost - - [2012-10-16 14:16:10,647] ('CREATE TABLE "queue" ("scheduled" DATETIME NOT NULL PRIMARY KEY, "mac_address" VARCHAR(255) NOT NULL, "action" VARCHAR(255) NOT NULL, "data" VARCHAR(255), "sent" SMALLINT NOT NULL)', None)
localhost - - [2012-10-16 14:16:10,680] ('CREATE UNIQUE INDEX "queue_scheduled" ON "queue" ("scheduled")', None)
Traceback (most recent call last):
File "test.py", line 39, in <module>
Queue.create_table()
File "/home/rcarmo/codebits/peewee.py", line 1969, in create_table
db.create_index(cls, fields, unique)
File "/home/rcarmo/codebits/peewee.py", line 1548, in create_index
field_objs = [model_class._meta.fields[f] if isinstance(f, basestring) else f for f in fields]
KeyError: 'm'
```
Any idea on what I'm doing wrong?
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/119/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/119/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/118 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/118/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/118/comments | https://api.github.com/repos/coleifer/peewee/issues/118/events | https://github.com/coleifer/peewee/issues/118 | 7,574,494 | MDU6SXNzdWU3NTc0NDk0 | 118 | Can't assign empty list on init | {
"login": "JCB-K",
"id": 636039,
"node_id": "MDQ6VXNlcjYzNjAzOQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/636039?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/JCB-K",
"html_url": "https://github.com/JCB-K",
"followers_url": "https://api.github.com/users/JCB-K/followers",
"following_url": "https://api.github.com/users/JCB-K/following{/other_user}",
"gists_url": "https://api.github.com/users/JCB-K/gists{/gist_id}",
"starred_url": "https://api.github.com/users/JCB-K/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/JCB-K/subscriptions",
"organizations_url": "https://api.github.com/users/JCB-K/orgs",
"repos_url": "https://api.github.com/users/JCB-K/repos",
"events_url": "https://api.github.com/users/JCB-K/events{/privacy}",
"received_events_url": "https://api.github.com/users/JCB-K/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Peewee models perform initialization on startup. Call the `super` method first:\n\n``` python\n\ndef __init__(self):\n super(Foo, self).__init__()\n self.list = []\n```\n"
] | 2012-10-14T15:46:22 | 2012-10-14T15:52:50 | 2012-10-14T15:52:50 | NONE | null | I'm trying to make an attribute of a class an empty list on init, but I get the following error:
```
File "~/.virtualenv/foobar/lib/python2.7/site-packages/peewee.py", line 281, in __set__
instance._data[self.att_name] = value
TypeError: 'NoneType' object does not support item assignment
```
Steps to reproduce:
```
class BaseModel(Model):
class Meta:
database = database
class Foo(BaseModel):
bar = CharField()
def __init__(self):
self.list = []
x = Foo()
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/118/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/118/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/117 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/117/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/117/comments | https://api.github.com/repos/coleifer/peewee/issues/117/events | https://github.com/coleifer/peewee/issues/117 | 7,546,699 | MDU6SXNzdWU3NTQ2Njk5 | 117 | UTF-8/Unicode Issues | {
"login": "rcarmo",
"id": 392683,
"node_id": "MDQ6VXNlcjM5MjY4Mw==",
"avatar_url": "https://avatars.githubusercontent.com/u/392683?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/rcarmo",
"html_url": "https://github.com/rcarmo",
"followers_url": "https://api.github.com/users/rcarmo/followers",
"following_url": "https://api.github.com/users/rcarmo/following{/other_user}",
"gists_url": "https://api.github.com/users/rcarmo/gists{/gist_id}",
"starred_url": "https://api.github.com/users/rcarmo/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/rcarmo/subscriptions",
"organizations_url": "https://api.github.com/users/rcarmo/orgs",
"repos_url": "https://api.github.com/users/rcarmo/repos",
"events_url": "https://api.github.com/users/rcarmo/events{/privacy}",
"received_events_url": "https://api.github.com/users/rcarmo/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Ouch -- could you paste the actual exception?\n",
"I've since worked around it by doing:\n\nd.name = unicode(name, 'utf-8') \n\nIn my code. I'm guessing there's a little more to this, but will try to check again later on.\n\nOn 12/10/2012, at 16:59, Charles Leifer [email protected] wrote:\n\n> Ouch -- could you paste the actual exception?\n> \n> —\n> Reply to this email directly or view it on GitHub.\n",
"I have been putting off learning about encoding for so long, i'm not gonna change today...but maybe you might understand a bit better. Do you know what might be different between your example and this test case?\n\nhttps://github.com/coleifer/peewee/blob/master/tests.py#L918\n",
"The tests are using a unicode string literal. If you pass in an encoding to the unicode builtin, e.g. `unicode(..., 'utf-8')` then it will try to decode the value passed in. If this value is an 8-bit string its fine, but if you pass in unicode you get `TypeError: decoding Unicode is not supported`.\n",
"Well, I'm passing in a POST value after cleaning up from bottle.py. I suppose it's not really unicode, but haven't had time to figure out the differences yet.\n"
] | 2012-10-12T15:58:44 | 2012-12-14T22:39:44 | 2012-12-14T22:39:44 | CONTRIBUTOR | null | There seem to be some UTF-8 issues lingering with Python 2.7.
While trying to set a text field to "Operações", I got the following stack dump:
Traceback (most recent call last):
...
File "/home/rcarmo/test/devices.py", line 81, in activate_device
d.save()
File "/home/rcarmo/test/peewee.py", line 1992, in save
update.execute()
File "/home/rcarmo/test/peewee.py", line 1397, in execute
result = self.database.execute(self)
File "/home/rcarmo/test/peewee.py", line 1505, in execute
sql, params = query.sql(self.get_compiler())
File "/home/rcarmo/test/peewee.py", line 1394, in sql
return compiler.parse_update_query(self)
File "/home/rcarmo/test/peewee.py", line 837, in parse_update_query
sets, params = self._parse_field_dictionary(query._update)
File "/home/rcarmo/test/peewee.py", line 828, in _parse_field_dictionary
val_params = [field.db_value(vp) for vp in val_params]
File "/home/rcarmo/test/peewee.py", line 321, in db_value
return value if value is None else self.coerce(value)
File "/home/rcarmo/test/peewee.py", line 387, in coerce
value = unicode(value or '')
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/117/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/117/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/116 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/116/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/116/comments | https://api.github.com/repos/coleifer/peewee/issues/116/events | https://github.com/coleifer/peewee/issues/116 | 7,527,715 | MDU6SXNzdWU3NTI3NzE1 | 116 | Disabled autocommit on select | {
"login": "obensonne",
"id": 121881,
"node_id": "MDQ6VXNlcjEyMTg4MQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/121881?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/obensonne",
"html_url": "https://github.com/obensonne",
"followers_url": "https://api.github.com/users/obensonne/followers",
"following_url": "https://api.github.com/users/obensonne/following{/other_user}",
"gists_url": "https://api.github.com/users/obensonne/gists{/gist_id}",
"starred_url": "https://api.github.com/users/obensonne/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/obensonne/subscriptions",
"organizations_url": "https://api.github.com/users/obensonne/orgs",
"repos_url": "https://api.github.com/users/obensonne/repos",
"events_url": "https://api.github.com/users/obensonne/events{/privacy}",
"received_events_url": "https://api.github.com/users/obensonne/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"My thinking was that we should only explicitly commit when, first of all, it is warranted (by being a query that writes something) and second of all, that the commit isn't being managed elsewhere.\n\nI am not aware of the need to open a transaction when doing SELECTs. That seems odd -- can you provide a little more info?\n",
"Thanks for reporting -- i didn't realize that psycopg2, as you said, opens a transaction every query. This should be fixed now, and select queries will have their transactions handled correctly\n",
"Great, thanks for the quick fix!\n"
] | 2012-10-11T21:37:35 | 2012-10-12T09:32:39 | 2012-10-12T08:41:18 | NONE | null | The `Database.execute_sql()` considers 2 parameters when deciding if to do a _commit_ after executing a statement:
``` python
def execute_sql(self, sql, params=None, require_commit=True):
cursor = self.get_cursor()
res = cursor.execute(sql, params or ())
if require_commit and self.get_autocommit():
self.commit()
logger.debug((sql, params))
return cursor
```
Two issues:
1. Shouldn't the condition be _or_-ed? At least the wording _require_ suggests this.
2. If no, why does a `SelectQuery` has set `require_commit = False`?
A continously running application which only does _selects_ opens a transaction once and keeps it open forever (tested with PostgreSQL).
Looks like a bug, isn't it?
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/116/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/116/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/115 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/115/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/115/comments | https://api.github.com/repos/coleifer/peewee/issues/115/events | https://github.com/coleifer/peewee/issues/115 | 7,504,947 | MDU6SXNzdWU3NTA0OTQ3 | 115 | I was wander if i can use connect pool for peewee? | {
"login": "xiocode",
"id": 1326473,
"node_id": "MDQ6VXNlcjEzMjY0NzM=",
"avatar_url": "https://avatars.githubusercontent.com/u/1326473?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/xiocode",
"html_url": "https://github.com/xiocode",
"followers_url": "https://api.github.com/users/xiocode/followers",
"following_url": "https://api.github.com/users/xiocode/following{/other_user}",
"gists_url": "https://api.github.com/users/xiocode/gists{/gist_id}",
"starred_url": "https://api.github.com/users/xiocode/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/xiocode/subscriptions",
"organizations_url": "https://api.github.com/users/xiocode/orgs",
"repos_url": "https://api.github.com/users/xiocode/repos",
"events_url": "https://api.github.com/users/xiocode/events{/privacy}",
"received_events_url": "https://api.github.com/users/xiocode/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"There's no reason you can't if it sits between your database driver and the python driver you use. However if you plan on implementing one below your database driver you will need to modify peewee.\n"
] | 2012-10-11T07:05:42 | 2012-10-11T18:37:54 | 2012-10-11T18:37:54 | NONE | null | thks
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/115/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/115/timeline | null | completed | null | null |