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/1318 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1318/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1318/comments | https://api.github.com/repos/coleifer/peewee/issues/1318/events | https://github.com/coleifer/peewee/issues/1318 | 242,947,517 | MDU6SXNzdWUyNDI5NDc1MTc= | 1,318 | CompositeKey as primary_key raises AttributeError | {
"login": "celestialorb",
"id": 321475,
"node_id": "MDQ6VXNlcjMyMTQ3NQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/321475?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/celestialorb",
"html_url": "https://github.com/celestialorb",
"followers_url": "https://api.github.com/users/celestialorb/followers",
"following_url": "https://api.github.com/users/celestialorb/following{/other_user}",
"gists_url": "https://api.github.com/users/celestialorb/gists{/gist_id}",
"starred_url": "https://api.github.com/users/celestialorb/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/celestialorb/subscriptions",
"organizations_url": "https://api.github.com/users/celestialorb/orgs",
"repos_url": "https://api.github.com/users/celestialorb/repos",
"events_url": "https://api.github.com/users/celestialorb/events{/privacy}",
"received_events_url": "https://api.github.com/users/celestialorb/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I do not encounter any such error running peewee 2.10.1.\r\n\r\nCode:\r\n\r\n```python\r\nimport datetime\r\nfrom peewee import *\r\n\r\n\r\nclass Base(Model):\r\n class Meta:\r\n database = SqliteDatabase(':memory:')\r\n\r\n\r\nclass UpdateBatch(Base):\r\n timestamp = DateTimeField(default=datetime.datetime.now)\r\n batch_type = CharField(default='DEFAULT')\r\n\r\n class Meta:\r\n db_table = 'update_batches'\r\n primary_key = CompositeKey('timestamp', 'batch_type')\r\n\r\n\r\nBase._meta.database.create_tables([UpdateBatch])\r\n```",
"Have you tried it with a MySQL backend? Looks like you're using Sqlite.",
"No, I don't have MySQL handy at the moment. Can you try the above code with SQLite, however? I'd like to verify if this is a peewee issue or a peewee/mysql issue.",
"Can do, please hold.",
"Tried your code on both Sqlite and MySQL (fresh Docker container) and didn't encounter any issues. Will reexamine my code / test environment to see if I can find a difference.",
"Looks like the issue is coming from my other classes in my model, which are using a `ForeignKeyField` to reference the `CompositeKey`. Looks like a duplicate of #270."
] | 2017-07-14T09:40:45 | 2017-07-15T23:03:17 | 2017-07-14T16:51:09 | NONE | null | I have a very basic model that peewee fails to create the model for (the table is created, but peewee raises an AttributeError.
My model is as shown:
```python
import datetime as dt
import peewee as pew
class BaseModel(pew.Model):
class Meta:
database = <DATABASE>
class UpdateBatch(BaseModel):
collected_at = pew.DateTimeField(default=dt.datetime.now)
batch_type = pew.CharField(default='DEFAULT')
class Meta:
db_table = 'UpdateBatches'
primary_key = pew.CompositeKey('collected_at', 'batch_type')
```
When starting from a fresh database and use `create_tables` I receive the following error:
```
AttributeError: 'CompositeKey' object has no attribute 'get_db_field'
```
`UpdateBatch` is the only model that has a `CompositeKey` in my application.
Note: this was using a MySQL database as a backend.
Using version peewee 2.10.1. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1318/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1318/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1317 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1317/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1317/comments | https://api.github.com/repos/coleifer/peewee/issues/1317/events | https://github.com/coleifer/peewee/issues/1317 | 242,893,940 | MDU6SXNzdWUyNDI4OTM5NDA= | 1,317 | db_table does not work | {
"login": "guangbaowan",
"id": 25094780,
"node_id": "MDQ6VXNlcjI1MDk0Nzgw",
"avatar_url": "https://avatars.githubusercontent.com/u/25094780?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/guangbaowan",
"html_url": "https://github.com/guangbaowan",
"followers_url": "https://api.github.com/users/guangbaowan/followers",
"following_url": "https://api.github.com/users/guangbaowan/following{/other_user}",
"gists_url": "https://api.github.com/users/guangbaowan/gists{/gist_id}",
"starred_url": "https://api.github.com/users/guangbaowan/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/guangbaowan/subscriptions",
"organizations_url": "https://api.github.com/users/guangbaowan/orgs",
"repos_url": "https://api.github.com/users/guangbaowan/repos",
"events_url": "https://api.github.com/users/guangbaowan/events{/privacy}",
"received_events_url": "https://api.github.com/users/guangbaowan/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2017-07-14T04:24:32 | 2017-07-14T04:42:07 | 2017-07-14T04:42:07 | NONE | null | Hi, guys, I used peewee to build models .
```
class BaseModel(Model):
class Meta:
# Mysql connection
database = DB
class PromotionUser(BaseModel):
created_at = DateTimeField(default=datetime.datetime.utcnow, index=True)
# seq_id = PrimaryKeyField(null=False)
source_uid = CharField()
source = CharField()
class Meta:
db_table = 'promotion_user'
```
PromotionUser.create_table(). the table name is 'promotionuser', not 'promotion_user', could someone plz help? | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1317/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1317/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1316 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1316/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1316/comments | https://api.github.com/repos/coleifer/peewee/issues/1316/events | https://github.com/coleifer/peewee/issues/1316 | 242,652,559 | MDU6SXNzdWUyNDI2NTI1NTk= | 1,316 | peewee.OperationalError: (1060, "Duplicate column name ) | {
"login": "iwwxiong",
"id": 12078753,
"node_id": "MDQ6VXNlcjEyMDc4NzUz",
"avatar_url": "https://avatars.githubusercontent.com/u/12078753?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/iwwxiong",
"html_url": "https://github.com/iwwxiong",
"followers_url": "https://api.github.com/users/iwwxiong/followers",
"following_url": "https://api.github.com/users/iwwxiong/following{/other_user}",
"gists_url": "https://api.github.com/users/iwwxiong/gists{/gist_id}",
"starred_url": "https://api.github.com/users/iwwxiong/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/iwwxiong/subscriptions",
"organizations_url": "https://api.github.com/users/iwwxiong/orgs",
"repos_url": "https://api.github.com/users/iwwxiong/repos",
"events_url": "https://api.github.com/users/iwwxiong/events{/privacy}",
"received_events_url": "https://api.github.com/users/iwwxiong/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Try aliasing one of the columns, Book.id.alias('book_id') or Author.id.alias('author_id')."
] | 2017-07-13T10:14:30 | 2017-07-13T14:57:40 | 2017-07-13T14:57:40 | NONE | null | Consider the following models:
```python
class Author(Model):
id = PrimaryKeyField()
name = CharField(max_length=50)
class Meta:
db_table = 'Author'
class Book(Model):
id = PrimaryKeyField()
name = CharField(max_length=255)
author = ForeignKeyField(Author)
class Meta:
db_table = 'Book'
```
Follow the models, I execute this query:
```python
Book.select(Book.id, Author.id).join(Author).limit(10).count()
```
some error throw `peewee.OperationalError: (1060, "Duplicate column name 'id')`. then i check the query sql like this:
```sql
SELECT COUNT(*1) FROM (SELECT `t1`.`id`, `t2`.`id` FROM `Book` AS t1 INNER JOIN `Author` AS t2 ON (`t1`.`author_id` = `t2`.`id`) LIMIT 10) AS wrapped_select
```
So, i konw this error is SQL as alias table SQL syntax error. But i think this case, we can empty the select conditions then excute count. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1316/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/1316/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1315 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1315/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1315/comments | https://api.github.com/repos/coleifer/peewee/issues/1315/events | https://github.com/coleifer/peewee/issues/1315 | 242,523,082 | MDU6SXNzdWUyNDI1MjMwODI= | 1,315 | N+1 avoidance not working? | {
"login": "c17r",
"id": 148640,
"node_id": "MDQ6VXNlcjE0ODY0MA==",
"avatar_url": "https://avatars.githubusercontent.com/u/148640?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/c17r",
"html_url": "https://github.com/c17r",
"followers_url": "https://api.github.com/users/c17r/followers",
"following_url": "https://api.github.com/users/c17r/following{/other_user}",
"gists_url": "https://api.github.com/users/c17r/gists{/gist_id}",
"starred_url": "https://api.github.com/users/c17r/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/c17r/subscriptions",
"organizations_url": "https://api.github.com/users/c17r/orgs",
"repos_url": "https://api.github.com/users/c17r/repos",
"events_url": "https://api.github.com/users/c17r/events{/privacy}",
"received_events_url": "https://api.github.com/users/c17r/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"You're going the \"wrong way\" when following that query. You'll need to use `prefetch()` instead.\r\n\r\nhttp://docs.peewee-orm.com/en/latest/peewee/querying.html#list-users-and-all-their-tweets\r\n\r\nI'd suggest giving the docs on N+1 a close read. The approach you're using works fine for getting an object and a singular related instance (i.e., would work fine for listing all members and a given group). But when you have a single instance and want to get all objects that are related to it, you need to use `prefetch()`."
] | 2017-07-12T21:35:55 | 2017-07-12T21:58:23 | 2017-07-12T21:58:23 | NONE | null | My models are
```
class BaseModel(peewee.Model):
class Meta:
database = database
class Group(BaseModel):
name = peewee.CharField(max_length=255)
reddit_name = peewee.CharField(max_length=30)
added = peewee.DateTimeField(default=_now)
member_count = peewee.IntegerField(default=0)
class Meta:
indexes = (
(('name', 'reddit_name'), True),
)
class Member(BaseModel):
group = peewee.ForeignKeyField(Group, related_name='members', index=True)
reddit_name = peewee.CharField(max_length=30)
added = peewee.DateTimeField(default=_now)
```
Trying to avoid the N+1, I do
```
>>> group = (Group
.select(Group, Member)
.join(Member)
.where(Group.name == 'test-group', Group.reddit_name == 'c17r')
.order_by(Member.reddit_name)
.get())
```
If I turn on logging, I can see that it did what I wanted to:
```
[2017-07-12 17:29:45.128426] DEBUG: peewee: ('SELECT "t1"."id", "t1"."name", "t1"."reddit_name", "t1"."added", "t1"."member_count", "t2"."id", "t2"."group_id", "t2"."reddit_name", "t2"."added" FROM "group" AS t1 INNER JOIN "member" AS t2 ON ("t1"."id" = "t2"."group_id") WHERE (("t1"."name" = ?) AND ("t1"."reddit_name" = ?)) ORDER BY "t2"."reddit_name" LIMIT 1 OFFSET 0', ['test-group', 'c17r'])
```
But,
```
>>> group.members
<class 'data.Member'> SELECT "t1"."id", "t1"."group_id", "t1"."reddit_name", "t1"."added" FROM "member" AS t1 WHERE ("t1"."group_id" = ?) [1]
>>>
>>> [m.reddit_name for m in group.members.iterator()]
[2017-07-12 17:30:25.148410] DEBUG: peewee: ('SELECT "t1"."id", "t1"."group_id", "t1"."reddit_name", "t1"."added" FROM "member" AS t1 WHERE ("t1"."group_id" = ?)', [1])
['one', 'two', 'three', 'four']
>>>
```
Did I miss something on the N+1 avoidance? | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1315/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1315/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1314 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1314/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1314/comments | https://api.github.com/repos/coleifer/peewee/issues/1314/events | https://github.com/coleifer/peewee/issues/1314 | 242,451,647 | MDU6SXNzdWUyNDI0NTE2NDc= | 1,314 | Relation already exists error when using Model's create_table with fail silently option | {
"login": "Tumetsu",
"id": 3398165,
"node_id": "MDQ6VXNlcjMzOTgxNjU=",
"avatar_url": "https://avatars.githubusercontent.com/u/3398165?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/Tumetsu",
"html_url": "https://github.com/Tumetsu",
"followers_url": "https://api.github.com/users/Tumetsu/followers",
"following_url": "https://api.github.com/users/Tumetsu/following{/other_user}",
"gists_url": "https://api.github.com/users/Tumetsu/gists{/gist_id}",
"starred_url": "https://api.github.com/users/Tumetsu/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/Tumetsu/subscriptions",
"organizations_url": "https://api.github.com/users/Tumetsu/orgs",
"repos_url": "https://api.github.com/users/Tumetsu/repos",
"events_url": "https://api.github.com/users/Tumetsu/events{/privacy}",
"received_events_url": "https://api.github.com/users/Tumetsu/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Found the problem which was in peewee_migrate. So nothing to see here. More information for curious: https://github.com/klen/peewee_migrate/issues/51"
] | 2017-07-12T17:08:35 | 2017-07-12T17:38:35 | 2017-07-12T17:38:34 | NONE | null | Hello, I'm using peewee with peewee_migrate library and encountered a problem today.
When I try to run my migrations, I get error
```
peewee.ProgrammingError: relation "migratehistory" already exists
```
More info in issue I posted to peewee_migrate's repo: https://github.com/klen/peewee_migrate/issues/51
I investigated the reason and found the following. In the peewee_migrate, the migration history is created in a following function:
```
@cached_property
def model(self):
"""Initialize and cache MigrationHistory model."""
MigrateHistory._meta.database = self.database
MigrateHistory._meta.db_table = self.migrate_table
MigrateHistory.create_table(True)
return MigrateHistory
```
Note the `create_table` call. After tinkering around a bit I noticed that the next version works:
```
@cached_property
def model(self):
"""Initialize and cache MigrationHistory model."""
MigrateHistory._meta.database = self.database
MigrateHistory._meta.db_table = self.migrate_table
self.database.create_table(MigrateHistory, safe=True)
return MigrateHistory
```
You see I use `database` object's class method instead of `Model`s.
This led me to wonder if the problem is actually in peewee and model's create_table won't work as expected. Of course it might be an issue with peewee_migrate (and therefore not really your business) as I originally suspected but I'd like to hear if you have any idea why the original code won't work or if there is indeed a bug in peewee :)
Finally here is link to peewee_migrate's file containing the snippets above: https://github.com/klen/peewee_migrate/blob/develop/peewee_migrate/router.py
And thanks by the way for creating peewee!
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1314/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1314/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1313 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1313/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1313/comments | https://api.github.com/repos/coleifer/peewee/issues/1313/events | https://github.com/coleifer/peewee/issues/1313 | 241,259,663 | MDU6SXNzdWUyNDEyNTk2NjM= | 1,313 | Peewee ignoring db_table on create_tables() | {
"login": "timlehr",
"id": 5310859,
"node_id": "MDQ6VXNlcjUzMTA4NTk=",
"avatar_url": "https://avatars.githubusercontent.com/u/5310859?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/timlehr",
"html_url": "https://github.com/timlehr",
"followers_url": "https://api.github.com/users/timlehr/followers",
"following_url": "https://api.github.com/users/timlehr/following{/other_user}",
"gists_url": "https://api.github.com/users/timlehr/gists{/gist_id}",
"starred_url": "https://api.github.com/users/timlehr/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/timlehr/subscriptions",
"organizations_url": "https://api.github.com/users/timlehr/orgs",
"repos_url": "https://api.github.com/users/timlehr/repos",
"events_url": "https://api.github.com/users/timlehr/events{/privacy}",
"received_events_url": "https://api.github.com/users/timlehr/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"It appears to be working as I'd expect. In the example below the database is reporting a table named \"Foo\" and the SELECT query is querying the \"Foo\" table (successfully).\r\n\r\n```python\r\nIn [1]: from peewee import *\r\n\r\nIn [2]: db = SqliteDatabase('/tmp/foo.db')\r\n\r\nIn [3]: class Foo(Model):\r\n ...: value = TextField()\r\n ...: class Meta:\r\n ...: db_table = 'Foo'\r\n ...: database = db\r\n ...: \r\n\r\nIn [4]: db.create_tables([Foo])\r\n\r\nIn [5]: db.get_tables()\r\nOut[5]: [u'Foo']\r\n\r\nIn [6]: Foo.create(value='x')\r\nOut[6]: <__main__.Foo at 0x7fdd08157ed0>\r\n\r\nIn [7]: Foo.select()\r\nOut[7]: <class '__main__.Foo'> SELECT \"t1\".\"id\", \"t1\".\"value\" FROM \"Foo\" AS t1 []\r\n\r\nIn [8]: Foo.get()\r\nOut[8]: <__main__.Foo at 0x7fdd0815eb10>\r\n\r\n```",
"Hi Charles, \r\nI found the issue after trying the deployment on a Linux machine. \r\nMySQL on Windows makes DB table names lowercase by default (for some reason).\r\nYou have to manually change that option in the ini-file.\r\n\r\nSorry for the trouble!\r\n\r\nCheers,\r\nTim"
] | 2017-07-07T13:12:17 | 2017-07-13T14:27:52 | 2017-07-12T21:58:34 | NONE | null | Hi Charles,
first: thanks for your hard work on peewee. It's a lovely package that already saved us a lot of time. :+1:
However, we have an issue similiar to #201 where our uppercase db names are converted to lowercase, even though we specify an explicit uppercase name in the `db_table` attribute of the `meta` class.
```
from luti.core.models.basemodel import BaseModel
from peewee import *
class Collection(BaseModel):
filter = CharField()
id = PrimaryKeyField(db_column='idCollection')
longname = CharField(null=True)
path = CharField()
class Meta:
db_table = 'Collection'
```
Whatever we put in `db_table` will be used when we create the tables with `create_tables()`, but it will ignore any uppercase characters and lowercase them. We are using Python 2.7, Peewee 2.10.0 and MariaDB 10.1.24 / MySQL 5.7.18 servers for our test databases. Any clues? | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1313/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1313/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1312 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1312/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1312/comments | https://api.github.com/repos/coleifer/peewee/issues/1312/events | https://github.com/coleifer/peewee/issues/1312 | 241,242,841 | MDU6SXNzdWUyNDEyNDI4NDE= | 1,312 | raw sql execute quote bug | {
"login": "fy0",
"id": 1579850,
"node_id": "MDQ6VXNlcjE1Nzk4NTA=",
"avatar_url": "https://avatars.githubusercontent.com/u/1579850?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/fy0",
"html_url": "https://github.com/fy0",
"followers_url": "https://api.github.com/users/fy0/followers",
"following_url": "https://api.github.com/users/fy0/following{/other_user}",
"gists_url": "https://api.github.com/users/fy0/gists{/gist_id}",
"starred_url": "https://api.github.com/users/fy0/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/fy0/subscriptions",
"organizations_url": "https://api.github.com/users/fy0/orgs",
"repos_url": "https://api.github.com/users/fy0/repos",
"events_url": "https://api.github.com/users/fy0/events{/privacy}",
"received_events_url": "https://api.github.com/users/fy0/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"It works fine for me:\r\n\r\n```python\r\nIn [1]: from peewee import *\r\n\r\nIn [2]: db = PostgresqlDatabase('peewee_test')\r\n\r\nIn [3]: db.execute_sql('select %s', ('asd',)).fetchone()\r\nOut[3]: ('asd',)\r\n```",
"@coleifer select is ok, but it's just a example. Table aaa is not exists so exception raised.\r\nI just want to say quote seems wrong, and some statements were influenced.",
"More realistic example:\r\n```python\r\n# You know column or table name starts with digit is valid on PostgreSQL\r\n# I guess that's a reason of db.quote_char design\r\n# SQL: create table \"123\"(\"456\" int);\r\n\r\ndb.execute_sql('select * from \"123\"')\r\n# OK\r\ndb.execute_sql('select * from %s', (\"123\",))\r\n# peewee.ProgrammingError: syntax error at or near \"'123'\"\r\n# LINE 1: select * from '123'\r\n\r\ndb.execute_sql('insert into %s (%s) values (1)', (\"123\", \"456\"))\r\n# peewee.ProgrammingError: syntax error at or near \"'123'\"\r\n# LINE 1: insert into '123' ('456') values (1)\r\n```\r\n\r\nIf design table by myself, I will never use these bad names.\r\nActually I'm trying to convert csv to postgreSQL table, so I should use origin names.\r\n",
"@fy0 -- Postgres quotes things using single quotes to express string literals. The quote_char is used to identify named entities, not for indicating string literals or doing some kind of escaping.",
"@coleifer ' for string literals, \" for identify named entities (columns, tables), right? \r\nNow table's name is 123, column's name is 456, and peewee's execute_sql crashed. \r\nI'm not sure I'm completely understand about how quote_char works, the crash is actually happened, others are my guess. \r\n\r\nsome snippets from peewee:\r\n```python\r\nclass QueryCompiler(object):\r\n def quote(self, s):\r\n return '%s%s%s' % (self.quote_char, s, self.quote_char)\r\n\r\nclass Database(object):\r\n compiler_class = QueryCompiler\r\n quote_char = '\"'\r\n\r\n def compiler(self):\r\n return self.compiler_class(\r\n self.quote_char, self.interpolation, self.field_overrides,\r\n self.op_overrides)\r\n\r\n def execute(self, clause):\r\n return self.execute_sql(*self.compiler().parse_node(clause))\r\n\r\n def execute_sql(self, sql, params=None, require_commit=True):\r\n logger.debug((sql, params))\r\n with self.exception_wrapper:\r\n cursor = self.get_cursor()\r\n try:\r\n cursor.execute(sql, params or ())\r\n except Exception:\r\n if self.autorollback and self.get_autocommit():\r\n self.rollback()\r\n raise\r\n else:\r\n if require_commit and self.get_autocommit():\r\n self.commit()\r\n return cursor\r\n\r\n\r\nclass PostgresqlDatabase(Database):\r\n pass # inherited\r\n\r\n\r\nclass MySQLDatabase(Database):\r\n quote_char = '`'\r\n```\r\n\r\nemmmm, maybe it's doesn't matter about quote_char because compiler not work?\r\n\r\n```python\r\ndb.execute(peewee.SQL('insert into %s (%s) values (1)', \"123\", \"456\"))\r\n# peewee.ProgrammingError: syntax error at or near \"'123'\"\r\n# LINE 1: insert into '123' ('456') values (1)\r\n```\r\n\r\nSomething went wrong, but it's too hard to find and solve it to me. \r\nFix it please. peewee is one of my favorite package of python, thanks for your hard works.\r\nGoing to bed, see you tomorrow.\r\n",
"I think you're mixing up quoting and escaping. They are two completely different things. In your last example (the INSERT INTO %s (%s) VALUES (1)) -- you are doing literally the exact opposite of what you should do. The table name and column name should be quoted literals -- not parameterized, while the actual value being inserted *should* be parameterized.\r\n\r\nWhat you want would be:\r\n\r\n 'INSERT INTO \"123\" (\"456\") VALUES (%s)', (1,)\r\n\r\nAs you can see, quote_char is a double quote, and it is used to wrap the named entities in the query -- the table and column. The \"%s\" is used to parameterize a query -- safely include values without risking SQL injection -- so we use the %s instead of the `1`.",
"@coleifer You mean there is no method to escape table and column names for raw sql execute .... %s is only for values, right?\r\n\r\nTested. Example of injection:\r\n```python\r\nclass NewModel(peewee.Model):\r\n class Meta:\r\n database = db\r\n db_table = '1\"23'\r\n\r\nq = NewModel.select()\r\nprint(q)\r\n# <class '__main__.NewModel'> SELECT \"t1\".\"id\" FROM \"1\"23\" AS t1 []\r\n```\r\n\r\n```python\r\nclass NewModel(peewee.Model):\r\n class Meta:\r\n database = db\r\n db_table = 'asd\" as t1; drop table \"123\" --'\r\n\r\nq = NewModel.select()\r\nprint(q)\r\nq.execute()\r\n\r\n# <class '__main__.NewModel'> SELECT \"t1\".\"id\" FROM \"asd\" as t1; drop table \"123\" --\" AS t1 []\r\n\r\n# asd is another table\r\n# now table '123' dropped\r\n```\r\n\r\nIf admin interface provide a table design page, attackers can easily do everything they want by post evil names. I always thought names are escaped by default, It's so dangerous ...\r\n",
"@fy0 -- yes, `%s` is just for values, and double quotes are to wrap things like table or column names.\r\n\r\nIf you're using Peewee, you'll typically declare your table and columns as Python Model classes. I don't see any risk for SQL Injection unless you were doing something like prompting the user to supply you with the table and column names to execute queries on... which seems ridiculous.\r\n\r\nAs a dev, you control the table and col names. Shouldn't be an issue.",
"@coleifer Developers not always have 100% control. Such as model design tool, import data, peewee's pwiz and csv tools.\r\n\r\nOn the other hand, different database usually beaver difference with name quote sign. ORM's work is eliminate difference between databases. It's my advice.",
"Peewee *does* eliminate the differences in parameterizing queries...you don't have to think about the fact that sqlite uses \"?\" and mysql/pg use \"%s\". Peewee also prevents you from having to think about quoting, because peewee automatically quotes tables and columns for you using the db-specific character.\r\n\r\nI'm not even sure what you're asking for at this point.",
"@coleifer I have the similar issue. \r\n```\r\nclass Base(playhouse.signals.Model):\r\n class Meta:\r\n database = db\r\n\r\n def partial_update(self, partial_data):\r\n SQL = \"update %s set data = data || %s where tid = %s\"\r\n vals = (self._meta.db_table, partial_data, self.tid)\r\n db_pointer.execute_sql(SQL, vals)\r\n\r\nclass Table1(Base):\r\n class Meta:\r\n db_table = 'table1'\r\n\r\nclass Table2(Base):\r\n class Meta:\r\n db_table = 'table2'\r\n```\r\nSo partial_update function can be called on any of the Table. For that, I need to use %s and the respective table name to update.\r\n\r\nThe error I received is:\r\n```\r\nFile \"/home/stark/.local/lib/python2.7/site-packages/playhouse/postgres_ext.py\", line 383, in execute_sql\r\n cursor.execute(sql, params or ())\r\nProgrammingError: syntax error at or near \" ' table1 ' \"\r\nLINE 1: update 'table1' set data = data || '{\"status\": ...`\r\n```\r\n\r\nWhat should I do in this case?\r\n\r\nPS: If I write the name of the table directly without using %s, then it works fine.",
"Why are you using an ORM like Peewee if you are writing simple update queries using plain sql?\r\n\r\n```python\r\n\r\ndef partial_update(self, partial_data):\r\n model = type(self) \r\n query = model.update({model.data: model.data.concat(partial_data)}).where(model.tid == self.tid)\r\n return query.execute()\r\n```\r\n\r\nAs for mixing string interpolation and query parameterization, I strongly suggest that you don't do it that way...it's so clumsy. If you must, you should do this:\r\n\r\n```python\r\nquery = \"update %s set data = %%s\" % table_name\r\ndb.execute_sql(query, params)\r\n```\r\n\r\nAlso db_pointer?? This is python bro.",
"@coleifer Could not find how to update jsonb field without getting the data that's why used plain SQL.\r\nI asked on StackOverflow but didn't get an answer. ([post)](https://stackoverflow.com/questions/48290053/how-to-update-jsonb-field-in-postgres-v9-4-using-peewee)\r\n\r\nRunning the update function you suggested, gave me the following error.\r\n```\r\nFile \"/home/stark/.local/lib/python2.7/site-packages/playhouse/postgres_ext.py\", line 383, in execute_sql\r\n cursor.execute(sql, params or ())\r\nDataError: invalid concatenation of jsonb objects\r\n```\r\nI have used `json.dumps(partial_data)` to send as string. Any suggestions.?",
"@pranjalsingi -- did you try not converting it to a string?",
"@coleifer It worked. I passed partial_data as a dictionary. \r\nThank you, soo much."
] | 2017-07-07T11:59:05 | 2018-01-18T22:53:54 | 2017-07-07T12:34:30 | NONE | null | Example:
```python
from playhouse.db_url import connect
db = connect('postgres://postgres@localhost:5432/')
print(db.quote_char)
# result is "
db.execute_sql('select %s from aaa', ('asd', ))
# Exception: LINE 1: select 'asd' from aaa
db.execute_sql('select "asd" from aaa')
# Exception: LINE 1: select "asd" from aaa
db.execute_sql('select \'asd\' from aaa')
# Exception: LINE 1: select 'asd' from aaa
```
Seems the quote_char is ', but " expected, right?
peewee version: from 2.9.3 to 2.10.1
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1312/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1312/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1311 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1311/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1311/comments | https://api.github.com/repos/coleifer/peewee/issues/1311/events | https://github.com/coleifer/peewee/issues/1311 | 241,197,127 | MDU6SXNzdWUyNDExOTcxMjc= | 1,311 | Certain operations not respecting the db_value() | {
"login": "TheLarsinator",
"id": 6304557,
"node_id": "MDQ6VXNlcjYzMDQ1NTc=",
"avatar_url": "https://avatars.githubusercontent.com/u/6304557?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/TheLarsinator",
"html_url": "https://github.com/TheLarsinator",
"followers_url": "https://api.github.com/users/TheLarsinator/followers",
"following_url": "https://api.github.com/users/TheLarsinator/following{/other_user}",
"gists_url": "https://api.github.com/users/TheLarsinator/gists{/gist_id}",
"starred_url": "https://api.github.com/users/TheLarsinator/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/TheLarsinator/subscriptions",
"organizations_url": "https://api.github.com/users/TheLarsinator/orgs",
"repos_url": "https://api.github.com/users/TheLarsinator/repos",
"events_url": "https://api.github.com/users/TheLarsinator/events{/privacy}",
"received_events_url": "https://api.github.com/users/TheLarsinator/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"It seems to be working OK for me:\r\n\r\n```python\r\nfrom peewee import *\r\n\r\nclass ListField(Field):\r\n def db_value(self, value):\r\n return ','.join(value)\r\n def python_value(self, value):\r\n return value.split(',')\r\n\r\ndb = SqliteDatabase(':memory:')\r\n\r\nclass Register(Model):\r\n data = TextField()\r\n items = ListField()\r\n class Meta:\r\n database = db\r\n\r\ndb.create_tables([Register])\r\n\r\nr = Register.create(data='foo,bar,baz', items=['foo', 'bar', 'baz'])\r\nr.items # ['foo', 'bar', 'baz']\r\n\r\nr_db = Register.get()\r\nr_db.items # ['foo', 'bar', 'baz']\r\n```",
"Ok, so I think I narrowed it down to the get_or_create method. \r\n\r\nr, c = Register.get_or_create(data='foo,bar,baz', items=['foo', 'bar', 'baz'])\r\n\r\nUse that to recreate",
"When doing a `SELECT`, peewee doesn't know if the list you are passing should be unpacked (as it would for an `IN` query, for example). To work around, when passing lists in this situation you should wrap it in Param:\r\n\r\n```python\r\nr = Register.select().where(Register.items == Param(['foo', 'bar', 'baz']))\r\n```",
"In Peewee 3.0a, you can accomplish the same `AsIs`.",
"Problem solved :) Thank you for the quick help!"
] | 2017-07-07T08:42:58 | 2017-07-07T10:51:48 | 2017-07-07T10:33:34 | NONE | null | I saw that this was an issue before, #150
But I experience the same problem, so perhaps this fix has been undone in a later release:
I have made a ListField, which is pretty much the same as here:
```
class ListField(Field):
def db_value(self, list):
return str(list)
def python_value(self, list):
return ast.literal_eval(list)
```
I get the same error: peewee.OperationalError: near ",": syntax error
db_value doesnt get a list, but gets called for each item in the list
Workaround:
Make a class that contains a list. Make a ClassField for this class, that uses the list to create the output.
Not an optimal solution, but works for now | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1311/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1311/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1310 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1310/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1310/comments | https://api.github.com/repos/coleifer/peewee/issues/1310/events | https://github.com/coleifer/peewee/pull/1310 | 241,072,825 | MDExOlB1bGxSZXF1ZXN0MTI5MjcxNDc0 | 1,310 | Copied example code on 'Using' from database.rst to api.rst. | {
"login": "jbremson",
"id": 2423578,
"node_id": "MDQ6VXNlcjI0MjM1Nzg=",
"avatar_url": "https://avatars.githubusercontent.com/u/2423578?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/jbremson",
"html_url": "https://github.com/jbremson",
"followers_url": "https://api.github.com/users/jbremson/followers",
"following_url": "https://api.github.com/users/jbremson/following{/other_user}",
"gists_url": "https://api.github.com/users/jbremson/gists{/gist_id}",
"starred_url": "https://api.github.com/users/jbremson/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/jbremson/subscriptions",
"organizations_url": "https://api.github.com/users/jbremson/orgs",
"repos_url": "https://api.github.com/users/jbremson/repos",
"events_url": "https://api.github.com/users/jbremson/events{/privacy}",
"received_events_url": "https://api.github.com/users/jbremson/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Replaced with a similar patch. Thnx."
] | 2017-07-06T20:15:15 | 2017-07-07T02:23:51 | 2017-07-07T02:23:51 | NONE | null | Simple doc change to clarify the use of 'Using' with example code. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1310/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1310/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/1310",
"html_url": "https://github.com/coleifer/peewee/pull/1310",
"diff_url": "https://github.com/coleifer/peewee/pull/1310.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/1310.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/1309 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1309/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1309/comments | https://api.github.com/repos/coleifer/peewee/issues/1309/events | https://github.com/coleifer/peewee/issues/1309 | 241,059,299 | MDU6SXNzdWUyNDEwNTkyOTk= | 1,309 | Swap databases to models | {
"login": "jbremson",
"id": 2423578,
"node_id": "MDQ6VXNlcjI0MjM1Nzg=",
"avatar_url": "https://avatars.githubusercontent.com/u/2423578?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/jbremson",
"html_url": "https://github.com/jbremson",
"followers_url": "https://api.github.com/users/jbremson/followers",
"following_url": "https://api.github.com/users/jbremson/following{/other_user}",
"gists_url": "https://api.github.com/users/jbremson/gists{/gist_id}",
"starred_url": "https://api.github.com/users/jbremson/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/jbremson/subscriptions",
"organizations_url": "https://api.github.com/users/jbremson/orgs",
"repos_url": "https://api.github.com/users/jbremson/repos",
"events_url": "https://api.github.com/users/jbremson/events{/privacy}",
"received_events_url": "https://api.github.com/users/jbremson/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I figured this out after some digging in the code. See my PR for a small change to the docs. ",
"It would be nice if there was a way to change the db handle on an application wide basis. The Using context manager loses scope when calling outside functions. \r\n\r\nI will take a stab at trying to implement this. Any advice on how to do it? ",
"> It would be nice if there was a way to change the db handle on an application wide basis.\r\n\r\nYou can always implement an abstraction layer that handles this kind of thing. Or use the `Proxy` object:\r\n\r\n```python\r\ndb = Proxy()\r\ndb_1 = SqliteDatabase('one.db')\r\ndb_2 = SqliteDatabase('two.db')\r\n\r\nclass MyModel(Model):\r\n class Meta:\r\n database = db\r\n\r\nclass AnotherModel(Model):\r\n class Meta:\r\n database = db\r\n\r\ndb.initialize(db_1) # Now MyModel and AnotherModel are using db_1\r\n\r\n# do some stuff....\r\n\r\ndb.initialize(db_2) # Now they're using db_2...\r\n```"
] | 2017-07-06T19:21:58 | 2017-07-07T03:49:44 | 2017-07-07T03:49:44 | NONE | null | I would like to test my models against a test db, but I'm not seeing an easy way to swap the db handle in the models.
How do I do this? | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1309/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1309/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1308 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1308/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1308/comments | https://api.github.com/repos/coleifer/peewee/issues/1308/events | https://github.com/coleifer/peewee/issues/1308 | 240,587,962 | MDU6SXNzdWUyNDA1ODc5NjI= | 1,308 | peewee support tornado coroutine ? | {
"login": "rfyiamcool",
"id": 3785409,
"node_id": "MDQ6VXNlcjM3ODU0MDk=",
"avatar_url": "https://avatars.githubusercontent.com/u/3785409?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/rfyiamcool",
"html_url": "https://github.com/rfyiamcool",
"followers_url": "https://api.github.com/users/rfyiamcool/followers",
"following_url": "https://api.github.com/users/rfyiamcool/following{/other_user}",
"gists_url": "https://api.github.com/users/rfyiamcool/gists{/gist_id}",
"starred_url": "https://api.github.com/users/rfyiamcool/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/rfyiamcool/subscriptions",
"organizations_url": "https://api.github.com/users/rfyiamcool/orgs",
"repos_url": "https://api.github.com/users/rfyiamcool/repos",
"events_url": "https://api.github.com/users/rfyiamcool/events{/privacy}",
"received_events_url": "https://api.github.com/users/rfyiamcool/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2017-07-05T09:17:59 | 2017-07-05T10:51:12 | 2017-07-05T10:51:12 | NONE | null | peewee support tornado coroutine mode? | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1308/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1308/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1307 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1307/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1307/comments | https://api.github.com/repos/coleifer/peewee/issues/1307/events | https://github.com/coleifer/peewee/issues/1307 | 240,533,143 | MDU6SXNzdWUyNDA1MzMxNDM= | 1,307 | Upsert support | {
"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 | [
"Implementing `INSERT/IGNORE` for all databases should be straightforward.\r\n\r\nFor SQLite and for MySQL, in the simple case of a `REPLACE` query, the semantics are the same just slightly different SQL syntax.\r\n\r\nFor MySQL and Postgresql, in the not-so-simple case, it seems like the following things will need to be in-place in Peewee's APIs:\r\n\r\n* Referencing the values that would have been inserted (`VALUES(x)` in MySQL, `EXCLUDED.x` in Postgres).\r\n* Referencing the pre-existing value of a column in the event of an update.\r\n* Specify which columns / constraint the conflict applies to (Postgres only).",
"In MySQL, Replace will delete the conflict row and insert a new row, but on duplicate key update just update the old row. So if the only constraint on the table was on column a, they are still different.",
"@hzweveryday -- thank you for letting me know of that distinction, that's quite important!",
"Roughing out some APIs / implementation: 500910da7f358c62b42ddd968b78f0352d7f49b3",
"Implemented for SQLite, MySQL and Postgres: 8de7d16f022a92daae2d8c0b9ea798b375e09bff\r\n\r\nHere are some examples (I'm open to suggestions on the API):\r\n\r\n```python\r\n# Stupid simple example.\r\nPerson.insert(name='huey').on_conflict('ignore')\r\n\r\n# Generates:\r\n# sqlite: INSERT OR IGNORE INTO \"person\" (\"name\") VALUES ('huey')\r\n# mysql: INSERT IGNORE INTO \"person\" (\"name\") VALUES ('huey')\r\n# postgres: INSERT INTO \"person\" (\"name\") VALUES ('huey') ON CONFLICT DO NOTHING\r\n\r\n# Slightly more interesting.\r\n(Person\r\n .insert({Person.name: 'huey', Person.dob: some_date})\r\n .on_conflict(\r\n preserve=(Person.dob,),\r\n update={Person.name: Person.name.concat(' (updated)')}))\r\n\r\n# Generates:\r\n# sqlite: not supported\r\n# mysql: INSERT INTO \"person\" (\"name\", \"dob\") VALUES ('huey', ...) \r\n# ON DUPLICATE KEY UPDATE \"dob\" = VALUES(\"dob\"), \"name\" = \"name\" || ' (updated)'\r\n# postgres: requires a conflict target, see next example\r\n\r\n(Person\r\n .insert(name='huey', dob=some_date)\r\n .on_conflict(\r\n conflict_target=(Person.name,),\r\n preserve=(Person.dob,),\r\n update={Person.name: Person.name.concat(' (updated)')))\r\n\r\n# postgres: INSERT INTO \"person\" (\"name\", \"dob\") VALUES ('huey', ...) \r\n# ON CONFLICT (\"name\")\r\n# DO UPDATE SET \"dob\" = EXCLUDED.\"dob\", \"name\" = \"name\" || ' (updated)'\r\n```",
"sqlite's `INSERT OR REPLACE` is not analogous to `UPSERT`. If you have a table with 4 fields -- 3 come from the outside and the 4th comes from elsewhere -- then `INSERT OR REPLACE` on that record loses the existing value in the 4th column.",
"For MySQL I've found that `REPLACE INTO` is hardly ever the right thing to do. So the preference would be to use `INSERT INTO ... ON DUPLICATE KEY`.\r\n\r\nThat also allows you to basically do a mass update of the table with only partial fields.\r\n\r\nTake a table with fields: id, a, b, c, d, e\r\nYou could do\r\n```sql\r\nINSERT INTO table (id, c) VALUES\r\n (1, 'something'),\r\n (2, 'somethingelse')\r\nON DUPLICATE KEY UPDATE\r\n c=VALUES(c)\r\n```\r\nand not lose the values in a, b, d, e (provided that each id already existed).\r\n\r\n(And yes, I just leveraged that for a real life case with the exception being I used an `INSERT INTO ... SELECT ... ON DUPLICATE KEY UPDATE` instead of suppling the values manually)",
"The upsert API for MySQL supports both REPLACE and ON DUPLICATE KEY.",
"The postgres example does not seem to work: \r\n\r\n`TypeError: on_conflict() got an unexpected keyword argument 'conflict_target'`",
"Postgres example from tests:\r\n\r\n```python\r\nclass Emp(TestModel):\r\n first = CharField()\r\n last = CharField()\r\n empno = CharField(unique=True)\r\n\r\n class Meta:\r\n indexes = (\r\n (('first', 'last'), True),\r\n )\r\n\r\ntest_data = (\r\n ('huey', 'cat', '123'),\r\n ('zaizee', 'cat', '124'),\r\n ('mickey', 'dog', '125'),\r\n )\r\n\r\nfor first, last, empno in self.test_data:\r\n Emp.create(first=first, last=last, empno=empno)\r\n\r\n def test_update(self):\r\n res = (Emp\r\n .insert(first='foo', last='bar', empno='125')\r\n .on_conflict(\r\n conflict_target=(Emp.empno,),\r\n preserve=(Emp.first, Emp.last),\r\n update={Emp.empno: '125.1'})\r\n .execute())\r\n self.assertData([\r\n ('huey', 'cat', '123'),\r\n ('zaizee', 'cat', '124'),\r\n ('foo', 'bar', '125.1')])\r\n\r\n res = (Emp\r\n .insert(first='foo', last='bar', empno='126')\r\n .on_conflict(\r\n conflict_target=(Emp.first, Emp.last),\r\n preserve=(Emp.first,),\r\n update={Emp.last: 'baze'})\r\n .execute())\r\n self.assertData([\r\n ('huey', 'cat', '123'),\r\n ('zaizee', 'cat', '124'),\r\n ('foo', 'baze', '125.1')])\r\n```",
"Hey @coleifer, long time no speak :) Just ran into an issue with this, I'm trying to use `bulk_insert()` and would like it to ignore any duplicate entries. This was also raised in https://github.com/coleifer/peewee/issues/1067 . Tried using `on_conflict()` but didn't seem to do anything when using `bulk_insert()`. Any ideas?\r\n\r\nEDIT: Ahh never mind, it was a bug on my own code, `on_conflict('IGNORE')` seems to work beautifully!",
"Oh hell yeah I'm glad to hear! I've been using it myself but only with sqlite. Good to hear from you @foxx",
"This project is so amazing! @coleifer Just wanted to say that you're amazing. One the best API designs I've seen. Thanks",
"Glad you're enjoying the project!",
"Any advice on how to get this to work with bulk operations? I'm trying to get it to function with bulk_insert_mappings. on_conflict('ignore') doesn't seem to have any effect.\r\n```\r\nsession.bulk_insert_mappings(\r\n Event,\r\n event_list\r\n ).on_conflict('ignore')\r\n```",
"Session and bulk insert mapping are not peewee apis.",
"Peewee would use:\r\n\r\n```python\r\nEvent.insert_many(event_list).on_conflict('ignore')\r\n```\r\n\r\nAssuming event_list was a list of dictionaries."
] | 2017-07-05T04:06:35 | 2018-07-26T13:06:48 | 2018-01-08T10:28:10 | OWNER | null | I'd like to consolidate the discussions in #942 and #1067 as they both concern extensions to basic INSERT and UPDATE queries. In this ticket I'll describe the various features and syntaxes Peewee will need to support -- please let me know if I've missed something!
---------------------------
### SQLite
[Docs](https://sqlite.org/lang_conflict.html).
* `INSERT OR <REPLACE|ROLLBACK|ABORT|FAIL|IGNORE> INTO ...`
* `REPLACE INTO ...` (as a shortcut for `INSERT OR REPLACE`).
These extra clauses are referred to in the docs as the [ON CONFLICT CLAUSE](https://sqlite.org/lang_conflict.html). We are only interested in the `IGNORE` and `REPLACE` strategies. Here's how `REPLACE` works:
> When a UNIQUE or PRIMARY KEY constraint violation occurs, the REPLACE algorithm deletes pre-existing rows that are causing the constraint violation prior to inserting or updating the current row and the command continues executing normally. If a NOT NULL constraint violation occurs, the REPLACE conflict resolution replaces the NULL value with the default value for that column, or if the column has no default value, then the ABORT algorithm is used. If a CHECK constraint violation occurs, the REPLACE conflict resolution algorithm always works like ABORT.
### MySQL
[Docs](https://dev.mysql.com/doc/refman/5.7/en/insert-on-duplicate.html).
* `INSERT IGNORE`
* `REPLACE INTO ...`
* `INSERT INTO ... ON DUPLICATE KEY UPDATE ...`
The last one is different from SQLite as it allows the user to specify a different query in the event of a conflict. Here's an example:
```sql
INSERT INTO table (a,b,c) VALUES (1,2,3)
ON DUPLICATE KEY UPDATE c=c+1;
```
No special syntax seems to be needed to reference the column value of the conflicting row. To reference the value from the `INSERT` portion of the query you can use the `VALUES()` function. I believe the following would be equivalent to a `REPLACE` if the only constraint on the table was on column `a`:
```sql
INSERT INTO table (a,b,c) VALUES (1, 2, 3)
ON DUPLICATE KEY UPDATE b = VALUES(b), c = VALUES(c)
```
### Postgresql
[Docs](https://www.postgresql.org/docs/9.5/static/sql-insert.html#SQL-ON-CONFLICT).
* `INSERT INTO ... ON CONFLICT DO NOTHING`
* `INSERT INTO ... ON CONFLICT (conflict_target) DO UPDATE SET ...`
Postgresql's upsert looks to be the most sophisticated, as you need to specify a conflict target to do an update. The conflict target description in the docs is very confusing but it seems to work fine if you just pass in the list of columns that have the appropriate constraint. You can also reference the value of the conflicting row using `EXCLUDED`.
Examples:
```sql
INSERT INTO distributors (did, dname)
VALUES (5, 'Gizmo Transglobal'), (6, 'Associated Computing, Inc')
ON CONFLICT (did) DO UPDATE SET dname = EXCLUDED.dname;
-- Don't update existing distributors based in a certain ZIP code
INSERT INTO distributors AS d (did, dname) VALUES (8, 'Anvil Distribution')
ON CONFLICT (did) DO UPDATE
SET dname = EXCLUDED.dname || ' (formerly ' || d.dname || ')'
WHERE d.zipcode <> '21201';
-- Name a constraint directly in the statement (uses associated
-- index to arbitrate taking the DO NOTHING action)
INSERT INTO distributors (did, dname) VALUES (9, 'Antwerp Design')
ON CONFLICT ON CONSTRAINT distributors_pkey DO NOTHING;
-- This statement could infer a partial unique index on "did"
-- with a predicate of "WHERE is_active", but it could also
-- just use a regular unique constraint on "did"
INSERT INTO distributors (did, dname) VALUES (10, 'Conrad International')
ON CONFLICT (did) WHERE is_active DO NOTHING;
``` | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1307/reactions",
"total_count": 6,
"+1": 6,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1307/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1306 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1306/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1306/comments | https://api.github.com/repos/coleifer/peewee/issues/1306/events | https://github.com/coleifer/peewee/issues/1306 | 240,437,838 | MDU6SXNzdWUyNDA0Mzc4Mzg= | 1,306 | No such module: FTS4 | {
"login": "Billmike",
"id": 24798364,
"node_id": "MDQ6VXNlcjI0Nzk4MzY0",
"avatar_url": "https://avatars.githubusercontent.com/u/24798364?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/Billmike",
"html_url": "https://github.com/Billmike",
"followers_url": "https://api.github.com/users/Billmike/followers",
"following_url": "https://api.github.com/users/Billmike/following{/other_user}",
"gists_url": "https://api.github.com/users/Billmike/gists{/gist_id}",
"starred_url": "https://api.github.com/users/Billmike/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/Billmike/subscriptions",
"organizations_url": "https://api.github.com/users/Billmike/orgs",
"repos_url": "https://api.github.com/users/Billmike/repos",
"events_url": "https://api.github.com/users/Billmike/events{/privacy}",
"received_events_url": "https://api.github.com/users/Billmike/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"You don't have the SQLite FTS4 extension. You'll need to either compile it as a standalone and load it at run-time, or recompile SQLite with full-text search feature enabled. https://sqlite.org/fts3.html",
"Hello, I am using Anaconda with Python 3.7, how can I install FTS4 extension?",
"I'd suggest asking anaconda."
] | 2017-07-04T14:32:44 | 2019-02-27T21:13:50 | 2017-07-05T05:02:32 | NONE | null | Traceback (most recent call last):
File "app.py", line 88, in <module>
main()
File "app.py", line 84, in main
database.create_tables([Entry, FTSEntry], safe=True)
File "C:\Users\Billmike\Documents\charlesblog\blog\lib\site-packages\peewee.py", line 3855, in create_tables
create_model_tables(models, fail_silently=safe)
File "C:\Users\Billmike\Documents\charlesblog\blog\lib\site-packages\peewee.py", line 5294, in create_model_tables
m.create_table(**create_table_kwargs)
File "C:\Users\Billmike\Documents\charlesblog\blog\lib\site-packages\playhouse\sqlite_ext.py", line 243, in create_table
cls._meta.database.create_table(cls, options=options)
File "C:\Users\Billmike\Documents\charlesblog\blog\lib\site-packages\playhouse\sqlite_ext.py", line 970, in create_table
return self.execute_sql(sql, params)
File "C:\Users\Billmike\Documents\charlesblog\blog\lib\site-packages\peewee.py", line 3775, in execute_sql
self.commit()
File "C:\Users\Billmike\Documents\charlesblog\blog\lib\site-packages\peewee.py", line 3598, in __exit__
reraise(new_type, new_type(*exc_args), traceback)
File "C:\Users\Billmike\Documents\charlesblog\blog\lib\site-packages\peewee.py", line 3768, in execute_sql
cursor.execute(sql, params or ())
peewee.OperationalError: no such module: FTS4 | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1306/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1306/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1305 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1305/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1305/comments | https://api.github.com/repos/coleifer/peewee/issues/1305/events | https://github.com/coleifer/peewee/issues/1305 | 240,375,012 | MDU6SXNzdWUyNDAzNzUwMTI= | 1,305 | support on duplicate key update and insert ignore | {
"login": "huangzhw",
"id": 3366133,
"node_id": "MDQ6VXNlcjMzNjYxMzM=",
"avatar_url": "https://avatars.githubusercontent.com/u/3366133?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/huangzhw",
"html_url": "https://github.com/huangzhw",
"followers_url": "https://api.github.com/users/huangzhw/followers",
"following_url": "https://api.github.com/users/huangzhw/following{/other_user}",
"gists_url": "https://api.github.com/users/huangzhw/gists{/gist_id}",
"starred_url": "https://api.github.com/users/huangzhw/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/huangzhw/subscriptions",
"organizations_url": "https://api.github.com/users/huangzhw/orgs",
"repos_url": "https://api.github.com/users/huangzhw/repos",
"events_url": "https://api.github.com/users/huangzhw/events{/privacy}",
"received_events_url": "https://api.github.com/users/huangzhw/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"duplicate of #1067"
] | 2017-07-04T10:09:00 | 2017-07-05T03:41:49 | 2017-07-05T03:41:49 | NONE | null | Can peewee support on duplicate key update and insert ignore in MySQL, it is really useful. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1305/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1305/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1304 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1304/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1304/comments | https://api.github.com/repos/coleifer/peewee/issues/1304/events | https://github.com/coleifer/peewee/issues/1304 | 240,058,992 | MDU6SXNzdWUyNDAwNTg5OTI= | 1,304 | [idea] New <SelectQuery> method: namedtuples() | {
"login": "ak4nv",
"id": 73960,
"node_id": "MDQ6VXNlcjczOTYw",
"avatar_url": "https://avatars.githubusercontent.com/u/73960?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/ak4nv",
"html_url": "https://github.com/ak4nv",
"followers_url": "https://api.github.com/users/ak4nv/followers",
"following_url": "https://api.github.com/users/ak4nv/following{/other_user}",
"gists_url": "https://api.github.com/users/ak4nv/gists{/gist_id}",
"starred_url": "https://api.github.com/users/ak4nv/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/ak4nv/subscriptions",
"organizations_url": "https://api.github.com/users/ak4nv/orgs",
"repos_url": "https://api.github.com/users/ak4nv/repos",
"events_url": "https://api.github.com/users/ak4nv/events{/privacy}",
"received_events_url": "https://api.github.com/users/ak4nv/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Added here: 13c15c3a8e086939184c3b885f3dbb4d057b68a5\r\n\r\nThis functionality is provided in the 3.0 branch (not yet public) as well."
] | 2017-07-03T03:26:33 | 2017-07-05T03:40:14 | 2017-07-05T03:40:14 | NONE | null | Like `dicts()` or `tuples()`, this method returns a result as tuple of `collection.namedtuple` objects. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1304/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1304/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1303 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1303/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1303/comments | https://api.github.com/repos/coleifer/peewee/issues/1303/events | https://github.com/coleifer/peewee/pull/1303 | 239,988,658 | MDExOlB1bGxSZXF1ZXN0MTI4NTA5MjUy | 1,303 | Modify add foreign key constraint. | {
"login": "EenTang",
"id": 16539902,
"node_id": "MDQ6VXNlcjE2NTM5OTAy",
"avatar_url": "https://avatars.githubusercontent.com/u/16539902?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/EenTang",
"html_url": "https://github.com/EenTang",
"followers_url": "https://api.github.com/users/EenTang/followers",
"following_url": "https://api.github.com/users/EenTang/following{/other_user}",
"gists_url": "https://api.github.com/users/EenTang/gists{/gist_id}",
"starred_url": "https://api.github.com/users/EenTang/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/EenTang/subscriptions",
"organizations_url": "https://api.github.com/users/EenTang/orgs",
"repos_url": "https://api.github.com/users/EenTang/repos",
"events_url": "https://api.github.com/users/EenTang/events{/privacy}",
"received_events_url": "https://api.github.com/users/EenTang/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"0137c5eb12172b1c127239f58ccbc98fbbbda982"
] | 2017-07-02T04:47:40 | 2018-01-31T12:36:14 | 2018-01-31T12:36:14 | NONE | null | Modify add foreign key constraint: support constraint type restrict and cascade | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1303/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1303/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/1303",
"html_url": "https://github.com/coleifer/peewee/pull/1303",
"diff_url": "https://github.com/coleifer/peewee/pull/1303.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/1303.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/1302 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1302/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1302/comments | https://api.github.com/repos/coleifer/peewee/issues/1302/events | https://github.com/coleifer/peewee/issues/1302 | 239,630,990 | MDU6SXNzdWUyMzk2MzA5OTA= | 1,302 | Foreign Key "ID descriptor" name incorrect when using `db_column` | {
"login": "ibushong",
"id": 9298422,
"node_id": "MDQ6VXNlcjkyOTg0MjI=",
"avatar_url": "https://avatars.githubusercontent.com/u/9298422?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/ibushong",
"html_url": "https://github.com/ibushong",
"followers_url": "https://api.github.com/users/ibushong/followers",
"following_url": "https://api.github.com/users/ibushong/following{/other_user}",
"gists_url": "https://api.github.com/users/ibushong/gists{/gist_id}",
"starred_url": "https://api.github.com/users/ibushong/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/ibushong/subscriptions",
"organizations_url": "https://api.github.com/users/ibushong/orgs",
"repos_url": "https://api.github.com/users/ibushong/repos",
"events_url": "https://api.github.com/users/ibushong/events{/privacy}",
"received_events_url": "https://api.github.com/users/ibushong/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I definitely understand your confusion, and likely the docs aren't clear on this point.\r\n\r\nInside `ForeignKeyField.add_to_class()` you can see that the \"id descriptor\" gets its attribute from the db_column (if set) and otherwise will be the field's name + \"_id\":\r\n\r\n```python\r\n self.db_column = obj_id_name = self.db_column or '%s_id' % self.name\r\n if obj_id_name == self.name:\r\n obj_id_name += '_id'\r\n```\r\n\r\nSo what you're seeing is correct according to the above logic.",
"Yeah, I eventually found that. I guess I just felt that if you're \"renaming\" a foreign key field, then both the name-descriptor and id-descriptor values would change accordingly. My goal in the example was to entirely replace the usage of place/place_id with venue/venue_id (without having to rename the actual database column). When I'm thinking about the venue FK, I want to hide/abstract-away the fact that under the hood it's actually referencing the `place_id` column.\r\n",
"I don't want to break backwards compatibility in case anyone was relying on the behavior described in your issue, *however* I've added a new parameter to `ForeignKeyField` that allows you to specify the name of the \"object id descriptor\". Your declaration would read:\r\n\r\n```python\r\nvenue = ForeignKeyField(Venue, db_column='place_id', object_id_name='venue_id')\r\n```",
"Awesome. That's a good solution. Thanks!"
] | 2017-06-29T22:40:05 | 2017-07-05T23:46:39 | 2017-07-05T05:00:53 | NONE | null | ```python
class Event(BaseModel):
venue = ForeignKeyField(Venue, db_column='place_id')
...
Event.select().where(Event.venue == 5) # this works fine
Event.select().where(Event.venue_id == 5) # --> AttributeError: type object 'Event' has no attribute 'venue_id'
Event.select().where(Event.place_id == 5) # --> This is successful, though, IMO, the above expression should be the correct one.
```
Hmm actually I guess I could see this being "correct". But just wanted to make sure it was expected. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1302/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1302/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1301 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1301/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1301/comments | https://api.github.com/repos/coleifer/peewee/issues/1301/events | https://github.com/coleifer/peewee/issues/1301 | 238,601,474 | MDU6SXNzdWUyMzg2MDE0NzQ= | 1,301 | can not use ArrayField when I imort PostgresqlExtDatabase? | {
"login": "wdrich",
"id": 358416,
"node_id": "MDQ6VXNlcjM1ODQxNg==",
"avatar_url": "https://avatars.githubusercontent.com/u/358416?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/wdrich",
"html_url": "https://github.com/wdrich",
"followers_url": "https://api.github.com/users/wdrich/followers",
"following_url": "https://api.github.com/users/wdrich/following{/other_user}",
"gists_url": "https://api.github.com/users/wdrich/gists{/gist_id}",
"starred_url": "https://api.github.com/users/wdrich/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/wdrich/subscriptions",
"organizations_url": "https://api.github.com/users/wdrich/orgs",
"repos_url": "https://api.github.com/users/wdrich/repos",
"events_url": "https://api.github.com/users/wdrich/events{/privacy}",
"received_events_url": "https://api.github.com/users/wdrich/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Um...are you referencing `ArrayField` somewhere in your module? `ArrayField` is defined in `playhouse.postgres_ext` so to use it you'll need to import it along with `PostgresqlExtDatabase`.",
"after that, I import ArrayField with:\r\nfrom playhouse.postgres_ext import ArrayField\r\n\r\nthat say:\"peewee.ProgrammingError: hstore type not found in the database. please install it from your 'contrib/hstore.sql' file\"\r\n\r\nthanks\r\n",
"other wise:\r\nI did not use 'hstore'",
"That is ok, NOW!!\r\n\r\ni forgot add hstore extension\r\nuse ‘ create extension hstore’\r\n"
] | 2017-06-26T16:40:40 | 2017-06-27T07:51:02 | 2017-06-27T07:51:02 | NONE | null | when I import PostgresqlExtDatabase like this:
from playhouse.postgres_ext import PostgresqlExtDatabase
that say:"NameError: name 'ArrayField' is not defined"
thanks | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1301/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1301/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1300 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1300/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1300/comments | https://api.github.com/repos/coleifer/peewee/issues/1300/events | https://github.com/coleifer/peewee/issues/1300 | 238,387,898 | MDU6SXNzdWUyMzgzODc4OTg= | 1,300 | Idea: Table prefixing | {
"login": "tomvlk",
"id": 3877688,
"node_id": "MDQ6VXNlcjM4Nzc2ODg=",
"avatar_url": "https://avatars.githubusercontent.com/u/3877688?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/tomvlk",
"html_url": "https://github.com/tomvlk",
"followers_url": "https://api.github.com/users/tomvlk/followers",
"following_url": "https://api.github.com/users/tomvlk/following{/other_user}",
"gists_url": "https://api.github.com/users/tomvlk/gists{/gist_id}",
"starred_url": "https://api.github.com/users/tomvlk/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/tomvlk/subscriptions",
"organizations_url": "https://api.github.com/users/tomvlk/orgs",
"repos_url": "https://api.github.com/users/tomvlk/repos",
"events_url": "https://api.github.com/users/tomvlk/events{/privacy}",
"received_events_url": "https://api.github.com/users/tomvlk/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"To customize the table name on a one-off basis, you set the `db_table` option on the model's inner `Meta` class.\r\n\r\nTo set the table name dynamically, you can actually specify a different `Meta` attribute `db_table_func`. This should be a callable that receives the newly-created `Model` class, and returns a string to use as the table name.\r\n\r\nI think this should probably accomplish what you want."
] | 2017-06-25T15:38:01 | 2017-06-26T00:22:26 | 2017-06-26T00:22:26 | NONE | null | Hello there,
First of all thanks for the simple and yet so powerful ORM!
I got one of our users that is asking if I can provide database table prefix configuration for my application. The application I'm talking about is PyPlanet, (issue from the user: https://github.com/PyPlanet/PyPlanet/issues/378).
I can most probably fix this myself with some kind of hacky method that will override the table name generation, but instead it would be cool to have this feature in Peewee itself where you can give the option to prefix all the tables with a prefix given in a configuration. (Also, I don't really want to hack this deep in Peewee).
I'm curious how you think about the idea. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1300/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1300/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1299 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1299/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1299/comments | https://api.github.com/repos/coleifer/peewee/issues/1299/events | https://github.com/coleifer/peewee/issues/1299 | 238,382,512 | MDU6SXNzdWUyMzgzODI1MTI= | 1,299 | utf8 stored inside BlobField errors | {
"login": "maugch",
"id": 6808345,
"node_id": "MDQ6VXNlcjY4MDgzNDU=",
"avatar_url": "https://avatars.githubusercontent.com/u/6808345?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/maugch",
"html_url": "https://github.com/maugch",
"followers_url": "https://api.github.com/users/maugch/followers",
"following_url": "https://api.github.com/users/maugch/following{/other_user}",
"gists_url": "https://api.github.com/users/maugch/gists{/gist_id}",
"starred_url": "https://api.github.com/users/maugch/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/maugch/subscriptions",
"organizations_url": "https://api.github.com/users/maugch/orgs",
"repos_url": "https://api.github.com/users/maugch/repos",
"events_url": "https://api.github.com/users/maugch/events{/privacy}",
"received_events_url": "https://api.github.com/users/maugch/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I'm not quite following...if you're just looking to store text (encoded as UTF-8), the proper field to use is the `TextField`.\r\n\r\nCan you try modifying your code to use `TextField` instead of `BlobField` and see if that resolves the issue?",
"Yes TextField works indeed. I think pwiz generated it as BlobField. I thought it was right since it can be huge. I am not sure now if the behaviour when it's BlobField is correct though.\r\n",
"Glad it's working."
] | 2017-06-25T14:06:25 | 2017-06-26T18:10:12 | 2017-06-26T18:10:12 | NONE | null | I have a database TEXT field stored as utf8mb4 on mysql which is translated to
`description = BlobField(db_column='description', null=True)`
I tried to use the model and store data interactively without any problem. When I use the model in my program, I get :
```
Traceback (most recent call last):
File "getSqlliteData.py", line 91, in <module>
main()
File "getSqlliteData.py", line 73, in main
getStuffFromJson(item,id_recipe)
File "/home/me/wp/python/database.py", line 244, in getRecipeFromJson
recipe.save()
File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 4971, in save
rows = self.update(**field_dict).where(self._pk_expr()).execute()
File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 3303, in execute
return self.database.rows_affected(self._execute())
File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 2820, in _execute
return self.database.execute_sql(sql, params, self.require_commit)
File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 3677, in execute_sql
self.commit()
File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 3501, in __exit__
reraise(new_type, new_type(*exc_args), traceback)
File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 3670, in execute_sql
cursor.execute(sql, params or ())
File "/usr/lib/python2.7/dist-packages/MySQLdb/cursors.py", line 226, in execute
self.errorhandler(self, exc, value)
File "/usr/lib/python2.7/dist-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
raise errorvalue
peewee.OperationalError: (1366, "Incorrect string value: '\\xA0 \\x0A ...' for column 'description' at row 1")
```
The error comes when I try to update a row on the DB. Note that it does happen even if I do a get() and then a save(), which means I get my utf8 string from the database and then try to put it back on it with 0 changes (I should avoid that, but I'm still learning).
I think there is a problem on how data are stored on my Model, possibly a bug in peewee?
In order to avoid it, before i save() my object, I added the following two lines:
```python
if myitem.description is not None:
myitem.description = u' '.join(myitem.description).encode('utf-8').strip()
```
I'm not sure how to write a simple test case. Is this description enough? | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1299/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1299/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1298 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1298/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1298/comments | https://api.github.com/repos/coleifer/peewee/issues/1298/events | https://github.com/coleifer/peewee/issues/1298 | 237,547,233 | MDU6SXNzdWUyMzc1NDcyMzM= | 1,298 | mypy type hints | {
"login": "mkurnikov",
"id": 2341827,
"node_id": "MDQ6VXNlcjIzNDE4Mjc=",
"avatar_url": "https://avatars.githubusercontent.com/u/2341827?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/mkurnikov",
"html_url": "https://github.com/mkurnikov",
"followers_url": "https://api.github.com/users/mkurnikov/followers",
"following_url": "https://api.github.com/users/mkurnikov/following{/other_user}",
"gists_url": "https://api.github.com/users/mkurnikov/gists{/gist_id}",
"starred_url": "https://api.github.com/users/mkurnikov/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/mkurnikov/subscriptions",
"organizations_url": "https://api.github.com/users/mkurnikov/orgs",
"repos_url": "https://api.github.com/users/mkurnikov/repos",
"events_url": "https://api.github.com/users/mkurnikov/events{/privacy}",
"received_events_url": "https://api.github.com/users/mkurnikov/received_events",
"type": "User",
"site_admin": false
} | [] | closed | true | null | [] | null | [
"No, type hints are, in my opinion, an abomination that has no business being part of the Python language :)",
"May I at least add peewee's .pyi stubs to python/typeshed repository? ",
"Anything you would like to do is totally fine by me, as the license for the software is permissive. I just do not want to merge anything into mainline that concerns type hinting.",
"@coleifer I'm expecting you will make a deal with static typing fans more and more. I'm partially agree you can do nothing in orm itself and should not, but you should try to understand `static dynamic` fans. Its not about limiting dynamism or to make new java from python, people just want `user.(name/id/group)` in IDE, they are tired to go from view to model definition, to 'google' any functions signature, to debug typo mistakes in runtime. \r\n\r\nGo has no objects and generics, and any data structure should upcast value to `interface{}`, C is just too low-level. You should check out [typeorm](http://typeorm.io/) and [diesel](http://diesel.rs/), Dart. \r\nStatic typing was stigmatized long time as a way to make compilable, fast languages like java, cpp. It has different purpose in dynamic languages now.",
"> I'm expecting you will make a deal with static typing fans more and more.\r\n\r\nNo way. Python is a powerful dynamic language. If I want static typing or a strong type system I will use C or go...or hell, Cython. I enjoy coding in those languages, too, but if I'm using Python I'm going to play to it's strengths.\r\n\r\n> IDE\r\n\r\nPeewee's design goals are composability and consistency -- learn once, apply everywhere -- precisely so that peewee will \"do what you expect\" without needing to check the docs.",
"@coleifer I'm not a strong proponent of Static Typing, but the type annotations are extremely useful when developing to help catch bugs. I debug enough Python at runtime, the more I can do to reduce that, the better.\r\n\r\nMypy is optional, you can choose to put annotations on things, for clarity. If the inclusion of these things only ever produces net gain, why not apply them. It's not an either-or camp. The degree to which you add Static Types is varying.\r\n\r\nSurely you can see the point of view of why Type annotations may be extremely useful? And in no ways detracts from the power and flexibility of Python by its inclusion.\r\n",
"Sorry to necro this thread but in my experience I've also noticed that type hints can also add a significant performance boost (sometimes >20%) since Cython can now use them for type inference. Granted, performance benefits aren't _guaranteed_ but they are likely. I see you have Cython support set up for PeeWee so it's entirely possible its performance could benefit from it.",
"Hi @coleifer,\r\n\r\nYou've done a great job with this lib. With or without type hints, it's nice to use.\r\n\r\nBut if someday you change your mind about type hints, I believe it won't hurt.",
"> No, type hints are, in my opinion, an abomination that has no business being part of the Python language :)\r\n\r\nAs a maintainer of typeshed, a big repository that is all about typing in Python, I think this is a perfectly valid opinion! I felt the same when I first learned about typing in Python. It shouldn't be something that library authors have to do, and it's optional by design.",
"This issue was opened nearly 5 years ago. In that time I've had plenty of opportunities to see python's type hinting in the wild. I still believe that it misses the mark, offerning none of the iron-clad guarantees you get from a statically-typed language, while being injurious to Python's inherent dynamism, readability, and simplicity. Since this issue tends to attract drive-by comments of little value, I'm going to close discussion for now.\r\n\r\nWhen I want static typing I reach for a statically-typed language. When I want expressiveness, simplicity and flexibility, I reach for Python."
] | 2017-06-21T14:08:34 | 2022-02-21T13:51:46 | 2017-06-21T16:19:25 | NONE | too heated | Will you accept inline type hints for the peewee like
```
# type: () -> None
```
as PR? | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1298/reactions",
"total_count": 6,
"+1": 6,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1298/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1297 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1297/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1297/comments | https://api.github.com/repos/coleifer/peewee/issues/1297/events | https://github.com/coleifer/peewee/issues/1297 | 236,902,903 | MDU6SXNzdWUyMzY5MDI5MDM= | 1,297 | flask note-taking app FTSModel classes must use the default `docid` primary key.' | {
"login": "quah6o",
"id": 29545530,
"node_id": "MDQ6VXNlcjI5NTQ1NTMw",
"avatar_url": "https://avatars.githubusercontent.com/u/29545530?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/quah6o",
"html_url": "https://github.com/quah6o",
"followers_url": "https://api.github.com/users/quah6o/followers",
"following_url": "https://api.github.com/users/quah6o/following{/other_user}",
"gists_url": "https://api.github.com/users/quah6o/gists{/gist_id}",
"starred_url": "https://api.github.com/users/quah6o/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/quah6o/subscriptions",
"organizations_url": "https://api.github.com/users/quah6o/orgs",
"repos_url": "https://api.github.com/users/quah6o/repos",
"events_url": "https://api.github.com/users/quah6o/events{/privacy}",
"received_events_url": "https://api.github.com/users/quah6o/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Ahh yeah, the code is probably a bit out-dated and does not reflect what I've since learned about some best practices for the full-text search extension. Let me see about updating things.",
"Ahh shit, I see I already left a note on code compatibility at the top of the post. I'm going to leave this alone for now, as I don't have time to go back through the code to update it all. Apologies for leaving you hanging -- I'll try to post an update, and when I do I'll update this ticket.",
"Ah I should read more carefully. I will use a older version for now. Thanks!"
] | 2017-06-19T14:07:17 | 2017-06-19T18:05:45 | 2017-06-19T17:09:43 | NONE | null | Hello together,
I'm new to python and only have a few basic programming skills.
I found this tutorial which creates a [flask note-taking app](http://charlesleifer.com/blog/saturday-morning-hacks-adding-full-text-search-to-the-flask-note-taking-app/). It is seperated in three steps. The first two steps work without any problems.
The complete project can be downloaded in [this gist](https://gist.github.com/coleifer/d93d6c43e59698d149c0).
But when I run the third step now, the following happens:
(.p2) qua@mbp:0:~/python/flask-note-v3$ python main.py
Traceback (most recent call last):
File "main.py", line 5, in <module>
from models import FTSNote
File "/Users/qua/python/flask-note-v3/models.py", line 125, in <module>
class FTSNote(FTSModel):
File "/Users/qua/.p2/lib/python2.7/site-packages/peewee.py", line 4855, in __new__
cls.validate_model()
File "/Users/qua/.p2/lib/python2.7/site-packages/playhouse/sqlite_ext.py", line 281, in validate_model
'FTSModel classes must use the default `docid` primary key.')
peewee.ImproperlyConfigured: FTSModel classes must use the default `docid` primary key.
(.p2) qua@mbp:1:~/python/flask-note-v3$ python app.py
(.p2) qua@mbp:0:~/python/flask-note-v3$
I try to get this project working and modify it to suit my needs. By that I hope learning a bit more of python.
Can you help me? (I already asked this on /r/learnprogramming/)
Regards,
Qua | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1297/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1297/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1296 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1296/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1296/comments | https://api.github.com/repos/coleifer/peewee/issues/1296/events | https://github.com/coleifer/peewee/issues/1296 | 236,796,341 | MDU6SXNzdWUyMzY3OTYzNDE= | 1,296 | Packet sequence number wrong - got 2 expected 1 to due to PyMySQL | {
"login": "kadnan",
"id": 273196,
"node_id": "MDQ6VXNlcjI3MzE5Ng==",
"avatar_url": "https://avatars.githubusercontent.com/u/273196?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/kadnan",
"html_url": "https://github.com/kadnan",
"followers_url": "https://api.github.com/users/kadnan/followers",
"following_url": "https://api.github.com/users/kadnan/following{/other_user}",
"gists_url": "https://api.github.com/users/kadnan/gists{/gist_id}",
"starred_url": "https://api.github.com/users/kadnan/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/kadnan/subscriptions",
"organizations_url": "https://api.github.com/users/kadnan/orgs",
"repos_url": "https://api.github.com/users/kadnan/repos",
"events_url": "https://api.github.com/users/kadnan/events{/privacy}",
"received_events_url": "https://api.github.com/users/kadnan/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"If you're trying to pass arguments into the pymysql constructor, just pass them in as keyword arguments to the `MySQLDatabase` initialization method. They'll get passed back to the database driver.",
"e.g. `MySQLDatabase(..., threadsafety=1)`",
"@coleifer \r\n\r\nGot exception:\r\n\r\n```\r\nFile \"/anaconda3/anaconda/lib/python3.5/site-packages/peewee.py\", line 3708, in _create_connection\r\n return self._connect(self.database, **self.connect_kwargs)\r\n File \"/anaconda3/anaconda/lib/python3.5/site-packages/peewee.py\", line 4256, in _connect\r\n return mysql.connect(db=database, **conn_kwargs)\r\n File \"/anaconda3/anaconda/lib/python3.5/site-packages/pymysql/__init__.py\", line 90, in Connect\r\n return Connection(*args, **kwargs)\r\nTypeError: __init__() got an unexpected keyword argument 'threadsafety'\r\n```\r\n\r\nThis is how I did:\r\n\r\n```\r\ndbhandle = MySQLDatabase(\r\n db_name, user=user,\r\n password=password,\r\n host=host,\r\n threadsafety=3\r\n)\r\n```",
"I have no idea then, but whatever the case, the issue is not with Peewee.",
"@kadnan 您好,我也遇到了这样的问题,请问您是怎么解决的呢?"
] | 2017-06-19T06:58:32 | 2020-06-01T07:31:12 | 2017-06-19T17:07:17 | NONE | null | I am using `PyMySQL` and they have discussed this problem [here](https://github.com/PyMySQL/PyMySQL/issues/422). They asked to set `threadsafety`. How to change value of `threadsafety`, if that is the issue? How do I do it in `peewee` as my app is multi-process and having a pool of two processes like this:
```
with Pool(2) as p:
result = p.map(parse, links)
```
**Update**
My Code Look like this:
```
from peewee import *
import datetime
import xmltodict
settings = None
with open('../settings.xml') as f:
settings = f.read()
config = xmltodict.parse(settings)
user = config['config']['database']['user']
password = config['config']['database']['password']
db_name = config['config']['database']['name']
host = config['config']['database']['host']
dbhandle = MySQLDatabase(
db_name, user=user,
password=password,
host=host
)
dbhandle.connect()
class BaseModel(Model):
class Meta:
database = dbhandle
class Links(BaseModel):
id = PrimaryKeyField(null=False)
url = CharField(max_length=255, default='')
duration = IntegerField(default=0)
status = IntegerField(
default=0) #
updated_at = DateTimeField(default=datetime.datetime.now)
class Meta:
db_table = "my_links"
order_by = ('updated_at',)
```
**MySQL Threads status**
```
mysql> show global status like '%thread%';
+------------------------------------------+-------+
| Variable_name | Value |
+------------------------------------------+-------+
| AuroraDb_thread_deadlocks | 0 |
| Delayed_insert_threads | 0 |
| Performance_schema_thread_classes_lost | 0 |
| Performance_schema_thread_instances_lost | 0 |
| Slow_launch_threads | 0 |
| Threads_cached | 0 |
| Threads_connected | 5 |
| Threads_created | 10 |
| Threads_running | 1 |
+------------------------------------------+-------+
9 rows in set (0.00 sec)
mysql> show global variables like '%thread%';
+-----------------------------------------+---------------------------------+
| Variable_name | Value |
+-----------------------------------------+---------------------------------+
| innodb_purge_threads | 1 |
| innodb_read_io_threads | 4 |
| innodb_thread_concurrency | 0 |
| innodb_thread_sleep_delay | 10000 |
| innodb_write_io_threads | 4 |
| max_delayed_threads | 20 |
| max_insert_delayed_threads | 20 |
| myisam_repair_threads | 1 |
| performance_schema_max_thread_classes | 50 |
| performance_schema_max_thread_instances | -1 |
| thread_cache_size | 0 |
| thread_concurrency | 10 |
| thread_handling | multiple-connections-per-thread |
| thread_stack | 262144 |
+-----------------------------------------+---------------------------------+
14 rows in set (0.00 sec)
``` | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1296/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1296/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1295 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1295/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1295/comments | https://api.github.com/repos/coleifer/peewee/issues/1295/events | https://github.com/coleifer/peewee/issues/1295 | 236,765,603 | MDU6SXNzdWUyMzY3NjU2MDM= | 1,295 | pwiz fails with cross-schema foreign keys | {
"login": "albireox",
"id": 568775,
"node_id": "MDQ6VXNlcjU2ODc3NQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/568775?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/albireox",
"html_url": "https://github.com/albireox",
"followers_url": "https://api.github.com/users/albireox/followers",
"following_url": "https://api.github.com/users/albireox/following{/other_user}",
"gists_url": "https://api.github.com/users/albireox/gists{/gist_id}",
"starred_url": "https://api.github.com/users/albireox/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/albireox/subscriptions",
"organizations_url": "https://api.github.com/users/albireox/orgs",
"repos_url": "https://api.github.com/users/albireox/repos",
"events_url": "https://api.github.com/users/albireox/events{/privacy}",
"received_events_url": "https://api.github.com/users/albireox/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Sorry, no plans to support that.",
"Is this supported now?"
] | 2017-06-19T02:30:21 | 2022-08-24T03:33:10 | 2017-06-19T17:04:30 | NONE | null | Not sure if there is a solution for this, but I'm trying to run pwiz on a schema that as foreign keys referencing other schema in the same DB. pwiz fails with
```
Traceback (most recent call last):
File "/Users/albireo/.pyenv/versions/3.6.1/bin/pwiz.py", line 201, in <module>
print_models(introspector, tables, preserve_order=options.preserve_order)
File "/Users/albireo/.pyenv/versions/3.6.1/bin/pwiz.py", line 47, in print_models
database = introspector.introspect(table_names=tables)
File "/Users/albireo/.pyenv/versions/3.6.1/Python.framework/Versions/3.6/lib/python3.6/site-packages/playhouse/reflection.py", line 520, in introspect
src = columns[foreign_key.table][foreign_key.column]
KeyError: 'platedb_plate_pk'
```
where `platedb_plate_pk` is one of the columns that are a foreign key to a column on a different schema. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1295/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1295/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1294 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1294/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1294/comments | https://api.github.com/repos/coleifer/peewee/issues/1294/events | https://github.com/coleifer/peewee/issues/1294 | 236,345,089 | MDU6SXNzdWUyMzYzNDUwODk= | 1,294 | Checking record exist | {
"login": "kadnan",
"id": 273196,
"node_id": "MDQ6VXNlcjI3MzE5Ng==",
"avatar_url": "https://avatars.githubusercontent.com/u/273196?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/kadnan",
"html_url": "https://github.com/kadnan",
"followers_url": "https://api.github.com/users/kadnan/followers",
"following_url": "https://api.github.com/users/kadnan/following{/other_user}",
"gists_url": "https://api.github.com/users/kadnan/gists{/gist_id}",
"starred_url": "https://api.github.com/users/kadnan/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/kadnan/subscriptions",
"organizations_url": "https://api.github.com/users/kadnan/orgs",
"repos_url": "https://api.github.com/users/kadnan/repos",
"events_url": "https://api.github.com/users/kadnan/events{/privacy}",
"received_events_url": "https://api.github.com/users/kadnan/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"ffs man documentation\r\n\r\n* http://docs.peewee-orm.com/en/latest/peewee/api.html#SelectQuery.exists\r\n* http://docs.peewee-orm.com/en/latest/peewee/api.html#SelectQuery.count",
"I was searching for the same thing (I don't usually RTFM right away either). Just to let you know that your links don't take you to the right place on the page as I assume the # is supposed to do.",
"* http://docs.peewee-orm.com/en/latest/peewee/api.html#SelectBase.exists\r\n* http://docs.peewee-orm.com/en/latest/peewee/api.html#SelectBase.count\r\n\r\ntl/dr\r\n\r\n```python\r\n\r\nquery = User.select().where(User.username == 'reads-the-manual')\r\nif query.exists():\r\n print('there are %s users who %s' (query.count(), 'read the manual'))\r\n```",
"Funny thing is that I had to google something similar after 4 years and I found my own opened issue 😆 ",
"Hell yeah. I've had that happen once or twice myself."
] | 2017-06-15T23:56:58 | 2021-02-14T14:10:48 | 2017-06-16T03:26:24 | NONE | null | I know about exception thrown in this regard, just want to know whether there's some `count` or `exists()` method to check whether some record returned or not? | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1294/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1294/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1293 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1293/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1293/comments | https://api.github.com/repos/coleifer/peewee/issues/1293/events | https://github.com/coleifer/peewee/issues/1293 | 236,132,798 | MDU6SXNzdWUyMzYxMzI3OTg= | 1,293 | get() raising exception | {
"login": "rrzaripov",
"id": 6154870,
"node_id": "MDQ6VXNlcjYxNTQ4NzA=",
"avatar_url": "https://avatars.githubusercontent.com/u/6154870?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/rrzaripov",
"html_url": "https://github.com/rrzaripov",
"followers_url": "https://api.github.com/users/rrzaripov/followers",
"following_url": "https://api.github.com/users/rrzaripov/following{/other_user}",
"gists_url": "https://api.github.com/users/rrzaripov/gists{/gist_id}",
"starred_url": "https://api.github.com/users/rrzaripov/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/rrzaripov/subscriptions",
"organizations_url": "https://api.github.com/users/rrzaripov/orgs",
"repos_url": "https://api.github.com/users/rrzaripov/repos",
"events_url": "https://api.github.com/users/rrzaripov/events{/privacy}",
"received_events_url": "https://api.github.com/users/rrzaripov/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"You're working with an instance but the `get()` method is a class-method. So:\r\n\r\n```python\r\nwith database.transaction():\r\n TestDB.create(k='key1', v='value1')\r\ntdb = TestDB.get(TestDB.k == 'key1')\r\n```"
] | 2017-06-15T09:39:37 | 2017-06-15T15:44:04 | 2017-06-15T15:44:04 | NONE | null | This is my code:
```python
# -*- coding: utf-8 -*-
from peewee import *
from playhouse.sqlite_ext import SqliteExtDatabase
__database_file__ = 'test.db'
database = SqliteExtDatabase(__database_file__)
class TestModelDB(Model):
class Meta:
database = database
class TestDB(TestModelDB):
k = TextField(null=False, unique=True)
v = TextField(null=False)
database.connect()
database.create_tables([TestDB])
tdb = TestDB()
with database.transaction():
tdb.create(k='key1', v='value1')
tdb.get(tdb.k == 'key1')
```
This give next traceback witn python 2.7 and last peewee release:
```
Traceback (most recent call last):
File "C:/git/get_peewee.py", line 25, in <module>
tdb.get(tdb.k == 'key1')
File "C:\Python27\lib\site-packages\peewee.py", line 4926, in get
return sq.get()
File "C:\Python27\lib\site-packages\peewee.py", line 3179, in get
clone = self.paginate(1, 1)
File "C:\Python27\lib\site-packages\peewee.py", line 397, in inner
clone = self.clone() # Assumes object implements `clone`.
File "C:\Python27\lib\site-packages\peewee.py", line 2771, in clone
return self._clone_attributes(query)
File "C:\Python27\lib\site-packages\peewee.py", line 3008, in _clone_attributes
query = super(SelectQuery, self)._clone_attributes(query)
File "C:\Python27\lib\site-packages\peewee.py", line 2775, in _clone_attributes
query._where = self._where.clone()
AttributeError: 'bool' object has no attribute 'clone'
```
get() shortcut is broken? Or maybe I'm doing something wrong?
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1293/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1293/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1292 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1292/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1292/comments | https://api.github.com/repos/coleifer/peewee/issues/1292/events | https://github.com/coleifer/peewee/issues/1292 | 236,113,683 | MDU6SXNzdWUyMzYxMTM2ODM= | 1,292 | there is two foreign keys in table A related to table B,how can I get table B's columns within one query? | {
"login": "linxi-1214",
"id": 20988026,
"node_id": "MDQ6VXNlcjIwOTg4MDI2",
"avatar_url": "https://avatars.githubusercontent.com/u/20988026?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/linxi-1214",
"html_url": "https://github.com/linxi-1214",
"followers_url": "https://api.github.com/users/linxi-1214/followers",
"following_url": "https://api.github.com/users/linxi-1214/following{/other_user}",
"gists_url": "https://api.github.com/users/linxi-1214/gists{/gist_id}",
"starred_url": "https://api.github.com/users/linxi-1214/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/linxi-1214/subscriptions",
"organizations_url": "https://api.github.com/users/linxi-1214/orgs",
"repos_url": "https://api.github.com/users/linxi-1214/repos",
"events_url": "https://api.github.com/users/linxi-1214/events{/privacy}",
"received_events_url": "https://api.github.com/users/linxi-1214/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Yeah actually that looks good! You can verify by turning query logging on:\r\n\r\n```python\r\nimport logging\r\nlogger = logging.getLogger('peewee')\r\nlogger.addHandler(logging.StreamHandler())\r\nlogger.setLevel(logging.DEBUG)\r\n```",
"I got the query log as the way you told me, and the log are as below\r\n__Note: This happened when I fetch both contract.customer.name and contract.salesman.name . And just the first query executed if I only fetch the contract.customer.name .__\r\n\r\n```sql\r\n--------------------------------------------------------------------------------\r\n('SELECT `t1`.`id`, `t1`.`contract_no`, `t1`.`customer_id`, `t1`.`salesman_id`, `t1`.`total_price`, `t1`.`is_internal`, `t1`.`company`, `t1`.`project`, `t1`.`sign_time`, `t1`.`effective_time`, `t1`.`expired_time`, `t1`.`notes`, `t1`.`timestamp`, `t2`.`username`, `t2`.`mphone`, `t3`.`username` FROM `t_contract` AS t1 INNER JOIN `t_user` AS t2 ON (`t1`.`customer_id` = `t2`.`id`) LEFT OUTER JOIN `t_user` AS t3 ON (`t1`.`salesman_id` = `t3`.`id`) WHERE (`t1`.`customer_id` = %s)', [u'1'])\r\n('SELECT `t1`.`id`, `t1`.`username`, `t1`.`role_id`, `t1`.`email`, `t1`.`mphone`, `t1`.`is_disable`, `t1`.`is_admin`, `t1`.`is_enterprise`, `t1`.`credits`, `t1`.`created_time`, `t1`.`updated_time` FROM `t_user` AS t1 WHERE (`t1`.`id` = %s) LIMIT 1', [u'345'])\r\n('SELECT `t1`.`id`, `t1`.`username`, `t1`.`role_id`, `t1`.`email`, `t1`.`mphone`, `t1`.`is_disable`, `t1`.`is_admin`, `t1`.`is_enterprise`, `t1`.`credits`, `t1`.`created_time`, `t1`.`updated_time` FROM `t_user` AS t1 WHERE (`t1`.`id` = %s) LIMIT 1', [u'346'])\r\n('SELECT `t1`.`id`, `t1`.`username`, `t1`.`role_id`, `t1`.`email`, `t1`.`mphone`, `t1`.`is_disable`, `t1`.`is_admin`, `t1`.`is_enterprise`, `t1`.`credits`, `t1`.`created_time`, `t1`.`updated_time` FROM `t_user` AS t1 WHERE (`t1`.`id` = %s) LIMIT 1', [u'345'])\r\n('SELECT `t1`.`id`, `t1`.`username`, `t1`.`role_id`, `t1`.`email`, `t1`.`mphone`, `t1`.`is_disable`, `t1`.`is_admin`, `t1`.`is_enterprise`, `t1`.`credits`, `t1`.`created_time`, `t1`.`updated_time` FROM `t_user` AS t1 WHERE (`t1`.`id` = %s) LIMIT 1', [u'345'])\r\n('SELECT `t1`.`id`, `t1`.`username`, `t1`.`role_id`, `t1`.`email`, `t1`.`mphone`, `t1`.`is_disable`, `t1`.`is_admin`, `t1`.`is_enterprise`, `t1`.`credits`, `t1`.`created_time`, `t1`.`updated_time` FROM `t_user` AS t1 WHERE (`t1`.`id` = %s) LIMIT 1', [u'345'])\r\n('SELECT `t1`.`id`, `t1`.`username`, `t1`.`role_id`, `t1`.`email`, `t1`.`mphone`, `t1`.`is_disable`, `t1`.`is_admin`, `t1`.`is_enterprise`, `t1`.`credits`, `t1`.`created_time`, `t1`.`updated_time` FROM `t_user` AS t1 WHERE (`t1`.`id` = %s) LIMIT 1', [u'345'])\r\n('SELECT `t1`.`id`, `t1`.`username`, `t1`.`role_id`, `t1`.`email`, `t1`.`mphone`, `t1`.`is_disable`, `t1`.`is_admin`, `t1`.`is_enterprise`, `t1`.`credits`, `t1`.`created_time`, `t1`.`updated_time` FROM `t_user` AS t1 WHERE (`t1`.`id` = %s) LIMIT 1', [u'345'])\r\n('SELECT `t1`.`id`, `t1`.`username`, `t1`.`role_id`, `t1`.`email`, `t1`.`mphone`, `t1`.`is_disable`, `t1`.`is_admin`, `t1`.`is_enterprise`, `t1`.`credits`, `t1`.`created_time`, `t1`.`updated_time` FROM `t_user` AS t1 WHERE (`t1`.`id` = %s) LIMIT 1', [u'345'])\r\n('SELECT `t1`.`id`, `t1`.`username`, `t1`.`role_id`, `t1`.`email`, `t1`.`mphone`, `t1`.`is_disable`, `t1`.`is_admin`, `t1`.`is_enterprise`, `t1`.`credits`, `t1`.`created_time`, `t1`.`updated_time` FROM `t_user` AS t1 WHERE (`t1`.`id` = %s) LIMIT 1', [u'345'])\r\n('SELECT `t1`.`id`, `t1`.`username`, `t1`.`role_id`, `t1`.`email`, `t1`.`mphone`, `t1`.`is_disable`, `t1`.`is_admin`, `t1`.`is_enterprise`, `t1`.`credits`, `t1`.`created_time`, `t1`.`updated_time` FROM `t_user` AS t1 WHERE (`t1`.`id` = %s) LIMIT 1', [u'345'])\r\n```\r\n\r\nI got N+1 queries",
"Finally I resolved this problem by Calling the SelectQuery instance's method `dicts()`.\r\n\r\n``` python\r\n Customer = User.alias()\r\n Salesman = User.alias()\r\n\r\n contracts = (Contract\r\n .select(Contract.id,\r\n Contract.contract_no,\r\n Contract.total_price,\r\n Contract.company,\r\n Contract.project,\r\n Contract.sign_time,\r\n Contract.is_internal,\r\n Customer.mphone,\r\n Customer.name.alias('customer_name'),\r\n Salesman.name.alias('salesman_name')\r\n )\r\n .join(Customer, on=(Contract.customer == Customer.id))\r\n .join(Salesman, JOIN.LEFT_OUTER, on=(Contract.salesman == Salesman.id))\r\n .where(Contract.customer == user_id)\r\n )\r\n for contract in contracts.dicts():\r\n contract.get('salesman_name')\r\n contract.get('customer_name')\r\n```\r\n\r\nIs there a cool way ?",
"Ahh shit I missed something in your initial query. In order to access related models, you will need to assign an alias to the join predicate. Additionally, after joining on Customer you need to switch the join context back to Contract so that when you join on Salesman peewee knows how to reconstruct the model graph. This code works as expected:\r\n\r\n```python\r\ncontracts = (Contract\r\n .select(Contract, Customer.name, Salesman.name)\r\n .join(Customer,\r\n on=(Contract.customer == Customer.id).alias('customer'))\r\n .switch(Contract)\r\n .join(Salesman,\r\n on=(Contract.salesman == Salesman.id).alias('salesman'))\r\n .order_by(Contract.contract_no))\r\nfor contract in contracts:\r\n print contract.contract_no, contract.customer.name, contract.salesman.name\r\n```"
] | 2017-06-15T08:26:57 | 2017-06-16T14:00:34 | 2017-06-15T15:45:25 | NONE | null | TABLE contract:
column | type | constraint
------- | -----| ------
id | int | primary key
contract_no | int | unique
customer| int | Foreign key to Table User
salesman | int | Foreign key to Table User
Table User:
column | type | constraint
------- | ---- | ------
id | int | Primary key
name| varchar |
I want to get contract_no, customer's name , salesman's name in one query?
I have saw the section "avoid N+1 querying", so my expression is \:
```python
Customer = User.alias()
Salesman = User.alias()
contracts = (Contract
.select(Contract, Customer.name, Salesman.name)
.join(Customer, on=(Contract.customer == Customer.id))
.join(Salesman, JOIN.LEFT_OUTER, on=(Contract.salesman == Salesman.id))
.where(Contract.customer == 1)
)
```
I wonder whether it's right or not? | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1292/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1292/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1291 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1291/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1291/comments | https://api.github.com/repos/coleifer/peewee/issues/1291/events | https://github.com/coleifer/peewee/issues/1291 | 235,304,957 | MDU6SXNzdWUyMzUzMDQ5NTc= | 1,291 | Inspecting query column names | {
"login": "josePhoenix",
"id": 172886,
"node_id": "MDQ6VXNlcjE3Mjg4Ng==",
"avatar_url": "https://avatars.githubusercontent.com/u/172886?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/josePhoenix",
"html_url": "https://github.com/josePhoenix",
"followers_url": "https://api.github.com/users/josePhoenix/followers",
"following_url": "https://api.github.com/users/josePhoenix/following{/other_user}",
"gists_url": "https://api.github.com/users/josePhoenix/gists{/gist_id}",
"starred_url": "https://api.github.com/users/josePhoenix/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/josePhoenix/subscriptions",
"organizations_url": "https://api.github.com/users/josePhoenix/orgs",
"repos_url": "https://api.github.com/users/josePhoenix/repos",
"events_url": "https://api.github.com/users/josePhoenix/events{/privacy}",
"received_events_url": "https://api.github.com/users/josePhoenix/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"This type of question is more appropriate to stackoverflow.\r\n\r\nHowever...when you create a query, you necessarily know what columns are being selected. So how can there be a problem?",
"Because you may want to write your code in such a way that it can be reused without passing the names of columns explicitly, especially because this information is already part of the results object.\r\n\r\nIt appears that you get a different API depending on whether speedups are enabled. With speedups disabled, there is a `column_meta` attribute on peewee.NaiveQueryResultWrapper that exposes all the metadata.\r\n\r\n```\r\n>>> type(results)\r\n<class 'peewee.NaiveQueryResultWrapper'>\r\n>>> for f in results.column_meta: print(f.name)\r\nobsid\r\npi_last_name\r\nobs_date\r\nexptime\r\n```",
"> Because you may want to write your code in such a way that it can be reused without passing the names of columns explicitly, especially because this information is already part of the results object.\r\n\r\nI definitely get that...especially in a template, like your example.\r\n\r\nI've updated the speedups module to expose the column_meta attribute, see f11802807f5e05dddeb32f93b8c84703b49bb498"
] | 2017-06-12T17:29:07 | 2017-06-16T21:37:50 | 2017-06-12T20:40:27 | NONE | null | I have some code that spits out an HTML table from some query results:
```python
<table>
<tr>{% for column in columns %}<th>{{ column }}</th>{% endfor %}<th>
{% for result in results %}
<tr>{% for column in columns %}<td>{{ result[column] }}</td>{% endfor %}</tr>
{% endfor %}
</table>
```
The best way I've found so far to get the `columns` from the query is:
```
results = query.execute()
first_row = results.next()
columns = first_row._meta.sorted_field_names
```
Is there a better way? (Incidentally, it's surprising to me that `list(results)` acts the same whether or not I call `results.next()`...) | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1291/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1291/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1290 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1290/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1290/comments | https://api.github.com/repos/coleifer/peewee/issues/1290/events | https://github.com/coleifer/peewee/issues/1290 | 235,225,661 | MDU6SXNzdWUyMzUyMjU2NjE= | 1,290 | peewee and multiprocess | {
"login": "pw717",
"id": 29229407,
"node_id": "MDQ6VXNlcjI5MjI5NDA3",
"avatar_url": "https://avatars.githubusercontent.com/u/29229407?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/pw717",
"html_url": "https://github.com/pw717",
"followers_url": "https://api.github.com/users/pw717/followers",
"following_url": "https://api.github.com/users/pw717/following{/other_user}",
"gists_url": "https://api.github.com/users/pw717/gists{/gist_id}",
"starred_url": "https://api.github.com/users/pw717/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/pw717/subscriptions",
"organizations_url": "https://api.github.com/users/pw717/orgs",
"repos_url": "https://api.github.com/users/pw717/repos",
"events_url": "https://api.github.com/users/pw717/events{/privacy}",
"received_events_url": "https://api.github.com/users/pw717/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I apologize but I don't have the time to read all that code.\r\n\r\nDepending on where you are fork-ing the process, you could definitely run into some problems. It looks from a quick read that you may be forking after you've initialized the connection, etc. This is probably what's causing the problems. You'll need to be sure that you don't initialize any connections until after you fork, as connections cannot be shared among multiple processes...even if you're using the pool.",
"Thank you very much four your answer!\r\nI understand you.\r\nIt is true that the connections are created first, then I launch the pool of processes.\r\nWhen I create the connection inside each process, it's just fine !\r\n\r\n```python\r\ndef ProxyModel():\r\n db = InitDB(\"tests\", usr=None, pwd=None, nb_conn=5, mode=\"url\")\r\n proxy = Proxy()\r\n proxy.initialize(db)\r\n return proxy\r\n\r\ndef ReadModelProxy(counter=None):\r\n global _MODELS, _STOP\r\n\r\n proxy = None\r\n # Get recordsets info :\r\n if counter and _STOP.value:\r\n PrintWarn(\"%sERROR IN POOL - Function has been stopped !!!\" % \"counter = %s - \" % counter if counter else \"\")\r\n return\r\n m = _MODELS['p']\r\n if m:\r\n try:\r\n proxy = ProxyModel()\r\n with Using(proxy, [m]):\r\n\r\n rs = m.select()\r\n nb = len(rs)\r\n msg = \"%s%s records found in Modele %s - table = %s\" % (\"counter = %s - \" % counter if counter else \"\", nb, m.__name__, m._meta.db_table)\r\n if nb == 0:\r\n PrintWarn(msg)\r\n else:\r\n PrintOk(msg)\r\n #for p in rs:\r\n # print \"\\t%s was born on %s\" % (p.name, p.birthday)\r\n\r\n except Exception as exc:\r\n PrintError(\"%sERROR : %s\" % (\"counter = %s - \" % counter if counter else \"\", exc))\r\n print traceback.format_exc()\r\n if counter:\r\n _STOP.value = True\r\n finally:\r\n if proxy and not proxy.is_closed():\r\n proxy.close()\r\n return\r\n```\r\nand in main :\r\n```python\r\n # OK : 5th test : \"with pool of processes within proxy peewee\"\r\n MultiProcRead(mode=\"proxy\")\r\n```\r\n\r\nThank-you very much again for all your work!\r\nIt's a great lib!\r\n\r\nPS : Yes, the code seems a bit long: I thought you could just copy/paste it and run as it is!\r\nIt only creates a `persons` table in `tests`mysql` database and adds some data in it.\r\n\r\nThen it does a first simple read of the table test.\r\nAfter that the same read called within a pool of 10 processes.\r\nThis is where I have the errors.\r\n\r\nThe other 2 tests left to show that when I each process runs it's own connection it's ok.\r\n\r\n"
] | 2017-06-12T13:04:41 | 2017-06-12T14:17:11 | 2017-06-12T14:17:11 | NONE | null | Hi,
I'm trying to use a mysql+pool connexion within a multiprocess treatment.
I have always the errors below :
ERROR : (2013, 'Lost connection to MySQL server during query')
ERROR : (2006, 'MySQL server has gone away')
I understand that the processes tries to use the same connection already in use.
I thought the use of a mysql pool would have prevented this.
I'm not sure wether it's an issue, a wrong usage of the peewee lib or a request.
When each process runs it's own MySQLdb connection than it's just fine (see test number 4 of the code below).
But I'd like to stay in the "peewee" pool of connexions, I don't know if this will be possible.
So I would rather say that I have a wrong usage of the lib, but could you be kind enough to guide me?
Here is below a piece of code in order to reproduce the behaviour, please see in particular test number 3 which leads to the MySQL errors.
I'm running this test under mac osx 10.12.5 with sierra.
Thank you in advance for your help.
```python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
from datetime import date, datetime
from os import path
from os.path import expanduser
import traceback
import multiprocessing
from multiprocessing import Process, Pool, Value, Manager
import MySQLdb
import MySQLdb.cursors
from peewee import *
from playhouse.db_url import connect
from playhouse.shortcuts import model_to_dict
from playhouse.pool import *
def InitDB(base, usr, pwd, nb_conn, mode):
db = None
usr = None
pwd = None
port = 3306
cnx_args = {"autocommit": True, "autorollback": False}
args = ""
srv = "mysql+pool"
args = "?max_connections=%d&stale_timeout=300" % nb_conn
if usr and pwd:
cnx = "%s://%s:%s@localhost%s/%s%s" % (srv, usr, pwd, ":%s" % port if port else "", base, args)
db = connect(cnx, **cnx_args)
elif usr:
cnx = "%s://%s@localhost%s/%s%s" % (srv, usr, ":%s" % port if port else "", base, args)
db = connect(cnx, read_default_file = '~/.my.cnf', **cnx_args)
else:
cnx = "%s://localhost%s/%s%s" % (srv, ":%s" % port if port else "", base, args)
if "mysql" in srv:
db = connect(cnx, read_default_file = '~/.my.cnf', **cnx_args)
else:
db = connect(cnx, **cnx_args)
return db
def MySqlConn(base, usr=None, pwd=None):
db = None
if usr and pwd:
db = MySQLdb.connect(host="localhost", port=3306, user=usr, passwd=pwd, db=base, cursorclass=MySQLdb.cursors.DictCursor)
elif usr:
db = MySQLdb.connect(host="localhost", port=3306, user=usr, read_default_file = '~/.my.cnf', db=base, cursorclass=MySQLdb.cursors.DictCursor)
else:
db = MySQLdb.connect(host="localhost", port=3306, read_default_file = '~/.my.cnf', db=base, cursorclass=MySQLdb.cursors.DictCursor)
return db
def InitModels(db):
global _MODELS
# ------- #
# Persons #
# ------- #
class Person(Model):
name = CharField(max_length = 60, null = False)
birthday = DateField(null = False)
class Meta:
db_table = 'persons'
database = db
_MODELS['p'] = Person
# Create table :
if db.is_closed():
db.connect()
if Person.table_exists():
db.drop_table(Person)
db.create_table(Person)
# Populate table :
for i, name in enumerate(['Alfred', 'Bernard', 'Charles', 'Dimitri', 'Eric', 'Franck', 'Gloria', 'Hope', 'Isadora', 'Junon',
'Kevin', 'Leonora', 'Marcel', 'Nora', 'Oscar', 'Patrick', 'Quentin', 'Romain', 'Samuel', 'Tadeus',
'Ursula', 'Virginia', 'Wilfrid', 'Xavier', 'Yann', 'Zoé']):
p = Person(name=name, birthday=date(1960, 1, i+1))
p.save()
db.close()
return
def PurgeExamples():
global _MODELS
for k in _MODELS.keys():
m = _MODELS[k]
db = m._meta.database
if db.is_closed():
db.connect()
if m.table_exists():
db.drop_table(m)
db.close()
return
def ReadModel(counter=None):
global _MODELS, _STOP
# Get recordsets info :
if counter and _STOP.value:
PrintWarn("%sERROR IN POOL - Function has been stopped !!!" % "counter = %s - " % counter if counter else "")
return
m = _MODELS['p']
if m:
db = m._meta.database
try:
if db.is_closed():
db.connect()
rs = m.select()
nb = len(rs)
msg = "%s%s records found in Modele %s - table = %s" % ("counter = %s - " % counter if counter else "", nb, m.__name__, m._meta.db_table)
if nb == 0:
PrintWarn(msg)
else:
PrintOk(msg)
#for p in rs:
# print "\t%s was born on %s" % (p.name, p.birthday)
except Exception as exc:
PrintError("%sERROR : %s" % ("counter = %s - " % counter if counter else "", exc))
print traceback.format_exc()
if counter:
_STOP.value = True
finally:
if not db.is_closed():
db.close()
return
def ReadTable(counter=None):
global _MODELS, _STOP
# Get recordsets info :
if counter and _STOP.value:
PrintWarn("%sERROR IN POOL - Function has been stopped !!!" % "counter = %s - " % counter if counter else "")
return
conn = MySqlConn("tests")
if conn:
cursor = None
try:
cursor = conn.cursor()
query = "SELECT name, birthday FROM persons;"
cursor.execute(query)
nb = cursor.rowcount
msg = "%s%s records found in table = persons" % ("counter = %s - " % counter if counter else "", nb)
if nb == 0:
PrintWarn(msg)
else:
PrintOk(msg)
#rs = cursor.fetchall()
#for r in rs:
# print "\t%s was born on %s" % (r["name"], r["birthday"])
except Exception as exc:
PrintError("%sERROR : %s" % ("counter = %s - " % counter if counter else "", exc))
print traceback.format_exc()
if counter:
_STOP.value = True
finally:
# Close the connection when it is open.
if cursor:
cursor.close()
if conn:
conn.close()
return
def MultiProcRead(mode="peewee"):
global _STOP
_STOP = Value('b', False)
trace_fct = "MultiProcRead(mode=\"%s\")" % mode
PrintInfo("\n%s - BEGIN %s" % (datetime.now(), trace_fct))
if mode == "peewee":
fct = ReadModel
else:
fct = ReadTable
nb_procs = 10
jobs = []
msg = "load processes loop"
PrintBold("Begin %s - %s" % (datetime.now(), msg))
for i in range(0, nb_procs):
out_list = list()
process = multiprocessing.Process(target=fct, args=(i, ))
jobs.append(process)
PrintBold("End %s - %s" % (datetime.now(), msg))
# Start the processes (i.e. calculate the random number lists)
msg = "start jobs loop"
PrintBold("Begin %s - %s" % (datetime.now(), msg))
for j in jobs:
j.start()
PrintBold("End %s - %s" % (datetime.now(), msg))
# Ensure all of the processes have finished
msg = "\"join\" operation loop"
PrintBold("Begin %s - %s" % (datetime.now(), msg))
for j in jobs:
j.join()
PrintBold("End %s - %s" % (datetime.now(), msg))
PrintInfo("\n%s - END %s" % (datetime.now(), trace_fct))
return
def PrintBold(string):
pref = u"\x1b[1m"
suff = u"\x1b[0m"
print "{0}{1}{2}".format(pref, string, suff)
return
def PrintInfo(string):
pref = u"\x1b[1;37;44m"
suff = u"\x1b[0m"
print "{0}{1}{2}".format(pref, string, suff)
return
def PrintOk(string):
pref = u"\x1b[1;30;42m"
suff = u"\x1b[0m"
print "{0}{1}{2}".format(pref, string, suff)
return
def PrintWarn(string):
pref = u"\x1b[1;37;45m"
suff = u"\x1b[0m"
print "{0}{1}{2}".format(pref, string, suff)
return
def PrintError(string):
pref = u"\x1b[1;37;41m"
suff = u"\x1b[0m"
print "{0}{1}{2}".format(pref, string, suff)
return
# ------- #
# GLOBALS #
# ------- #
_MODELS = {}
_MNGR = Manager()
_STOP = Value('b', False)
_LOCK = multiprocessing.Manager().Lock()
# ------------- #
# Fonction main #
# ------------- #
def main(argv):
db = None
try:
db = InitDB("tests", usr=None, pwd=None, nb_conn=5, mode="url")
InitModels(db)
# OK : 1st test : simple read with peewee connect
ReadModel()
# NOK : 2nd test : "with pool of processes within peewee"
MultiProcRead(mode="peewee")
# OK : 3rd test : simple read with MySQLdb cursor
ReadTable()
# OK : 4th test : "with pool of processes within MySQLdb"
# Each process runs it's own connection : then it's fine
MultiProcRead(mode="table")
PurgeExamples()
except Exception as exc:
PrintError("ERROR : %s" % exc)
print traceback.format_exc()
finally:
if db and not db.is_closed():
db.close()
return
if __name__ == "__main__":
main(sys.argv[1:])
```
Last question if you may :
I don't see where I should "play" your
```python
def before_request_handler():
database.connect()
def after_request_handler():
database.close()
```
Is it reserved to web context only ?
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1290/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1290/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1289 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1289/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1289/comments | https://api.github.com/repos/coleifer/peewee/issues/1289/events | https://github.com/coleifer/peewee/issues/1289 | 234,013,275 | MDU6SXNzdWUyMzQwMTMyNzU= | 1,289 | Mysql "USE INDEX" clause? | {
"login": "ParthGandhi",
"id": 819237,
"node_id": "MDQ6VXNlcjgxOTIzNw==",
"avatar_url": "https://avatars.githubusercontent.com/u/819237?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/ParthGandhi",
"html_url": "https://github.com/ParthGandhi",
"followers_url": "https://api.github.com/users/ParthGandhi/followers",
"following_url": "https://api.github.com/users/ParthGandhi/following{/other_user}",
"gists_url": "https://api.github.com/users/ParthGandhi/gists{/gist_id}",
"starred_url": "https://api.github.com/users/ParthGandhi/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/ParthGandhi/subscriptions",
"organizations_url": "https://api.github.com/users/ParthGandhi/orgs",
"repos_url": "https://api.github.com/users/ParthGandhi/repos",
"events_url": "https://api.github.com/users/ParthGandhi/events{/privacy}",
"received_events_url": "https://api.github.com/users/ParthGandhi/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I actually found a better way to do it:\r\n\r\n```python\r\nquery = query.from_(SQL(f'`<table_name>` as `t1` USE INDEX(`<index_name>`)'))\r\n```\r\n\r\nIs this the expected way?",
"Unfortunately, doing something like this is not really well-supported by Peewee. Your solutions look acceptable but I agree that having to do all that stuff isn't ideal. I don't think that I'll be adding support for this any time soon, so I think you're stuck with implementing this using a less-than-ideal hack."
] | 2017-06-06T20:24:05 | 2017-06-12T13:49:58 | 2017-06-12T13:49:58 | NONE | null | Is there a way to use this option? Or in general, to add arbitrary clauses to the query?
Currently i've hacked the internal `QueryCompiler` to allow adding the required clause, but thats dirty as hell cause it forces me to copy the entire method into the app code and add only 3 lines to it.
Here it is:
```python
def generate_select(self, query, alias_map=None):
from peewee import CompoundSelect, _StripParens, SQL, EnclosedClause, Clause, CommaClause
model = query.model_class
db = model._meta.database
alias_map = self.calculate_alias_map(query, alias_map)
if isinstance(query, CompoundSelect):
clauses = [_StripParens(query)]
else:
if not query._distinct:
clauses = [SQL('SELECT')]
else:
clauses = [SQL('SELECT DISTINCT')]
if query._distinct not in (True, False):
clauses += [SQL('ON'), EnclosedClause(*query._distinct)]
select_clause = Clause(*query._select)
select_clause.glue = ', '
clauses.extend((select_clause, SQL('FROM')))
if query._from is None:
clauses.append(model.as_entity().alias(alias_map[model]))
else:
clauses.append(CommaClause(*query._from))
"""CUSTOM CODE START"""
if query._use_index is not None:
clauses.append(SQL(f'USE INDEX({query._use_index})'))
"""CUSTOM CODE END"""
if query._windows is not None:
clauses.append(SQL('WINDOW'))
clauses.append(CommaClause(*[
Clause(
SQL(window._alias),
SQL('AS'),
window.__sql__())
for window in query._windows]))
join_clauses = self.generate_joins(query._joins, model, alias_map)
if join_clauses:
clauses.extend(join_clauses)
if query._where is not None:
clauses.extend([SQL('WHERE'), query._where])
if query._group_by:
clauses.extend([SQL('GROUP BY'), CommaClause(*query._group_by)])
if query._having:
clauses.extend([SQL('HAVING'), query._having])
if query._order_by:
clauses.extend([SQL('ORDER BY'), CommaClause(*query._order_by)])
if query._limit is not None or (query._offset and db.limit_max):
limit = query._limit if query._limit is not None else db.limit_max
clauses.append(SQL('LIMIT %s' % limit))
if query._offset is not None:
clauses.append(SQL('OFFSET %s' % query._offset))
for_update, no_wait = query._for_update
if for_update:
stmt = 'FOR UPDATE NOWAIT' if no_wait else 'FOR UPDATE'
clauses.append(SQL(stmt))
return self.build_query(clauses, alias_map)
``` | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1289/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1289/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1288 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1288/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1288/comments | https://api.github.com/repos/coleifer/peewee/issues/1288/events | https://github.com/coleifer/peewee/pull/1288 | 232,949,732 | MDExOlB1bGxSZXF1ZXN0MTIzNTUwMjg3 | 1,288 | #1287 - Support ManyToManyField in model_to_dict | {
"login": "gcscaglia",
"id": 12768288,
"node_id": "MDQ6VXNlcjEyNzY4Mjg4",
"avatar_url": "https://avatars.githubusercontent.com/u/12768288?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/gcscaglia",
"html_url": "https://github.com/gcscaglia",
"followers_url": "https://api.github.com/users/gcscaglia/followers",
"following_url": "https://api.github.com/users/gcscaglia/following{/other_user}",
"gists_url": "https://api.github.com/users/gcscaglia/gists{/gist_id}",
"starred_url": "https://api.github.com/users/gcscaglia/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/gcscaglia/subscriptions",
"organizations_url": "https://api.github.com/users/gcscaglia/orgs",
"repos_url": "https://api.github.com/users/gcscaglia/repos",
"events_url": "https://api.github.com/users/gcscaglia/events{/privacy}",
"received_events_url": "https://api.github.com/users/gcscaglia/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I've merged a patch that adds support manytomany in model_to_dict. Available in Peewee 3.x.\r\n\r\nhttp://docs.peewee-orm.com/en/latest/peewee/playhouse.html#model_to_dict"
] | 2017-06-01T17:16:29 | 2018-01-31T12:40:29 | 2018-01-31T12:40:29 | NONE | null | Adds `dereference_many_to_many_fields` parameter to `model_to_dict` function.
This parameter controls whether to hide the junction table for `ManyToManyFields`.
See the related issue for details.
The default value is False, which preserves the old behavior for compatibility.
I've also added some simple tests for the new behavior; Let me know if they are insufficient and/or something should be changed. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1288/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1288/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/1288",
"html_url": "https://github.com/coleifer/peewee/pull/1288",
"diff_url": "https://github.com/coleifer/peewee/pull/1288.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/1288.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/1287 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1287/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1287/comments | https://api.github.com/repos/coleifer/peewee/issues/1287/events | https://github.com/coleifer/peewee/issues/1287 | 232,699,565 | MDU6SXNzdWUyMzI2OTk1NjU= | 1,287 | model_to_dict - Support ManyToManyField | {
"login": "gcscaglia",
"id": 12768288,
"node_id": "MDQ6VXNlcjEyNzY4Mjg4",
"avatar_url": "https://avatars.githubusercontent.com/u/12768288?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/gcscaglia",
"html_url": "https://github.com/gcscaglia",
"followers_url": "https://api.github.com/users/gcscaglia/followers",
"following_url": "https://api.github.com/users/gcscaglia/following{/other_user}",
"gists_url": "https://api.github.com/users/gcscaglia/gists{/gist_id}",
"starred_url": "https://api.github.com/users/gcscaglia/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/gcscaglia/subscriptions",
"organizations_url": "https://api.github.com/users/gcscaglia/orgs",
"repos_url": "https://api.github.com/users/gcscaglia/repos",
"events_url": "https://api.github.com/users/gcscaglia/events{/privacy}",
"received_events_url": "https://api.github.com/users/gcscaglia/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"+1 for this",
"This is fixed in 3.0a by 0914cee. Example from test-case:\r\n\r\n```python\r\nclass Owner(TestModel):\r\n name = TextField()\r\n\r\nclass Label(TestModel):\r\n label = TextField()\r\n\r\nclass Gallery(TestModel):\r\n name = TextField()\r\n labels = ManyToManyField(Label, backref='galleries')\r\n owner = ForeignKeyField(Owner, backref='galleries')\r\n\r\nGalleryLabel = Gallery.labels.through_model\r\n\r\n def test_manytomany_field(self):\r\n data = (\r\n ('charlie', 'family', ('nuggie', 'bearbe')),\r\n ('charlie', 'pets', ('huey', 'zaizee', 'beanie')),\r\n ('peewee', 'misc', ('nuggie', 'huey')))\r\n for owner_name, gallery, labels in data:\r\n owner, _ = Owner.get_or_create(name=owner_name)\r\n gallery = Gallery.create(name=gallery, owner=owner)\r\n label_objects = [Label.get_or_create(label=l)[0] for l in labels]\r\n gallery.labels.add(label_objects)\r\n\r\n query = (Gallery\r\n .select(Gallery, Owner)\r\n .join(Owner)\r\n .switch(Gallery)\r\n .join(GalleryLabel)\r\n .join(Label)\r\n .where(Label.label == 'nuggie')\r\n .order_by(Gallery.id))\r\n rows = [model_to_dict(gallery, backrefs=True, manytomany=True)\r\n for gallery in query]\r\n self.assertEqual(rows, [\r\n {\r\n 'id': 1,\r\n 'name': 'family',\r\n 'owner': {'id': 1, 'name': 'charlie'},\r\n 'labels': [{'id': 1, 'label': 'nuggie'},\r\n {'id': 2, 'label': 'bearbe'}],\r\n },\r\n {\r\n 'id': 3,\r\n 'name': 'misc',\r\n 'owner': {'id': 2, 'name': 'peewee'},\r\n 'labels': [{'id': 1, 'label': 'nuggie'},\r\n {'id': 3, 'label': 'huey'}],\r\n }])\r\n```"
] | 2017-05-31T21:19:20 | 2018-01-22T22:50:50 | 2018-01-22T22:50:50 | NONE | null | Consider the following models:
```python
class Tag(Model):
name = TextField(unique=True)
class Gallery(BaseModel):
title = TextField(null=True)
tags = ManyToManyField(Tag, related_name='galleries')
```
When calling `model_to_dict` in a `Gallery` instance, one would expect the result dict to be:
```python
{
'id': 1,
'title': 'my title',
'tags': [
{
'id': 1,
'name': 'my tag'
}
]
}
```
But the actual result is:
```python
{
'id': 1,
'title': 'my title',
'gallerytagthrough_set': [
{
'id': 1,
'tag': {
'id': 1,
'name': 'my tag',
},
},
],
}
```
While I do realize this is the result from how `ManyToManyField` works under the hood, the whole point of `ManyToManyField` is to pretend there is no relation table at all. Should't the returned dict be like the first one? | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1287/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/1287/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1286 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1286/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1286/comments | https://api.github.com/repos/coleifer/peewee/issues/1286/events | https://github.com/coleifer/peewee/issues/1286 | 232,381,463 | MDU6SXNzdWUyMzIzODE0NjM= | 1,286 | attrdict causing issues with doctests | {
"login": "kennethlove",
"id": 11908,
"node_id": "MDQ6VXNlcjExOTA4",
"avatar_url": "https://avatars.githubusercontent.com/u/11908?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/kennethlove",
"html_url": "https://github.com/kennethlove",
"followers_url": "https://api.github.com/users/kennethlove/followers",
"following_url": "https://api.github.com/users/kennethlove/following{/other_user}",
"gists_url": "https://api.github.com/users/kennethlove/gists{/gist_id}",
"starred_url": "https://api.github.com/users/kennethlove/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/kennethlove/subscriptions",
"organizations_url": "https://api.github.com/users/kennethlove/orgs",
"repos_url": "https://api.github.com/users/kennethlove/repos",
"events_url": "https://api.github.com/users/kennethlove/events{/privacy}",
"received_events_url": "https://api.github.com/users/kennethlove/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2017-05-30T21:04:02 | 2017-05-30T21:49:03 | 2017-05-30T21:49:03 | NONE | null | Using the suggested method of `from peewee import *` brings in `JOIN` and friends, which are all instances of `attrdict`.
If you want to write and run doctests in your code, then, running `python -m doctest your_script.py` will throw a `KeyError` as it attempts to look up the `__wrapped__` attribute as `doctest` checks to see if it's a wrapped function. Example follows:
```python
File "C:\Users\Kenne\.virtualenvs\nicecore\lib\site-packages\peewee.py", line 318, in __getattr__
return self[attr]
KeyError: '__wrapped__'
```
Seems like the solution would be to add a `try/except` block to the `attrdict` class. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1286/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1286/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1285 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1285/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1285/comments | https://api.github.com/repos/coleifer/peewee/issues/1285/events | https://github.com/coleifer/peewee/issues/1285 | 232,179,504 | MDU6SXNzdWUyMzIxNzk1MDQ= | 1,285 | Very strange error with data update (MySQL) | {
"login": "MarcSky",
"id": 4164003,
"node_id": "MDQ6VXNlcjQxNjQwMDM=",
"avatar_url": "https://avatars.githubusercontent.com/u/4164003?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/MarcSky",
"html_url": "https://github.com/MarcSky",
"followers_url": "https://api.github.com/users/MarcSky/followers",
"following_url": "https://api.github.com/users/MarcSky/following{/other_user}",
"gists_url": "https://api.github.com/users/MarcSky/gists{/gist_id}",
"starred_url": "https://api.github.com/users/MarcSky/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/MarcSky/subscriptions",
"organizations_url": "https://api.github.com/users/MarcSky/orgs",
"repos_url": "https://api.github.com/users/MarcSky/repos",
"events_url": "https://api.github.com/users/MarcSky/events{/privacy}",
"received_events_url": "https://api.github.com/users/MarcSky/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I'm not sure, if you could put this into a failing test-case that demonstrated a bug in Peewee then I would be happy to look into it. As it is, this type of question is more appropriate for stackoverflow or the peewee mailing list. http://docs.peewee-orm.com/en/latest/peewee/contributing.html#questions"
] | 2017-05-30T08:35:21 | 2017-05-30T13:54:54 | 2017-05-30T13:54:54 | NONE | null | Good afternoon, I encountered a very strange mistake. I need to add bonuses to my users every day. To do this, I get a list of users who have the opportunity to receive a bonus and in the cycle update their bonus fields in the database. I do it atomically. And it happens, so some fields are updated from one user and others are not, for example, gaming money for some increases and others do not, and in the database it is written that a person received a bonus. Very strange, one user object, some data is updated, the other is not. I used to use Sqlite before and everything worked fine until I had a lot of users.
Please can u help me, i dont undastand where is mistake :(( Why one field in row changed but other not.
PEOPLE_PER_PAGE = 100
all_count_users = User.select(fn.Count(User.id)).where((User.balance > 0.0) & (User.daily_profit == False)).scalar()
pages = math.ceil(all_count_users / PEOPLE_PER_PAGE)
for i in range(0, pages):
users = User.select().where((User.balance > 0.0) & (User.daily_profit == False)).paginate(i + 1, PEOPLE_PER_PAGE)
for user in users:
with database.atomic():
current_percentage = percentage
if user.referral_individual != None and user.referral_individual > 0:
current_percentage = user.referral_individual
profit = round(formula(user.balance, current_percentage), 2)
user.residue = round(user.residue + profit, 2)
user.total_profit = round(user.total_profit + profit, 2)
user.daily_profit = True
user.save()
All the daily_profit field is updated perfectly, but not all the residue field changes. I just do not eat anything like that at all! Operation is atomic. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1285/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1285/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1284 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1284/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1284/comments | https://api.github.com/repos/coleifer/peewee/issues/1284/events | https://github.com/coleifer/peewee/issues/1284 | 231,424,375 | MDU6SXNzdWUyMzE0MjQzNzU= | 1,284 | Facilitate case insensitive searches | {
"login": "Naatan",
"id": 278649,
"node_id": "MDQ6VXNlcjI3ODY0OQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/278649?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/Naatan",
"html_url": "https://github.com/Naatan",
"followers_url": "https://api.github.com/users/Naatan/followers",
"following_url": "https://api.github.com/users/Naatan/following{/other_user}",
"gists_url": "https://api.github.com/users/Naatan/gists{/gist_id}",
"starred_url": "https://api.github.com/users/Naatan/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/Naatan/subscriptions",
"organizations_url": "https://api.github.com/users/Naatan/orgs",
"repos_url": "https://api.github.com/users/Naatan/repos",
"events_url": "https://api.github.com/users/Naatan/events{/privacy}",
"received_events_url": "https://api.github.com/users/Naatan/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"For case-insensitive LIKE you would just use ILIKE.",
"You should make that clearer in the docs, this currently isn't evident.",
"ILIKE is called ILIKE because it's case-insensitive.",
"I get that now, but that's not self-evident. And it's not something you can search the docs for because nowhere does it say the word \"insensitive\"."
] | 2017-05-25T18:44:59 | 2017-05-25T21:38:44 | 2017-05-25T21:28:15 | NONE | null | The docs state:
> LIKE and ILIKE with SQLite
> Because SQLite’s LIKE operation is case-insensitive by default, peewee will use the SQLite GLOB operation for case-sensitive searches. The glob operation uses asterisks for wildcards as opposed to the usual percent-sign. If you are using SQLite and want case-sensitive partial string matching, remember to use asterisks for the wildcard.
Unfortunately it does not touch on the not at all unlikely scenario of wanting to do case insensitive LIKE queries. It would be nice if peewee touched in its docs, ideally facilitating it, otherwise just stating that you should use `SQL()`. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1284/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1284/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1283 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1283/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1283/comments | https://api.github.com/repos/coleifer/peewee/issues/1283/events | https://github.com/coleifer/peewee/issues/1283 | 230,973,344 | MDU6SXNzdWUyMzA5NzMzNDQ= | 1,283 | HStoreField from playhouse.postgres_ext | {
"login": "bmlis",
"id": 6079729,
"node_id": "MDQ6VXNlcjYwNzk3Mjk=",
"avatar_url": "https://avatars.githubusercontent.com/u/6079729?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/bmlis",
"html_url": "https://github.com/bmlis",
"followers_url": "https://api.github.com/users/bmlis/followers",
"following_url": "https://api.github.com/users/bmlis/following{/other_user}",
"gists_url": "https://api.github.com/users/bmlis/gists{/gist_id}",
"starred_url": "https://api.github.com/users/bmlis/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/bmlis/subscriptions",
"organizations_url": "https://api.github.com/users/bmlis/orgs",
"repos_url": "https://api.github.com/users/bmlis/repos",
"events_url": "https://api.github.com/users/bmlis/events{/privacy}",
"received_events_url": "https://api.github.com/users/bmlis/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"My bad, I was using wrong db connection"
] | 2017-05-24T09:20:02 | 2017-05-24T12:45:05 | 2017-05-24T12:44:33 | NONE | null | `HStoryField.db_field` value seems to be incorrect. When creating model with HStoreField and trying to migrate it I get:
```
peewee.ProgrammingError: type "hash" does not exist
```
even though the hstore extension is installed. When I changed db_field to `'hstore'` value migration was applied without any problems. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1283/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1283/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1282 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1282/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1282/comments | https://api.github.com/repos/coleifer/peewee/issues/1282/events | https://github.com/coleifer/peewee/issues/1282 | 230,359,501 | MDU6SXNzdWUyMzAzNTk1MDE= | 1,282 | migrations - field is not null but has no default | {
"login": "binrush",
"id": 3984423,
"node_id": "MDQ6VXNlcjM5ODQ0MjM=",
"avatar_url": "https://avatars.githubusercontent.com/u/3984423?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/binrush",
"html_url": "https://github.com/binrush",
"followers_url": "https://api.github.com/users/binrush/followers",
"following_url": "https://api.github.com/users/binrush/following{/other_user}",
"gists_url": "https://api.github.com/users/binrush/gists{/gist_id}",
"starred_url": "https://api.github.com/users/binrush/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/binrush/subscriptions",
"organizations_url": "https://api.github.com/users/binrush/orgs",
"repos_url": "https://api.github.com/users/binrush/repos",
"events_url": "https://api.github.com/users/binrush/events{/privacy}",
"received_events_url": "https://api.github.com/users/binrush/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"That's odd. Thanks for the report, I'll check it out.",
"Thank you @coleifer . Just ping me if you need any additional information.",
"What database engine are you using, out of curiosity?",
"We are using Sqlite",
"Are you using an extension? I'm not familiar with some of the APIs being used:\r\n\r\n```python\r\n MyModel = migrator.orm['my_table'] # XXX\r\n type_new = pw.CharField(null=True, constraints=[pw.Check(\r\n \"type_new in ('type1', 'type2', 'type3')\")])\r\n migrator.add_fields(MyModel, type_new=type_new)\r\n migrator.sql('UPDATE my_table SET type_new=type') # XXX\r\n```",
"Seems like we are using peewee-migrate https://github.com/klen/peewee_migrate\r\nIs it better to file issue to that project?",
"I think something weird must be going on with that extension.\r\n\r\nRunning this:\r\n\r\n```python\r\nfrom peewee import *\r\nfrom playhouse.migrate import *\r\n\r\ndb = SqliteDatabase('test.db')\r\n\r\nclass TestModel(Model):\r\n data = TextField()\r\n class Meta:\r\n database = db\r\n\r\nTestModel.drop_table(True)\r\nTestModel.create_table()\r\n\r\nm = SqliteMigrator(db)\r\nmigrate(\r\n m.add_column(TestModel._meta.db_table, 'new_column', TextField(null=True)),\r\n)\r\n```\r\n\r\nResults in:\r\n\r\n```\r\n∫ sqlite3 test.db\r\nSQLite version 3.19.0 2017-04-10 12:31:15\r\nEnter \".help\" for usage hints.\r\nsqlite> .schema\r\nCREATE TABLE IF NOT EXISTS \"testmodel\" (\"id\" INTEGER NOT NULL PRIMARY KEY, \"data\" TEXT NOT NULL, \"new_column\" TEXT);\r\n```",
"Thank you. Opened new issue https://github.com/klen/peewee_migrate/issues/43",
"Cool, feel free to kick it back over here if need be.",
"@coleifer, I have a migration:\r\n\r\n```from myapp import db\r\nfrom myapp.models import Message, User\r\nfrom playhouse.migrate import *\r\nfrom playhouse.postgres_ext import *\r\n\r\nmigrator = PostgresqlMigrator(db.database)\r\n\r\ndef up():\r\n\tmigrate(\r\n\t\tmigrator.drop_column('message', 'user_id'),\r\n\t\tmigrator.add_column('message', 'user_id', ForeignKeyField(User, backref='messages')),\r\n\t)\r\n```\r\n\r\nI get following error:\r\n`ValueError: user_id is not null but has no default`\r\n\r\nWhere I was mistaken?",
"Why are you dropping and then re-adding it?",
"@coleifer \r\nI wanted make changes:\r\n`user = ForeignKeyField(Cert, backref='messages') -> user = ForeignKeyField(User, backref='messages')`",
"Is there existing data in that table?",
"Yes",
"How are you migrating a foreign-key that points to \"Cert\" so that it points instead to \"User\"? Won't the existing values all be incorrect, since originally they reference ``Cert.id`` but will then reference ``User.id``?",
"You are right. I deleted all rows.\r\n\r\nhttps://github.com/coleifer/peewee/blob/7e61d86bf6c3f256d09b2a3e1897693dfd68b48d/playhouse/migrate.py#L264-L265\r\n\r\nMy PK dont't have default value and not NULL\r\n\r\n```\r\nif not field.null and field.default is None:\r\n if not is_foreign_key:\r\n raise ValueError('%s is not null but has no default' % column_name)\r\n```",
"Well, if you deleted all rows, can you not just drop and re-create the table entirely using the normal `Model.create_table()` API?",
"Another option is to add the field and make it nullable, then do a \"drop_not_null()\" afterwards.",
"```python\r\n# Just drop and re-create:\r\ndef up():\r\n Message.drop_table()\r\n Message.create_table()\r\n\r\n# OR:\r\ndef up():\r\n\tmigrate(\r\n\t\tmigrator.drop_column('message', 'user_id'),\r\n\t\tmigrator.add_column('message', 'user_id', ForeignKeyField(User, null=True)),\r\n migrator.drop_not_null('message', 'user_id'),\r\n\t)\r\n```"
] | 2017-05-22T11:00:34 | 2018-07-19T14:27:59 | 2017-05-22T16:42:26 | NONE | null | I have a migration with the following code:
```
def migrate(migrator, database, fake=False, **kwargs):
"""Write your migrations here."""
MyModel = migrator.orm['my_table']
type_new = pw.CharField(null=True, constraints=[pw.Check(
"type_new in ('type1', 'type2', 'type3')")])
migrator.add_fields(MyModel, type_new=type_new)
migrator.sql('UPDATE my_table SET type_new=type')
migrator.remove_fields(MyModel, 'type')
migrator.rename_field(MyModel, 'type_new', 'type')
migrator.add_not_null(MyModel, 'type')
```
And when appllying it I get following error:
```
ValueError: type_new is not null but has no default
````
I'm explicitly passing `null=True`, but peewee claims this field to be non-null, how it is possible? Is it peewee bug or am I missing something? | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1282/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1282/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1281 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1281/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1281/comments | https://api.github.com/repos/coleifer/peewee/issues/1281/events | https://github.com/coleifer/peewee/issues/1281 | 230,287,627 | MDU6SXNzdWUyMzAyODc2Mjc= | 1,281 | CompositeKey primary key not inheritable | {
"login": "rhkubiak",
"id": 8471676,
"node_id": "MDQ6VXNlcjg0NzE2NzY=",
"avatar_url": "https://avatars.githubusercontent.com/u/8471676?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/rhkubiak",
"html_url": "https://github.com/rhkubiak",
"followers_url": "https://api.github.com/users/rhkubiak/followers",
"following_url": "https://api.github.com/users/rhkubiak/following{/other_user}",
"gists_url": "https://api.github.com/users/rhkubiak/gists{/gist_id}",
"starred_url": "https://api.github.com/users/rhkubiak/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/rhkubiak/subscriptions",
"organizations_url": "https://api.github.com/users/rhkubiak/orgs",
"repos_url": "https://api.github.com/users/rhkubiak/repos",
"events_url": "https://api.github.com/users/rhkubiak/events{/privacy}",
"received_events_url": "https://api.github.com/users/rhkubiak/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Thanks for reporting this. I've pushed your suggested fix along with a test-case."
] | 2017-05-22T05:24:23 | 2017-05-23T03:53:16 | 2017-05-23T03:52:24 | NONE | null | I have a model A in which the primary key is defined via CompositeKey. Model B inherits from model A. A database table generated from B does not have a primary key.
The things get better if the 'elif' in the code below (peewee version 2.10.1) is replaced with just an 'if':
composite_key = False
if model_pk is None:
if parent_pk:
model_pk, pk_name = parent_pk, parent_pk.name
else:
model_pk, pk_name = PrimaryKeyField(primary_key=True), 'id'
elif isinstance(model_pk, CompositeKey):
pk_name = '_composite_key'
composite_key = True
What do you think? | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1281/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1281/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1280 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1280/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1280/comments | https://api.github.com/repos/coleifer/peewee/issues/1280/events | https://github.com/coleifer/peewee/issues/1280 | 229,847,128 | MDU6SXNzdWUyMjk4NDcxMjg= | 1,280 | [Feature request] pg8000 support | {
"login": "vaygr",
"id": 8810597,
"node_id": "MDQ6VXNlcjg4MTA1OTc=",
"avatar_url": "https://avatars.githubusercontent.com/u/8810597?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/vaygr",
"html_url": "https://github.com/vaygr",
"followers_url": "https://api.github.com/users/vaygr/followers",
"following_url": "https://api.github.com/users/vaygr/following{/other_user}",
"gists_url": "https://api.github.com/users/vaygr/gists{/gist_id}",
"starred_url": "https://api.github.com/users/vaygr/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/vaygr/subscriptions",
"organizations_url": "https://api.github.com/users/vaygr/orgs",
"repos_url": "https://api.github.com/users/vaygr/repos",
"events_url": "https://api.github.com/users/vaygr/events{/privacy}",
"received_events_url": "https://api.github.com/users/vaygr/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Is it something not considered as a high priority at the moment?\r\n\r\nI've also seen people trying to implement this, e.g. [here](https://www.quora.com/Is-it-possible-to-swap-in-a-pg8000-backend-for-psycopg2-when-using-Peewee).",
"You can implement it by doing something like the above code snippet.\r\n\r\n```python\r\nclass PostgresqlDatabasePG8000(PostgresqlDatabase):\r\n ...\r\n```",
"Yeah, but is there any chance it could get official support in peewee in the future?"
] | 2017-05-19T01:32:04 | 2017-06-09T18:17:43 | 2017-05-22T16:21:17 | NONE | null | It'd be nice to have one pure-Python PostgreSQL driver supported to minimize amount of dependencies installed on the system.
I think [pg8000](https://github.com/mfenniak/pg8000) is a great candidate. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1280/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/1280/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1279 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1279/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1279/comments | https://api.github.com/repos/coleifer/peewee/issues/1279/events | https://github.com/coleifer/peewee/issues/1279 | 229,803,446 | MDU6SXNzdWUyMjk4MDM0NDY= | 1,279 | TimestampField reads `0` as `null` | {
"login": "avivey",
"id": 1530242,
"node_id": "MDQ6VXNlcjE1MzAyNDI=",
"avatar_url": "https://avatars.githubusercontent.com/u/1530242?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/avivey",
"html_url": "https://github.com/avivey",
"followers_url": "https://api.github.com/users/avivey/followers",
"following_url": "https://api.github.com/users/avivey/following{/other_user}",
"gists_url": "https://api.github.com/users/avivey/gists{/gist_id}",
"starred_url": "https://api.github.com/users/avivey/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/avivey/subscriptions",
"organizations_url": "https://api.github.com/users/avivey/orgs",
"repos_url": "https://api.github.com/users/avivey/repos",
"events_url": "https://api.github.com/users/avivey/events{/privacy}",
"received_events_url": "https://api.github.com/users/avivey/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"This is confusing to me -- why use `0` instead of `null`? A zero timestamp corresponds to midnight Jan 1st, 1970.",
"Not sure what you're asking. `0` is not the same as `null`, but the `TimestampField` thinks they are. I think it's a bug.",
"I guess what I'm asking is why you're using `0` instead of `NULL`, when `0` for a timestamp represents midnight jan 1st, 1970?",
"Because I want a non-null value there. `Null` means \"no value\", `0` means \"midnight, Jan 1st, 1970\".\r\n\r\nWhy should the ORM read `0` as `None`? ",
"That's fine -- as long as you were aware of the distinction.",
"Added support for specifying the zero value for the `TimestampField`. You can now write:\r\n\r\n```python\r\ntimestamp = TimestampField(zero_value=datetime.fromtimestamp(0))\r\n```",
"Thanks!"
] | 2017-05-18T21:00:36 | 2017-05-22T19:37:36 | 2017-05-22T19:33:09 | CONTRIBUTOR | null | I guess this is the relevant line https://github.com/coleifer/peewee/blob/master/peewee.py#L1346
At least for mysql, if we have a TimestampField that's defined like this:
```
not_before = TimestampField(default=0, utc=True, null=False)
```
the DB type is `int(11) NOT NULL`.
If the DB gets a value of `0` (For any reason, like "I think it's a valid value" or "The data is already there"), trying to update the value fails:
```
x = Task.get(...)
x.status = 'good'
x.save()
pymysql.err.IntegrityError: (1048, "Column 'not_before' cannot be null")
```
I'm not sure about the reasoning behind this, as the code looks intentional. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1279/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1279/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1278 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1278/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1278/comments | https://api.github.com/repos/coleifer/peewee/issues/1278/events | https://github.com/coleifer/peewee/issues/1278 | 228,971,782 | MDU6SXNzdWUyMjg5NzE3ODI= | 1,278 | question: InternalError: current transaction is aborted | {
"login": "nskalis",
"id": 8971544,
"node_id": "MDQ6VXNlcjg5NzE1NDQ=",
"avatar_url": "https://avatars.githubusercontent.com/u/8971544?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/nskalis",
"html_url": "https://github.com/nskalis",
"followers_url": "https://api.github.com/users/nskalis/followers",
"following_url": "https://api.github.com/users/nskalis/following{/other_user}",
"gists_url": "https://api.github.com/users/nskalis/gists{/gist_id}",
"starred_url": "https://api.github.com/users/nskalis/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/nskalis/subscriptions",
"organizations_url": "https://api.github.com/users/nskalis/orgs",
"repos_url": "https://api.github.com/users/nskalis/repos",
"events_url": "https://api.github.com/users/nskalis/events{/privacy}",
"received_events_url": "https://api.github.com/users/nskalis/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"You'll want to be in a transaction in order to rollback, so:\r\n\r\n```python\r\nwith database.atomic():\r\n try:\r\n BgpCommunities.create(...)\r\n except IntegrityError:\r\n # handle exception however.\r\n```",
"thanks @coleifer but could you advise bit more, still the connections is locked\r\n```\r\nIn [3]: with database.atomic():\r\n ...: try:\r\n ...: BgpCommunities.create(comm_name=\"BBB\", comm_value=\"6830:2222\", label=\"bbb\", used_as=\"\")\r\n ...: except IntegrityError:\r\n ...: pass\r\n ...: \r\n\r\nIn [4]: BgpCommunities.create(comm_name=\"CCC\", comm_value=\"6830:3333\", label=\"ccc\", used_as=\"generic\")\r\n---------------------------------------------------------------------------\r\nInternalError Traceback (most recent call last)\r\n/usr/lib/python3.4/site-packages/peewee.py in execute_sql(self, sql, params, require_commit)\r\n 3767 try:\r\n-> 3768 cursor.execute(sql, params or ())\r\n 3769 except Exception:\r\n\r\nInternalError: current transaction is aborted, commands ignored until end of transaction block\r\n\r\n\r\nDuring handling of the above exception, another exception occurred:\r\n\r\nInternalError Traceback (most recent call last)\r\n<ipython-input-4-d4d4f5a290c0> in <module>()\r\n----> 1 BgpCommunities.create(comm_name=\"CCC\", comm_value=\"6830:3333\", label=\"ccc\", used_as=\"generic\")\r\n\r\n/usr/lib/python3.4/site-packages/peewee.py in create(cls, **query)\r\n 4913 def create(cls, **query):\r\n 4914 inst = cls(**query)\r\n-> 4915 inst.save(force_insert=True)\r\n 4916 inst._prepare_instance()\r\n 4917 return inst\r\n\r\n/usr/lib/python3.4/site-packages/peewee.py in save(self, force_insert, only)\r\n 5106 rows = 1\r\n 5107 else:\r\n-> 5108 pk_from_cursor = self.insert(**field_dict).execute()\r\n 5109 if pk_from_cursor is not None:\r\n 5110 pk_value = pk_from_cursor\r\n\r\n/usr/lib/python3.4/site-packages/peewee.py in execute(self)\r\n 3524 return self._qr\r\n 3525 else:\r\n-> 3526 cursor = self._execute()\r\n 3527 if not self._is_multi_row_insert:\r\n 3528 if self.database.insert_returning:\r\n\r\n/usr/lib/python3.4/site-packages/peewee.py in _execute(self)\r\n 2910 def _execute(self):\r\n 2911 sql, params = self.sql()\r\n-> 2912 return self.database.execute_sql(sql, params, self.require_commit)\r\n 2913 \r\n 2914 def execute(self):\r\n\r\n/usr/lib/python3.4/site-packages/peewee.py in execute_sql(self, sql, params, require_commit)\r\n 3773 else:\r\n 3774 if require_commit and self.get_autocommit():\r\n-> 3775 self.commit()\r\n 3776 return cursor\r\n 3777 \r\n\r\n/usr/lib/python3.4/site-packages/peewee.py in __exit__(self, exc_type, exc_value, traceback)\r\n 3596 else:\r\n 3597 exc_args = exc_value.args\r\n-> 3598 reraise(new_type, new_type(*exc_args), traceback)\r\n 3599 \r\n 3600 class _BaseConnectionLocal(object):\r\n\r\n/usr/lib/python3.4/site-packages/peewee.py in reraise(tp, value, tb)\r\n 133 def reraise(tp, value, tb=None):\r\n 134 if value.__traceback__ is not tb:\r\n--> 135 raise value.with_traceback(tb)\r\n 136 raise value\r\n 137 elif PY2:\r\n\r\n/usr/lib/python3.4/site-packages/peewee.py in execute_sql(self, sql, params, require_commit)\r\n 3766 cursor = self.get_cursor()\r\n 3767 try:\r\n-> 3768 cursor.execute(sql, params or ())\r\n 3769 except Exception:\r\n 3770 if self.autorollback and self.get_autocommit():\r\n\r\nInternalError: current transaction is aborted, commands ignored until end of transaction block\r\n\r\n```",
"Can you share some code I can run locally to reproduce the error?",
"Thanks a lot !\r\n\r\nthe table is defined as:\r\n```\r\n# \\d+ bgp_communities \r\n Table \"doc.bgp_communities\"\r\n Column | Type | Modifiers | Storage | Stats target | Description \r\n-------------+--------------------------+-------------------------------------------------------------+----------+--------------+-------------\r\n i | integer | not null default nextval('bgp_communities_i_seq'::regclass) | plain | | \r\n comm_name | text | not null | extended | | \r\n comm_value | text | not null | extended | | \r\n label | text | not null | extended | | \r\n used_as | text | not null | extended | | \r\n modified_on | timestamp with time zone | default now() | plain | | \r\nIndexes:\r\n \"bgp_communities_pkey\" PRIMARY KEY, btree (i)\r\n \"bgp_communities_comm_value_key\" UNIQUE CONSTRAINT, btree (comm_value)\r\nCheck constraints:\r\n \"bgp_communities_comm_value_check\" CHECK (comm_value ~ similar_escape('%:%'::text, NULL::text) OR comm_value ~ similar_escape('%:%:%'::text, NULL:\r\n:text))\r\n \"bgp_communities_used_as_check\" CHECK (used_as = ANY (ARRAY['bgp-customer'::text, 'destination'::text, 'dtv-peer'::text, 'free-peer'::text, 'gener\r\nic'::text, 'infrastructure'::text, 'origin'::text, 'private-peer'::text, 'public-peer'::text, 'traffic-eng'::text, 'voip-peer'::text]))\r\nHas OIDs: no\r\n```\r\n\r\nand the model generator produces:\r\n```\r\n$ python3 -m pwiz --engine=postgresql --host= --port=5432 --user= --password --schema=doc --tables=bgp_communities ip_spotlight\r\nPassword: \r\nfrom peewee import *\r\n\r\ndatabase = PostgresqlDatabase('ip_spotlight', **{'password': '', 'host': '', 'port': 5432, 'user': ''})\r\n\r\nclass UnknownField(object):\r\n def __init__(self, *_, **__): pass\r\n\r\nclass BaseModel(Model):\r\n class Meta:\r\n database = database\r\n\r\nclass BgpCommunities(BaseModel):\r\n comm_name = TextField()\r\n comm_value = TextField(unique=True)\r\n i = PrimaryKeyField()\r\n label = TextField()\r\n modified_on = DateTimeField(null=True)\r\n used_as = TextField()\r\n\r\n class Meta:\r\n db_table = 'bgp_communities'\r\n schema = 'doc'\r\n\r\n```\r\n\r\nthis query is correct:\r\n`BgpCommunities.create(comm_name=\"CCC\", comm_value=\"6830:3333\", label=\"ccc\", used_as=\"generic\")`\r\nthis query is wrong:\r\n`BgpCommunities.create(comm_name=\"BBB\", comm_value=\"6830:2222\", label=\"bbb\", used_as=\"\")`\r\n\r\nand the `database` is initialised like ` database = PostgresqlDatabase('ip_spotlight', autocommit=True, autorollback=True, **`",
"Hello, \r\n\r\nAny updates on this topic? There had beed no answer and the question is closed. I am having the same issue with connection to postgres being locked even after calling db.rollback() like suggested + db.close() at the end of the function does not release the connection.\r\n\r\nAny further suggestions?",
"I cannot advise what the issue may be, but I don't think it's a peewee issue in that case. It doesn't make sense to me why rolling-back and closing the connection would have no effect, unless you're also using the connection-pool or have omitted other important information.",
"I was having an issue with the same symptom. In my case, the problem was solved by specifying `autorollback=True` when creating the database.",
"This error usually surfaces after an `IntegrityError` has been raised. When using postgres and a constraint is violated, you need to abort the transaction by calling `db.rollback()`. This is handled automatically if you are using the `atomic()` / `transaction()` etc context-managers."
] | 2017-05-16T09:39:29 | 2021-08-01T18:15:23 | 2017-05-16T13:42:47 | NONE | null | Hi,
I was wondering if you could advise on the following: when i make a wrong insert, I am getting `InternalError: current transaction is aborted, commands ignored until end of transaction block`
For example, the database connector is initialised like this:
`database = PostgresqlDatabase('ip_spotlight', autocommit=True, autorollback=True, **{'password': 'xxx', 'host': 'x.x.x.x', 'port': 5432, 'user': 'xxx'}) `
and I try to do the following insert
```
try:
BgpCommunities.create(comm_name="BBB", comm_value="1111:2222", label="bbb", used_as="")
except Exception as e:
database.rollback()
```
the database connection is locked, thus all sub-sequent queries will fail inevitably.
There is a related discussion over here: https://github.com/coleifer/peewee/issues/240
But I am not abel to figure it how to deal with it. Could you please advise ? | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1278/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1278/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1277 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1277/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1277/comments | https://api.github.com/repos/coleifer/peewee/issues/1277/events | https://github.com/coleifer/peewee/issues/1277 | 228,664,519 | MDU6SXNzdWUyMjg2NjQ1MTk= | 1,277 | Peewee >= 2.4.3 is required. Found version ... | {
"login": "thebalthasar",
"id": 6739166,
"node_id": "MDQ6VXNlcjY3MzkxNjY=",
"avatar_url": "https://avatars.githubusercontent.com/u/6739166?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/thebalthasar",
"html_url": "https://github.com/thebalthasar",
"followers_url": "https://api.github.com/users/thebalthasar/followers",
"following_url": "https://api.github.com/users/thebalthasar/following{/other_user}",
"gists_url": "https://api.github.com/users/thebalthasar/gists{/gist_id}",
"starred_url": "https://api.github.com/users/thebalthasar/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/thebalthasar/subscriptions",
"organizations_url": "https://api.github.com/users/thebalthasar/orgs",
"repos_url": "https://api.github.com/users/thebalthasar/repos",
"events_url": "https://api.github.com/users/thebalthasar/events{/privacy}",
"received_events_url": "https://api.github.com/users/thebalthasar/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Yes, this is fixed in sqlite-web. See the issue there: https://github.com/coleifer/sqlite-web/issues/30",
"sqlite-web 0.1.8 was released as well, fixing the issue if you try again."
] | 2017-05-15T10:00:06 | 2017-05-15T21:35:41 | 2017-05-15T21:34:30 | NONE | null |
The instruction which is reported while doing the version check is misleading. This is the runtime error and its message:
RuntimeError: Peewee >= 2.4.3 is required. Found version 2.10.1. Please update by running pip install --update peewee
Should be instead:
**pip install peewee --upgrade**
The error comes from comparing versions in line 58 of sqlite_web.py
>>>version_old='2.4.3'
>>>version_new='2.10.1'
>>>version_new>version_old
**False**
A better comparison would be:
>>> from distutils.version import StrictVersion
>>>StrictVersion(version_new) > StrictVersion(version_old)
**True**
Thank you for your work!
:-)
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1277/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1277/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1276 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1276/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1276/comments | https://api.github.com/repos/coleifer/peewee/issues/1276/events | https://github.com/coleifer/peewee/issues/1276 | 228,510,821 | MDU6SXNzdWUyMjg1MTA4MjE= | 1,276 | [playhouse.dataset] Cannot process column name contain upper case char | {
"login": "renweibo",
"id": 6316209,
"node_id": "MDQ6VXNlcjYzMTYyMDk=",
"avatar_url": "https://avatars.githubusercontent.com/u/6316209?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/renweibo",
"html_url": "https://github.com/renweibo",
"followers_url": "https://api.github.com/users/renweibo/followers",
"following_url": "https://api.github.com/users/renweibo/following{/other_user}",
"gists_url": "https://api.github.com/users/renweibo/gists{/gist_id}",
"starred_url": "https://api.github.com/users/renweibo/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/renweibo/subscriptions",
"organizations_url": "https://api.github.com/users/renweibo/orgs",
"repos_url": "https://api.github.com/users/renweibo/repos",
"events_url": "https://api.github.com/users/renweibo/events{/privacy}",
"received_events_url": "https://api.github.com/users/renweibo/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Version:\r\n- Python: 3.6.1\r\n- peewee: 2.10.1 ",
"d68ae11501face8f4eb6adfde82d8eda79728dc7"
] | 2017-05-14T01:16:51 | 2017-05-16T13:59:33 | 2017-05-16T13:59:33 | NONE | null | Here is the test case.
```python
def test_case_2(self):
db = DataSet('sqlite:///:memory:')
books = db["books"]
books.insert(bookId="ISBN1234567")
```
It should work but report following error:
```python
Traceback (most recent call last):
... ...
File "/Users/renweibo/PycharmProjects/DailyNovel/common/test_driver.py", line 17, in test_case_2
books.insert(bookId="ISBN1234567")
File "/Users/renweibo/.virtualenvs/flask1/lib/python3.6/site-packages/playhouse/dataset.py", line 219, in insert
return self.model_class.insert(**data).execute()
File "/Users/renweibo/.virtualenvs/flask1/lib/python3.6/site-packages/peewee.py", line 4893, in insert
fdict.update([(cls._meta.fields[f], insert[f]) for f in insert])
File "/Users/renweibo/.virtualenvs/flask1/lib/python3.6/site-packages/peewee.py", line 4893, in <listcomp>
fdict.update([(cls._meta.fields[f], insert[f]) for f in insert])
KeyError: 'bookId'
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1276/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1276/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1275 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1275/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1275/comments | https://api.github.com/repos/coleifer/peewee/issues/1275/events | https://github.com/coleifer/peewee/issues/1275 | 228,510,657 | MDU6SXNzdWUyMjg1MTA2NTc= | 1,275 | [playhouse.dataset.DataSet] Cannot process column name contain "_" | {
"login": "renweibo",
"id": 6316209,
"node_id": "MDQ6VXNlcjYzMTYyMDk=",
"avatar_url": "https://avatars.githubusercontent.com/u/6316209?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/renweibo",
"html_url": "https://github.com/renweibo",
"followers_url": "https://api.github.com/users/renweibo/followers",
"following_url": "https://api.github.com/users/renweibo/following{/other_user}",
"gists_url": "https://api.github.com/users/renweibo/gists{/gist_id}",
"starred_url": "https://api.github.com/users/renweibo/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/renweibo/subscriptions",
"organizations_url": "https://api.github.com/users/renweibo/orgs",
"repos_url": "https://api.github.com/users/renweibo/repos",
"events_url": "https://api.github.com/users/renweibo/events{/privacy}",
"received_events_url": "https://api.github.com/users/renweibo/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Version:\r\n- Python: 3.6.1\r\n- peewee: 2.10.1 ",
"The problem is the \"_id\" suffix. DataSet relies on the introspection tools in the `playhouse.reflection` module. These tools are used to read the database and generate peewee Model definitions. There's a convention in peewee, borrowed from Django, to append \"_id\" to foreign key fields. So if I have a Tweet and User model, and the Tweet.author is a foreign key to a User, the column will actually be called Tweet.author_id (though the field name is \"author\"). This comes into play when introspecting, which does the inverse -- if it sees a column named \"xxx_id\", it will strip the \"_id\" from the field name (preserving it for the column).\r\n\r\nI'll look into how to fix this, at any rate.",
"d68ae11501face8f4eb6adfde82d8eda79728dc7",
"Thanks for the quick fix and support. ",
"For sure, thanks for the nice reports."
] | 2017-05-14T01:12:41 | 2017-05-17T02:11:38 | 2017-05-16T13:59:30 | NONE | null | Here is the test case.
```python
def test_case_1(self):
db = DataSet('sqlite:///:memory:')
books = db["books"]
books.insert(book_id="ISBN1234567")
```
It should work but report following error:
```python
Traceback (most recent call last):
... ...
File "/Users/renweibo/PycharmProjects/DailyNovel/common/test_driver.py", line 12, in test_case_1
books.insert(book_id="ISBN1234567")
File "/Users/renweibo/.virtualenvs/flask1/lib/python3.6/site-packages/playhouse/dataset.py", line 219, in insert
return self.model_class.insert(**data).execute()
File "/Users/renweibo/.virtualenvs/flask1/lib/python3.6/site-packages/peewee.py", line 4893, in insert
fdict.update([(cls._meta.fields[f], insert[f]) for f in insert])
File "/Users/renweibo/.virtualenvs/flask1/lib/python3.6/site-packages/peewee.py", line 4893, in <listcomp>
fdict.update([(cls._meta.fields[f], insert[f]) for f in insert])
KeyError: 'book_id'
``` | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1275/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1275/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1274 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1274/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1274/comments | https://api.github.com/repos/coleifer/peewee/issues/1274/events | https://github.com/coleifer/peewee/issues/1274 | 228,482,307 | MDU6SXNzdWUyMjg0ODIzMDc= | 1,274 | Preserve model structure when get dicts from SelectQuery | {
"login": "gugadev",
"id": 22750424,
"node_id": "MDQ6VXNlcjIyNzUwNDI0",
"avatar_url": "https://avatars.githubusercontent.com/u/22750424?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/gugadev",
"html_url": "https://github.com/gugadev",
"followers_url": "https://api.github.com/users/gugadev/followers",
"following_url": "https://api.github.com/users/gugadev/following{/other_user}",
"gists_url": "https://api.github.com/users/gugadev/gists{/gist_id}",
"starred_url": "https://api.github.com/users/gugadev/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/gugadev/subscriptions",
"organizations_url": "https://api.github.com/users/gugadev/orgs",
"repos_url": "https://api.github.com/users/gugadev/repos",
"events_url": "https://api.github.com/users/gugadev/events{/privacy}",
"received_events_url": "https://api.github.com/users/gugadev/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Just one hint: you need to call `switch()` here:\r\n\r\n```python\r\nquery = (Campaign\r\n .select(Campaign, User, Channel)\r\n .join(User, on=(Campaign.user == User.id))\r\n .switch(Campaign) # ADD THIS.\r\n .join(Channel, on=(Campaign.channel == Channel.id))\r\n .where(Campaign.state == state)\r\n .order_by(Campaign.name)\r\n .paginate(page, 10))\r\n```\r\n\r\nSecondly, why not try using the `model_to_dict` helper? I don't see why it would be more code or why you'd need to explicitly create the dictionary:\r\n\r\n```python\r\ncampaigns = [model_to_dict(campaign, recurse=True) for campaign in query]\r\n```",
"You are complety right. I don't need do that. I've applied what you do and works fine. Thanks for clarify this and forgive me if was a silly question, I have little time with Python. Thanks again; I going to close this thread.",
"Not silly at all, glad to help.",
"Hi @coleifer I didn't open a new issue because it's related with this.\r\n\r\nI have a problem using `model_to_dict` on a join query where the foreign key is on inverse side.\r\n\r\n```python\r\nclass User(Base):\r\n name = CharField(null=False)\r\n photo = CharField()\r\n email = CharField(unique=True, null=False)\r\n password = CharField(null=False)\r\n website = CharField(unique=True, null=False)\r\n role = CharField(null=False, default=\"user\")\r\n reason = TextField(null=True)\r\n state = CharField(null=False, default=\"waiting\")\r\n created_at = DateTimeField(null=False, default=datetime.now())\r\n\r\nclass Wallet(Base):\r\n user = ForeignKeyField(User, null=False, related_name=\"wallet\")\r\n funds = DoubleField(null=False, default=0.0)\r\n```\r\nSo, I did this query to get all users with their wallets:\r\n\r\n```python\r\nqs = Box(request.args, default_box=True)\r\n page = int(qs.page[0])\r\n state = qs.state[0]\r\n query = (User\r\n .select(User, Wallet)\r\n .join(Wallet)\r\n .switch(User)\r\n .where(User.state == state)\r\n .order_by(User.name)\r\n .paginate(page, 10))\r\n```\r\nIf iterate the query accesing to the `wallet.funds` field, it works (show me available users funds). But when I try to convert it to dicts the wallet field is missing:\r\n\r\n```python\r\nusers = [model_to_dict(user, recurse=True) for user in query]\r\nfor user in users:\r\n print(user.get(\"wallet\", \"There is no wallet\")) # prints \"There is no wallet\"\r\n```",
"That's because, due to the way you've modeled the data, a User may have many wallets. So model_to_dict isn't able to infer, ahead-of-time, that a user will 0, 1, or many wallets. If you want to include back-references, just call `model_to_dict` with `backrefs=True` (in addition to `recurse=True`) and the wallets will be included as a list.",
"This is all very clearly documented, in my opinion: http://docs.peewee-orm.com/en/latest/peewee/playhouse.html#model_to_dict\r\n\r\nPlease let me know if you found the docs confusing."
] | 2017-05-13T15:59:44 | 2017-05-16T19:27:35 | 2017-05-14T01:14:01 | NONE | null | I have three models:
```python
class User(Base):
name = CharField(null=False)
photo = BlobField()
email = CharField(unique=True, null=False)
password = CharField(null=False)
website = CharField(unique=True, null=False)
role = CharField(null=False, default="user")
reason = TextField(null=True)
state = CharField(null=False, default="waiting")
created_at = DateTimeField(null=False, default=datetime.now())
class Channel(Base):
name = CharField(unique=True, null=False)
cost = DoubleField(null=False)
passback = CharField(null=False)
class Campaign(Base):
name = CharField(null=False)
user = ForeignKeyField(User, null=False)
channel = ForeignKeyField(Channel, null=False)
target = CharField(null=False)
reason = TextField(null=True)
description = TextField(null=True)
state = CharField(null=False, default="waiting")
created_at = DateTimeField(null=False, default=datetime.now())
```
If a made a simple query I get the campaigns that I want, joining User and Channel models:
```python
qs = Box(request.args, default_box=True)
page = int(qs.page[0])
state = qs.state[0]
query = (Campaign
.select(Campaign, User, Channel)
.join(User, on=(Campaign.user == User.id))
.join(Channel, on=(Campaign.channel == Channel.id))
.where(Campaign.state == state)
.order_by(Campaign.name)
.paginate(page, 10))
```
At this point I can simple iterate the query and get the data of joined models:
```ptyhon
for cursor in query:
print(cursor.user.website) # http://johndoe.com
```
However, I need to return the query results in JSON, so, I did this (if I try to return the raw SelectQuery I get an *"maximum recursion level reached" from ujson*):
```python
return json(query.dicts())
```
And the result is this:
```javascript
[
{
"id": 5,
"name": "Computers and technology",
"user": 3,
"channel": 5,
"target": "http://janedoe.com",
"reason": null,
"description": "This is a campaign for my homepage",
"state": "active",
"created_at": 1494099722,
"photo": "/avatars/jane-doe.jpg",
"email": "[email protected]",
"password": "$2y$10$p/BuVFoKi9F9SVOc2yJzA.CM6n88xHhMBipNShp4skv9.WBbYxgQ2",
"website": "http://janedoe.com",
"role": "USER",
"cost": 0.04,
"passback": "https://pcmag.com"
}
]
```
All fields are mixed and, obviously, duplicated keys (name property of `User` and `Channel` are removed). This is not the expected result. Obviously, I can make a for loop to create a dict for each result and for model properties use `model_to_dict`:
```python
# convert a select query to a dicts array
campaigns = []
for row in query:
campaign = {}
campaign["name"] = row.name
campaign["target"] = row.target
campaign["user"] = model_to_dict(row.user)
campaign["channel"] = model_to_dict(row.channel)
campaign["description"] = row.description
campaign["reason"] = row.reason
campaign["state"] = row.state
campaign["created_at"] = row.created_at
campaigns.append(campaign)
```
But this means extra code and I like to keep things simple. So, the question is: exists some way to preserve the model structure when I convert the `SelectQuery` to dicts? | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1274/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/1274/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1273 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1273/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1273/comments | https://api.github.com/repos/coleifer/peewee/issues/1273/events | https://github.com/coleifer/peewee/issues/1273 | 228,454,107 | MDU6SXNzdWUyMjg0NTQxMDc= | 1,273 | Update method dont work | {
"login": "pandbsoftware",
"id": 21987868,
"node_id": "MDQ6VXNlcjIxOTg3ODY4",
"avatar_url": "https://avatars.githubusercontent.com/u/21987868?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/pandbsoftware",
"html_url": "https://github.com/pandbsoftware",
"followers_url": "https://api.github.com/users/pandbsoftware/followers",
"following_url": "https://api.github.com/users/pandbsoftware/following{/other_user}",
"gists_url": "https://api.github.com/users/pandbsoftware/gists{/gist_id}",
"starred_url": "https://api.github.com/users/pandbsoftware/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/pandbsoftware/subscriptions",
"organizations_url": "https://api.github.com/users/pandbsoftware/orgs",
"repos_url": "https://api.github.com/users/pandbsoftware/repos",
"events_url": "https://api.github.com/users/pandbsoftware/events{/privacy}",
"received_events_url": "https://api.github.com/users/pandbsoftware/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Try property indenting and surrounding your code in code blocks.",
"Please take the extra minute to ensure your code is properly formatted. I've done it for you this time as a courtesy.",
"There is something wrong in your code or in the state of your database, because I get an error (as expected):\r\n\r\n```python\r\nTraceback (most recent call last):\r\n File \"x.py\", line 25, in <module>\r\n obj = Lista.get(Lista.cuenta == \"test\")\r\n File \"/home/charles/pypath/peewee.py\", line 4926, in get\r\n return sq.get()\r\n File \"/home/charles/pypath/peewee.py\", line 3185, in get\r\n % self.sql())\r\n__main__.ListaDoesNotExist: Instance matching query does not exist:\r\nSQL: SELECT \"t1\".\"id\", \"t1\".\"cuenta\", \"t1\".\"tiempo\" FROM \"lista\" AS t1 WHERE (\"t1\".\"cuenta\" = ?)\r\n```"
] | 2017-05-13T06:51:26 | 2017-05-14T00:56:37 | 2017-05-14T00:56:37 | NONE | null | ```python
from peewee import *
from playhouse.sqlite_ext import SqliteExtDatabase
import datetime
db = SqliteExtDatabase('lis22.db')
class BaseModel(Model):
class Meta:
database = db
class Lista(BaseModel):
cuenta = CharField(unique=True)
tiempo = CharField()
try:
db.connect()
db.create_tables([Lista])
except:
pass
lista = Lista.create(cuenta="test", tiempo="a")
a = Lista.update(cuenta="test_changed").where(Lista.cuenta == "test")
a.execute()
Lista.get(Lista.cuenta == "test").cuenta
#output: u'test'
``` | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1273/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1273/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1272 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1272/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1272/comments | https://api.github.com/repos/coleifer/peewee/issues/1272/events | https://github.com/coleifer/peewee/pull/1272 | 228,416,230 | MDExOlB1bGxSZXF1ZXN0MTIwNDEyNDg5 | 1,272 | Added note to quickstart regarding separate modules importing the db … | {
"login": "ardeaf",
"id": 20672831,
"node_id": "MDQ6VXNlcjIwNjcyODMx",
"avatar_url": "https://avatars.githubusercontent.com/u/20672831?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/ardeaf",
"html_url": "https://github.com/ardeaf",
"followers_url": "https://api.github.com/users/ardeaf/followers",
"following_url": "https://api.github.com/users/ardeaf/following{/other_user}",
"gists_url": "https://api.github.com/users/ardeaf/gists{/gist_id}",
"starred_url": "https://api.github.com/users/ardeaf/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/ardeaf/subscriptions",
"organizations_url": "https://api.github.com/users/ardeaf/orgs",
"repos_url": "https://api.github.com/users/ardeaf/repos",
"events_url": "https://api.github.com/users/ardeaf/events{/privacy}",
"received_events_url": "https://api.github.com/users/ardeaf/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I don't think that this makes sense. What does it mean to \"call\" a db variable anyways? I think it's clear enough."
] | 2017-05-12T21:47:56 | 2017-05-14T00:59:12 | 2017-05-14T00:59:12 | NONE | null | Just a sample of what I was thinking of adding to the quickstart.
This commit fixes #1271. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1272/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1272/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/1272",
"html_url": "https://github.com/coleifer/peewee/pull/1272",
"diff_url": "https://github.com/coleifer/peewee/pull/1272.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/1272.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/1271 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1271/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1271/comments | https://api.github.com/repos/coleifer/peewee/issues/1271/events | https://github.com/coleifer/peewee/issues/1271 | 228,409,951 | MDU6SXNzdWUyMjg0MDk5NTE= | 1,271 | Tests in separate modules | {
"login": "ardeaf",
"id": 20672831,
"node_id": "MDQ6VXNlcjIwNjcyODMx",
"avatar_url": "https://avatars.githubusercontent.com/u/20672831?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/ardeaf",
"html_url": "https://github.com/ardeaf",
"followers_url": "https://api.github.com/users/ardeaf/followers",
"following_url": "https://api.github.com/users/ardeaf/following{/other_user}",
"gists_url": "https://api.github.com/users/ardeaf/gists{/gist_id}",
"starred_url": "https://api.github.com/users/ardeaf/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/ardeaf/subscriptions",
"organizations_url": "https://api.github.com/users/ardeaf/orgs",
"repos_url": "https://api.github.com/users/ardeaf/repos",
"events_url": "https://api.github.com/users/ardeaf/events{/privacy}",
"received_events_url": "https://api.github.com/users/ardeaf/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"This is not Peewee, this is Python. The database attribute of the Model's `Meta` class holds a reference to the `db` object a module scope... This is resolved at module-load time. So no magic.",
"@ardeaf That's an easy mistake to make. If you want to be absolutely sure to use the right connection, I think you could do:\r\n\r\n with BaseModel.Meta.database.atomic():\r\n\r\nBut that's super ugly, yeah..."
] | 2017-05-12T21:14:21 | 2017-05-15T06:27:39 | 2017-05-14T01:01:01 | NONE | null | I followed the quickstart guide and wasn't as thorough as I should have been with the docs, eventually locating the "extra" section which solved my problem. However, I think adding to the docs a best practices note in the quickstart on how to do tests with peewee would be beneficial.
My tests were in separate module, so I didn't know I was using a different db connection in my test modules when I made the db variable at the beginning of my test modules. I was trying to use transactions:
main/models.py
```
from peewee import *
db = SqliteDatabase('/home/ardeaf/my_app.db')
class BaseModel(Model):
class Meta:
database = db
class User(BaseModel):
username = CharField(unique=True)
```
tests/test_models.py
```
from main.models import User
db = SqliteDatabase('/home/ardeaf/my_app.db')
test_save_user():
db.atomic() as txn:
username.Create("ardeaf")
assert User.get(User.username == "ardeaf").username == "ardeaf"
txn.rollback
````
So that wasn't working -- admittedly, I'm an idiot. Tests passed, but database wasn't being rolled back. I eventually figured out the whole connection thing and ended up making my database dynamically defined at runtime.
However, it might be great to add a how-to on this in the quickstart docs in case someone was writing tests. I believe this would also be the case if you end up using the models in different modules, right? Perhaps a quick note explaining how to do that would help.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1271/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1271/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1270 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1270/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1270/comments | https://api.github.com/repos/coleifer/peewee/issues/1270/events | https://github.com/coleifer/peewee/issues/1270 | 227,933,639 | MDU6SXNzdWUyMjc5MzM2Mzk= | 1,270 | FTSModels for sqlite - weights in search() and search_bm25() don't work. | {
"login": "eugeniominissale",
"id": 24990712,
"node_id": "MDQ6VXNlcjI0OTkwNzEy",
"avatar_url": "https://avatars.githubusercontent.com/u/24990712?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/eugeniominissale",
"html_url": "https://github.com/eugeniominissale",
"followers_url": "https://api.github.com/users/eugeniominissale/followers",
"following_url": "https://api.github.com/users/eugeniominissale/following{/other_user}",
"gists_url": "https://api.github.com/users/eugeniominissale/gists{/gist_id}",
"starred_url": "https://api.github.com/users/eugeniominissale/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/eugeniominissale/subscriptions",
"organizations_url": "https://api.github.com/users/eugeniominissale/orgs",
"repos_url": "https://api.github.com/users/eugeniominissale/repos",
"events_url": "https://api.github.com/users/eugeniominissale/events{/privacy}",
"received_events_url": "https://api.github.com/users/eugeniominissale/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I found a bug in the Python implementation of the default rank() function...the Cython version worked fine, but the Python version wasn't respecting the weights parameter due to some careless variable naming on my part. When I run it locally, I now get the following output:\r\n\r\n```python\r\n(u'mario', -2.0)\r\n(u'documento', -1.0)\r\n(u'documento', u'mario', -0.0)\r\n(u'mario', u'descrizione', -0.0)\r\n```\r\n\r\nThis doesn't address your question about BM25, but the BM25 scoring function is actually unit-tested and I know from using it on my own projects that it does work. To ensure this, I've added an additional unit-test that specifically tests the weight parameter. You can view the code here: cfd5aee9f85352a7a7b0054467eaa0d6ad5b87d9\r\n\r\nI think that perhaps the `0.` results are simply a result of the sample size being so constrained."
] | 2017-05-11T09:38:27 | 2017-05-17T03:15:08 | 2017-05-17T03:15:08 | NONE | null | I'm having an issue using the sqlite_ext FTS extension.
That's the example of the documentation:
```from playhouse.signals import Model
from playhouse.sqlite_ext import SqliteExtDatabase, FTSModel, SearchField
from peewee import TextField
db = SqliteExtDatabase(':memory:', threadlocals=True)
class Document(Model):
title = TextField(null=False, unique=True)
content = TextField(null=False)
class Meta:
database = db
class DocumentIndex(FTSModel):
title = SearchField()
content = SearchField()
class Meta:
database = db
extension_options = {'tokenize': 'porter'}
def store_document(document):
DocumentIndex.insert({
DocumentIndex.docid: document.id,
DocumentIndex.title: document.title,
DocumentIndex.content: document.content}).execute()
def search(phrase):
docs = DocumentIndex.search(
phrase,
weights={'title': 2.0, 'content': 1.0},
with_score=True,
score_alias='search_score')
for result in docs:
print(result.title, result.search_score)
def search_bm25(phrase):
best_bm25 = DocumentIndex.search_bm25(phrase,
weights=[2.0, 1.0],
with_score=True).tuples()
for result in best_bm25:
print(result)
Document.create_table(fail_silently=True)
DocumentIndex.create_table(fail_silently=True)
DocumentIndex.rebuild()
DocumentIndex.optimize()
if __name__ == '__main__':
doc1 = Document.create(
title="documento",
content="mario")
doc2 = Document.create(
title="mario",
content="descrizione")
store_document(doc1)
store_document(doc2)
search('mario')
search_bm25('mario')
```
The ouput given is not what I expect.
```
documento -0.0
mario -0.0
('documento', 'mario', -0.0)
('mario', 'descrizione', -0.0)
```
Seems like when I put some weights inside the functions the calculated score is automatically set to -0.0.
Am I missing something? | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1270/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1270/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1269 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1269/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1269/comments | https://api.github.com/repos/coleifer/peewee/issues/1269/events | https://github.com/coleifer/peewee/issues/1269 | 227,554,374 | MDU6SXNzdWUyMjc1NTQzNzQ= | 1,269 | db.create_table() and db.create_tables([,]) have different behavior? | {
"login": "piperck",
"id": 8776176,
"node_id": "MDQ6VXNlcjg3NzYxNzY=",
"avatar_url": "https://avatars.githubusercontent.com/u/8776176?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/piperck",
"html_url": "https://github.com/piperck",
"followers_url": "https://api.github.com/users/piperck/followers",
"following_url": "https://api.github.com/users/piperck/following{/other_user}",
"gists_url": "https://api.github.com/users/piperck/gists{/gist_id}",
"starred_url": "https://api.github.com/users/piperck/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/piperck/subscriptions",
"organizations_url": "https://api.github.com/users/piperck/orgs",
"repos_url": "https://api.github.com/users/piperck/repos",
"events_url": "https://api.github.com/users/piperck/events{/privacy}",
"received_events_url": "https://api.github.com/users/piperck/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"These methods are very confusingly named -- apologies for that.\r\n\r\nHistory:\r\n\r\nOriginally, you would use `Model.create_table()` which would create the table along with the indexes and other constraints. The `Database.create_table()` method was used behind-the-scenes and it **only** creates the table -- not indexes.\r\n\r\nThen I realized there is a common situation where you need to create many tables, and create them in the right order so that the dependency graph is created correctly. To accomplish this, I added the `Database.create_tables()` method (table**s**). It accepts a list of models, does a topological sort to obtain a total ordering, then calls `Model.create_table()` on each table in succession, which ensures the indexes are created as well.\r\n\r\nSo, long story short, `Database.create_table()` should not be used unless you have a very specific reason for using it.\r\n\r\nYou should use `Model.create_table()` to create a single model's table & indexes, and `Database.create_tables()` when you want to create tables & indexes for more than one model.",
"Ok! Thanks for your long story and long story short !!\r\n It entirely solve my problem!🤣😇"
] | 2017-05-10T03:00:13 | 2017-05-10T03:20:45 | 2017-05-10T03:20:45 | CONTRIBUTOR | null | ```python
class Account(BaseModel):
class Meta:
db_table = 'account'
indexes = (
(('app_id', 'user_id'), True),
)
app_id = IntegerField()
user_id = IntegerField()
amount = DecimalField(15, 2)
create_time = DateTimeField(default=datetime.datetime.now)
update_time = DateTimeField(default=datetime.datetime.now)
```
I try to create my tables.And I found if I use `create_table(Account)` can not make `indexes=(xx)` coming into effect.
I use `show create table account` check my mysql_tables. It shows
```sql
| account | CREATE TABLE `account` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`app_id` int(11) NOT NULL,
`user_id` int(11) NOT NULL,
`amount` decimal(15,2) NOT NULL,
`create_time` datetime NOT NULL,
`update_time` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci |
```
But I use `create_tables([Account,])`, It works!
```sql
| account | CREATE TABLE `account` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`app_id` int(11) NOT NULL,
`user_id` int(11) NOT NULL,
`amount` decimal(15,2) NOT NULL,
`create_time` datetime NOT NULL,
`update_time` datetime NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `account_app_id_user_id` (`app_id`,`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci |
```
Is this a problem or expectable? | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1269/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1269/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1268 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1268/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1268/comments | https://api.github.com/repos/coleifer/peewee/issues/1268/events | https://github.com/coleifer/peewee/issues/1268 | 227,548,246 | MDU6SXNzdWUyMjc1NDgyNDY= | 1,268 | Pwiz requires workaround for columns beginning with numbers | {
"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 | [] | 2017-05-10T02:11:30 | 2017-05-10T02:39:44 | 2017-05-10T02:39:44 | OWNER | null | I'm trying out peewee on one of our existing development mysql databases. I've run pwiz and generated a database model. I've noticed a python/db problem with class variables starting with numbers. Does peewee have a solution for dealing with this issue? I couldn't find anything addressing this problem in the documentation.
```python
class AshFinderGryM2F2G3F3G4Rat1D3HMin13ETests(BaseModel):
4m5_min = FloatField()
alarm = IntegerField()
alarm1 = IntegerField()
alarm2 = IntegerField()
alarm3 = IntegerField()
...
class AshFinderRayRealdaytimeTests(BaseModel):
10_perc_4m5 = FloatField(null=True)
10_perc_ash_group_num_pix = IntegerField(null=True)
90_perc_4m5 = FloatField(null=True)
90_perc_ash_group_num_pix = IntegerField(null=True)
alarm = IntegerField()
alarm_4m5 = IntegerField()
...
```
--- received in contact form sent through my site. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1268/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1268/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1267 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1267/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1267/comments | https://api.github.com/repos/coleifer/peewee/issues/1267/events | https://github.com/coleifer/peewee/issues/1267 | 227,263,508 | MDU6SXNzdWUyMjcyNjM1MDg= | 1,267 | Child table referencing a mother table | {
"login": "martinjoubert",
"id": 1816885,
"node_id": "MDQ6VXNlcjE4MTY4ODU=",
"avatar_url": "https://avatars.githubusercontent.com/u/1816885?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/martinjoubert",
"html_url": "https://github.com/martinjoubert",
"followers_url": "https://api.github.com/users/martinjoubert/followers",
"following_url": "https://api.github.com/users/martinjoubert/following{/other_user}",
"gists_url": "https://api.github.com/users/martinjoubert/gists{/gist_id}",
"starred_url": "https://api.github.com/users/martinjoubert/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/martinjoubert/subscriptions",
"organizations_url": "https://api.github.com/users/martinjoubert/orgs",
"repos_url": "https://api.github.com/users/martinjoubert/repos",
"events_url": "https://api.github.com/users/martinjoubert/events{/privacy}",
"received_events_url": "https://api.github.com/users/martinjoubert/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"That works perfectly in the end. My mistake was elsewhere.\r\n\r\nHave a nice day!"
] | 2017-05-09T06:30:09 | 2017-05-09T06:43:12 | 2017-05-09T06:43:12 | NONE | null | Hi!
I can't figure out how to get a table referencing itself. My goal is to get a child table referencing a mother table with same types.
This code seems to be not working:
DeferredMyTable = DeferredRelation()
class MyTable(BaseModel):
name = TextField()
image = TextField()
root_my_table_id = ForeignKeyField(MyTable, null=True)
class Meta:
db_table = 'MyTable'
DeferredMyTable.set_model(MyTable)
Am I wrong when I design my table like that or is it an issue?
Regards,
Gaël | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1267/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1267/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1266 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1266/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1266/comments | https://api.github.com/repos/coleifer/peewee/issues/1266/events | https://github.com/coleifer/peewee/issues/1266 | 227,259,056 | MDU6SXNzdWUyMjcyNTkwNTY= | 1,266 | Bad Magic Number | {
"login": "ahopkins",
"id": 166269,
"node_id": "MDQ6VXNlcjE2NjI2OQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/166269?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/ahopkins",
"html_url": "https://github.com/ahopkins",
"followers_url": "https://api.github.com/users/ahopkins/followers",
"following_url": "https://api.github.com/users/ahopkins/following{/other_user}",
"gists_url": "https://api.github.com/users/ahopkins/gists{/gist_id}",
"starred_url": "https://api.github.com/users/ahopkins/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/ahopkins/subscriptions",
"organizations_url": "https://api.github.com/users/ahopkins/orgs",
"repos_url": "https://api.github.com/users/ahopkins/repos",
"events_url": "https://api.github.com/users/ahopkins/events{/privacy}",
"received_events_url": "https://api.github.com/users/ahopkins/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"It seems maybe someone should look into the pypi package. I installed via git, and that seemed fine.",
"Thanks for bringing this to my attention. Pushed a new minor release and verified it is working correctly for me using 2.7 and 3.6 + PyPI."
] | 2017-05-09T06:02:10 | 2017-05-09T09:15:40 | 2017-05-09T09:15:40 | NONE | null | I created a new virtualenv to test out peewee. I was simply trying to follow the [Quick Start](http://docs.peewee-orm.com/en/latest/peewee/quickstart.html).
mkvirtualenv peweetest -p python3
python
>>> import peewee
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: bad magic number in 'peewee': b'\x03\xf3\r\n'
I have python 3.5 running (I also tried with 2.7 and 3.6), and peewee is on v 2.10.0.
Anyone else see this? Ideas?
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1266/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1266/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1265 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1265/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1265/comments | https://api.github.com/repos/coleifer/peewee/issues/1265/events | https://github.com/coleifer/peewee/issues/1265 | 227,241,853 | MDU6SXNzdWUyMjcyNDE4NTM= | 1,265 | Done | {
"login": "congaductq",
"id": 19276305,
"node_id": "MDQ6VXNlcjE5Mjc2MzA1",
"avatar_url": "https://avatars.githubusercontent.com/u/19276305?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/congaductq",
"html_url": "https://github.com/congaductq",
"followers_url": "https://api.github.com/users/congaductq/followers",
"following_url": "https://api.github.com/users/congaductq/following{/other_user}",
"gists_url": "https://api.github.com/users/congaductq/gists{/gist_id}",
"starred_url": "https://api.github.com/users/congaductq/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/congaductq/subscriptions",
"organizations_url": "https://api.github.com/users/congaductq/orgs",
"repos_url": "https://api.github.com/users/congaductq/repos",
"events_url": "https://api.github.com/users/congaductq/events{/privacy}",
"received_events_url": "https://api.github.com/users/congaductq/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Uhhhh",
"@coleifer Sorry about that, I just don't want to make trash here."
] | 2017-05-09T03:47:32 | 2017-05-09T05:16:51 | 2017-05-09T04:24:32 | NONE | null | Done | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1265/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1265/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1264 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1264/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1264/comments | https://api.github.com/repos/coleifer/peewee/issues/1264/events | https://github.com/coleifer/peewee/issues/1264 | 226,693,174 | MDU6SXNzdWUyMjY2OTMxNzQ= | 1,264 | Potential for security issues with AESEncryptedField | {
"login": "cym13",
"id": 4958985,
"node_id": "MDQ6VXNlcjQ5NTg5ODU=",
"avatar_url": "https://avatars.githubusercontent.com/u/4958985?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/cym13",
"html_url": "https://github.com/cym13",
"followers_url": "https://api.github.com/users/cym13/followers",
"following_url": "https://api.github.com/users/cym13/following{/other_user}",
"gists_url": "https://api.github.com/users/cym13/gists{/gist_id}",
"starred_url": "https://api.github.com/users/cym13/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/cym13/subscriptions",
"organizations_url": "https://api.github.com/users/cym13/orgs",
"repos_url": "https://api.github.com/users/cym13/repos",
"events_url": "https://api.github.com/users/cym13/events{/privacy}",
"received_events_url": "https://api.github.com/users/cym13/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"@cym13 -- may I ask what you intend to use the `AESEncryptedField` for? Is this for an application you're working on?",
"Sorry, I should've added -- I definitely intend to address the issues you've raised. Thanks. I also edited the title of the comment to be a little more representative of the situation.\r\n\r\nThe code I'm using **is mostly based on the example in pycrypto itself**, [you can see here](https://pypi.python.org/pypi/pycrypto):\r\n\r\n```python\r\n>>> from Crypto.Cipher import AES\r\n>>> obj = AES.new('This is a key123', AES.MODE_CBC, 'This is an IV456')\r\n>>> message = \"The answer is no\"\r\n>>> ciphertext = obj.encrypt(message)\r\n>>> ciphertext\r\n'\\xd6\\x83\\x8dd!VT\\x92\\xaa`A\\x05\\xe0\\x9b\\x8b\\xf1'\r\n>>> obj2 = AES.new('This is a key123', AES.MODE_CBC, 'This is an IV456')\r\n>>> obj2.decrypt(ciphertext)\r\n'The answer is no'\r\n```\r\n\r\nVersus peewee:\r\n\r\n```python\r\n def get_cipher(self, key, iv):\r\n if len(key) > 32:\r\n raise ValueError('Key length cannot exceed 32 bytes.')\r\n key = key + bytes(' ') * (32 - len(key))\r\n return AES.new(key, AES.MODE_CFB, iv)\r\n\r\n def encrypt(self, value):\r\n iv = Random.get_random_bytes(AES.block_size)\r\n cipher = self.get_cipher(self.key, iv)\r\n return iv + cipher.encrypt(value)\r\n\r\n def decrypt(self, value):\r\n iv = value[:AES.block_size]\r\n cipher = self.get_cipher(self.key, iv)\r\n return cipher.decrypt(value[AES.block_size:])\r\n\r\n```",
"I don't use this field myself, someone else I know does. Maybe he'll come comment himself he he feels like so.\r\n\r\nWhat PyCrypto does is completely different from what your code does and the PyCrypto snippet you choose shows nothing of its internal mechanics. I'm sorry, but there's no way arround it: AESEncryptedField is broken and endangers its users. Maybe I'll take some time this weekend to demonstrate actual decryption, the flaw is important enough that I have no doubt about the feasibility of it. It's not one of those theoretical issues.\r\n\r\nAs a side note I would recommend against taking PyCrypto as a reference when it comes to security. The project is very flawed itself with some vulnerabilities that aren't likely to be fixed ever (https://github.com/dlitz/pycrypto/issues/176). The API makes it very easy to get things wrong too. Try https://pypi.python.org/pypi/cryptography or PyCryptodome which is a fork of PyCrypto if you need compatibility.",
"Thanks for the explanation. I'll go ahead and remove the field, that seems like the best option.",
"Removed for 2.10.0: https://github.com/coleifer/peewee/releases/tag/2.10.0 -- thanks for bringing these problems to my attention."
] | 2017-05-05T21:11:58 | 2017-05-08T21:11:41 | 2017-05-08T21:11:41 | NONE | null | Hi,
The AESEncryptField's encryption is initialized as such:
def get_cipher(self, key, iv):
if len(key) > 32:
raise ValueError('Key length cannot exceed 32 bytes.')
key = key + bytes(' ') * (32 - len(key))
return AES.new(key, AES.MODE_CFB, iv)
It doesn'st use a key derivation algorithm such as PBKDF2 and padds the key with spaces. This is wrong on two levels:
- The key needs to be random. Using the password directly exposes it to frequency attacks.
- If the key isn't 32 chars long then you are guaranteed that the last byte of the key is a space. In the same way you are almost guaranteed that the byte before is a space. In fact, as people think that this is a password they're not likely to use much more than 12 characters, which means that half the key will often be spaces. This has of course dramatic consequences on the security of encrypted data.
Besides there have been attacks against CFB mode but it doesn't seem usable there. If you can I'd recommend using CTR instead.
EDIT: fixed misleading terminology | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1264/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1264/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1263 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1263/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1263/comments | https://api.github.com/repos/coleifer/peewee/issues/1263/events | https://github.com/coleifer/peewee/pull/1263 | 226,692,111 | MDExOlB1bGxSZXF1ZXN0MTE5MjU4NzU4 | 1,263 | Fix AESEncryptField for python3 | {
"login": "Moutix",
"id": 7975575,
"node_id": "MDQ6VXNlcjc5NzU1NzU=",
"avatar_url": "https://avatars.githubusercontent.com/u/7975575?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/Moutix",
"html_url": "https://github.com/Moutix",
"followers_url": "https://api.github.com/users/Moutix/followers",
"following_url": "https://api.github.com/users/Moutix/following{/other_user}",
"gists_url": "https://api.github.com/users/Moutix/gists{/gist_id}",
"starred_url": "https://api.github.com/users/Moutix/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/Moutix/subscriptions",
"organizations_url": "https://api.github.com/users/Moutix/orgs",
"repos_url": "https://api.github.com/users/Moutix/repos",
"events_url": "https://api.github.com/users/Moutix/events{/privacy}",
"received_events_url": "https://api.github.com/users/Moutix/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Related to: https://github.com/coleifer/peewee/issues/1262",
"The tests for the playhouse extra_fields are not run automatically. Is there a particular reason?",
"Will all those byte literals be compatible with Python 2.6?",
"See comments on #1262 and #1264 "
] | 2017-05-05T21:07:00 | 2017-05-08T21:12:39 | 2017-05-08T21:12:39 | NONE | null | In python3 you can't create a bytes string with bytes(' ') because you need to specify an encoding.
```
2017-05-05 22:34:43,025 ERROR File "/home/moutix/.virtualenvs/stepmania-server/lib/python3.5/site-packages/playhouse/fields.py", line 320, in get_cipher
key = key + bytes(' ') * (32 - len(key))
2017-05-05 22:34:43,025 ERROR Uncaught exception: string argument without an encoding
``` | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1263/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1263/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/1263",
"html_url": "https://github.com/coleifer/peewee/pull/1263",
"diff_url": "https://github.com/coleifer/peewee/pull/1263.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/1263.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/1262 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1262/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1262/comments | https://api.github.com/repos/coleifer/peewee/issues/1262/events | https://github.com/coleifer/peewee/issues/1262 | 226,691,112 | MDU6SXNzdWUyMjY2OTExMTI= | 1,262 | Encryption with python3 throws TypeError | {
"login": "cym13",
"id": 4958985,
"node_id": "MDQ6VXNlcjQ5NTg5ODU=",
"avatar_url": "https://avatars.githubusercontent.com/u/4958985?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/cym13",
"html_url": "https://github.com/cym13",
"followers_url": "https://api.github.com/users/cym13/followers",
"following_url": "https://api.github.com/users/cym13/following{/other_user}",
"gists_url": "https://api.github.com/users/cym13/gists{/gist_id}",
"starred_url": "https://api.github.com/users/cym13/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/cym13/subscriptions",
"organizations_url": "https://api.github.com/users/cym13/orgs",
"repos_url": "https://api.github.com/users/cym13/repos",
"events_url": "https://api.github.com/users/cym13/events{/privacy}",
"received_events_url": "https://api.github.com/users/cym13/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"This field has been removed in the latest release, 2.10.0. For details and explanation of why, see https://github.com/coleifer/peewee/releases/tag/2.10.0"
] | 2017-05-05T21:02:41 | 2017-05-08T21:12:08 | 2017-05-08T21:12:08 | NONE | null | Hi,
the AESEncryptedField in playhouse/fields.py is broken in python3.
Line 320 we see:
key = key + bytes(' ') * (32 - len(key))
but bytes(' ') isn't valid python3 and will throw a TypeError. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1262/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1262/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1261 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1261/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1261/comments | https://api.github.com/repos/coleifer/peewee/issues/1261/events | https://github.com/coleifer/peewee/pull/1261 | 226,631,919 | MDExOlB1bGxSZXF1ZXN0MTE5MjE2NjQz | 1,261 | README: Use the svg Travis badge | {
"login": "kevinji",
"id": 1146876,
"node_id": "MDQ6VXNlcjExNDY4NzY=",
"avatar_url": "https://avatars.githubusercontent.com/u/1146876?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/kevinji",
"html_url": "https://github.com/kevinji",
"followers_url": "https://api.github.com/users/kevinji/followers",
"following_url": "https://api.github.com/users/kevinji/following{/other_user}",
"gists_url": "https://api.github.com/users/kevinji/gists{/gist_id}",
"starred_url": "https://api.github.com/users/kevinji/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/kevinji/subscriptions",
"organizations_url": "https://api.github.com/users/kevinji/orgs",
"repos_url": "https://api.github.com/users/kevinji/repos",
"events_url": "https://api.github.com/users/kevinji/events{/privacy}",
"received_events_url": "https://api.github.com/users/kevinji/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Cool thankee"
] | 2017-05-05T16:55:02 | 2017-05-08T16:27:26 | 2017-05-08T13:44:51 | CONTRIBUTOR | null | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1261/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1261/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/1261",
"html_url": "https://github.com/coleifer/peewee/pull/1261",
"diff_url": "https://github.com/coleifer/peewee/pull/1261.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/1261.patch",
"merged_at": "2017-05-08T13:44:51"
} |
|
https://api.github.com/repos/coleifer/peewee/issues/1260 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1260/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1260/comments | https://api.github.com/repos/coleifer/peewee/issues/1260/events | https://github.com/coleifer/peewee/issues/1260 | 226,515,064 | MDU6SXNzdWUyMjY1MTUwNjQ= | 1,260 | Aiopeewee | {
"login": "kszucs",
"id": 961747,
"node_id": "MDQ6VXNlcjk2MTc0Nw==",
"avatar_url": "https://avatars.githubusercontent.com/u/961747?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/kszucs",
"html_url": "https://github.com/kszucs",
"followers_url": "https://api.github.com/users/kszucs/followers",
"following_url": "https://api.github.com/users/kszucs/following{/other_user}",
"gists_url": "https://api.github.com/users/kszucs/gists{/gist_id}",
"starred_url": "https://api.github.com/users/kszucs/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/kszucs/subscriptions",
"organizations_url": "https://api.github.com/users/kszucs/orgs",
"repos_url": "https://api.github.com/users/kszucs/repos",
"events_url": "https://api.github.com/users/kszucs/events{/privacy}",
"received_events_url": "https://api.github.com/users/kszucs/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"@kszucs Have you seen https://github.com/05bit/peewee-async ?",
"Sure. Peewee-async uses another approach, with a centralized manager object.",
"@kszucs Neat. Does aiopeewee only support Postgres right now?",
"Only Mysql, but postgres support is easy to implement - need to port only a couple of methods. "
] | 2017-05-05T09:12:07 | 2017-05-08T19:46:07 | 2017-05-08T19:46:07 | NONE | null | I've created an asyncio wrapper for peewee, adapted ideas from torpeewee.
It isn't feature complete yet, but I'm working on it.
@coleifer Could You give me a general feedback?
I need to duplicate a lot of code (due to asyncio nature), but I'm wondering how could I reduce it.
Could You give some advice?
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1260/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1260/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1259 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1259/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1259/comments | https://api.github.com/repos/coleifer/peewee/issues/1259/events | https://github.com/coleifer/peewee/issues/1259 | 226,485,471 | MDU6SXNzdWUyMjY0ODU0NzE= | 1,259 | Add `RetryOperationalError` support for `playhouse.db_url.connect`. | {
"login": "futursolo",
"id": 11693215,
"node_id": "MDQ6VXNlcjExNjkzMjE1",
"avatar_url": "https://avatars.githubusercontent.com/u/11693215?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/futursolo",
"html_url": "https://github.com/futursolo",
"followers_url": "https://api.github.com/users/futursolo/followers",
"following_url": "https://api.github.com/users/futursolo/following{/other_user}",
"gists_url": "https://api.github.com/users/futursolo/gists{/gist_id}",
"starred_url": "https://api.github.com/users/futursolo/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/futursolo/subscriptions",
"organizations_url": "https://api.github.com/users/futursolo/orgs",
"repos_url": "https://api.github.com/users/futursolo/repos",
"events_url": "https://api.github.com/users/futursolo/events{/privacy}",
"received_events_url": "https://api.github.com/users/futursolo/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"You can do this yourself. I assume you have a MySQLDatabase subclass that you intend to use.... You can, then:\r\n\r\n```python\r\n\r\nfrom playhouse.db_url import connect, register_database\r\n\r\nregister_database(MySQLDatabaseSubClass, 'mysqlretry')\r\ndb = connect('mysqlretry://....')\r\n```"
] | 2017-05-05T06:32:47 | 2017-05-08T21:14:33 | 2017-05-08T21:14:33 | NONE | null | Currently, I am working on a project using peewee object model built against both MariaDB(for production) and SQLite(for testing). Using `playhouse.db_url.connect` seems like to be the best solution.
However, when using the MariaDB backend, after a certain amount of time, the service starts to constantly output `Error 2006: MySQL server has gone away` until I restart the service. After some researches, I found that the documentation says it can be mitigated by adding `RetryOperationalError` mixin to the database class, but it cannot be used with `playhouse.db_url.connect`.
Please add `RetryOperationalError` support for `playhouse.db_url.connect`. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1259/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1259/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1258 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1258/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1258/comments | https://api.github.com/repos/coleifer/peewee/issues/1258/events | https://github.com/coleifer/peewee/issues/1258 | 226,397,245 | MDU6SXNzdWUyMjYzOTcyNDU= | 1,258 | Better Error message | {
"login": "MinchinWeb",
"id": 1548809,
"node_id": "MDQ6VXNlcjE1NDg4MDk=",
"avatar_url": "https://avatars.githubusercontent.com/u/1548809?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/MinchinWeb",
"html_url": "https://github.com/MinchinWeb",
"followers_url": "https://api.github.com/users/MinchinWeb/followers",
"following_url": "https://api.github.com/users/MinchinWeb/following{/other_user}",
"gists_url": "https://api.github.com/users/MinchinWeb/gists{/gist_id}",
"starred_url": "https://api.github.com/users/MinchinWeb/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/MinchinWeb/subscriptions",
"organizations_url": "https://api.github.com/users/MinchinWeb/orgs",
"repos_url": "https://api.github.com/users/MinchinWeb/repos",
"events_url": "https://api.github.com/users/MinchinWeb/events{/privacy}",
"received_events_url": "https://api.github.com/users/MinchinWeb/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Unfortunately I don't think so in this case. The error is coming from the fact that the `property` has no setter. The property you've defined overrides the other class attribute, so I'm not even sure how to detect it."
] | 2017-05-04T20:21:35 | 2017-05-05T08:13:23 | 2017-05-05T08:13:23 | NONE | null | I managed to break peewee, but the error message turnout to be be very unhelpful. Ultimately, the issue was I had model with a field and a property of the same name.
Simplified model:
```python
from peewee import CharField, Model
class BaseCustomer(Model):
city = CharField(null=True)
# a bunch of other fields
# about 100 lines of code
@property
def city(self):
return None
```
If you try and add a record with a value for `city`, the error that comes up is `AttributeError: can't set attribute`. This is technically true, but not particularly helpful in figuring out what went wrong (I had to monkey-patch peewee to figure it out myself).
Would it be possible to add a more helpful error message? If detectable, a warning about having a field and a property would have helped me fix my error in a couple of minutes. If nothing else, even just saying what key peewee isn't able to set would be helpful.
P.S. Thanks for peewee; it's been a great help in my projects and is much appreciated!
P.P.S. I'm using peewee v 2.9.2, and the stacktrace I got points to line 4861 of `peewee.py` | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1258/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1258/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1257 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1257/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1257/comments | https://api.github.com/repos/coleifer/peewee/issues/1257/events | https://github.com/coleifer/peewee/issues/1257 | 225,603,230 | MDU6SXNzdWUyMjU2MDMyMzA= | 1,257 | Huge bug - needs high priority | {
"login": "Chemmic",
"id": 8461326,
"node_id": "MDQ6VXNlcjg0NjEzMjY=",
"avatar_url": "https://avatars.githubusercontent.com/u/8461326?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/Chemmic",
"html_url": "https://github.com/Chemmic",
"followers_url": "https://api.github.com/users/Chemmic/followers",
"following_url": "https://api.github.com/users/Chemmic/following{/other_user}",
"gists_url": "https://api.github.com/users/Chemmic/gists{/gist_id}",
"starred_url": "https://api.github.com/users/Chemmic/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/Chemmic/subscriptions",
"organizations_url": "https://api.github.com/users/Chemmic/orgs",
"repos_url": "https://api.github.com/users/Chemmic/repos",
"events_url": "https://api.github.com/users/Chemmic/events{/privacy}",
"received_events_url": "https://api.github.com/users/Chemmic/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"LOL. I'm sorry your shit got fucked so hard. Peewee doesn't fuck very much but when it does it fucks **hard**.\r\n\r\nCan you tell me about the bug?",
"Please comment with some details and I'll re-open for discussion."
] | 2017-05-02T06:40:27 | 2017-05-04T11:54:55 | 2017-05-04T11:54:41 | NONE | null | Hello,
Im using ur program since 2 years now, I figured out that there exists a huge bug wich fucks the whole programe over.
You really Need to work on it and fix it asap.
The program is really unusable without Fixing it so please get your lazy ass off and fix it.
- Chemmic | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1257/reactions",
"total_count": 2,
"+1": 0,
"-1": 1,
"laugh": 1,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1257/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1256 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1256/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1256/comments | https://api.github.com/repos/coleifer/peewee/issues/1256/events | https://github.com/coleifer/peewee/issues/1256 | 224,786,899 | MDU6SXNzdWUyMjQ3ODY4OTk= | 1,256 | StopIteration thrown using load_csv | {
"login": "horkko",
"id": 9282917,
"node_id": "MDQ6VXNlcjkyODI5MTc=",
"avatar_url": "https://avatars.githubusercontent.com/u/9282917?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/horkko",
"html_url": "https://github.com/horkko",
"followers_url": "https://api.github.com/users/horkko/followers",
"following_url": "https://api.github.com/users/horkko/following{/other_user}",
"gists_url": "https://api.github.com/users/horkko/gists{/gist_id}",
"starred_url": "https://api.github.com/users/horkko/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/horkko/subscriptions",
"organizations_url": "https://api.github.com/users/horkko/orgs",
"repos_url": "https://api.github.com/users/horkko/repos",
"events_url": "https://api.github.com/users/horkko/events{/privacy}",
"received_events_url": "https://api.github.com/users/horkko/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"It looks like the CSV reader is expecting more lines in the file than there are. The CSV code is tested and should be working, so I doubt a bug as serious as \"loading a CSV file is broken\"... Guessing the issue is with the file.",
"How many lines are needed at least for expecting CSV reader to work as expected?\r\nShould I set `sample_size` greater than default 10? My CSV file is 15 lines long ...."
] | 2017-04-27T13:40:06 | 2017-04-27T19:08:56 | 2017-04-27T15:48:41 | NONE | null | Hi,
I try to load a csv file in sqlite db using `peewee 2.8.1`.
To do so, I've been using `playhouse.csv_utils`.
However, when I try to load CSV file, I've got a `StopIteration` thrown:
```
File "/home/tuco/src/workspace/taxadb/lib/python3.5/site-packages/playhouse/csv_utils.py", line 309, in load_csv
return loader.load()
File "/home/tuco/src/workspace/taxadb/lib/python3.5/site-packages/playhouse/csv_utils.py", line 277, in load
next(reader)
StopIteration
```
Below are the first 3 lines of my csv file:
```
ncbi_taxid,parent_taxid,tax_name,lineage_level
1,1,root,no rank
2,131567,Bacteria,superkingdom
...
```
and the way I call `load_csv`:
```python
...
load_csv(model, data, has_header=True, delimiter=",")
...
```
where `model` is as such:
```python
class Taxa(BaseModel):
ncbi_taxid = pw.IntegerField(null=False, primary_key=True, unique=True)
parent_taxid = pw.IntegerField(null=False)
tax_name = pw.CharField()
lineage_level = pw.CharField()
```
and `BaseModel` as below:
```python
db = peewee.Proxy()
class BaseModel(peewee.Model):
class Meta:
database = db
```
If I use a `database` object instead of a `model` another error is then thrown:
```python
...
File "/home/tuco/src/workspace/taxadb/lib/python3.5/site-packages/playhouse/csv_utils.py", line 309, in load_csv
return loader.load()
File "/home/tuco/src/workspace/taxadb/lib/python3.5/site-packages/playhouse/csv_utils.py", line 266, in load
self.analyze_csv()
File "/home/tuco/src/workspace/taxadb/lib/python3.5/site-packages/playhouse/csv_utils.py", line 243, in analyze_csv
**self.reader_kwargs)
File "/home/tuco/src/workspace/taxadb/lib/python3.5/site-packages/playhouse/csv_utils.py", line 138, in extract_rows
header, rows = rows[0], rows[1:]
IndexError: list index out of range
```
Is there something I do not use or set correctly?
Thx | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1256/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1256/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1255 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1255/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1255/comments | https://api.github.com/repos/coleifer/peewee/issues/1255/events | https://github.com/coleifer/peewee/issues/1255 | 224,164,370 | MDU6SXNzdWUyMjQxNjQzNzA= | 1,255 | playhouse dburl if password contains '@' , the parse will failed | {
"login": "ygsun",
"id": 2366231,
"node_id": "MDQ6VXNlcjIzNjYyMzE=",
"avatar_url": "https://avatars.githubusercontent.com/u/2366231?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/ygsun",
"html_url": "https://github.com/ygsun",
"followers_url": "https://api.github.com/users/ygsun/followers",
"following_url": "https://api.github.com/users/ygsun/following{/other_user}",
"gists_url": "https://api.github.com/users/ygsun/gists{/gist_id}",
"starred_url": "https://api.github.com/users/ygsun/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/ygsun/subscriptions",
"organizations_url": "https://api.github.com/users/ygsun/orgs",
"repos_url": "https://api.github.com/users/ygsun/repos",
"events_url": "https://api.github.com/users/ygsun/events{/privacy}",
"received_events_url": "https://api.github.com/users/ygsun/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"IDK, it seems like it works to me:\r\n\r\n```python\r\nIn [3]: parse('postgresql://postgres:my_p@ssword@localhost:5432/my_database')\r\nOut[3]: \r\n{'database': 'my_database',\r\n 'host': 'localhost',\r\n 'password': 'my_p@ssword',\r\n 'port': 5432,\r\n 'user': 'postgres'}\r\n```"
] | 2017-04-25T14:47:00 | 2017-04-25T14:55:54 | 2017-04-25T14:55:53 | NONE | null | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1255/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1255/timeline | null | completed | null | null |
|
https://api.github.com/repos/coleifer/peewee/issues/1254 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1254/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1254/comments | https://api.github.com/repos/coleifer/peewee/issues/1254/events | https://github.com/coleifer/peewee/issues/1254 | 223,083,772 | MDU6SXNzdWUyMjMwODM3NzI= | 1,254 | Decorator for 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 | [
"It won't work as a class decorator, I don't think -- not without dynamically modifying the setup/teardown methods."
] | 2017-04-20T14:20:16 | 2017-05-14T01:30:38 | 2017-05-14T01:30:38 | NONE | null | Using the the context manager test_database is very useful while testing. But I found myself writing that a lot in the tests which amounted to quite some boilerplate. Perhaps it would be worthwhile to make that usable as class decorator?
Let me know what you think. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1254/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1254/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1253 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1253/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1253/comments | https://api.github.com/repos/coleifer/peewee/issues/1253/events | https://github.com/coleifer/peewee/issues/1253 | 222,872,189 | MDU6SXNzdWUyMjI4NzIxODk= | 1,253 | How should I structure my peewee postgres database for hosting on heroku | {
"login": "rahul3103",
"id": 10813252,
"node_id": "MDQ6VXNlcjEwODEzMjUy",
"avatar_url": "https://avatars.githubusercontent.com/u/10813252?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/rahul3103",
"html_url": "https://github.com/rahul3103",
"followers_url": "https://api.github.com/users/rahul3103/followers",
"following_url": "https://api.github.com/users/rahul3103/following{/other_user}",
"gists_url": "https://api.github.com/users/rahul3103/gists{/gist_id}",
"starred_url": "https://api.github.com/users/rahul3103/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/rahul3103/subscriptions",
"organizations_url": "https://api.github.com/users/rahul3103/orgs",
"repos_url": "https://api.github.com/users/rahul3103/repos",
"events_url": "https://api.github.com/users/rahul3103/events{/privacy}",
"received_events_url": "https://api.github.com/users/rahul3103/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Responded on SO. Issue had nothing to do w/your peewee setup."
] | 2017-04-19T21:08:03 | 2017-04-19T22:32:40 | 2017-04-19T22:32:40 | NONE | null | http://stackoverflow.com/questions/43505529/peewee-and-postgres-on-heroku-not-able-to-create-table
I tried a lot but I was not able to run a simple code with peewee and postgres on heroku. Without database my app is running on heroku but with peewee and database its not running. If you can help me a little bit it will be great. The app [link](https://github.com/rahul3103/test-heroku) | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1253/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1253/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1252 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1252/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1252/comments | https://api.github.com/repos/coleifer/peewee/issues/1252/events | https://github.com/coleifer/peewee/issues/1252 | 222,687,969 | MDU6SXNzdWUyMjI2ODc5Njk= | 1,252 | Automatically creating all tables, in right order. | {
"login": "tomvlk",
"id": 3877688,
"node_id": "MDQ6VXNlcjM4Nzc2ODg=",
"avatar_url": "https://avatars.githubusercontent.com/u/3877688?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/tomvlk",
"html_url": "https://github.com/tomvlk",
"followers_url": "https://api.github.com/users/tomvlk/followers",
"following_url": "https://api.github.com/users/tomvlk/following{/other_user}",
"gists_url": "https://api.github.com/users/tomvlk/gists{/gist_id}",
"starred_url": "https://api.github.com/users/tomvlk/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/tomvlk/subscriptions",
"organizations_url": "https://api.github.com/users/tomvlk/orgs",
"repos_url": "https://api.github.com/users/tomvlk/repos",
"events_url": "https://api.github.com/users/tomvlk/events{/privacy}",
"received_events_url": "https://api.github.com/users/tomvlk/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"`db.create_tables()` does just that.",
"I'm very sorry, thanks :+1: "
] | 2017-04-19T10:14:01 | 2017-04-19T20:24:27 | 2017-04-19T19:39:10 | NONE | null | I don't know if this was suggested before, but it would be great to have a function to create all tables, that automatically orders them in dependencies (like foreign keys etc.) so you would be able to have a dynamic application with dynamic models easily running without having to struggle with foreign keys while creating tables. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1252/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1252/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1251 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1251/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1251/comments | https://api.github.com/repos/coleifer/peewee/issues/1251/events | https://github.com/coleifer/peewee/issues/1251 | 222,113,090 | MDU6SXNzdWUyMjIxMTMwOTA= | 1,251 | Return back LTreeField support | {
"login": "spumer",
"id": 735150,
"node_id": "MDQ6VXNlcjczNTE1MA==",
"avatar_url": "https://avatars.githubusercontent.com/u/735150?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/spumer",
"html_url": "https://github.com/spumer",
"followers_url": "https://api.github.com/users/spumer/followers",
"following_url": "https://api.github.com/users/spumer/following{/other_user}",
"gists_url": "https://api.github.com/users/spumer/gists{/gist_id}",
"starred_url": "https://api.github.com/users/spumer/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/spumer/subscriptions",
"organizations_url": "https://api.github.com/users/spumer/orgs",
"repos_url": "https://api.github.com/users/spumer/repos",
"events_url": "https://api.github.com/users/spumer/events{/privacy}",
"received_events_url": "https://api.github.com/users/spumer/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I wasn't interested in supporting it. 1.0 was also released back in 2012, a relative eternity ago."
] | 2017-04-17T11:11:53 | 2017-04-17T21:18:26 | 2017-04-17T21:17:32 | NONE | null | I saw in 1.0.0 version peewee have LTreeField support, but now we have only HSTORE and JSON.
Why this feature dropped?
Previous inital support of ltree extension for PG
https://github.com/coleifer/peewee/commit/9959cd8142ecece6704fd82e9c6274de2794d8c4 | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1251/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1251/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1250 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1250/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1250/comments | https://api.github.com/repos/coleifer/peewee/issues/1250/events | https://github.com/coleifer/peewee/pull/1250 | 221,948,656 | MDExOlB1bGxSZXF1ZXN0MTE2MDI1NjAx | 1,250 | Implement __ne__ for CompositeKey. | {
"login": "timster",
"id": 173666,
"node_id": "MDQ6VXNlcjE3MzY2Ng==",
"avatar_url": "https://avatars.githubusercontent.com/u/173666?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/timster",
"html_url": "https://github.com/timster",
"followers_url": "https://api.github.com/users/timster/followers",
"following_url": "https://api.github.com/users/timster/following{/other_user}",
"gists_url": "https://api.github.com/users/timster/gists{/gist_id}",
"starred_url": "https://api.github.com/users/timster/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/timster/subscriptions",
"organizations_url": "https://api.github.com/users/timster/orgs",
"repos_url": "https://api.github.com/users/timster/repos",
"events_url": "https://api.github.com/users/timster/events{/privacy}",
"received_events_url": "https://api.github.com/users/timster/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Wouldn't it just be:\r\n\r\n```python\r\ndef __ne__(self, other):\r\n return ~(self == other)\r\n```",
"Yeah, that works too. Forgot about `~` when I wrote it."
] | 2017-04-15T13:34:30 | 2017-04-18T19:31:51 | 2017-04-18T19:31:51 | NONE | null | For a model with a single primary key, you can do both of these:
```python
(obj._meta.primary_key == obj._get_pk_value())
(obj._meta.primary_key != obj._get_pk_value())
```
And both return a `peewee.Expression` object.
However if the primary key happens to be CompositeKey, the `!=` compare returns `False`.
This fixes that. I can write tests if you'd like. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1250/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1250/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/1250",
"html_url": "https://github.com/coleifer/peewee/pull/1250",
"diff_url": "https://github.com/coleifer/peewee/pull/1250.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/1250.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/1249 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1249/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1249/comments | https://api.github.com/repos/coleifer/peewee/issues/1249/events | https://github.com/coleifer/peewee/issues/1249 | 221,293,901 | MDU6SXNzdWUyMjEyOTM5MDE= | 1,249 | How about make a transparent cache layer? | {
"login": "aiportal",
"id": 878799,
"node_id": "MDQ6VXNlcjg3ODc5OQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/878799?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/aiportal",
"html_url": "https://github.com/aiportal",
"followers_url": "https://api.github.com/users/aiportal/followers",
"following_url": "https://api.github.com/users/aiportal/following{/other_user}",
"gists_url": "https://api.github.com/users/aiportal/gists{/gist_id}",
"starred_url": "https://api.github.com/users/aiportal/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/aiportal/subscriptions",
"organizations_url": "https://api.github.com/users/aiportal/orgs",
"repos_url": "https://api.github.com/users/aiportal/repos",
"events_url": "https://api.github.com/users/aiportal/events{/privacy}",
"received_events_url": "https://api.github.com/users/aiportal/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2017-04-12T15:06:21 | 2017-04-12T18:57:48 | 2017-04-12T18:57:48 | NONE | null | If small table, cache all data in memory or redis or memcached like this:
```
class MyModel(Cache.Model):
Meta:
cache_db = ':memory:' # or 'redis' or 'memcached'
...
```
If big table, cache a part of data by a range define.
```
class MyModel(Cache.Model):
Meta:
cache_db = ':memory:'
cache_range = CacheRange(fieldname, min_value, max_value)
...
```
If need dynamic cache, record select sql history, and merge result data by primary key in cache db.
If new select sql in history, hit cache, if not, select from backend database and cache it.
User can limit cache items count by cache_limit parameter.
If save or delete executed, remove cache data or reload cache data.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1249/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1249/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1248 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1248/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1248/comments | https://api.github.com/repos/coleifer/peewee/issues/1248/events | https://github.com/coleifer/peewee/issues/1248 | 220,857,352 | MDU6SXNzdWUyMjA4NTczNTI= | 1,248 | Allow disabling lazy loading | {
"login": "tuukkamustonen",
"id": 94327,
"node_id": "MDQ6VXNlcjk0MzI3",
"avatar_url": "https://avatars.githubusercontent.com/u/94327?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/tuukkamustonen",
"html_url": "https://github.com/tuukkamustonen",
"followers_url": "https://api.github.com/users/tuukkamustonen/followers",
"following_url": "https://api.github.com/users/tuukkamustonen/following{/other_user}",
"gists_url": "https://api.github.com/users/tuukkamustonen/gists{/gist_id}",
"starred_url": "https://api.github.com/users/tuukkamustonen/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/tuukkamustonen/subscriptions",
"organizations_url": "https://api.github.com/users/tuukkamustonen/orgs",
"repos_url": "https://api.github.com/users/tuukkamustonen/repos",
"events_url": "https://api.github.com/users/tuukkamustonen/events{/privacy}",
"received_events_url": "https://api.github.com/users/tuukkamustonen/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Here are a couple ideas:\r\n\r\n* Use the `<fk field>_id` accessor -- this will return the value of the foreign key column w/o triggering a lookup on the related table.\r\n* Subclass `ForeignKeyField` and override the `_get_descriptor()` method to return a descriptor w/the desired behavior",
"Thanks, I'll try those out!",
"FYI for anyone wondering about the same: I decided to just use option 1 (using `<fk field>_id` as accessor).\r\n\r\nImplementing custom `RelationDescriptor` (option 2) is easy, but it becomes confusing what the field should return:\r\n\r\n```python\r\na = Foo.create()\r\nb = Foo.create(parent=a)\r\n\r\nb.parent # has a instance in object cache so returns a's Foo() instance\r\nb.parent.id # works\r\n\r\nb2 = Foo.get(id=b.id)\r\n\r\nb2.parent # only has PK and parent instance is not cached so should it return int or throw error or what...? if it returns int then:\r\nb2.parent.id # fails to exception\r\n```\r\n\r\nIf I made descriptor always return raw PK value, that would be less confusing, but then doing something like `a.parent.id` would not be possible, even if `a` had parent instance already cached. So, going to use use `<fk field>_id` accessors for now."
] | 2017-04-11T07:01:02 | 2017-04-13T07:44:28 | 2017-04-11T09:27:35 | NONE | null | Is it possible to disable lazy loading of foreign keys somehow? I assume the magic happens in some `__getattr__` or proxy class but not sure where.
You probably don't want to add this as a built-in option, but if you have any pointers to what I should stab, that would be nice.
Use case: I am tuning my code for performance and wouldn't like peewee to do any queries that I didn't intend. I have some quite large fields in DB that I don't want to accidentally load. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1248/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1248/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1247 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1247/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1247/comments | https://api.github.com/repos/coleifer/peewee/issues/1247/events | https://github.com/coleifer/peewee/issues/1247 | 220,624,113 | MDU6SXNzdWUyMjA2MjQxMTM= | 1,247 | The select loop is processed twice | {
"login": "MarcSky",
"id": 4164003,
"node_id": "MDQ6VXNlcjQxNjQwMDM=",
"avatar_url": "https://avatars.githubusercontent.com/u/4164003?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/MarcSky",
"html_url": "https://github.com/MarcSky",
"followers_url": "https://api.github.com/users/MarcSky/followers",
"following_url": "https://api.github.com/users/MarcSky/following{/other_user}",
"gists_url": "https://api.github.com/users/MarcSky/gists{/gist_id}",
"starred_url": "https://api.github.com/users/MarcSky/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/MarcSky/subscriptions",
"organizations_url": "https://api.github.com/users/MarcSky/orgs",
"repos_url": "https://api.github.com/users/MarcSky/repos",
"events_url": "https://api.github.com/users/MarcSky/events{/privacy}",
"received_events_url": "https://api.github.com/users/MarcSky/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Are you using SQLite, and in the body of the for loop are you issuing any INSERT/UPDATE/DELETE queries?",
"#450 touches on this, but essentially you should do one of the following:\r\n\r\n* wrap the for loop in a transaction using `with db.atomic():`\r\n* coerce the select query to a list before iterating over it."
] | 2017-04-10T12:08:54 | 2017-04-10T19:25:08 | 2017-04-10T19:25:07 | NONE | null | I have a strange problem, the select loop is processed twice. Ie I receive from the database 2 objects, and the cycle passes 4 times.
for enter in Enter.select().join(PaySystem).where(
(Enter.en_status == 1) &
(Enter.en_date >= startdate) &
(PaySystem.ps_abbr=='btc')):
I made a variable count and derived its value, it turned out 4. Why is it so? | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1247/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1247/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1246 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1246/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1246/comments | https://api.github.com/repos/coleifer/peewee/issues/1246/events | https://github.com/coleifer/peewee/pull/1246 | 220,515,683 | MDExOlB1bGxSZXF1ZXN0MTE1MDExMjk4 | 1,246 | #1245 Implemented _Array.__repr__(). | {
"login": "maaaks",
"id": 3010238,
"node_id": "MDQ6VXNlcjMwMTAyMzg=",
"avatar_url": "https://avatars.githubusercontent.com/u/3010238?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/maaaks",
"html_url": "https://github.com/maaaks",
"followers_url": "https://api.github.com/users/maaaks/followers",
"following_url": "https://api.github.com/users/maaaks/following{/other_user}",
"gists_url": "https://api.github.com/users/maaaks/gists{/gist_id}",
"starred_url": "https://api.github.com/users/maaaks/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/maaaks/subscriptions",
"organizations_url": "https://api.github.com/users/maaaks/orgs",
"repos_url": "https://api.github.com/users/maaaks/repos",
"events_url": "https://api.github.com/users/maaaks/events{/privacy}",
"received_events_url": "https://api.github.com/users/maaaks/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2017-04-10T01:17:29 | 2017-04-10T19:22:22 | 2017-04-10T19:22:22 | CONTRIBUTOR | null | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1246/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1246/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/1246",
"html_url": "https://github.com/coleifer/peewee/pull/1246",
"diff_url": "https://github.com/coleifer/peewee/pull/1246.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/1246.patch",
"merged_at": null
} |
|
https://api.github.com/repos/coleifer/peewee/issues/1245 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1245/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1245/comments | https://api.github.com/repos/coleifer/peewee/issues/1245/events | https://github.com/coleifer/peewee/issues/1245 | 220,515,322 | MDU6SXNzdWUyMjA1MTUzMjI= | 1,245 | Implement _Array.__repr__() | {
"login": "maaaks",
"id": 3010238,
"node_id": "MDQ6VXNlcjMwMTAyMzg=",
"avatar_url": "https://avatars.githubusercontent.com/u/3010238?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/maaaks",
"html_url": "https://github.com/maaaks",
"followers_url": "https://api.github.com/users/maaaks/followers",
"following_url": "https://api.github.com/users/maaaks/following{/other_user}",
"gists_url": "https://api.github.com/users/maaaks/gists{/gist_id}",
"starred_url": "https://api.github.com/users/maaaks/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/maaaks/subscriptions",
"organizations_url": "https://api.github.com/users/maaaks/orgs",
"repos_url": "https://api.github.com/users/maaaks/repos",
"events_url": "https://api.github.com/users/maaaks/events{/privacy}",
"received_events_url": "https://api.github.com/users/maaaks/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I think I will pass on this, but thank you.",
"Are there maybe some other plans to make the messages containing Arrays more readable?"
] | 2017-04-10T01:12:39 | 2017-04-10T20:21:13 | 2017-04-10T19:22:07 | CONTRIBUTOR | null | For convenient display in lists of params in stderr. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1245/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1245/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1244 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1244/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1244/comments | https://api.github.com/repos/coleifer/peewee/issues/1244/events | https://github.com/coleifer/peewee/pull/1244 | 220,514,665 | MDExOlB1bGxSZXF1ZXN0MTE1MDEwNzAy | 1,244 | Fixed sort_models_topologically() | {
"login": "maaaks",
"id": 3010238,
"node_id": "MDQ6VXNlcjMwMTAyMzg=",
"avatar_url": "https://avatars.githubusercontent.com/u/3010238?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/maaaks",
"html_url": "https://github.com/maaaks",
"followers_url": "https://api.github.com/users/maaaks/followers",
"following_url": "https://api.github.com/users/maaaks/following{/other_user}",
"gists_url": "https://api.github.com/users/maaaks/gists{/gist_id}",
"starred_url": "https://api.github.com/users/maaaks/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/maaaks/subscriptions",
"organizations_url": "https://api.github.com/users/maaaks/orgs",
"repos_url": "https://api.github.com/users/maaaks/repos",
"events_url": "https://api.github.com/users/maaaks/events{/privacy}",
"received_events_url": "https://api.github.com/users/maaaks/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Nice!"
] | 2017-04-10T01:04:45 | 2017-04-10T19:43:07 | 2017-04-10T19:43:07 | CONTRIBUTOR | null | #1076 | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1244/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1244/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/1244",
"html_url": "https://github.com/coleifer/peewee/pull/1244",
"diff_url": "https://github.com/coleifer/peewee/pull/1244.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/1244.patch",
"merged_at": "2017-04-10T19:43:07"
} |
https://api.github.com/repos/coleifer/peewee/issues/1243 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1243/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1243/comments | https://api.github.com/repos/coleifer/peewee/issues/1243/events | https://github.com/coleifer/peewee/issues/1243 | 220,363,755 | MDU6SXNzdWUyMjAzNjM3NTU= | 1,243 | Using attached databases with sqlite? | {
"login": "kdart",
"id": 33999,
"node_id": "MDQ6VXNlcjMzOTk5",
"avatar_url": "https://avatars.githubusercontent.com/u/33999?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/kdart",
"html_url": "https://github.com/kdart",
"followers_url": "https://api.github.com/users/kdart/followers",
"following_url": "https://api.github.com/users/kdart/following{/other_user}",
"gists_url": "https://api.github.com/users/kdart/gists{/gist_id}",
"starred_url": "https://api.github.com/users/kdart/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/kdart/subscriptions",
"organizations_url": "https://api.github.com/users/kdart/orgs",
"repos_url": "https://api.github.com/users/kdart/repos",
"events_url": "https://api.github.com/users/kdart/events{/privacy}",
"received_events_url": "https://api.github.com/users/kdart/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"It should work -- you'll need to run the \"ATTACH\" query at some point by calling database.execute_sql(). As for your model classes -- you may find it easiest to work with two sets of model classes, each of which defines a \"schema\" Meta option of \"main\" and whatever your attached db is. This will prefix all table accesses with the database name (equivalent of specifying the \"schema\").",
"So: it may not be easy, but it should be *possible*. Just experimenting in the shell, it looks like you could do something like this:\r\n\r\n```python\r\nclass MyModel(Model):\r\n data = TextField()\r\n\r\n class Meta:\r\n schema = 'main' # Or omit, but main is default sqlite db\r\n\r\nclass MyModelAttached(MyModel):\r\n class Meta:\r\n db_table = MyModel._meta.db_table\r\n schema = 'cache' # Or whatever the attached db is named\r\n\r\nMyModel.select()\r\n# Outputs SELECT \"t1\".\"id\", \"t1\".\"data\" FROM \"main\".\"mymodel\" AS t1\r\n\r\nMyModelAttached.select()\r\n# Outputs SELECT \"t1\".\"id\", \"t1\".\"data\" FROM \"cache\".\"mymodel\" AS t1\r\n```",
"Thanks for taking the time to investigate that. That can get me started. This method, however, is rather \"static\", as it's embedded in the code. I'm trying to find a way to make the schema dynamic (provided by user). I suppose it's possible to update the meta attribute on the fly. \r\nI'll try that. \r\n",
"You can update the \"meta\" attribute on the fly, but it will affect the class-as-a-whole.",
"OK. sqlite allows you to mix schema per query (SELECT * from main.Table as t1, other.Table as t2 ...) and perform a cross-schema query. At least it appears that way, I haven't tried it yet. I don't see how to accomplish that with the peewee API. It looks to me like that would be a big change. I'll probably have to work around it by using multiple queries to the different schemas. ",
"I've done this before. It's possible and not a complete nightmare. You need to specify the join condition since there are no foreign keys set in peewee in this case.\r\n\r\n```python\r\n\r\nimport peewee\r\n\r\ndatabase = peewee.SqliteDatabase('main.db')\r\n\r\ndatabase.execute_sql('attach database \"another.db\" as other')\r\n\r\nclass Main(peewee.Model):\r\n name = peewee.CharField()\r\n\r\n class Meta:\r\n database = database\r\n schema = 'main'\r\n\r\nclass Other(peewee.Model):\r\n name = peewee.CharField()\r\n\r\n class Meta:\r\n database = database\r\n schema = 'other'\r\n\r\nMain.create_table()\r\nOther.create_table()\r\n\r\nMain.create(name='tim')\r\nOther.create(name='tim')\r\nOther.create(name='john')\r\n\r\nrecord = Main.select().join(Other, on=(Other.name == Main.name)).first()\r\n\r\nprint(record.name)\r\n```",
"thx @timster. FYI, you don't need to update the schema name, as [sqlite will look for tables in attached databases anyway](https://www.sqlite.org/lang_naming.html)."
] | 2017-04-08T00:58:46 | 2019-02-27T16:39:38 | 2017-04-10T20:00:17 | NONE | null | Greetings,
This is more of a feature request or request for comment.
SQlite has a feature to attach multiple database files: [ATTACH DATABASE](https://sqlite.org/lang_attach.html) that seems to enable queries across multiple database files. So I was wondering is there support for this in peewee already, or, if not, how one might accomplish this with peewee.
I'm especially interested in the case where the schema of the two files is the same, but contain different data.
Would a new model definition be required?
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1243/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1243/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1242 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1242/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1242/comments | https://api.github.com/repos/coleifer/peewee/issues/1242/events | https://github.com/coleifer/peewee/pull/1242 | 220,253,160 | MDExOlB1bGxSZXF1ZXN0MTE0ODQ0Njk1 | 1,242 | Model generator support tables with no primary key | {
"login": "onlyice",
"id": 1173899,
"node_id": "MDQ6VXNlcjExNzM4OTk=",
"avatar_url": "https://avatars.githubusercontent.com/u/1173899?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/onlyice",
"html_url": "https://github.com/onlyice",
"followers_url": "https://api.github.com/users/onlyice/followers",
"following_url": "https://api.github.com/users/onlyice/following{/other_user}",
"gists_url": "https://api.github.com/users/onlyice/gists{/gist_id}",
"starred_url": "https://api.github.com/users/onlyice/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/onlyice/subscriptions",
"organizations_url": "https://api.github.com/users/onlyice/orgs",
"repos_url": "https://api.github.com/users/onlyice/repos",
"events_url": "https://api.github.com/users/onlyice/events{/privacy}",
"received_events_url": "https://api.github.com/users/onlyice/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Merged equivalent patch."
] | 2017-04-07T15:47:01 | 2017-04-10T19:47:16 | 2017-04-10T19:47:16 | NONE | null | Currently for tables with no primary key, pwiz would generate model files without `primary_key = False`. Thus peewee assumes that there is a `id` column as primary key in the table, and the query failed.
Add `primary_key = False` in the `Meta` definition would prevent this error. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1242/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1242/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/1242",
"html_url": "https://github.com/coleifer/peewee/pull/1242",
"diff_url": "https://github.com/coleifer/peewee/pull/1242.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/1242.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/1241 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1241/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1241/comments | https://api.github.com/repos/coleifer/peewee/issues/1241/events | https://github.com/coleifer/peewee/issues/1241 | 220,031,775 | MDU6SXNzdWUyMjAwMzE3NzU= | 1,241 | Hybrid Attributes and TextFields don't properly form an expression (SQLite) | {
"login": "ballan91",
"id": 1587844,
"node_id": "MDQ6VXNlcjE1ODc4NDQ=",
"avatar_url": "https://avatars.githubusercontent.com/u/1587844?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/ballan91",
"html_url": "https://github.com/ballan91",
"followers_url": "https://api.github.com/users/ballan91/followers",
"following_url": "https://api.github.com/users/ballan91/following{/other_user}",
"gists_url": "https://api.github.com/users/ballan91/gists{/gist_id}",
"starred_url": "https://api.github.com/users/ballan91/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/ballan91/subscriptions",
"organizations_url": "https://api.github.com/users/ballan91/orgs",
"repos_url": "https://api.github.com/users/ballan91/repos",
"events_url": "https://api.github.com/users/ballan91/events{/privacy}",
"received_events_url": "https://api.github.com/users/ballan91/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Cool -- I think I need to modify the string based fields to use concatenation for the `+` operator overload. Nice catch.",
"1740cc1132ca01d3964f543eca00f1dc9532bc24",
"Thanks for such a swift reply! Release schedule wise, there appear to be a number of fixes since the last release, do you expect to issue a new release in the near future?",
"Just released 2.9.2, thanks!"
] | 2017-04-06T21:00:55 | 2017-04-07T23:46:58 | 2017-04-07T03:26:19 | NONE | null | Basic repro below, but just as the description says, I cannot seem to get the two to play nicely, I was going off some examples in SQLAlchemy which I believe was the basis for hybrid attributes.
Using SQLite and tested with the latest release version of peewee 2.9.1
```python
from peewee import TextField, Model
from playhouse.hybrid import hybrid_property
class TestModel(Model):
first_name = TextField()
last_name = TextField()
@hybrid_property
def full_name(self):
return self.first_name + ' ' + self.last_name
def test():
TestModel.create_table(fail_silently=True)
TestModel.insert(
first_name='John',
last_name='Doe'
).execute()
for person in TestModel.select():
print(person.full_name)
q = TestModel.select().where(
TestModel.full_name == 'John Doe'
)
if q.count() == 0:
print('Failed with')
print(q.sql())
else:
print('Success')
if __name__ == '__main__':
test()
``` | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1241/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1241/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1240 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1240/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1240/comments | https://api.github.com/repos/coleifer/peewee/issues/1240/events | https://github.com/coleifer/peewee/issues/1240 | 219,971,424 | MDU6SXNzdWUyMTk5NzE0MjQ= | 1,240 | Question: Can I use FlaskDB.Model in non-Flask process? | {
"login": "devkhan",
"id": 8049092,
"node_id": "MDQ6VXNlcjgwNDkwOTI=",
"avatar_url": "https://avatars.githubusercontent.com/u/8049092?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/devkhan",
"html_url": "https://github.com/devkhan",
"followers_url": "https://api.github.com/users/devkhan/followers",
"following_url": "https://api.github.com/users/devkhan/following{/other_user}",
"gists_url": "https://api.github.com/users/devkhan/gists{/gist_id}",
"starred_url": "https://api.github.com/users/devkhan/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/devkhan/subscriptions",
"organizations_url": "https://api.github.com/users/devkhan/orgs",
"repos_url": "https://api.github.com/users/devkhan/repos",
"events_url": "https://api.github.com/users/devkhan/events{/privacy}",
"received_events_url": "https://api.github.com/users/devkhan/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"This is do-able. You'll need to initialize the Flask application, though. Something like this:\r\n\r\n```\r\nwith app.app_context():\r\n # Try using the database here.\r\n```\r\n\r\nThis definitely isn't a bug, so I'm closing as this type of question belongs on Stackoverflow."
] | 2017-04-06T17:24:33 | 2017-04-07T03:13:07 | 2017-04-07T03:13:07 | NONE | null | I have defined a model `X` by subclassing `FlaskDB.Model`, and then I want to access one of the instances in a celery worker process. Is it possible, and if so, how should I go about that?
I've already tried that, and receiving an `AttributeError: Cannot use uninitialized Proxy.`. But I guess that is because of not opening a database connection, which also sparks the question that how should I use the database in the worker as there is no Flask app context to provide?
Any help is highly appreciated. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1240/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1240/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1239 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1239/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1239/comments | https://api.github.com/repos/coleifer/peewee/issues/1239/events | https://github.com/coleifer/peewee/issues/1239 | 219,873,343 | MDU6SXNzdWUyMTk4NzMzNDM= | 1,239 | order_by with subqueries and UNION fails to fill model | {
"login": "Karel-van-de-Plassche",
"id": 6404167,
"node_id": "MDQ6VXNlcjY0MDQxNjc=",
"avatar_url": "https://avatars.githubusercontent.com/u/6404167?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/Karel-van-de-Plassche",
"html_url": "https://github.com/Karel-van-de-Plassche",
"followers_url": "https://api.github.com/users/Karel-van-de-Plassche/followers",
"following_url": "https://api.github.com/users/Karel-van-de-Plassche/following{/other_user}",
"gists_url": "https://api.github.com/users/Karel-van-de-Plassche/gists{/gist_id}",
"starred_url": "https://api.github.com/users/Karel-van-de-Plassche/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/Karel-van-de-Plassche/subscriptions",
"organizations_url": "https://api.github.com/users/Karel-van-de-Plassche/orgs",
"repos_url": "https://api.github.com/users/Karel-van-de-Plassche/repos",
"events_url": "https://api.github.com/users/Karel-van-de-Plassche/events{/privacy}",
"received_events_url": "https://api.github.com/users/Karel-van-de-Plassche/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"As always, found a solution in #1178 right after posting. Replacing\r\n```\r\n.select(SQL('*'))\r\n```\r\nby\r\n```\r\n.select(getattr(join_clause.c, column.name))\r\n```\r\nfixes this problem\r\n",
"For future dwellers, this works for tables with `ForeignKeyField` or `CompositeKey` as `PrimaryKeyField` too:\r\n\r\n```python\r\ndef get_closest(column, value):\r\n model_class = column.model_class\r\n id = model_class.id.alias('id')\r\n if model_class._meta.primary_key.__class__ in [PrimaryKeyField, ForeignKeyField]:\r\n prim_key_names = [model_class._meta.primary_key.db_column]\r\n else:\r\n prim_key_names = [x + '_id' for x in model_class._meta.primary_key.field_names]\r\n prim_key_fields = [getattr(model_class, name) for name in prim_key_names]\r\n low_query = (model_class\r\n .select(*prim_key_fields, column)\r\n .where(column >= value)\r\n .order_by(column)\r\n .limit(1)\r\n )\r\n high_query = (model_class\r\n .select(*prim_key_fields, column)\r\n .where(column < value)\r\n .order_by(column.desc())\r\n .limit(1)\r\n )\r\n join_clause = low_query.union_all(high_query).alias('res')\r\n\r\n join_fields = [getattr(join_clause.c, name) for name in prim_key_names]\r\n query = (model_class\r\n .select(\r\n *join_fields,\r\n getattr(join_clause.c, column.name))\r\n .from_(join_clause)\r\n .order_by(fn.abs(value - SQL(column.name)))\r\n .limit(1)\r\n )\r\n query_res = query.get()\r\n res = model_class.select()\r\n for key in prim_key_fields:\r\n res = res.where(key == getattr(query_res, key.name))\r\n return res.get()\r\n```"
] | 2017-04-06T11:51:13 | 2017-04-06T13:19:49 | 2017-04-06T12:08:37 | NONE | null | I'm trying to find the closest point to a specific value. As per [stackoverflow](http://stackoverflow.com/questions/6102824/is-there-a-postgres-closest-operator) suggestion, I'm using subqueries and a UNION ALL to efficiently find the point. The following SQL works on my setup (PostgreSQL 3.6, adminer 4.2.5):
``` SQL
SELECT * FROM
(
(SELECT id, binormal_wavevector FROM wavevector WHERE binormal_wavevector >= 0.3 ORDER BY binormal_wavevector LIMIT 1)
UNION ALL
(SELECT id, binormal_wavevector FROM wavevector WHERE binormal_wavevector < 0.3 ORDER BY binormal_wavevector DESC LIMIT 1)
) AS res
ORDER BY abs(0.3-binormal_wavevector) LIMIT 1
```
I use the following peewee (2.9.1) to re-create this statement:
```python
def get_closest(column, value):
model_class = column.model_class
low_query = (model_class
.select(model_class.id, column)
.where(column >= value)
.order_by(column)
.limit(1)
)
high_query = (model_class
.select(model_class.id, column)
.where(column < value)
.order_by(column.desc())
.limit(1)
)
join_clause = low_query.union_all(high_query).alias('res')
query = (Wavevector
.select(SQL('*'))
.from_(join_clause)
.order_by(fn.abs(value - SQL(column.name)))
.limit(1)
)
return query
res = get_closest(Wavevector.binormal_wavevector, 0.3)
```
All seems well:
``` python
In [1]: res.count()
Out[1]: 2
In[2]: res.sql()
Out[2]: ('SELECT * FROM ((SELECT "t1"."id", "t1"."binormal_wavevector" FROM "develop"."wavevector" AS t1 WHERE ("t1"."binormal_wavevector" >= %s) ORDER BY "t1"."binormal_wavevector" LIMIT 1) UNION ALL (SELECT "t2"."id", "t2"."binormal_wavevector" FROM "develop"."wavevector" AS t2 WHERE ("t2"."binormal_wavevector" < %s) ORDER BY "t2"."binormal_wavevector" DESC LIMIT 1)) AS res ORDER BY abs(%s - binormal_wavevector) LIMIT 1',
[0.3, 0.3, 0.3])
```
But the resulting model is (for lack of a better word) empty:
```python
In [1]: [x.binormal_wavevector for x in query]
Out[1]: [None]
```
The subqueries work:
```python
In [2]: [x.binormal_wavevector for x in high_query]
Out[2]: [0.251516]
In [3]: [x.binormal_wavevector for x in low_query]
Out[3]: [0.314465]
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1239/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1239/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1238 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1238/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1238/comments | https://api.github.com/repos/coleifer/peewee/issues/1238/events | https://github.com/coleifer/peewee/issues/1238 | 219,578,364 | MDU6SXNzdWUyMTk1NzgzNjQ= | 1,238 | ValueError: too many values to unpack (expected 3) | {
"login": "lqsgd123",
"id": 24636251,
"node_id": "MDQ6VXNlcjI0NjM2MjUx",
"avatar_url": "https://avatars.githubusercontent.com/u/24636251?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/lqsgd123",
"html_url": "https://github.com/lqsgd123",
"followers_url": "https://api.github.com/users/lqsgd123/followers",
"following_url": "https://api.github.com/users/lqsgd123/following{/other_user}",
"gists_url": "https://api.github.com/users/lqsgd123/gists{/gist_id}",
"starred_url": "https://api.github.com/users/lqsgd123/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/lqsgd123/subscriptions",
"organizations_url": "https://api.github.com/users/lqsgd123/orgs",
"repos_url": "https://api.github.com/users/lqsgd123/repos",
"events_url": "https://api.github.com/users/lqsgd123/events{/privacy}",
"received_events_url": "https://api.github.com/users/lqsgd123/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2017-04-05T13:14:52 | 2017-04-06T05:17:54 | 2017-04-06T05:17:54 | NONE | null | I want to calculate the days between two dates.
```
def isLeapYear(year):
if year%400 == 0:
return True
elif year%100!=0 and year%4==0:
return True
else:
return False
def nextDay(year,month,day):
if isLeapYear(year):
daysOfMonths1 = [ 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
daysOfMonths = daysOfMonths1
return daysOfMonths
else:
daysOfMonths2 = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
daysOfMonths = daysOfMonths2
return daysOfMonths
if day < daysOfMonths[month-1]:
return year, month, day + 1
else:
if month == 12:
return year + 1, 1, 1
else:
return year, month + 1, 1
def dateIsBefore(year1, month1, day1, year2, month2, day2):
"""Returns True if year1-month1-day1 is before year2-month2-day2. Otherwise, returns False."""
if year1 < year2:
return True
if year1 == year2:
if month1 < month2:
return True
if month1 == month2:
return day1 < day2
return False
def daysBetweenDates(year1, month1, day1, year2, month2, day2):
"""Returns the number of days between year1/month1/day1
and year2/month2/day2. Assumes inputs are valid dates
in Gregorian calendar."""
# program defensively! Add an assertion if the input is not valid!
assert not dateIsBefore(year2, month2, day2, year1, month1, day1)
days = 0
while dateIsBefore(year1, month1, day1, year2, month2, day2):
year1, month1, day1 = nextDay(year1, month1, day1)
days += 1
return days
print(daysBetweenDates(2012,1,1,2012,2,29))
```
Sadly this doesn't work:
`>>> runfile('G:/Anaconda3/ex1.py', wdir='G:/Anaconda3')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "G:\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 866, in runfile
execfile(filename, namespace)
File "G:\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "G:/Anaconda3/ex1.py", line 56, in <module>
print(daysBetweenDates(2012,1,1,2012,2,22))
File "G:/Anaconda3/ex1.py", line 51, in daysBetweenDates
year1, month1, day1 = nextDay(year1, month1, day1)
ValueError: too many values to unpack (expected 3)` | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1238/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1238/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1237 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1237/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1237/comments | https://api.github.com/repos/coleifer/peewee/issues/1237/events | https://github.com/coleifer/peewee/issues/1237 | 218,919,054 | MDU6SXNzdWUyMTg5MTkwNTQ= | 1,237 | any documentation that doesn't require flask. | {
"login": "faststare",
"id": 20119279,
"node_id": "MDQ6VXNlcjIwMTE5Mjc5",
"avatar_url": "https://avatars.githubusercontent.com/u/20119279?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/faststare",
"html_url": "https://github.com/faststare",
"followers_url": "https://api.github.com/users/faststare/followers",
"following_url": "https://api.github.com/users/faststare/following{/other_user}",
"gists_url": "https://api.github.com/users/faststare/gists{/gist_id}",
"starred_url": "https://api.github.com/users/faststare/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/faststare/subscriptions",
"organizations_url": "https://api.github.com/users/faststare/orgs",
"repos_url": "https://api.github.com/users/faststare/repos",
"events_url": "https://api.github.com/users/faststare/events{/privacy}",
"received_events_url": "https://api.github.com/users/faststare/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"What are you talking about? Hardly anything is Flask-specific!",
"Maybe you're talking about the example application, which is a flask application?\r\n\r\nAt any rate, the documentation is intentionally designed to be framework- or implementation-agnostic. It doesn't matter if you're doing batch processing, ETL, web, whatever....the docs describe the APIs and mechanics of peewee and don't tie you to a particular usage scenario.",
"how I map specific user with name column with insert function?\r\nexample:\r\nMessage.insert(msg='example', user_id=1#<--need to replace an user name here)\r\nexample schema:\r\nUsers:\r\n username = CharField()\r\n password = CharField()\r\nMsg:\r\n user_id = ForeignKey(Users, related_name='username'')\r\n msg = Charfield()\r\n timestamp = DateTimeField()\r\n"
] | 2017-04-03T12:34:40 | 2017-04-03T23:21:56 | 2017-04-03T14:47:47 | NONE | null | it gets complicated that you mix peewee and flask. not all developer develop web app nor flask.
documentation should be simple like ponyorm docs.
it seems that you didn't the import this mantra with your package that you develop.
peewee have potential but too much quirks in the docs therefore new developer who try peewee will stay because of messy documentation.
I'm just suggest to improve the quality of peewee documentation.
thanks | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1237/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1237/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1236 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1236/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1236/comments | https://api.github.com/repos/coleifer/peewee/issues/1236/events | https://github.com/coleifer/peewee/issues/1236 | 218,751,253 | MDU6SXNzdWUyMTg3NTEyNTM= | 1,236 | pymysql.err.OperationalError: (2014, 'Command Out of Sync') | {
"login": "aiportal",
"id": 878799,
"node_id": "MDQ6VXNlcjg3ODc5OQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/878799?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/aiportal",
"html_url": "https://github.com/aiportal",
"followers_url": "https://api.github.com/users/aiportal/followers",
"following_url": "https://api.github.com/users/aiportal/following{/other_user}",
"gists_url": "https://api.github.com/users/aiportal/gists{/gist_id}",
"starred_url": "https://api.github.com/users/aiportal/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/aiportal/subscriptions",
"organizations_url": "https://api.github.com/users/aiportal/orgs",
"repos_url": "https://api.github.com/users/aiportal/repos",
"events_url": "https://api.github.com/users/aiportal/events{/privacy}",
"received_events_url": "https://api.github.com/users/aiportal/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Not sure looks like an issue in pymysql, the database driver, as opposed to peewee.",
"I have a same problem.\r\nwith the same env:\r\npeewee + pymysql + uwsgi(multi processes. every process have only 1 thread running)\r\n\r\nat the beginning, errors comes about 8 hours since uwsgi starts(about 10k queries). With there is more and more user, it crashes faster and faster. Now it will crash every hour.\r\n\r\nI tried to use PooledMySQLConnection, but havn't solve this problem.\r\nBut why a PooledConnection can still suffer a \"connection problem\"? Keep every connection alive and usable is the duty for a ConnectionPool, isn't it?",
"> Keep every connection alive and usable is the duty for a ConnectionPool, isn't it?\r\n\r\nIf you read the code in the `playhouse.pool` module you'll see that Peewee does this when a connection is requested. It verifies that the connection is usable before returning it to the user, using an implementation-specific method for each db driver. MySQL uses the \"ping()\" method."
] | 2017-04-02T08:54:24 | 2018-12-05T12:35:58 | 2017-04-03T15:22:05 | NONE | null | My code in flask is like this:
```
db_connections = [db_fetch, db_zb123]
class Database:
@staticmethod
def connect():
for conn in db_connections:
if conn.is_closed():
conn.connect()
@staticmethod
def close():
for conn in db_connections:
if not conn.is_closed():
conn.close()
@app.before_request
def before_req():
Database.connect()
@app.teardown_request
def teardown_req(exc):
Database.close()
```
And my web app is under uwsgi.
I found exception log in uwsgi log file.
```
Traceback (most recent call last):
File "/env/flask/lib/python3.5/site-packages/peewee.py", line 3754, in commit
self.get_conn().commit()
File "/env/flask/lib/python3.5/site-packages/pymysql/connections.py", line 784, in commit
self._read_ok_packet()
File "/env/flask/lib/python3.5/site-packages/pymysql/connections.py", line 765, in _read_ok_packet
raise err.OperationalError(2014, "Command Out of Sync")
pymysql.err.OperationalError: (2014, 'Command Out of Sync')
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/env/flask/lib/python3.5/site-packages/peewee.py", line 3746, in execute_sql
self.commit()
File "/env/flask/lib/python3.5/site-packages/peewee.py", line 3754, in commit
self.get_conn().commit()
File "/env/flask/lib/python3.5/site-packages/peewee.py", line 3569, in __exit__
reraise(new_type, new_type(*exc_args), traceback)
File "/env/flask/lib/python3.5/site-packages/peewee.py", line 135, in reraise
raise value.with_traceback(tb)
File "/env/flask/lib/python3.5/site-packages/peewee.py", line 3754, in commit
self.get_conn().commit()
File "/env/flask/lib/python3.5/site-packages/pymysql/connections.py", line 784, in commit
self._read_ok_packet()
File "/env/flask/lib/python3.5/site-packages/pymysql/connections.py", line 765, in _read_ok_packet
raise err.OperationalError(2014, "Command Out of Sync")
peewee.OperationalError: (2014, 'Command Out of Sync')
During handling of the above exception, another exception occurred:
...
```
Why this error happens and how to fix it? | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1236/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1236/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1235 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1235/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1235/comments | https://api.github.com/repos/coleifer/peewee/issues/1235/events | https://github.com/coleifer/peewee/issues/1235 | 218,737,243 | MDU6SXNzdWUyMTg3MzcyNDM= | 1,235 | Python3: AESEncryptedField attempts to combine strings and bytes | {
"login": "jlowin",
"id": 153965,
"node_id": "MDQ6VXNlcjE1Mzk2NQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/153965?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/jlowin",
"html_url": "https://github.com/jlowin",
"followers_url": "https://api.github.com/users/jlowin/followers",
"following_url": "https://api.github.com/users/jlowin/following{/other_user}",
"gists_url": "https://api.github.com/users/jlowin/gists{/gist_id}",
"starred_url": "https://api.github.com/users/jlowin/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/jlowin/subscriptions",
"organizations_url": "https://api.github.com/users/jlowin/orgs",
"repos_url": "https://api.github.com/users/jlowin/repos",
"events_url": "https://api.github.com/users/jlowin/events{/privacy}",
"received_events_url": "https://api.github.com/users/jlowin/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2017-04-02T02:40:52 | 2017-04-07T03:06:31 | 2017-04-07T03:06:31 | NONE | null | This is only an error in Python 3.
In [this line](https://github.com/coleifer/peewee/blame/master/playhouse/fields.py#L320), the AESEncryptedField attempts to concatenate the `key` (a `bytes` object) with `' '` (a `str`). This raises an error since the operation is not allowed. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1235/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1235/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1234 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1234/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1234/comments | https://api.github.com/repos/coleifer/peewee/issues/1234/events | https://github.com/coleifer/peewee/issues/1234 | 218,688,266 | MDU6SXNzdWUyMTg2ODgyNjY= | 1,234 | Add a way to copy over where clause between queries | {
"login": "tasn",
"id": 108670,
"node_id": "MDQ6VXNlcjEwODY3MA==",
"avatar_url": "https://avatars.githubusercontent.com/u/108670?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/tasn",
"html_url": "https://github.com/tasn",
"followers_url": "https://api.github.com/users/tasn/followers",
"following_url": "https://api.github.com/users/tasn/following{/other_user}",
"gists_url": "https://api.github.com/users/tasn/gists{/gist_id}",
"starred_url": "https://api.github.com/users/tasn/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/tasn/subscriptions",
"organizations_url": "https://api.github.com/users/tasn/orgs",
"repos_url": "https://api.github.com/users/tasn/repos",
"events_url": "https://api.github.com/users/tasn/events{/privacy}",
"received_events_url": "https://api.github.com/users/tasn/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Well, for one, INSERT queries don't take a WHERE clause.\r\n\r\nBut to your point, just put the expressions together and assign them to a variable...\r\n\r\n```python\r\nCOND = (MyModel.foo == 'bar') & (MyModel.baz < 4)\r\nq1 = MyModel.select().where(COND)\r\nMyModel.delete().where(COND).execute()\r\n\r\n# or\r\nMyModel.delete().where(MyModel.id << q1)\r\n```"
] | 2017-04-01T10:56:17 | 2017-04-01T16:44:01 | 2017-04-01T16:44:01 | NONE | null | Hi,
I want to be able to do:
```
a = Model.select().where(COMPLEX_CONDITION_HERE)
Model.insert(a=1).inherit(a)
```
Not sure if this is the best API, but this is a start.
There are two main places where this is useful:
1. When you want to do two manipulations on the same consecutively. For example, run a select, do some calculations, and if condition X applies, delete all of the entries that match the query without having to repeat yourself.
2. This one is more important because not having it here can introduce bugs: when the select query is abstracted away, either by a helper function that conditionally returns a different set, and then you can't know what is the set you have, so you can't easily delete it, or even in the most by sense by the built it "related_set". So for example, a.related_set.delete() is a useful operation, and at the moment people would have to resort to reimplementing the implementation of related_set to delete all related objects.
I asked on IRC and there were no database-only solutions to this problem. I.e the best solutions proposed were fetching all of the entries and then acting on them using the "in" operator, or alternatively just deleting/updating the objects one by one. Both are slow and unacceptable.
I hope this makes sense for the project. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1234/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1234/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1233 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1233/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1233/comments | https://api.github.com/repos/coleifer/peewee/issues/1233/events | https://github.com/coleifer/peewee/issues/1233 | 218,648,675 | MDU6SXNzdWUyMTg2NDg2NzU= | 1,233 | Can not pull data for joined models | {
"login": "kalpesh99",
"id": 543100,
"node_id": "MDQ6VXNlcjU0MzEwMA==",
"avatar_url": "https://avatars.githubusercontent.com/u/543100?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/kalpesh99",
"html_url": "https://github.com/kalpesh99",
"followers_url": "https://api.github.com/users/kalpesh99/followers",
"following_url": "https://api.github.com/users/kalpesh99/following{/other_user}",
"gists_url": "https://api.github.com/users/kalpesh99/gists{/gist_id}",
"starred_url": "https://api.github.com/users/kalpesh99/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/kalpesh99/subscriptions",
"organizations_url": "https://api.github.com/users/kalpesh99/orgs",
"repos_url": "https://api.github.com/users/kalpesh99/repos",
"events_url": "https://api.github.com/users/kalpesh99/events{/privacy}",
"received_events_url": "https://api.github.com/users/kalpesh99/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Could you please take the time to format your code?",
"```python\r\nclass User(Model):\r\n id = PrimaryKeyField()\r\n username = CharField(max_length=32, null=False)\r\n password = TextField(null=False)\r\n first_name = CharField(max_length=32, null=True)\r\n last_name = CharField(max_length=32, null=True)\r\n email = CharField(max_length=64, null=True)\r\n class Meta:\r\n database = db\r\n db_table = 'user'\r\n\r\nclass VLesson(Model):\r\n id = PrimaryKeyField()\r\n description = TextField()\r\n title = TextField()\r\n class Meta:\r\n database = db\r\n db_table = 'vlesson'\r\n\r\nclass TLesson(Model):\r\n id = PrimaryKeyField()\r\n description = TextField()\r\n title = TextField()\r\n class Meta:\r\n database = db\r\n db_table = 'tlesson'\r\n\r\nclass Lesson(Model):\r\n id = PrimaryKeyField()\r\n module = IntegerField()\r\n tlesson_id = ForeignKeyField(db_column='tlesson_id', null=True, rel_model=TLesson, to_field='id')\r\n vlesson_id = ForeignKeyField(db_column='vlesson_id', null=True, rel_model=VLesson, to_field='id')\r\n class Meta:\r\n database = db\r\n db_table = 'lesson'\r\n\r\nclass UserLesson(Model):\r\n id = PrimaryKeyField()\r\n user_id = ForeignKeyField(db_column='user_id', null=True, rel_model=User, to_field='id')\r\n lesson_id = ForeignKeyField(db_column='lesson_id', null=True, rel_model=Lesson, to_field='id')\r\n class Meta:\r\n database = db\r\n db_table = 'user_lesson'\r\n```\r\n\r\nFollowing query works as expected\r\n```python\r\nUserLesson.select(UserLesson, Lesson, User).join(Lesson).switch(UserLesson).join(User).first() \r\n```\r\n\r\nBut following query returns only \"Lesson\" class/model instead of all three models. For this query I did verify SQL output dumped by peeewee works as expected when tried in SQLite console, so SQL produced by peewee is right but data retrieved from SQLite don't get populated correctly in to classes/models. \r\n```python\r\nLesson.select(Lesson, UserLesson, User).join(UserLesson).join(User).first() \r\n```\r\n\r\nSorry for not formatting code before and thank you for prompt response.",
"Because a `Lesson` may be associated with more than one `UserLesson`, the way peewee aliases the joins is slightly different.\r\n\r\nDid you try accessing the `UserLesson` object like this:\r\n\r\n```python\r\nlesson = Lesson.select(Lesson, UserLesson, User).join(UserLesson).join(User).first()\r\nprint lesson.userlesson.user_id.username\r\n```\r\n\r\n?",
"userlesson and/or user_lesson attribute not present\r\n\r\n```python\r\n>>> lesson = Lesson.select(Lesson, UserLesson).join(UserLesson).first()\r\n>>> lesson.user_lesson\r\nTraceback (most recent call last):\r\n File \"<stdin>\", line 1, in <module>\r\nAttributeError: 'Lesson' object has no attribute 'user_lesson'\r\n>>> lesson.__dict__\r\n{'_data': {'vlesson_id': None, 'id': 1, 'tlesson_id': 1, 'module': 1}, '_obj_cache': {}, '_dirty': set()}\r\n>>> lesson.userlesson\r\nTraceback (most recent call last):\r\n File \"<stdin>\", line 1, in <module>\r\nAttributeError: 'Lesson' object has no attribute 'userlesson'\r\n```\r\n\r\nBut the same query works as expected if I change my model to have foreign key defined on on ```TLesson```, ```VLesson``` instead of on ```Lesson``` as shown below. \r\n```python\r\n\r\nclass User(Model):\r\n id = PrimaryKeyField()\r\n\r\n username = CharField(max_length=32, null=False)\r\n password = TextField(null=False)\r\n\r\n first_name = CharField(max_length=32, null=True)\r\n last_name = CharField(max_length=32, null=True)\r\n email = CharField(max_length=64, null=True)\r\n class Meta:\r\n database = main.jdb\r\n db_table = 'user'\r\n\r\nclass Lesson(Model):\r\n id = PrimaryKeyField()\r\n module = IntegerField()\r\n lesson = IntegerField()\r\n class Meta:\r\n database = main.jdb\r\n db_table = 'lesson'\r\n\r\nclass TLesson(Model):\r\n id = PrimaryKeyField()\r\n description = TextField()\r\n title = TextField()\r\n lesson_id = ForeignKeyField(db_column='lesson_id', null=False, rel_model=Lesson, to_field='id')\r\n class Meta:\r\n database = main.jdb\r\n db_table = 'tlesson'\r\n\r\nclass VLesson(Model):\r\n id = PrimaryKeyField()\r\n description = TextField()\r\n title = TextField()\r\n lesson_id = ForeignKeyField(db_column='lesson_id', null=False, rel_model=Lesson, to_field='id')\r\n class Meta:\r\n database = main.jdb\r\n db_table = 'vlesson'\r\n\r\nclass UserLesson(Model):\r\n id = PrimaryKeyField()\r\n user_id = ForeignKeyField(db_column='user_id', null=False, rel_model=User, to_field='id')\r\n lesson_id = ForeignKeyField(db_column='lesson_id', null=False, rel_model=Lesson, to_field='id')\r\n date = IntegerField(null=False)\r\n class Meta:\r\n database = main.jdb\r\n db_table = 'user_lesson'\r\n```\r\n"
] | 2017-04-01T00:14:33 | 2017-04-07T03:03:39 | 2017-04-07T03:03:39 | NONE | null | UserLesson.select(UserLesson, Lesson, User).join(Lesson).switch(UserLesson).join(User).first() query works as expected (returning data for all three classes) but Lesson.select(Lesson, UserLesson, User).join(UserLesson).join(User).first() returns only Lesson class/model for models shown below. Why does it behave like it? I am not sure if this is a right place to ask this kind of question, so forgive me if I made a mistake. Thank you.
class User(Model):
id = PrimaryKeyField()
username = CharField(max_length=32, null=False)
password = TextField(null=False)
first_name = CharField(max_length=32, null=True)
last_name = CharField(max_length=32, null=True)
email = CharField(max_length=64, null=True)
class Meta:
database = db
db_table = 'user'
class VLesson(Model):
id = PrimaryKeyField()
description = TextField()
title = TextField()
class Meta:
database = db
db_table = 'vlesson'
class TLesson(Model):
id = PrimaryKeyField()
description = TextField()
title = TextField()
class Meta:
database = db
db_table = 'tlesson'
class Lesson(Model):
id = PrimaryKeyField()
module = IntegerField()
tlesson_id = ForeignKeyField(db_column='tlesson_id', null=True, rel_model=TLesson, to_field='id')
vlesson_id = ForeignKeyField(db_column='vlesson_id', null=True, rel_model=VLesson, to_field='id')
class Meta:
database = db
db_table = 'lesson'
class UserLesson(Model):
id = PrimaryKeyField()
user_id = ForeignKeyField(db_column='user_id', null=True, rel_model=User, to_field='id')
lesson_id = ForeignKeyField(db_column='lesson_id', null=True, rel_model=Lesson, to_field='id')
class Meta:
database = db
db_table = 'user_lesson'
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1233/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1233/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1232 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1232/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1232/comments | https://api.github.com/repos/coleifer/peewee/issues/1232/events | https://github.com/coleifer/peewee/issues/1232 | 218,195,331 | MDU6SXNzdWUyMTgxOTUzMzE= | 1,232 | Why "from peewee import *" doesn't import InsertQuery? | {
"login": "TwoAnts",
"id": 5968383,
"node_id": "MDQ6VXNlcjU5NjgzODM=",
"avatar_url": "https://avatars.githubusercontent.com/u/5968383?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/TwoAnts",
"html_url": "https://github.com/TwoAnts",
"followers_url": "https://api.github.com/users/TwoAnts/followers",
"following_url": "https://api.github.com/users/TwoAnts/following{/other_user}",
"gists_url": "https://api.github.com/users/TwoAnts/gists{/gist_id}",
"starred_url": "https://api.github.com/users/TwoAnts/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/TwoAnts/subscriptions",
"organizations_url": "https://api.github.com/users/TwoAnts/orgs",
"repos_url": "https://api.github.com/users/TwoAnts/repos",
"events_url": "https://api.github.com/users/TwoAnts/events{/privacy}",
"received_events_url": "https://api.github.com/users/TwoAnts/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Typically you would not import an InsertQuery directly, but use the `insert()` model method.",
"Please read the docs.",
"I think I have found my answer from http://stackoverflow.com/questions/44834/can-someone-explain-all-in-python.\r\nMaybe I'm a little stupid here, now I'm clear. I see `__all__` is used in peewee.py and other variables will not be imported by `from peewee import *`.\r\nThanks a lot for your patience.",
"I see - so you were less interested, then, in using `InsertQuery` and were more interested in the mechanics of the Python import statement...",
"😁"
] | 2017-03-30T13:22:31 | 2017-04-03T02:23:36 | 2017-03-31T00:16:37 | NONE | null | ```
Python 2.7.6 (default, Oct 26 2016, 20:30:19)
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from peewee import *
>>> InsertQuery()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'InsertQuery' is not defined
>>> from peewee import InsertQuery
>>> InsertQuery()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: __init__() takes at least 2 arguments (1 given)
>>>
```
`from peewee import *` doesn't import InsertQuery,
but `from peewee import InsertQuery` does.
I have tested it on Python 2.7.6 and Python 2.7.12 , got the same result.
A little curious.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1232/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1232/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1231 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1231/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1231/comments | https://api.github.com/repos/coleifer/peewee/issues/1231/events | https://github.com/coleifer/peewee/issues/1231 | 217,431,948 | MDU6SXNzdWUyMTc0MzE5NDg= | 1,231 | how to make peewee work with MysqlProxy | {
"login": "knightliao",
"id": 3657476,
"node_id": "MDQ6VXNlcjM2NTc0NzY=",
"avatar_url": "https://avatars.githubusercontent.com/u/3657476?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/knightliao",
"html_url": "https://github.com/knightliao",
"followers_url": "https://api.github.com/users/knightliao/followers",
"following_url": "https://api.github.com/users/knightliao/following{/other_user}",
"gists_url": "https://api.github.com/users/knightliao/gists{/gist_id}",
"starred_url": "https://api.github.com/users/knightliao/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/knightliao/subscriptions",
"organizations_url": "https://api.github.com/users/knightliao/orgs",
"repos_url": "https://api.github.com/users/knightliao/repos",
"events_url": "https://api.github.com/users/knightliao/events{/privacy}",
"received_events_url": "https://api.github.com/users/knightliao/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"my solution is:\r\n\r\n1. make mysql connection with autocommit = true\r\n \r\n `connect_kwargs.update({'autocommit': True})`\r\n\r\n2. no transaction sql without commit \r\n```\r\n\r\ndef execute_sql(self, sql, params=None, require_commit=True):\r\n logger.debug((sql, params))\r\n with self.exception_wrapper():\r\n cursor = self.get_cursor()\r\n try:\r\n cursor.execute(sql, params or ())\r\n except Exception as exc:\r\n if self.get_autocommit() and self.autorollback:\r\n self.rollback()\r\n if self.sql_error_handler(exc, sql, params, require_commit):\r\n raise\r\n else:\r\n pass\r\n return cursor\r\n```\r\n\r\n\r\n3. when using transaction, add begin statement\r\n\r\n```\r\ndef begin(self):\r\n logging.debug(\"trans begin\")\r\n self.get_conn().begin()\r\n\r\n```\r\n\r\nthe total code is :\r\n\r\n```\r\nclass ProxyPooledMySQLDatabase(PooledMySQLDatabase):\r\n def init(self, database, **connect_kwargs):\r\n connect_kwargs.update({'autocommit': True})\r\n super(ProxyPooledMySQLDatabase, self).init(database, **connect_kwargs)\r\n\r\n def execute_sql(self, sql, params=None, require_commit=True):\r\n logger.debug((sql, params))\r\n with self.exception_wrapper():\r\n cursor = self.get_cursor()\r\n try:\r\n cursor.execute(sql, params or ())\r\n except Exception as exc:\r\n if self.get_autocommit() and self.autorollback:\r\n self.rollback()\r\n if self.sql_error_handler(exc, sql, params, require_commit):\r\n raise\r\n else:\r\n pass\r\n return cursor\r\n\r\n def begin(self):\r\n logging.debug(\"trans begin\")\r\n self.get_conn().begin()\r\n```\r\n\r\nwhat do you think about my solution ?",
"?",
"?"
] | 2017-03-28T02:42:21 | 2017-04-01T19:44:35 | 2017-04-01T19:44:35 | NONE | null | hello, peewee recommend 'read-slave module' ( http://docs.peewee-orm.com/en/latest/peewee/database.html?highlight=slave#read-slaves ) to do with master/slave mysql.
atlas(https://github.com/Qihoo360/Atlas) is a mysql proxy, user write less code when use it.
and my question is 'how peewee can do with mysql proxy? ' ( such as Atlas)
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1231/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1231/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1230 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1230/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1230/comments | https://api.github.com/repos/coleifer/peewee/issues/1230/events | https://github.com/coleifer/peewee/issues/1230 | 217,232,553 | MDU6SXNzdWUyMTcyMzI1NTM= | 1,230 | Where clause cannot handle dict_values (dict view - python3) | {
"login": "dhiana",
"id": 34568,
"node_id": "MDQ6VXNlcjM0NTY4",
"avatar_url": "https://avatars.githubusercontent.com/u/34568?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/dhiana",
"html_url": "https://github.com/dhiana",
"followers_url": "https://api.github.com/users/dhiana/followers",
"following_url": "https://api.github.com/users/dhiana/following{/other_user}",
"gists_url": "https://api.github.com/users/dhiana/gists{/gist_id}",
"starred_url": "https://api.github.com/users/dhiana/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/dhiana/subscriptions",
"organizations_url": "https://api.github.com/users/dhiana/orgs",
"repos_url": "https://api.github.com/users/dhiana/repos",
"events_url": "https://api.github.com/users/dhiana/events{/privacy}",
"received_events_url": "https://api.github.com/users/dhiana/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Convert it to a list explicitly:\r\n\r\n```python\r\n.where(SomeModel.field << list(some_dict.values()))\r\n```"
] | 2017-03-27T12:40:32 | 2017-03-27T16:33:52 | 2017-03-27T16:33:52 | NONE | null | When trying to use a where clause comparing a field to a dict_value, I get this error.
peewee.ProgrammingError: syntax error at or near "'dict_values([‘’foo’’, “bar’’])’”
LINE 1: …baz = ‘quz’)) AND ("t1”.”qux” IN 'dict_valu...
https://docs.python.org/3.0/library/stdtypes.html#dict.values
My code was working on python 2, but when modifying iteritems to items to use python 3, now I need to force list() on the dict_values. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1230/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1230/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1229 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1229/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1229/comments | https://api.github.com/repos/coleifer/peewee/issues/1229/events | https://github.com/coleifer/peewee/issues/1229 | 216,619,293 | MDU6SXNzdWUyMTY2MTkyOTM= | 1,229 | Model.drop_table disregards Database.drop_cascade | {
"login": "nad2000",
"id": 177266,
"node_id": "MDQ6VXNlcjE3NzI2Ng==",
"avatar_url": "https://avatars.githubusercontent.com/u/177266?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/nad2000",
"html_url": "https://github.com/nad2000",
"followers_url": "https://api.github.com/users/nad2000/followers",
"following_url": "https://api.github.com/users/nad2000/following{/other_user}",
"gists_url": "https://api.github.com/users/nad2000/gists{/gist_id}",
"starred_url": "https://api.github.com/users/nad2000/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/nad2000/subscriptions",
"organizations_url": "https://api.github.com/users/nad2000/orgs",
"repos_url": "https://api.github.com/users/nad2000/repos",
"events_url": "https://api.github.com/users/nad2000/events{/privacy}",
"received_events_url": "https://api.github.com/users/nad2000/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2017-03-24T01:26:04 | 2017-04-01T19:47:31 | 2017-04-01T19:47:31 | NONE | null | Attempting to drop a table in Sqlite DB with **cascade=True** fails even if `Database.drop_cascade=False` with:
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> File ".../peewee.py", line 5000, in drop_table
> cls._meta.database.drop_table(cls, fail_silently, cascade)
> File ".../site-packages/peewee.py", line 3870, in drop_table
> model_class, fail_silently, cascade))
> File ".../site-packages/peewee.py", line 3755, in execute_sql
> self.commit()
> File ".../site-packages/peewee.py", line 3578, in __exit__
> reraise(new_type, new_type(*exc_args), traceback)
> File ".../site-packages/peewee.py", line 135, in reraise
> raise value.with_traceback(tb)
> File ".../site-packages/peewee.py", line 3748, in execute_sql
> cursor.execute(sql, params or ())
> **peewee.OperationalError: near "CASCADE": syntax error**
> **near "CASCADE": syntax error**
>
The SQL get built (`DROP TABLE "foo" CASCADE`) without taking in account if DB supports DROP CASCADE (`Database.drop_cascade`): https://github.com/coleifer/peewee/blob/master/peewee.py#L2187
While the test (`TestDropTableCascade`) does get skipped for the case when DB doesn't support DROP CASCADE.
Perhaps it should be handled a bit more gracefully, either 1) with more specific exception or 2) implementing cascaded dropping for the dependant tables.
### Test code:
```python
from peewee import Model, TextField, ForeignKeyField
from peewee import drop_model_tables, SqliteDatabase
db = SqliteDatabase(":memory:")
class Foo(Model):
foo = TextField()
class Meta:
database = db
Foo.create_table()
Foo.drop_table(cascade=True)
``` | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1229/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1229/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1228 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1228/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1228/comments | https://api.github.com/repos/coleifer/peewee/issues/1228/events | https://github.com/coleifer/peewee/issues/1228 | 216,239,504 | MDU6SXNzdWUyMTYyMzk1MDQ= | 1,228 | Default Snake Case Table Names | {
"login": "joshuamcginnis",
"id": 391074,
"node_id": "MDQ6VXNlcjM5MTA3NA==",
"avatar_url": "https://avatars.githubusercontent.com/u/391074?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/joshuamcginnis",
"html_url": "https://github.com/joshuamcginnis",
"followers_url": "https://api.github.com/users/joshuamcginnis/followers",
"following_url": "https://api.github.com/users/joshuamcginnis/following{/other_user}",
"gists_url": "https://api.github.com/users/joshuamcginnis/gists{/gist_id}",
"starred_url": "https://api.github.com/users/joshuamcginnis/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/joshuamcginnis/subscriptions",
"organizations_url": "https://api.github.com/users/joshuamcginnis/orgs",
"repos_url": "https://api.github.com/users/joshuamcginnis/repos",
"events_url": "https://api.github.com/users/joshuamcginnis/events{/privacy}",
"received_events_url": "https://api.github.com/users/joshuamcginnis/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Sorry for the inconvenience, but you'll need to specify the `db_table` attribute.\r\n\r\nAlternatively, you can pass in a function using `db_table_func` that does the conversion the way you'd prefer. Something like:\r\n\r\n```python\r\ndef make_table_name(model_cls):\r\n name = model_cls.__name__\r\n # change name to snake-case\r\n return new_name\r\n\r\nclass BaseModel(Model):\r\n class Meta:\r\n db_table_func = make_table_name\r\n\r\nclass FooType(BaseModel):\r\n ...\r\n\r\nclass FooScoreAttributes(BaseModel):\r\n ...\r\n```",
"@coleifer Thanks! `db_table_func` is just what I need."
] | 2017-03-22T23:32:15 | 2017-03-23T20:30:06 | 2017-03-23T17:56:12 | NONE | null | I have several tables that have camelcased names (`FooType`, `FooScoreAttributes`, etc) and on table creation, the table names are: `footype` and `fooscoreattributes`.
Is there a way to have all table names snake cased like: `foo_type` without having to specify the `db_table` in each model? | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1228/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1228/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1227 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1227/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1227/comments | https://api.github.com/repos/coleifer/peewee/issues/1227/events | https://github.com/coleifer/peewee/issues/1227 | 216,037,550 | MDU6SXNzdWUyMTYwMzc1NTA= | 1,227 | PostgreSQL - range types | {
"login": "Phibedy",
"id": 1841954,
"node_id": "MDQ6VXNlcjE4NDE5NTQ=",
"avatar_url": "https://avatars.githubusercontent.com/u/1841954?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/Phibedy",
"html_url": "https://github.com/Phibedy",
"followers_url": "https://api.github.com/users/Phibedy/followers",
"following_url": "https://api.github.com/users/Phibedy/following{/other_user}",
"gists_url": "https://api.github.com/users/Phibedy/gists{/gist_id}",
"starred_url": "https://api.github.com/users/Phibedy/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/Phibedy/subscriptions",
"organizations_url": "https://api.github.com/users/Phibedy/orgs",
"repos_url": "https://api.github.com/users/Phibedy/repos",
"events_url": "https://api.github.com/users/Phibedy/events{/privacy}",
"received_events_url": "https://api.github.com/users/Phibedy/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I'm going to pass on implementing these right now, though I may revisit this feature in the future. If you're looking for ideas on implementation, I'd suggest checking out the other custom field types in `playhouse.postgres_ext`."
] | 2017-03-22T11:56:22 | 2017-04-07T23:48:15 | 2017-04-07T23:48:15 | NONE | null | Hi,
would like to use [range types](https://www.postgresql.org/docs/9.3/static/rangetypes.html) (in my case datetime with time zone), but I am not sure how to implement it for all types.
Any help appreciated :) | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1227/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1227/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1226 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1226/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1226/comments | https://api.github.com/repos/coleifer/peewee/issues/1226/events | https://github.com/coleifer/peewee/pull/1226 | 215,957,360 | MDExOlB1bGxSZXF1ZXN0MTExOTM1Mjc2 | 1,226 | Explicitly document that `default` may be callable | {
"login": "avivey",
"id": 1530242,
"node_id": "MDQ6VXNlcjE1MzAyNDI=",
"avatar_url": "https://avatars.githubusercontent.com/u/1530242?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/avivey",
"html_url": "https://github.com/avivey",
"followers_url": "https://api.github.com/users/avivey/followers",
"following_url": "https://api.github.com/users/avivey/following{/other_user}",
"gists_url": "https://api.github.com/users/avivey/gists{/gist_id}",
"starred_url": "https://api.github.com/users/avivey/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/avivey/subscriptions",
"organizations_url": "https://api.github.com/users/avivey/orgs",
"repos_url": "https://api.github.com/users/avivey/repos",
"events_url": "https://api.github.com/users/avivey/events{/privacy}",
"received_events_url": "https://api.github.com/users/avivey/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2017-03-22T05:30:55 | 2017-03-23T14:40:03 | 2017-03-23T14:40:02 | CONTRIBUTOR | null | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1226/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1226/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/1226",
"html_url": "https://github.com/coleifer/peewee/pull/1226",
"diff_url": "https://github.com/coleifer/peewee/pull/1226.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/1226.patch",
"merged_at": "2017-03-23T14:40:02"
} |
|
https://api.github.com/repos/coleifer/peewee/issues/1225 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1225/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1225/comments | https://api.github.com/repos/coleifer/peewee/issues/1225/events | https://github.com/coleifer/peewee/issues/1225 | 215,881,157 | MDU6SXNzdWUyMTU4ODExNTc= | 1,225 | Inconsistent behaviour from commit() in nested db.atomic() (PostgreSQL) | {
"login": "Syeberman",
"id": 4551516,
"node_id": "MDQ6VXNlcjQ1NTE1MTY=",
"avatar_url": "https://avatars.githubusercontent.com/u/4551516?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/Syeberman",
"html_url": "https://github.com/Syeberman",
"followers_url": "https://api.github.com/users/Syeberman/followers",
"following_url": "https://api.github.com/users/Syeberman/following{/other_user}",
"gists_url": "https://api.github.com/users/Syeberman/gists{/gist_id}",
"starred_url": "https://api.github.com/users/Syeberman/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/Syeberman/subscriptions",
"organizations_url": "https://api.github.com/users/Syeberman/orgs",
"repos_url": "https://api.github.com/users/Syeberman/repos",
"events_url": "https://api.github.com/users/Syeberman/events{/privacy}",
"received_events_url": "https://api.github.com/users/Syeberman/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Thanks, fixed."
] | 2017-03-21T21:18:09 | 2017-03-23T18:06:32 | 2017-03-23T18:06:26 | NONE | null | `db.atomic()` returns either a transaction or a savepoint, depending on the nesting level. Manually committing or rolling back a transaction starts a new transaction, but *not* for savepoints. In PostgreSQL, it is valid to [roll back](https://www.postgresql.org/docs/current/static/sql-rollback-to.html) a savepoint multiple times, but you can only [commit once](https://www.postgresql.org/docs/current/static/sql-release-savepoint.html).
The net result of all this is inconsistent behaviour from the object returned by `db.atomic()`:
```python
class Test(Model):
value = CharField()
class Meta:
database = db
db.connect()
db.drop_table(Test)
db.create_table(Test)
with db.atomic() as trans:
Test.create(value='trans rollback')
trans.rollback()
Test.create(value='trans commit')
trans.commit() # success
with db.atomic() as savep:
Test.create(value='savep rollback')
savep.rollback()
Test.create(value='savep commit')
# savep.commit() # `InternalError: no such savepoint` on __exit__
for test in Test.select():
print(test.value)
```
I believe that the object returned from `db.atomic()` should *always* behave like a transaction, where manually committing or rolling back starts a new transaction. The code above makes it obvious that there are nested transactions, but consider a helper method that sometimes is called in a transaction and sometimes not: that method cannot manually commit. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1225/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1225/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1224 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1224/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1224/comments | https://api.github.com/repos/coleifer/peewee/issues/1224/events | https://github.com/coleifer/peewee/issues/1224 | 215,167,581 | MDU6SXNzdWUyMTUxNjc1ODE= | 1,224 | pip3 install peewee error m wrong cython version | {
"login": "stanta",
"id": 6910492,
"node_id": "MDQ6VXNlcjY5MTA0OTI=",
"avatar_url": "https://avatars.githubusercontent.com/u/6910492?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/stanta",
"html_url": "https://github.com/stanta",
"followers_url": "https://api.github.com/users/stanta/followers",
"following_url": "https://api.github.com/users/stanta/following{/other_user}",
"gists_url": "https://api.github.com/users/stanta/gists{/gist_id}",
"starred_url": "https://api.github.com/users/stanta/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/stanta/subscriptions",
"organizations_url": "https://api.github.com/users/stanta/orgs",
"repos_url": "https://api.github.com/users/stanta/repos",
"events_url": "https://api.github.com/users/stanta/events{/privacy}",
"received_events_url": "https://api.github.com/users/stanta/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"That does indeed look like an invalid version number. Plus it's too old at any rate.",
"yeah, I downloaded cython sources from repo and go through \"python setup install\" - all became OK "
] | 2017-03-18T05:18:01 | 2017-03-19T05:39:53 | 2017-03-18T21:44:59 | NONE | null | Hi, when I install peewee from pip, have an issue: ValueError: invalid version number '0.20.1post0'
on vagrant/ Ubuntu Trusty 14.04.5 LTS, says:
**elif StrictVersion(cython_version) < StrictVersion(cython_min_version):**
look:
root@lists:~/.pip# sudo pip3 install peewee
Downloading/unpacking peewee
Downloading peewee-2.9.1.tar.gz (514kB): 514kB downloaded
Running setup.py (path:/tmp/pip_build_root/peewee/setup.py) egg_info for package peewee
Traceback (most recent call last):
File "<string>", line 17, in <module>
File "/tmp/pip_build_root/peewee/setup.py", line 29, in <module>
elif StrictVersion(cython_version) < StrictVersion(cython_min_version):
File "/usr/lib/python3.4/distutils/version.py", line 40, in __init__
self.parse(vstring)
File "/usr/lib/python3.4/distutils/version.py", line 143, in parse
raise ValueError("invalid version number '%s'" % vstring)
ValueError: invalid version number '0.20.1post0'
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 17, in <module>
File "/tmp/pip_build_root/peewee/setup.py", line 29, in <module>
**elif StrictVersion(cython_version) < StrictVersion(cython_min_version):**
File "/usr/lib/python3.4/distutils/version.py", line 40, in __init__
self.parse(vstring)
File "/usr/lib/python3.4/distutils/version.py", line 143, in parse
raise ValueError("invalid version number '%s'" % vstring)
ValueError: invalid version number '0.20.1post0'
----------------------------------------
Cleaning up...
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1224/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1224/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1223 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1223/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1223/comments | https://api.github.com/repos/coleifer/peewee/issues/1223/events | https://github.com/coleifer/peewee/issues/1223 | 215,089,975 | MDU6SXNzdWUyMTUwODk5NzU= | 1,223 | Peewee writing to peewee.db not my.db | {
"login": "mtairu",
"id": 4996264,
"node_id": "MDQ6VXNlcjQ5OTYyNjQ=",
"avatar_url": "https://avatars.githubusercontent.com/u/4996264?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/mtairu",
"html_url": "https://github.com/mtairu",
"followers_url": "https://api.github.com/users/mtairu/followers",
"following_url": "https://api.github.com/users/mtairu/following{/other_user}",
"gists_url": "https://api.github.com/users/mtairu/gists{/gist_id}",
"starred_url": "https://api.github.com/users/mtairu/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/mtairu/subscriptions",
"organizations_url": "https://api.github.com/users/mtairu/orgs",
"repos_url": "https://api.github.com/users/mtairu/repos",
"events_url": "https://api.github.com/users/mtairu/events{/privacy}",
"received_events_url": "https://api.github.com/users/mtairu/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Check that your model is specifying the database as a meta option:\r\n\r\n```python\r\nmy_db = SqliteDatabase('my.db')\r\n\r\nclass MyModel(Model):\r\n class Meta:\r\n database = my_db\r\n```",
"For what it's worth (I can't believe I'm even taking the time to type this), don't you imagine if something as fundamental as writing to the \"wrong\" database were happening, that this would be a massive bug? That the tests would probably be failing? Etc? Did it not occur to you that you had made an error?",
"sorry coleifer.. you correction worked and has been working. Just forgot to comeback and say so.\r\n\r\nTo think, I wanted to learn sqlalchemy.... not worth it. Peewee is good enough. Just having difficulty sorting my datetime values 2017-04-07T01:51:00.000Z all the way to time. It sorts the dates but the time is always an issue I tried everything.",
"Are you using 24-hour encoding? They should sort correctly simply due to being in order alphabetically. Of course if time-zones are introduced that may not be the case."
] | 2017-03-17T18:43:28 | 2017-04-10T20:01:35 | 2017-03-17T19:41:20 | NONE | null | When I insert items to db, it writes to peewee.db not my.db | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1223/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1223/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1222 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1222/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1222/comments | https://api.github.com/repos/coleifer/peewee/issues/1222/events | https://github.com/coleifer/peewee/issues/1222 | 214,267,662 | MDU6SXNzdWUyMTQyNjc2NjI= | 1,222 | not support multiple union query ! | {
"login": "b0123456789",
"id": 21169660,
"node_id": "MDQ6VXNlcjIxMTY5NjYw",
"avatar_url": "https://avatars.githubusercontent.com/u/21169660?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/b0123456789",
"html_url": "https://github.com/b0123456789",
"followers_url": "https://api.github.com/users/b0123456789/followers",
"following_url": "https://api.github.com/users/b0123456789/following{/other_user}",
"gists_url": "https://api.github.com/users/b0123456789/gists{/gist_id}",
"starred_url": "https://api.github.com/users/b0123456789/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/b0123456789/subscriptions",
"organizations_url": "https://api.github.com/users/b0123456789/orgs",
"repos_url": "https://api.github.com/users/b0123456789/repos",
"events_url": "https://api.github.com/users/b0123456789/events{/privacy}",
"received_events_url": "https://api.github.com/users/b0123456789/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Can you please provide a small example so I can reproduce the issue? Can you be more clear where the obvious errors / issues are?",
"OK, so I guess in the second query you are wanting `AccountBilibili` to be aliased to `t1` instead of `t3`? In the third query (`c`) the same issue? Would that even work, though?",
"The issue here is that the parentheses are not valid in MySQL.\r\nThis should have been fixed with #1173 in version 2.8.7.\r\n\r\nSo the solution might just be to upgrade to the latest version of peewee.\r\n",
"The correct sql should be like this below.\r\n<pre>\r\n(\r\n\tSELECT\r\n\t\t`t1`.`am_id` AS id,\r\n\t\t`t1`.`am_name` AS name,\r\n\t\t(SELECT 'bilibili') AS type\r\n\tFROM\r\n\t\t`wyx_account_bilibili` AS t1\r\n)\r\nUNION \r\n\t(\r\n\t\tSELECT\r\n\t\t\t`t2`.`am_id` AS id,\r\n\t\t\t`t2`.`am_name` AS name,\r\n\t\t\t(SELECT 'meipai') AS type\r\n\t\tFROM\r\n\t\t\t`wyx_account_meipai` AS t2\r\n\t)\r\nUNION \r\n\t(\r\n\t\tSELECT\r\n\t\t\t`t3`.`am_id` AS id,\r\n\t\t\t`t3`.`am_name` AS name,\r\n\t\t\t(SELECT 'miaopai') AS type\r\n\t\tFROM\r\n\t\t\t`wyx_account_miaopai` AS t3\r\n\t)\r\n</pre>\r\n\r\nThe first issue is that the <pre>the first parentheses outside is not support by mysql. </pre>\r\nthe second issue is that <pre> the seconde union `t3` table is not found as well as the third union table ` t4`</pre>",
"It still get errors after upgrading to 2.9.1, tell me what's the date the next vesion release. i'll try.",
" I change \"**d= (a|b|c)**\" to \"**d = a.union_all(b).union_all(c)**\"\r\nIt output this.\r\n<pre>\r\n(\"(SELECT `t1`.`am_id` AS id, `t1`.`am_name` AS `name`, (select 'bilibili') AS type FROM `wyx_account_bilibili` AS t1) UNION ALL (SELECT `t2`.`am_id` AS id, `t3`.`am_name` AS `name`, (select 'meipai') AS type FROM `wyx_account_meipai` AS t2) UNION ALL (SELECT `t3`.`am_id` AS id, `t4`.`am_name` AS `name`, (se\r\nlect 'miaopai') AS type FROM `wyx_account_miaopai` AS t3)\", [])\r\n</pre>\r\n\r\nIt output that below when it formated.\r\n<pre>\r\n(\r\n\tSELECT\r\n\t\t`t1`.`am_id` AS id,\r\n\t\t`t1`.`am_name` AS `name`,\r\n\t\t(SELECT 'bilibili') AS type\r\n\tFROM\r\n\t\t`wyx_account_bilibili` AS t1\r\n)\r\nUNION ALL\r\n\t(\r\n\t\tSELECT\r\n\t\t\t`t2`.`am_id` AS id,\r\n\t\t\t`t3`.`am_name` AS `name`,\r\n\t\t\t(SELECT 'meipai') AS type\r\n\t\tFROM\r\n\t\t\t`wyx_account_meipai` AS t2\r\n\t)\r\nUNION ALL\r\n\t(\r\n\t\tSELECT\r\n\t\t\t`t3`.`am_id` AS id,\r\n\t\t\t`t4`.`am_name` AS `name`,\r\n\t\t\t(SELECT 'miaopai') AS type\r\n\t\tFROM\r\n\t\t\t`wyx_account_miaopai` AS t3\r\n\t)\r\n</pre>\r\n\r\nIt has not first issue above,but it still got the seconde issue \"**[Err] 1054 - Unknown column 't3.am_name' in 'field list'**\" the table is not correct.\r\n",
"\r\nFor test.\r\n<pre>\r\nCREATE TABLE `wyx_account_bilibili` (\r\n `am_id` int(10) unsigned NOT NULL AUTO_INCREMENT,\r\n `am_name` varchar(150) NOT NULL DEFAULT '',\r\n PRIMARY KEY (`am_id`)\r\n) ENGINE=InnoDB AUTO_INCREMENT=345 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT;\r\n\r\nCREATE TABLE `wyx_account_meipai` (\r\n `am_id` int(10) unsigned NOT NULL AUTO_INCREMENT,\r\n `am_name` varchar(150) NOT NULL DEFAULT '',\r\n PRIMARY KEY (`am_id`)\r\n) ENGINE=InnoDB AUTO_INCREMENT=345 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT;\r\n\r\n\r\nCREATE TABLE `wyx_account_miaopai` (\r\n `am_id` int(10) unsigned NOT NULL AUTO_INCREMENT,\r\n `am_name` varchar(150) NOT NULL DEFAULT '',\r\n PRIMARY KEY (`am_id`)\r\n) ENGINE=InnoDB AUTO_INCREMENT=345 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT;\r\n\r\n</pre>\r\n\r\n<pre>\r\n# encoding: utf-8\r\n\r\n\r\nfrom peewee import *\r\nfrom playhouse.read_slave import ReadSlaveModel\r\nfrom playhouse.shortcuts import RetryOperationalError\r\n\r\n\r\nclass MyRetryDB(RetryOperationalError, MySQLDatabase):\r\n pass\r\n\r\n\r\nmaster = MyRetryDB(\r\n host='127.0.0.1',\r\n user='root',\r\n passwd='root',\r\n database='weiyingxiao',\r\n charset='utf8',\r\n port=3306\r\n)\r\n\r\n\r\nclass BaseModel(ReadSlaveModel):\r\n class Meta:\r\n database = master\r\n\r\n\r\nclass AccountBilibili(BaseModel):\r\n class Meta:\r\n db_table = 'wyx_account_bilibili'\r\n\r\n am_id = PrimaryKeyField()\r\n am_name = CharField() # nickname\r\n\r\n\r\nclass AccountMeipai(BaseModel):\r\n class Meta:\r\n db_table = 'wyx_account_meipai'\r\n\r\n am_id = PrimaryKeyField() #\r\n am_name = CharField() # nickname\r\n\r\n\r\nclass AccountMiaopai(BaseModel):\r\n class Meta:\r\n db_table = 'wyx_account_miaopai'\r\n\r\n am_id = PrimaryKeyField() # \r\n am_name = CharField() # nickname\r\n\r\n\r\ndef get_video_account():\r\n a = AccountBilibili.select(AccountBilibili.am_id.alias('id'), AccountBilibili.am_name.alias('name'),\r\n SQL(\"(select 'bilibili')\").alias('type'))\r\n\r\n b = AccountMeipai.select(AccountMeipai.am_id.alias('id'), AccountBilibili.am_name.alias('name'),\r\n SQL(\"(select 'meipai')\").alias('type'))\r\n\r\n c = AccountMiaopai.select(AccountMiaopai.am_id.alias('id'), AccountBilibili.am_name.alias('name'),\r\n SQL(\"(select 'miaopai')\").alias('type'))\r\n\r\n d = (a | b | c)\r\n # d = a.union_all(b).union_all(c)\r\n\r\n print(d.sql())\r\n\r\n\r\nif __name__ == '__main__':\r\n get_video_account()\r\n\r\n</pre>\r\n\r\n",
"You are mixing models in your queries.\r\n\r\nIt should be:\r\n```python\r\ndef get_video_account():\r\n a = AccountBilibili.select(AccountBilibili.am_id.alias('id'), AccountBilibili.am_name.alias('name'),\r\n SQL(\"(select 'bilibili')\").alias('type'))\r\n\r\n b = AccountMeipai.select(AccountMeipai.am_id.alias('id'), AccountMeipai.am_name.alias('name'),\r\n SQL(\"(select 'meipai')\").alias('type'))\r\n\r\n c = AccountMiaopai.select(AccountMiaopai.am_id.alias('id'), AccountMiaopai.am_name.alias('name'),\r\n SQL(\"(select 'miaopai')\").alias('type'))\r\n\r\n d = (a | b | c)\r\n```",
"THX",
"Copy/paste fail? I wondered why the models were all mixed up like that :/",
"Yes, It make mistake form copying and pasting."
] | 2017-03-15T02:54:42 | 2017-03-22T01:30:14 | 2017-03-18T21:53:27 | NONE | null | <pre>
a = AccountBilibili.select(AccountBilibili.am_id.alias('id'), AccountBilibili.am_name.alias('name'), SQL("(select 'bilibili')").alias('type'))
b = AccountMeipai. select(AccountMeipai.am_id.alias('id'), AccountBilibili.am_name.alias('name'), SQL("(select 'meipai')").alias('type'))
c = AccountMiaopai. select(AccountMiaopai.am_id.alias('id'), AccountBilibili.am_name.alias('name'), SQL("(select 'miaopai')").alias('type'))
d= (a|b|c)
print(d.sql())
</pre>
It output this below.
<pre>
("((SELECT `t1`.`am_id` AS id, `t1`.`am_name` AS name, (select 'bilibili') AS type FROM `wyx_account_bilibili` AS t1) UNION (SELECT `t2`.`am_id` AS id, `t3`.`am_name` AS name, (select 'meipai') AS type FROM `wyx_account_meipai` AS t2)) UNION (SELECT `t3`.`am_id` AS id, `t4`.`am_name` AS name, (select 'miaopai') AS type FROM `wyx_account_miaopai` AS t3)", [])
</pre>
It output this when I formated .
<pre>
(
(
SELECT
`t1`.`am_id` AS id,
`t1`.`am_name` AS NAME,
(SELECT 'bilibili') AS type
FROM
`wyx_account_bilibili` AS t1
)
UNION
(
SELECT
`t2`.`am_id` AS id,
`t3`.`am_name` AS NAME,
(SELECT 'meipai') AS type
FROM
`wyx_account_meipai` AS t2
)
)
UNION
(
SELECT
`t3`.`am_id` AS id,
`t4`.`am_name` AS NAME,
(SELECT 'miaopai') AS type
FROM
`wyx_account_miaopai` AS t3
)
</pre>
Mysql not support this sql, and there are some obvious errer here. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1222/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1222/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1221 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1221/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1221/comments | https://api.github.com/repos/coleifer/peewee/issues/1221/events | https://github.com/coleifer/peewee/issues/1221 | 213,961,400 | MDU6SXNzdWUyMTM5NjE0MDA= | 1,221 | Regular Expressions for SQLite always case-insensitive | {
"login": "phryk",
"id": 1021513,
"node_id": "MDQ6VXNlcjEwMjE1MTM=",
"avatar_url": "https://avatars.githubusercontent.com/u/1021513?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/phryk",
"html_url": "https://github.com/phryk",
"followers_url": "https://api.github.com/users/phryk/followers",
"following_url": "https://api.github.com/users/phryk/following{/other_user}",
"gists_url": "https://api.github.com/users/phryk/gists{/gist_id}",
"starred_url": "https://api.github.com/users/phryk/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/phryk/subscriptions",
"organizations_url": "https://api.github.com/users/phryk/orgs",
"repos_url": "https://api.github.com/users/phryk/repos",
"events_url": "https://api.github.com/users/phryk/events{/privacy}",
"received_events_url": "https://api.github.com/users/phryk/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"This is a backwards-incompatible change, as you noted, but I think a sensible one. In the meantime, why not just register your own regexp function?\r\n\r\n```python\r\ndb = SqliteExtDatabase(...)\r\n\r\[email protected]('regex')\r\ndef regex(rgx, s):\r\n return re.search(rgx, s) is not None\r\n```",
"9be3341940616b781f2b0948bbee6eb5872cba64 -- I added a 3rd optional parameter, `case_sensitive` which defaults to `False`. You can pass `True` to get the desired behavior.",
"Thanks for the help thus far. But I am not sure the committed fix is applicable for me.\r\n\r\nIf I understand it correctly, I can only pass a python `bool` to that function if I call it via\r\n`peewee.fn.regexp`. However, I have a the following function to build a `CHECK` `Clause`:\r\n```\r\ndef RegexpConstraint(field_name, regexp):\r\n\r\n return peewee.Clause(\r\n peewee.SQL('CHECK('),\r\n peewee.Expression(\r\n QuotedSQL(field_name),\r\n peewee.OP.REGEXP,\r\n QuotedSQL(regexp),\r\n flat=True\r\n ),\r\n peewee.SQL(')'),\r\n )\r\n```\r\n\r\nUsage: `name = CharField(index=True, unique=True, null=False, constraints=[RegexpConstraint('name', '^[a-z0-9_\\-]+$')])`\r\n\r\nSeems to me that even if I can figure out how to pass extra parameters via SQL within\r\nthe `CHECK` clause, I won't be able to pass in a `False`. Plus, even if that is possible,\r\nit'll probably make that bit of code incompatible with anything but SQLite.\r\n\r\nCan I adapt my `RegexpConstraint` to pass `False` to _sqlite_regexp or I should just opt\r\nfor the `@db.func` approach?\r\n\r\nAnother thing to consider is that PostgreSQL and MySQL both do regular expressions\r\ncase-sensitively by default. This might bite people in the arse, if they want to support multiple\r\nDBMSes in a project that uses peewee.\r\n\r\nWandering the wide web and the IRCs of this world, I found that the best practice for making\r\na query using regular expressions case-insensitive is apparently doing it like:\r\n`LOWER(col) REGEXP \"^.*$\"`\r\n\r\nI was told actually using case-insensitive regular expressions (like with the `~*` operator for Postgres)\r\nin `WHERE` clauses can lead to performance issues due to indexing problems, but I can't really claim to have understood that in its entirety.",
"You can pass in `0` of course, but why not just write your own user-defined function that behaves exactly as you want?",
"That's what I'll do then. Mostly wanted to make sure not to add any unneeded code that might make maintenance harder in the future. Thanks for the reply. :)"
] | 2017-03-14T03:49:43 | 2017-03-19T01:16:42 | 2017-03-16T03:27:06 | NONE | null | https://github.com/coleifer/peewee/blob/master/peewee.py#L306
You're statically passing the `IGNORECASE` (`re.I`) flag for regexps in SQLite.
This makes it impossible to match only lower-case letters, which is kind of a
big deal for `CHECK` constraints using regular expressions.
I'd like to ask for this flag to simply be dropped from the `re.search` call.
I realize this might introduce an issue with backwards compatibility for some of
the people who currently depend on the case-insensitivity (if any). But nothing
those people are doing now will be impossible; Worst case they'll have to add
`A-Z` into some of their regexps… | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1221/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1221/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/1220 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1220/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1220/comments | https://api.github.com/repos/coleifer/peewee/issues/1220/events | https://github.com/coleifer/peewee/pull/1220 | 213,592,737 | MDExOlB1bGxSZXF1ZXN0MTEwMjkxOTcz | 1,220 | Use `get_primary_key_fields()` instead of `primary_key`, because the former knows how to handle composite keys | {
"login": "Necoro",
"id": 68708,
"node_id": "MDQ6VXNlcjY4NzA4",
"avatar_url": "https://avatars.githubusercontent.com/u/68708?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/Necoro",
"html_url": "https://github.com/Necoro",
"followers_url": "https://api.github.com/users/Necoro/followers",
"following_url": "https://api.github.com/users/Necoro/following{/other_user}",
"gists_url": "https://api.github.com/users/Necoro/gists{/gist_id}",
"starred_url": "https://api.github.com/users/Necoro/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/Necoro/subscriptions",
"organizations_url": "https://api.github.com/users/Necoro/orgs",
"repos_url": "https://api.github.com/users/Necoro/repos",
"events_url": "https://api.github.com/users/Necoro/events{/privacy}",
"received_events_url": "https://api.github.com/users/Necoro/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Nice, thanks!",
"I also merged another fix that should also take care of any other instances of the issue."
] | 2017-03-12T09:14:08 | 2017-03-12T14:57:06 | 2017-03-12T14:56:38 | CONTRIBUTOR | null | There is already a method `get_primary_key_fields()` which does just what is expected: return the list of all primary key fields, also handling CompositeKeys just right.
There are probably some more instances throughout the code, where using that method instead of `primary_key` would be advisable.
This should fix isse #1219. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1220/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1220/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/1220",
"html_url": "https://github.com/coleifer/peewee/pull/1220",
"diff_url": "https://github.com/coleifer/peewee/pull/1220.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/1220.patch",
"merged_at": "2017-03-12T14:56:38"
} |
https://api.github.com/repos/coleifer/peewee/issues/1219 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/1219/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/1219/comments | https://api.github.com/repos/coleifer/peewee/issues/1219/events | https://github.com/coleifer/peewee/issues/1219 | 213,591,075 | MDU6SXNzdWUyMTM1OTEwNzU= | 1,219 | CompositeKey in subquery not resolved | {
"login": "Necoro",
"id": 68708,
"node_id": "MDQ6VXNlcjY4NzA4",
"avatar_url": "https://avatars.githubusercontent.com/u/68708?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/Necoro",
"html_url": "https://github.com/Necoro",
"followers_url": "https://api.github.com/users/Necoro/followers",
"following_url": "https://api.github.com/users/Necoro/following{/other_user}",
"gists_url": "https://api.github.com/users/Necoro/gists{/gist_id}",
"starred_url": "https://api.github.com/users/Necoro/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/Necoro/subscriptions",
"organizations_url": "https://api.github.com/users/Necoro/orgs",
"repos_url": "https://api.github.com/users/Necoro/repos",
"events_url": "https://api.github.com/users/Necoro/events{/privacy}",
"received_events_url": "https://api.github.com/users/Necoro/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2017-03-12T08:36:14 | 2017-03-12T14:55:21 | 2017-03-12T14:55:21 | CONTRIBUTOR | null | Given the following simple model with a composite PK:
```python
class DocumentTag(BaseModel):
document = ForeignKeyField(Document, related_name = 'tags')
tag = ForeignKeyField(Tag)
class Meta:
primary_key = CompositeKey('document', 'tag')
```
`DocumentTag.select()` works as expected, yielding
```sql
SELECT "t1"."document_id", "t1"."tag_id" FROM "documenttag" AS t1
```
When I now want to use `DocumentTag` in a subquery, the CompositeKey is not resolved as one would expect (the query does not make sense, but works for illustration purposes):
`Document.select().where(DocumentTag.select() == 1)` now yields
```sql
SELECT "t1".*
FROM "document" AS t1
WHERE ((SELECT ? FROM "documenttag" AS t2) = ?)
[<peewee.CompositeKey object at 0x7f1c0465b438>, 1]
```
The same holds for other uses of subqueries, like joining with a subquery. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/1219/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/1219/timeline | null | completed | null | null |
Subsets and Splits