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/414 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/414/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/414/comments | https://api.github.com/repos/coleifer/peewee/issues/414/events | https://github.com/coleifer/peewee/issues/414 | 40,221,597 | MDU6SXNzdWU0MDIyMTU5Nw== | 414 | No quotes are put around "user" table name | {
"login": "extesy",
"id": 65872,
"node_id": "MDQ6VXNlcjY1ODcy",
"avatar_url": "https://avatars.githubusercontent.com/u/65872?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/extesy",
"html_url": "https://github.com/extesy",
"followers_url": "https://api.github.com/users/extesy/followers",
"following_url": "https://api.github.com/users/extesy/following{/other_user}",
"gists_url": "https://api.github.com/users/extesy/gists{/gist_id}",
"starred_url": "https://api.github.com/users/extesy/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/extesy/subscriptions",
"organizations_url": "https://api.github.com/users/extesy/orgs",
"repos_url": "https://api.github.com/users/extesy/repos",
"events_url": "https://api.github.com/users/extesy/events{/privacy}",
"received_events_url": "https://api.github.com/users/extesy/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"What SQL was generated previously? Was an alias used? Sorry I don't recall.\n",
"I don't know, probably just quotes around the table name, just like right after UPDATE word.\n",
"This should be fixed by bb48ca37fcdd2728c469c50aee8cb824a8aff4f1\n"
] | 2014-08-14T04:12:04 | 2014-08-19T20:17:37 | 2014-08-19T18:17:54 | NONE | null | Upgrading peewee from 2.2.5 to 2.3.0 broke something since now I get syntax error exception for this postgres query:
```
UPDATE "user" SET "last_active_at" = %s WHERE (user."id" = %s)
```
The problem is that "user" table name is a reserved keyword so it must be put in quotes.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/414/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/414/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/413 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/413/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/413/comments | https://api.github.com/repos/coleifer/peewee/issues/413/events | https://github.com/coleifer/peewee/pull/413 | 39,919,985 | MDExOlB1bGxSZXF1ZXN0MTk1Nzg2NDI= | 413 | Add in support for passing in JSON dumps functions | {
"login": "alexlatchford",
"id": 628146,
"node_id": "MDQ6VXNlcjYyODE0Ng==",
"avatar_url": "https://avatars.githubusercontent.com/u/628146?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/alexlatchford",
"html_url": "https://github.com/alexlatchford",
"followers_url": "https://api.github.com/users/alexlatchford/followers",
"following_url": "https://api.github.com/users/alexlatchford/following{/other_user}",
"gists_url": "https://api.github.com/users/alexlatchford/gists{/gist_id}",
"starred_url": "https://api.github.com/users/alexlatchford/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/alexlatchford/subscriptions",
"organizations_url": "https://api.github.com/users/alexlatchford/orgs",
"repos_url": "https://api.github.com/users/alexlatchford/repos",
"events_url": "https://api.github.com/users/alexlatchford/events{/privacy}",
"received_events_url": "https://api.github.com/users/alexlatchford/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Nice, thanks for this!\n"
] | 2014-08-10T23:45:38 | 2014-09-06T12:49:50 | 2014-09-06T12:49:47 | CONTRIBUTOR | null | Hi Charles,
I've added in support for passing through a `json.dumps` function to psycopg2. I need it to serialise datetime formats going into the db, but obviously this is nice and generic.
Let me know what you think.
Cheers,
Alex
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/413/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/413/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/413",
"html_url": "https://github.com/coleifer/peewee/pull/413",
"diff_url": "https://github.com/coleifer/peewee/pull/413.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/413.patch",
"merged_at": "2014-09-06T12:49:46"
} |
https://api.github.com/repos/coleifer/peewee/issues/412 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/412/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/412/comments | https://api.github.com/repos/coleifer/peewee/issues/412/events | https://github.com/coleifer/peewee/issues/412 | 39,698,915 | MDU6SXNzdWUzOTY5ODkxNQ== | 412 | Getting size of a ResultSet without using count() | {
"login": "arski",
"id": 904818,
"node_id": "MDQ6VXNlcjkwNDgxOA==",
"avatar_url": "https://avatars.githubusercontent.com/u/904818?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/arski",
"html_url": "https://github.com/arski",
"followers_url": "https://api.github.com/users/arski/followers",
"following_url": "https://api.github.com/users/arski/following{/other_user}",
"gists_url": "https://api.github.com/users/arski/gists{/gist_id}",
"starred_url": "https://api.github.com/users/arski/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/arski/subscriptions",
"organizations_url": "https://api.github.com/users/arski/orgs",
"repos_url": "https://api.github.com/users/arski/repos",
"events_url": "https://api.github.com/users/arski/events{/privacy}",
"received_events_url": "https://api.github.com/users/arski/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"You were very close -- the best way to get the result size if you plan to iterate anyways, is to call `list()` on the query and then take the length of that.\n\n``` python\nquery = User.select()\nnum_results = len(list(query))\nfor item in query:\n print item\n```\n\nThis will only result in a single select query being issued.\n",
"Aha, thank you!\n"
] | 2014-08-07T07:11:39 | 2014-08-07T13:12:53 | 2014-08-07T13:10:33 | NONE | null | Basically the reason is that I don't want to run another query when I know that I will be iterating over the ResultSet anyway, so I'd be happy to load it into memory and use `len()` or something like that.
I'm used to Django doing this automatically when you call `len()` on a query/resultset, but here even if I do `.execute()` first, `len()` still doesn't work..
What would be the best approach to do this?
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/412/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/412/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/411 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/411/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/411/comments | https://api.github.com/repos/coleifer/peewee/issues/411/events | https://github.com/coleifer/peewee/issues/411 | 39,455,591 | MDU6SXNzdWUzOTQ1NTU5MQ== | 411 | include sql command when sql/programmer error raised | {
"login": "Amleto",
"id": 2996796,
"node_id": "MDQ6VXNlcjI5OTY3OTY=",
"avatar_url": "https://avatars.githubusercontent.com/u/2996796?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/Amleto",
"html_url": "https://github.com/Amleto",
"followers_url": "https://api.github.com/users/Amleto/followers",
"following_url": "https://api.github.com/users/Amleto/following{/other_user}",
"gists_url": "https://api.github.com/users/Amleto/gists{/gist_id}",
"starred_url": "https://api.github.com/users/Amleto/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/Amleto/subscriptions",
"organizations_url": "https://api.github.com/users/Amleto/orgs",
"repos_url": "https://api.github.com/users/Amleto/repos",
"events_url": "https://api.github.com/users/Amleto/events{/privacy}",
"received_events_url": "https://api.github.com/users/Amleto/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"You can try logging: http://docs.peewee-orm.com/en/latest/peewee/cookbook.html#logging-queries\n\nOr you can implement `Database.sql_error_handler` http://docs.peewee-orm.com/en/latest/peewee/api.html?highlight=sql_error_handler#Database.sql_error_handler\n\nPlease comment if you find that this is an error in peewee.\n"
] | 2014-08-04T20:04:44 | 2014-08-04T20:06:50 | 2014-08-04T20:06:50 | NONE | null | Hi,
I have tens or hundreds of thousands of rows to commit (MySQL) and I had db connection issues when trying to commit them all in one go. The data is provided by a generator and I take slices (itertools.islice) that are passed in to an insert_many(...).execute() call.
When calling insert_many(...).execute() for the second time an sql/programmer exception is raised. I initially thought this was just because the generator was exhausted, but after writing unit tests (well, I wrote units for in memory sqlite, but the real code is connecting to mysql) I see that peewee handles this ok.
It's strange to me that insert_many(...).execute() works the first time but not the second. If I could see the sql that fails it could be useful.
Any help/advice appreciated.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/411/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/411/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/410 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/410/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/410/comments | https://api.github.com/repos/coleifer/peewee/issues/410/events | https://github.com/coleifer/peewee/issues/410 | 39,281,532 | MDU6SXNzdWUzOTI4MTUzMg== | 410 | sql_error_handler not called | {
"login": "tfeldmann",
"id": 385566,
"node_id": "MDQ6VXNlcjM4NTU2Ng==",
"avatar_url": "https://avatars.githubusercontent.com/u/385566?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/tfeldmann",
"html_url": "https://github.com/tfeldmann",
"followers_url": "https://api.github.com/users/tfeldmann/followers",
"following_url": "https://api.github.com/users/tfeldmann/following{/other_user}",
"gists_url": "https://api.github.com/users/tfeldmann/gists{/gist_id}",
"starred_url": "https://api.github.com/users/tfeldmann/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/tfeldmann/subscriptions",
"organizations_url": "https://api.github.com/users/tfeldmann/orgs",
"repos_url": "https://api.github.com/users/tfeldmann/repos",
"events_url": "https://api.github.com/users/tfeldmann/events{/privacy}",
"received_events_url": "https://api.github.com/users/tfeldmann/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Yeah, I think you're right... Perhaps the `ExceptionWrapper` code is getting in the way. Let me look into it.\n\nPS, you can use the `playhouse.pool.PooledMySQLDatabase` with a stale timeout and it will automatically recycle connections for you. Docs: http://docs.peewee-orm.com/en/latest/peewee/playhouse.html#pool\n",
"How experimental is this module really? Anything I have to consider?\n",
"> How experimental is this module really?\n\nI myself have not used it in deployment (I use SQLite for most of my projects), but it's been unit tested and I believe it should be safe to use.\n\nAs an aside, I made a script that does what you described -- connect to a mysql db, create a row, kill the database server, try to create another row.\n\nWhen I try to create another row, the `sql_error_handler()` is being called.\n",
"Strange. I tested this in an iPython Notebook and stopped the db manually. I'm using pymysql instead of MySQLdb -- maybe that's the cause?\nIf you send me the script I can test it on my machine.\n",
"``` python\n#!/usr/bin/env python\n\nimport logging\n\nfrom peewee import *\nfrom peewee import create_model_tables\n\nclass FakeMySQLDatabase(MySQLDatabase):\n def sql_error_handler(self, exception, sql, params, require_commit):\n import ipdb; ipdb.set_trace()\n\ndb = FakeMySQLDatabase('peewee_test')\n\nclass BaseModel(Model):\n class Meta:\n database = db\n\nclass Testmodel(BaseModel):\n data = CharField()\n\ndef main():\n create_model_tables([Testmodel], fail_silently=True)\n Testmodel.create(data='1')\n raw_input('stop server and press enter')\n Testmodel.create(data='2')\n\nif __name__ == '__main__':\n main()\n```\n",
"Alright, well I think that `sql_error_handler` is behaving correctly so I'm going to close. Please comment if you feel there is still an issue.\n",
"Thanks for the script. I found it works successfully in Python2 with MySQLdb driver but fails with PyMySQL (0.6.2) in both Python2 and Python3. \n",
"I got the error handler with pymysql using my script. The exception was:\n\n``` python\nOperationalError(2013, 'Lost connection to MySQL server during query')\n```\n",
"The error is handled, but an ArgumentError follows:\n[peewee_issue410.py](http://pastebin.com/E2ZSWey3)\n\nMySqlDb\n\n```\npip install -U virtualenv\nvirtualenv test1\nsource test1/bin/activate\npip install mysql-python peewee\npython peewee_issue410.py\n\n# Output:\nStarting MySQL\n. SUCCESS! \nShutting down MySQL\n.... SUCCESS! \nError handled: (OperationalError(2006, 'MySQL server has gone away'), 'INSERT INTO `testmodel` (`data`) VALUES (%s)', [u'2'], True) {}\n```\n\nPyMySql:\n\n```\npip install -U virtualenv\nvirtualenv test2\nsource test2/bin/activate\npip install pymysql peewee\npython peewee_issue410.py\n\n# Output:\nStarting MySQL\n. SUCCESS! \nShutting down MySQL\n.... SUCCESS! \nError handled: (OperationalError(2013, \"Lost connection to MySQL server during query (error(54, 'Connection reset by peer'))\"), 'INSERT INTO `testmodel` (`data`) VALUES (%s)', [u'2'], True) {}\nTraceback (most recent call last):\n File \"peewee_issue410.py\", line 33, in <module>\n main()\n File \"peewee_issue410.py\", line 30, in main\n Testmodel.create(data='2')\n File \"/Users/thomasfeldmann/Desktop/test2/lib/python2.7/site-packages/peewee.py\", line 3038, in create\n inst.save(force_insert=True)\n File \"/Users/thomasfeldmann/Desktop/test2/lib/python2.7/site-packages/peewee.py\", line 3163, in save\n pk_from_cursor = self.insert(**field_dict).execute()\n File \"/Users/thomasfeldmann/Desktop/test2/lib/python2.7/site-packages/peewee.py\", line 2247, in execute\n return self.database.last_insert_id(self._execute(), self.model_class)\n File \"/Users/thomasfeldmann/Desktop/test2/lib/python2.7/site-packages/peewee.py\", line 2388, in last_insert_id\n return cursor.lastrowid\nAttributeError: 'Cursor' object has no attribute 'lastrowid'\n```\n",
"Right -- you need to `return True` from the `sql_error_handler()` in order to re-raise the original exception.\n",
"Okay, didn't know that, I didn't find that in the docs. But how would you stop the exception being thrown? `return False` doesn't work.\n",
"Yeah, I guess the issue is with `pymysql` not assigning the `lastrowid` if the insert doesn't succeed. I think this behavior is acceptable, since you can still reconnect and re-execute the query from within the error handler.\n",
"Upgrade your openssl. Also that is not even remotely related to peewee or\nthis ticket. Go away.\nOn Aug 22, 2015 6:35 AM, \"Sateesh H\" [email protected] wrote:\n\n> I have the below connection and using the Pooled database as shown below.\n> DATABASE = {\n> 'name': 'testdb',\n> 'engine': 'playhouse.pool.PooledPostgresqlExtDatabase',\n> 'register_hstore': False,\n> 'user': 'test',\n> 'host':'localhost',\n> 'password':'test',\n> 'port':5432,\n> 'max_connections': 100,\n> 'stale_timeout': 6000,\n> }\n> Still i m facing the same the error\n> \"OpenSSL error of the type “decryption failed or bad record mac”?\n> \n> Is there other way to solve this issue?\n> \n> —\n> Reply to this email directly or view it on GitHub\n> https://github.com/coleifer/peewee/issues/410#issuecomment-133678364.\n"
] | 2014-08-01T11:23:57 | 2015-08-22T12:59:49 | 2014-08-04T12:26:34 | NONE | null | Hi! After connecting to a mysql database and waiting for a long time (>8h) subsequent database calls fail with a "2006 MySQL has gone away". To work around this problem I want to implement a "ReconnectingMySQLDatabase" that reconnects if this exception is detected.
For testing purposes I created the BaseModel tables and called `BaseModel.create()` several times (works), then shut down the database and called create() again. I expected the sql_error_handler to be called but it wasn't. [See the logfile](http://pastebin.com/x4zBuRgh)
``` python
import datetime
from peewee import *
class ReconnectingMySQLDatabase(MySQLDatabase):
def sql_error_handler(self, exception, sql, params, require_commit):
# I just want to print the arguments...
print(exception, sql, params, require_commit)
database = ReconnectingMySQLDatabase(
host='host',
user='user',
passwd='pass',
database='name',
threadlocals=True,
)
class BaseModel(Model):
created = DateTimeField(index=True, default=datetime.datetime.now)
modified = DateTimeField(index=True)
class Meta:
database = database
def save(self, *args, **kwargs):
self.modified = datetime.datetime.now()
return super().save(*args, **kwargs)
```
Is there a better way to do this?
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/410/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/410/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/409 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/409/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/409/comments | https://api.github.com/repos/coleifer/peewee/issues/409/events | https://github.com/coleifer/peewee/issues/409 | 39,249,447 | MDU6SXNzdWUzOTI0OTQ0Nw== | 409 | Ability to change query_context when joining | {
"login": "alexlatchford",
"id": 628146,
"node_id": "MDQ6VXNlcjYyODE0Ng==",
"avatar_url": "https://avatars.githubusercontent.com/u/628146?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/alexlatchford",
"html_url": "https://github.com/alexlatchford",
"followers_url": "https://api.github.com/users/alexlatchford/followers",
"following_url": "https://api.github.com/users/alexlatchford/following{/other_user}",
"gists_url": "https://api.github.com/users/alexlatchford/gists{/gist_id}",
"starred_url": "https://api.github.com/users/alexlatchford/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/alexlatchford/subscriptions",
"organizations_url": "https://api.github.com/users/alexlatchford/orgs",
"repos_url": "https://api.github.com/users/alexlatchford/repos",
"events_url": "https://api.github.com/users/alexlatchford/events{/privacy}",
"received_events_url": "https://api.github.com/users/alexlatchford/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I'm presuming the raw SQL produced should be something like this, which shows it's possible:\n\n``` sql\nSELECT\n a.title\nFROM\n article a,\n INNER JOIN news_feed nf ON a.news_feed_id = a.uuid\n INNER JOIN article_state ars ON ars.article_id = a.uuid\nWHERE\n nf.enabled = 1\n AND ars.state = 'a'\nGROUP BY\n a.title\nHAVING\n COUNT(ars.article_id) > 0\n```\n",
"You can use [.switch()](http://docs.peewee-orm.com/en/latest/peewee/api.html#Query.switch) to switch the query context. I believe that's what you're looking for.\n",
"Awesome, was looking for change instead of switch. Hate it when that happens! And with the docs literally just below where I was looking!\n"
] | 2014-07-31T23:38:04 | 2014-08-04T06:54:50 | 2014-08-01T12:51:44 | CONTRIBUTOR | null | Hi Charles,
Just been writing a query that I think should be functionally possible in SQL but isn't currently supported in peewee.
The query is looking to select any articles that are in an enabled news feed, with at least one entry with a specific state in the article_state table.
``` python
class NewsFeed(Model):
uuid = UUIDField(primary_key=True)
enabled = BooleanField()
class Article(Model):
uuid = UUIDField(primary_key=True)
title = CharField()
news_feed = ForeignKeyField(NewsFeed)
class ArticleState(Model):
state = CharField(choices=('a', 'b', 'c'))
article = ForeignKeyField(Article)
# Create and populate..
recent_articles = Article.select(
Article.title
).join(NewsFeed).join(ArticleState).where(
(NewsFeed.enabled == True) & (ArticleState.state == 'a')
).group_by(
Article.title
).having(fn.Count(ArticleState.article) > 0)
```
That query throws the following error:
```
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 808, in __bootstrap_inner
self.run()
File "/Library/Python/2.7/site-packages/cherrypy/process/plugins.py", line 485, in run
self.function(*self.args, **self.kwargs)
File "/Users/alexlatchford/Code/abbreviate/a8-aggregate/a8_aggregate/../a8_aggregate/tasks/sync_feeds.py", line 40, in sync_feeds
load_cache(cached_articles)
File "/Users/alexlatchford/Code/abbreviate/a8-aggregate/a8_aggregate/../a8_aggregate/tasks/sync_feeds.py", line 27, in load_cache
).join(NewsFeed).join(ArticleState).where(
File "/Library/Python/2.7/site-packages/peewee.py", line 241, in inner
func(clone, *args, **kwargs)
File "/Library/Python/2.7/site-packages/peewee.py", line 1752, in join
self._query_ctx, model_class))
ValueError: No foreign key between <class 'a8_aggregate.database.NewsFeed'> and <class 'a8_aggregate.database.ArticleState'>
```
I understand the problem is the ordering of the `join()` calls and I'm wondering if there is a different way to write this query to achieve the results I'm after. For the meantime I'm going to write it as two queries but it's obviously not ideal :(
Cheers,
Alex
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/409/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/409/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/408 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/408/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/408/comments | https://api.github.com/repos/coleifer/peewee/issues/408/events | https://github.com/coleifer/peewee/issues/408 | 38,721,517 | MDU6SXNzdWUzODcyMTUxNw== | 408 | Auto-incrementing BigIntegerField | {
"login": "tfeldmann",
"id": 385566,
"node_id": "MDQ6VXNlcjM4NTU2Ng==",
"avatar_url": "https://avatars.githubusercontent.com/u/385566?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/tfeldmann",
"html_url": "https://github.com/tfeldmann",
"followers_url": "https://api.github.com/users/tfeldmann/followers",
"following_url": "https://api.github.com/users/tfeldmann/following{/other_user}",
"gists_url": "https://api.github.com/users/tfeldmann/gists{/gist_id}",
"starred_url": "https://api.github.com/users/tfeldmann/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/tfeldmann/subscriptions",
"organizations_url": "https://api.github.com/users/tfeldmann/orgs",
"repos_url": "https://api.github.com/users/tfeldmann/repos",
"events_url": "https://api.github.com/users/tfeldmann/events{/privacy}",
"received_events_url": "https://api.github.com/users/tfeldmann/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"As a workaround I overrode the `create` method. Please let me know if there is a better way.\n\n``` python\nclass Dataset(BaseModel):\n id = BigIntegerField(primary_key=True)\n\n @classmethod\n def create(cls, *args, **kwargs):\n next_id = cls.select(fn.Max(cls.id)).scalar() + 1\n return super().create(id=next_id, *args, **kwargs)\n```\n",
"Yes but it's not built-in at the moment. You can create a new field type and register it with the db, or create a subclass of the bigint field and override the `__ddl__()` method. [Here are docs on creating a custom field](http://docs.peewee-orm.com/en/latest/peewee/models.html#creating-a-custom-field).\n\nGoing the former route, you might:\n\n``` python\nclass AutoBigIntegerField(BigIntegerField):\n db_field = 'auto_bigint'\n\ndb = MySQLDatabase('mydb', ...)\ndb.register_fields('auto_bigint', 'BIGINT AUTO_INCREMENT')\n```\n\nI _believe_ that should do what you want.\n",
"Thank you, cool stuff!\n`fields` must be a dict and `register_fields()` did not work (KeyError on `create_table()`, so I did this:\n\n``` python\ndatabase = MySQLDatabase(\n user=...\n ...\n fields={'auto_bigint': 'BIGINT AUTO_INCREMENT'},\n)\n```\n",
"Oh right, yep just woke up... Cool well if that's working then I'm going to close. Please let me know if you are still encountering issues.\n"
] | 2014-07-25T11:40:46 | 2014-07-25T12:27:30 | 2014-07-25T12:27:30 | NONE | null | Hello,
I'm working on an application with a mysql database. Several hundred loggers will each send a measurement value every second for three years - so I have to use a BigIntegerField.
`id = BigIntegerField(primary_key=True)` works, but doesn't auto-increment. Is there any way to do this in peewee?
Thanks!
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/408/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/408/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/407 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/407/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/407/comments | https://api.github.com/repos/coleifer/peewee/issues/407/events | https://github.com/coleifer/peewee/issues/407 | 38,715,476 | MDU6SXNzdWUzODcxNTQ3Ng== | 407 | Not unique table/alias in a single INNER JOIN query | {
"login": "lalstef",
"id": 1503661,
"node_id": "MDQ6VXNlcjE1MDM2NjE=",
"avatar_url": "https://avatars.githubusercontent.com/u/1503661?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/lalstef",
"html_url": "https://github.com/lalstef",
"followers_url": "https://api.github.com/users/lalstef/followers",
"following_url": "https://api.github.com/users/lalstef/following{/other_user}",
"gists_url": "https://api.github.com/users/lalstef/gists{/gist_id}",
"starred_url": "https://api.github.com/users/lalstef/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/lalstef/subscriptions",
"organizations_url": "https://api.github.com/users/lalstef/orgs",
"repos_url": "https://api.github.com/users/lalstef/repos",
"events_url": "https://api.github.com/users/lalstef/events{/privacy}",
"received_events_url": "https://api.github.com/users/lalstef/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Just an FYI that the `filter()` API is actually deprecated.\n\nThat aside, it looks like it's interpreting the foreign key as a column requiring a join. This query should accomplish what you want:\n\n``` python\nDataRow.select().where(DataRow.parent == 1234)\n```\n\nAlso, if you find yourself wanting to perform a join on the parent row, you need to use [Model.alias()](http://docs.peewee-orm.com/en/latest/peewee/api.html#Model.alias).\n"
] | 2014-07-25T10:06:38 | 2014-07-25T12:33:38 | 2014-07-25T12:33:38 | NONE | null | Hi,
I have a model DataRow which has a foreign key to itself (you can see it below). This query
```
DataRow.filter(parent=1864)
```
caused the following error:
```
InternalError: (1066, u"Not unique table/alias: 't1'")
```
Here is the SQL that was executed:
```
Error executing query
SELECT t1.`id`, t1.`data`, t1.`parent_id`, t1.`board_id`, t1.`order`, t1.`colour`
FROM `datarow` AS t1 INNER JOIN `datarow` AS t1 ON (t1.`parent_id` = t1.`id`) WHERE
(t1.`parent_id` = %s) ([1864])
```
Here is the data model:
```
import peewee
from flask_peewee.db import Database
app = Flask(__name__, static_url_path='/assets')
db = Database(app)
class DataRow(db.Model):
DEFAULT_ROW_COLOUR = '#ffffff'
data = peewee.TextField()
parent = peewee.ForeignKeyField('self', null=True, blank=True)
board = peewee.ForeignKeyField(Board)
order = peewee.FloatField(null=True)
colour = peewee.CharField(default=DEFAULT_ROW_COLOUR)
```
Even though I may have made some mistake in data modeling or in my peewee usage, I think I shouldn't be getting this error, right?
Thanks
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/407/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/407/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/406 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/406/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/406/comments | https://api.github.com/repos/coleifer/peewee/issues/406/events | https://github.com/coleifer/peewee/issues/406 | 38,581,277 | MDU6SXNzdWUzODU4MTI3Nw== | 406 | Question: why does clear_limit default to True (simply for backwards compatibility?) | {
"login": "bryhoyt",
"id": 4769854,
"node_id": "MDQ6VXNlcjQ3Njk4NTQ=",
"avatar_url": "https://avatars.githubusercontent.com/u/4769854?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/bryhoyt",
"html_url": "https://github.com/bryhoyt",
"followers_url": "https://api.github.com/users/bryhoyt/followers",
"following_url": "https://api.github.com/users/bryhoyt/following{/other_user}",
"gists_url": "https://api.github.com/users/bryhoyt/gists{/gist_id}",
"starred_url": "https://api.github.com/users/bryhoyt/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/bryhoyt/subscriptions",
"organizations_url": "https://api.github.com/users/bryhoyt/orgs",
"repos_url": "https://api.github.com/users/bryhoyt/repos",
"events_url": "https://api.github.com/users/bryhoyt/events{/privacy}",
"received_events_url": "https://api.github.com/users/bryhoyt/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I agree and have updated wrapped_count() to have `clear_limit` default to `False`. I also added the option to pass that parameter through the call to `count()`. Finally, I made it so that calls to `count()` for queries that have a limit or offset will use wrapped_count() instead.\n",
"If for some reason I have misunderstood your concerns, please leave a comment. Based on my understanding of your comments I think I've fixed the behavior of count. Thanks for taking the time to bring these issues to my attention. I hope that you'll keep submitting quality issues like these!\n",
"Everything looks great to me -- your commit addresses my concerns perfectly.\n\nMy only question at this point would be whether anyone out there is depending on the current behaviour. But hopefully not -- and it could be something you could perhaps handle better with a comment in the release notes or docs for the next version. I've checked flask-admin's peewee module, and it has no problems in either case, because it calls .count() before the limit is applied anyway.\n"
] | 2014-07-23T22:59:36 | 2014-07-24T02:57:08 | 2014-07-24T02:16:48 | CONTRIBUTOR | null | I realise it may well break backwards compatibility to change anything at this point, but I'm interested in understanding the rationale, if any, for the way things are, so I can grok the API better.
As far as I see it, LIMIT and OFFSET are genuinely part of a given query -- if I want to know the total number of results, I will execute .count() on a query with no limit/offset. If I want to know how many results in a query filtered by a column, then I'll execute .count() on that query, and expect the filtered number of results. Thus, if I execute .count() on a query filtered by limit/offset, I expect the result to be the limited number.
Any reason for the default being the opposite to what I expect?
(I haven't tested this, but I believe both SQLAlchemy and Django ORM work in the way I'd expect -- not that that's necessarily a point in favour, just an interesting reference. Looks like SQLAlchemy may have struggled with this a bit, and settled on an always-does-what-you'd-expect answer using a subquery: http://docs.sqlalchemy.org/en/rel_0_9/orm/tutorial.html#counting)
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/406/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/406/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/405 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/405/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/405/comments | https://api.github.com/repos/coleifer/peewee/issues/405/events | https://github.com/coleifer/peewee/issues/405 | 38,580,178 | MDU6SXNzdWUzODU4MDE3OA== | 405 | Should count() default to wrapped_count() when query contains a limit or offset? | {
"login": "bryhoyt",
"id": 4769854,
"node_id": "MDQ6VXNlcjQ3Njk4NTQ=",
"avatar_url": "https://avatars.githubusercontent.com/u/4769854?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/bryhoyt",
"html_url": "https://github.com/bryhoyt",
"followers_url": "https://api.github.com/users/bryhoyt/followers",
"following_url": "https://api.github.com/users/bryhoyt/following{/other_user}",
"gists_url": "https://api.github.com/users/bryhoyt/gists{/gist_id}",
"starred_url": "https://api.github.com/users/bryhoyt/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/bryhoyt/subscriptions",
"organizations_url": "https://api.github.com/users/bryhoyt/orgs",
"repos_url": "https://api.github.com/users/bryhoyt/repos",
"events_url": "https://api.github.com/users/bryhoyt/events{/privacy}",
"received_events_url": "https://api.github.com/users/bryhoyt/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Additionally, I think count() should have a clear_limit parameter which it passes through to wrapped_count() -- I'm mentioning this as a comment here, not a separate issue, because it would only make sense if count deferred to wrapped_count for limits and offsets.\n",
"> I think that's nice; exactly what you want in the case of distinct or group by. Wouldn't it make sense for it to do the same if the query has a limit or offset?\n\nYeah, now that I think about it I agree.\n",
"Thanks, looks great -- really appreciate the quick fixes. I'm loving using Peewee with Flask -- thanks for the great ORM!\n"
] | 2014-07-23T22:43:39 | 2014-07-24T02:53:51 | 2014-07-24T02:13:18 | CONTRIBUTOR | null | As far as I can tell, count() returns meaningless results when the query contains a limit or offset (neither the total, nor the limited, number of results).
As per the docs, "count() will automatically default to wrapped_count() in the event the query is distinct or has a grouping".
I think that's nice; exactly what you want in the case of distinct or group by. Wouldn't it make sense for it to do the same if the query has a limit or offset?
If not, what's the rationale behind that?
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/405/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/405/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/404 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/404/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/404/comments | https://api.github.com/repos/coleifer/peewee/issues/404/events | https://github.com/coleifer/peewee/issues/404 | 38,579,889 | MDU6SXNzdWUzODU3OTg4OQ== | 404 | wrapped_count() parameter clear_limit is undocumented | {
"login": "bryhoyt",
"id": 4769854,
"node_id": "MDQ6VXNlcjQ3Njk4NTQ=",
"avatar_url": "https://avatars.githubusercontent.com/u/4769854?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/bryhoyt",
"html_url": "https://github.com/bryhoyt",
"followers_url": "https://api.github.com/users/bryhoyt/followers",
"following_url": "https://api.github.com/users/bryhoyt/following{/other_user}",
"gists_url": "https://api.github.com/users/bryhoyt/gists{/gist_id}",
"starred_url": "https://api.github.com/users/bryhoyt/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/bryhoyt/subscriptions",
"organizations_url": "https://api.github.com/users/bryhoyt/orgs",
"repos_url": "https://api.github.com/users/bryhoyt/repos",
"events_url": "https://api.github.com/users/bryhoyt/events{/privacy}",
"received_events_url": "https://api.github.com/users/bryhoyt/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Thanks for pointing this out.\n"
] | 2014-07-23T22:40:03 | 2014-07-24T02:03:16 | 2014-07-24T02:03:11 | CONTRIBUTOR | null | I was confused when count() was behaving unexpectedly, and discovered wrapped_count() by trawling the issues page, but it took me a bit more probing to find the clear_limit parameter to get the actual number of results in the query, rather than the total without limit/offset.
Would be helpful if clear_limit were documented here: https://peewee.readthedocs.org/en/latest/peewee/api.html#SelectQuery.wrapped_count
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/404/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/404/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/403 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/403/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/403/comments | https://api.github.com/repos/coleifer/peewee/issues/403/events | https://github.com/coleifer/peewee/pull/403 | 38,552,936 | MDExOlB1bGxSZXF1ZXN0MTg3OTA2MTA= | 403 | Adding PyMySQL to the error message | {
"login": "denilsonsa",
"id": 121676,
"node_id": "MDQ6VXNlcjEyMTY3Ng==",
"avatar_url": "https://avatars.githubusercontent.com/u/121676?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/denilsonsa",
"html_url": "https://github.com/denilsonsa",
"followers_url": "https://api.github.com/users/denilsonsa/followers",
"following_url": "https://api.github.com/users/denilsonsa/following{/other_user}",
"gists_url": "https://api.github.com/users/denilsonsa/gists{/gist_id}",
"starred_url": "https://api.github.com/users/denilsonsa/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/denilsonsa/subscriptions",
"organizations_url": "https://api.github.com/users/denilsonsa/orgs",
"repos_url": "https://api.github.com/users/denilsonsa/repos",
"events_url": "https://api.github.com/users/denilsonsa/events{/privacy}",
"received_events_url": "https://api.github.com/users/denilsonsa/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2014-07-23T17:38:40 | 2014-07-23T17:39:38 | 2014-07-23T17:39:38 | CONTRIBUTOR | null | Since `peewee` supports both `MySQLdb` and `PyMySQL` modules, it makes sense to report them both at the error message.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/403/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/403/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/403",
"html_url": "https://github.com/coleifer/peewee/pull/403",
"diff_url": "https://github.com/coleifer/peewee/pull/403.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/403.patch",
"merged_at": "2014-07-23T17:39:38"
} |
https://api.github.com/repos/coleifer/peewee/issues/402 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/402/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/402/comments | https://api.github.com/repos/coleifer/peewee/issues/402/events | https://github.com/coleifer/peewee/pull/402 | 38,543,940 | MDExOlB1bGxSZXF1ZXN0MTg3ODQ5Njc= | 402 | Added support for postgres raw encryption functions. | {
"login": "stas",
"id": 112147,
"node_id": "MDQ6VXNlcjExMjE0Nw==",
"avatar_url": "https://avatars.githubusercontent.com/u/112147?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/stas",
"html_url": "https://github.com/stas",
"followers_url": "https://api.github.com/users/stas/followers",
"following_url": "https://api.github.com/users/stas/following{/other_user}",
"gists_url": "https://api.github.com/users/stas/gists{/gist_id}",
"starred_url": "https://api.github.com/users/stas/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/stas/subscriptions",
"organizations_url": "https://api.github.com/users/stas/orgs",
"repos_url": "https://api.github.com/users/stas/repos",
"events_url": "https://api.github.com/users/stas/events{/privacy}",
"received_events_url": "https://api.github.com/users/stas/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2014-07-23T16:02:42 | 2014-09-06T13:36:34 | 2014-09-06T12:48:22 | NONE | null | This introduces a new field type for `playhouse.postgres_ext` to handle encrypted columns.
This should work with AES and Blowfish algorithms. The encryption is handled by the [pgcrypto](http://www.postgresql.org/docs/9.3/static/pgcrypto.html) module.
Although this works, this is not very optimized. See #401
I opened this PR mostly because I'm interested in having encryption support in peewee.
Although this is pretty raw, I hope to get some feedback and other people review and play with this.
Thanks a lot for all the work on peewee!
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/402/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/402/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/402",
"html_url": "https://github.com/coleifer/peewee/pull/402",
"diff_url": "https://github.com/coleifer/peewee/pull/402.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/402.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/401 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/401/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/401/comments | https://api.github.com/repos/coleifer/peewee/issues/401/events | https://github.com/coleifer/peewee/issues/401 | 38,542,628 | MDU6SXNzdWUzODU0MjYyOA== | 401 | Database functions fields support | {
"login": "stas",
"id": 112147,
"node_id": "MDQ6VXNlcjExMjE0Nw==",
"avatar_url": "https://avatars.githubusercontent.com/u/112147?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/stas",
"html_url": "https://github.com/stas",
"followers_url": "https://api.github.com/users/stas/followers",
"following_url": "https://api.github.com/users/stas/following{/other_user}",
"gists_url": "https://api.github.com/users/stas/gists{/gist_id}",
"starred_url": "https://api.github.com/users/stas/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/stas/subscriptions",
"organizations_url": "https://api.github.com/users/stas/orgs",
"repos_url": "https://api.github.com/users/stas/repos",
"events_url": "https://api.github.com/users/stas/events{/privacy}",
"received_events_url": "https://api.github.com/users/stas/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I think I'm going to pass on merging this, but thank you for your hard work!\n",
"@coleifer It would be great if you could share your opinions on this.\n\nBtw, this issue is not directly relevant to the PR #402 you just closed, which is fine tbh.\n",
"> It would be great if you could share your opinions on this.\n\nFor sure, sorry for being vague. I think this could lead to subtle bugs, especially if you wanted to work with the raw value stored in the column (without the function). I also think that there are limited use-cases -- encryption/decryption is really the only one that comes to mind.\n\nIn my opinion, it would be better to be explicit:\n\n``` python\n\nSecretModel.select(\n SecretModel.id,\n fn.decrypt_iv(SecretModel.data, 'my key', 'iv', 'aes').alias('data'))\n\nSecretModel.insert(\n data=fn.encrypt_iv('shhhh', 'my key', 'iv', 'aes')).execute()\n```\n",
"Thanks, this is really helpful!\n"
] | 2014-07-23T15:50:21 | 2014-09-06T15:02:49 | 2014-09-06T12:48:17 | NONE | null | The issue is related to the way field nodes are parsed.
At this moment there's no way you can dynamically embed a function in the field `SelectQuery` (although this is partially achievable through psycopg2 API for PostgreSQL, other database adapters are very unlikely to provide the same functionality).
A good example for this use-case could be the pgcrypto functions that can be used to encrypt/decrypt data at the query level. Below is an example SQL query I would like to be able to build through the `Field` API:
``` sql
INSERT INTO mytable (mycolumn) VALUES (encrypt_iv('TEST_DATA', '_key', '_iv', 'aes'));
SELECT t1."id", decrypt_iv(t1."mycolumn", '_key', '_iv', 'aes') as mycolumn FROM mytable as t1;
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/401/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/401/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/400 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/400/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/400/comments | https://api.github.com/repos/coleifer/peewee/issues/400/events | https://github.com/coleifer/peewee/issues/400 | 38,538,748 | MDU6SXNzdWUzODUzODc0OA== | 400 | Add support for MySQL TIMESTAMP field | {
"login": "denilsonsa",
"id": 121676,
"node_id": "MDQ6VXNlcjEyMTY3Ng==",
"avatar_url": "https://avatars.githubusercontent.com/u/121676?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/denilsonsa",
"html_url": "https://github.com/denilsonsa",
"followers_url": "https://api.github.com/users/denilsonsa/followers",
"following_url": "https://api.github.com/users/denilsonsa/following{/other_user}",
"gists_url": "https://api.github.com/users/denilsonsa/gists{/gist_id}",
"starred_url": "https://api.github.com/users/denilsonsa/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/denilsonsa/subscriptions",
"organizations_url": "https://api.github.com/users/denilsonsa/orgs",
"repos_url": "https://api.github.com/users/denilsonsa/repos",
"events_url": "https://api.github.com/users/denilsonsa/events{/privacy}",
"received_events_url": "https://api.github.com/users/denilsonsa/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"You can always implement a custom field type: http://peewee.readthedocs.org/en/latest/peewee/models.html#creating-a-custom-field\n\nI do not have any plans at the moment to implement the timestamp field, however.\n",
"For future reference, MySQL's `TIMESTAMP` field behaves almost like `DateTimeField`, so a trivial implementation looks like this:\n\n```\n# Custom field, behaves just like DateTimeField.\nclass TimestampField(DateTimeField):\n db_field = 'timestamp'\n\nMySQLDatabase.register_fields({'timestamp': 'TIMESTAMP'})\n```\n\nHowever, this implementation is likely incomplete. In special, a `DATETIME` field stores the date in the exact format passed to the database, while a `TIMESTAMP` field will convert to UTC while writing, and convert from UTC to local time in a SELECT result.\n\nFor a simple order_by, I can use `TIMESTAMP` and `DATETIME` the same way. For anything else, we might need extra code.\n"
] | 2014-07-23T15:12:34 | 2014-07-24T03:11:13 | 2014-07-24T02:18:29 | CONTRIBUTOR | null | Peewee already has support for `datetime` field, but if I'm working with a "legacy" database, it would be desirable to also have [`timestamp` field](https://dev.mysql.com/doc/refman/5.5/en/datetime.html).
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/400/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/400/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/399 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/399/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/399/comments | https://api.github.com/repos/coleifer/peewee/issues/399/events | https://github.com/coleifer/peewee/issues/399 | 38,314,718 | MDU6SXNzdWUzODMxNDcxOA== | 399 | Request: joining subqueries | {
"login": "alvra",
"id": 470642,
"node_id": "MDQ6VXNlcjQ3MDY0Mg==",
"avatar_url": "https://avatars.githubusercontent.com/u/470642?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/alvra",
"html_url": "https://github.com/alvra",
"followers_url": "https://api.github.com/users/alvra/followers",
"following_url": "https://api.github.com/users/alvra/following{/other_user}",
"gists_url": "https://api.github.com/users/alvra/gists{/gist_id}",
"starred_url": "https://api.github.com/users/alvra/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/alvra/subscriptions",
"organizations_url": "https://api.github.com/users/alvra/orgs",
"repos_url": "https://api.github.com/users/alvra/repos",
"events_url": "https://api.github.com/users/alvra/events{/privacy}",
"received_events_url": "https://api.github.com/users/alvra/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"``` python\nthings = Thing.select().alias('j1')\nRelated.select().join(things, on=(Related.thing == things.c.id))\n```\n",
"Thanks :)\n"
] | 2014-07-21T15:36:47 | 2014-08-14T06:35:24 | 2014-08-14T03:44:27 | NONE | null | I'd like to be able to construct queries like
``` sql
SELECT *
FROM t1
INNER JOIN (
SELECT * FROM t2
) ON t2.rel_id = t2.id
```
so that's joining a subquery (`peewee.SelectQuery`) instead of a table (`peewee.Model` or `peewee.ModelAlias`). (Of course, this makes more sense if the subquery is a bit more complex, but you get the idea.)
Currently (2.2.5), when trying this, it doensn't work.
```
>>> Related.select().join(Thing, on=Thing.related==thing) # works as expected
<class 'peewee.Related'> SELECT ... FROM "related" AS t1 INNER JOIN "thing" AS t2 ON (t2."related_id" = t1."id") []
>>> Related.select().join(Thing.select(), on=Thing.related==thing) # fails unfortunately
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "peewee.py", line 1677, in __repr__
instance = collected_models[key]
File "peewee.py", line 2059, in sql
return query
File "peewee.py", line 1254, in generate_select
left_field = field
File "peewee.py", line 1203, in calculate_alias_map
if node._negated:
File "peewee.py", line 1194, in <lambda>
unknown = True
AttributeError: 'SelectQueryWrapper' object has no attribute '_meta'
```
When looking through the code it seems Peewee doesn't support this, and I couldn't find a simple way to make this work.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/399/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/399/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/398 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/398/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/398/comments | https://api.github.com/repos/coleifer/peewee/issues/398/events | https://github.com/coleifer/peewee/issues/398 | 38,275,408 | MDU6SXNzdWUzODI3NTQwOA== | 398 | Support Request: Nested dicts (1 -> n) select query | {
"login": "alexlatchford",
"id": 628146,
"node_id": "MDQ6VXNlcjYyODE0Ng==",
"avatar_url": "https://avatars.githubusercontent.com/u/628146?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/alexlatchford",
"html_url": "https://github.com/alexlatchford",
"followers_url": "https://api.github.com/users/alexlatchford/followers",
"following_url": "https://api.github.com/users/alexlatchford/following{/other_user}",
"gists_url": "https://api.github.com/users/alexlatchford/gists{/gist_id}",
"starred_url": "https://api.github.com/users/alexlatchford/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/alexlatchford/subscriptions",
"organizations_url": "https://api.github.com/users/alexlatchford/orgs",
"repos_url": "https://api.github.com/users/alexlatchford/repos",
"events_url": "https://api.github.com/users/alexlatchford/events{/privacy}",
"received_events_url": "https://api.github.com/users/alexlatchford/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Unfortunately this is not currently supported using `.dicts()`. Searching 1 -> N can be accomplished using the special `prefetch` API. Behind-the-scenes, `prefetch` will construct the appropriate subqueries to ensure you don't have O(n) queries when fetching \"keywords\" in your example.\n\nYour best bet is to write something like the following:\n\n``` python\nfilters = Filter.select().order_by(Filter.name.desc())\nkeywords = Keyword.select().order_by(Keyword.keyword.desc())\nfilter_keyword = prefetch(filters, keywords)\n\ndef filter_to_dict(f):\n data = f._data.copy()\n data['keywords'] = [k.keyword for k in f.keywords_prefetch]\n return data\n\nprint map(filter_to_dict, filter_keyword)\n```\n\nWould print:\n\n```\n[{'keywords': [u'k3-3', u'k3-2', u'k3-1'], 'id': 3, 'name': u'filter3'},\n {'keywords': [u'k2-3', u'k2-2', u'k2-1'], 'id': 2, 'name': u'filter2'},\n {'keywords': [u'k1-3', u'k1-2', u'k1-1'], 'id': 1, 'name': u'filter1'}]\n```\n",
"Awesome, cheers :)\n"
] | 2014-07-21T04:05:56 | 2014-07-22T02:36:06 | 2014-07-22T02:36:06 | CONTRIBUTOR | null | Hi Charles,
I'm looking to produce a list of dictionaries from a query so it's easy to serialise to json for API output.. The twist over the conventional usage of `dicts()` is that I'd like to perform a join and have that aggregate into a sub-list..
Puesdo-code example:
``` python
class Filter(Model):
uuid = UUIDField(primary_key=True)
name = CharField()
class Keyword(Model):
name = CharField()
filter = ForeignKeyField(Filter)
# Create and populate tables..
json = Filter.select(Filter.uuid, Filter.name, Keyword.name).join(Keyword, JOIN_LEFT_OUTER).dicts()
```
I'd like the API to output something like this..
``` json
[
{
"uuid": "...",
"name": "My filter 1",
"keywords": ["a", "b", "c"]
},
{
"uuid": "...",
"name": "My filter 2",
"keywords": ["d", "e", "f"]
},
{
"uuid": "...",
"name": "My filter 3",
"keywords": []
},
...
]
```
Sorry for the puesdo-code, is there a helper that could perform something like this or should I just roll my own? It'll be a reasonably common operation for this API unfortunately thus I'm asking to see if I've missed anything in the manual :)
Thanks,
Alex
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/398/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/398/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/397 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/397/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/397/comments | https://api.github.com/repos/coleifer/peewee/issues/397/events | https://github.com/coleifer/peewee/pull/397 | 38,234,424 | MDExOlB1bGxSZXF1ZXN0MTg2MjExMjE= | 397 | Add support for conditional saving model. | {
"login": "yadutaf",
"id": 739985,
"node_id": "MDQ6VXNlcjczOTk4NQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/739985?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/yadutaf",
"html_url": "https://github.com/yadutaf",
"followers_url": "https://api.github.com/users/yadutaf/followers",
"following_url": "https://api.github.com/users/yadutaf/following{/other_user}",
"gists_url": "https://api.github.com/users/yadutaf/gists{/gist_id}",
"starred_url": "https://api.github.com/users/yadutaf/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/yadutaf/subscriptions",
"organizations_url": "https://api.github.com/users/yadutaf/orgs",
"repos_url": "https://api.github.com/users/yadutaf/repos",
"events_url": "https://api.github.com/users/yadutaf/events{/privacy}",
"received_events_url": "https://api.github.com/users/yadutaf/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Thank you but I will pass on this, since it can be accomplished with an `UpdateQuery`.\n"
] | 2014-07-19T14:34:37 | 2014-07-20T12:31:02 | 2014-07-20T12:31:02 | NONE | null | Concurrent nodes of an application attempting to update the same record might result in data corruption/loss. To help with this scenario, this PR adds an optional `conditions` parameter on `Model.Save`. When the conditions are not met, updated record count will be `0` letting the application know the failure.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/397/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/397/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/397",
"html_url": "https://github.com/coleifer/peewee/pull/397",
"diff_url": "https://github.com/coleifer/peewee/pull/397.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/397.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/396 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/396/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/396/comments | https://api.github.com/repos/coleifer/peewee/issues/396/events | https://github.com/coleifer/peewee/issues/396 | 38,156,305 | MDU6SXNzdWUzODE1NjMwNQ== | 396 | SQLite doesn't like double parens | {
"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 | [
"``` sql\nSELECT t1.\"id\"\nFROM \"users\" AS t1 \nWHERE Exists((SELECT t2.\"id\" FROM \"users\" AS t2))\n```\n",
"Nice, thanks!\n"
] | 2014-07-18T08:14:40 | 2014-07-18T17:20:44 | 2014-07-18T15:28:55 | CONTRIBUTOR | null | This sample program shows the problem
``` python
from peewee import Model
from peewee import fn
from peewee import SqliteDatabase
db = SqliteDatabase(':memory:')
class User(Model):
class Meta:
db = db
User.create_table()
list(User.select().where(fn.Exists(User.select(User.id))))
```
Func always wraps the nodes in parens: https://github.com/coleifer/peewee/blob/2.2.5/peewee.py#L1141
And nested selects are always in parens: https://github.com/coleifer/peewee/blob/2.2.5/peewee.py#L1174
One approach might just be in the `isinstance(node, Func)` detect if the sql to wrap already `startswith('(')` and `endswith(')')`, but maybe there is something more clever.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/396/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/396/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/395 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/395/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/395/comments | https://api.github.com/repos/coleifer/peewee/issues/395/events | https://github.com/coleifer/peewee/issues/395 | 38,154,078 | MDU6SXNzdWUzODE1NDA3OA== | 395 | problem with Model.select(SQL('*'))... | {
"login": "goir",
"id": 586209,
"node_id": "MDQ6VXNlcjU4NjIwOQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/586209?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/goir",
"html_url": "https://github.com/goir",
"followers_url": "https://api.github.com/users/goir/followers",
"following_url": "https://api.github.com/users/goir/following{/other_user}",
"gists_url": "https://api.github.com/users/goir/gists{/gist_id}",
"starred_url": "https://api.github.com/users/goir/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/goir/subscriptions",
"organizations_url": "https://api.github.com/users/goir/orgs",
"repos_url": "https://api.github.com/users/goir/repos",
"events_url": "https://api.github.com/users/goir/events{/privacy}",
"received_events_url": "https://api.github.com/users/goir/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Peewee does not currently support this, unfortunately. You can always pass in the model class to `.select()` and it will select the appropriate columns.\n"
] | 2014-07-18T07:34:05 | 2014-07-18T12:46:55 | 2014-07-18T12:46:55 | NONE | null | Hi,
I have a very complex Query and want to use SQL('*') to select all fields to avoid specifying all fields and making the query even longer.
Very basic example:
```
from peewee import SqliteDatabase, PrimaryKeyField, CharField, Model, SQL, fn
db = SqliteDatabase(':memory:')
class Model1(Model):
id = PrimaryKeyField()
column = CharField()
class Meta(object):
database = db
Model1.create_table()
Model1.create(id=1, column='bar')
Model1.create(id=2, column='foo')
Model1.create(id=3, column='baz')
res = Model1.select(SQL("*"))
print res
for a in res:
print a
```
which results in the following error:
```
<class '__main__.Model1'> SELECT * FROM "model1" AS t1 []
File "<path>/tests/bla.py", line 30, in <module>
for a in res:
File "<path>/env_local/local/lib/python2.7/site-packages/peewee.py", line 1615, in next
obj = self.iterate()
File "<path>/env_local/local/lib/python2.7/site-packages/peewee.py", line 1601, in iterate
self.initialize(self.cursor.description)
File "<path>/env_local/local/lib/python2.7/site-packages/peewee.py", line 1643, in initialize
select_column = self.column_meta[i]
IndexError: list index out of range
```
i'm using the current master.
Thanks
Goir
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/395/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/395/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/394 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/394/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/394/comments | https://api.github.com/repos/coleifer/peewee/issues/394/events | https://github.com/coleifer/peewee/pull/394 | 37,939,947 | MDExOlB1bGxSZXF1ZXN0MTg0NDQyNjE= | 394 | UUID fixes | {
"login": "alexlatchford",
"id": 628146,
"node_id": "MDQ6VXNlcjYyODE0Ng==",
"avatar_url": "https://avatars.githubusercontent.com/u/628146?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/alexlatchford",
"html_url": "https://github.com/alexlatchford",
"followers_url": "https://api.github.com/users/alexlatchford/followers",
"following_url": "https://api.github.com/users/alexlatchford/following{/other_user}",
"gists_url": "https://api.github.com/users/alexlatchford/gists{/gist_id}",
"starred_url": "https://api.github.com/users/alexlatchford/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/alexlatchford/subscriptions",
"organizations_url": "https://api.github.com/users/alexlatchford/orgs",
"repos_url": "https://api.github.com/users/alexlatchford/repos",
"events_url": "https://api.github.com/users/alexlatchford/events{/privacy}",
"received_events_url": "https://api.github.com/users/alexlatchford/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Awesome cheers Charles. \n\nThis is amazing, I've already taken your code and am currently building and about to push to live :)\n"
] | 2014-07-16T00:43:42 | 2014-07-16T01:15:51 | 2014-07-16T01:05:09 | CONTRIBUTOR | null | Hi Charles,
Found another couple of bugs in the UUID implementation.
1. Finish off the UUIDField ForeignKeyField fixes, forgot to do the python_value implementation.. `UUID(None)` fails hard :(
2. Using a model as a query param fails for UUID primary key models with the following error:
```
[16/Jul/2014:10:05:35] HTTP Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/cherrypy/_cprequest.py", line 656, in respond
response.body = self.handler()
File "/Library/Python/2.7/site-packages/cherrypy/lib/encoding.py", line 188, in __call__
self.body = self.oldhandler(*args, **kwargs)
File "/Library/Python/2.7/site-packages/cherrypy/_cpdispatch.py", line 34, in __call__
return self.callable(*self.args, **self.kwargs)
File "/Users/alexlatchford/Code/abbreviate/a8-product/a8_product/../a8_product/routes/external_api/v1/summaries.py", line 190, in POST
db_image = SummaryImage.get(SummaryImage.summary == db_summary, SummaryImage.src == image['src'])
File "/Library/Python/2.7/site-packages/peewee.py", line 3049, in get
return sq.get()
File "/Library/Python/2.7/site-packages/peewee.py", line 2093, in get
return clone.execute().next()
File "/Library/Python/2.7/site-packages/peewee.py", line 2132, in execute
self._qr = ResultWrapper(model_class, self._execute(), query_meta)
File "/Library/Python/2.7/site-packages/peewee.py", line 1838, in _execute
return self.database.execute_sql(sql, params, self.require_commit)
File "/Library/Python/2.7/site-packages/playhouse/postgres_ext.py", line 255, in execute_sql
self.commit()
File "/Library/Python/2.7/site-packages/peewee.py", line 2283, in __exit__
reraise(new_type, new_type(*exc_value.args), traceback)
File "/Library/Python/2.7/site-packages/playhouse/postgres_ext.py", line 248, in execute_sql
res = cursor.execute(sql, params or ())
ProgrammingError: can't adapt type 'UUID'
```
I think this example should demonstrate the problem!
``` python
from peewee import *
from playhouse.postgres_ext import *
from uuid import UUID
class SomeModelA(Model):
uuid = UUIDField(primary_key=True)
class SomeModelB(Model):
name = CharField()
some_model_a = ForeignKeyField(SomeModelA)
# Create and populate the tables etc..
some_model_a = SomeModelA.get(SomeModelA.uuid == UUID('<uuid>'))
some_model_b = SomeModelB.get(SomeModelB.some_model_a == some_model_a)
# throws ProgrammingError
```
Thanks,
Alex
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/394/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/394/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/394",
"html_url": "https://github.com/coleifer/peewee/pull/394",
"diff_url": "https://github.com/coleifer/peewee/pull/394.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/394.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/393 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/393/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/393/comments | https://api.github.com/repos/coleifer/peewee/issues/393/events | https://github.com/coleifer/peewee/issues/393 | 37,874,286 | MDU6SXNzdWUzNzg3NDI4Ng== | 393 | create_table() got an unexpected keyword argument 'options' | {
"login": "danieldiekmeier",
"id": 2098462,
"node_id": "MDQ6VXNlcjIwOTg0NjI=",
"avatar_url": "https://avatars.githubusercontent.com/u/2098462?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/danieldiekmeier",
"html_url": "https://github.com/danieldiekmeier",
"followers_url": "https://api.github.com/users/danieldiekmeier/followers",
"following_url": "https://api.github.com/users/danieldiekmeier/following{/other_user}",
"gists_url": "https://api.github.com/users/danieldiekmeier/gists{/gist_id}",
"starred_url": "https://api.github.com/users/danieldiekmeier/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/danieldiekmeier/subscriptions",
"organizations_url": "https://api.github.com/users/danieldiekmeier/orgs",
"repos_url": "https://api.github.com/users/danieldiekmeier/repos",
"events_url": "https://api.github.com/users/danieldiekmeier/events{/privacy}",
"received_events_url": "https://api.github.com/users/danieldiekmeier/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Your models need to be using the `playhouse.sqlite_ext.SqliteExtDatabase` instead of the normal `peewee.SqliteDatabase`.\n",
"So:\n\n``` python\nclass FTSBook(FTSModel):\n content = TextField()\n class Meta:\n database = <some SqliteExtDatabase() instance>\n```\n"
] | 2014-07-15T11:39:33 | 2014-07-15T13:49:21 | 2014-07-15T13:49:21 | NONE | null | Okay, so I'm trying to create a FTSModel according to the instructions here: http://peewee.readthedocs.org/en/latest/peewee/playhouse.html#FTSModel
I have a model `Book` and a model
```
class FTSBook(FTSModel):
content = TextField()
```
that should be created and filled with
```
FTSBook.create_table(content=Book)
FTSBook.rebuild()
FTSBook.optimize()
```
but on the `create_table`-statement, I get the following error:
```
Traceback (most recent call last):
File "upgrade.py", line 218, in <module>
FTSBook.create_table(content=Book)
File "/Users/Daniel/dev/python/lesetagebuch/venv/lib/python3.4/site-packages/playhouse/sqlite_ext.py", line 102, in create_table
cls._meta.database.create_table(cls, options=options)
TypeError: create_table() got an unexpected keyword argument 'options'
```
So it seems to be an error inside the sqlite_ext-Module. Why is the options-keyword unexpected? I tried to just to `FTSBook.create_table()` (without any options), but I get the same error.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/393/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/393/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/392 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/392/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/392/comments | https://api.github.com/repos/coleifer/peewee/issues/392/events | https://github.com/coleifer/peewee/issues/392 | 37,860,276 | MDU6SXNzdWUzNzg2MDI3Ng== | 392 | meta_options are overwritten by clauses in child-classes | {
"login": "alexlatchford",
"id": 628146,
"node_id": "MDQ6VXNlcjYyODE0Ng==",
"avatar_url": "https://avatars.githubusercontent.com/u/628146?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/alexlatchford",
"html_url": "https://github.com/alexlatchford",
"followers_url": "https://api.github.com/users/alexlatchford/followers",
"following_url": "https://api.github.com/users/alexlatchford/following{/other_user}",
"gists_url": "https://api.github.com/users/alexlatchford/gists{/gist_id}",
"starred_url": "https://api.github.com/users/alexlatchford/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/alexlatchford/subscriptions",
"organizations_url": "https://api.github.com/users/alexlatchford/orgs",
"repos_url": "https://api.github.com/users/alexlatchford/repos",
"events_url": "https://api.github.com/users/alexlatchford/events{/privacy}",
"received_events_url": "https://api.github.com/users/alexlatchford/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Thanks for reporting this -- yes, peewee replaces the `order_by` string with a clause, but this is acting up in the chlid-classes. I will get a fix out soon.\n"
] | 2014-07-15T08:13:13 | 2014-07-15T14:14:18 | 2014-07-15T14:14:18 | CONTRIBUTOR | null | Hi Charles,
I think this example should be valid but is having difficulties:
``` python
from peewee import *
db = SqliteDatabase(':memory:')
db.connect()
class BaseModel(Model):
created = DateTimeField()
class Meta:
database = db
order_by = ('-created',)
class Extension(BaseModel):
some_field = CharField()
```
Gives the following error:
```
alexs-air:Code alexlatchford$ python test.py
Traceback (most recent call last):
File "test.py", line 13, in <module>
class Extension(BaseModel):
File "/Library/Python/2.7/site-packages/peewee.py", line 2990, in __new__
cls._meta.prepared()
File "/Library/Python/2.7/site-packages/peewee.py", line 2861, in prepared
field = self.fields[clause.lstrip('-')]
AttributeError: 'DateTimeField' object has no attribute 'lstrip'
```
Sorry I haven't had time to investigate it and find a patch, I'll see what I can do if this really annoys me. I'm just putting the order_by declarations on the sub-classes instead of the parent :)
Thanks,
Alex
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/392/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/392/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/391 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/391/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/391/comments | https://api.github.com/repos/coleifer/peewee/issues/391/events | https://github.com/coleifer/peewee/issues/391 | 37,751,856 | MDU6SXNzdWUzNzc1MTg1Ng== | 391 | Chaining separate .where() clauses with OR instead of AND | {
"login": "bryhoyt",
"id": 4769854,
"node_id": "MDQ6VXNlcjQ3Njk4NTQ=",
"avatar_url": "https://avatars.githubusercontent.com/u/4769854?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/bryhoyt",
"html_url": "https://github.com/bryhoyt",
"followers_url": "https://api.github.com/users/bryhoyt/followers",
"following_url": "https://api.github.com/users/bryhoyt/following{/other_user}",
"gists_url": "https://api.github.com/users/bryhoyt/gists{/gist_id}",
"starred_url": "https://api.github.com/users/bryhoyt/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/bryhoyt/subscriptions",
"organizations_url": "https://api.github.com/users/bryhoyt/orgs",
"repos_url": "https://api.github.com/users/bryhoyt/repos",
"events_url": "https://api.github.com/users/bryhoyt/events{/privacy}",
"received_events_url": "https://api.github.com/users/bryhoyt/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I think I'm going to leave the API as-is, but thank you for the suggestion.\n",
"Thanks for getting back to me really quickly. This does leave me with a couple questions:\n\nI love Peewee, and I love how using an ORM means I can factor my queries by using separate functions to further refine a query, without the messy string manipulation that would be necessary to factor plain-old-sql queries. But (without hacking peewee's internals) I can only refine existing queries with further restrictions, not extend them with further allowable criteria.\n\nIn most cases, this isn't a problem, because you can write your query from scratch. But I have a use-case in flask-admin, where I want to override a ModelView's `get_list()` method to further extend the search. I have a `Picture` model, where each `Picture` has multiple `Tags`. The builtin flask-admin search will filter on various columns I give it, but I want to include pictures that have tags included in the search keywords.\n\nCan you make a better suggestion than hacking into peewee's internals? \n",
"Sorry for necroposting but I have exactly the same issue. Actually this problem is not related with peewee. E.g. django ORM has the same API. If you want to extend your query you need to work with expression instead of query:\r\n\r\n expression = (Model.a == 'x') & (Model.b == 'y')\r\n if something:\r\n expression |= (Model.c == 'z')\r\n\r\n result = Model.select().where(expression)\r\n",
"Yes, necroposting but this really helped me @askabelin. \r\nFollowing up on that I'll post how I solve my problem:\r\n\r\n```\r\nfor item in list:\r\n if item is not None:\r\n expression &= (getattr(Model,item) == 'x')\r\n\r\nresult = Model.select().where(expression)\r\n```",
"The best way is to:\r\n\r\n```python\r\nimport operator\r\nfrom functools import reduce\r\n\r\nexpr_list = [\r\n (Foo.bar == 1),\r\n (Foo.baz == 2),\r\n (Foo.biz == 4)]\r\n\r\norexpr = reduce(operator.or_, expr_list)\r\n```\r\n\r\nYou can use `operator.and_` to AND- them together.",
"The original problem here was not chaining expressions together, but extending the WHERE clause of a full query. If you have a situation where you're provided with an existing query (`query = Model.select().where()`), there's no clear way to extend that query with an OR clause, when you don't have direct access to the underlying WHERE expression.\r\n\r\n@coleifer added `.orwhere()` for this purpose in https://github.com/coleifer/peewee/commit/f5ca758358f4de88e337399cd156b044208e167c but I notice that `.orwhere()` no longer exists in the latest peewee.py (unless I'm missing something). Did you decide it wasn't worth keeping in there?\r\n",
"I've re-added orwhere, thanks for the comment and the clarification:\r\n\r\nd8ff4d2bffd7ed1db97a6ddd016e8db3a73b3437",
"@askabelin Thank You for the answer. I need to write a conditioning script, which should change due to global parameter. Now I have a long if-else case:\r\n```\r\n if q is not None and ordering.find('starting_time'):\r\n tasks = Task.select().where(Task.name.contains(q)).order_by(Task.start_time).paginate(page, per_page)\r\n elif q is None and ordering.find('starting_time'):\r\n tasks = Task.select().order_by(Task.start_time)\r\n```\r\nCan You help how can I make it easier?\r\nThank You in advance!\r\n",
"```python\r\ntasks = Task.select().order_by(Task.start_time)\r\nif q is not None:\r\n tasks = tasks.where(Task.name.contains(q))\r\n```"
] | 2014-07-13T23:40:26 | 2021-04-30T05:01:34 | 2014-07-14T03:21:36 | CONTRIBUTOR | null | I have an existing query in my code that I wish to further extend the query with additional WHERE criteria, but chained with OR instead of AND.
I can't find a way to do this in peewee. Am I missing something? I am aware that I can dynamically chain multiple clauses with OR using `reduce(operator.or_, clauses)`, but this is a different thing -- it doesn't help me to extend an additional query.
I believe I can achieve this with something like `query._where = query._where | additional_criteria`, but this feels like a hack that requires knowledge of peewee's implementation details, not the published API -- always a bad idea.
I'm currently tinkering with a helper function something like the following:
```
def orwhere(query, *expressions):
import operator
query = query.clone()
reduced = reduce(operator.and_, expressions)
query._where = (query._where or True) | reduced # `or True` so that if it's the first expression in the clause, it still behaves consistently by broadening the queryset rather than restricting it.
return query
```
What do you think about adding .orwhere() to the query API? Or is there a better way that I'm missing?
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/391/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/391/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/390 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/390/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/390/comments | https://api.github.com/repos/coleifer/peewee/issues/390/events | https://github.com/coleifer/peewee/issues/390 | 37,547,955 | MDU6SXNzdWUzNzU0Nzk1NQ== | 390 | ImproperlyConfigured: MySQLdb must be installed. | {
"login": "Casyfill",
"id": 2675621,
"node_id": "MDQ6VXNlcjI2NzU2MjE=",
"avatar_url": "https://avatars.githubusercontent.com/u/2675621?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/Casyfill",
"html_url": "https://github.com/Casyfill",
"followers_url": "https://api.github.com/users/Casyfill/followers",
"following_url": "https://api.github.com/users/Casyfill/following{/other_user}",
"gists_url": "https://api.github.com/users/Casyfill/gists{/gist_id}",
"starred_url": "https://api.github.com/users/Casyfill/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/Casyfill/subscriptions",
"organizations_url": "https://api.github.com/users/Casyfill/orgs",
"repos_url": "https://api.github.com/users/Casyfill/repos",
"events_url": "https://api.github.com/users/Casyfill/events{/privacy}",
"received_events_url": "https://api.github.com/users/Casyfill/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Hi\n\nAre you using Python3? This may be a case for PyMySQL.\n\nMaybe the error message should be edited.\n",
"no, python 2.7\n",
"I installed PyMySQL already – still same issue(\n",
"This is not a peewee bug. You need to install one of the mysql python drivers:\n- mysql-python\n- pymysql\n\nYou can verify one of them is installed by running either:\n- import MySQLdb\n- import pymysql\n",
"I have both installed and passing this 'import test'\n",
"same error \n\n```\nraise ImproperlyConfigured('MySQLdb or PyMySQL must be installed.')\npeewee.ImproperlyConfigured: MySQLdb or PyMySQL must be installed.\n>>> \n>>> \n>>> import pymysql\n>>>\n```\n",
"This is the code, I'm not sure how it's failing:\n\n``` python\ntry:\n import MySQLdb as mysql # prefer the C module.\nexcept ImportError:\n try:\n import pymysql as mysql\n except ImportError:\n mysql = None\n```\n\nThen later...\n\n``` python\nclass MySQLDatabase(Database):\n ...\n def _connect(self, database, **kwargs):\n if not mysql:\n raise ImproperlyConfigured('MySQLdb or PyMySQL must be installed.')\n\n```\n",
"If you want to run that exact code and let me know the output that'd help to debug.\n\nYou can also try: `from peewee import mysql; print mysql` and share the output.\n",
"I have also pysqlite, but it always says , \"peewee.ImproperlyConfigured: pysqlite or sqlite3 must be installed. \"\n\nBelow is the list of PIP\nantiorm (1.2.1)\nblinker (1.4)\ncffi (1.7.0)\nclick (6.6)\nConfigArgParse (0.10.0)\ncryptography (1.4)\ndb (0.1.1)\ndb-sqlite3 (0.0.1)\nenum34 (1.1.6)\nFlask (0.11.1)\nFlask-Compress (1.3.0)\nFlask-Cors (2.1.2)\nFlask-MySQL (1.3)\nflask-peewee (0.6.7)\nfuture (0.15.2)\ngeopy (1.11.0)\ngpsoauth (0.3.0)\nidna (2.1)\nipaddress (1.0.16)\nitsdangerous (0.24)\nJinja2 (2.8)\nMarkupSafe (0.23)\nMySQL-python (1.2.5)\nmysql-replication (0.9)\nmysqli (0.5.3)\nneopysqlite (0.2.2)\npeewee (2.8.1)\npip (8.1.2)\nprotobuf (2.6.1)\nprotobuf-to-dict (0.1.0)\npyasn1 (0.1.9)\npycparser (2.14)\npycryptodomex (3.4.2)\nPyMySQL (0.7.5)\nPyMySQL3 (0.5)\npymysqlblinker (1.2)\npymysqlrpc (0.1.4)\npyOpenSSL (16.0.0)\npysqlite (2.8.2)\npython-dateutil (2.5.3)\nrequests (2.10.0)\ns2sphere (0.2.4)\nsetuptools (25.1.1)\nsix (1.10.0)\nsqlist (0.2.1b0)\nSQLite3Database (0.2.0)\ntermcolor (1.1.0)\ntomdb (0.5.1)\nWerkzeug (0.11.10)\nwheel (0.29.0)\nwtf-peewee (0.2.6)\nWTForms (2.1)\n\nI have tried many package, but it dose not work.\n",
"My Code is very simple\n\n`#!/usr/bin/python\n\n# -_\\- coding: utf-8 -_-\n\nimport logging\nimport logging.handlers\nfrom peewee import SqliteDatabase,Model, InsertQuery, IntegerField, CharField, \\\n FloatField, BooleanField, DateTimeField\n\nLOG_FILE = 'tst.log'\nhandler = logging.handlers.RotatingFileHandler(LOG_FILE, maxBytes=1024*1024, backupCount=5)\n # 实例化handler\nfmt = '%(asctime)s - %(filename)s:%(lineno)s - %(name)s - %(message)s'\n\nformatter = logging.Formatter(fmt) # 实例化formatter\nhandler.setFormatter(formatter) # 为handler添加formatter\nconsole = logging.StreamHandler()\nconsole.setLevel(logging.INFO)\nlogging.getLogger('').addHandler(console)\n\nlogger = logging.getLogger('test') \nlogger.addHandler(handler) \nlogger.setLevel(logging.DEBUG)\n\ndb = SqliteDatabase(\"peewee_db_learn.db\")\nprint db\nlogger.info(\"In die Software\")\n\nclass TestModel(Model):\n class Meta:\n database = db\n order_by = ('-num_id',)\n\n```\nnum_id = IntegerField(primary_key=True)\nname = CharField()\ntime = DateTimeField()\n```\n\ndef create_db():\n logger.info(\"PeeWee Connection\")\n db.connect()\n db.create_table(TestModel, safe=True)\n db.close()\n logger.info(\"PeeWee Finished\")\n\nif **name** == '**main**':\n create_db()\n`\n\nThe error is:\n\n`\nTraceback (most recent call last):\n File \"pwee.py\", line 49, in <module>\n create_db()\n File \"pwee.py\", line 43, in create_db\n db.connect()\n File \"/usr/local/lib/python2.7/site-packages/peewee.py\", line 3402, in connect\n **self.connect_kwargs)\n File \"/usr/local/lib/python2.7/site-packages/peewee.py\", line 3657, in _connect\n raise ImproperlyConfigured('pysqlite or sqlite3 must be installed.')\npeewee.ImproperlyConfigured: pysqlite or sqlite3 must be installed.\n`\n\nand now I have no idea, please help me . Thanks very much.\n",
"Well, apparently you don't have SQLite installed. If you're going to use\nthe SQLiteDatabase class, then you need SQLite bindings installed.\nTypically these are part of the normal python installation, but I'm not\nsure what kind of system you're running on so perhaps your Python was\ncompiled without SQLite.\n\nIt's an easy fix, though, just do:\n\npip install pysqlite\n\nOr you can install my fork of pysqlite ;)\n\npip install -e git+https://github.com/coleifer/pysqlite#egg=pysqlite\n\nCharles\n\nOn Sat, Jul 30, 2016 at 12:48 PM, Kevin Hao [email protected]\nwrote:\n\n> My Code is very simple\n> \n> `#!/usr/bin/python\n> -_\\- coding: utf-8 -_-\n> \n> import logging\n> import logging.handlers\n> from peewee import SqliteDatabase,Model, InsertQuery, IntegerField,\n> CharField, \\\n> FloatField, BooleanField, DateTimeField\n> \n> LOG_FILE = 'tst.log'\n> handler = logging.handlers.RotatingFileHandler(LOG_FILE,\n> maxBytes=1024*1024, backupCount=5)\n> \n> # 实例化handler\n> \n> fmt = '%(asctime)s - %(filename)s:%(lineno)s - %(name)s - %(message)s'\n> \n> formatter = logging.Formatter(fmt) # 实例化formatter\n> handler.setFormatter(formatter) # 为handler添加formatter\n> console = logging.StreamHandler()\n> console.setLevel(logging.INFO)\n> logging.getLogger('').addHandler(console)\n> \n> logger = logging.getLogger('test')\n> \n> logger.addHandler(handler)\n> \n> logger.setLevel(logging.DEBUG)\n> \n> db = SqliteDatabase(\"peewee_db_learn.db\")\n> print db\n> logger.info(\"In die Software\")\n> \n> class TestModel(Model):\n> class Meta:\n> database = db\n> order_by = ('-num_id',)\n> \n> num_id = IntegerField(primary_key=True)\n> name = CharField()\n> time = DateTimeField()\n> \n> def create_db():\n> logger.info(\"PeeWee Connection\")\n> db.connect()\n> db.create_table(TestModel, safe=True)\n> db.close()\n> logger.info(\"PeeWee Finished\")\n> \n> if _name_ == '_main_':\n> create_db()\n> `\n> \n> The error is:\n> \n> Traceback (most recent call last):\n> File \"pwee.py\", line 49, in <module>\n> create_db()\n> File \"pwee.py\", line 43, in create_db\n> db.connect()\n> File \"/usr/local/lib/python2.7/site-packages/peewee.py\", line 3402, in\n> connect\n> **self.connect_kwargs)\n> File \"/usr/local/lib/python2.7/site-packages/peewee.py\", line 3657, in\n> _connect\n> raise ImproperlyConfigured('pysqlite or sqlite3 must be installed.')\n> peewee.ImproperlyConfigured: pysqlite or sqlite3 must be installed.\n> \n> and now I have no idea, please help me . Thanks very much.\n> \n> —\n> You are receiving this because you modified the open/close state.\n> Reply to this email directly, view it on GitHub\n> https://github.com/coleifer/peewee/issues/390#issuecomment-236379147,\n> or mute the thread\n> https://github.com/notifications/unsubscribe-auth/AAHUpnMKSCkjxn279qFXy11v3WkvP-L_ks5qa45xgaJpZM4CL55a\n> .\n",
"Sorry, I read your post a bit more closely, and I see now that you have\ninstalled pysqlite 2.8.2. You can uninstall all that bullshit like\nneopysqlite (whatever the hell that is) and Sqlite3Database.\n\nIn your virtualenv, try activating it (assuming you are comfortable working\nwith virtualenv), running python and typing:\n\n> > > from pysqlite2 import dbapi2 as sqlite3\n> > > conn = sqlite3.connect(':memory:')\n\nDo you get an ImportError? If you do, then something is wrong with your\ninstallation of pysqlite.\n\nIf you do not get an ImportError, try the following:\n\n> > > from peewee import sqlite3\n> > > sqlite3 # just type the name of the module and press \"Enter\".\n\nWhat does it show for your sqlite3? Here's an example from one of my\nvirtualenvs where I've got a custom version of pysqlite:\n\n> > > from peewee import sqlite3\n> > > sqlite3\n> > > <module 'pysqlite2.dbapi2' from\n> > > '/home/code/envs/media_manager/lib/python2.7/site-packages/pysqlite2/dbapi2.pyc'>\n\nLet me know, thanks!\n\nOn Sat, Jul 30, 2016 at 1:42 PM, Charles Leifer [email protected] wrote:\n\n> Well, apparently you don't have SQLite installed. If you're going to use\n> the SQLiteDatabase class, then you need SQLite bindings installed.\n> Typically these are part of the normal python installation, but I'm not\n> sure what kind of system you're running on so perhaps your Python was\n> compiled without SQLite.\n> \n> It's an easy fix, though, just do:\n> \n> pip install pysqlite\n> \n> Or you can install my fork of pysqlite ;)\n> \n> pip install -e git+https://github.com/coleifer/pysqlite#egg=pysqlite\n> \n> Charles\n> \n> On Sat, Jul 30, 2016 at 12:48 PM, Kevin Hao [email protected]\n> wrote:\n> \n> > My Code is very simple\n> > \n> > `#!/usr/bin/python\n> > -_\\- coding: utf-8 -_-\n> > \n> > import logging\n> > import logging.handlers\n> > from peewee import SqliteDatabase,Model, InsertQuery, IntegerField,\n> > CharField, \\\n> > FloatField, BooleanField, DateTimeField\n> > \n> > LOG_FILE = 'tst.log'\n> > handler = logging.handlers.RotatingFileHandler(LOG_FILE,\n> > maxBytes=1024*1024, backupCount=5)\n> > \n> > # 实例化handler\n> > \n> > fmt = '%(asctime)s - %(filename)s:%(lineno)s - %(name)s - %(message)s'\n> > \n> > formatter = logging.Formatter(fmt) # 实例化formatter\n> > handler.setFormatter(formatter) # 为handler添加formatter\n> > console = logging.StreamHandler()\n> > console.setLevel(logging.INFO)\n> > logging.getLogger('').addHandler(console)\n> > \n> > logger = logging.getLogger('test')\n> > \n> > logger.addHandler(handler)\n> > \n> > logger.setLevel(logging.DEBUG)\n> > \n> > db = SqliteDatabase(\"peewee_db_learn.db\")\n> > print db\n> > logger.info(\"In die Software\")\n> > \n> > class TestModel(Model):\n> > class Meta:\n> > database = db\n> > order_by = ('-num_id',)\n> > \n> > num_id = IntegerField(primary_key=True)\n> > name = CharField()\n> > time = DateTimeField()\n> > \n> > def create_db():\n> > logger.info(\"PeeWee Connection\")\n> > db.connect()\n> > db.create_table(TestModel, safe=True)\n> > db.close()\n> > logger.info(\"PeeWee Finished\")\n> > \n> > if _name_ == '_main_':\n> > create_db()\n> > `\n> > \n> > The error is:\n> > \n> > Traceback (most recent call last):\n> > File \"pwee.py\", line 49, in <module>\n> > create_db()\n> > File \"pwee.py\", line 43, in create_db\n> > db.connect()\n> > File \"/usr/local/lib/python2.7/site-packages/peewee.py\", line 3402, in\n> > connect\n> > **self.connect_kwargs)\n> > File \"/usr/local/lib/python2.7/site-packages/peewee.py\", line 3657, in\n> > _connect\n> > raise ImproperlyConfigured('pysqlite or sqlite3 must be installed.')\n> > peewee.ImproperlyConfigured: pysqlite or sqlite3 must be installed.\n> > \n> > and now I have no idea, please help me . Thanks very much.\n> > \n> > —\n> > You are receiving this because you modified the open/close state.\n> > Reply to this email directly, view it on GitHub\n> > https://github.com/coleifer/peewee/issues/390#issuecomment-236379147,\n> > or mute the thread\n> > https://github.com/notifications/unsubscribe-auth/AAHUpnMKSCkjxn279qFXy11v3WkvP-L_ks5qa45xgaJpZM4CL55a\n> > .\n",
"@Casyfill Thanks for your answer, but in my server I have installed the MySQL-python. It seems not to work for me. And I program it not for managing MySQL ,instead of Sqlite. I have tried for 1 day, but still not solved. Thanks. \n",
"@Casyfill Now I will follow your advice to create a table. Then , tell you the results. Thanks.\n",
"@Casyfill I have tried to create a table , but it still does not work.\n",
"@seriousdude No , I am programing with Python 2.7 \n",
"I have solved the problem. Before I compiled the Python 2.7, I have not still installed the Sqlite. There is no sqlite.so. Thanks.\n",
"needs to `pip install PyMySQL`\r\nin python3.5.2\r\n\r\nthat fixed my problem, thanks @seriousdude ",
"Hi, first let me thank you for all the hard work. Thanks!\r\nI'm facing this same issue on an ubuntu server, production deploy. But not all the times, I got it for most of reuquests for my Flask app, but for some some others it does work.\r\n\r\nIts on a virtualenv python 3.5.2, I have installed pymysql and imports work, I also got peewee working just fine on separate anaconda 3.6 environment.\r\n\r\nNot sure how to debug this, as the modules and all this threads point that I'm doing OK.\r\n\r\nThanks in advice ! \r\n\r\n",
"@laureanoarcanio -- that sounds very much like a deployment issue. Peewee needs to be installed in the same virtual environment as pymysql in order to work correctly.",
"Hi,\r\nI have bumped into the same issue today, except with psycopg2.\r\nI have deployed a Flask application with apache mod_wsgi, with virtualenv.\r\nRunning `from peewee import psycopg2` from console is successful.\r\nBut when accessed through the web application peewee raises `ImproperlyConfigured: psycopg2 must be installed.`\r\n",
"You're surely running your app using a different python-path (sys.path) than when you run your console.",
"The wsgi starts the same venv, and everything is visible from there. It turns out, the actual error when importing pycopg2 is this:\r\n`ImportError: /home/sysadm/customizer/venv/local/lib/python2.7/site-packages/psycopg2/_psycopg.so: wrong ELF class: ELFCLASS32`",
"Aha, thanks @asztalosdani -- hope you got things working."
] | 2014-07-10T09:58:29 | 2018-03-14T13:57:51 | 2014-07-10T14:34:42 | NONE | null | I am getting this any time I am trying to create a table or do something with connected DB,
althrough I installed MySQL-python lib and it looks working
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/390/reactions",
"total_count": 2,
"+1": 2,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/390/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/389 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/389/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/389/comments | https://api.github.com/repos/coleifer/peewee/issues/389/events | https://github.com/coleifer/peewee/issues/389 | 37,435,917 | MDU6SXNzdWUzNzQzNTkxNw== | 389 | Dirty field not set in RelationDescriptor __set__ override | {
"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 | [
"Another related question is just, why not default to always only saving dirty fields. Just wondering if I am missing something where that would be unsafe? That does seem to be the behavior when you have a CompositeKey? https://github.com/coleifer/peewee/blob/2.2.5/peewee.py#L3159\n",
"> Another related question is just, why not default to always only saving dirty fields.\n\nIt's easier to understand.\n",
"I can just actually lead to some unclear behavior. What happened to me is that I have an incrementing field on an object, num_members. I never modify this in code, only in a trigger, but save was overwriting num_members with an older value. The advantage of only saving modified fields is that you can be sure there are no unintended overwrites like this.\n"
] | 2014-07-09T05:50:32 | 2014-07-09T17:36:03 | 2014-07-09T17:32:07 | CONTRIBUTOR | null | Setting foreign key values doesn't mark those fields dirty.
https://github.com/coleifer/peewee/blob/2.2.5/peewee.py#L885
I am also wondering if Model.prepared should clear dirty fields. As is, just fetching objects from the DB ends up marking all the fields dirty.
https://github.com/coleifer/peewee/blob/2.2.5/peewee.py#L3140
Both of these issues make it hard to call save with `only=self.dirty_fields`
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/389/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/389/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/388 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/388/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/388/comments | https://api.github.com/repos/coleifer/peewee/issues/388/events | https://github.com/coleifer/peewee/issues/388 | 37,431,839 | MDU6SXNzdWUzNzQzMTgzOQ== | 388 | Duplicate results when iterating a select query and creating unrelated models | {
"login": "moloney",
"id": 1376566,
"node_id": "MDQ6VXNlcjEzNzY1NjY=",
"avatar_url": "https://avatars.githubusercontent.com/u/1376566?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/moloney",
"html_url": "https://github.com/moloney",
"followers_url": "https://api.github.com/users/moloney/followers",
"following_url": "https://api.github.com/users/moloney/following{/other_user}",
"gists_url": "https://api.github.com/users/moloney/gists{/gist_id}",
"starred_url": "https://api.github.com/users/moloney/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/moloney/subscriptions",
"organizations_url": "https://api.github.com/users/moloney/orgs",
"repos_url": "https://api.github.com/users/moloney/repos",
"events_url": "https://api.github.com/users/moloney/events{/privacy}",
"received_events_url": "https://api.github.com/users/moloney/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I found that wrapping the for loop in a transaction solves the problem, so I guess this is expected behavior. It does still seem worth it to make this more clear in the documentation.\n",
"Check out:\n- https://github.com/coleifer/peewee/issues/12#issuecomment-5614404\n- https://github.com/coleifer/peewee/issues/81\n"
] | 2014-07-09T03:46:51 | 2014-10-01T20:16:47 | 2014-07-09T12:50:30 | NONE | null | I know modification of an iterable while iterating over it can cause problems, but it seems surprising that I can't iterate a select query while creating completely unrelated model instances.
``` python
import peewee as pw
class DatabaseModel(pw.Model):
class Meta:
database = pw.SqliteDatabase(':memory:')
class A(DatabaseModel):
name = pw.CharField()
class B(DatabaseModel):
name = pw.CharField()
A.create_table()
B.create_table()
for name in ('test1', 'test2'):
A.create(name=name)
for a in A.select():
print a.name
B.create(name='blah')
```
Produces:
```
test1
test2
test1
test2
```
Not sure if this is expected, but I couldn't find anything in the documentation.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/388/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/388/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/387 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/387/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/387/comments | https://api.github.com/repos/coleifer/peewee/issues/387/events | https://github.com/coleifer/peewee/pull/387 | 37,242,972 | MDExOlB1bGxSZXF1ZXN0MTgwMjg4ODI= | 387 | Fix nullable UUID foreign keys | {
"login": "alexlatchford",
"id": 628146,
"node_id": "MDQ6VXNlcjYyODE0Ng==",
"avatar_url": "https://avatars.githubusercontent.com/u/628146?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/alexlatchford",
"html_url": "https://github.com/alexlatchford",
"followers_url": "https://api.github.com/users/alexlatchford/followers",
"following_url": "https://api.github.com/users/alexlatchford/following{/other_user}",
"gists_url": "https://api.github.com/users/alexlatchford/gists{/gist_id}",
"starred_url": "https://api.github.com/users/alexlatchford/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/alexlatchford/subscriptions",
"organizations_url": "https://api.github.com/users/alexlatchford/orgs",
"repos_url": "https://api.github.com/users/alexlatchford/repos",
"events_url": "https://api.github.com/users/alexlatchford/events{/privacy}",
"received_events_url": "https://api.github.com/users/alexlatchford/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Looks good, thanks for this!\n",
"Awesome cheers Charles. Just me being cheeky but what's your release schedule normally? Is it just when it hits a critical mass or is timed etc., obviously looking to get this into my product officially (I'll use a git dependency for now though :))\n\nThanks again,\nAlex\n",
"It's very abstract at the moment, but I can push a new release, no probs.\n",
"2.2.5 now available on pypi.\n",
"Awesome, thanks! Love this module :smile: \n"
] | 2014-07-07T06:48:30 | 2014-07-08T22:37:57 | 2014-07-07T11:41:17 | CONTRIBUTOR | null | Hi guys,
Found a bug in the PostgresExt implementation of UUIDField for foreign keys. Let me know if the patch is satisfactory, it fixes my bug but not sure of the impact, would be great to get this in from my point of view :)
Example:
``` python
class Entity(Model):
uuid = UUIDField(primary_key=True)
name = CharField()
class User(Model):
name = CharField()
entity = ForeignKeyField(Entity, related_name="users", null=True)
User.create(name="Joe")
user = User.select().where(name="Joe").first()
user.name = "Barry"
user.save() # See error below..
```
Obviously a user **may** belong to a entity. I get this with the current implementation :(
```
Traceback (most recent call last):
... <redacted>
File "/Users/alexlatchford/Code/abbreviate/a8-product/a8_product/../a8_product/database/__init__.py", line 77, in save
return super(MetaBaseModel, self).save(*args, **kwargs)
File "/Library/Python/2.7/site-packages/peewee.py", line 3106, in save
rows = self.update(**field_dict).where(self.pk_expr()).execute()
File "/Library/Python/2.7/site-packages/peewee.py", line 2140, in execute
return self.database.rows_affected(self._execute())
File "/Library/Python/2.7/site-packages/peewee.py", line 1796, in _execute
return self.database.execute_sql(sql, params, self.require_commit)
File "/Library/Python/2.7/site-packages/playhouse/postgres_ext.py", line 255, in execute_sql
self.commit()
File "/Library/Python/2.7/site-packages/peewee.py", line 2234, in __exit__
reraise(new_type, new_type(*exc_value.args), traceback)
File "/Library/Python/2.7/site-packages/playhouse/postgres_ext.py", line 248, in execute_sql
res = cursor.execute(sql, params or ())
DataError: invalid input syntax for uuid: "None"
LINE 1: ...'c8c4bb1aba234033b57d30b433f03354', "entity_id" = 'None', "i...
```
Many thanks,
Alex
PS. That example should work, my current one is a little bit more complicated than this so I had to write the example on the fly to simplify it down, apologies if it doesn't. You get the gist :)
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/387/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/387/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/387",
"html_url": "https://github.com/coleifer/peewee/pull/387",
"diff_url": "https://github.com/coleifer/peewee/pull/387.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/387.patch",
"merged_at": "2014-07-07T11:41:17"
} |
https://api.github.com/repos/coleifer/peewee/issues/386 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/386/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/386/comments | https://api.github.com/repos/coleifer/peewee/issues/386/events | https://github.com/coleifer/peewee/issues/386 | 37,208,743 | MDU6SXNzdWUzNzIwODc0Mw== | 386 | pylint doesn't see .id members of model instances | {
"login": "pitchforks",
"id": 4378791,
"node_id": "MDQ6VXNlcjQzNzg3OTE=",
"avatar_url": "https://avatars.githubusercontent.com/u/4378791?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/pitchforks",
"html_url": "https://github.com/pitchforks",
"followers_url": "https://api.github.com/users/pitchforks/followers",
"following_url": "https://api.github.com/users/pitchforks/following{/other_user}",
"gists_url": "https://api.github.com/users/pitchforks/gists{/gist_id}",
"starred_url": "https://api.github.com/users/pitchforks/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/pitchforks/subscriptions",
"organizations_url": "https://api.github.com/users/pitchforks/orgs",
"repos_url": "https://api.github.com/users/pitchforks/repos",
"events_url": "https://api.github.com/users/pitchforks/events{/privacy}",
"received_events_url": "https://api.github.com/users/pitchforks/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I'm not sure what to do about this on the peewee side -- perhaps you could just add the following to your models:\n\n``` python\nid = PrimaryKeyField()\n```\n",
"This works. Thank you.\n"
] | 2014-07-06T00:16:45 | 2014-07-07T03:31:28 | 2014-07-07T00:30:17 | NONE | null | I am not sure this is a peewee issue, so feel free to close it if you think it's invalid (or if you are confident this is a pylint bug)
I am using peewee-2.2.4
Everytime I have a line like myModelInstance.id in the code, pylint complains that "[E1101] Instance of 'MyModel' has no 'id' member".
I don't want to turn this error off globally in the config file of pylint. So, to make pylint shut up, I end with a lot of comments that turn each error off explicitly: "# pylint: disable=E1101" - one such comment at the end of each line where pylint complains. This feels extremely ugly.
Is it possible to make peewee somehow expose this id field, so pylint would stop complaining about it?
edit: typo
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/386/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/386/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/385 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/385/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/385/comments | https://api.github.com/repos/coleifer/peewee/issues/385/events | https://github.com/coleifer/peewee/issues/385 | 37,189,655 | MDU6SXNzdWUzNzE4OTY1NQ== | 385 | How to set threadlocals when using peewee with Flask? | {
"login": "kramer65",
"id": 596581,
"node_id": "MDQ6VXNlcjU5NjU4MQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/596581?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/kramer65",
"html_url": "https://github.com/kramer65",
"followers_url": "https://api.github.com/users/kramer65/followers",
"following_url": "https://api.github.com/users/kramer65/following{/other_user}",
"gists_url": "https://api.github.com/users/kramer65/gists{/gist_id}",
"starred_url": "https://api.github.com/users/kramer65/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/kramer65/subscriptions",
"organizations_url": "https://api.github.com/users/kramer65/orgs",
"repos_url": "https://api.github.com/users/kramer65/repos",
"events_url": "https://api.github.com/users/kramer65/events{/privacy}",
"received_events_url": "https://api.github.com/users/kramer65/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"In your `DATABASE` declaration just put `'threadlocals': True` -- that's all you need to do.\n"
] | 2014-07-05T00:01:55 | 2014-07-05T18:12:21 | 2014-07-05T18:12:21 | NONE | null | I'm using Peewee with Flask (which is an awesome combination) and because I use threading I want to set `threadlocals=True`. In [the documentation](http://peewee.readthedocs.org/en/latest/peewee/cookbook.html#multi-threaded-applications), it is suggested that I use it like so:
```
concurrent_db = SqliteDatabase('stats.db', threadlocals=True)
```
In my Flask app however, I initialise the DB like this:
```
app = Flask(__name__)
app.config.from_object('config')
db = Database(app)
```
and in the config file I've got among other stuff, this to define the DB:
```
DATABASE = {
'name': 'mydb',
'engine': 'playhouse.postgres_ext.PostgresqlExtDatabase',
'user': 'myuser',
'password': 'supersecret'
}
```
I tried putting `threadlocals = True` in the config file, which doesn't give any errors, but how do I know whether it really picked it up and is using it? Is there a way to check whether I'm actually using threadlocals?
What is the proper way to set threadlocals to True when using Flask? All tips are welcome!
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/385/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/385/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/384 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/384/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/384/comments | https://api.github.com/repos/coleifer/peewee/issues/384/events | https://github.com/coleifer/peewee/issues/384 | 37,140,341 | MDU6SXNzdWUzNzE0MDM0MQ== | 384 | UUID primary keys | {
"login": "alexlatchford",
"id": 628146,
"node_id": "MDQ6VXNlcjYyODE0Ng==",
"avatar_url": "https://avatars.githubusercontent.com/u/628146?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/alexlatchford",
"html_url": "https://github.com/alexlatchford",
"followers_url": "https://api.github.com/users/alexlatchford/followers",
"following_url": "https://api.github.com/users/alexlatchford/following{/other_user}",
"gists_url": "https://api.github.com/users/alexlatchford/gists{/gist_id}",
"starred_url": "https://api.github.com/users/alexlatchford/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/alexlatchford/subscriptions",
"organizations_url": "https://api.github.com/users/alexlatchford/orgs",
"repos_url": "https://api.github.com/users/alexlatchford/repos",
"events_url": "https://api.github.com/users/alexlatchford/events{/privacy}",
"received_events_url": "https://api.github.com/users/alexlatchford/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Aha, scratch that I found the 1.0 -> 2.0 upgrade notes. My bad, closing...\n\nFor anyone finding this:\n\n``` python\nclass MyModel(Model):\n uuid = UUIDField(primary_key=True)\n ...\n```\n"
] | 2014-07-04T03:45:09 | 2014-07-04T03:52:06 | 2014-07-04T03:52:06 | CONTRIBUTOR | null | I'd like to have `playhouse.postgres_ext.UUIDField` as the primary key for a table.
https://github.com/coleifer/peewee/issues/9 seems to suggest that this should be possible, but seems to have been deprecated since it's first introduction in 2012. Any suggestions?
Cheers,
Alex
PS. Awesome ORM, switched over from SQLAlchemy and loving every minute of it thus far!
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/384/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/384/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/383 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/383/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/383/comments | https://api.github.com/repos/coleifer/peewee/issues/383/events | https://github.com/coleifer/peewee/issues/383 | 36,959,483 | MDU6SXNzdWUzNjk1OTQ4Mw== | 383 | Does peewee work with Gevent? | {
"login": "yueyoum",
"id": 2081686,
"node_id": "MDQ6VXNlcjIwODE2ODY=",
"avatar_url": "https://avatars.githubusercontent.com/u/2081686?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/yueyoum",
"html_url": "https://github.com/yueyoum",
"followers_url": "https://api.github.com/users/yueyoum/followers",
"following_url": "https://api.github.com/users/yueyoum/following{/other_user}",
"gists_url": "https://api.github.com/users/yueyoum/gists{/gist_id}",
"starred_url": "https://api.github.com/users/yueyoum/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/yueyoum/subscriptions",
"organizations_url": "https://api.github.com/users/yueyoum/orgs",
"repos_url": "https://api.github.com/users/yueyoum/repos",
"events_url": "https://api.github.com/users/yueyoum/events{/privacy}",
"received_events_url": "https://api.github.com/users/yueyoum/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Yes it does, You need to set Threadlocals to True\n\n```\n# app configuration\nDATABASE = {\n 'name': 'my_db',\n 'engine': 'peewee.PostgresqlDatabase',\n 'user': 'postgres',\n 'threadlocals': True, # <-- this\n}\n```\n\nand then just monkey patch the thread module.\n",
"If you're using it with postgresql you need to monkeypatch `psycopg2`:\n\n``` python\nfrom gevent import monkey\n\nfrom gevent.socket import wait_read, wait_write\ntry:\n from psycopg2 import extensions\nexcept ImportError:\n extensions = None\n\n\ndef monkeypatch_psycopg2():\n extensions.set_wait_callback(gevent_wait_callback)\n\ndef gevent_wait_callback(conn, timeout=None):\n \"\"\"A wait callback useful to allow gevent to work with Psycopg.\"\"\"\n while 1:\n state = conn.poll()\n if state == extensions.POLL_OK:\n break\n elif state == extensions.POLL_READ:\n wait_read(conn.fileno(), timeout=timeout)\n elif state == extensions.POLL_WRITE:\n wait_write(conn.fileno(), timeout=timeout)\n else:\n raise psycopg2.OperationalError(\n \"Bad result from poll: %r\" % state)\n```\n"
] | 2014-07-02T07:56:38 | 2014-07-02T13:35:10 | 2014-07-02T13:35:10 | NONE | null | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/383/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/383/timeline | null | completed | null | null |
|
https://api.github.com/repos/coleifer/peewee/issues/382 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/382/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/382/comments | https://api.github.com/repos/coleifer/peewee/issues/382/events | https://github.com/coleifer/peewee/issues/382 | 36,836,910 | MDU6SXNzdWUzNjgzNjkxMA== | 382 | Unable to reach foreign key when doing an 'join on' with table | {
"login": "jonathan-s",
"id": 2124818,
"node_id": "MDQ6VXNlcjIxMjQ4MTg=",
"avatar_url": "https://avatars.githubusercontent.com/u/2124818?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/jonathan-s",
"html_url": "https://github.com/jonathan-s",
"followers_url": "https://api.github.com/users/jonathan-s/followers",
"following_url": "https://api.github.com/users/jonathan-s/following{/other_user}",
"gists_url": "https://api.github.com/users/jonathan-s/gists{/gist_id}",
"starred_url": "https://api.github.com/users/jonathan-s/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/jonathan-s/subscriptions",
"organizations_url": "https://api.github.com/users/jonathan-s/orgs",
"repos_url": "https://api.github.com/users/jonathan-s/repos",
"events_url": "https://api.github.com/users/jonathan-s/events{/privacy}",
"received_events_url": "https://api.github.com/users/jonathan-s/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Try adding `UserOrder.link_to_id` to the select clause:\n\n``` python\n(ExtensionData.\n select(\n ExtensionData, UserOrder.avg_user, UserOrder.link_to_id)\n .join(UserOrder, on=(ExtensionData.id == UserOrder.link_to_id))\n .order_by(UserOrder.avg_user.desc()))\n```\n\nIf that doesn't work, could you share a minimal set of model code so that I can attempt to reproduce the issue?\n",
"Nope, your suggested solution did not work. I've shared my model code below. UserOrder is a view. \n\n```\nclass BaseModel(Model):\n class Meta:\n database = db\n\nclass ExtensionData(BaseModel):\n name = CharField()\n link = CharField(unique=True) \n hp = CharField(null=True)\n email = CharField(null=True)\n category = CharField(null=True)\n browser = CharField()\n updated = DateField(default=datetime.date.today())\n\nclass DailyData(BaseModel):\n date_scraped = DateField(default=datetime.date.today())\n link_to = ForeignKeyField(ExtensionData, related_name='data_entries')\n nr_users = IntegerField()\n nr_reviews = IntegerField()\n downloads = IntegerField(null=True)\n rating = DecimalField()\n\nclass UserOrder(BaseModel):\n link_to_id = PrimaryKeyField()\n avg_user = FloatField()\n\n class Meta:\n db_table = 'user_order'\n```\n",
"The issue is that the `id` field is getting overwritten by the related `UserOrder`. To fix this:\n\n``` python\n(ExtensionData.\n select(\n ExtensionData, UserOrder.avg_user, UserOrder.link_to_id)\n .join(\n UserOrder, \n on=(ExtensionData.id == UserOrder.link_to_id).alias('user_order'))\n .order_by(UserOrder.avg_user.desc()))\n```\n",
"Great, thank you. I'm thinking of writing something about this in the documentation, it would be nice to include something about referring views as well as I couldn't find that in the documentation either when I was looking. Perhaps under Peewee cookbook section?\n",
"Sounds good, feel free to submit a pull-request.\n"
] | 2014-06-30T20:44:48 | 2014-07-01T20:32:41 | 2014-07-01T19:42:47 | NONE | null | So when I join the ExtensionData and UserOrder together I'm unable to access the foreign key relationship (data_entries) with DailyData. It seems as if it doesn't get the primary key from ExtensionData because of [None] at the end of the SQL query. This does not happen when you the ExtensionData by itself.
```
output = ExtensionData.select(ExtensionData, UserOrder.avg_user).join(
UserOrder, on=(ExtensionData.id == UserOrder.link_to_id)
).order_by(UserOrder.avg_user.desc())
entry = output[0]
entry.data_entries >
<class 'models.DailyData'> SELECT t1."id", t1."date_scraped", t1."link_to_id", t1."nr_users", t1."nr_reviews", t1."downloads", t1."rating" FROM "dailydata" AS t1 WHERE (t1."link_to_id" = %s) [None]
entry.id >
<models.UserOrder object at 0x1593490> # id has been replaced by this
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/382/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/382/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/381 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/381/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/381/comments | https://api.github.com/repos/coleifer/peewee/issues/381/events | https://github.com/coleifer/peewee/pull/381 | 36,812,371 | MDExOlB1bGxSZXF1ZXN0MTc3ODIzNDA= | 381 | MySQL Prefetch with Limit Fix | {
"login": "jpttrssn",
"id": 194305,
"node_id": "MDQ6VXNlcjE5NDMwNQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/194305?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/jpttrssn",
"html_url": "https://github.com/jpttrssn",
"followers_url": "https://api.github.com/users/jpttrssn/followers",
"following_url": "https://api.github.com/users/jpttrssn/following{/other_user}",
"gists_url": "https://api.github.com/users/jpttrssn/gists{/gist_id}",
"starred_url": "https://api.github.com/users/jpttrssn/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/jpttrssn/subscriptions",
"organizations_url": "https://api.github.com/users/jpttrssn/orgs",
"repos_url": "https://api.github.com/users/jpttrssn/repos",
"events_url": "https://api.github.com/users/jpttrssn/events{/privacy}",
"received_events_url": "https://api.github.com/users/jpttrssn/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I'm going to pass on merging this changeset. Even though MySQL does not support LIMIT on subqueries, you still could perform the limit prior to calling `prefetch()`, e.g.:\n\n``` python\nq1 = User.select()\nq2 = Blog.select().limit(10)\nprefetch(q1, q2) # does not work on mysql\n```\n\nInstead do:\n\n``` python\nq1 = User.select()\nq2 = Blog.select().limit(10)\nq2_fixed = Blog.select().where(Blog.id << [x.id for x in q2])\nprefetch(q1, q2_fixed) # this should work fine.\n```\n",
"What if I need to limit the User query and not the Blog query?\n\n```\nq1 = User.select().limit(10)\nq2 = Blog.select()\nprefetch(q1, q2) # does not work on mysql\n```\n",
"Do the same thing...\n\n``` python\nq1 = User.select().limit(10)\nq1_fixed = User.select().where(User.id << [x.id for x in q1])\nprefetch(q1_fixed, Blog.select())\n```\n",
"I'm trying to avoid running extra queries, but this will do. Thanks, man!\n"
] | 2014-06-30T16:11:52 | 2014-07-02T19:54:48 | 2014-07-02T19:20:33 | CONTRIBUTOR | null | MySQL does not support using LIMIT and IN subquery. To fix you have to run the subquery first and then pass in the result. This will add 1 additional query for every subquery passed to prefetch. This approach causes errors in test_prefetch_non_pk_fk, test_prefetch_subquery and test_prefetch_subquery_same_depth due to there being no database to run the subquery on and fails on test_prefetch_multi_depth and test_prefetch_simple because of the additional queries.
There is a potential work around that would reduce this back to the optimal number of queries by running the outer queries when needed without changing the select, storing the result, and getting the necessary list of foreign keys to use for the inner query result. This would be a decent amount of changes and I defer to you to decide if this is worth it for this specific case and whether this solution is MySQL only. There may be a performance benefit here when you no longer need to run the subquery inside the IN clause, but it could also be worse for larger datasets? Is passing in a list of 1,000 or 10,000 foreign keys to an IN clause problematic? Perhaps there could be a flag that you set on whether you want to use a subquery in the IN clause or a list of results? You would probably know better.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/381/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/381/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/381",
"html_url": "https://github.com/coleifer/peewee/pull/381",
"diff_url": "https://github.com/coleifer/peewee/pull/381.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/381.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/380 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/380/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/380/comments | https://api.github.com/repos/coleifer/peewee/issues/380/events | https://github.com/coleifer/peewee/issues/380 | 36,289,035 | MDU6SXNzdWUzNjI4OTAzNQ== | 380 | SQLite migration bug? | {
"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 can confirm the weird behavior with the testcase above and on my code too. In my case the models are similar: a Feed model and an Entry model, with the latter having a FK to Feed. \n\nOn my machine it gives this error:\n\n> peewee.OperationalError: table page__tmp__ has no column named FOREIGN\n\nI'm using:\n\n```\nUnderworld:$ python\nPython 2.7.6 (v2.7.6:3a1db0d2747e, Nov 10 2013, 00:42:54) \n>>> import sqlite3 as s\n>>> s.version\n'2.6.0'\n>>> s.sqlite_version\n'3.7.13'\n```\n",
"Replicated this in a test-case, working up a fix.\n"
] | 2014-06-23T13:11:32 | 2014-07-09T18:24:02 | 2014-07-09T18:24:02 | OWNER | null | ``` python
class User(BaseModel):
id = peewee.CharField(primary_key=True, max_length=20)
class Page(BaseModel):
id = peewee.PrimaryKeyField()
name = peewee.TextField(unique=True, null=True)
user = peewee.ForeignKeyField(User, null=True, related_name='pages')
```
Migration Script:
``` python
from playhouse import migrate
my_db = migrate.SqliteDatabase('database')
migrator = migrate.SqliteMigrator(my_db)
with my_db.transaction():
migrate.migrate(
migrator.rename_column('page', 'name', 'title')
)
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/380/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/380/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/379 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/379/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/379/comments | https://api.github.com/repos/coleifer/peewee/issues/379/events | https://github.com/coleifer/peewee/pull/379 | 36,181,559 | MDExOlB1bGxSZXF1ZXN0MTc0MTQzODY= | 379 | Enable automated testing with Python 3.4 | {
"login": "frewsxcv",
"id": 416575,
"node_id": "MDQ6VXNlcjQxNjU3NQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/416575?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/frewsxcv",
"html_url": "https://github.com/frewsxcv",
"followers_url": "https://api.github.com/users/frewsxcv/followers",
"following_url": "https://api.github.com/users/frewsxcv/following{/other_user}",
"gists_url": "https://api.github.com/users/frewsxcv/gists{/gist_id}",
"starred_url": "https://api.github.com/users/frewsxcv/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/frewsxcv/subscriptions",
"organizations_url": "https://api.github.com/users/frewsxcv/orgs",
"repos_url": "https://api.github.com/users/frewsxcv/repos",
"events_url": "https://api.github.com/users/frewsxcv/events{/privacy}",
"received_events_url": "https://api.github.com/users/frewsxcv/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2014-06-20T16:20:07 | 2014-06-20T19:07:11 | 2014-06-20T16:35:33 | CONTRIBUTOR | null | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/379/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/379/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/379",
"html_url": "https://github.com/coleifer/peewee/pull/379",
"diff_url": "https://github.com/coleifer/peewee/pull/379.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/379.patch",
"merged_at": "2014-06-20T16:35:33"
} |
|
https://api.github.com/repos/coleifer/peewee/issues/378 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/378/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/378/comments | https://api.github.com/repos/coleifer/peewee/issues/378/events | https://github.com/coleifer/peewee/issues/378 | 36,012,862 | MDU6SXNzdWUzNjAxMjg2Mg== | 378 | Is it possible to create a view peewee or join a created query with model? | {
"login": "jonathan-s",
"id": 2124818,
"node_id": "MDQ6VXNlcjIxMjQ4MTg=",
"avatar_url": "https://avatars.githubusercontent.com/u/2124818?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/jonathan-s",
"html_url": "https://github.com/jonathan-s",
"followers_url": "https://api.github.com/users/jonathan-s/followers",
"following_url": "https://api.github.com/users/jonathan-s/following{/other_user}",
"gists_url": "https://api.github.com/users/jonathan-s/gists{/gist_id}",
"starred_url": "https://api.github.com/users/jonathan-s/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/jonathan-s/subscriptions",
"organizations_url": "https://api.github.com/users/jonathan-s/orgs",
"repos_url": "https://api.github.com/users/jonathan-s/repos",
"events_url": "https://api.github.com/users/jonathan-s/events{/privacy}",
"received_events_url": "https://api.github.com/users/jonathan-s/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Ok, I solved it. \n\nI created a view in my database and then in my models.py I created a model for it. \n\n```\nclass UserOrder(BaseModel):\n link_to_id = PrimaryKeyField()\n avg_user = FloatField()\n\n class Meta:\n db_table = 'user_order'\n```\n\nWhere db_table is the reference to the actual view and the fields in the view are listed above. Then I could happily join the two together. \n"
] | 2014-06-18T18:18:50 | 2014-06-19T15:20:22 | 2014-06-19T15:07:31 | NONE | null | I tried doing this. But got an error.
```
daily = DailyData.select(DailyData.link_to, fn.avg(DailyData.nr_users).alias('avg_user')).group_by(DailyData.link_to)
output = ExtensionData.select(ExtensionData.name).join(daily).order_by(sql('avg_user DESC')).limit(500)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/scraper/.virtualenvs/superfish/lib/python2.6/site-packages/peewee.py", line 233, in inner
func(clone, *args, **kwargs)
File "/home/scraper/.virtualenvs/superfish/lib/python2.6/site-packages/peewee.py", line 1708, in join
if not self._query_ctx._meta.rel_exists(model_class) and on is None:
File "/home/scraper/.virtualenvs/superfish/lib/python2.6/site-packages/peewee.py", line 2849, in rel_exists
return self.rel_for_model(model) or self.reverse_rel_for_model(model)
File "/home/scraper/.virtualenvs/superfish/lib/python2.6/site-packages/peewee.py", line 2846, in reverse_rel_for_model
return model._meta.rel_for_model(self.model_class)
AttributeError: 'SelectQuery' object has no attribute '_meta'
```
DailyData.link_to is the foreign key to ExtensionData. Is there another way of doing this?
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/378/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/378/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/377 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/377/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/377/comments | https://api.github.com/repos/coleifer/peewee/issues/377/events | https://github.com/coleifer/peewee/issues/377 | 35,996,050 | MDU6SXNzdWUzNTk5NjA1MA== | 377 | pwiz.py fails for postgres when schemas have cross-dependencies | {
"login": "demongoo",
"id": 941459,
"node_id": "MDQ6VXNlcjk0MTQ1OQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/941459?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/demongoo",
"html_url": "https://github.com/demongoo",
"followers_url": "https://api.github.com/users/demongoo/followers",
"following_url": "https://api.github.com/users/demongoo/following{/other_user}",
"gists_url": "https://api.github.com/users/demongoo/gists{/gist_id}",
"starred_url": "https://api.github.com/users/demongoo/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/demongoo/subscriptions",
"organizations_url": "https://api.github.com/users/demongoo/orgs",
"repos_url": "https://api.github.com/users/demongoo/repos",
"events_url": "https://api.github.com/users/demongoo/events{/privacy}",
"received_events_url": "https://api.github.com/users/demongoo/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"pwiz certainly has limitations and it's very possible cross-schema foreign keys are one of them. I think I will close this as wontfix but feel free to submit a patch.\n"
] | 2014-06-18T15:18:27 | 2014-06-19T18:02:17 | 2014-06-19T18:02:17 | NONE | null | I have a large PostgreSQL database, with multiple schemas. Some foreign keys involve cross-schema references. Currently `pwiz` just fails with `KeyError` here and there. In my case I've just quick-fixed script to ignore some missing keys and to spit out `UNDEFINED` instead of missing information, but of course it is not a solution.
The problem is that in my case `pwiz` just failed before outputting code, and was useless. Given the size of DB I prefered to have at least some missing Foreign keys, instead of nothing. It may be fixed temporarily by some `--ignore-errors` key, for example.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/377/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/377/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/376 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/376/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/376/comments | https://api.github.com/repos/coleifer/peewee/issues/376/events | https://github.com/coleifer/peewee/issues/376 | 35,871,976 | MDU6SXNzdWUzNTg3MTk3Ng== | 376 | Created signal is not triggered. | {
"login": "soasme",
"id": 369081,
"node_id": "MDQ6VXNlcjM2OTA4MQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/369081?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/soasme",
"html_url": "https://github.com/soasme",
"followers_url": "https://api.github.com/users/soasme/followers",
"following_url": "https://api.github.com/users/soasme/following{/other_user}",
"gists_url": "https://api.github.com/users/soasme/gists{/gist_id}",
"starred_url": "https://api.github.com/users/soasme/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/soasme/subscriptions",
"organizations_url": "https://api.github.com/users/soasme/orgs",
"repos_url": "https://api.github.com/users/soasme/repos",
"events_url": "https://api.github.com/users/soasme/events{/privacy}",
"received_events_url": "https://api.github.com/users/soasme/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
":+1: \n"
] | 2014-06-17T09:29:37 | 2014-06-18T14:54:46 | 2014-06-18T14:51:16 | CONTRIBUTOR | null | Signal in playhouse/signal.py:
``` python
def save(self, *args, **kwargs):
created = not bool(self.get_id())
pre_save.send(self, created=created)
super(Model, self).save(*args, **kwargs)
post_save.send(self, created=created)
```
If I create a model via
``` python
model = Model()
model.id = uuid.uuid4()
model.save(force_insert=True)
```
then created is always `False`, which means that I can never trigger created event.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/376/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/376/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/375 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/375/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/375/comments | https://api.github.com/repos/coleifer/peewee/issues/375/events | https://github.com/coleifer/peewee/pull/375 | 35,871,686 | MDExOlB1bGxSZXF1ZXN0MTcyMjQ0NTg= | 375 | Fix `count`, refs #350: default count changed to COUNT(*) | {
"login": "demongoo",
"id": 941459,
"node_id": "MDQ6VXNlcjk0MTQ1OQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/941459?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/demongoo",
"html_url": "https://github.com/demongoo",
"followers_url": "https://api.github.com/users/demongoo/followers",
"following_url": "https://api.github.com/users/demongoo/following{/other_user}",
"gists_url": "https://api.github.com/users/demongoo/gists{/gist_id}",
"starred_url": "https://api.github.com/users/demongoo/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/demongoo/subscriptions",
"organizations_url": "https://api.github.com/users/demongoo/orgs",
"repos_url": "https://api.github.com/users/demongoo/repos",
"events_url": "https://api.github.com/users/demongoo/events{/privacy}",
"received_events_url": "https://api.github.com/users/demongoo/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Nice, I've added your changes.\n"
] | 2014-06-17T09:25:58 | 2014-06-18T14:49:44 | 2014-06-18T14:49:44 | NONE | null | Tests pass. Is there a strong reason to COUNT by primary keys rather than `COUNT(*)` ?
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/375/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/375/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/375",
"html_url": "https://github.com/coleifer/peewee/pull/375",
"diff_url": "https://github.com/coleifer/peewee/pull/375.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/375.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/374 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/374/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/374/comments | https://api.github.com/repos/coleifer/peewee/issues/374/events | https://github.com/coleifer/peewee/issues/374 | 35,735,471 | MDU6SXNzdWUzNTczNTQ3MQ== | 374 | Row not inserted into table when using CompositeKey | {
"login": "scls19fr",
"id": 109167,
"node_id": "MDQ6VXNlcjEwOTE2Nw==",
"avatar_url": "https://avatars.githubusercontent.com/u/109167?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/scls19fr",
"html_url": "https://github.com/scls19fr",
"followers_url": "https://api.github.com/users/scls19fr/followers",
"following_url": "https://api.github.com/users/scls19fr/following{/other_user}",
"gists_url": "https://api.github.com/users/scls19fr/gists{/gist_id}",
"starred_url": "https://api.github.com/users/scls19fr/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/scls19fr/subscriptions",
"organizations_url": "https://api.github.com/users/scls19fr/orgs",
"repos_url": "https://api.github.com/users/scls19fr/repos",
"events_url": "https://api.github.com/users/scls19fr/events{/privacy}",
"received_events_url": "https://api.github.com/users/scls19fr/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Try reading\nhttp://peewee.readthedocs.org/en/latest/peewee/models.html#non-integer-primary-keys\nOn Jun 14, 2014 2:56 PM, \"scls19fr\" [email protected] wrote:\n\n> Hello,\n> \n> I'm new to Peewee.\n> \n> I did this code:\n> \n> from peewee import *\n> \n> db = SqliteDatabase('json_rpc.sqlite')\n> \n> class RPC(Model):\n> terminal_id = CharField()\n> request_id = CharField()\n> request = CharField()\n> response = CharField()\n> \n> ```\n> class Meta:\n> database = db\n> primary_key = CompositeKey('terminal_id', 'request_id')\n> ```\n> \n> # connect to our database\n> \n> db.connect()\n> \n> RPC.create_table()\n> \n> terminal_id = 'test01'\n> request_id = 2\n> request = '{\"jsonrpc\": \"2.0\", \"method\": \"subtract\", \"params\": [42, 23], \"id\": '+ str(request_id) + '}'\n> response = \"\"\n> rpc = RPC(\n> terminal_id=terminal_id,\n> request_id = request_id,\n> request=request,\n> response=response\n> )\n> rpc.save()\n> \n> Unfortunatelly row is not inserted into SQLite database (without any\n> error).\n> \n> If I comment primary_key = CompositeKey('terminal_id', 'request_id')\n> row is inserted (but there is no security to ensure that there is a unique\n> couple (terminal_id, request_id)).\n> \n> So I don't know if this is really an issue or a misunderstanding from my\n> side.\n> \n> Kind regards\n> \n> —\n> Reply to this email directly or view it on GitHub\n> https://github.com/coleifer/peewee/issues/374.\n",
"Thanks for the tip\n`rpc.save(force_insert=True)` fixes my problem\n"
] | 2014-06-14T19:56:06 | 2014-06-16T02:32:59 | 2014-06-16T02:32:59 | NONE | null | Hello,
I'm new to Peewee.
I did this code:
```
from peewee import *
db = SqliteDatabase('json_rpc.sqlite')
class RPC(Model):
terminal_id = CharField()
request_id = CharField()
request = CharField()
response = CharField()
class Meta:
database = db
primary_key = CompositeKey('terminal_id', 'request_id')
# connect to our database
db.connect()
RPC.create_table()
terminal_id = 'test01'
request_id = 2
request = '{"jsonrpc": "2.0", "method": "subtract", "params": [42, 23], "id": '+ str(request_id) + '}'
response = ""
rpc = RPC(
terminal_id=terminal_id,
request_id = request_id,
request=request,
response=response
)
rpc.save()
```
Unfortunatelly row is not inserted into SQLite database (without any error).
If I comment `primary_key = CompositeKey('terminal_id', 'request_id')`
row is inserted (but there is no security to ensure that there is a unique couple (terminal_id, request_id)).
So I don't know if this is really an issue or a misunderstanding from my side.
Kind regards
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/374/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/374/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/373 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/373/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/373/comments | https://api.github.com/repos/coleifer/peewee/issues/373/events | https://github.com/coleifer/peewee/issues/373 | 35,735,018 | MDU6SXNzdWUzNTczNTAxOA== | 373 | Row not inserted into table when using CompositeKey in Meta Model | {
"login": "scls19fr",
"id": 109167,
"node_id": "MDQ6VXNlcjEwOTE2Nw==",
"avatar_url": "https://avatars.githubusercontent.com/u/109167?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/scls19fr",
"html_url": "https://github.com/scls19fr",
"followers_url": "https://api.github.com/users/scls19fr/followers",
"following_url": "https://api.github.com/users/scls19fr/following{/other_user}",
"gists_url": "https://api.github.com/users/scls19fr/gists{/gist_id}",
"starred_url": "https://api.github.com/users/scls19fr/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/scls19fr/subscriptions",
"organizations_url": "https://api.github.com/users/scls19fr/orgs",
"repos_url": "https://api.github.com/users/scls19fr/repos",
"events_url": "https://api.github.com/users/scls19fr/events{/privacy}",
"received_events_url": "https://api.github.com/users/scls19fr/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2014-06-14T19:32:22 | 2014-06-16T02:33:03 | 2014-06-16T02:33:03 | NONE | null | Hello,
I'm new to Peewee.
I did this code:
```
from peewee import *
db = SqliteDatabase('json_rpc.sqlite')
class RPC(Model):
terminal_id = CharField()
request_id = CharField()
request = CharField()
response = CharField()
class Meta:
database = db # this model uses the people database
primary_key = CompositeKey('terminal_id', 'request_id')
# connect to our database
db.connect()
RPC.create_table()
terminal_id = 'test01'
request_id = 2
request = '{"jsonrpc": "2.0", "method": "subtract", "params": [42, 23], "id": '+ str(request_id) + '}'
response = ""
rpc = RPC(
terminal_id=terminal_id,
request_id = request_id,
request=request,
response=response
)
rpc.save()
```
Unfortunatelly row is not inserted into SQLite database (without any error).
If I comment `primary_key = CompositeKey('terminal_id', 'request_id')`
row is inserted (but there is no security to ensure that there is a unique couple (terminal_id, request_id)).
So I don't know if this is really an issue or a misunderstanding from my side.
Kind regards
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/373/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/373/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/372 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/372/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/372/comments | https://api.github.com/repos/coleifer/peewee/issues/372/events | https://github.com/coleifer/peewee/issues/372 | 35,733,318 | MDU6SXNzdWUzNTczMzMxOA== | 372 | playhouse.migrate should use Database.compiler_class when possible | {
"login": "stas",
"id": 112147,
"node_id": "MDQ6VXNlcjExMjE0Nw==",
"avatar_url": "https://avatars.githubusercontent.com/u/112147?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/stas",
"html_url": "https://github.com/stas",
"followers_url": "https://api.github.com/users/stas/followers",
"following_url": "https://api.github.com/users/stas/following{/other_user}",
"gists_url": "https://api.github.com/users/stas/gists{/gist_id}",
"starred_url": "https://api.github.com/users/stas/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/stas/subscriptions",
"organizations_url": "https://api.github.com/users/stas/orgs",
"repos_url": "https://api.github.com/users/stas/repos",
"events_url": "https://api.github.com/users/stas/events{/privacy}",
"received_events_url": "https://api.github.com/users/stas/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Good catch, thanks I will look into fixing this.\n",
"The thing is that the migrator methods for adding indexes are not aware of the column types, so this doesn't really make sense. Maybe it would be better to subclass `Migrator` and allow the `add_index` operation to accept some additional arguments?\n\nFor now I am closing as wontfix.\n",
"You're right, the problem is that migrator has no idea about the column type. As a solution right now, I'm calling the `Model._meta.database.add_index` instead. Tbh, I would just make the migrator method do the same: pass the call to the existent database instance method.\n"
] | 2014-06-14T18:02:00 | 2014-07-11T08:22:17 | 2014-07-09T18:27:23 | NONE | null | There're some inconsistencies between database compiler and migrator methods.
A good example is the `add_index` method where when using Postgres, array and hstore fields won't get gist index types.
Delegating these methods to the compiler class fixes the issue.
This will also reduce the duplication.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/372/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/372/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/371 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/371/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/371/comments | https://api.github.com/repos/coleifer/peewee/issues/371/events | https://github.com/coleifer/peewee/pull/371 | 35,315,964 | MDExOlB1bGxSZXF1ZXN0MTY5MDMyNjk= | 371 | correct variable name in insert_many example | {
"login": "amedeedaboville",
"id": 826619,
"node_id": "MDQ6VXNlcjgyNjYxOQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/826619?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/amedeedaboville",
"html_url": "https://github.com/amedeedaboville",
"followers_url": "https://api.github.com/users/amedeedaboville/followers",
"following_url": "https://api.github.com/users/amedeedaboville/following{/other_user}",
"gists_url": "https://api.github.com/users/amedeedaboville/gists{/gist_id}",
"starred_url": "https://api.github.com/users/amedeedaboville/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/amedeedaboville/subscriptions",
"organizations_url": "https://api.github.com/users/amedeedaboville/orgs",
"repos_url": "https://api.github.com/users/amedeedaboville/repos",
"events_url": "https://api.github.com/users/amedeedaboville/events{/privacy}",
"received_events_url": "https://api.github.com/users/amedeedaboville/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2014-06-09T19:31:45 | 2014-06-13T13:31:25 | 2014-06-10T00:44:53 | CONTRIBUTOR | null | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/371/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/371/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/371",
"html_url": "https://github.com/coleifer/peewee/pull/371",
"diff_url": "https://github.com/coleifer/peewee/pull/371.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/371.patch",
"merged_at": "2014-06-10T00:44:53"
} |
|
https://api.github.com/repos/coleifer/peewee/issues/370 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/370/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/370/comments | https://api.github.com/repos/coleifer/peewee/issues/370/events | https://github.com/coleifer/peewee/pull/370 | 35,262,638 | MDExOlB1bGxSZXF1ZXN0MTY4NzI4MDc= | 370 | Updated Google Cloud SQL Documentation | {
"login": "jpttrssn",
"id": 194305,
"node_id": "MDQ6VXNlcjE5NDMwNQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/194305?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/jpttrssn",
"html_url": "https://github.com/jpttrssn",
"followers_url": "https://api.github.com/users/jpttrssn/followers",
"following_url": "https://api.github.com/users/jpttrssn/following{/other_user}",
"gists_url": "https://api.github.com/users/jpttrssn/gists{/gist_id}",
"starred_url": "https://api.github.com/users/jpttrssn/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/jpttrssn/subscriptions",
"organizations_url": "https://api.github.com/users/jpttrssn/orgs",
"repos_url": "https://api.github.com/users/jpttrssn/repos",
"events_url": "https://api.github.com/users/jpttrssn/events{/privacy}",
"received_events_url": "https://api.github.com/users/jpttrssn/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Nice, could you rebase your commits into a single commit?\n",
"Done.\n",
"Nice, thank you very much!\n"
] | 2014-06-09T06:16:52 | 2014-06-20T17:41:56 | 2014-06-09T19:36:13 | CONTRIBUTOR | null | I updated the Google Cloud SQL documentation section to reflect how to use peewee in both development and production.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/370/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/370/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/370",
"html_url": "https://github.com/coleifer/peewee/pull/370",
"diff_url": "https://github.com/coleifer/peewee/pull/370.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/370.patch",
"merged_at": "2014-06-09T19:36:13"
} |
https://api.github.com/repos/coleifer/peewee/issues/369 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/369/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/369/comments | https://api.github.com/repos/coleifer/peewee/issues/369/events | https://github.com/coleifer/peewee/pull/369 | 35,219,209 | MDExOlB1bGxSZXF1ZXN0MTY4NTc5MDA= | 369 | Resolved issues with using peewee on app engine. | {
"login": "jpttrssn",
"id": 194305,
"node_id": "MDQ6VXNlcjE5NDMwNQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/194305?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/jpttrssn",
"html_url": "https://github.com/jpttrssn",
"followers_url": "https://api.github.com/users/jpttrssn/followers",
"following_url": "https://api.github.com/users/jpttrssn/following{/other_user}",
"gists_url": "https://api.github.com/users/jpttrssn/gists{/gist_id}",
"starred_url": "https://api.github.com/users/jpttrssn/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/jpttrssn/subscriptions",
"organizations_url": "https://api.github.com/users/jpttrssn/orgs",
"repos_url": "https://api.github.com/users/jpttrssn/repos",
"events_url": "https://api.github.com/users/jpttrssn/events{/privacy}",
"received_events_url": "https://api.github.com/users/jpttrssn/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I think I might take a crack at this myself. I'm surprised that there's no sqlite on GAE!\n",
"Fixed in 6838d8ec54093ebefca4b436abff601e14f94795 -- thanks for the diff and bringing this to my attention! Look forward to more PRs in the future!\n"
] | 2014-06-07T21:37:06 | 2014-07-06T01:49:55 | 2014-06-08T11:33:44 | CONTRIBUTOR | null | App Engine does not support sqlite3 so in order to get peewee to work I had to add in checks for it. This was my quick and dirty solution. There's probably a more elegant way to handle this.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/369/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/369/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/369",
"html_url": "https://github.com/coleifer/peewee/pull/369",
"diff_url": "https://github.com/coleifer/peewee/pull/369.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/369.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/368 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/368/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/368/comments | https://api.github.com/repos/coleifer/peewee/issues/368/events | https://github.com/coleifer/peewee/issues/368 | 34,857,316 | MDU6SXNzdWUzNDg1NzMxNg== | 368 | Model.__getattribute__ | {
"login": "jonathan-s",
"id": 2124818,
"node_id": "MDQ6VXNlcjIxMjQ4MTg=",
"avatar_url": "https://avatars.githubusercontent.com/u/2124818?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/jonathan-s",
"html_url": "https://github.com/jonathan-s",
"followers_url": "https://api.github.com/users/jonathan-s/followers",
"following_url": "https://api.github.com/users/jonathan-s/following{/other_user}",
"gists_url": "https://api.github.com/users/jonathan-s/gists{/gist_id}",
"starred_url": "https://api.github.com/users/jonathan-s/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/jonathan-s/subscriptions",
"organizations_url": "https://api.github.com/users/jonathan-s/orgs",
"repos_url": "https://api.github.com/users/jonathan-s/repos",
"events_url": "https://api.github.com/users/jonathan-s/events{/privacy}",
"received_events_url": "https://api.github.com/users/jonathan-s/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Where is the `TypeError` originating from? Can you include the full traceback?\n",
"Actually I think I know what might be happening.\n\nTry changing your `__getattribute__()` to `getattr`, e.g.\n\n``` python\nExtensionData.select().order_by(getattr(DailyData, prop).desc()).limit(500).iterator()\n```\n",
"Thanks!\n"
] | 2014-06-03T12:10:03 | 2014-06-03T13:56:42 | 2014-06-03T13:53:06 | NONE | null | The following works as expected:
```
prop = 'nr_users'
datapoints = entry.data_entries.order_by(DailyData.date_scraped.desc()).limit(10)
data = data + [str(entry.__getattribute__(prop)) for entry in datapoints]
```
However the following does not work. I'm not sure if that is expected or not. But I expected it to work. Instead this returns `TypeError: expected 1 arguments, got 0`:
```
output = ExtensionData.select().join(DailyData).order_by(
DailyData.__getattribute__(prop).desc()).limit(500).iterator()
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/368/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/368/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/367 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/367/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/367/comments | https://api.github.com/repos/coleifer/peewee/issues/367/events | https://github.com/coleifer/peewee/issues/367 | 34,746,365 | MDU6SXNzdWUzNDc0NjM2NQ== | 367 | test failures under py3 in latest release | {
"login": "idella",
"id": 1655078,
"node_id": "MDQ6VXNlcjE2NTUwNzg=",
"avatar_url": "https://avatars.githubusercontent.com/u/1655078?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/idella",
"html_url": "https://github.com/idella",
"followers_url": "https://api.github.com/users/idella/followers",
"following_url": "https://api.github.com/users/idella/following{/other_user}",
"gists_url": "https://api.github.com/users/idella/gists{/gist_id}",
"starred_url": "https://api.github.com/users/idella/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/idella/subscriptions",
"organizations_url": "https://api.github.com/users/idella/orgs",
"repos_url": "https://api.github.com/users/idella/repos",
"events_url": "https://api.github.com/users/idella/events{/privacy}",
"received_events_url": "https://api.github.com/users/idella/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I run continuous integration with python versions 2.6, 2.7, 3.2 and 3.3 and both sqlite and postgresql backends. All appear to be passing:\n\nhttps://travis-ci.org/coleifer/peewee\n",
"On current Gentoo (unstable), I observe the same test failures and output as idella attached above when running `PEEWEE_TEST_BACKEND=sqlite python runtests.py` under Python 3.3.5, and also the same (apart from test_tuples_dicts which does not fail) under Python 3.4.0. Adding the '-a' switch, as per .travis.yml yields `ImportError: No module named 'StringIO'`.\n",
"ok with a prompt from eroen, it came to my attention that 2.2.1 is in fact an old release. How this came about is frankly an unhelpful factor here. Suffice to say we figured it. Now have a 2.2.4 passing the testsuite under all pythons\n",
"Glad you have 2.2.4 passing, sorry for the confusion this must have caused.\n"
] | 2014-06-02T05:03:56 | 2014-06-02T13:41:03 | 2014-06-02T09:57:12 | NONE | null | On the presumption peewee is intended to support py3. we have the following;
Running with system python 3.3;
``` python
======================================================================
ERROR: test_slicing_dicing (tests.QueryResultWrapperTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/mnt/gen2/TmpDir/portage/dev-python/peewee-2.2.1/work/peewee-2.2.1/tests.py", line 1461, in test_slicing_dicing
res = uq[5:]
File "/mnt/gen2/TmpDir/portage/dev-python/peewee-2.2.1/work/peewee-2.2.1/peewee.py", line 2000, in __getitem__
if index >= 0:
TypeError: unorderable types: NoneType() >= int()
======================================================================
ERROR: test_slicing_dicing (tests.QueryResultWrapperTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/mnt/gen2/TmpDir/portage/dev-python/peewee-2.2.1/work/peewee-2.2.1/peewee.py", line 2223, in execute_sql
res = cursor.execute(sql, params or ())
sqlite3.OperationalError: database table is locked
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/mnt/gen2/TmpDir/portage/dev-python/peewee-2.2.1/work/peewee-2.2.1/tests.py", line 1234, in tearDown
drop_tables(self.requires)
File "/mnt/gen2/TmpDir/portage/dev-python/peewee-2.2.1/work/peewee-2.2.1/tests.py", line 392, in drop_tables
model.drop_table(True)
File "/mnt/gen2/TmpDir/portage/dev-python/peewee-2.2.1/work/peewee-2.2.1/peewee.py", line 2873, in drop_table
cls._meta.database.drop_table(cls, fail_silently, cascade)
File "/mnt/gen2/TmpDir/portage/dev-python/peewee-2.2.1/work/peewee-2.2.1/peewee.py", line 2314, in drop_table
model_class, fail_silently, cascade))
File "/mnt/gen2/TmpDir/portage/dev-python/peewee-2.2.1/work/peewee-2.2.1/peewee.py", line 2232, in execute_sql
self.commit()
File "/mnt/gen2/TmpDir/portage/dev-python/peewee-2.2.1/work/peewee-2.2.1/peewee.py", line 2104, in __exit__
reraise(new_type, new_type(*exc_value.args), traceback)
File "/mnt/gen2/TmpDir/portage/dev-python/peewee-2.2.1/work/peewee-2.2.1/peewee.py", line 93, in reraise
raise value.with_traceback(tb)
File "/mnt/gen2/TmpDir/portage/dev-python/peewee-2.2.1/work/peewee-2.2.1/peewee.py", line 2223, in execute_sql
res = cursor.execute(sql, params or ())
peewee.OperationalError: database table is locked
======================================================================
ERROR: test_tuples_dicts (tests.QueryResultWrapperTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/mnt/gen2/TmpDir/portage/dev-python/peewee-2.2.1/work/peewee-2.2.1/peewee.py", line 2223, in execute_sql
res = cursor.execute(sql, params or ())
sqlite3.OperationalError: database table is locked
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/mnt/gen2/TmpDir/portage/dev-python/peewee-2.2.1/work/peewee-2.2.1/tests.py", line 1230, in setUp
drop_tables(self.requires)
File "/mnt/gen2/TmpDir/portage/dev-python/peewee-2.2.1/work/peewee-2.2.1/tests.py", line 392, in drop_tables
model.drop_table(True)
File "/mnt/gen2/TmpDir/portage/dev-python/peewee-2.2.1/work/peewee-2.2.1/peewee.py", line 2873, in drop_table
cls._meta.database.drop_table(cls, fail_silently, cascade)
File "/mnt/gen2/TmpDir/portage/dev-python/peewee-2.2.1/work/peewee-2.2.1/peewee.py", line 2314, in drop_table
model_class, fail_silently, cascade))
File "/mnt/gen2/TmpDir/portage/dev-python/peewee-2.2.1/work/peewee-2.2.1/peewee.py", line 2232, in execute_sql
self.commit()
File "/mnt/gen2/TmpDir/portage/dev-python/peewee-2.2.1/work/peewee-2.2.1/peewee.py", line 2104, in __exit__
reraise(new_type, new_type(*exc_value.args), traceback)
File "/mnt/gen2/TmpDir/portage/dev-python/peewee-2.2.1/work/peewee-2.2.1/peewee.py", line 93, in reraise
raise value.with_traceback(tb)
File "/mnt/gen2/TmpDir/portage/dev-python/peewee-2.2.1/work/peewee-2.2.1/peewee.py", line 2223, in execute_sql
res = cursor.execute(sql, params or ())
peewee.OperationalError: database table is locked
======================================================================
ERROR: test_failure (tests.TestSavepoints)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/mnt/gen2/TmpDir/portage/dev-python/peewee-2.2.1/work/peewee-2.2.1/tests.py", line 3863, in test_failure
ValueError, self._outer, fail_outer=True, fail_inner=True)
File "/usr/lib64/python3.3/unittest/case.py", line 570, in assertRaises
return context.handle('assertRaises', callableObj, args, kwargs)
File "/usr/lib64/python3.3/unittest/case.py", line 135, in handle
callable_obj(*args, **kwargs)
File "/mnt/gen2/TmpDir/portage/dev-python/peewee-2.2.1/work/peewee-2.2.1/tests.py", line 3822, in _outer
with test_db.savepoint():
File "/mnt/gen2/TmpDir/portage/dev-python/peewee-2.2.1/work/peewee-2.2.1/peewee.py", line 2351, in savepoint
return savepoint_sqlite(self, sid)
File "/mnt/gen2/TmpDir/portage/dev-python/peewee-2.2.1/work/peewee-2.2.1/peewee.py", line 2519, in __init__
self.sid = sid or 's' + uuid.uuid4().get_hex()
AttributeError: 'UUID' object has no attribute 'get_hex'
======================================================================
ERROR: test_inner_failure (tests.TestSavepoints)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/mnt/gen2/TmpDir/portage/dev-python/peewee-2.2.1/work/peewee-2.2.1/tests.py", line 3849, in test_inner_failure
self._outer(fail_inner=True)
File "/mnt/gen2/TmpDir/portage/dev-python/peewee-2.2.1/work/peewee-2.2.1/tests.py", line 3822, in _outer
with test_db.savepoint():
File "/mnt/gen2/TmpDir/portage/dev-python/peewee-2.2.1/work/peewee-2.2.1/peewee.py", line 2351, in savepoint
return savepoint_sqlite(self, sid)
File "/mnt/gen2/TmpDir/portage/dev-python/peewee-2.2.1/work/peewee-2.2.1/peewee.py", line 2519, in __init__
self.sid = sid or 's' + uuid.uuid4().get_hex()
AttributeError: 'UUID' object has no attribute 'get_hex'
======================================================================
ERROR: test_outer_failure (tests.TestSavepoints)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/mnt/gen2/TmpDir/portage/dev-python/peewee-2.2.1/work/peewee-2.2.1/tests.py", line 3857, in test_outer_failure
self.assertRaises(ValueError, self._outer, fail_outer=True)
File "/usr/lib64/python3.3/unittest/case.py", line 570, in assertRaises
return context.handle('assertRaises', callableObj, args, kwargs)
File "/usr/lib64/python3.3/unittest/case.py", line 135, in handle
callable_obj(*args, **kwargs)
File "/mnt/gen2/TmpDir/portage/dev-python/peewee-2.2.1/work/peewee-2.2.1/tests.py", line 3822, in _outer
with test_db.savepoint():
File "/mnt/gen2/TmpDir/portage/dev-python/peewee-2.2.1/work/peewee-2.2.1/peewee.py", line 2351, in savepoint
return savepoint_sqlite(self, sid)
File "/mnt/gen2/TmpDir/portage/dev-python/peewee-2.2.1/work/peewee-2.2.1/peewee.py", line 2519, in __init__
self.sid = sid or 's' + uuid.uuid4().get_hex()
AttributeError: 'UUID' object has no attribute 'get_hex'
======================================================================
ERROR: test_success (tests.TestSavepoints)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/mnt/gen2/TmpDir/portage/dev-python/peewee-2.2.1/work/peewee-2.2.1/tests.py", line 3843, in test_success
self._outer()
File "/mnt/gen2/TmpDir/portage/dev-python/peewee-2.2.1/work/peewee-2.2.1/tests.py", line 3822, in _outer
with test_db.savepoint():
File "/mnt/gen2/TmpDir/portage/dev-python/peewee-2.2.1/work/peewee-2.2.1/peewee.py", line 2351, in savepoint
return savepoint_sqlite(self, sid)
File "/mnt/gen2/TmpDir/portage/dev-python/peewee-2.2.1/work/peewee-2.2.1/peewee.py", line 2519, in __init__
self.sid = sid or 's' + uuid.uuid4().get_hex()
AttributeError: 'UUID' object has no attribute 'get_hex'
----------------------------------------------------------------------
Ran 168 tests in 186.719s
FAILED (errors=7)
TESTING USING PYTHON 3.3.5 (default, Apr 23 2014, 10:45:31)
[GCC 4.8.2]
SQLITE VERSION: 2.6.0
Skipping "for update" tests
Skipping "sequence" tests
Skipping "foreign key" tests
Skipping "drop/cascade" tests
Skipping "window function" tests
Adding tests for "tests"
```
Under py3.4, it yielded
FAILED (errors=6). Not much in it.
Do you require anything further?
On the presumption peewee is not intended to support py3, please cancel the above.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/367/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/367/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/366 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/366/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/366/comments | https://api.github.com/repos/coleifer/peewee/issues/366/events | https://github.com/coleifer/peewee/issues/366 | 34,727,608 | MDU6SXNzdWUzNDcyNzYwOA== | 366 | How to get foreign key column itself? | {
"login": "ayang",
"id": 556676,
"node_id": "MDQ6VXNlcjU1NjY3Ng==",
"avatar_url": "https://avatars.githubusercontent.com/u/556676?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/ayang",
"html_url": "https://github.com/ayang",
"followers_url": "https://api.github.com/users/ayang/followers",
"following_url": "https://api.github.com/users/ayang/following{/other_user}",
"gists_url": "https://api.github.com/users/ayang/gists{/gist_id}",
"starred_url": "https://api.github.com/users/ayang/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/ayang/subscriptions",
"organizations_url": "https://api.github.com/users/ayang/orgs",
"repos_url": "https://api.github.com/users/ayang/repos",
"events_url": "https://api.github.com/users/ayang/events{/privacy}",
"received_events_url": "https://api.github.com/users/ayang/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"You can use `Pet._data['owner']`.\n",
"Thank you\n"
] | 2014-06-01T12:35:32 | 2014-06-01T14:28:42 | 2014-06-01T13:51:33 | NONE | null | Example for this:
class Person(Model):
name = CharField()
birthday = DateField()
class Pet(Model):
owner = ForeignKeyField(Person, related_name='pets')
name = CharField()
I want to get pet.owner_id, but I can only use pet.owner.id, which will execute a sql query extraly.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/366/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/366/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/365 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/365/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/365/comments | https://api.github.com/repos/coleifer/peewee/issues/365/events | https://github.com/coleifer/peewee/issues/365 | 34,718,411 | MDU6SXNzdWUzNDcxODQxMQ== | 365 | How to do deferred engine selection? | {
"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 | [
"I am now monkey-patching my models (see issue mentioned above). Would be great if we could come up with a less 'hacky' solutions, though.\n",
"Check out these docs: http://peewee.readthedocs.org/en/latest/peewee/cookbook.html#dynamically-defining-a-database\n",
"Ah. D'oh. Thank you. Works like a charm.\n",
"Link http://peewee.readthedocs.org/en/latest/peewee/cookbook.html#dynamically-defining-a-database doesn't exist anymore. Can you help?",
"* http://docs.peewee-orm.com/en/latest/peewee/database.html#run-time-database-configuration\r\n* http://docs.peewee-orm.com/en/latest/peewee/database.html#dynamically-defining-a-database",
"Thank you,\n\nworks very well!\nRegards / Liebe Grüße,\n\nRalph Mueller\n\nAnnastrasse 44, 64673 Zwingenberg\nMobile: +49 177 449 0460\nOffice: +49 6251 789545\nemail: [email protected] <mailto:[email protected]>\nhttps://www.ralph-mueller.net <https://www.ralph-mueller.net/>\n\n\n\n> Am 15.03.2018 um 14:51 schrieb Charles Leifer <[email protected]>:\n> \n> http://docs.peewee-orm.com/en/latest/peewee/database.html#run-time-database-configuration <http://docs.peewee-orm.com/en/latest/peewee/database.html#run-time-database-configuration>\n> http://docs.peewee-orm.com/en/latest/peewee/database.html#dynamically-defining-a-database <http://docs.peewee-orm.com/en/latest/peewee/database.html#dynamically-defining-a-database>\n> —\n> You are receiving this because you commented.\n> Reply to this email directly, view it on GitHub <https://github.com/coleifer/peewee/issues/365#issuecomment-373382277>, or mute the thread <https://github.com/notifications/unsubscribe-auth/ADTj_Fu6e-McLX3HmyYyH7Pm9bsnFbHRks5tenHggaJpZM4CABL7>.\n> \n\n"
] | 2014-06-01T00:13:55 | 2018-03-15T16:07:48 | 2014-06-01T13:49:33 | NONE | null | How can one do deferred engine selection?
For example, if I use a class similarly as `Database` of `flask-peewee`, I would like to select the engine/configure peewee after creation of the instance (ie, the commong `init_app()` approach). Unfortunately, all my models need to know their baseclass to reference the database. Is there any way around this? Can I change the database in the baseclass?
This is related to https://github.com/coleifer/flask-peewee/issues/69
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/365/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/365/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/364 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/364/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/364/comments | https://api.github.com/repos/coleifer/peewee/issues/364/events | https://github.com/coleifer/peewee/issues/364 | 34,495,696 | MDU6SXNzdWUzNDQ5NTY5Ng== | 364 | DISTINCT ON | {
"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 did a bit of digging and it looks like you can write:\n\n```\nSELECT DISTINCT(col1, col2), col1, ... FROM\n```\n\nSo I'm going to close this since you can emulate this:\n\n``` python\nMyModel.select(fn.DISTINCT(MyModel.col1, MyModel.col2), MyModel.col1)...\n```\n",
"Actually it turns out the semantics are a bit different... reopening.\n",
"Fixed by 19d2c2e738f874c\n"
] | 2014-05-28T18:54:13 | 2014-05-29T03:32:17 | 2014-05-29T03:32:07 | OWNER | null | First-class support for this feature.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/364/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/364/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/363 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/363/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/363/comments | https://api.github.com/repos/coleifer/peewee/issues/363/events | https://github.com/coleifer/peewee/pull/363 | 34,462,355 | MDExOlB1bGxSZXF1ZXN0MTY0MjQ2MDQ= | 363 | Created a new parameter 'reconnect' to indicate if MySQLAdapter can try ... | {
"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 am going to pass on this, but if you would like you can always subclass `MySQLDatabase` and implement this logic yourself. Catching `Exception` is far too broad and I believe this will lead to unpredictable behavior.\n",
"It's true. I created a MySQLWithReconnectDatabase and narrowed the exception to _mysql_exceptions.OperationalError error code 2006.\n\nThanks, Charles.\n",
"I actually like the idea of having it auto-reconnect on that error, I've\nhad the same issue before and fixed it by manually making a new connection\nevery time.\n\nOn Wed, May 28, 2014 at 10:56 PM, André Martins [email protected]:\n\n> It's true. I created a MySQLWithReconnectDatabase and narrowed the\n> exception to _mysql_exceptions.OperationalError error code 2006.\n> \n> Thanks, Charles.\n> \n> —\n> Reply to this email directly or view it on GitHubhttps://github.com/coleifer/peewee/pull/363#issuecomment-44438590\n> .\n",
"Perhaps this database subclass could go in `playhouse.mysql_ext`?\n",
"I think there is no need for auto-reconnect feature. \n\nThe connection must be explicitly handled on every request by the developer of the app, not by peewee. That includes opening/closing it when needed.\n",
"> The connection must be explicitly handled on every request by the developer of the app, not by peewee. That includes opening/closing it when needed.\n\n**Yes.**\n",
"I agree, but there is not a single point in code to handle this. Instead, every use of peewee can throw this error. How could separate responsabilities and use peewee with a datapool, for example?\n",
"In case you're interested, I've got a mixin for retrying failed queries in 017e4e4952f0b429dd21f0e90465a0f644cf6015 . Docs:\n\nhttp://docs.peewee-orm.com/en/latest/peewee/database.html#automatic-reconnect\n"
] | 2014-05-28T12:42:52 | 2015-09-30T03:40:31 | 2014-05-28T15:22:24 | NONE | null | Created a new parameter 'reconnect' to indicate if MySQLAdapter can try reconnect to server.
In long time connections, timeout makes connection to drop.
I have an app that faces too many "MySQL server has gone away" errors. So, this can try reconnect to the server in case of timeout.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/363/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/363/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/363",
"html_url": "https://github.com/coleifer/peewee/pull/363",
"diff_url": "https://github.com/coleifer/peewee/pull/363.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/363.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/362 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/362/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/362/comments | https://api.github.com/repos/coleifer/peewee/issues/362/events | https://github.com/coleifer/peewee/issues/362 | 34,407,470 | MDU6SXNzdWUzNDQwNzQ3MA== | 362 | Having to declare database path as static global is harmful | {
"login": "mchaput",
"id": 362643,
"node_id": "MDQ6VXNlcjM2MjY0Mw==",
"avatar_url": "https://avatars.githubusercontent.com/u/362643?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/mchaput",
"html_url": "https://github.com/mchaput",
"followers_url": "https://api.github.com/users/mchaput/followers",
"following_url": "https://api.github.com/users/mchaput/following{/other_user}",
"gists_url": "https://api.github.com/users/mchaput/gists{/gist_id}",
"starred_url": "https://api.github.com/users/mchaput/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/mchaput/subscriptions",
"organizations_url": "https://api.github.com/users/mchaput/orgs",
"repos_url": "https://api.github.com/users/mchaput/repos",
"events_url": "https://api.github.com/users/mchaput/events{/privacy}",
"received_events_url": "https://api.github.com/users/mchaput/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Docs:\n- http://peewee.readthedocs.org/en/latest/peewee/cookbook.html#deferring-initialization\n- http://peewee.readthedocs.org/en/latest/peewee/cookbook.html#dynamically-defining-a-database\n\n> If the only way to use it is with globals, I don't think I can use peewee at all and I'll have to try something else.\n\nTo be honest, I don't want users with an attitude like yours.\n"
] | 2014-05-27T20:01:13 | 2014-05-27T20:12:16 | 2014-05-27T20:12:16 | NONE | null | It's a real problem for me that I have to hardcode the path to the database as a global. This basically makes it impossible to use peewee in a library where I expect to have the database path passed to me.
I can work around hardcoding the value by gymnastics stuffing a value into a global location before I import peewee, but it's still global so it's impossible to create two separate database instances using peewee (e.g. in a library or a blueprint).
I expected it to be possible to use peewee based on the database instance, e.g. something like:
``` python
class Page(Model):
title = CharField()
content = TextField()
def get_db(path):
db = SqliteDatabase(path)
db.create_table(Page)
return db
def add_page(db, title, content):
p = db.create(Page, title=title, content=content)
p.save()
```
Is it possible I missed a way to use peewee similar to this? If the only way to use it is with globals, I don't think I can use peewee at all and I'll have to try something else.
Thanks.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/362/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/362/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/361 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/361/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/361/comments | https://api.github.com/repos/coleifer/peewee/issues/361/events | https://github.com/coleifer/peewee/issues/361 | 34,252,927 | MDU6SXNzdWUzNDI1MjkyNw== | 361 | test failures in -0.2.1; test_choices test_null_form_saving | {
"login": "idella",
"id": 1655078,
"node_id": "MDQ6VXNlcjE2NTUwNzg=",
"avatar_url": "https://avatars.githubusercontent.com/u/1655078?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/idella",
"html_url": "https://github.com/idella",
"followers_url": "https://api.github.com/users/idella/followers",
"following_url": "https://api.github.com/users/idella/following{/other_user}",
"gists_url": "https://api.github.com/users/idella/gists{/gist_id}",
"starred_url": "https://api.github.com/users/idella/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/idella/subscriptions",
"organizations_url": "https://api.github.com/users/idella/orgs",
"repos_url": "https://api.github.com/users/idella/repos",
"events_url": "https://api.github.com/users/idella/events{/privacy}",
"received_events_url": "https://api.github.com/users/idella/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"The latest version, 0.2.3, is passing for me.\n",
"sorry, still get 1 fail; Updated to peewee>=2.0.0, also wtforms.\n$ python -V\nPython 2.7.6\n\n``` python\nwtf-peewee-0.2.3 $ PYTHONPATH=. python ./runtests.py \ntest_blog_form (wtfpeewee.tests.WTFPeeweeTestCase) ... ok\ntest_blog_form_saving (wtfpeewee.tests.WTFPeeweeTestCase) ... ok\ntest_blog_form_with_obj (wtfpeewee.tests.WTFPeeweeTestCase) ... ok\ntest_choices (wtfpeewee.tests.WTFPeeweeTestCase) ... ok\ntest_defaults (wtfpeewee.tests.WTFPeeweeTestCase) ... ok\ntest_entry_form (wtfpeewee.tests.WTFPeeweeTestCase) ... ok\ntest_entry_form_saving (wtfpeewee.tests.WTFPeeweeTestCase) ... ok\ntest_entry_form_with_obj (wtfpeewee.tests.WTFPeeweeTestCase) ... ok\ntest_form_multiple (wtfpeewee.tests.WTFPeeweeTestCase) ... ok\ntest_form_with_only_exclude (wtfpeewee.tests.WTFPeeweeTestCase) ... ok\ntest_hidden_field (wtfpeewee.tests.WTFPeeweeTestCase) ... ok\ntest_hidden_field_none (wtfpeewee.tests.WTFPeeweeTestCase) ... ok\ntest_non_int_pk (wtfpeewee.tests.WTFPeeweeTestCase) ... ok\ntest_null_form_saving (wtfpeewee.tests.WTFPeeweeTestCase) ... FAIL\n\n======================================================================\nFAIL: test_null_form_saving (wtfpeewee.tests.WTFPeeweeTestCase)\n----------------------------------------------------------------------\nTraceback (most recent call last):\n File \"/mnt/gen2/TmpDir/portage/dev-python/wtf-peewee-0.2.3/work/wtf-peewee-0.2.3/wtfpeewee/tests.py\", line 348, in test_null_form_saving\n self.assertEqual(nfm.b, True)\nAssertionError: False != True\n\n----------------------------------------------------------------------\nRan 14 tests in 0.097s\n\nFAILED (failures=1)\n```\n"
] | 2014-05-25T03:11:34 | 2014-07-07T02:41:13 | 2014-05-25T09:33:44 | NONE | null | tested under only py2.7.
``` python
======================================================
FAIL: test_choices (wtfpeewee.tests.WTFPeeweeTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/mnt/gen2/TmpDir/portage/dev-python/wtf-peewee-0.2.1/work/wtf-peewee-0.2.1/wtfpeewee/tests.py", line 162, in test_choices
self.assertFalse(form.validate())
AssertionError: True is not false
=====================================================
FAIL: test_null_form_saving (wtfpeewee.tests.WTFPeeweeTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/mnt/gen2/TmpDir/portage/dev-python/wtf-peewee-0.2.1/work/wtf-peewee-0.2.1/wtfpeewee/tests.py", line 330, in test_null_form_saving
self.assertEqual(nfm.b, True)
AssertionError: False != True
----------------------------------------------------------------------
Ran 13 tests in 0.058s
FAILED (failures=2)
```
Do you replicate? Do you require anything further.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/361/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/361/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/360 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/360/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/360/comments | https://api.github.com/repos/coleifer/peewee/issues/360/events | https://github.com/coleifer/peewee/issues/360 | 34,173,362 | MDU6SXNzdWUzNDE3MzM2Mg== | 360 | Compiler interpolation | {
"login": "oz123",
"id": 1083045,
"node_id": "MDQ6VXNlcjEwODMwNDU=",
"avatar_url": "https://avatars.githubusercontent.com/u/1083045?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/oz123",
"html_url": "https://github.com/oz123",
"followers_url": "https://api.github.com/users/oz123/followers",
"following_url": "https://api.github.com/users/oz123/following{/other_user}",
"gists_url": "https://api.github.com/users/oz123/gists{/gist_id}",
"starred_url": "https://api.github.com/users/oz123/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/oz123/subscriptions",
"organizations_url": "https://api.github.com/users/oz123/orgs",
"repos_url": "https://api.github.com/users/oz123/repos",
"events_url": "https://api.github.com/users/oz123/events{/privacy}",
"received_events_url": "https://api.github.com/users/oz123/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"The `Database` class has an `interpolation` attribute which you could set:\n\n``` python\nclass OracleDatabase(Database):\n interpolation = '%s'\n```\n\nUnfortunately there is no support for automatically numbering parameters. Will `%s` work?\n"
] | 2014-05-23T13:12:56 | 2014-05-23T17:02:47 | 2014-05-23T17:02:47 | NONE | null | Hi,
I am trying to use peewee with cx_Oracle. So far with limited success. When I issue
`inst.save()` it compiles an expression with `?`. e.g I have a model :
```
class TestDBOz(pw.BaseModel):
sessionid = pw.IntegerField()
action = pw.Charfield()
sid=TestDbOz(sessionid=123, action='Test')
sid.save()
```
The above compiles to:
```
'INSERT INTO "testdboz" ("sessionid", "action") VALUES (?, ?)', [123, Test])'
```
Which sadly, is not accepted by oracle. I was wondering if there is a quick way to replace interpolation with a function that yields a numeric interpolation:
```
'INSERT INTO "testdboz" ("sessionid", "action") VALUES (:1, :2)', [123, Test])'
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/360/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/360/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/359 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/359/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/359/comments | https://api.github.com/repos/coleifer/peewee/issues/359/events | https://github.com/coleifer/peewee/issues/359 | 33,768,414 | MDU6SXNzdWUzMzc2ODQxNA== | 359 | peewee.IntegrityErro no fallback to update | {
"login": "DarkRedman",
"id": 367844,
"node_id": "MDQ6VXNlcjM2Nzg0NA==",
"avatar_url": "https://avatars.githubusercontent.com/u/367844?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/DarkRedman",
"html_url": "https://github.com/DarkRedman",
"followers_url": "https://api.github.com/users/DarkRedman/followers",
"following_url": "https://api.github.com/users/DarkRedman/following{/other_user}",
"gists_url": "https://api.github.com/users/DarkRedman/gists{/gist_id}",
"starred_url": "https://api.github.com/users/DarkRedman/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/DarkRedman/subscriptions",
"organizations_url": "https://api.github.com/users/DarkRedman/orgs",
"repos_url": "https://api.github.com/users/DarkRedman/repos",
"events_url": "https://api.github.com/users/DarkRedman/events{/privacy}",
"received_events_url": "https://api.github.com/users/DarkRedman/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"> could it be updated to work with unique constraint too?\n\nThat would be a couple line function to write, so I think I will leave it out of peewee for now.\n"
] | 2014-05-19T03:09:43 | 2014-05-19T14:53:30 | 2014-05-19T14:53:30 | NONE | null | When I read this section : http://peewee.readthedocs.org/en/latest/peewee/api.html?highlight=save#Model.save
I see the force_insert only work for the primary key, could it be updated to work with unique constraint too ?
For example if I create a sql object with a varchar field with unique constraint (and the has a duplicate) it should fallback to update to get the existing object and update it.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/359/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/359/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/358 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/358/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/358/comments | https://api.github.com/repos/coleifer/peewee/issues/358/events | https://github.com/coleifer/peewee/issues/358 | 33,707,702 | MDU6SXNzdWUzMzcwNzcwMg== | 358 | Create a test_database | {
"login": "jonathan-s",
"id": 2124818,
"node_id": "MDQ6VXNlcjIxMjQ4MTg=",
"avatar_url": "https://avatars.githubusercontent.com/u/2124818?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/jonathan-s",
"html_url": "https://github.com/jonathan-s",
"followers_url": "https://api.github.com/users/jonathan-s/followers",
"following_url": "https://api.github.com/users/jonathan-s/following{/other_user}",
"gists_url": "https://api.github.com/users/jonathan-s/gists{/gist_id}",
"starred_url": "https://api.github.com/users/jonathan-s/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/jonathan-s/subscriptions",
"organizations_url": "https://api.github.com/users/jonathan-s/orgs",
"repos_url": "https://api.github.com/users/jonathan-s/repos",
"events_url": "https://api.github.com/users/jonathan-s/events{/privacy}",
"received_events_url": "https://api.github.com/users/jonathan-s/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"You have many options, actually. You can:\n1. Set `ModelClass._meta.database` by hand, changing it to a test database.\n2. Use a `Proxy` for your `Database` and initialize it with a different database when testing [how-to](http://peewee.readthedocs.org/en/latest/peewee/cookbook.html#dynamically-defining-a-database).\n3. Use an uninitialized `Database` and initialize it with a different db name [how-to](http://peewee.readthedocs.org/en/latest/peewee/cookbook.html#deferring-initialization).\n4. Use `test_utils.test_database` context manager. [how-to](http://peewee.readthedocs.org/en/latest/peewee/playhouse.html#test_database)\n",
"You can also create and drop tables.\n\n``` python\nfrom peewee import create_model_tables\nfrom peewee import drop_model_tables\n\nMODELS = [ModelA, ModelB, ...]\n\n...\ndef setUp(self):\n create_model_tables(MODELS)\n\ndef tearDown(self):\n drop_model_tables(MODELS)\n```\n",
"Thanks a lot! I'm still learning obviously. :)\n",
"> When you create a model, the database is tightly coupled with the model itself.\n\nI understand, you just sounded like you were speaking from a point of authority.\n"
] | 2014-05-16T20:41:17 | 2014-05-16T21:49:49 | 2014-05-16T21:43:03 | NONE | null | When you create a model, the database is tightly coupled with the model itself. When testing a model it doesn't seem to be possible to create a test_database which you then destroy at the end of the test.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/358/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/358/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/357 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/357/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/357/comments | https://api.github.com/repos/coleifer/peewee/issues/357/events | https://github.com/coleifer/peewee/issues/357 | 33,677,954 | MDU6SXNzdWUzMzY3Nzk1NA== | 357 | Override 'AS' in 'FROM table AS t1' | {
"login": "devsli",
"id": 3928644,
"node_id": "MDQ6VXNlcjM5Mjg2NDQ=",
"avatar_url": "https://avatars.githubusercontent.com/u/3928644?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/devsli",
"html_url": "https://github.com/devsli",
"followers_url": "https://api.github.com/users/devsli/followers",
"following_url": "https://api.github.com/users/devsli/following{/other_user}",
"gists_url": "https://api.github.com/users/devsli/gists{/gist_id}",
"starred_url": "https://api.github.com/users/devsli/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/devsli/subscriptions",
"organizations_url": "https://api.github.com/users/devsli/orgs",
"repos_url": "https://api.github.com/users/devsli/repos",
"events_url": "https://api.github.com/users/devsli/events{/privacy}",
"received_events_url": "https://api.github.com/users/devsli/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Interesting, I think this should be fixable but will require a quick code change.\n\n``` python\n def parse_node(self, node, alias_map=None, conv=None):\n sql, params, unknown = self._parse(node, alias_map, conv)\n if unknown and conv and params:\n params = [conv.db_value(i) for i in params]\n\n if isinstance(node, Node):\n if node._negated:\n sql = 'NOT %s' % sql\n if node._alias:\n sql = ' '.join((sql, 'AS', node._alias))\n if node._ordering:\n sql = ' '.join((sql, node._ordering))\n return sql, params\n```\n\nAlternatively, you could subclass `QueryCompiler` and specify it in your subclass of `Database` that uses firebird's driver. Can you share your firebird db class, btw? I'd be interested in integrating it into the `playhouse` module.\n",
"Thank you for response! By the way, [my class](https://github.com/devsli/peewee-fdb/blob/master/peewee_fdb.py) is untidy now (I'm just learning Python). If you are interested, I'll let you know when it will become better.\n"
] | 2014-05-16T14:13:45 | 2014-05-17T18:33:25 | 2014-05-17T18:30:02 | NONE | null | Seems like 'AS' is hardcoded [here](https://github.com/coleifer/peewee/blob/master/peewee.py#L1179). Is it possible to override it in database subclass?
Firebird [doesn't use](http://www.firebirdsql.org/refdocs/langrefupd21-select.html) 'AS' for aliases.
EDIT: worksforme in firebird2.5 test case, need clarification
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/357/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/357/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/356 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/356/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/356/comments | https://api.github.com/repos/coleifer/peewee/issues/356/events | https://github.com/coleifer/peewee/issues/356 | 33,596,116 | MDU6SXNzdWUzMzU5NjExNg== | 356 | Using PostgreSQL, Model.create() leaves connection idle in transaction | {
"login": "gmcnutt",
"id": 1097321,
"node_id": "MDQ6VXNlcjEwOTczMjE=",
"avatar_url": "https://avatars.githubusercontent.com/u/1097321?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/gmcnutt",
"html_url": "https://github.com/gmcnutt",
"followers_url": "https://api.github.com/users/gmcnutt/followers",
"following_url": "https://api.github.com/users/gmcnutt/following{/other_user}",
"gists_url": "https://api.github.com/users/gmcnutt/gists{/gist_id}",
"starred_url": "https://api.github.com/users/gmcnutt/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/gmcnutt/subscriptions",
"organizations_url": "https://api.github.com/users/gmcnutt/orgs",
"repos_url": "https://api.github.com/users/gmcnutt/repos",
"events_url": "https://api.github.com/users/gmcnutt/events{/privacy}",
"received_events_url": "https://api.github.com/users/gmcnutt/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Duplicate of #353. The latest pypi release (2.2.4) has the fix.\n",
"Confirmed, thanks.\n"
] | 2014-05-15T15:23:47 | 2014-05-15T16:25:09 | 2014-05-15T15:27:28 | NONE | null | peewee==2.1.7
psycopg2==2.5.1
psql (9.3.4)
Python 3.4.0 (default, Apr 28 2014, 13:52:15)
The following code snippet will reproduce it:
``` python
from peewee import *
db = PostgresqlDatabase('dbname', user='user', password='password',
host='localhost')
db.connect()
class Test(Model):
class Meta:
database = db
pk = PrimaryKeyField()
val = IntegerField()
```
Test.create_table(fail_silently=True)
Test.create(val=1)
The postgresql log shows this:
2014-05-15 09:14:50 MDT LOG: statement: COMMIT
2014-05-15 09:14:54 MDT LOG: statement: BEGIN
2014-05-15 09:14:54 MDT LOG: statement: INSERT INTO "test" ("val") VALUES (1)
2014-05-15 09:14:54 MDT LOG: statement: COMMIT
2014-05-15 09:14:54 MDT LOG: statement: BEGIN
2014-05-15 09:14:54 MDT LOG: statement: SELECT CURRVAL('"test_pk_seq"')
The problem is there is no COMMIT following that last SELECT, leaving the transaction open. On PostgreSQL this can cause problems _even in other databases on the same server_. See http://www.postgresql.org/message-id/[email protected]
I'll submit a pull request with a patch to fix.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/356/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/356/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/355 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/355/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/355/comments | https://api.github.com/repos/coleifer/peewee/issues/355/events | https://github.com/coleifer/peewee/issues/355 | 33,578,449 | MDU6SXNzdWUzMzU3ODQ0OQ== | 355 | IntegrityError | {
"login": "tfeldmann",
"id": 385566,
"node_id": "MDQ6VXNlcjM4NTU2Ng==",
"avatar_url": "https://avatars.githubusercontent.com/u/385566?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/tfeldmann",
"html_url": "https://github.com/tfeldmann",
"followers_url": "https://api.github.com/users/tfeldmann/followers",
"following_url": "https://api.github.com/users/tfeldmann/following{/other_user}",
"gists_url": "https://api.github.com/users/tfeldmann/gists{/gist_id}",
"starred_url": "https://api.github.com/users/tfeldmann/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/tfeldmann/subscriptions",
"organizations_url": "https://api.github.com/users/tfeldmann/orgs",
"repos_url": "https://api.github.com/users/tfeldmann/repos",
"events_url": "https://api.github.com/users/tfeldmann/events{/privacy}",
"received_events_url": "https://api.github.com/users/tfeldmann/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"The issue is that the samples are instantiated before the `Group` has an ID. Peewee looks at the group passed in (`group=self`) and attempts to read an ID off it. Since it has no ID at the time of assignment, you get the error you're seeing. Put the call to `g.save()` before `g.samples()[0].name` and you'll be set.\n",
"Thank you for your answer.\nIs it possible to make the samples reread the group id?\nI want to assign properties to the samples before saving the group itself.\n(I think I could work around that by using a transaction, but unfortunately the corresponding code is quite distributed.)\n",
"It's just python so you can do whatever you want!\n\n``` python\n def samples(self):\n \"\"\"Samples are generated the first time they are requested\"\"\"\n if self._samples is None:\n self._samples = [Sample() for _ in range(10)]\n for sample in self._samples:\n sample.group = self\n return self._samples\n```\n",
" Thanks! :+1:\nDidn't think of that.\n"
] | 2014-05-15T11:54:47 | 2014-05-15T14:00:28 | 2014-05-15T13:44:59 | NONE | null | Example code:
``` python
from peewee import *
database = SqliteDatabase(':memory:', threadlocals=True)
class BaseModel(Model):
class Meta:
database = database
class Group(BaseModel):
name = IntegerField()
_samples = None
def samples(self):
"""Samples are generated the first time they are requested"""
if self._samples is None:
self._samples = [Sample(group=self) for _ in range(10)]
return self._samples
def __repr__(self):
return '<Group(name={})>'.format(self.name)
class Sample(BaseModel):
name = CharField(null=True)
group = ForeignKeyField(Group)
def __repr__(self):
return '<Sample(name="{}", group={})>'.format(self.name, self.group)
Group.create_table()
Sample.create_table()
# This works as expected
# ----------------------
g = Group(name=1)
g.save()
g.samples()[0].name = 'Something'
for sample in g.samples():
sample.save()
# This doesn't work although the group should have an ID when saved?
# ------------------------------------------------------------------
g = Group(name=2)
g.samples()[0].name = 'Something else'
g.save()
for sample in g.samples():
sample.save()
```
Maybe I'm doing that wrong, but shouldn't the group have an ID as soon as it is saved?
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/355/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/355/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/354 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/354/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/354/comments | https://api.github.com/repos/coleifer/peewee/issues/354/events | https://github.com/coleifer/peewee/issues/354 | 33,532,378 | MDU6SXNzdWUzMzUzMjM3OA== | 354 | Race condition in example | {
"login": "kmarekspartz",
"id": 969868,
"node_id": "MDQ6VXNlcjk2OTg2OA==",
"avatar_url": "https://avatars.githubusercontent.com/u/969868?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/kmarekspartz",
"html_url": "https://github.com/kmarekspartz",
"followers_url": "https://api.github.com/users/kmarekspartz/followers",
"following_url": "https://api.github.com/users/kmarekspartz/following{/other_user}",
"gists_url": "https://api.github.com/users/kmarekspartz/gists{/gist_id}",
"starred_url": "https://api.github.com/users/kmarekspartz/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/kmarekspartz/subscriptions",
"organizations_url": "https://api.github.com/users/kmarekspartz/orgs",
"repos_url": "https://api.github.com/users/kmarekspartz/repos",
"events_url": "https://api.github.com/users/kmarekspartz/events{/privacy}",
"received_events_url": "https://api.github.com/users/kmarekspartz/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"That's too bad you found a \"code smell\".\n\nThe example app is meant to be very simple and approachable, especially for someone new to peewee. The fact that it doesn't handle concurrent requests to create a new account was acceptable to me when I wrote it, but I guess that is a code smell.\n\nSince you point it out, I have changed the code smell and also updated due to some changes in flask's session serialization: 5fa6d43f0a806f6b965f8ae3bacaf3e42b2335de .\n",
"Thanks! I've been bitten in the past by this exact bug with other libraries because I hadn't seen examples done \"correctly\". Now I know how to account for this.\n"
] | 2014-05-14T20:57:41 | 2014-05-14T23:03:50 | 2014-05-14T22:42:31 | NONE | null | I was trying out peewee and reading through the documentation when I came across a code smell.
The [documentation](http://peewee.readthedocs.org/en/latest/peewee/example.html?#creating-new-objects) gives an example as follows:
``` Python
try:
user = User.get(User.username == request.form['username'])
...
except User.DoesNotExist:
user = User.create( ... )
...
```
This isn't how I [normally](http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html#eafp-vs-lbyl) see this sort of functionality implemented, due to a race condition where e.g. two clients are both interacting and both successfully determine that a user does not exist before either creates the user, then both create the user.
Generally, I would see something like the following instead, which may be possible in peewee already... I haven't used it enough yet to know how exceptions and uniqueness work. If that's the case, this is just a documentation fix.
``` Python
try:
user = User.create( ... )
...
except User.AlreadyExists:
user = User.get(User.username == request.form['username'])
...
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/354/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/354/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/353 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/353/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/353/comments | https://api.github.com/repos/coleifer/peewee/issues/353/events | https://github.com/coleifer/peewee/issues/353 | 33,450,220 | MDU6SXNzdWUzMzQ1MDIyMA== | 353 | PostgresqlDatabase.last_insert_id w/ autocommit=True leaves open transactions | {
"login": "justinrosenthal",
"id": 804338,
"node_id": "MDQ6VXNlcjgwNDMzOA==",
"avatar_url": "https://avatars.githubusercontent.com/u/804338?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/justinrosenthal",
"html_url": "https://github.com/justinrosenthal",
"followers_url": "https://api.github.com/users/justinrosenthal/followers",
"following_url": "https://api.github.com/users/justinrosenthal/following{/other_user}",
"gists_url": "https://api.github.com/users/justinrosenthal/gists{/gist_id}",
"starred_url": "https://api.github.com/users/justinrosenthal/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/justinrosenthal/subscriptions",
"organizations_url": "https://api.github.com/users/justinrosenthal/orgs",
"repos_url": "https://api.github.com/users/justinrosenthal/repos",
"events_url": "https://api.github.com/users/justinrosenthal/events{/privacy}",
"received_events_url": "https://api.github.com/users/justinrosenthal/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Are you sure about this? Any way you can demonstrate this behavior?\nOn May 13, 2014 6:58 PM, \"Justin Rosenthal\" [email protected]\nwrote:\n\n> If you do a Model.create with a PostgresqlDatabase that has autocommit\n> enabled, you'll be left with an unclosed transaction. Since it's in\n> autocommit mode, it's most likely the case that you won't close it yourself.\n> \n> InsertQuery.execute returns self.database.last_insert_id(self._execute(),\n> self.model_class). The last_insert_id method does a cursor.execute('SELECT\n> ...') and then returns the result. The execute() will have implicitly\n> started a new transaction that doesn't get closed. I think the solution\n> might be as simple as adding a couple self.commit() calls, as shown\n> below, but I don't know the codebase well enough to know if that's the\n> right thing to do or not.\n> \n> ```\n> def last_insert_id(self, cursor, model):\n> meta = model._meta\n> seq = meta.primary_key.sequence\n> schema = ''\n> if meta.schema:\n> schema = '%s.' % meta.schema\n> if seq:\n> cursor.execute(\"SELECT CURRVAL('%s\\\"%s\\\"')\" % (schema, seq))\n> self.commit() # <----------- HERE\n> return cursor.fetchone()[0]\n> elif meta.auto_increment:\n> cursor.execute(\"SELECT CURRVAL('%s\\\"%s_%s_seq\\\"')\" % (\n> schema, meta.db_table, meta.primary_key.db_column))\n> self.commit() # <----------- AND HERE\n> return cursor.fetchone()[0]\n> ```\n> \n> —\n> Reply to this email directly or view it on GitHubhttps://github.com/coleifer/peewee/issues/353\n> .\n",
"This is the best way I could think to prove the point:\nhttps://gist.github.com/justinrosenthal/873ca0bfbf938ccf5689\n\nYou'll want to run that against a quiet database (optimally no other connections, so the SELECT only returns you a single row).\n\nNote that the Event table does not have a primary key defined, which causes Postgres to assign one via a sequence. If you specify your own primary key, `last_insert_id` doesn't run a SELECT, so you won't see the issue.\n",
"Yipes you're totally right.\n"
] | 2014-05-13T23:58:14 | 2014-05-15T15:27:28 | 2014-05-14T02:22:35 | NONE | null | If you do a `Model.create` with a PostgresqlDatabase that has autocommit enabled, you'll be left with an unclosed transaction. Since it's in autocommit mode, it's most likely the case that you won't close it yourself.
`InsertQuery.execute` returns `self.database.last_insert_id(self._execute(), self.model_class)`. The `last_insert_id` method does a `cursor.execute('SELECT ...')` and then returns the result. The `execute()` will have implicitly started a new transaction that doesn't get closed. I think the solution might be as simple as adding a couple `self.commit()` calls, as shown below, but I don't know the codebase well enough to know if that's the right thing to do or not.
``` python
def last_insert_id(self, cursor, model):
meta = model._meta
seq = meta.primary_key.sequence
schema = ''
if meta.schema:
schema = '%s.' % meta.schema
if seq:
cursor.execute("SELECT CURRVAL('%s\"%s\"')" % (schema, seq))
self.commit() # <----------- HERE
return cursor.fetchone()[0]
elif meta.auto_increment:
cursor.execute("SELECT CURRVAL('%s\"%s_%s_seq\"')" % (
schema, meta.db_table, meta.primary_key.db_column))
self.commit() # <----------- AND HERE
return cursor.fetchone()[0]
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/353/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/353/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/352 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/352/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/352/comments | https://api.github.com/repos/coleifer/peewee/issues/352/events | https://github.com/coleifer/peewee/issues/352 | 33,319,614 | MDU6SXNzdWUzMzMxOTYxNA== | 352 | Show sql feature | {
"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 | [] | 2014-05-12T15:44:58 | 2014-05-12T16:14:22 | 2014-05-12T16:14:22 | NONE | null | Is there a feature that write to console in debug mode or not the sql created?
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/352/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/352/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/351 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/351/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/351/comments | https://api.github.com/repos/coleifer/peewee/issues/351/events | https://github.com/coleifer/peewee/issues/351 | 33,138,473 | MDU6SXNzdWUzMzEzODQ3Mw== | 351 | peewee mysql gone away error | {
"login": "FashtimeDotCom",
"id": 3240392,
"node_id": "MDQ6VXNlcjMyNDAzOTI=",
"avatar_url": "https://avatars.githubusercontent.com/u/3240392?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/FashtimeDotCom",
"html_url": "https://github.com/FashtimeDotCom",
"followers_url": "https://api.github.com/users/FashtimeDotCom/followers",
"following_url": "https://api.github.com/users/FashtimeDotCom/following{/other_user}",
"gists_url": "https://api.github.com/users/FashtimeDotCom/gists{/gist_id}",
"starred_url": "https://api.github.com/users/FashtimeDotCom/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/FashtimeDotCom/subscriptions",
"organizations_url": "https://api.github.com/users/FashtimeDotCom/orgs",
"repos_url": "https://api.github.com/users/FashtimeDotCom/repos",
"events_url": "https://api.github.com/users/FashtimeDotCom/events{/privacy}",
"received_events_url": "https://api.github.com/users/FashtimeDotCom/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"This is not a bug with peewee per-se. This has been brought up a few times.\n- #225\n- #239 \n- #67 \n\nPlease search before creating new issues in the future!\n",
"## http://docs.peewee-orm.com/en/latest/peewee/database.html#error-2006-mysql-server-has-gone-away\n",
"An alternate fix is implemented in 017e4e4952f0b429dd21f0e90465a0f644cf6015\n",
"Hi @coleifer: Apologies for re-addressing this closed issue, which I see you have addressed in numerous places. I have reviewed the issues and StackOverflow, and the error persists for me.\r\n\r\nI am using a single connection (not a pool), and using the connection context manager, as described in the PeeWee documentation. The data volume is small (~100KB per row), and the problem only arises with using `self.model.insert_many(rows).execute()`. Writing a small number of rows at one time works (~1-30 rows), and debugging shows that the connection object displaying the expected behavior: the connection is closed prior to entering the context manager, open during the context manager, and closes thereafter. Writing 30+ rows fails with the 2006 error. \r\n\r\n```\r\n batch_size = 100\r\n logger.info(db_to_use.is_closed())\r\n with db_to_use.connection_context():\r\n logger.info(db_to_use.is_closed())\r\n with db_to_use.atomic():\r\n logger.info(db_to_use.is_closed())\r\n for idx in range(0, len(row_data), batch_size):\r\n logger.info(db_to_use.is_closed())\r\n rows = row_data[idx:idx + batch_size]\r\n self.model.insert_many(rows).execute()\r\n logger.info(db_to_use.is_closed())\r\n```\r\n\r\nAlternatively, using `batch_commit` does not create a 2006 error, regardless of batch size.\r\n```\r\nbatch_size = 100\r\nlogger.info(db_to_use.is_closed())\r\nwith db_to_use.connection_context():\r\n logger.info(db_to_use.is_closed())\r\n with db_to_use.atomic():\r\n logger.info(db_to_use.is_closed())\r\n for row in db_to_use.batch_commit(row_data, batch_size):\r\n logger.info(db_to_use.is_closed())\r\n self.model.create(**row)\r\nlogger.info(db_to_use.is_closed())\r\n```\r\n\r\nAnd, committing without batches also works:\r\n```\r\nlogger.info(db_to_use.is_closed())\r\nwith db_to_use.connection_context():\r\n logger.info(db_to_use.is_closed())\r\n with db_to_use.atomic():\r\n logger.info(db_to_use.is_closed())\r\n for row in row_data:\r\n logger.info(db_to_use.is_closed())\r\n self.model.create(**row)\r\nlogger.info(db_to_use.is_closed())\r\n```\r\n\r\nFor now, I can workaround this issue by using `batch_commit`. It would be helpful to understand why `insert_many` has this behavior. Thanks.",
"I can't explain it, no idea. All this stuff is unit-tested across python versions and supported databases (sqlite/mysql/python), so I'm confident there's nothing fundamentally broken in the implementations. Did you try committing after each round of `insert_many` with success? Are you running out of memory because of a large transaction and mysql is closing the connection? You might check your server logs to see why mysql is dropping you."
] | 2014-05-09T01:09:13 | 2019-09-13T16:26:05 | 2014-05-09T13:21:26 | NONE | null | when i use peewee,and try to fix this error, but try more ways failed! the error always occured!
exception::
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/tornado/web.py", line 1141, in _when_complete
callback()
File "/usr/local/lib/python2.7/dist-packages/tornado/web.py", line 1162, in _execute_method
self._when_complete(method(_self.path_args, *_self.path_kwargs),
File "/home/sch/cakeshop/src/handler/site.py", line 17, in get
for shop in Shop.select(Shop.name, Shop.ename, Shop.cover, Shop.price).where((Shop.cid != 2) & (Shop.status != 9)).order_by(Shop.views.desc()).limit(6):
File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 2086, in __iter__
return iter(self.execute())
File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 2079, in execute
self._qr = ResultWrapper(model_class, self._execute(), query_meta)
File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 1796, in _execute
return self.database.execute_sql(sql, params, self.require_commit)
File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 2359, in execute_sql
self.commit()
File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 2230, in __exit__
reraise(new_type, new_type(*exc_value.args), traceback)
File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 2351, in execute_sql
cursor.execute(sql, params or ())
File "/usr/local/lib/python2.7/dist-packages/MySQLdb/cursors.py", line 205, in execute
self.errorhandler(self, exc, value)
File "/usr/local/lib/python2.7/dist-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
raise errorclass, errorvalue
OperationalError: (2006, 'MySQL server has gone away')
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/351/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/351/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/350 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/350/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/350/comments | https://api.github.com/repos/coleifer/peewee/issues/350/events | https://github.com/coleifer/peewee/issues/350 | 33,127,819 | MDU6SXNzdWUzMzEyNzgxOQ== | 350 | count() and exists() don't work when primary_key is a CompositeKey | {
"login": "PatSmuk",
"id": 75297,
"node_id": "MDQ6VXNlcjc1Mjk3",
"avatar_url": "https://avatars.githubusercontent.com/u/75297?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/PatSmuk",
"html_url": "https://github.com/PatSmuk",
"followers_url": "https://api.github.com/users/PatSmuk/followers",
"following_url": "https://api.github.com/users/PatSmuk/following{/other_user}",
"gists_url": "https://api.github.com/users/PatSmuk/gists{/gist_id}",
"starred_url": "https://api.github.com/users/PatSmuk/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/PatSmuk/subscriptions",
"organizations_url": "https://api.github.com/users/PatSmuk/orgs",
"repos_url": "https://api.github.com/users/PatSmuk/repos",
"events_url": "https://api.github.com/users/PatSmuk/events{/privacy}",
"received_events_url": "https://api.github.com/users/PatSmuk/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Is this example code related to bitcoin in some way?\n",
"It is. We're using peewee to power [our website](http://blackcoinpool.com/). If you drop a wallet address I'd be happy to send some Bitcoin or Blackcoin your way. :smiley: \n",
"> It is. We're using peewee to power our website. If you drop a wallet address I'd be happy to send some Bitcoin or Blackcoin your way. \n\nHaha awesome, I appreciate that. I don't have a wallet but thank you.\n",
"Just thought I'd re-open the issue because I just encountered the same problem with count() and flask-peewee's admin system.\n",
"I have the same erron in count().\n",
"Currently count is implemented as the [following](https://github.com/coleifer/peewee/blob/master/peewee.py#L2068-2073): \n\n```\ndef count(self):\n if self._distinct or self._group_by:\n return self.wrapped_count()\n\n # defaults to a count() of the primary key\n return self.aggregate(convert=False) or 0\n```\n\nWhat is the purpose that it \"defaults to a count() of the primary key\" rather than `COUNT(*)`?\n",
"Thanks @coleifer !\n"
] | 2014-05-08T21:57:47 | 2014-06-18T21:19:07 | 2014-06-18T14:47:09 | NONE | null | I have a table that has its primary_key set to a CompositeKey, and attempting to use count() or exists() with that table causes a **peewee.ProgrammingError**.
Here's the trace:
```
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\flask\app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "C:\Python27\lib\site-packages\flask\app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "C:\Python27\lib\site-packages\flask\app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "C:\Python27\lib\site-packages\flask\app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "C:\Python27\lib\site-packages\flask\app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
File "C:\Python27\lib\site-packages\flask\app.py", line 1381, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "C:\Python27\lib\site-packages\flask\app.py", line 1475, in full_dispatch_request
rv = self.dispatch_request()
File "C:\Python27\lib\site-packages\flask\app.py", line 1461, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "C:\Users\Pat\Source\blackcoinpool\flask_site\app.py", line 213, in pool_stats
Stat.select().where(Stat.server == server).where(Stat.time > five_minutes_ago).exists()
File "C:\Python27\lib\site-packages\peewee.py", line 2035, in exists
return bool(clone.scalar())
File "C:\Python27\lib\site-packages\peewee.py", line 1805, in scalar
row = self._execute().fetchone()
File "C:\Python27\lib\site-packages\peewee.py", line 1796, in _execute
return self.database.execute_sql(sql, params, self.require_commit)
File "C:\Python27\lib\site-packages\peewee.py", line 2359, in execute_sql
self.commit()
File "C:\Python27\lib\site-packages\peewee.py", line 2230, in __exit__
reraise(new_type, new_type(*exc_value.args), traceback)
File "C:\Python27\lib\site-packages\peewee.py", line 2351, in execute_sql
cursor.execute(sql, params or ())
ProgrammingError: can't adapt type 'CompositeKey'
```
And the Model itself:
``` python
class Stat(db.Model):
server = ForeignKeyField(db_column='server_id', rel_model=Server)
coin = ForeignKeyField(db_column='coin_id', rel_model=Coin)
hash_rate = DecimalField(default=0)
hash_type = ForeignKeyField(db_column='hash_type_id', rel_model=HashType)
share_count = DecimalField(default=0)
time = DateTimeField()
worker_count = IntegerField(default=0)
class Meta:
db_table = 'stats'
primary_key = CompositeKey('server', 'time', 'coin')
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/350/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/350/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/349 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/349/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/349/comments | https://api.github.com/repos/coleifer/peewee/issues/349/events | https://github.com/coleifer/peewee/issues/349 | 32,464,735 | MDU6SXNzdWUzMjQ2NDczNQ== | 349 | delete_instance() deletes multiple rows in a table | {
"login": "nullism",
"id": 730290,
"node_id": "MDQ6VXNlcjczMDI5MA==",
"avatar_url": "https://avatars.githubusercontent.com/u/730290?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/nullism",
"html_url": "https://github.com/nullism",
"followers_url": "https://api.github.com/users/nullism/followers",
"following_url": "https://api.github.com/users/nullism/following{/other_user}",
"gists_url": "https://api.github.com/users/nullism/gists{/gist_id}",
"starred_url": "https://api.github.com/users/nullism/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/nullism/subscriptions",
"organizations_url": "https://api.github.com/users/nullism/orgs",
"repos_url": "https://api.github.com/users/nullism/repos",
"events_url": "https://api.github.com/users/nullism/events{/privacy}",
"received_events_url": "https://api.github.com/users/nullism/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I added a testcase in deef4531b9fc0c87cbecdec8d059650d6e83936c and it is passing. You may need to upgrade your peewee version. What version are you using currently?\n",
"I'm currently on 2.2.2. I'll test with the upgrade ASAP. Thanks for the assistance ;)\n\n```\n>>> import peewee\n>>> peewee.__version__\n'2.2.2'\n```\n",
"Yup! That totally fixed it. Thanks again!\n\n```\nCurrent branches: \n----------------------------------------\nmaster 1\nfoo 1\ntest-branch 1\nCurrent branch count: 3\nDeleting 1 branch: foo\nactual delete count: 1\nRemaining branches: \n----------------------------------------\nmaster 1\ntest-branch 1\nRemaining branch count: 2\n```\n"
] | 2014-04-29T17:05:19 | 2014-04-29T20:22:55 | 2014-04-29T20:22:55 | NONE | null | Hello, I've poured over the documentation for delete_instance(), but I found no reference for this behavior I'm currently seeing.
I have two models. `Project` and `ProjectBranch`.
`Project` is just a CharField.
`ProjectBranch` is as follows:
``` python
class ProjectBranch(DBModel):
name = CharField()
project = ForeignKeyField(Project, related_name='branches')
class Meta:
primary_key = CompositeKey('name', 'project')
```
However, when I call `delete_instance()` on any `ProjectBranch()` object, it deletes all rows from the table.
Example:
``` python
print "Current branches: "
print "-"*40
i = 0
for branch in md.ProjectBranch.select():
i += 1
print branch.name, branch.project.id
print "Current branch count: ", i
project = md.Project.get(id=1)
branch_foo = md.ProjectBranch.get(name='foo', project=project)
print "Deleting 1 branch: ", branch_foo.name
print "actual delete count: ", branch_foo.delete_instance()
print "Remaining branches: "
print "-"*40
i = 0
for branch in md.ProjectBranch.select():
i += 1
print branch.name, branch.project.id
print "Remaining branch count: ", i
```
Output:
```
Current branches:
----------------------------------------
master 1
test-branch 1
foo 1
Current branch count: 3
Deleting 1 branch: foo
actual delete count: 3
Remaining branches:
----------------------------------------
Remaining branch count: 0
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/349/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/349/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/348 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/348/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/348/comments | https://api.github.com/repos/coleifer/peewee/issues/348/events | https://github.com/coleifer/peewee/issues/348 | 32,350,573 | MDU6SXNzdWUzMjM1MDU3Mw== | 348 | Sqlite and ESCAPE | {
"login": "ticapix",
"id": 3089662,
"node_id": "MDQ6VXNlcjMwODk2NjI=",
"avatar_url": "https://avatars.githubusercontent.com/u/3089662?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/ticapix",
"html_url": "https://github.com/ticapix",
"followers_url": "https://api.github.com/users/ticapix/followers",
"following_url": "https://api.github.com/users/ticapix/following{/other_user}",
"gists_url": "https://api.github.com/users/ticapix/gists{/gist_id}",
"starred_url": "https://api.github.com/users/ticapix/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/ticapix/subscriptions",
"organizations_url": "https://api.github.com/users/ticapix/orgs",
"repos_url": "https://api.github.com/users/ticapix/repos",
"events_url": "https://api.github.com/users/ticapix/events{/privacy}",
"received_events_url": "https://api.github.com/users/ticapix/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"You can put together a clause:\n\n``` python\n>>> query = User.select().where(User.username ** Clause('t\\_t', SQL(\"ESCAPE '\\\\'\")))\n>>> print query.sql()\n('SELECT t1.\"id\", t1.\"username\" FROM \"user\" AS t1 WHERE (t1.\"username\" LIKE ? ESCAPE \\'\\\\\\')', [u't\\\\_t'])\n\n```\n"
] | 2014-04-28T11:18:20 | 2014-04-28T16:34:41 | 2014-04-28T16:34:41 | NONE | null | Hi,
I'm trying to use the LIKE operator to match entries containing underscore '_' and percent '%'.
If I understood correctly the Sqlite doc [1], I have to add the ESCAPE 'my escape char'
The common escape char is '\' (I saw '!' too in some online examples)
```
sqlite> SELECT 't_t' LIKE 't\_t' ESCAPE '\';
1
sqlite> SELECT 'tft' LIKE 't\_t' ESCAPE '\';
0
```
Is there a way to register a new operator that add the ESCAPE clause or override the contains function ?
[1] http://www.sqlite.org/lang_expr.html#like
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/348/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/348/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/347 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/347/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/347/comments | https://api.github.com/repos/coleifer/peewee/issues/347/events | https://github.com/coleifer/peewee/issues/347 | 32,200,713 | MDU6SXNzdWUzMjIwMDcxMw== | 347 | pwiz not iterating columns for the correct database | {
"login": "caelx",
"id": 1686351,
"node_id": "MDQ6VXNlcjE2ODYzNTE=",
"avatar_url": "https://avatars.githubusercontent.com/u/1686351?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/caelx",
"html_url": "https://github.com/caelx",
"followers_url": "https://api.github.com/users/caelx/followers",
"following_url": "https://api.github.com/users/caelx/following{/other_user}",
"gists_url": "https://api.github.com/users/caelx/gists{/gist_id}",
"starred_url": "https://api.github.com/users/caelx/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/caelx/subscriptions",
"organizations_url": "https://api.github.com/users/caelx/orgs",
"repos_url": "https://api.github.com/users/caelx/repos",
"events_url": "https://api.github.com/users/caelx/events{/privacy}",
"received_events_url": "https://api.github.com/users/caelx/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I'm not very familiar with MySQL's handling of `table_schema`. What is the effect of saying `table_schema = DATABASE()`?\n",
"Also, fwiw, I just pushed a rewrite of pwiz (183cf77cb9446d428f12612c8a0e47a5279a0fcc), so any changes will be against that code.\n",
"the table_schema is the database that the table comes from. I'm not sure with how postgres handles the connection, but when you query information schema it's not restricted to the database that you are currently using, which is why there is a need to add table_schema to the where clause.\n\nHere's an example:\n\n```\nmysql> show databases;\n+--------------------+\n| Database |\n+--------------------+\n| information_schema |\n| mysql |\n| performance_schema |\n| phpmyadmin |\n| test1 |\n| test2 |\n+--------------------+\n6 rows in set (0.00 sec)\n\nmysql> describe test1.test_table;\n+-------+---------+------+-----+---------+-------+\n| Field | Type | Null | Key | Default | Extra |\n+-------+---------+------+-----+---------+-------+\n| id1 | int(11) | NO | | NULL | |\n+-------+---------+------+-----+---------+-------+\n1 row in set (0.00 sec)\n\nmysql> describe test2.test_table;\n+-------+---------+------+-----+---------+-------+\n| Field | Type | Null | Key | Default | Extra |\n+-------+---------+------+-----+---------+-------+\n| id2 | int(11) | NO | | NULL | |\n+-------+---------+------+-----+---------+-------+\n1 row in set (0.00 sec)\n\nmysql> SELECT column_name, is_nullable, data_type, character_maximum_length\n -> FROM information_schema.columns\n -> WHERE table_name='test_table';\n+-------------+-------------+-----------+--------------------------+\n| column_name | is_nullable | data_type | character_maximum_length |\n+-------------+-------------+-----------+--------------------------+\n| id1 | NO | int | NULL |\n| id2 | NO | int | NULL |\n+-------------+-------------+-----------+--------------------------+\n2 rows in set (0.00 sec)\n\nmysql> use test1\nReading table information for completion of table and column names\nYou can turn off this feature to get a quicker startup with -A\n\nDatabase changed\nmysql> SELECT column_name, is_nullable, data_type, character_maximum_length\n -> FROM information_schema.columns\n -> WHERE table_name='test_table';\n+-------------+-------------+-----------+--------------------------+\n| column_name | is_nullable | data_type | character_maximum_length |\n+-------------+-------------+-----------+--------------------------+\n| id1 | NO | int | NULL |\n| id2 | NO | int | NULL |\n+-------------+-------------+-----------+--------------------------+\n2 rows in set (0.00 sec)\n\nmysql> SELECT column_name, is_nullable, data_type, character_maximum_length\n -> FROM information_schema.columns\n -> WHERE table_name='test_table'\n -> AND table_schema=DATABASE();\n+-------------+-------------+-----------+--------------------------+\n| column_name | is_nullable | data_type | character_maximum_length |\n+-------------+-------------+-----------+--------------------------+\n| id1 | NO | int | NULL |\n+-------------+-------------+-----------+--------------------------+\n1 row in set (0.00 sec)\n\nmysql>\n```\n"
] | 2014-04-25T01:48:16 | 2014-05-03T14:54:05 | 2014-05-03T14:54:05 | NONE | null | We have two databases with tables that have the same name, this can sometimes cause pwiz to fail when inspecting the columns because the database is not specified.
This is what causes the issue:
``` python
def get_columns(self, table):
pk_col = self.get_primary_key(table)
# Get basic metadata about columns. Amazingly, this is the same query
# as we use with postgresql.
curs = self.conn.execute_sql("""
SELECT column_name, is_nullable, data_type, character_maximum_length
FROM information_schema.columns
WHERE table_name=%s""", (table,))
columns = curs.fetchall()
```
To fix this issue, you'll need to pass the name the database in for the table_schema column.
``` python
def get_columns(self, table):
pk_col = self.get_primary_key(table)
# Get basic metadata about columns. Amazingly, this is the same query
# as we use with postgresql.
curs = self.conn.execute_sql("""
SELECT column_name, is_nullable, data_type, character_maximum_length
FROM information_schema.columns
WHERE table_name=%s
AND table_schema = DATABASE()""", (table,))
columns = curs.fetchall()
```
We're using mysql, but I imagine this can affect postgres as well.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/347/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/347/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/346 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/346/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/346/comments | https://api.github.com/repos/coleifer/peewee/issues/346/events | https://github.com/coleifer/peewee/issues/346 | 32,104,019 | MDU6SXNzdWUzMjEwNDAxOQ== | 346 | Count() returns 0 with pagination > 1, else it returns the full result set. | {
"login": "nullism",
"id": 730290,
"node_id": "MDQ6VXNlcjczMDI5MA==",
"avatar_url": "https://avatars.githubusercontent.com/u/730290?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/nullism",
"html_url": "https://github.com/nullism",
"followers_url": "https://api.github.com/users/nullism/followers",
"following_url": "https://api.github.com/users/nullism/following{/other_user}",
"gists_url": "https://api.github.com/users/nullism/gists{/gist_id}",
"starred_url": "https://api.github.com/users/nullism/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/nullism/subscriptions",
"organizations_url": "https://api.github.com/users/nullism/orgs",
"repos_url": "https://api.github.com/users/nullism/repos",
"events_url": "https://api.github.com/users/nullism/events{/privacy}",
"received_events_url": "https://api.github.com/users/nullism/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"When performing a LIMIT or OFFSET you need to wrap the call to count:\n\n``` python\nCommit.select().paginate(1, 5).count() # 8\nCommit.select().paginate(1, 5).wrapped_count(False) # 5\n```\n",
"Ah understood. I apologize for submitting this. Apparently I assume too much ;)\n"
] | 2014-04-23T22:05:33 | 2014-04-24T01:17:43 | 2014-04-23T22:14:33 | NONE | null | Is this expected behavior? It seems strange to me, but I acknowledge that there may be some reason for it which I don't fully understand.
Example:
``` python
def print_commits(commits):
print "="*20
total = 0
for c in commits:
total += 1
#print c.id
print "Total:", total, "Count():", commits.count()
commits = md.Commit.select().paginate(1,5)
print_commits(commits)
commits = md.Commit.select().paginate(2,5)
print_commits(commits)
```
Output:
```
====================
Total: 5 Count(): 8
====================
Total: 3 Count(): 0
```
Expected output:
```
====================
Total: 5 Count(): 5
====================
Total: 3 Count(): 3
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/346/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/346/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/345 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/345/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/345/comments | https://api.github.com/repos/coleifer/peewee/issues/345/events | https://github.com/coleifer/peewee/pull/345 | 31,886,590 | MDExOlB1bGxSZXF1ZXN0MTQ5NjE4MzE= | 345 | Typo fix | {
"login": "thedod",
"id": 225574,
"node_id": "MDQ6VXNlcjIyNTU3NA==",
"avatar_url": "https://avatars.githubusercontent.com/u/225574?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/thedod",
"html_url": "https://github.com/thedod",
"followers_url": "https://api.github.com/users/thedod/followers",
"following_url": "https://api.github.com/users/thedod/following{/other_user}",
"gists_url": "https://api.github.com/users/thedod/gists{/gist_id}",
"starred_url": "https://api.github.com/users/thedod/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/thedod/subscriptions",
"organizations_url": "https://api.github.com/users/thedod/orgs",
"repos_url": "https://api.github.com/users/thedod/repos",
"events_url": "https://api.github.com/users/thedod/events{/privacy}",
"received_events_url": "https://api.github.com/users/thedod/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2014-04-21T08:41:29 | 2014-07-06T01:49:58 | 2014-04-21T14:04:17 | CONTRIBUTOR | null | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/345/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/345/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/345",
"html_url": "https://github.com/coleifer/peewee/pull/345",
"diff_url": "https://github.com/coleifer/peewee/pull/345.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/345.patch",
"merged_at": "2014-04-21T14:04:17"
} |
|
https://api.github.com/repos/coleifer/peewee/issues/344 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/344/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/344/comments | https://api.github.com/repos/coleifer/peewee/issues/344/events | https://github.com/coleifer/peewee/issues/344 | 31,835,906 | MDU6SXNzdWUzMTgzNTkwNg== | 344 | Feature request: provide feedback if Model.save() succeeded | {
"login": "CodeZombieCH",
"id": 729017,
"node_id": "MDQ6VXNlcjcyOTAxNw==",
"avatar_url": "https://avatars.githubusercontent.com/u/729017?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/CodeZombieCH",
"html_url": "https://github.com/CodeZombieCH",
"followers_url": "https://api.github.com/users/CodeZombieCH/followers",
"following_url": "https://api.github.com/users/CodeZombieCH/following{/other_user}",
"gists_url": "https://api.github.com/users/CodeZombieCH/gists{/gist_id}",
"starred_url": "https://api.github.com/users/CodeZombieCH/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/CodeZombieCH/subscriptions",
"organizations_url": "https://api.github.com/users/CodeZombieCH/orgs",
"repos_url": "https://api.github.com/users/CodeZombieCH/repos",
"events_url": "https://api.github.com/users/CodeZombieCH/events{/privacy}",
"received_events_url": "https://api.github.com/users/CodeZombieCH/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Peewee doesn't try to be too clever here, but you're right, the update statement will fail silently, which I agree is bad.\n",
"Fixed in e73d3db12fb370c48cca8f45514a7fed9637949c -- returns number of rows affected (1 always in case of inserts, but could be 0/1 for updates).\n",
"Cool, thanks a lot.\n"
] | 2014-04-19T02:18:21 | 2014-04-22T12:50:11 | 2014-04-20T12:14:57 | NONE | null | The current implementation of [Model.save()](https://github.com/coleifer/peewee/blob/master/peewee.py#L3071) does not provide any feedback if the save operation failed or succeeded. In the case a retrieved record has been deleted by a concurrent process in the meantime, the executed UPDATE statement finds no matching record and "fails" silently.
**Proposal 1**
The Model.save() implementation should be changed so it returns the number of affected rows by the executed SQL statement. This allows developers to ensure a successful save operation.
**Proposal 2**
The Model.save() implementation should be changed so it raises an exception in the case the number of rows affected by the UPDATE statement is not 1.
Example describing the issue:
```
from peewee import *
db = SqliteDatabase('example.sqlite')
class BaseModel(Model):
class Meta:
database = db
class Foo(BaseModel):
bar = CharField()
def init():
db.connect()
Foo.create_table(True)
def close():
db.close()
init()
# Prepare sample for test
f = Foo.create(bar='Lorem ipsum')
f.save()
f1 = Foo.get(Foo.bar == 'Lorem ipsum')
f2 = Foo.get(Foo.bar == 'Lorem ipsum')
f1.delete_instance()
f2.bar = 'dolor sit'
# Saving a record deleted in the meantime does "fail" silently
f2.save()
close()
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/344/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/344/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/343 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/343/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/343/comments | https://api.github.com/repos/coleifer/peewee/issues/343/events | https://github.com/coleifer/peewee/pull/343 | 31,830,805 | MDExOlB1bGxSZXF1ZXN0MTQ5Mzc2OTg= | 343 | playhouse.sqlcipher_ext.SqlCipherDatabase | {
"login": "thedod",
"id": 225574,
"node_id": "MDQ6VXNlcjIyNTU3NA==",
"avatar_url": "https://avatars.githubusercontent.com/u/225574?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/thedod",
"html_url": "https://github.com/thedod",
"followers_url": "https://api.github.com/users/thedod/followers",
"following_url": "https://api.github.com/users/thedod/following{/other_user}",
"gists_url": "https://api.github.com/users/thedod/gists{/gist_id}",
"starred_url": "https://api.github.com/users/thedod/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/thedod/subscriptions",
"organizations_url": "https://api.github.com/users/thedod/orgs",
"repos_url": "https://api.github.com/users/thedod/repos",
"events_url": "https://api.github.com/users/thedod/events{/privacy}",
"received_events_url": "https://api.github.com/users/thedod/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Ouch :cold_sweat: forgot to test _without_ `-e pysqlcipher`. Sorting it out now...\n",
"If you take a look at peewee's source code you will see that I have tried to stick to pep8 in most places. I've also tried to have uniform formatting of comments.\n",
"I believe your tests are failing because you have not registered some default type converters. Take a look at the top of the peewee module and you'll see what I'm referring to (line ~130, `sqlite3.register_adapter()`).\n\nAlso there should be some basic unit tests for this module. You can see the other modules in the `playhouse` have some unit tests.\n",
"> I believe your tests are failing because you have not registered some default type converters. Take a look at the top of the peewee module and you'll see what I'm referring to (line ~130, sqlite3.register_adapter()).\n\nThanks. I'll look into this.\n\n> Also there should be some basic unit tests for this module. You can see the other modules in the playhouse have some unit tests.\n\nThe only `--pyciphersql` test I can think of (that is not covered by running the regular tests with `-e pysqlcipher`) is: Create a db, store something, try to open it with wrong passphrase and fail, try with the right one and succeed. Would that do?\n",
"This is close but not quite ready. I don't know how many times I need to mention this but pay attention to spacing in your operations. Read pep8.\n",
"Lookin good mane. Last thing (I promise) is some docs in the `playhouse` documentation file.\n",
"This is now merged, thanks for the contribution!\n"
] | 2014-04-18T23:06:38 | 2014-06-19T08:10:04 | 2014-05-03T15:37:22 | CONTRIBUTOR | null | Tests pass with `-e pysqcipher` and with `--pysqlcipher`
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/343/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/343/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/343",
"html_url": "https://github.com/coleifer/peewee/pull/343",
"diff_url": "https://github.com/coleifer/peewee/pull/343.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/343.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/342 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/342/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/342/comments | https://api.github.com/repos/coleifer/peewee/issues/342/events | https://github.com/coleifer/peewee/issues/342 | 31,694,294 | MDU6SXNzdWUzMTY5NDI5NA== | 342 | Coersion failing because of function type conversion | {
"login": "caelx",
"id": 1686351,
"node_id": "MDQ6VXNlcjE2ODYzNTE=",
"avatar_url": "https://avatars.githubusercontent.com/u/1686351?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/caelx",
"html_url": "https://github.com/caelx",
"followers_url": "https://api.github.com/users/caelx/followers",
"following_url": "https://api.github.com/users/caelx/following{/other_user}",
"gists_url": "https://api.github.com/users/caelx/gists{/gist_id}",
"starred_url": "https://api.github.com/users/caelx/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/caelx/subscriptions",
"organizations_url": "https://api.github.com/users/caelx/orgs",
"repos_url": "https://api.github.com/users/caelx/repos",
"events_url": "https://api.github.com/users/caelx/events{/privacy}",
"received_events_url": "https://api.github.com/users/caelx/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Unfortunately that code is there for a reason. Consider a field like this:\n\n``` python\nclass CSVField(CharField):\n def db_value(self, value):\n return ','.join(value)\n\n def python_value(self, value):\n return value.split(',')\n```\n\nThis field would be used to store or retrieve lists of data encoded in CSV.\n\nWhat if you wanted to do a case insensitive search for some particular items? Then we'd want to pass the value to the field's conversion function:\n\n``` python\nMyModel.select().where(MyModel.csv_data == fn.LOWER(Param(['item1', 'item2'])))\n```\n\nI admit it's a bit of a contrived example, but that was the reasoning behind the conversion.\n",
"This is now fixed. In order to avoid coercing the values you would write:\n\n``` python\nIP.select().where(IP.ip == fn.INET_ATON('8.8.8.8').coerce(False)).execute()\n```\n",
"Awesome as usual, thanks!\n\nI understand why you need to do the coercion, I was just looking for an expressive interface for manually disabling it which you have provided perfectly.\n\nI actually tried calling the coerce method with false myself but it didn't do what I hoped it did at that time.\n"
] | 2014-04-17T01:25:53 | 2014-04-17T22:06:53 | 2014-04-17T12:45:49 | NONE | null | I'm trying to use the mysql function 'INET_ATON' which takes a string representation of an IP address and returns an integer, and the comparing that integer to a integer stored in my database. The issue is that when I do peewee is trying to coerce the original string input into an integer before executing the query and error'ing out.
Here's a snippet of code that will generate the error:
``` python
from peewee import *
# configure your mysql db here
database = MySQLDatabase(DB, host=DB_HOST, port=DB_PORT, user=DB_USER, passwd=DB_PASSWD)
class BaseModel(Model):
class Meta:
database = database
class IP(BaseModel):
ip = IntegerField()
def main():
database.connect()
IP.create_table()
IP.insert(ip=fn.INET_ATON('8.8.8.8')).execute()
IP.select().where(IP.ip == fn.INET_ATON('8.8.8.8')).execute()
if __name__ == '__main__':
main()
```
Is there some way to disable the coersion for functions, I tried to look through the source code but I didn't really see a way.
Error:
```
2014-04-16 15:20:31,358 - peewee - DEBUG - ('INSERT INTO `ip` (`ip`) VALUES (INET_ATON(%s))', ['8.8.8.8'])
Traceback (most recent call last):
File "snippet.py", line 28, in <module>
main()
File "snippet.py", line 24, in main
IP.select().where(IP.ip == fn.INET_ATON('8.8.8.8')).execute()
File "/Users/cael/.virtualenvs/sqlgen/lib/python2.7/site-packages/peewee.py", line 2036, in execute
self._qr = ResultWrapper(model_class, self._execute(), query_meta)
File "/Users/cael/.virtualenvs/sqlgen/lib/python2.7/site-packages/peewee.py", line 1752, in _execute
sql, params = self.sql()
File "/Users/cael/.virtualenvs/sqlgen/lib/python2.7/site-packages/peewee.py", line 2012, in sql
return self.compiler().generate_select(self)
File "/Users/cael/.virtualenvs/sqlgen/lib/python2.7/site-packages/peewee.py", line 1260, in generate_select
return self.build_query(clauses, alias_map)
File "/Users/cael/.virtualenvs/sqlgen/lib/python2.7/site-packages/peewee.py", line 1171, in build_query
return self.parse_node(Clause(*clauses), alias_map)
File "/Users/cael/.virtualenvs/sqlgen/lib/python2.7/site-packages/peewee.py", line 1135, in parse_node
sql, params, unknown = self._parse(node, alias_map, conv)
File "/Users/cael/.virtualenvs/sqlgen/lib/python2.7/site-packages/peewee.py", line 1081, in _parse
node.nodes, alias_map, conv, node.glue)
File "/Users/cael/.virtualenvs/sqlgen/lib/python2.7/site-packages/peewee.py", line 1152, in parse_node_list
node_sql, node_params = self.parse_node(node, alias_map, conv)
File "/Users/cael/.virtualenvs/sqlgen/lib/python2.7/site-packages/peewee.py", line 1135, in parse_node
sql, params, unknown = self._parse(node, alias_map, conv)
File "/Users/cael/.virtualenvs/sqlgen/lib/python2.7/site-packages/peewee.py", line 1067, in _parse
rhs, rparams = self.parse_node(node.rhs, alias_map, conv)
File "/Users/cael/.virtualenvs/sqlgen/lib/python2.7/site-packages/peewee.py", line 1135, in parse_node
sql, params, unknown = self._parse(node, alias_map, conv)
File "/Users/cael/.virtualenvs/sqlgen/lib/python2.7/site-packages/peewee.py", line 1077, in _parse
sql, params = self.parse_node_list(node.arguments, alias_map, conv)
File "/Users/cael/.virtualenvs/sqlgen/lib/python2.7/site-packages/peewee.py", line 1152, in parse_node_list
node_sql, node_params = self.parse_node(node, alias_map, conv)
File "/Users/cael/.virtualenvs/sqlgen/lib/python2.7/site-packages/peewee.py", line 1137, in parse_node
params = [conv.db_value(i) for i in params]
File "/Users/cael/.virtualenvs/sqlgen/lib/python2.7/site-packages/peewee.py", line 579, in db_value
return value if value is None else self.coerce(value)
ValueError: invalid literal for int() with base 10: '8.8.8.8'
```
Versions:
```
MySQL-python==1.2.3
bottle==0.12.5
dnspython==1.11.1
dnsq==1.1.2
expiringdict==1.1
peewee==2.2.2
wsgiref==0.1.2
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/342/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/342/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/341 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/341/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/341/comments | https://api.github.com/repos/coleifer/peewee/issues/341/events | https://github.com/coleifer/peewee/issues/341 | 31,534,022 | MDU6SXNzdWUzMTUzNDAyMg== | 341 | Low performance compared to plain sqlite3 | {
"login": "piacias",
"id": 7080293,
"node_id": "MDQ6VXNlcjcwODAyOTM=",
"avatar_url": "https://avatars.githubusercontent.com/u/7080293?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/piacias",
"html_url": "https://github.com/piacias",
"followers_url": "https://api.github.com/users/piacias/followers",
"following_url": "https://api.github.com/users/piacias/following{/other_user}",
"gists_url": "https://api.github.com/users/piacias/gists{/gist_id}",
"starred_url": "https://api.github.com/users/piacias/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/piacias/subscriptions",
"organizations_url": "https://api.github.com/users/piacias/orgs",
"repos_url": "https://api.github.com/users/piacias/repos",
"events_url": "https://api.github.com/users/piacias/events{/privacy}",
"received_events_url": "https://api.github.com/users/piacias/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Have you tried running the import in a transaction? Peewee calls `commit()` after issuing `INSERT` by default, which may not be happening with sqlite by itself.\n\nYou would basically:\n\n``` python\nwith db.transaction():\n process_entries()\n```\n\nPlease give that a shot and let me know.\n",
"Ok, I've changed code to be executed as one transaction and result is very good:\n\n0:11:30.584987 - peewee - sqlite\n\nPlease notice that I've had already autocommit set to False (on db initialization), so I'm not sure is 'commit' is it only thing.\n\nAnyway, thanks for reply.\n"
] | 2014-04-15T08:19:39 | 2014-04-15T12:24:03 | 2014-04-15T12:24:03 | NONE | null | Hi, I'm writing simple logparser. I have 3 models defined as below. I set database as shown:
```
db = peewee.SqliteDatabase(DATABASE, autocommit=False)
class Entry(BaseModel):
timestamp = peewee.DateTimeField()
level = peewee.IntegerField()
module = peewee.CharField()
line = peewee.IntegerField()
exception = peewee.CharField()
description = peewee.CharField()
orig_exception = peewee.CharField(null=True)
orig_description = peewee.CharField(null=True)
class TracebackEntry(BaseModel):
path = peewee.CharField()
line = peewee.IntegerField()
class Traceback(BaseModel):
entry = peewee.ForeignKeyField(Entry)
traceback_entry = peewee.ForeignKeyField(TracebackEntry)
```
Input data are stored in logfile (tsv), each log entry contains some basic data and optional traceback - I'm using following method to process entry:
param entry is list which contains:
- some basic data - this line is required
- If entry has traceback - last line contains original exception (orig_exception, orig_description)
- Other lines - contain traceback entries (path + line)
```
def process_entry(entry):
e1, e2, e3, e4, e5, e6= entry[0].split('\t')
e = Entry(
timestamp=e1,
level=e2,
module=e3,
line=e4,
exception=e5,
description=e6
)
tb_entries = [] # this contains traceback entries objects to set m2m
if len(entry) > 1:
exc, exc_desc = entry[-1].split('\t')
e.orig_exception = exc
e.orig_description = exc_desc
# collecting already defined traceback entries (it doesn't contain lots of data)
defined_tb_entries = TracebackEntry.select()
# gather traceback entries
for l in entry[1:-1]:
path, line = l.split('\t')
found = False
for tb in defined_tb_entries:
if tb.path == path and tb.line == int(line):
found = True
tb_entries.append(tb)
break
if not found:
# create missing
tb_entries.append(TracebackEntry.create(path=path, line=line))
e.save()
# Set m2m Entry,TracebackEntry
Traceback.insert_many(
{
'entry': e,
'traceback_entry': tb_entry
} for tb_entry in tb_entries
).execute()
```
I've got problem with performance while parsing big log file (800MB).
After parsing there are:
- 1102086 - Entry objects
- 177 - TracebackEntry objects
- 3750785 - Traceback objects (m2m)
stored in database.
When I'm using peewee, I get results in:
1:23:22.891102 - peewee - sqlite (file - not :memory:)
0:42:46.240624 - peewee - mysql
but when I change method 'process_entry' to use native sqlite3 module, I get results in:
0:08:22.793224 - sqlite3
What am I doing wrong, or how can I speedup processing of entries.
Notice: I've simplified process_entry method to increase readability (may not run without errors)
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/341/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/341/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/340 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/340/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/340/comments | https://api.github.com/repos/coleifer/peewee/issues/340/events | https://github.com/coleifer/peewee/issues/340 | 31,527,492 | MDU6SXNzdWUzMTUyNzQ5Mg== | 340 | Subquery in FROM needs an alias in PostgreSQL | {
"login": "tonycpsu",
"id": 914142,
"node_id": "MDQ6VXNlcjkxNDE0Mg==",
"avatar_url": "https://avatars.githubusercontent.com/u/914142?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/tonycpsu",
"html_url": "https://github.com/tonycpsu",
"followers_url": "https://api.github.com/users/tonycpsu/followers",
"following_url": "https://api.github.com/users/tonycpsu/following{/other_user}",
"gists_url": "https://api.github.com/users/tonycpsu/gists{/gist_id}",
"starred_url": "https://api.github.com/users/tonycpsu/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/tonycpsu/subscriptions",
"organizations_url": "https://api.github.com/users/tonycpsu/orgs",
"repos_url": "https://api.github.com/users/tonycpsu/repos",
"events_url": "https://api.github.com/users/tonycpsu/events{/privacy}",
"received_events_url": "https://api.github.com/users/tonycpsu/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Can you please share a minimal set of models I can use to reproduce the error?\n",
"Sure, here's a simple test script I've cooked up: https://gist.github.com/tonycpsu/10737226\n\nRun it with \"sqlite\" or \"postgres\" as arguments to test both backends (Postgres database must exist first.) I get different errors from both.\n",
"It's a little tricky...there are a couple things going on.\n- When peewee encounters a \"bare\" sub-select, it will only select the primary key. This is because commonly you use a sub-select to filter on the primary key. To work around this, you need to manually specify which columns to select in your subquery.\n- When peewee builds the outer query, it uses the alias `t1`, so you need to specify that as the alias for the sub-select.\n\nThe following test-case is passing on both sqlite and postgres:\n\n``` python\nclass FromMultiTableTestCase(ModelTestCase):\n requires = [Blog, Comment, User]\n\n def setUp(self):\n super(FromMultiTableTestCase, self).setUp()\n\n for u in range(2):\n user = User.create(username='u%s' % u)\n for i in range(3):\n b = Blog.create(user=user, title='b%s-%s' % (u, i))\n for j in range(i):\n Comment.create(blog=b, comment='c%s-%s' % (i, j))\n\n def test_from_multi_table(self):\n q = (Blog\n .select(Blog, User)\n .from_(Blog, User)\n .where(\n (Blog.user == User.id) &\n (User.username == 'u0'))\n .order_by(Blog.pk)\n .naive())\n\n qc = len(self.queries())\n blogs = [b.title for b in q]\n self.assertEqual(blogs, ['b0-0', 'b0-1', 'b0-2'])\n\n usernames = [b.username for b in q]\n self.assertEqual(usernames, ['u0', 'u0', 'u0'])\n self.assertEqual(len(self.queries()) - qc, 1)\n\n def test_subselect(self):\n inner = User.select(User.username)\n self.assertEqual(\n [u.username for u in inner.order_by(User.username)], ['u0', 'u1'])\n\n # Have to manually specify the alias as \"t1\" because the outer query\n # will expect that.\n outer = (User\n .select(User.username)\n .from_(inner.alias('t1')))\n sql, params = compiler.generate_select(outer)\n self.assertEqual(sql, (\n 'SELECT users.\"username\" FROM '\n '(SELECT users.\"username\" FROM \"users\" AS users) AS t1'))\n\n self.assertEqual(\n [u.username for u in outer.order_by(User.username)], ['u0', 'u1'])\n\n```\n",
"I see.... I had tried `.from(inner).alias('t1')`, but not `.from_(inner.alias('t1'))`. If there's no easy way for the outer query to properly infer/add the alias, then I guess there's no bug here, and I'll just put \"t1\" or whatever in explicitly. Thanks.\n",
"Yeah, I'm realizing I may need to figure out how to make the outer query aware of the inner query's alias, but that doesn't seem like it'll be all that easy. I definitely understand the approaches I've shown are kind of hacky.\n\nI'll leave this open so I can think on it for a little and see if I can come up w/something better.\n",
"OK, while you're at it, I'm noticing that if the \"inner\" query is of type `peewee.CompoundSelect` (rather than `peewee.SelectQuery`), it barfs, with:\n\n```\npeewee.OperationalError: near \"SELECT\": syntax error\n```\n\nThe .sql() of the outer query in such a case yields:\n\n```\n('SELECT * FROM SELECT t2.\"name\" FROM \"person\" AS t2 UNION SELECT t3.\"name\" FROM \"person\" AS t3 AS t1', [])\n```\n\n(Note the absence of parens around the \"inner\" UNION query.)\n",
"My test snippet for the above (using the same model as the gist I linked to previously) is:\n\n```\ninner = (Person\n .select(Person.name)\n )\n\ninner2 = ( inner | inner )\n\nprint inner2.sql()\nprint list(inner2)\n\nouter = (Person\n .select(SQL('*'))\n .from_(inner2.alias('t1'))\n )\n\nprint outer.sql()\nprint list(outer)\n```\n",
"Nice catch. Yes, I had to explicitly tell peewee not to put parentheses around `CompoundSelect` because SQLite wasn't handling them correctly.\n",
"Using an alias works fine. But as you already stated, the outer query doesn't know the about the alias for the inner query so you can't use values from the inner query for a join. e.g.\n\n```\nsubselect = TestModel.select(TestModel.id, TestModel.column1)\nfinal = (TestModel2.select(TestModel.id, TestModel.column1).from_(subselect)\n .join(TestModel3, on=(subselect.id == TestModel3.id)))\n```\n\nproblem is the _on_ part which doesn't know about the inner query and its alias.\n",
"This is now \"fixed\", or at least possible. Here is a test-case exemplifying the new behavior:\n\n``` python\n def test_subselect_with_join(self):\n inner = User.select(User.id, User.username).alias('q1')\n outer = (Blog\n .select(inner.c.id, inner.c.username)\n .from_(inner)\n .join(Comment, on=(inner.c.id == Comment.id)))\n sql, params = compiler.generate_select(outer)\n self.assertEqual(sql, (\n 'SELECT \"q1\".\"id\", \"q1\".\"username\" FROM ('\n 'SELECT users.\"id\", users.\"username\" FROM \"users\" AS users) AS q1 '\n 'INNER JOIN \"comment\" AS comment ON (\"q1\".\"id\" = comment.\"id\")'))\n```\n"
] | 2014-04-15T05:39:24 | 2014-07-12T14:25:17 | 2014-07-12T14:24:23 | NONE | null | I'd like to do a subquery in the FROM clause, as per https://github.com/coleifer/peewee/commit/22ce07c43cbf3c7cf871326fc22177cc1e5f8345 . However, with the Postgres backend, these subqueries must have an alias, or you get `peewee.ProgrammingError: subquery in FROM must have an alias`.
Peewee doesn't seem to add one automatically, and when I try to add one with, e.g.
`.select().from_(inner).alias("inner")`, I still get the error indicating lack of an alias.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/340/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/340/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/339 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/339/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/339/comments | https://api.github.com/repos/coleifer/peewee/issues/339/events | https://github.com/coleifer/peewee/issues/339 | 31,444,252 | MDU6SXNzdWUzMTQ0NDI1Mg== | 339 | Insert_many - ids of created rows | {
"login": "piacias",
"id": 7080293,
"node_id": "MDQ6VXNlcjcwODAyOTM=",
"avatar_url": "https://avatars.githubusercontent.com/u/7080293?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/piacias",
"html_url": "https://github.com/piacias",
"followers_url": "https://api.github.com/users/piacias/followers",
"following_url": "https://api.github.com/users/piacias/following{/other_user}",
"gists_url": "https://api.github.com/users/piacias/gists{/gist_id}",
"starred_url": "https://api.github.com/users/piacias/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/piacias/subscriptions",
"organizations_url": "https://api.github.com/users/piacias/orgs",
"repos_url": "https://api.github.com/users/piacias/repos",
"events_url": "https://api.github.com/users/piacias/events{/privacy}",
"received_events_url": "https://api.github.com/users/piacias/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I suppose, the reason I had not added that was out of memory considerations but on the whole I think that even if you were inserting a very large number of rows, it would be ok to keep the list of IDs around.\n",
"Actually, because the insert will in most cases be only a single statement, there is not a way to efficiently get the PK of all the inserted rows.\n"
] | 2014-04-14T08:58:11 | 2014-04-14T20:06:06 | 2014-04-14T20:06:06 | NONE | null | Is it possible to get newly created ids, when creating rows via insert_many ?
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/339/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/339/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/338 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/338/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/338/comments | https://api.github.com/repos/coleifer/peewee/issues/338/events | https://github.com/coleifer/peewee/issues/338 | 31,409,461 | MDU6SXNzdWUzMTQwOTQ2MQ== | 338 | Array and JSON fields do not output SQL with table aliases | {
"login": "mtwesley",
"id": 145616,
"node_id": "MDQ6VXNlcjE0NTYxNg==",
"avatar_url": "https://avatars.githubusercontent.com/u/145616?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/mtwesley",
"html_url": "https://github.com/mtwesley",
"followers_url": "https://api.github.com/users/mtwesley/followers",
"following_url": "https://api.github.com/users/mtwesley/following{/other_user}",
"gists_url": "https://api.github.com/users/mtwesley/gists{/gist_id}",
"starred_url": "https://api.github.com/users/mtwesley/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/mtwesley/subscriptions",
"organizations_url": "https://api.github.com/users/mtwesley/orgs",
"repos_url": "https://api.github.com/users/mtwesley/repos",
"events_url": "https://api.github.com/users/mtwesley/events{/privacy}",
"received_events_url": "https://api.github.com/users/mtwesley/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Ah, nice catch!\n",
"Thanks for your help reporting and debugging this issue.\n"
] | 2014-04-13T16:05:55 | 2014-04-13T16:17:25 | 2014-04-13T16:17:10 | NONE | null | I was having a problem with joining two tables with the same field name when one of them was of an array type, using the extra Postgres functionality from the Playhouse package. I narrowed it down to it being related to the table alias not being included in the where clause of the query.
Took a while, and I'm not sure whether this is the correct "fix", but I think the problem was related to the alias_map not being passed into the parse_node() function, leading to an output of:
``` sql
where ("int_values"[1] = 123);
```
Instead of:
``` sql
where (t1."int_values"[1] = 123);
```
Here's a diff of the change I made that appears to work:
``` diff
diff --git a/playhouse/postgres_ext.py b/playhouse/postgres_ext.py
index a9c864f..98fc3e7 100644
--- a/playhouse/postgres_ext.py
+++ b/playhouse/postgres_ext.py
@@ -203,13 +203,13 @@ class PostgresqlExtCompiler(QueryCompiler):
if unknown:
if isinstance(node, ObjectSlice):
unknown = False
- sql, params = self.parse_node(node.node)
+ sql, params = self.parse_node(node.node, alias_map, conv)
# Postgresql uses 1-based indexes.
parts = [str(part + 1) for part in node.parts]
sql = '%s[%s]' % (sql, ':'.join(parts))
if isinstance(node, JsonLookup):
unknown = False
- sql, params = self.parse_node(node.node)
+ sql, params = self.parse_node(node.node, alias_map, conv)
lookups = [sql]
for part in node.parts:
part_sql, part_params = self.parse_node(part)
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/338/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/338/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/337 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/337/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/337/comments | https://api.github.com/repos/coleifer/peewee/issues/337/events | https://github.com/coleifer/peewee/issues/337 | 31,250,842 | MDU6SXNzdWUzMTI1MDg0Mg== | 337 | Possible to aggregate by month, day, etc? | {
"login": "tonycpsu",
"id": 914142,
"node_id": "MDQ6VXNlcjkxNDE0Mg==",
"avatar_url": "https://avatars.githubusercontent.com/u/914142?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/tonycpsu",
"html_url": "https://github.com/tonycpsu",
"followers_url": "https://api.github.com/users/tonycpsu/followers",
"following_url": "https://api.github.com/users/tonycpsu/following{/other_user}",
"gists_url": "https://api.github.com/users/tonycpsu/gists{/gist_id}",
"starred_url": "https://api.github.com/users/tonycpsu/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/tonycpsu/subscriptions",
"organizations_url": "https://api.github.com/users/tonycpsu/orgs",
"repos_url": "https://api.github.com/users/tonycpsu/repos",
"events_url": "https://api.github.com/users/tonycpsu/events{/privacy}",
"received_events_url": "https://api.github.com/users/tonycpsu/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"It depends on your database.\n\nFor sqlite you might use the `strftime` function to truncate a timestamp. This would calculate a sum of some value for each month:\n\n``` python\nquery = (Values\n .select(fn.Sum(Values.value).alias('average_value'))\n .group_by(fn.strftime('%Y-%m', Values.timestamp))\n .tuples())\n```\n\nFor postgresql you would use `date_trunc`.\n\n``` python\nquery = (Values\n .select(fn.Sum(Values.value).alias('average_value'))\n .group_by(fn.date_trunc('month', Values.timestamp))\n .tuples())\n```\n",
"OK, was looking for something that wasn't as dependent on the underlying DB, but I can use that for now. Thanks.\n",
"Yeah, it might be a good idea to create a custom `date_trunc` function for sqlite. As far as MySQL, I'm not really sure since I don't use MySQL myself.\n",
"Fixed in b6b6c2e9ed7215e25494c8bf4b8a73118eedc724\n"
] | 2014-04-10T14:58:11 | 2014-04-11T14:31:30 | 2014-04-11T14:31:30 | NONE | null | What's the recommended way to do a group by month or day with a DateTimeField? I know some of the underlying databases have date functions, and I know I could do it by formatting it as a string and truncating the hours, minutes, etc. but I thought there might be a more portable way to do it using Peewee.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/337/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/337/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/336 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/336/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/336/comments | https://api.github.com/repos/coleifer/peewee/issues/336/events | https://github.com/coleifer/peewee/issues/336 | 30,963,069 | MDU6SXNzdWUzMDk2MzA2OQ== | 336 | MySQL - using 'from_' function - 'Every derived table must have its own alias' | {
"login": "Seidr",
"id": 795518,
"node_id": "MDQ6VXNlcjc5NTUxOA==",
"avatar_url": "https://avatars.githubusercontent.com/u/795518?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/Seidr",
"html_url": "https://github.com/Seidr",
"followers_url": "https://api.github.com/users/Seidr/followers",
"following_url": "https://api.github.com/users/Seidr/following{/other_user}",
"gists_url": "https://api.github.com/users/Seidr/gists{/gist_id}",
"starred_url": "https://api.github.com/users/Seidr/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/Seidr/subscriptions",
"organizations_url": "https://api.github.com/users/Seidr/orgs",
"repos_url": "https://api.github.com/users/Seidr/repos",
"events_url": "https://api.github.com/users/Seidr/events{/privacy}",
"received_events_url": "https://api.github.com/users/Seidr/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Sorry, I should of mentioned..while this is using the flask-peewee wrapper, I've updated peewee to the most recent version (git clone) and am still experiencing the issue described above, and believe that if I were to re-write this test to use purely peewee, this issue would still be experienced.\n",
"Have you tried applying an alias to the inner query?\n\n```\nuser_id = SQL(\"inner_query.user_id\")\nresult_list = SQL(\"inner_query.result_list\")\nresults = ResultSet.select(\n fn.Group_Concat(result_list).alias(\"result_list_n\")\n).from_(\n ResultSet.select(\n ResultSet.user.alias(\"user_id\"),\n ResultSet.result.alias(\"result_list\")\n ).\n order_by(\n ResultSet.result.asc()\n ).\n limit(\n 5\n ).\n alias('inner_query')\n).group_by(user_id).first().result_list_n\n```\n\nOn Mon, Apr 7, 2014 at 3:24 AM, Seidr [email protected] wrote:\n\n> Sorry, I should of mentioned..while this is using the flask-peewee\n> wrapper, I've updated peewee to the most recent version (git clone) and am\n> still experiencing the issue described above, and believe that if I were to\n> re-write this test to use purely peewee, this issue would still be\n> experienced.\n> \n> ## \n> \n> Reply to this email directly or view it on GitHubhttps://github.com/coleifer/peewee/issues/336#issuecomment-39706110\n> .\n",
"Wow - I'm sure I had tried that..\n\nThanks for getting back to me, and indeed aliasing the inner query solves the problem.\n"
] | 2014-04-07T07:30:41 | 2014-04-07T13:14:20 | 2014-04-07T13:14:20 | NONE | null | While playing around with the 'from_' function that was introduced recently (I believe it was pretty recent (see https://groups.google.com/forum/#!topic/peewee-orm/FSHhd9lZvUE), and ran into a bit of an issue when attempting to use the same query that worked under SQLITE, on a MySQL database.
The issue is - as the error message describes - that the table that is derived after using the 'from_' function is not provided with an alias.
Please see the below link to a gist that demonstrates this issue. Using SQLITE, upon visiting the root of the app (http://localhost:5000) you will get a list of IDs resulting from the Group_Concat (1,2,3,4,5). When running the same script, while using the MySQL config, you will get the following error upon visiting the root of the app.
"OperationalError: (1248, 'Every derived table must have its own alias')"
A solution would be to have an alias pool for queries that make use of the 'from_' function, for nested queries.
A test to demonstrate an error when using nested queries in peewee (MySQL): https://gist.github.com/Seidr/10016077
While I can work around this by performing the Group_Concat outside of peewee (i.e. just creating the list by looping over the result set), it'd be nice to be able to alias nested queries within peewee.
If you need any more information, do let me know, and I'll be happy to help.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/336/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/336/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/335 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/335/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/335/comments | https://api.github.com/repos/coleifer/peewee/issues/335/events | https://github.com/coleifer/peewee/issues/335 | 30,942,628 | MDU6SXNzdWUzMDk0MjYyOA== | 335 | inconsistent programming error | {
"login": "Agrisolum",
"id": 5942632,
"node_id": "MDQ6VXNlcjU5NDI2MzI=",
"avatar_url": "https://avatars.githubusercontent.com/u/5942632?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/Agrisolum",
"html_url": "https://github.com/Agrisolum",
"followers_url": "https://api.github.com/users/Agrisolum/followers",
"following_url": "https://api.github.com/users/Agrisolum/following{/other_user}",
"gists_url": "https://api.github.com/users/Agrisolum/gists{/gist_id}",
"starred_url": "https://api.github.com/users/Agrisolum/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/Agrisolum/subscriptions",
"organizations_url": "https://api.github.com/users/Agrisolum/orgs",
"repos_url": "https://api.github.com/users/Agrisolum/repos",
"events_url": "https://api.github.com/users/Agrisolum/events{/privacy}",
"received_events_url": "https://api.github.com/users/Agrisolum/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I tried the same thing with a local sqlite db (_much_ slower...) and this happened:\n\n```\nTraceback (most recent call last):\n File \"<stdin>\", line 1, in <module>\n File \"smap\\job.py\", line 82, in run2\n db.SmapDataPoint.insert_many(islice(dict_data_gen, p[0], p[1])).execute()\n File \"D:\\Coding\\Python27\\lib\\site-packages\\peewee.py\", line 2149, in execute\n return last_id\nUnboundLocalError: local variable 'last_id' referenced before assignment\n```\n",
"Pushed 46b9e4a850d3929644ca4312d0b7807baad99276 which should fix the unbound local error. Do you mind trying that out and updating the ticket? Sorry for the inconvenience.\n",
"Yes, that fixes the unbound error :)\n",
"Does it fix the other error as well when running with MySQL?\n",
"I just wrote a little test script and ran it against sqlite and mysql without issue:\n\n``` python\n#!/usr/bin/env python\n\nimport random\n\nfrom peewee import *\n\ndb = SqliteDatabase('test.db')\n# or db = MySQLDatabase('peewee_test')\n\nclass Value(Model):\n number = FloatField()\n\n class Meta:\n database = db\n\n\nValue.drop_table(True)\nValue.create_table()\n\nnumbers = [\n random.random() for i in range(1000*1000)]\n\n# Bulk insert in groups of 500.\nchunk_size = 500\nfor i in range(0, len(numbers), chunk_size):\n vals = [{'number': j} for j in numbers[i:i+chunk_size]]\n Value.insert_many(vals).execute()\n\nprint 'Inserted %s rows.' % Value.select().count()\n```\n",
"I reproduced by adjusting your script thus:\n\n```\nimport random\nfrom itertools import islice\nfrom peewee import *\n\n#db = SqliteDatabase('test.db')\n# or db = MySQLDatabase('peewee_test')\n\n\n#db = SqliteDatabase(\"e:/temp/peewee.db\")\ndb = MySQLDatabase( <my ec2 RDS credentials> )\n\n\nclass Value_dbg(Model):\n id = PrimaryKeyField()\n number = FloatField()\n number2 = FloatField()\n number3 = FloatField()\n\n class Meta:\n database = db\n\n\nValue_dbg.drop_table(True)\nValue_dbg.create_table()\n\nbig_len = 150000\nnumbers = ((random.random(), random.random(), random.random()) for i in xrange(big_len))\n\nkeys=('number', 'number2', 'number3')\n\n# Bulk insert in groups of 500.\nchunk_size = 10000\nfor i in range(0, big_len, chunk_size):\n print '{}...{}'.format(i, i+chunk_size)\n\n vals = (dict(zip(keys, row)) for row in islice(numbers,i,i+chunk_size))\n\n Value_dbg.insert_many(vals).execute()\n\nprint 'Inserted %s rows.' % Value_dbg.select().count()\n```\n\n```\n0...10000\n10000...20000\n20000...30000\n30000...40000\n40000...50000\n50000...60000\nTraceback (most recent call last):\n File \"smap\\job_test.py\", line 46, in <module>\n Value_dbg.insert_many(vals).execute()\n File \"D:\\Coding\\Python27\\lib\\site-packages\\peewee.py\", line 2151, in execute\n return self.database.last_insert_id(self._execute(), self.model_class)\n File \"D:\\Coding\\Python27\\lib\\site-packages\\peewee.py\", line 1753, in _execute\n return self.database.execute_sql(sql, params, self.require_commit)\n File \"D:\\Coding\\Python27\\lib\\site-packages\\peewee.py\", line 2316, in execute_s\nql\n self.commit()\n File \"D:\\Coding\\Python27\\lib\\site-packages\\peewee.py\", line 2187, in __exit__\n reraise(new_type, new_type(*exc_value.args), traceback)\n File \"D:\\Coding\\Python27\\lib\\site-packages\\peewee.py\", line 2307, in execute_s\nql\n cursor.execute(sql, params or ())\n File \"D:\\Coding\\Python27\\lib\\site-packages\\MySQLdb\\cursors.py\", line 174, in e\nxecute\n self.errorhandler(self, exc, value)\n File \"D:\\Coding\\Python27\\lib\\site-packages\\MySQLdb\\connections.py\", line 36, i\nn defaulterrorhandler\n raise errorclass, errorvalue\npeewee.ProgrammingError: (1064, \"You have an error in your SQL syntax; check the\n manual that corresponds to your MySQL server version for the right syntax to us\ne near '' at line 1\")\n```\n",
"You've got a bug in your code. `numbers` is a generator, but you're calling `itertools.islice` on it, causing it to be exhausted.\n\nSo the first iteration, you are grabbing the first 10K numbers from the generator...that's fine. The second iteration, though, you are actually advancing the generator by 20K. The third iteration takes 30K off the generator, etc. If you modify this line then it works as you'd expect:\n\n``` python\n# ORIGINAL\nvals = (dict(zip(keys, row)) for row in islice(numbers,i,i+chunk_size))\n\n# NEW\nvals = (dict(zip(keys, row)) for row in islice(numbers, 0, chunk_size))\n```\n",
"ah, sorry! first time using itertools/generators.\n\nThanks for quick responses.\n"
] | 2014-04-06T18:01:25 | 2014-04-07T15:52:40 | 2014-04-07T15:52:40 | NONE | null | I have a large number of rows that I want to add (~150000) to a MySQL db
The rows have 9 float fields and a PrimaryKeyField.
If I try to add them all in one go:
```
db.SmapDataPoint.insert_many(dict_data_gen).execute()
```
The database 'goes away' (peewee.OperationalError: (2006, 'MySQL server has gone away')).
If I split up the data and apply several insert_manys then I receive a ProgrammingError
```
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "smap\job.py", line 80, in run2
db.SmapDataPoint.insert_many(islice(dict_data_gen, p[0], p[1])).execute()
File "D:\Coding\Python27\lib\site-packages\peewee.py", line 2150, in execute
return self.database.last_insert_id(self._execute(), self.model_class)
File "D:\Coding\Python27\lib\site-packages\peewee.py", line 1753, in _execute
return self.database.execute_sql(sql, params, self.require_commit)
File "D:\Coding\Python27\lib\site-packages\peewee.py", line 2315, in execute_s
ql
self.commit()
File "D:\Coding\Python27\lib\site-packages\peewee.py", line 2186, in __exit__
reraise(new_type, new_type(*exc_value.args), traceback)
File "D:\Coding\Python27\lib\site-packages\peewee.py", line 2306, in execute_s
ql
cursor.execute(sql, params or ())
File "D:\Coding\Python27\lib\site-packages\MySQLdb\cursors.py", line 174, in e
xecute
self.errorhandler(self, exc, value)
File "D:\Coding\Python27\lib\site-packages\MySQLdb\connections.py", line 36, i
n defaulterrorhandler
raise errorclass, errorvalue
peewee.ProgrammingError: (1064, "You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version for the right syntax to us
e near '' at line 1")
```
The point at which it occurs is dependent on the chunk size and not upon the actual data. ie if I change the chunk size the error will occur on the 'n'th execute() but the insert_many chunk will not necessarily contain the same data as on a previous attempt with a different chunk size.
The failure is consistent if the chunk size remains constant.
```
def save_to_db(filename)
data = <list of tuples generated from data in filename> # tuples are all same length
dict_data_gen = (dict(zip(dbfields, row)) for row in data)
db.connect()
print 'updating db...'
num_rows = len(data)
slice_length = 22000
slice_points = list()
for i in xrange(0, num_rows, slice_length):
slice_points.append((i, min(i + slice_length, num_rows)))
for p in slice_points:
print "insert_many for region {}:{}".format(p[0], p[1])
#db.DataPoint.insert_many(islice(dict_data_gen, p[0], p[1])).execute()
db.DataPoint.insert_many(dict_data_gen).execute()
print 'Job {} complete!'.format(filename)
```
here is my model
```
class DataPoint(BaseModel):
id = PrimaryKeyField()
latitude = FloatField(db_column='Latitude')
longitude = FloatField(db_column='Longitude')
#datetime = DateTimeField()
bare_soil_roughness_retrieved = FloatField()
radar_vegetation_index = FloatField()
soil_moisture_snapshot = FloatField()
soil_moisture_snapshot_dvz = FloatField(db_column='soil_moisture_snapshot_DVZ')
soil_moisture_snapshot_shi = FloatField()
soil_moisture_time_series = FloatField()
soil_moisture_time_series_kvz = FloatField(db_column='soil_moisture_time_series_KVZ')
```
I appreciate any help you can give on this - it may be down to a configuration issue on my side?
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/335/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/335/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/334 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/334/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/334/comments | https://api.github.com/repos/coleifer/peewee/issues/334/events | https://github.com/coleifer/peewee/issues/334 | 30,938,447 | MDU6SXNzdWUzMDkzODQ0Nw== | 334 | Interface erors with PostgreSQL on Ubuntu | {
"login": "kramer65",
"id": 596581,
"node_id": "MDQ6VXNlcjU5NjU4MQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/596581?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/kramer65",
"html_url": "https://github.com/kramer65",
"followers_url": "https://api.github.com/users/kramer65/followers",
"following_url": "https://api.github.com/users/kramer65/following{/other_user}",
"gists_url": "https://api.github.com/users/kramer65/gists{/gist_id}",
"starred_url": "https://api.github.com/users/kramer65/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/kramer65/subscriptions",
"organizations_url": "https://api.github.com/users/kramer65/orgs",
"repos_url": "https://api.github.com/users/kramer65/repos",
"events_url": "https://api.github.com/users/kramer65/events{/privacy}",
"received_events_url": "https://api.github.com/users/kramer65/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I have no idea... Is your application multi-threaded?\n",
"Well, I indeed run one function using APScheduler while also calling it manually sometimes. I guess this could cause the function to be called twice simultaneously. Since you asked specifically about it, I guess this is a problem?\n",
"Interesting -- I'm guessing this is the problem. How are you instantiating your database? You might try passing `threadlocals=True`.\n",
"Can you try instantiating your database with `threadlocals=True` and getting back to me with whether that works?\n",
"I'm going to close this for now, please leave a comment if you have any updates.\n"
] | 2014-04-06T14:25:20 | 2014-04-10T14:28:02 | 2014-04-10T14:28:02 | NONE | null | I'm using (and loving) Peewee in a project with PostgreSQL 9.3 and since I want to use the JSON field in Postgres I use the Peewee Playhouse package. I now "sometimes" hit upon Interface errors. Sometimes in this case means that I run the same function every second (using APScheduler), but about 5% of the time I get errors. I so far have gotten the following two errors, of which the first errors happens most:
```
File "/home/kramer65/xs/app/order_management.py", line 210, in checkExpiration
if len(list(pendingOrders_q)) > 0:
File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 1988, in __iter__
return iter(self.execute())
File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 1981, in execute
self._qr = ResultWrapper(model_class, self._execute(), query_meta)
File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 1698, in _execute
return self.database.execute_sql(sql, params, self.require_commit)
File "/usr/local/lib/python2.7/dist-packages/playhouse/postgres_ext.py", line 251, in execute_sql
self.commit()
File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 2104, in __exit__
reraise(new_type, new_type(*exc_value.args), traceback)
File "/usr/local/lib/python2.7/dist-packages/playhouse/postgres_ext.py", line 242, in execute_sql
cursor = self.get_cursor()
File "/usr/local/lib/python2.7/dist-packages/playhouse/postgres_ext.py", line 229, in get_cursor
return self.get_conn().cursor(name=name)
InterfaceError: connection already closed
```
And the second error:
```
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/apscheduler/scheduler.py", line 512, in _run_job
retval = job.func(*job.args, **job.kwargs)
File "/home/kramer65/xs/app/order_management.py", line 207, in checkForDetails
for order in paidInOrders_q:
File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 1411, in next
obj = self.iterate()
File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 1392, in iterate
row = self.cursor.fetchone()
InterfaceError: cursor already closed
```
Does anybody know whats wrong here?
I know that using len(list(q)) to do a count on the results from a query isn't very nice, but it used to work well for me until I hit this error. Since it succeeds most of the time, I don't really know where to look for the error. Is it in Postgres, in Peewee, in psycopg2, or in my own code?
All tips are welcome!
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/334/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/334/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/333 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/333/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/333/comments | https://api.github.com/repos/coleifer/peewee/issues/333/events | https://github.com/coleifer/peewee/issues/333 | 30,778,696 | MDU6SXNzdWUzMDc3ODY5Ng== | 333 | PostgreSQL cast array to list | {
"login": "mmqqg",
"id": 6891135,
"node_id": "MDQ6VXNlcjY4OTExMzU=",
"avatar_url": "https://avatars.githubusercontent.com/u/6891135?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/mmqqg",
"html_url": "https://github.com/mmqqg",
"followers_url": "https://api.github.com/users/mmqqg/followers",
"following_url": "https://api.github.com/users/mmqqg/following{/other_user}",
"gists_url": "https://api.github.com/users/mmqqg/gists{/gist_id}",
"starred_url": "https://api.github.com/users/mmqqg/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/mmqqg/subscriptions",
"organizations_url": "https://api.github.com/users/mmqqg/orgs",
"repos_url": "https://api.github.com/users/mmqqg/repos",
"events_url": "https://api.github.com/users/mmqqg/events{/privacy}",
"received_events_url": "https://api.github.com/users/mmqqg/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I'm confused...isn't it already a list?\n\n``` python\nIn [1]: from playhouse.tests_postgres import *\n\nIn [2]: am = Array\nArrayField ArrayModel \n\nIn [2]: am = ArrayModel(tags=['foo', 'bar', 'baz'])\n\nIn [3]: for tag in am.tags:\n ...: print tag\n ...: \nfoo\nbar\nbaz\n```\n",
"@mmqqg -- can you please respond with more details?\n",
"It's my fault, sorry. I check the db and find \n\n```\ntags | character varying | not null\n```\n\nIt should be\n\n```\ntags | character varying(255)[] | not null\n```\n\nMaybe I modify some peewee code that caused \"Model.create_table()\" didn't work well.\n\nThanks a lot!\n"
] | 2014-04-03T14:15:43 | 2014-04-04T05:20:54 | 2014-04-04T05:20:54 | NONE | null | ```
post = BlogPost(content='awesome', tags=['foo', 'bar', 'baz'])
```
Is there a way to use
``` python
for tag in post.tags:
print(tag)
```
?
http://initd.org/psycopg/docs/extensions.html#psycopg2.extensions.new_array_type
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/333/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/333/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/332 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/332/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/332/comments | https://api.github.com/repos/coleifer/peewee/issues/332/events | https://github.com/coleifer/peewee/issues/332 | 30,524,271 | MDU6SXNzdWUzMDUyNDI3MQ== | 332 | feature request: add support for printing SQL statments | {
"login": "intrixs",
"id": 2215059,
"node_id": "MDQ6VXNlcjIyMTUwNTk=",
"avatar_url": "https://avatars.githubusercontent.com/u/2215059?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/intrixs",
"html_url": "https://github.com/intrixs",
"followers_url": "https://api.github.com/users/intrixs/followers",
"following_url": "https://api.github.com/users/intrixs/following{/other_user}",
"gists_url": "https://api.github.com/users/intrixs/gists{/gist_id}",
"starred_url": "https://api.github.com/users/intrixs/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/intrixs/subscriptions",
"organizations_url": "https://api.github.com/users/intrixs/orgs",
"repos_url": "https://api.github.com/users/intrixs/repos",
"events_url": "https://api.github.com/users/intrixs/events{/privacy}",
"received_events_url": "https://api.github.com/users/intrixs/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Did some research, and found out that maybe I can use 'logging' module to achieve part of 'sqlall' functionalities. \n\nhttp://stackoverflow.com/questions/6350411/how-to-retrieve-executed-sql-code-from-sqlalchemy\n"
] | 2014-03-31T15:55:23 | 2014-04-02T12:10:49 | 2014-04-02T12:10:49 | NONE | null | So in Django, you have the 'sqlall' command that allows you to do the following:
##### Prints the CREATE TABLE, custom SQL and CREATE INDEX SQL statments for the given model module name(s).
It would be nice if peewee adds support for displaying database-specific SQL statements of a model or query.
Thanks.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/332/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/332/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/331 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/331/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/331/comments | https://api.github.com/repos/coleifer/peewee/issues/331/events | https://github.com/coleifer/peewee/pull/331 | 30,488,382 | MDExOlB1bGxSZXF1ZXN0MTQxNjIzODk= | 331 | adapt_array unicode | {
"login": "mmqqg",
"id": 6891135,
"node_id": "MDQ6VXNlcjY4OTExMzU=",
"avatar_url": "https://avatars.githubusercontent.com/u/6891135?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/mmqqg",
"html_url": "https://github.com/mmqqg",
"followers_url": "https://api.github.com/users/mmqqg/followers",
"following_url": "https://api.github.com/users/mmqqg/following{/other_user}",
"gists_url": "https://api.github.com/users/mmqqg/gists{/gist_id}",
"starred_url": "https://api.github.com/users/mmqqg/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/mmqqg/subscriptions",
"organizations_url": "https://api.github.com/users/mmqqg/orgs",
"repos_url": "https://api.github.com/users/mmqqg/repos",
"events_url": "https://api.github.com/users/mmqqg/events{/privacy}",
"received_events_url": "https://api.github.com/users/mmqqg/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Hey, I saw your comment on #peewee but was away from the computer. I'll take a look though it appears there's an issue with Py3K.\n"
] | 2014-03-31T06:47:41 | 2014-06-17T01:45:48 | 2014-04-02T13:48:41 | NONE | null | modify adapt_array and add some unicode test
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/331/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/331/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/331",
"html_url": "https://github.com/coleifer/peewee/pull/331",
"diff_url": "https://github.com/coleifer/peewee/pull/331.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/331.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/330 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/330/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/330/comments | https://api.github.com/repos/coleifer/peewee/issues/330/events | https://github.com/coleifer/peewee/issues/330 | 30,424,782 | MDU6SXNzdWUzMDQyNDc4Mg== | 330 | Check constraint not working with .create_table() | {
"login": "bartkl",
"id": 2497867,
"node_id": "MDQ6VXNlcjI0OTc4Njc=",
"avatar_url": "https://avatars.githubusercontent.com/u/2497867?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/bartkl",
"html_url": "https://github.com/bartkl",
"followers_url": "https://api.github.com/users/bartkl/followers",
"following_url": "https://api.github.com/users/bartkl/following{/other_user}",
"gists_url": "https://api.github.com/users/bartkl/gists{/gist_id}",
"starred_url": "https://api.github.com/users/bartkl/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/bartkl/subscriptions",
"organizations_url": "https://api.github.com/users/bartkl/orgs",
"repos_url": "https://api.github.com/users/bartkl/repos",
"events_url": "https://api.github.com/users/bartkl/events{/privacy}",
"received_events_url": "https://api.github.com/users/bartkl/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I looked into this matter some more, and apparently it is a MySQL issue:\n\n> The CHECK clause is parsed but ignored by all storage engines.\n\n[http://dev.mysql.com/doc/refman/5.5/en/create-table.html](MySQL docs)\n(Version 5.5 corresponds with the one I use, but note that the latest documentation (5.7) also documents this.)\n\nSo, I'm sorry for wasting your time, this issue can be closed.\n"
] | 2014-03-28T21:38:22 | 2014-03-29T00:59:26 | 2014-03-29T00:59:26 | NONE | null | Hi,
I'm trying to define a simple `CHECK` constraint on a table, and to create it with `.create_all()`. It can't get it to work. I get no errors, but when I look at the table definition of the created table, it has no constraints defined.
My models file:
``` python
from peewee import *
db = MySQLDatabase('my_db_name, host='127.0.0.1', port=3306, user='my_user', password='my_secret')
class BaseModel(Model):
class Meta:
database = db
class Film(BaseModel):
title = CharField()
year = IntegerField(constraints=[Check('year > 0')])
```
The table definition according to `SHOW CREATE TABLE film`:
``` mysql
CREATE TABLE `film` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(255) NOT NULL,
`year` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
```
I have browsed through peewee's source code, and I get the feeling any constraints other than the `FOREIGN KEY` aren't even touched by the `.create_table()` method. Relevant part quoted from its definition:
``` python
for field in meta.get_fields():
columns.append(self.field_definition(field))
if isinstance(field, ForeignKeyField) and not field.deferred:
constraints.append(self.foreign_key_constraint(field))
```
Be warned, I'm a relative newbie, so I might be foolishly mistaken.
Thank you,
Bart
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/330/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/330/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/329 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/329/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/329/comments | https://api.github.com/repos/coleifer/peewee/issues/329/events | https://github.com/coleifer/peewee/pull/329 | 30,339,876 | MDExOlB1bGxSZXF1ZXN0MTQwODA5NzY= | 329 | Fixed access to uninitialized variable in pwiz | {
"login": "wojtek",
"id": 31813,
"node_id": "MDQ6VXNlcjMxODEz",
"avatar_url": "https://avatars.githubusercontent.com/u/31813?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/wojtek",
"html_url": "https://github.com/wojtek",
"followers_url": "https://api.github.com/users/wojtek/followers",
"following_url": "https://api.github.com/users/wojtek/following{/other_user}",
"gists_url": "https://api.github.com/users/wojtek/gists{/gist_id}",
"starred_url": "https://api.github.com/users/wojtek/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/wojtek/subscriptions",
"organizations_url": "https://api.github.com/users/wojtek/orgs",
"repos_url": "https://api.github.com/users/wojtek/repos",
"events_url": "https://api.github.com/users/wojtek/events{/privacy}",
"received_events_url": "https://api.github.com/users/wojtek/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Isn't this the same fix as #328 ?\n",
"Oh yeah, I actually fixed it locally a couple of days ago before #328 existed, my bad.\n"
] | 2014-03-27T20:39:02 | 2014-07-06T01:50:04 | 2014-03-27T20:56:35 | NONE | null | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/329/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/329/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/329",
"html_url": "https://github.com/coleifer/peewee/pull/329",
"diff_url": "https://github.com/coleifer/peewee/pull/329.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/329.patch",
"merged_at": null
} |
|
https://api.github.com/repos/coleifer/peewee/issues/328 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/328/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/328/comments | https://api.github.com/repos/coleifer/peewee/issues/328/events | https://github.com/coleifer/peewee/pull/328 | 30,144,947 | MDExOlB1bGxSZXF1ZXN0MTM5NjUxMDY= | 328 | Pwiz fails on MySQL databases | {
"login": "johnhuffsmith",
"id": 483024,
"node_id": "MDQ6VXNlcjQ4MzAyNA==",
"avatar_url": "https://avatars.githubusercontent.com/u/483024?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/johnhuffsmith",
"html_url": "https://github.com/johnhuffsmith",
"followers_url": "https://api.github.com/users/johnhuffsmith/followers",
"following_url": "https://api.github.com/users/johnhuffsmith/following{/other_user}",
"gists_url": "https://api.github.com/users/johnhuffsmith/gists{/gist_id}",
"starred_url": "https://api.github.com/users/johnhuffsmith/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/johnhuffsmith/subscriptions",
"organizations_url": "https://api.github.com/users/johnhuffsmith/orgs",
"repos_url": "https://api.github.com/users/johnhuffsmith/repos",
"events_url": "https://api.github.com/users/johnhuffsmith/events{/privacy}",
"received_events_url": "https://api.github.com/users/johnhuffsmith/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Thanks!\n"
] | 2014-03-25T17:25:52 | 2014-06-28T04:17:46 | 2014-03-27T21:08:29 | NONE | null | On line 262 it's attempting to set a value on kwargs before kwargs is initialized. I've just move the kwargs initialization to be before this operation.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/328/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/328/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/328",
"html_url": "https://github.com/coleifer/peewee/pull/328",
"diff_url": "https://github.com/coleifer/peewee/pull/328.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/328.patch",
"merged_at": "2014-03-27T21:08:29"
} |
https://api.github.com/repos/coleifer/peewee/issues/327 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/327/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/327/comments | https://api.github.com/repos/coleifer/peewee/issues/327/events | https://github.com/coleifer/peewee/issues/327 | 29,976,913 | MDU6SXNzdWUyOTk3NjkxMw== | 327 | two first result in double | {
"login": "dkmatt0",
"id": 5724752,
"node_id": "MDQ6VXNlcjU3MjQ3NTI=",
"avatar_url": "https://avatars.githubusercontent.com/u/5724752?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/dkmatt0",
"html_url": "https://github.com/dkmatt0",
"followers_url": "https://api.github.com/users/dkmatt0/followers",
"following_url": "https://api.github.com/users/dkmatt0/following{/other_user}",
"gists_url": "https://api.github.com/users/dkmatt0/gists{/gist_id}",
"starred_url": "https://api.github.com/users/dkmatt0/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/dkmatt0/subscriptions",
"organizations_url": "https://api.github.com/users/dkmatt0/orgs",
"repos_url": "https://api.github.com/users/dkmatt0/repos",
"events_url": "https://api.github.com/users/dkmatt0/events{/privacy}",
"received_events_url": "https://api.github.com/users/dkmatt0/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"If I add \n\n```\n[s for s in select]\n```\n\nbetween select and for, like this :\n\n```\nselect = Test.select()\n[s for s in select]\nfor s in select:\n print(s.id)\n Test.update(name=0).where(Test.id==s.id).execute()\n```\n\nI haven't this problem...\n\nI don't understand why ?!\n",
"@dkmatt0 \n\nPEP-XXX (I don't remember which one) or just sane idea:\nYou should not modify object while you iterate over it. And you should be even more careful with lazy-objects.\n\nIs this bug, or not, the better way to perform this logic (as I think):\n\n_(pseudocode)_\n\n```\nwith transaction\n id_list = list(select(ids))\n for every id in id_list\n perform operation and save\n```\n\nSomething similar you do in your example with `[s for s in select]`: you consume laziness and perform operations related to static dataset.\n\nBut, again, its my IMHO.\n",
"See: \n- https://github.com/coleifer/peewee/issues/12#issuecomment-5614404\n- https://github.com/coleifer/peewee/issues/81\n",
"OK perfect ! Thank you :+1: \n"
] | 2014-03-23T01:11:28 | 2014-10-01T20:16:47 | 2014-03-25T17:13:22 | NONE | null | Hi, (I'm french, sorry for poor english...)
I make this code for testing :
```
from peewee import *
import datetime
class Test(Model):
name = TextField(null=True)
Test.create_table()
Test.create(name='a')
Test.create(name='b')
Test.create(name='c')
Test.create(name='d')
Test.create(name='e')
Test.create(name='f')
select = Test.select()
for s in select:
print(s.id)
Test.update(name=0).where(Test.id==s.id).execute()
```
and I get this :
```
1
2
1
2
3
4
5
6
```
You can see "id" 1 and 2 appear two times !
If i change last line by :
```
print(Test.update(name=0).where(Test.id==s.id))
```
I haven't this problem (but my db is not updated)
It's normal or it's a bug ?
Thank
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/327/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/327/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/326 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/326/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/326/comments | https://api.github.com/repos/coleifer/peewee/issues/326/events | https://github.com/coleifer/peewee/issues/326 | 29,934,782 | MDU6SXNzdWUyOTkzNDc4Mg== | 326 | table_alias | {
"login": "stanegit",
"id": 3876591,
"node_id": "MDQ6VXNlcjM4NzY1OTE=",
"avatar_url": "https://avatars.githubusercontent.com/u/3876591?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/stanegit",
"html_url": "https://github.com/stanegit",
"followers_url": "https://api.github.com/users/stanegit/followers",
"following_url": "https://api.github.com/users/stanegit/following{/other_user}",
"gists_url": "https://api.github.com/users/stanegit/gists{/gist_id}",
"starred_url": "https://api.github.com/users/stanegit/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/stanegit/subscriptions",
"organizations_url": "https://api.github.com/users/stanegit/orgs",
"repos_url": "https://api.github.com/users/stanegit/repos",
"events_url": "https://api.github.com/users/stanegit/events{/privacy}",
"received_events_url": "https://api.github.com/users/stanegit/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Can you give me a set of models and a query that reproduces this error?\n"
] | 2014-03-21T20:24:50 | 2014-04-01T14:15:11 | 2014-04-01T14:15:11 | NONE | null | Hi , I know I asked for this and it is working but trying to get sql server working with peewee (pyodbc) in this part of code in peewee
```
def _max_alias(self, alias_map):
max_alias = 0
if alias_map:
for alias in alias_map.values():
alias_number = int(alias.lstrip('t'))
if alias_number > max_alias:
max_alias = alias_number
return max_alias + 1
```
alias_number = int(alias.lstrip('t')) this part of code "assume" that alias for table is
like 't1'... etc, but if I defined table_alias this is were you get exception
so I kind of fix it (for what I understand :) ) with this
def _max_alias(self, alias_map):
max_alias = 0
```
if alias_map :
# for alias in alias_map.values():
# fix
for key,alias in alias_map.iteritems():
if len(key._meta.table_alias) < 1:
alias_number = int(alias.lstrip('t'))
if alias_number > max_alias:
max_alias = alias_number
return max_alias + 1
```
I hope this helps
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/326/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/326/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/325 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/325/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/325/comments | https://api.github.com/repos/coleifer/peewee/issues/325/events | https://github.com/coleifer/peewee/issues/325 | 29,517,663 | MDU6SXNzdWUyOTUxNzY2Mw== | 325 | Joining 2 tables with naive is messing up pks | {
"login": "masell",
"id": 4653351,
"node_id": "MDQ6VXNlcjQ2NTMzNTE=",
"avatar_url": "https://avatars.githubusercontent.com/u/4653351?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/masell",
"html_url": "https://github.com/masell",
"followers_url": "https://api.github.com/users/masell/followers",
"following_url": "https://api.github.com/users/masell/following{/other_user}",
"gists_url": "https://api.github.com/users/masell/gists{/gist_id}",
"starred_url": "https://api.github.com/users/masell/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/masell/subscriptions",
"organizations_url": "https://api.github.com/users/masell/orgs",
"repos_url": "https://api.github.com/users/masell/repos",
"events_url": "https://api.github.com/users/masell/events{/privacy}",
"received_events_url": "https://api.github.com/users/masell/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"What do you want to happen, I guess? When you use `.naive()` peewee simply `setattr`s named values from the result column onto the model instance. If multiple columns are named `id` then the last one wins.\n\nTo circumvent that you could:\n\n``` python\nres = (Model1\n .select(Model1.id, Model1.a, Model2.id.alias('model2_id'), Model2.b)\n .join(Model2)\n .naive())\n```\n\nThe other issue is that model1 may have many model2's. A better plan would be to use prefetch:\n\n``` python\n\nres = prefetch(Model1, Model2)\nfor a in res:\n for b in a.model2_set_prefetch:\n ....\n```\n",
"I dont know, i think i may have missunderstood the docs.\n"
] | 2014-03-16T14:29:39 | 2014-03-18T16:25:42 | 2014-03-18T16:25:42 | NONE | null | Should i not have only 1 instance of Model1 when calling with naive?
The ids are from Model2, but on Model1's instances.
I guess it's because the select query does not use any prefixing when selecting from multiple tables.
from peewee import SqliteDatabase, Model, PrimaryKeyField, CharField, \
IntegerField, ForeignKeyField
from playhouse.test_utils import test_database
test_db = SqliteDatabase(':memory:')
class Model1(Model):
a = CharField()
class Model2(Model):
b = CharField()
m1 = ForeignKeyField(Model1)
if **name** == '**main**':
with test_database(test_db, (Model1, Model2)):
Model1.\
create(id=1, a="A1").\
create(id=2, a="A2")
```
Model2.\
create(id=3, b="example2", m1=1).\
create(id=4, b="example3", m1=1).\
create(id=5, b="example4", m1=1)
res = (Model1
.select(Model1, Model2)
.join(Model2)
.naive())
print res.sql
for a in res:
print a, a.id, a.a
```
output>
<bound method SelectQuery.sql of <class '__main__.Model1'> SELECT t1."id", t1."a", t2."id", t2."b", t2."m1_id" FROM "model1" AS t1 INNER JOIN "model2" AS t2 ON (t1."id" = t2."m1_id") []>
<**main**.Model1 object at 0x1f61810> 3 A1
<**main**.Model1 object at 0x1f61d90> 4 A1
<**main**.Model1 object at 0x1f61a50> 5 A1
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/325/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/325/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/324 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/324/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/324/comments | https://api.github.com/repos/coleifer/peewee/issues/324/events | https://github.com/coleifer/peewee/issues/324 | 29,351,753 | MDU6SXNzdWUyOTM1MTc1Mw== | 324 | Prefetch issue | {
"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 in e9a38d24ba0ef75b26728fc29cd8909fbda4e3f7 by manually selecting only the relevant PK when generating the subquery.\n"
] | 2014-03-13T13:55:08 | 2014-03-13T14:09:23 | 2014-03-13T14:09:23 | OWNER | null | Via SO: http://stackoverflow.com/questions/22368917/prefetch-db-rows-using-the-python-peewee-orm
---
I want to use the python peewee prefetch functionality.
I have three tables: A, B, and C.
B has a foreign key in its table to A, and table C has a foreign key to B.
I want to select all the rows in B, while also prefetching the rows in C that belong to those in B. However, I also want to grab the rows in A that B belongs to so I don't launch new queries every time I try accessing that property from the results.
This is the code I have currently:
``` python
b_query = B.select(B, A).join(A).where(B.user_id == user_id)
c_query = C.select()
prefetch(b_query, c_query)
```
However, this code fails with the error: OperationalError: (1241, 'Operand should contain 1 column(s)')
When I change the code to this it works:
``` python
b_query = B.select().join(A).where(B.user_id == user_id)
c_query = C.select()
```
But, since I am no longer selecting A in b_query, I believe every time I access b.a it will launch a new query, which I am trying to avoid. Any suggestions?
EDIT:
I did some more digging into this, and it seems that trying to do it the way I initially proposed might be impossible. The successful mechanism results in this query as one of the two queries resulting from the prefetch:
```
SELECT C.* from C WHERE C.B_id IN (SELECT B.id FROM B WHERE B.user_id == <user_id>)
```
Trying to add A into the select for b_query results in the following query:
```
SELECT C.* from C WHERE C.B_id IN (SELECT B.*, A.* WHERE B.user_id == <user_id>)
```
Obviously this won't work.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/324/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/324/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/323 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/323/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/323/comments | https://api.github.com/repos/coleifer/peewee/issues/323/events | https://github.com/coleifer/peewee/issues/323 | 29,344,231 | MDU6SXNzdWUyOTM0NDIzMQ== | 323 | entering datetime with timezone results in illegal SQL INSERT | {
"login": "shikasta-net",
"id": 1693155,
"node_id": "MDQ6VXNlcjE2OTMxNTU=",
"avatar_url": "https://avatars.githubusercontent.com/u/1693155?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/shikasta-net",
"html_url": "https://github.com/shikasta-net",
"followers_url": "https://api.github.com/users/shikasta-net/followers",
"following_url": "https://api.github.com/users/shikasta-net/following{/other_user}",
"gists_url": "https://api.github.com/users/shikasta-net/gists{/gist_id}",
"starred_url": "https://api.github.com/users/shikasta-net/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/shikasta-net/subscriptions",
"organizations_url": "https://api.github.com/users/shikasta-net/orgs",
"repos_url": "https://api.github.com/users/shikasta-net/repos",
"events_url": "https://api.github.com/users/shikasta-net/events{/privacy}",
"received_events_url": "https://api.github.com/users/shikasta-net/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Peewee is not converting the date to a string when it sends it to MySQL. Instead, the MySQL adapter is probably doing the conversion for you. Are you using different versions of MySQLdb or pymysql between your two machines?\n\nIf you'd like to implement this more cleanly, you can subclass `DateTimeField` and implement one that removes the timezone before sending it to the database:\n\n``` python\nclass NoTZDateTimeField(DateTimeField):\n def db_value(self, value):\n return value.replace(tzinfo=None) # I think this should do it\n```\n\nThen you'd replace your fields with the NoTZDateTimeField.\n\nPlease give that a shot and let me know!\n",
"My apology for not having dug far enough through the dependencies, I assumed the datetime conversion was done when it was cast to string. Seems you were right, version 1.2.3 MySQLdb works but 1.2.5 does not (it seems the repository version for linux is behind that of PyPI). I can't find another work around, but your suggested fix is better than mine. \n"
] | 2014-03-13T11:51:59 | 2014-03-13T17:44:44 | 2014-03-13T17:44:44 | NONE | null | When attempting to INSERT key values pairs, where the value is an instance datetime.datetime(2014, 1, 12, 14, 0, tzinfo=<UTC>), peewee converts these (via datetime's default to string encoding) to 2014-01-12 15:00:00+00:00 which is not a valid format for MySQL. The timezone information should be ignored as MySQL only accepts 0000-00-00 00:00:00, or variants, without +00:00 at the end. Oddly, this problem only occurs when the script is run on a Windows Server 2012. The problem does not exist for Linux despite both using the same datetime to string conversion.
I think this can be fixed by giving all TimeField classes a `db_value` function which does the inverse of the existing `format_date_time` function, overriding the default datetime to string conversion.
The following monkey patch works in my case, but I think this would be worth implementing properly.
```
def format_date_time(value, formats, post_process=None):
post_process = post_process or (lambda x: x)
for fmt in formats:
try:
if isinstance(value, datetime):
return value.strftime(fmt)
else :
return post_process(datetime.datetime.strptime(value, fmt))
except ValueError:
pass
return value
class DateTimeField(peewee._BaseFormattedField):
db_field = 'datetime'
formats = [
'%Y-%m-%d %H:%M:%S.%f',
'%Y-%m-%d %H:%M:%S',
'%Y-%m-%d',
]
def python_value(self, value):
if value and isinstance(value, basestring):
return format_date_time(value, self.formats)
return value
def db_value(self, value):
if value and isinstance(value, datetime):
return format_date_time(value, self.formats)
return value
year = property(peewee._date_part('year'))
month = property(peewee._date_part('month'))
day = property(peewee._date_part('day'))
hour = property(peewee._date_part('hour'))
minute = property(peewee._date_part('minute'))
second = property(peewee._date_part('second'))
peewee.format_date_time = format_date_time
peewee.DateTimeField = DateTimeField
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/323/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/323/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/322 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/322/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/322/comments | https://api.github.com/repos/coleifer/peewee/issues/322/events | https://github.com/coleifer/peewee/issues/322 | 29,298,375 | MDU6SXNzdWUyOTI5ODM3NQ== | 322 | Suggestion: normalize keyword arguments when connecting to db | {
"login": "exaroth",
"id": 3927388,
"node_id": "MDQ6VXNlcjM5MjczODg=",
"avatar_url": "https://avatars.githubusercontent.com/u/3927388?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/exaroth",
"html_url": "https://github.com/exaroth",
"followers_url": "https://api.github.com/users/exaroth/followers",
"following_url": "https://api.github.com/users/exaroth/following{/other_user}",
"gists_url": "https://api.github.com/users/exaroth/gists{/gist_id}",
"starred_url": "https://api.github.com/users/exaroth/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/exaroth/subscriptions",
"organizations_url": "https://api.github.com/users/exaroth/orgs",
"repos_url": "https://api.github.com/users/exaroth/repos",
"events_url": "https://api.github.com/users/exaroth/events{/privacy}",
"received_events_url": "https://api.github.com/users/exaroth/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2014-03-12T20:23:10 | 2014-03-13T13:24:54 | 2014-03-13T13:24:54 | NONE | null | I noticed that when passing password to MySQLDatabase you have to use passwd = "..." as keyword argument while in Postgres its password = "...". I think it would be good idea to normalize it, to make it easier for apps with database choice to connect.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/322/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/322/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/321 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/321/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/321/comments | https://api.github.com/repos/coleifer/peewee/issues/321/events | https://github.com/coleifer/peewee/issues/321 | 29,027,865 | MDU6SXNzdWUyOTAyNzg2NQ== | 321 | Model has no attribute insert_many | {
"login": "shikasta-net",
"id": 1693155,
"node_id": "MDQ6VXNlcjE2OTMxNTU=",
"avatar_url": "https://avatars.githubusercontent.com/u/1693155?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/shikasta-net",
"html_url": "https://github.com/shikasta-net",
"followers_url": "https://api.github.com/users/shikasta-net/followers",
"following_url": "https://api.github.com/users/shikasta-net/following{/other_user}",
"gists_url": "https://api.github.com/users/shikasta-net/gists{/gist_id}",
"starred_url": "https://api.github.com/users/shikasta-net/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/shikasta-net/subscriptions",
"organizations_url": "https://api.github.com/users/shikasta-net/orgs",
"repos_url": "https://api.github.com/users/shikasta-net/repos",
"events_url": "https://api.github.com/users/shikasta-net/events{/privacy}",
"received_events_url": "https://api.github.com/users/shikasta-net/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2014-03-08T19:12:38 | 2014-03-08T19:33:26 | 2014-03-08T19:33:26 | NONE | null | Version 2.2.1 available through pip, does not include `insert_many()` in its `Model` class. This does not agree with the documentation for the same version number.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/321/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/321/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/320 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/320/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/320/comments | https://api.github.com/repos/coleifer/peewee/issues/320/events | https://github.com/coleifer/peewee/issues/320 | 28,943,346 | MDU6SXNzdWUyODk0MzM0Ng== | 320 | Travis CI | {
"login": "bndr",
"id": 1145456,
"node_id": "MDQ6VXNlcjExNDU0NTY=",
"avatar_url": "https://avatars.githubusercontent.com/u/1145456?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/bndr",
"html_url": "https://github.com/bndr",
"followers_url": "https://api.github.com/users/bndr/followers",
"following_url": "https://api.github.com/users/bndr/following{/other_user}",
"gists_url": "https://api.github.com/users/bndr/gists{/gist_id}",
"starred_url": "https://api.github.com/users/bndr/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/bndr/subscriptions",
"organizations_url": "https://api.github.com/users/bndr/orgs",
"repos_url": "https://api.github.com/users/bndr/repos",
"events_url": "https://api.github.com/users/bndr/events{/privacy}",
"received_events_url": "https://api.github.com/users/bndr/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"+1\n",
"I absolutely hate their site and had removed travis-ci a while ago. Be happy to add it back, though.\n",
"It's back. It's like damn whack-a-mole trying to get these tests passing (all of which pass locally, of course). If you all can help debug these failures I'd always appreciate it! https://travis-ci.org/coleifer/peewee\n",
"Well that was fast. I was planning on debugging those tests this weekend, but it seems almost all of them are passing now. Good job! :)\n",
"All but this one test, getting very close. I had no idea there were so many py3k issues, so this was definitely a good suggestion.\n",
"[![Build Status](https://travis-ci.org/coleifer/peewee.png?branch=master)](https://travis-ci.org/coleifer/peewee)\n"
] | 2014-03-07T07:39:39 | 2014-03-08T00:02:11 | 2014-03-08T00:02:11 | CONTRIBUTOR | null | Hi!
I would like to suggest implementing Travis CI for automation of tests on pull requests. http://docs.travis-ci.com/
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/320/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/320/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/319 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/319/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/319/comments | https://api.github.com/repos/coleifer/peewee/issues/319/events | https://github.com/coleifer/peewee/issues/319 | 28,862,100 | MDU6SXNzdWUyODg2MjEwMA== | 319 | How to use order_by with alias field? | {
"login": "thibaultmeyer",
"id": 1005086,
"node_id": "MDQ6VXNlcjEwMDUwODY=",
"avatar_url": "https://avatars.githubusercontent.com/u/1005086?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/thibaultmeyer",
"html_url": "https://github.com/thibaultmeyer",
"followers_url": "https://api.github.com/users/thibaultmeyer/followers",
"following_url": "https://api.github.com/users/thibaultmeyer/following{/other_user}",
"gists_url": "https://api.github.com/users/thibaultmeyer/gists{/gist_id}",
"starred_url": "https://api.github.com/users/thibaultmeyer/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/thibaultmeyer/subscriptions",
"organizations_url": "https://api.github.com/users/thibaultmeyer/orgs",
"repos_url": "https://api.github.com/users/thibaultmeyer/repos",
"events_url": "https://api.github.com/users/thibaultmeyer/events{/privacy}",
"received_events_url": "https://api.github.com/users/thibaultmeyer/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"You have a couple options:\n\n``` python\n.order_by(SQL('date'))\n\n.order_by(fn.MIN(Transaction.date))\n```\n",
"oh thanks. I can use .desc() & .asc() too ?\n"
] | 2014-03-06T09:56:46 | 2014-03-06T21:11:12 | 2014-03-06T14:27:52 | NONE | null | Hello,
we have 2 issues with the order_by function when we use it with aliased field.
1. How to use ASC and DESC with aliased field ?
2. The SQL generated request :
``` python
lstTransaction = Transaction.select(Transaction.id, Transaction.vendor,
Transaction.amount, Transaction.client, fn.MIN(Transaction.date).alias("date")
.where(Transaction.vendor == 1).distinct().group_by(Transaction.client)
.order_by("date")
```
Output request:
``` sql
SELECT DISTINCT t1.`id`, t1.`vendor`, t1.`amount`, t1.`client`,
MIN(t1.`date`) AS date FROM `transaction` AS t1
GROUP BY t1.`matricule` ORDER BY 'date'
```
Rather than
``` sql
SELECT DISTINCT t1.`id`, t1.`vendor`, t1.`amount`, t1.`client`,
MIN(t1.`date`) AS date FROM `transaction` AS t1
GROUP BY t1.`matricule` ORDER BY `date`
```
In MySQL 5.5.35, the request results is bad ordered with "date" but is well ordered with `date`.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/319/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/319/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/318 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/318/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/318/comments | https://api.github.com/repos/coleifer/peewee/issues/318/events | https://github.com/coleifer/peewee/issues/318 | 28,788,812 | MDU6SXNzdWUyODc4ODgxMg== | 318 | auto_round gone from DoubleField | {
"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 | [
"Ah. Apparently auto_round was only intended (and meaningful) for DecimalFields. \n\nStarting from 2.2.0 peewee now complains about the superfluous attribute; something that it didn't before, so our upgrade failed.\n\nCan someone confirm this?\n",
"Yes that is correct.\n",
"Sorry for the inconvenience, I refactored a lot of Field code, including cleaning up the attributes.\n",
"Np, just caused us to clean up our code.\n"
] | 2014-03-05T13:23:40 | 2014-03-05T15:58:14 | 2014-03-05T15:58:14 | NONE | null | During upgrade from 2.17 to 2.2.0, auto_round vanished from DoubleField
Is that a bug, or is there a migration necessary? If the latter, there's a notice missing in the docs.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/318/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/318/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/317 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/317/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/317/comments | https://api.github.com/repos/coleifer/peewee/issues/317/events | https://github.com/coleifer/peewee/pull/317 | 28,767,263 | MDExOlB1bGxSZXF1ZXN0MTMxOTc2MTQ= | 317 | Allow subclass receive signals. | {
"login": "soasme",
"id": 369081,
"node_id": "MDQ6VXNlcjM2OTA4MQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/369081?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/soasme",
"html_url": "https://github.com/soasme",
"followers_url": "https://api.github.com/users/soasme/followers",
"following_url": "https://api.github.com/users/soasme/following{/other_user}",
"gists_url": "https://api.github.com/users/soasme/gists{/gist_id}",
"starred_url": "https://api.github.com/users/soasme/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/soasme/subscriptions",
"organizations_url": "https://api.github.com/users/soasme/orgs",
"repos_url": "https://api.github.com/users/soasme/repos",
"events_url": "https://api.github.com/users/soasme/events{/privacy}",
"received_events_url": "https://api.github.com/users/soasme/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
":thumbsup: great PR!!\n"
] | 2014-03-05T06:01:07 | 2014-06-28T04:17:41 | 2014-03-05T15:08:08 | CONTRIBUTOR | null | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/317/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/317/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/317",
"html_url": "https://github.com/coleifer/peewee/pull/317",
"diff_url": "https://github.com/coleifer/peewee/pull/317.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/317.patch",
"merged_at": "2014-03-05T15:08:08"
} |
|
https://api.github.com/repos/coleifer/peewee/issues/316 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/316/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/316/comments | https://api.github.com/repos/coleifer/peewee/issues/316/events | https://github.com/coleifer/peewee/pull/316 | 28,704,746 | MDExOlB1bGxSZXF1ZXN0MTMxNjA3NjU= | 316 | "AS" support on fn.* method | {
"login": "thibaultmeyer",
"id": 1005086,
"node_id": "MDQ6VXNlcjEwMDUwODY=",
"avatar_url": "https://avatars.githubusercontent.com/u/1005086?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/thibaultmeyer",
"html_url": "https://github.com/thibaultmeyer",
"followers_url": "https://api.github.com/users/thibaultmeyer/followers",
"following_url": "https://api.github.com/users/thibaultmeyer/following{/other_user}",
"gists_url": "https://api.github.com/users/thibaultmeyer/gists{/gist_id}",
"starred_url": "https://api.github.com/users/thibaultmeyer/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/thibaultmeyer/subscriptions",
"organizations_url": "https://api.github.com/users/thibaultmeyer/orgs",
"repos_url": "https://api.github.com/users/thibaultmeyer/repos",
"events_url": "https://api.github.com/users/thibaultmeyer/events{/privacy}",
"received_events_url": "https://api.github.com/users/thibaultmeyer/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Thanks for this. I've already implemented this as `.alias()` on all `Node` subclasses (includes `fn` objects).\n"
] | 2014-03-04T13:29:05 | 2014-07-06T01:50:15 | 2014-03-04T13:50:34 | NONE | null | Now user can do fn.MIN(Transaction.amount, AS='amount')
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/316/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/316/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/316",
"html_url": "https://github.com/coleifer/peewee/pull/316",
"diff_url": "https://github.com/coleifer/peewee/pull/316.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/316.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/315 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/315/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/315/comments | https://api.github.com/repos/coleifer/peewee/issues/315/events | https://github.com/coleifer/peewee/issues/315 | 28,694,115 | MDU6SXNzdWUyODY5NDExNQ== | 315 | Using fn.* on select() : can't rebuild model object | {
"login": "thibaultmeyer",
"id": 1005086,
"node_id": "MDQ6VXNlcjEwMDUwODY=",
"avatar_url": "https://avatars.githubusercontent.com/u/1005086?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/thibaultmeyer",
"html_url": "https://github.com/thibaultmeyer",
"followers_url": "https://api.github.com/users/thibaultmeyer/followers",
"following_url": "https://api.github.com/users/thibaultmeyer/following{/other_user}",
"gists_url": "https://api.github.com/users/thibaultmeyer/gists{/gist_id}",
"starred_url": "https://api.github.com/users/thibaultmeyer/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/thibaultmeyer/subscriptions",
"organizations_url": "https://api.github.com/users/thibaultmeyer/orgs",
"repos_url": "https://api.github.com/users/thibaultmeyer/repos",
"events_url": "https://api.github.com/users/thibaultmeyer/events{/privacy}",
"received_events_url": "https://api.github.com/users/thibaultmeyer/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I write a little hack to add support of \"AS\" in the function fn.MIN. It works, but I'm not sure that is the best way to proceed.\n\npeewee.py - Class Func(Node)\n\n``` python\n 406 def __getattr__(self, attr): \n 407 def dec(*args, **kwargs): \n 408 _as = kwargs.pop('AS', None) \n 409 if _as is None: \n 410 return Func(attr, *args, **kwargs) \n 411 else: \n 412 return Clause(Func(attr, *args, **kwargs), SQL('AS'), _as) \n 413 return dec\n```\n",
"That already exists actually, just call `.alias()` instead of as, e.g.:\n\n``` python\nfn.MIN(SuchAndSuch.date).alias('min_date')\n```\n",
"**BUT** I admire your enthusiasm for fixing this! Moar patches :)\n"
] | 2014-03-04T10:21:46 | 2014-03-04T13:50:07 | 2014-03-04T13:49:37 | NONE | null | Hello,
When I use fn.MIN(Transaction.date), MySQL return an column named "fn.MIN(Transaction.date)" intead of "date"... So all Transaction items returned have attribute "date" == None.
It would be nice to have the possibility to do something like that
```
fn.MIN(Transaction.date, AS="date")
```
Test:
```
lstTransaction = Transaction.select().where(Transaction.vendor ==
1).distinct().group_by(Transaction.client).order_by(Transaction.amount)
OK
print lstTransaction[0].date
==> 2014-02-01 12:21:45
lstTransaction = Transaction.select(Transaction.id, Transaction.vendor,
Transaction.amount, Transaction.client, Transaction.date).where(
Transaction.vendor == 1).distinct().group_by(Transaction.client)
.order_by(Transaction.amount)
OK
print lstTransaction[0].date
==> 2014-02-01 12:21:45
lstTransaction = Transaction.select(Transaction.id, Transaction.vendor,
Transaction.amount, Transaction.client, fn.MIN(Transaction.date))
.where(Transaction.vendor == 1).distinct().group_by(Transaction.client)
.order_by(Transaction.amount)
KO --> All Transaction items on list have attribute date == None
print lstTransaction[0].date
==> None
print lstTransaction[0].__dict__
==> {'_data': {'client': 1, 'vendor': 1, 'amount': 10.0, 'Min(t1.`date`)': datetime.datetime(2014, 2, 24, 10, 52, 32),}}
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/315/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/315/timeline | null | completed | null | null |