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/2218 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2218/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2218/comments | https://api.github.com/repos/coleifer/peewee/issues/2218/events | https://github.com/coleifer/peewee/issues/2218 | 651,238,790 | MDU6SXNzdWU2NTEyMzg3OTA= | 2,218 | How to get ridoff double quotes | {
"login": "wilberh",
"id": 6799242,
"node_id": "MDQ6VXNlcjY3OTkyNDI=",
"avatar_url": "https://avatars.githubusercontent.com/u/6799242?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/wilberh",
"html_url": "https://github.com/wilberh",
"followers_url": "https://api.github.com/users/wilberh/followers",
"following_url": "https://api.github.com/users/wilberh/following{/other_user}",
"gists_url": "https://api.github.com/users/wilberh/gists{/gist_id}",
"starred_url": "https://api.github.com/users/wilberh/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/wilberh/subscriptions",
"organizations_url": "https://api.github.com/users/wilberh/orgs",
"repos_url": "https://api.github.com/users/wilberh/repos",
"events_url": "https://api.github.com/users/wilberh/events{/privacy}",
"received_events_url": "https://api.github.com/users/wilberh/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Responded to this when you asked on a different issue: https://github.com/coleifer/peewee/issues/2064#issuecomment-654236281\r\n\r\nThe alternative is to maintain a list of all sql reserved words and only quote words when they happen to collide with a sql keyword, and that seems silly. Quoting identifiers is the best way to handle this. Similarly, I've seen people who use whitespace and all kinds of other unexpected things in their sql identifiers. Quoting ensures that they work in all cases."
] | 2020-07-06T04:32:40 | 2020-07-06T13:27:39 | 2020-07-06T13:27:39 | NONE | null | I'm using a database driver that is DB API (PEP-249) v2.0 compliant.
How can I tell peewee to not add double quotes on everything?
ex:
My base class is inheriting from the Model class. Whenever I call ItemModel.select() and noticed peewee is adding double quotes. How can I configure the class Model to not add double quotes.
Is coming out like:
SELECT "t1"."item1", "t1"."item2", "t1"."item3" FROM "trex_inventory_recipe_material" AS t1
I need it like this:
SELECT t1.item1, t1.item2, t1.item3 FROM trex_inventory_recipe_material AS t1 | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2218/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2218/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2217 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2217/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2217/comments | https://api.github.com/repos/coleifer/peewee/issues/2217/events | https://github.com/coleifer/peewee/issues/2217 | 650,911,828 | MDU6SXNzdWU2NTA5MTE4Mjg= | 2,217 | Multiple joins on same table produces ambiguous column name | {
"login": "Zverik",
"id": 766031,
"node_id": "MDQ6VXNlcjc2NjAzMQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/766031?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/Zverik",
"html_url": "https://github.com/Zverik",
"followers_url": "https://api.github.com/users/Zverik/followers",
"following_url": "https://api.github.com/users/Zverik/following{/other_user}",
"gists_url": "https://api.github.com/users/Zverik/gists{/gist_id}",
"starred_url": "https://api.github.com/users/Zverik/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/Zverik/subscriptions",
"organizations_url": "https://api.github.com/users/Zverik/orgs",
"repos_url": "https://api.github.com/users/Zverik/repos",
"events_url": "https://api.github.com/users/Zverik/events{/privacy}",
"received_events_url": "https://api.github.com/users/Zverik/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
">I have solved this with MailCode.alias()\r\n\r\nThis is the peewee-official way to do reference the same table in multiple contexts within a single query."
] | 2020-07-04T15:40:56 | 2020-07-04T15:50:51 | 2020-07-04T15:50:51 | CONTRIBUTOR | null | I've got this code that inner joins the same table twice:
```
cnt = (
User.select()
.join_from(User, MailCode, on=MailCode.sent_by)
.join_from(User, MailCode, on=MailCode.sent_to)
.where(User.is_active == True).count()
)
```
For some reason it uses alias "t2" twice:
```
SELECT COUNT(1) FROM (
SELECT 1 FROM "user" AS "t1"
INNER JOIN "mailcode" AS "t2" ON ("t2"."sent_by_id" = "t1"."id")
INNER JOIN "mailcode" AS "t2" ON ("t2"."sent_to_id" = "t1"."id")
WHERE ("t1"."is_active" = True)
) AS "_wrapped"
```
Is this expected behaviour? There is nothing on that in the documentation.
(I have solved this with `MailCode.alias()`, but it seems a pretty common case not to be processed.) | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2217/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2217/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2216 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2216/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2216/comments | https://api.github.com/repos/coleifer/peewee/issues/2216/events | https://github.com/coleifer/peewee/issues/2216 | 650,052,367 | MDU6SXNzdWU2NTAwNTIzNjc= | 2,216 | Any integration with Hadoop (Hive)? | {
"login": "wilberh",
"id": 6799242,
"node_id": "MDQ6VXNlcjY3OTkyNDI=",
"avatar_url": "https://avatars.githubusercontent.com/u/6799242?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/wilberh",
"html_url": "https://github.com/wilberh",
"followers_url": "https://api.github.com/users/wilberh/followers",
"following_url": "https://api.github.com/users/wilberh/following{/other_user}",
"gists_url": "https://api.github.com/users/wilberh/gists{/gist_id}",
"starred_url": "https://api.github.com/users/wilberh/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/wilberh/subscriptions",
"organizations_url": "https://api.github.com/users/wilberh/orgs",
"repos_url": "https://api.github.com/users/wilberh/repos",
"events_url": "https://api.github.com/users/wilberh/events{/privacy}",
"received_events_url": "https://api.github.com/users/wilberh/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"never heard of it. Read the manual:\r\n\r\nhttp://docs.peewee-orm.com/en/latest/peewee/database.html#adding-a-new-database-driver"
] | 2020-07-02T16:11:48 | 2020-07-02T16:33:39 | 2020-07-02T16:33:38 | NONE | null | Does Peewee have support / extension for Hadoop (Hive / Pyhive)? | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2216/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2216/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2215 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2215/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2215/comments | https://api.github.com/repos/coleifer/peewee/issues/2215/events | https://github.com/coleifer/peewee/issues/2215 | 648,096,937 | MDU6SXNzdWU2NDgwOTY5Mzc= | 2,215 | peewee + asyncpg | {
"login": "jet10000",
"id": 2258120,
"node_id": "MDQ6VXNlcjIyNTgxMjA=",
"avatar_url": "https://avatars.githubusercontent.com/u/2258120?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/jet10000",
"html_url": "https://github.com/jet10000",
"followers_url": "https://api.github.com/users/jet10000/followers",
"following_url": "https://api.github.com/users/jet10000/following{/other_user}",
"gists_url": "https://api.github.com/users/jet10000/gists{/gist_id}",
"starred_url": "https://api.github.com/users/jet10000/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/jet10000/subscriptions",
"organizations_url": "https://api.github.com/users/jet10000/orgs",
"repos_url": "https://api.github.com/users/jet10000/repos",
"events_url": "https://api.github.com/users/jet10000/events{/privacy}",
"received_events_url": "https://api.github.com/users/jet10000/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2020-06-30T11:29:09 | 2020-06-30T13:08:18 | 2020-06-30T13:08:18 | NONE | null | I want to use peewee to manage tables and queries, use peewee to generate sql queries, and then use asyncpg to execute. How can I do it? I hope there is an example.
```
import asyncio
import asyncpg
from devtools import debug
from auth.models import User
async def main():
conn = await asyncpg.connect('postgresql://postgres:pass@localhost:5432/testdb')
# Execute a statement to create a new table.
q = User.select().sql()
debug(q)
res = await conn.fetch(q)
debug(res)
await conn.close()
asyncio.get_event_loop().run_until_complete(main())
```
```
entry = self._entries.get(query) # type: _StatementCacheEntry
TypeError: unhashable type: 'list'
```` | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2215/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2215/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2214 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2214/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2214/comments | https://api.github.com/repos/coleifer/peewee/issues/2214/events | https://github.com/coleifer/peewee/issues/2214 | 647,989,124 | MDU6SXNzdWU2NDc5ODkxMjQ= | 2,214 | Add UUIDKeyField for postgres | {
"login": "jet10000",
"id": 2258120,
"node_id": "MDQ6VXNlcjIyNTgxMjA=",
"avatar_url": "https://avatars.githubusercontent.com/u/2258120?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/jet10000",
"html_url": "https://github.com/jet10000",
"followers_url": "https://api.github.com/users/jet10000/followers",
"following_url": "https://api.github.com/users/jet10000/following{/other_user}",
"gists_url": "https://api.github.com/users/jet10000/gists{/gist_id}",
"starred_url": "https://api.github.com/users/jet10000/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/jet10000/subscriptions",
"organizations_url": "https://api.github.com/users/jet10000/orgs",
"repos_url": "https://api.github.com/users/jet10000/repos",
"events_url": "https://api.github.com/users/jet10000/events{/privacy}",
"received_events_url": "https://api.github.com/users/jet10000/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"CockroachDB provides this function out-of-the-box. Postgres requires an extension, so it is not provided as a built-in. It is quite easy to add this if you want it, though -- just use the implementation from cockroachdb or create your own subclass.",
"PostgreSQL 13 \r\nhttps://www.postgresql.org/docs/13/functions-uuid.html"
] | 2020-06-30T08:46:05 | 2020-10-10T18:17:58 | 2020-06-30T13:11:35 | NONE | null | I found a UUIDKeyField in cockroachdb, Please add a UUIDKeyField for PostgreSQL, the default value `gen_random_uuid()`.
```
CREATE EXTENSION IF NOT EXISTS "pgcrypto";
```
https://medium.com/@shawnoy/generate-a-uuid-as-postgresql-default-value-fc0ae41a37d2
if extension not exists, reminder to install this extension.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2214/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2214/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2213 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2213/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2213/comments | https://api.github.com/repos/coleifer/peewee/issues/2213/events | https://github.com/coleifer/peewee/pull/2213 | 646,426,772 | MDExOlB1bGxSZXF1ZXN0NDQwNzE4MDI5 | 2,213 | Fix invalid escape sequence in regex | {
"login": "narusemotoki",
"id": 1593495,
"node_id": "MDQ6VXNlcjE1OTM0OTU=",
"avatar_url": "https://avatars.githubusercontent.com/u/1593495?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/narusemotoki",
"html_url": "https://github.com/narusemotoki",
"followers_url": "https://api.github.com/users/narusemotoki/followers",
"following_url": "https://api.github.com/users/narusemotoki/following{/other_user}",
"gists_url": "https://api.github.com/users/narusemotoki/gists{/gist_id}",
"starred_url": "https://api.github.com/users/narusemotoki/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/narusemotoki/subscriptions",
"organizations_url": "https://api.github.com/users/narusemotoki/orgs",
"repos_url": "https://api.github.com/users/narusemotoki/repos",
"events_url": "https://api.github.com/users/narusemotoki/events{/privacy}",
"received_events_url": "https://api.github.com/users/narusemotoki/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2020-06-26T18:04:51 | 2020-06-26T18:27:33 | 2020-06-26T18:20:14 | CONTRIBUTOR | null | Hello.
Lint tools told me about `\` in regex. I think it's better to be raw strings.
pycodestyle says me:
```
playhouse/cockroachdb.py:71:48: W605 invalid escape sequence '\d'
playhouse/cockroachdb.py:71:52: W605 invalid escape sequence '\.'
playhouse/cockroachdb.py:71:55: W605 invalid escape sequence '\d'
playhouse/cockroachdb.py:71:59: W605 invalid escape sequence '\.'
playhouse/cockroachdb.py:71:62: W605 invalid escape sequence '\d'
```
Also pylint says:
```
playhouse/cockroachdb.py:71:17: W1401: Anomalous backslash in string: '\d'. String constant might be missing an r prefix. (anomalous-backslash-in-string)
playhouse/cockroachdb.py:71:21: W1401: Anomalous backslash in string: '\.'. String constant might be missing an r prefix. (anomalous-backslash-in-string)
playhouse/cockroachdb.py:71:24: W1401: Anomalous backslash in string: '\d'. String constant might be missing an r prefix. (anomalous-backslash-in-string)
playhouse/cockroachdb.py:71:28: W1401: Anomalous backslash in string: '\.'. String constant might be missing an r prefix. (anomalous-backslash-in-string)
playhouse/cockroachdb.py:71:31: W1401: Anomalous backslash in string: '\d'. String constant might be missing an r prefix. (anomalous-backslash-in-string)
```
Reference https://stackoverflow.com/questions/19030952/pep8-warning-on-regex-string-in-python-eclipse | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2213/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2213/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/2213",
"html_url": "https://github.com/coleifer/peewee/pull/2213",
"diff_url": "https://github.com/coleifer/peewee/pull/2213.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/2213.patch",
"merged_at": "2020-06-26T18:20:14"
} |
https://api.github.com/repos/coleifer/peewee/issues/2212 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2212/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2212/comments | https://api.github.com/repos/coleifer/peewee/issues/2212/events | https://github.com/coleifer/peewee/issues/2212 | 645,963,760 | MDU6SXNzdWU2NDU5NjM3NjA= | 2,212 | Field in query results has ") appended to its name | {
"login": "zacc",
"id": 966053,
"node_id": "MDQ6VXNlcjk2NjA1Mw==",
"avatar_url": "https://avatars.githubusercontent.com/u/966053?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/zacc",
"html_url": "https://github.com/zacc",
"followers_url": "https://api.github.com/users/zacc/followers",
"following_url": "https://api.github.com/users/zacc/following{/other_user}",
"gists_url": "https://api.github.com/users/zacc/gists{/gist_id}",
"starred_url": "https://api.github.com/users/zacc/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/zacc/subscriptions",
"organizations_url": "https://api.github.com/users/zacc/orgs",
"repos_url": "https://api.github.com/users/zacc/repos",
"events_url": "https://api.github.com/users/zacc/events{/privacy}",
"received_events_url": "https://api.github.com/users/zacc/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"You're probably using an older version of Sqlite(?) or otherwise the database is generating a column-name for your MAX value like 'MAX(\"t1\".\"score\")'. Just specify an alias:\r\n\r\n```python\r\nfn.MAX(Comment.score).alias('max_score')\r\n```\r\n\r\nThen it will be available as the \"max_score\" attribute.",
"Sorry yes I should have mentioned SQLite! For your reference I am using 3.22, it has a version tag `3.22.0 2018-01-22 18:45:57` . Regards."
] | 2020-06-26T02:32:48 | 2020-06-27T01:56:21 | 2020-06-26T13:06:52 | NONE | null | Executing this query in Python\:
`Comment.select(Comment.submission_id, Comment.id, fn.Max(Comment.score)).group_by(Comment.submission_id)`
The `.sql()` output of the query is:
`('SELECT "t1"."submission_id", "t1"."id", Max("t1"."score") FROM "comment" AS "t1" GROUP BY "t1"."submission_id"', [])`
Running `print(vars(record))` on the output of the query shows:
`{'__data__': {'submission_id': '7k57rl', 'id': 'drbr3hf'}, '_dirty': set(), '__rel__': {}, 'score")': 37}`
The score field now is labelled `score")`
Working around it with `getattr(record, 'score\")'` for the moment!
The output appears to be correct, though!
The SQL might not be optimum for the case but I thought the bug might be of interest anyway.
Thank you for the excellent ORM. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2212/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2212/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2211 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2211/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2211/comments | https://api.github.com/repos/coleifer/peewee/issues/2211/events | https://github.com/coleifer/peewee/pull/2211 | 643,289,554 | MDExOlB1bGxSZXF1ZXN0NDM4MTE4NDkw | 2,211 | Fix for Falcon integration example code | {
"login": "zgoda",
"id": 141999,
"node_id": "MDQ6VXNlcjE0MTk5OQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/141999?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/zgoda",
"html_url": "https://github.com/zgoda",
"followers_url": "https://api.github.com/users/zgoda/followers",
"following_url": "https://api.github.com/users/zgoda/following{/other_user}",
"gists_url": "https://api.github.com/users/zgoda/gists{/gist_id}",
"starred_url": "https://api.github.com/users/zgoda/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/zgoda/subscriptions",
"organizations_url": "https://api.github.com/users/zgoda/orgs",
"repos_url": "https://api.github.com/users/zgoda/repos",
"events_url": "https://api.github.com/users/zgoda/events{/privacy}",
"received_events_url": "https://api.github.com/users/zgoda/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2020-06-22T18:50:50 | 2020-06-22T20:44:13 | 2020-06-22T20:40:25 | CONTRIBUTOR | null | The signature for response processing in middlewares has one more argument (see https://falcon.readthedocs.io/en/stable/api/middleware.html) | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2211/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2211/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/2211",
"html_url": "https://github.com/coleifer/peewee/pull/2211",
"diff_url": "https://github.com/coleifer/peewee/pull/2211.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/2211.patch",
"merged_at": "2020-06-22T20:40:25"
} |
https://api.github.com/repos/coleifer/peewee/issues/2210 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2210/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2210/comments | https://api.github.com/repos/coleifer/peewee/issues/2210/events | https://github.com/coleifer/peewee/issues/2210 | 643,203,713 | MDU6SXNzdWU2NDMyMDM3MTM= | 2,210 | Use JSONField with database proxy? | {
"login": "LVerneyPEReN",
"id": 58298410,
"node_id": "MDQ6VXNlcjU4Mjk4NDEw",
"avatar_url": "https://avatars.githubusercontent.com/u/58298410?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/LVerneyPEReN",
"html_url": "https://github.com/LVerneyPEReN",
"followers_url": "https://api.github.com/users/LVerneyPEReN/followers",
"following_url": "https://api.github.com/users/LVerneyPEReN/following{/other_user}",
"gists_url": "https://api.github.com/users/LVerneyPEReN/gists{/gist_id}",
"starred_url": "https://api.github.com/users/LVerneyPEReN/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/LVerneyPEReN/subscriptions",
"organizations_url": "https://api.github.com/users/LVerneyPEReN/orgs",
"repos_url": "https://api.github.com/users/LVerneyPEReN/repos",
"events_url": "https://api.github.com/users/LVerneyPEReN/events{/privacy}",
"received_events_url": "https://api.github.com/users/LVerneyPEReN/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"No, that's not really do-able, as each database tends to require it's own form of syntax and operations.",
"You could try to apply a hook when the database proxy is initialized, which at that point would add the correct Json field to the model instance, I guess?",
"Digging into `peewee` code, I came across https://github.com/coleifer/peewee/blob/master/peewee.py#L4904-L4928 which seems to have a different behavior depending on the database in use.\r\n\r\nWouldn't it be possible to somehow unify https://github.com/coleifer/peewee/blob/master/playhouse/sqlite_ext.py#L122-L194 and https://github.com/coleifer/peewee/blob/master/playhouse/postgres_ext.py#L294-L320 in a single `JSONField` class with a similar approach, with actual implementation depending on the database object?\r\n\r\nBeyond the quick and dirty hack, I guess this would require either moving this code from Playhouse to Peewee core or making a super `*Database` class in Playhouse which would supercede the `*Database` classes from Peewee.\r\n\r\n\r\nThis is something I regularly need and the usual way to fix this is to create from scratch and naive `JSONField` (no knowledge of the JSON structure, just encoded/decoded from text field). If something generic as described above is achievable here in a robust way, I can definitely help write and test it."
] | 2020-06-22T16:20:46 | 2020-06-23T07:52:49 | 2020-06-22T18:00:11 | NONE | null | Hi,
I see that Playhouse extensions have dedicated `JSONField` for each database implementation. However, I did not find an abstract `JSONField` which could be used in a database proxy scenario.
For instance, I am using something like:
```python
import peewee
from playhouse.db_url import connect
database_proxy = peewee.DatabaseProxy()
database_proxy.initialize(
connect(os.environ.get('DATABASE', 'sqlite:///data.db'))
)
class BaseModel(Model):
class Meta:
database = database_proxy
field = JSONField() # <-- where JSONField is either the JSONField from sqlite_ext, postgres_ext or mysql_ext depending on the `connect` URI.
```
Is something like this achievable easily?
Thanks!
Best, | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2210/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2210/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2209 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2209/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2209/comments | https://api.github.com/repos/coleifer/peewee/issues/2209/events | https://github.com/coleifer/peewee/issues/2209 | 642,285,170 | MDU6SXNzdWU2NDIyODUxNzA= | 2,209 | peewee.ProgrammingError: missing FROM-clause entry for table "t1" | {
"login": "jet10000",
"id": 2258120,
"node_id": "MDQ6VXNlcjIyNTgxMjA=",
"avatar_url": "https://avatars.githubusercontent.com/u/2258120?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/jet10000",
"html_url": "https://github.com/jet10000",
"followers_url": "https://api.github.com/users/jet10000/followers",
"following_url": "https://api.github.com/users/jet10000/following{/other_user}",
"gists_url": "https://api.github.com/users/jet10000/gists{/gist_id}",
"starred_url": "https://api.github.com/users/jet10000/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/jet10000/subscriptions",
"organizations_url": "https://api.github.com/users/jet10000/orgs",
"repos_url": "https://api.github.com/users/jet10000/repos",
"events_url": "https://api.github.com/users/jet10000/events{/privacy}",
"received_events_url": "https://api.github.com/users/jet10000/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I can't see a problem in the SQL being generated. Can you provide the SQL for a working version and highlight the differences? Also what database are you using?",
"PostgreSQL12\r\n\r\n",
"Can you provide the SQL for a working version?",
"```\r\nquery3 = Bookchapter.select(\r\n Bookchapter.id,\r\n Bookchapter.chapter,\r\n)\r\n\r\ntt = Books.insert_from(query3, fields=[\r\n Books.id,\r\n Books.chapter\r\n]).on_conflict(\r\n conflict_target=[Books.id],\r\n update={Books.chapter: Bookchapter.chapter}\r\n).sql()\r\n\r\nprint(tt)\r\n```\r\n\r\n```\r\n<peewee.PostgresqlDatabase object at 0x10d7571c0>\r\n('INSERT INTO \"books\" (\"id\", \"chapter\") SELECT \"t1\".\"id\", \"t1\".\"chapter\" FROM \"bookchapter\" AS \"t1\" ON CONFLICT (\"id\") DO UPDATE SET \"chapter\" = \"t1\".\"chapter\"', [])\r\n```\r\n",
"I thought you said it was not working. Please share the sql to a version of the query that works.",
"The proper way to write this is to reference the \"new\" update-value using `EXCLUDED`. Peewee provides a shortcut, which is the `preserve` option.\r\n\r\n```python\r\nBooks.insert_from(query3, fields=[\r\n Books.id,\r\n Books.chapter\r\n]).on_conflict(\r\n conflict_target=[Books.id],\r\n preserve=[q.c.name] # Note we're referencing the name here.\r\n)\r\n```\r\n\r\nYou can also write:\r\n\r\n```python\r\n.on_conflict(\r\n conflict_target=[Books.id],\r\n preserve=['name'] # Name of column to preserve (\"carry over\") from insert.\r\n)\r\n```"
] | 2020-06-20T01:46:12 | 2020-06-22T14:07:53 | 2020-06-22T14:07:53 | NONE | null | ```
query3 = Bookchapter.select(
Bookchapter.id,
Bookchapter.chapter,
)
Books.insert_from(query3, fields=[
Books.id,
Books.chapter
]).on_conflict(
conflict_target=[Books.id],
update={Books.chapter: Bookchapter.chapter}
).execute()
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2209/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2209/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2208 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2208/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2208/comments | https://api.github.com/repos/coleifer/peewee/issues/2208/events | https://github.com/coleifer/peewee/pull/2208 | 642,277,642 | MDExOlB1bGxSZXF1ZXN0NDM3MzQyOTc1 | 2,208 | Add missing parenthesis in sqlite_ext docs | {
"login": "jinai",
"id": 7669687,
"node_id": "MDQ6VXNlcjc2Njk2ODc=",
"avatar_url": "https://avatars.githubusercontent.com/u/7669687?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/jinai",
"html_url": "https://github.com/jinai",
"followers_url": "https://api.github.com/users/jinai/followers",
"following_url": "https://api.github.com/users/jinai/following{/other_user}",
"gists_url": "https://api.github.com/users/jinai/gists{/gist_id}",
"starred_url": "https://api.github.com/users/jinai/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/jinai/subscriptions",
"organizations_url": "https://api.github.com/users/jinai/orgs",
"repos_url": "https://api.github.com/users/jinai/repos",
"events_url": "https://api.github.com/users/jinai/events{/privacy}",
"received_events_url": "https://api.github.com/users/jinai/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2020-06-20T00:54:30 | 2020-06-20T01:08:01 | 2020-06-20T01:08:01 | CONTRIBUTOR | null | If you were to copy and paste the first example in the `Getting started` section of the sqlite_ext docs,
you'd get a `SyntaxError`. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2208/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2208/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/2208",
"html_url": "https://github.com/coleifer/peewee/pull/2208",
"diff_url": "https://github.com/coleifer/peewee/pull/2208.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/2208.patch",
"merged_at": "2020-06-20T01:08:01"
} |
https://api.github.com/repos/coleifer/peewee/issues/2207 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2207/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2207/comments | https://api.github.com/repos/coleifer/peewee/issues/2207/events | https://github.com/coleifer/peewee/issues/2207 | 641,850,068 | MDU6SXNzdWU2NDE4NTAwNjg= | 2,207 | AttributeError: module 'Person' has no attribute '_meta' | {
"login": "teamcloud-jh",
"id": 66046114,
"node_id": "MDQ6VXNlcjY2MDQ2MTE0",
"avatar_url": "https://avatars.githubusercontent.com/u/66046114?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/teamcloud-jh",
"html_url": "https://github.com/teamcloud-jh",
"followers_url": "https://api.github.com/users/teamcloud-jh/followers",
"following_url": "https://api.github.com/users/teamcloud-jh/following{/other_user}",
"gists_url": "https://api.github.com/users/teamcloud-jh/gists{/gist_id}",
"starred_url": "https://api.github.com/users/teamcloud-jh/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/teamcloud-jh/subscriptions",
"organizations_url": "https://api.github.com/users/teamcloud-jh/orgs",
"repos_url": "https://api.github.com/users/teamcloud-jh/repos",
"events_url": "https://api.github.com/users/teamcloud-jh/events{/privacy}",
"received_events_url": "https://api.github.com/users/teamcloud-jh/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"It seems like `Person` does not inherit `Model`. You did not put the code for `Person` so it's just a guess.",
"Thanks for the reply.\r\n\r\nHowever, I do have Person inherit Model.\r\n\r\nCode:\r\n> from peewee import *\r\n> class Person(Model):\r\n\r\nAlso tried\r\n> import peewee\r\n> class Person(peewee.Model):"
] | 2020-06-19T09:54:10 | 2020-06-22T05:19:09 | 2020-06-19T12:53:01 | NONE | null | Unable to create a table containing foreign keys due to this error.
Code:
import peewee
import Person
db = peewee.MySQLDatabase('database', user='user', passwd='')
class Activity(peewee.Model):
id = peewee.CharField(primary_key=True)
userId = peewee.ForeignKeyField(model=Person)
class Meta:
database = db
db_table = 'activities'
Activity.create_table()
Error:
Traceback (most recent call last):
File ".../Activity.py", line 7, in <module>
class Activity(peewee.Model):
File "...\AppData\Local\Programs\Python\Python38-32\lib\site-packages\peewee.py", line 6128, in __new__
cls._meta.add_field(name, field)
File "...\AppData\Local\Programs\Python\Python38-32\lib\site-packages\peewee.py", line 5917, in add_field
field.bind(self.model, field_name, set_attribute)
File "...\AppData\Local\Programs\Python\Python38-32\lib\site-packages\peewee.py", line 5180, in bind self.rel_field = self.rel_model._meta.primary_key
AttributeError: module 'Person' has no attribute '_meta'
Other tables without foreign key can be created.
I've checked other sites for solutions but none fit my situation.
Versions:
peewee - 3.13.3
Python - 3.8.3
OS - Windows 10 | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2207/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2207/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2206 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2206/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2206/comments | https://api.github.com/repos/coleifer/peewee/issues/2206/events | https://github.com/coleifer/peewee/issues/2206 | 641,489,194 | MDU6SXNzdWU2NDE0ODkxOTQ= | 2,206 | Hadaoop (hdfs) extension? | {
"login": "wilberh",
"id": 6799242,
"node_id": "MDQ6VXNlcjY3OTkyNDI=",
"avatar_url": "https://avatars.githubusercontent.com/u/6799242?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/wilberh",
"html_url": "https://github.com/wilberh",
"followers_url": "https://api.github.com/users/wilberh/followers",
"following_url": "https://api.github.com/users/wilberh/following{/other_user}",
"gists_url": "https://api.github.com/users/wilberh/gists{/gist_id}",
"starred_url": "https://api.github.com/users/wilberh/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/wilberh/subscriptions",
"organizations_url": "https://api.github.com/users/wilberh/orgs",
"repos_url": "https://api.github.com/users/wilberh/repos",
"events_url": "https://api.github.com/users/wilberh/events{/privacy}",
"received_events_url": "https://api.github.com/users/wilberh/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"No"
] | 2020-06-18T19:16:18 | 2020-06-18T22:13:03 | 2020-06-18T22:13:03 | NONE | null | Any Hadoop (hdfs) extension available? | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2206/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2206/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2205 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2205/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2205/comments | https://api.github.com/repos/coleifer/peewee/issues/2205/events | https://github.com/coleifer/peewee/issues/2205 | 639,440,781 | MDU6SXNzdWU2Mzk0NDA3ODE= | 2,205 | LATERAL constant string doesn't have JOIN inside | {
"login": "lephuongbg",
"id": 1001176,
"node_id": "MDQ6VXNlcjEwMDExNzY=",
"avatar_url": "https://avatars.githubusercontent.com/u/1001176?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/lephuongbg",
"html_url": "https://github.com/lephuongbg",
"followers_url": "https://api.github.com/users/lephuongbg/followers",
"following_url": "https://api.github.com/users/lephuongbg/following{/other_user}",
"gists_url": "https://api.github.com/users/lephuongbg/gists{/gist_id}",
"starred_url": "https://api.github.com/users/lephuongbg/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/lephuongbg/subscriptions",
"organizations_url": "https://api.github.com/users/lephuongbg/orgs",
"repos_url": "https://api.github.com/users/lephuongbg/repos",
"events_url": "https://api.github.com/users/lephuongbg/events{/privacy}",
"received_events_url": "https://api.github.com/users/lephuongbg/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I'm following the examples provided here in pg's doc: https://www.postgresql.org/docs/current/queries-table-expressions.html#QUERIES-LATERAL\r\n\r\nI suppose we probably also need to support an inner lateral join, too, though I'm not sure how that would be used.",
"The way I'm currently going to address this is to add the `lateral()` method to the select query class.\r\n\r\nThis gives you the opportunity to use joins more naturally, and signifies only that the subquery being joined should be interpreted as a lateral join, which I think is more \"correct\" anyways.\r\n\r\nExample:\r\n\r\n```python\r\n\r\n# Here we use a subquery to get the most-recent two tweets by each user.\r\nsubq = (Tweet\r\n .select(Tweet.content, Tweet.timestamp)\r\n .where(Tweet.user == User.id)\r\n .order_by(Tweet.timestamp.desc())\r\n .limit(2)\r\n .lateral())\r\n\r\n# Here we do an inner join on the (lateral) subquery of tweets.\r\nquery = (User\r\n .select(User, subq.c.content)\r\n .join(subq, on=True)\r\n .order_by(subq.c.timestamp))\r\n```",
"The example that you referred to with only `LATERAL` is actually multiple `FROM` clause, which needs a comma between them. \r\n\r\n\r\n\r\nAbove clause is equivalent to `INNER JOIN LATERAL` or just `JOIN LATERAL`.\r\n\r\nI do like the current API of `LATERAL` though (`.join(sq, join_type=JOIN.LATERAL)`), and I noticed there is also `CROSS JOIN LATERAL` too."
] | 2020-06-16T07:34:37 | 2020-06-17T08:18:23 | 2020-06-16T15:28:10 | NONE | null | `JOIN.LATERAL` constant string currently only contains `'LATERAL'`, which causes syntax error with Postgresql. It should be either `'INNER JOIN LATERAL'` or simply `'JOIN LATERAL'`
`JOIN.LEFT_LATERAL` is correct though (`'LEFT JOIN LATERAL'`). | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2205/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2205/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2204 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2204/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2204/comments | https://api.github.com/repos/coleifer/peewee/issues/2204/events | https://github.com/coleifer/peewee/issues/2204 | 639,403,185 | MDU6SXNzdWU2Mzk0MDMxODU= | 2,204 | Peewee/psychopg2 always in transaction mode | {
"login": "RickMeasham",
"id": 79414,
"node_id": "MDQ6VXNlcjc5NDE0",
"avatar_url": "https://avatars.githubusercontent.com/u/79414?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/RickMeasham",
"html_url": "https://github.com/RickMeasham",
"followers_url": "https://api.github.com/users/RickMeasham/followers",
"following_url": "https://api.github.com/users/RickMeasham/following{/other_user}",
"gists_url": "https://api.github.com/users/RickMeasham/gists{/gist_id}",
"starred_url": "https://api.github.com/users/RickMeasham/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/RickMeasham/subscriptions",
"organizations_url": "https://api.github.com/users/RickMeasham/orgs",
"repos_url": "https://api.github.com/users/RickMeasham/repos",
"events_url": "https://api.github.com/users/RickMeasham/events{/privacy}",
"received_events_url": "https://api.github.com/users/RickMeasham/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
">When there's a database error, postgres leaves me in a failed transaction.\r\n\r\nYes, in which case you should issue a rollback.\r\n\r\nPeewee is currently designed to work *with* psycopg2's transaction handling. Setting `autocommit=True` may break Peewee's transactional APIs or may have other unintended consequences. Unless you're very familiar with both peewee's transaction semantics and psycopg2's, I wouldn't recommend setting pg to autocommit.\r\n\r\nIf the issue is simply that you are issuing queries that fail due to errors, I suggest you fix your queries to make them more robust, and wrap them with peewee's `atomic` (or ensure that you properly roll-back upon a query failure).\r\n\r\nBy the way, your traceback is not relevant I don't think, since that is the query you are attempting to execute *after* a previous query failed."
] | 2020-06-16T06:22:38 | 2020-06-16T13:27:09 | 2020-06-16T13:27:08 | NONE | null | When there's a database error, postgres leaves me in a failed transaction. This appears to be because psycopg2 [defaults to manual commits](https://www.psycopg.org/docs/connection.html#connection.autocommit). So I updated the connection to pass through `autocommit=True` but it appears I'm still stuck in failed transactions when there are errors:
Here's my connection code:
```
database = PostgresqlExtDatabase(
config.database('dbname'),
host=config.database('host'),
user=config.database('username'),
password=config.database('password'),
autocommit=True
)
```
Is that the right way to connect with autocommit?
Here's the traceback if it helps:
```
Traceback (most recent call last):
File "/var/task/handler/trial.py", line 97, in handler
return trial_new(event)
File "/var/task/handler/trial.py", line 22, in trial_new
client = User.get(User.mobile == mobile)
File "/var/task/peewee.py", line 6384, in get
return sq.get()
File "/var/task/peewee.py", line 6807, in get
return clone.execute(database)[0]
File "/var/task/peewee.py", line 1886, in inner
return method(self, database, *args, **kwargs)
File "/var/task/peewee.py", line 1957, in execute
return self._execute(database)
File "/var/task/peewee.py", line 2129, in _execute
cursor = database.execute(self)
File "/var/task/playhouse/postgres_ext.py", line 490, in execute
cursor = self.execute_sql(sql, params, commit=commit)
File "/var/task/peewee.py", line 3106, in execute_sql
self.commit()
File "/var/task/peewee.py", line 2873, in __exit__
reraise(new_type, new_type(exc_value, *exc_args), traceback)
File "/var/task/peewee.py", line 183, in reraise
raise value.with_traceback(tb)
File "/var/task/peewee.py", line 3099, in execute_sql
cursor.execute(sql, params or ())
``` | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2204/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2204/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2203 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2203/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2203/comments | https://api.github.com/repos/coleifer/peewee/issues/2203/events | https://github.com/coleifer/peewee/issues/2203 | 638,199,563 | MDU6SXNzdWU2MzgxOTk1NjM= | 2,203 | How to scrape an img src url? | {
"login": "xdebbie",
"id": 57162213,
"node_id": "MDQ6VXNlcjU3MTYyMjEz",
"avatar_url": "https://avatars.githubusercontent.com/u/57162213?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/xdebbie",
"html_url": "https://github.com/xdebbie",
"followers_url": "https://api.github.com/users/xdebbie/followers",
"following_url": "https://api.github.com/users/xdebbie/following{/other_user}",
"gists_url": "https://api.github.com/users/xdebbie/gists{/gist_id}",
"starred_url": "https://api.github.com/users/xdebbie/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/xdebbie/subscriptions",
"organizations_url": "https://api.github.com/users/xdebbie/orgs",
"repos_url": "https://api.github.com/users/xdebbie/repos",
"events_url": "https://api.github.com/users/xdebbie/events{/privacy}",
"received_events_url": "https://api.github.com/users/xdebbie/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"This is a question about some scraping library you are using. peewee issue tracker is not for questions, much less questions about a completely unrelated and unidentified html library.\r\n"
] | 2020-06-13T17:25:50 | 2020-06-13T17:32:20 | 2020-06-13T17:32:19 | NONE | null | I'm using peewee to scrape a webpage, and everything is working fine except when I try to get the url of an "img src=" tag. Does anyone know what is the correct syntax to get the url?
My code goes like this:
```
# record label
label = resp.html.find('.labels-list__item')
if label:
data['label'] = label[0].text
# genre
genre = resp.html.find('.genre-list__link')
if genre:
data['genre'] = genre[0].text
# artwork
artwork = resp.html.find('.single-album-tombstone__art img')
if artwork:
data['artwork'] = artwork[0].text
```
The # record label and # genre tags work fine, but with the #artwork it returns an "EMPTY" tag on my database. This is the html:

How can I insert the attribute 'src' so it will return the actual url of the image?
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2203/reactions",
"total_count": 1,
"+1": 0,
"-1": 1,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2203/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2202 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2202/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2202/comments | https://api.github.com/repos/coleifer/peewee/issues/2202/events | https://github.com/coleifer/peewee/issues/2202 | 637,362,997 | MDU6SXNzdWU2MzczNjI5OTc= | 2,202 | model to dict extra_attrs | {
"login": "JPilarr",
"id": 45560120,
"node_id": "MDQ6VXNlcjQ1NTYwMTIw",
"avatar_url": "https://avatars.githubusercontent.com/u/45560120?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/JPilarr",
"html_url": "https://github.com/JPilarr",
"followers_url": "https://api.github.com/users/JPilarr/followers",
"following_url": "https://api.github.com/users/JPilarr/following{/other_user}",
"gists_url": "https://api.github.com/users/JPilarr/gists{/gist_id}",
"starred_url": "https://api.github.com/users/JPilarr/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/JPilarr/subscriptions",
"organizations_url": "https://api.github.com/users/JPilarr/orgs",
"repos_url": "https://api.github.com/users/JPilarr/repos",
"events_url": "https://api.github.com/users/JPilarr/events{/privacy}",
"received_events_url": "https://api.github.com/users/JPilarr/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I'm sorry but I don't understand the question, what these special field subclasses are, or really what the problem is."
] | 2020-06-11T22:39:15 | 2020-06-15T00:28:46 | 2020-06-15T00:28:46 | NONE | null | Hello,
i have model like.
```
class Printer(pw.Model, ch.Model):
# DB fields
id = pw.AutoField(primary_key=True)
name = pw.CharField()
# cache field stored in redis
state = ch.CharField(default=State.OFFLINE.name)
```
i have problem serialize redis part of model by model_to_dict. If i use exclude it work's but if i use only and after use something like result['state'] = self.state. it doesn't work with error `"TypeError: Object of type CharField is not JSON serializable"`
```
self.cache_get()
self.fix_state()
result = model_to_dict(self, only=[Printer.id, Printer.name,
Printer.location, Printer.state]
)
# from json import load
result['state'] = self.state
if self.printer_type_id:
result['printer_type_id'] = self.printer_type.id
return result
```
can you help me whats wrong? I dont' want use huge exclude. Is it way how to do it by extra_attrs parameter for model_to_dict. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2202/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2202/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2201 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2201/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2201/comments | https://api.github.com/repos/coleifer/peewee/issues/2201/events | https://github.com/coleifer/peewee/issues/2201 | 636,365,759 | MDU6SXNzdWU2MzYzNjU3NTk= | 2,201 | Should AsIs() set converter attribute to False? | {
"login": "theosotr",
"id": 6434138,
"node_id": "MDQ6VXNlcjY0MzQxMzg=",
"avatar_url": "https://avatars.githubusercontent.com/u/6434138?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/theosotr",
"html_url": "https://github.com/theosotr",
"followers_url": "https://api.github.com/users/theosotr/followers",
"following_url": "https://api.github.com/users/theosotr/following{/other_user}",
"gists_url": "https://api.github.com/users/theosotr/gists{/gist_id}",
"starred_url": "https://api.github.com/users/theosotr/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/theosotr/subscriptions",
"organizations_url": "https://api.github.com/users/theosotr/orgs",
"repos_url": "https://api.github.com/users/theosotr/repos",
"events_url": "https://api.github.com/users/theosotr/events{/privacy}",
"received_events_url": "https://api.github.com/users/theosotr/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"One may still want the option to apply converter logic, so converter is not explicitly disabled."
] | 2020-06-10T15:56:10 | 2020-06-10T16:59:45 | 2020-06-10T16:59:45 | NONE | null | According to the documentation of `AsIs`.
> Represents a Value that is treated as-is, and passed directly back to the database driver. This may be useful if you are using database extensions that accept native Python data-types and you do not wish Peewee to impose any handling of the values.
However, this is not true, as `peewee` impose handling of the value passed in `AsIs`on this line https://github.com/coleifer/peewee/blob/master/peewee.py#L622
Should `AsIs` initialize a `Value` object as following?
```python
def AsIs(value):
return Value(value, converter=False, unpack=False)
``` | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2201/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2201/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2200 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2200/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2200/comments | https://api.github.com/repos/coleifer/peewee/issues/2200/events | https://github.com/coleifer/peewee/issues/2200 | 635,272,169 | MDU6SXNzdWU2MzUyNzIxNjk= | 2,200 | sub-expressions not wrapped by parentheses | {
"login": "theosotr",
"id": 6434138,
"node_id": "MDQ6VXNlcjY0MzQxMzg=",
"avatar_url": "https://avatars.githubusercontent.com/u/6434138?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/theosotr",
"html_url": "https://github.com/theosotr",
"followers_url": "https://api.github.com/users/theosotr/followers",
"following_url": "https://api.github.com/users/theosotr/following{/other_user}",
"gists_url": "https://api.github.com/users/theosotr/gists{/gist_id}",
"starred_url": "https://api.github.com/users/theosotr/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/theosotr/subscriptions",
"organizations_url": "https://api.github.com/users/theosotr/orgs",
"repos_url": "https://api.github.com/users/theosotr/repos",
"events_url": "https://api.github.com/users/theosotr/events{/privacy}",
"received_events_url": "https://api.github.com/users/theosotr/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Thanks for reporting. This bug was caused by modifying an internal flag on the expression node without copying it first. This caused subsequent usages of that expression node to carry-over the flag when they shouldn't have."
] | 2020-06-09T09:33:53 | 2020-06-09T14:07:45 | 2020-06-09T14:07:06 | NONE | null | I have the following query (simplified for opening issue):
```python
expr = (Value(1) + Model.column)
squared = (expr * expr)
Model.select(fn.sum(expr), fn.avg(squared)).objects()
```
peewee generates the SQL query below
```sql
SELECT sum(1 + "t1"."column"), avg(1 + "t1"."column" * 1 + "t1"."column") FROM "model" AS "t1"
```
Notably, the sub-expressions in `avg(1 + "t1"."column" * 1 + "t1"."column")` are not wrapped by parentheses as expected. That is
```sql
SELECT sum(1 + "t1"."column"), avg((1 + "t1"."column") * (1 + "t1"."column")) FROM "model" AS "t1"
``` | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2200/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2200/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2199 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2199/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2199/comments | https://api.github.com/repos/coleifer/peewee/issues/2199/events | https://github.com/coleifer/peewee/issues/2199 | 635,062,582 | MDU6SXNzdWU2MzUwNjI1ODI= | 2,199 | Database.bind_ctx preserves the binded database | {
"login": "cslanziano",
"id": 36748119,
"node_id": "MDQ6VXNlcjM2NzQ4MTE5",
"avatar_url": "https://avatars.githubusercontent.com/u/36748119?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/cslanziano",
"html_url": "https://github.com/cslanziano",
"followers_url": "https://api.github.com/users/cslanziano/followers",
"following_url": "https://api.github.com/users/cslanziano/following{/other_user}",
"gists_url": "https://api.github.com/users/cslanziano/gists{/gist_id}",
"starred_url": "https://api.github.com/users/cslanziano/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/cslanziano/subscriptions",
"organizations_url": "https://api.github.com/users/cslanziano/orgs",
"repos_url": "https://api.github.com/users/cslanziano/repos",
"events_url": "https://api.github.com/users/cslanziano/events{/privacy}",
"received_events_url": "https://api.github.com/users/cslanziano/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Thanks for reporting. This is a bug and has to do with peewee performing redundant trips through the model graph."
] | 2020-06-09T02:35:09 | 2020-06-09T14:46:19 | 2020-06-09T14:46:19 | NONE | null | I am trying to set the database at run-time. Then the Models do not have the meta class defined. That means `Model._meta.database` is `None`. The first code below executes as I expected, after the `with` block the database parameter return to `None`.
```python
from peewee import SqliteDatabase, Model
class TableA(Model):
pass
class TableB(Model):
pass
db = SqliteDatabase(':memory:')
print('before', TableA._meta.database)
with db.bind_ctx([TableA, TableB]):
print('inside A', TableA._meta.database)
print('inside B', TableB._meta.database)
print('after', TableA._meta.database)
```
The issue is when a third table has foreign keys to both tables. The `Model._meta.database` is not returned to `None` as I was expecting.
```python
from peewee import SqliteDatabase, ForeignKeyField, Model
class TableA(Model):
pass
class TableB(Model):
pass
class TableAB(Model):
field1 = ForeignKeyField(TableA)
field2 = ForeignKeyField(TableB)
db = SqliteDatabase(':memory:')
print('before', TableA._meta.database)
with db.bind_ctx([TableA, TableB]):
print('inside A', TableA._meta.database)
print('after', TableA._meta.database)
```
The `bind_backrefs` set to `False` solves the issue. But, is this a bug? or is the normal behavior?. The version of peewee is `3.13.3`.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2199/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2199/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2198 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2198/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2198/comments | https://api.github.com/repos/coleifer/peewee/issues/2198/events | https://github.com/coleifer/peewee/issues/2198 | 633,598,069 | MDU6SXNzdWU2MzM1OTgwNjk= | 2,198 | Postgresql materialized views not showing | {
"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 | [
"First result on google my dude.\r\n\r\nhttps://stackoverflow.com/questions/58720894/check-a-materialized-view-exists",
"I know how to use the `pg_class` table, \"my dude\", I was asking if this can be do directly in Peewee using its API. I won't be opening any more issues trying to improve Peewee since there doesn't seem to be an interest for it."
] | 2020-06-07T17:26:40 | 2020-06-08T00:18:05 | 2020-06-07T21:10:04 | NONE | null | It seems Postgresql materialized views are not seen as a table or a view in Peewee. I have a model of a materialized view that works fine otherwise but `Model.table_exists()` returns `False`. If I try to find it in `database.get_tables()` or `database.get_views()` it does not appears anywhere. Is there a way to check if a materialized view model actually exists? | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2198/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2198/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2197 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2197/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2197/comments | https://api.github.com/repos/coleifer/peewee/issues/2197/events | https://github.com/coleifer/peewee/issues/2197 | 632,932,114 | MDU6SXNzdWU2MzI5MzIxMTQ= | 2,197 | BinaryUUIDFields do not seem to work with Mysql/pymysql | {
"login": "stevenj",
"id": 764829,
"node_id": "MDQ6VXNlcjc2NDgyOQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/764829?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/stevenj",
"html_url": "https://github.com/stevenj",
"followers_url": "https://api.github.com/users/stevenj/followers",
"following_url": "https://api.github.com/users/stevenj/following{/other_user}",
"gists_url": "https://api.github.com/users/stevenj/gists{/gist_id}",
"starred_url": "https://api.github.com/users/stevenj/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/stevenj/subscriptions",
"organizations_url": "https://api.github.com/users/stevenj/orgs",
"repos_url": "https://api.github.com/users/stevenj/repos",
"events_url": "https://api.github.com/users/stevenj/events{/privacy}",
"received_events_url": "https://api.github.com/users/stevenj/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"BinaryUUIDField is tested against all databases, including MySQL, and seems to work just fine.\r\n\r\nIf you can produce a failing test-case I will look into it some more.",
"https://github.com/coleifer/peewee/blob/master/tests/fields.py#L841-L897",
"I ran the tests, and the warning is generated by them. The fields however are generated so there must be something else wrong with my code. However, the warnings end up in my logs and fill up the logs unnecessarily. It seems with mysql, ALL binary fields should be prefaced with the \"introducer\" _binary\r\nlike so:\r\n\r\nreplace:\r\n\r\ncursor.execute(\"\"\"\r\n INSERT INTO `user` (uuid)\r\n VALUES (%s)\r\n\"\"\", my_uuid)\r\n\r\nwith\r\n\r\ncursor.execute(\"\"\"\r\n INSERT INTO `user` (uuid)\r\n VALUES (_binary %s)\r\n\"\"\", my_uuid)",
"I'd suggest taking it up with the pymysql devs.",
"There is a connection option \"binary_prefix=True\" i am experimenting to see if it fixes the issue. ",
"Ok, I can confirm if you pass \"binary_prefix=True\" to the init the spurious warning goes away.\r\nlike so:\r\n\r\n```\r\ndb = MySQLDatabase(None)\r\n\r\n...\r\n db.init(\r\n dbname,\r\n host=dburl,\r\n user=dbuser,\r\n password=dbpassword,\r\n charset=\"utf8mb4\",\r\n binary_prefix=True,\r\n )\r\n```\r\n\r\npymysql does not do it by default because some orms do it for themselves. Would suggest at the very least a comment in the docs relating to peewee and mysql, in much the same way charset is documented.",
"Since MySQL is raising warnings because of binary data being stored into a VARBINARY column, I really think this is a MySQL bug. I read their issue tracker and frankly it's a complete bullshit response. Prefixing with \"_binary\" is the workaround they suggest, or alternatively using a literal parameter prefixed with \"x\". Neither of these is palatable to me for inclusion in Peewee. I'd suggest that MySQL users just use the regular UUIDField instead, which stores the hex representation at the cost of a few more bytes of storage... Or switch to MariaDB, which doesn't seem to have this problem.",
"`charset` is not really documented per-se, but rather given as an example that you should consult your driver documentation. Not everyone who uses Peewee with MySQL will be using pymysql, so you're encouraged to read the docs for whichever db driver you're using.",
"Yeah, i agree its a bullshit response on the mysql side. Its not a true warning, its just pointless noise and they know it. I would use a different DB but i am limited by what the company chose. For my part, it works fine with the option, if anyone else has the issue i am sure they will find this thread in the issues and see the workaround. Sorry for saying the UUID didn't work. It clearly does. I must have had another issue and was being bamboozled by the crap warning. Its OT, but i am actually really liking peewee so, thankyou.\r\n\r\nTo be honest, these sorts of workarounds should be in the driver, again i don't know why its so difficult for pymysql to check binary fields and prefix them if they are not already prefixed. But cest la vie.",
"No worries at all, I understand the confusion. I am surprised I hadn't seen this come up until now, but I'm glad the driver at least provides some measure of workaround."
] | 2020-06-07T02:18:51 | 2020-06-09T14:08:41 | 2020-06-07T16:06:00 | NONE | null | I am using Mysql8 and pymysql.
I have a field defined thus:
```
class Adapter(BaseModel):
id = BinaryUUIDField(primary_key=True)
class Meta:
"""Metadata."""
table_name = "adapter"
```
the matching sql is:
```
CREATE TABLE `adapter` (
`id` VARBINARY(16) NOT NULL ,
PRIMARY KEY (`id`)
) ENGINE=INNODB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci ;
```
When trying to create records I get:
```
... lib/python3.8/site-packages/pymysql/cursors.py:170: Warning: (1300, "Invalid utf8mb4 character string: 'C65E72'")
result = self._query(query)
```
The `C65E72` is part of the UUID in Hex.
The record does not get created, so its fatal to the create, not just a warning. The bigger issue is, when this happens the create returns with a new object indicating the create succeeded. But there is actually no record in the database. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2197/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2197/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2196 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2196/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2196/comments | https://api.github.com/repos/coleifer/peewee/issues/2196/events | https://github.com/coleifer/peewee/issues/2196 | 631,530,360 | MDU6SXNzdWU2MzE1MzAzNjA= | 2,196 | An empty query result if JOIN.CROSS is combined with JOIN.INNER. At the same time, raw() worked properly | {
"login": "navolotsky",
"id": 43314216,
"node_id": "MDQ6VXNlcjQzMzE0MjE2",
"avatar_url": "https://avatars.githubusercontent.com/u/43314216?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/navolotsky",
"html_url": "https://github.com/navolotsky",
"followers_url": "https://api.github.com/users/navolotsky/followers",
"following_url": "https://api.github.com/users/navolotsky/following{/other_user}",
"gists_url": "https://api.github.com/users/navolotsky/gists{/gist_id}",
"starred_url": "https://api.github.com/users/navolotsky/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/navolotsky/subscriptions",
"organizations_url": "https://api.github.com/users/navolotsky/orgs",
"repos_url": "https://api.github.com/users/navolotsky/repos",
"events_url": "https://api.github.com/users/navolotsky/events{/privacy}",
"received_events_url": "https://api.github.com/users/navolotsky/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Try using `.objects()` instead at the end of your \"non-raw\" query, which will skip the model-join graph reconstruction step. You don't need it as you're only selecting from one table and it seems to be the issue.",
"I'm having a bit of trouble parsing-out exactly what your query is designed to accomplish. There's a bit of unnecessary cruft in there (filegroup, e.g.). Can you make a smaller, more semantic example so I can get a better handle on what you're trying to accomplish?",
"> Try using .objects()\r\n\r\nIt works.\r\n\r\n> Can you make a smaller\r\n\r\nI will try do it. This is a visualization diagram. Code will go below.\r\n\r\n\r\n\r\nI renamed FileGroup to Storage.\r\n\r\nOne Storage is related with many files (by storing Storage id in File relation) and several Folders (also Folder related with Storage by id).\r\n\r\nOne Folder is related to one Storage.\r\n\r\nOne File is related with one Storage and one Folder.\r\n\r\nOne Folder is related to many Files but File do not explicitly bound with Folder by id. Instead, File and Folder are implicitly bound through:\r\n\r\n```sql\r\nfile.storage = folder.storage AND\r\nfile.filename_info = filebasename.id AND\r\nCAST(filebasename.type AS TEXT) = CAST(folder.type AS TEXT)\r\n```\r\n\r\nThere is a way to avoid this strange things by defining foreign key references folder.id.\r\n\r\nAlso to rewrite the query as it will follow below.\r\n\r\nI don't like the first way because this implicit bind is uniquely specified so you don't need to have an additional field in the large File table.\r\n\r\nI don't like folder_another_way() and folder_another_way_2() because they do not show that this bind is implicit.\r\n\r\n```python\r\nimport logging\r\nimport traceback\r\n\r\nfrom peewee import JOIN, CharField, ForeignKeyField, Model, SqliteDatabase\r\n\r\ndatabase = SqliteDatabase(\":memory:\")\r\n\r\n\r\nclass BaseModel(Model):\r\n class Meta:\r\n database = database\r\n\r\n\r\nclass Storage(BaseModel):\r\n name = CharField()\r\n\r\n\r\nclass Folder(BaseModel):\r\n storage = ForeignKeyField(model=Storage)\r\n type = CharField() # Enum in DB\r\n\r\n\r\nclass FileBasename(BaseModel):\r\n string = CharField()\r\n type = CharField() # Enum in DB with the same values as in Folder.type\r\n\r\n\r\nclass File(BaseModel):\r\n storage = ForeignKeyField(model=Storage)\r\n filename_info = ForeignKeyField(model=FileBasename, backref='files')\r\n\r\n def folder(self):\r\n query = (\r\n Folder.select()\r\n .join(File, join_type=JOIN.CROSS)\r\n .join_from(File, FileBasename)\r\n .where(\r\n self._pk_expr() &\r\n (File.storage == Folder.storage) &\r\n (FileBasename.type.cast('TEXT') == Folder.type.cast('TEXT'))\r\n )\r\n )\r\n result = query.execute()\r\n return result[0] if result else None\r\n\r\n def folder_raw(self):\r\n query = (\r\n Folder.select()\r\n .join(File, join_type=JOIN.CROSS)\r\n .join_from(File, FileBasename)\r\n .where(\r\n self._pk_expr() &\r\n (File.storage == Folder.storage) &\r\n (FileBasename.type.cast('TEXT') == Folder.type.cast('TEXT'))\r\n )\r\n )\r\n sql, params = query.sql()\r\n result = Folder.raw(sql, *params).execute()\r\n return result[0] if result else None\r\n\r\n def folder_another_way(self):\r\n query = (\r\n Folder.select()\r\n .join(File, on=(File.storage == Folder.storage))\r\n .join_from(File, FileBasename)\r\n .where(\r\n self._pk_expr() &\r\n (FileBasename.type.cast('TEXT') == Folder.type.cast('TEXT'))\r\n )\r\n )\r\n result = query.execute()\r\n return result[0] if result else None\r\n\r\n def folder_another_way_2(self):\r\n query = (\r\n Folder.select()\r\n .join(Storage)\r\n .join(File)\r\n .join(FileBasename)\r\n .where(\r\n self._pk_expr() &\r\n (FileBasename.type.cast('TEXT') == Folder.type.cast('TEXT'))\r\n )\r\n )\r\n result = query.execute()\r\n return result[0] if result else None\r\n\r\n\r\nif __name__ == \"__main__\":\r\n database.create_tables(\r\n models=[Storage, FileBasename, File, Folder])\r\n with database.atomic():\r\n storage = Storage.create(name=\"first storage\")\r\n Folder.create(type=\"first type\", storage=storage)\r\n filename_info = FileBasename.create(\r\n type=\"first type\", string=\"base part of some name\")\r\n File.create(storage=storage, filename_info=filename_info)\r\n\r\n file = File.get_by_id(1)\r\n\r\n logger = logging.getLogger('peewee')\r\n logger.addHandler(logging.StreamHandler())\r\n logger.setLevel(logging.DEBUG)\r\n\r\n try:\r\n print(\"This won't be printed:\", repr(file.folder()))\r\n except Exception:\r\n traceback.print_exc()\r\n\r\n print(\"Let's try with raw():\", repr(file.folder_raw()))\r\n print(\"And now another way:\", repr(file.folder_another_way()))\r\n print(\"Another way #2:\", repr(file.folder_another_way_2()))\r\n\r\n```\r\n",
"This is more or less the way I would have expected the query to be written:\r\n\r\n```python\r\n def folder_another_way(self):\r\n query = (\r\n Folder.select()\r\n .join(File, on=(File.storage == Folder.storage))\r\n .join_from(File, FileBasename)\r\n .where(\r\n self._pk_expr() &\r\n (FileBasename.type.cast('TEXT') == Folder.type.cast('TEXT'))\r\n )\r\n )\r\n result = query.execute()\r\n return result[0] if result else None\r\n```"
] | 2020-06-05T11:46:53 | 2020-06-08T16:18:41 | 2020-06-05T20:44:44 | NONE | null | ```python
import logging
import traceback
from peewee import JOIN, CharField, ForeignKeyField, Model, SqliteDatabase
database = SqliteDatabase(":memory:")
class BaseModel(Model):
class Meta:
database = database
class FileGroup(BaseModel):
descr = CharField()
class FileBasename(BaseModel):
string = CharField()
type = CharField()
class BaseFile(BaseModel):
name_end_part = CharField()
class FileFolder(BaseModel):
group = ForeignKeyField(model=FileGroup, backref='folders')
name = CharField()
type = CharField()
class File(BaseModel):
group = ForeignKeyField(model=FileGroup, backref='files')
filename_info = ForeignKeyField(model=FileBasename, backref='files')
base_file = ForeignKeyField(model=BaseFile, backref='derived_files')
@property
def filename(self):
return (self.filename_info.string +
self.base_file.name_end_part)
def folder(self):
query = (
FileFolder.select()
.join(File, join_type=JOIN.CROSS)
.join_from(File, FileBasename)
.where(
self._pk_expr() &
(File.group == FileFolder.group) &
(FileBasename.type.cast('TEXT') == FileFolder.type.cast('TEXT'))
)
)
result = query.execute()
return result[0] if result else None
def folder_raw(self):
query = (
FileFolder.select()
.join(File, join_type=JOIN.CROSS)
.join_from(File, FileBasename)
.where(
self._pk_expr() &
(File.group == FileFolder.group) &
(FileBasename.type.cast('TEXT') == FileFolder.type.cast('TEXT'))
)
)
sql, params = query.sql()
result = FileFolder.raw(sql, *params).execute()
return result[0] if result else None
if __name__ == "__main__":
database.create_tables(
models=[FileGroup, FileBasename, BaseFile, File, FileFolder])
with database.atomic():
FileGroup.create(descr="first group")
FileFolder.create(group=1, name="first folder", type="first type")
FileBasename.create(string="some_file_name", type="first type")
BaseFile.create(name_end_part=".end")
File.create(group=1, filename_info=1, base_file=1)
file = File.get_by_id(1)
logger = logging.getLogger('peewee')
logger.addHandler(logging.StreamHandler())
logger.setLevel(logging.DEBUG)
try:
print("This won't be printed:", repr(file.folder()))
except Exception:
traceback.print_exc()
print("Let's try with raw():", repr(file.folder_raw()))
```
Run result:
```
(.venv_3.8.3-64) C:\Projects\Python>python peewee_cross_join.py
('SELECT "t1"."id", "t1"."group_id", "t1"."name", "t1"."type" FROM "filefolder" AS "t1" CROSS JOIN "file" AS "t2" INNER JOIN "filebasename" AS "t3" ON ("t2"."filename_info_id" = "t3"."id") WHERE ((("t2"."id" = ?) AND ("t2"."group_id" = "t1"."group_id")) AND (CAST("t3"."type" AS TEXT) = CAST("t1"."type" AS TEXT)))', [1])
Traceback (most recent call last):
File "peewee_cross_join.py", line 90, in <module>
print("This won't be printed:", repr(file.folder()))
File "peewee_cross_join.py", line 55, in folder
return result[0] if result else None
File "C:\Projects\Python\.venv_3.8.3-64\lib\site-packages\peewee.py", line 4232, in __len__
self.fill_cache()
File "C:\Projects\Python\.venv_3.8.3-64\lib\site-packages\peewee.py", line 4273, in fill_cache
iterator.next()
File "C:\Projects\Python\.venv_3.8.3-64\lib\site-packages\peewee.py", line 4329, in next
self.cursor_wrapper.iterate()
File "C:\Projects\Python\.venv_3.8.3-64\lib\site-packages\peewee.py", line 4248, in iterate
result = self.process_row(row)
File "C:\Projects\Python\.venv_3.8.3-64\lib\site-packages\peewee.py", line 7502, in process_row
instance = objects[src]
KeyError: <Model: File>
('SELECT "t1"."id", "t1"."group_id", "t1"."name", "t1"."type" FROM "filefolder" AS "t1" CROSS JOIN "file" AS "t2" INNER JOIN "filebasename" AS "t3" ON ("t2"."filename_info_id" = "t3"."id") WHERE ((("t2"."id" = ?) AND ("t2"."group_id" = "t1"."group_id")) AND (CAST("t3"."type" AS TEXT) = CAST("t1"."type" AS TEXT)))', [1])
Let's try with raw(): <FileFolder: 1>
(.venv_3.8.3-64) C:\Projects\Python>
``` | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2196/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2196/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2195 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2195/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2195/comments | https://api.github.com/repos/coleifer/peewee/issues/2195/events | https://github.com/coleifer/peewee/issues/2195 | 631,282,269 | MDU6SXNzdWU2MzEyODIyNjk= | 2,195 | SUM subquery | {
"login": "Feijo",
"id": 1585710,
"node_id": "MDQ6VXNlcjE1ODU3MTA=",
"avatar_url": "https://avatars.githubusercontent.com/u/1585710?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/Feijo",
"html_url": "https://github.com/Feijo",
"followers_url": "https://api.github.com/users/Feijo/followers",
"following_url": "https://api.github.com/users/Feijo/following{/other_user}",
"gists_url": "https://api.github.com/users/Feijo/gists{/gist_id}",
"starred_url": "https://api.github.com/users/Feijo/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/Feijo/subscriptions",
"organizations_url": "https://api.github.com/users/Feijo/orgs",
"repos_url": "https://api.github.com/users/Feijo/repos",
"events_url": "https://api.github.com/users/Feijo/events{/privacy}",
"received_events_url": "https://api.github.com/users/Feijo/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"```python\r\n\r\nsubq = (MyEntity\r\n .select(MyEntity.value_1)\r\n .where((MyEntity.ClientId == i) | (MyEntity.date == z)))\r\n .alias('subquery'))\r\nMyEntity.select(fn.MAX(subq.c.value_1)).from_(subq)\r\n```"
] | 2020-06-05T03:24:17 | 2020-06-05T16:50:58 | 2020-06-05T16:50:58 | NONE | null | I am working on a formula-based application, which each function contructs a piece of the SQL query that will be executed. In other words, each function is a formula, which can call other formulas.
For example:
```
class Formulas():
def formula_piece_1(self, i, z):
return (MyEntity.select(MyEntity.value_1).where((MyEntity.ClientId == i) | (MyEntity.date == z))).alias('subquery')
def formula_piece_2(self, i, j):
return MyEntity.select(fn.MAX(self.formula_piece_1(i, j).select(MyEntity.value_1)))
# I'd have thousands of functions like these, that could be combined in any order.
f = Formulas()
result = f.formula_piece_2(12, date(2016, 1, 1))
```
This is the query I was expecting:
```
SELECT MAX (subquery.value_1)
FROM (
SELECT "t1"."value_1"
FROM "my_entity" AS "t1"
WHERE (("t1"."client_id" = 12) OR ("t1"."date" = '2016-01-01'))
) subquery
```
Instead I got this:
```
SELECT MAX
(
SELECT "t1"."value_1"
FROM "my_entity" AS "t1"
WHERE (("t1"."client_id" = 12) OR
("t1"."date" = '2016-01-01'))
)
FROM "my_entity" AS "t1"
```
What would be the correct way of doing it? | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2195/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2195/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2194 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2194/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2194/comments | https://api.github.com/repos/coleifer/peewee/issues/2194/events | https://github.com/coleifer/peewee/issues/2194 | 628,997,829 | MDU6SXNzdWU2Mjg5OTc4Mjk= | 2,194 | Regarding aliased columns of relationships | {
"login": "theosotr",
"id": 6434138,
"node_id": "MDQ6VXNlcjY0MzQxMzg=",
"avatar_url": "https://avatars.githubusercontent.com/u/6434138?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/theosotr",
"html_url": "https://github.com/theosotr",
"followers_url": "https://api.github.com/users/theosotr/followers",
"following_url": "https://api.github.com/users/theosotr/following{/other_user}",
"gists_url": "https://api.github.com/users/theosotr/gists{/gist_id}",
"starred_url": "https://api.github.com/users/theosotr/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/theosotr/subscriptions",
"organizations_url": "https://api.github.com/users/theosotr/orgs",
"repos_url": "https://api.github.com/users/theosotr/repos",
"events_url": "https://api.github.com/users/theosotr/events{/privacy}",
"received_events_url": "https://api.github.com/users/theosotr/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Peewee puts stuff on the model it belongs to. You're just aliasing the author's first-name, so peewee puts that on the author model. When you have an expression where it is unclear what model it belongs to, then it gets placed on the root/selected model.\r\n\r\nIf you don't want to be dealing with a graph of models, just use `.objects()` at the end of your query and *all* attributes will be placed on the root/selected model."
] | 2020-06-02T08:14:50 | 2020-06-02T16:19:20 | 2020-06-02T16:19:19 | NONE | null | I have the following models
```python
class Author(BaseModel):
first_name = CharField()
surname = CharField()
class Meta:
table_name = 'author'
class Book(BaseModel):
author = ForeignKeyField(column_name='author_id', field='id', model=Author)
isbn = CharField(null=True, unique=True)
title = CharField()
class Meta:
table_name = 'book'
class Review(BaseModel):
book = ForeignKeyField(column_name='book_id', field='id', model=Book)
content = CharField(null=True)
rating = IntegerField(null=True)
reviewer_name = CharField(null=True)
class Meta:
table_name = 'review'
```
And I perform the following query
```python
name = Review.book.author.first_name.alias('name')
res = Review.select(name).join(Book).join(Author).where(
(Review.rating >= 2) & (Author.first_name <= Value('Z')))
for r in res:
print(r.name)
```
this gives me the following error
```
Traceback (most recent call last):
File "test.py", line 10, in <module>
print(r.name)
AttributeError: 'Review' object has no attribute 'name'
```
To make the code above to work, I have to print `r.book.author.name`.
When I create compound aliased column (e.g., (`Review.book.author.first_name + Review.book.title).alias('name')`), the result set *does* contain the property `name` as expected.
For example, this query works
```python
name = (Review.book.author.first_name + Review.book.title).alias('name')
res = Review.select(name).join(Book).join(Author).where(
(Review.rating >= 2) & (Author.first_name <= Value('Z')))
for r in res:
print(r.name)
```
I don't know if this is a feature or bug, but I find it counter-intuitive. I would expect peewee to store all aliased columns to the object of the result set, i.e., I would like to make an alias on the namespace of the final result set. Am I missing something here? | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2194/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2194/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2193 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2193/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2193/comments | https://api.github.com/repos/coleifer/peewee/issues/2193/events | https://github.com/coleifer/peewee/issues/2193 | 628,993,043 | MDU6SXNzdWU2Mjg5OTMwNDM= | 2,193 | How to define computed fields? | {
"login": "bravegag",
"id": 4385408,
"node_id": "MDQ6VXNlcjQzODU0MDg=",
"avatar_url": "https://avatars.githubusercontent.com/u/4385408?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/bravegag",
"html_url": "https://github.com/bravegag",
"followers_url": "https://api.github.com/users/bravegag/followers",
"following_url": "https://api.github.com/users/bravegag/following{/other_user}",
"gists_url": "https://api.github.com/users/bravegag/gists{/gist_id}",
"starred_url": "https://api.github.com/users/bravegag/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/bravegag/subscriptions",
"organizations_url": "https://api.github.com/users/bravegag/orgs",
"repos_url": "https://api.github.com/users/bravegag/repos",
"events_url": "https://api.github.com/users/bravegag/events{/privacy}",
"received_events_url": "https://api.github.com/users/bravegag/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2020-06-02T08:07:13 | 2020-06-02T16:16:28 | 2020-06-02T16:16:28 | NONE | null | Can anyone please help with this?
https://stackoverflow.com/questions/62147440/how-to-define-computed-fields-in-peewee | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2193/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2193/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2192 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2192/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2192/comments | https://api.github.com/repos/coleifer/peewee/issues/2192/events | https://github.com/coleifer/peewee/issues/2192 | 628,428,843 | MDU6SXNzdWU2Mjg0Mjg4NDM= | 2,192 | According to the MySQL worklog, VALUES function will be deprecated soon | {
"login": "ShuFFel",
"id": 21026699,
"node_id": "MDQ6VXNlcjIxMDI2Njk5",
"avatar_url": "https://avatars.githubusercontent.com/u/21026699?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/ShuFFel",
"html_url": "https://github.com/ShuFFel",
"followers_url": "https://api.github.com/users/ShuFFel/followers",
"following_url": "https://api.github.com/users/ShuFFel/following{/other_user}",
"gists_url": "https://api.github.com/users/ShuFFel/gists{/gist_id}",
"starred_url": "https://api.github.com/users/ShuFFel/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/ShuFFel/subscriptions",
"organizations_url": "https://api.github.com/users/ShuFFel/orgs",
"repos_url": "https://api.github.com/users/ShuFFel/repos",
"events_url": "https://api.github.com/users/ShuFFel/events{/privacy}",
"received_events_url": "https://api.github.com/users/ShuFFel/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Thanks for the heads-up. I wonder how they intend to reference the selected column. Anyways we'll cross that bridge when we get there."
] | 2020-06-01T13:14:00 | 2020-06-01T14:22:14 | 2020-06-01T14:22:14 | NONE | null | Found task in MySQL worklog: [https://dev.mysql.com/worklog/task/?id=13325]
Right now it's just a warning about deprecation, but seems that this function will be removed in future | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2192/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2192/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2191 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2191/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2191/comments | https://api.github.com/repos/coleifer/peewee/issues/2191/events | https://github.com/coleifer/peewee/pull/2191 | 625,765,606 | MDExOlB1bGxSZXF1ZXN0NDIzOTA3OTY3 | 2,191 | fix analytics example | {
"login": "phanirithvij",
"id": 29627898,
"node_id": "MDQ6VXNlcjI5NjI3ODk4",
"avatar_url": "https://avatars.githubusercontent.com/u/29627898?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/phanirithvij",
"html_url": "https://github.com/phanirithvij",
"followers_url": "https://api.github.com/users/phanirithvij/followers",
"following_url": "https://api.github.com/users/phanirithvij/following{/other_user}",
"gists_url": "https://api.github.com/users/phanirithvij/gists{/gist_id}",
"starred_url": "https://api.github.com/users/phanirithvij/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/phanirithvij/subscriptions",
"organizations_url": "https://api.github.com/users/phanirithvij/orgs",
"repos_url": "https://api.github.com/users/phanirithvij/repos",
"events_url": "https://api.github.com/users/phanirithvij/events{/privacy}",
"received_events_url": "https://api.github.com/users/phanirithvij/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2020-05-27T14:50:37 | 2020-05-27T15:12:55 | 2020-05-27T15:12:54 | CONTRIBUTOR | null | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2191/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2191/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/2191",
"html_url": "https://github.com/coleifer/peewee/pull/2191",
"diff_url": "https://github.com/coleifer/peewee/pull/2191.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/2191.patch",
"merged_at": "2020-05-27T15:12:54"
} |
|
https://api.github.com/repos/coleifer/peewee/issues/2190 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2190/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2190/comments | https://api.github.com/repos/coleifer/peewee/issues/2190/events | https://github.com/coleifer/peewee/pull/2190 | 625,736,133 | MDExOlB1bGxSZXF1ZXN0NDIzODgzOTI2 | 2,190 | fix diary example | {
"login": "phanirithvij",
"id": 29627898,
"node_id": "MDQ6VXNlcjI5NjI3ODk4",
"avatar_url": "https://avatars.githubusercontent.com/u/29627898?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/phanirithvij",
"html_url": "https://github.com/phanirithvij",
"followers_url": "https://api.github.com/users/phanirithvij/followers",
"following_url": "https://api.github.com/users/phanirithvij/following{/other_user}",
"gists_url": "https://api.github.com/users/phanirithvij/gists{/gist_id}",
"starred_url": "https://api.github.com/users/phanirithvij/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/phanirithvij/subscriptions",
"organizations_url": "https://api.github.com/users/phanirithvij/orgs",
"repos_url": "https://api.github.com/users/phanirithvij/repos",
"events_url": "https://api.github.com/users/phanirithvij/events{/privacy}",
"received_events_url": "https://api.github.com/users/phanirithvij/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"wow that was fast.",
"@coleifer The build failed for some reason might want to revert?",
"https://travis-ci.org/github/coleifer/peewee/builds/691771699"
] | 2020-05-27T14:18:13 | 2020-05-27T14:38:44 | 2020-05-27T14:21:26 | CONTRIBUTOR | null | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2190/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2190/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/2190",
"html_url": "https://github.com/coleifer/peewee/pull/2190",
"diff_url": "https://github.com/coleifer/peewee/pull/2190.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/2190.patch",
"merged_at": "2020-05-27T14:21:26"
} |
|
https://api.github.com/repos/coleifer/peewee/issues/2189 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2189/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2189/comments | https://api.github.com/repos/coleifer/peewee/issues/2189/events | https://github.com/coleifer/peewee/issues/2189 | 624,032,131 | MDU6SXNzdWU2MjQwMzIxMzE= | 2,189 | any plan to support async/await | {
"login": "DieterLi",
"id": 9697015,
"node_id": "MDQ6VXNlcjk2OTcwMTU=",
"avatar_url": "https://avatars.githubusercontent.com/u/9697015?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/DieterLi",
"html_url": "https://github.com/DieterLi",
"followers_url": "https://api.github.com/users/DieterLi/followers",
"following_url": "https://api.github.com/users/DieterLi/following{/other_user}",
"gists_url": "https://api.github.com/users/DieterLi/gists{/gist_id}",
"starred_url": "https://api.github.com/users/DieterLi/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/DieterLi/subscriptions",
"organizations_url": "https://api.github.com/users/DieterLi/orgs",
"repos_url": "https://api.github.com/users/DieterLi/repos",
"events_url": "https://api.github.com/users/DieterLi/events{/privacy}",
"received_events_url": "https://api.github.com/users/DieterLi/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Discussed and dismissed many times, notably #263. There are so many things I dislike about the ~twisted~ asyncio approach, mostly the fact that you have to write \"asyncio\"-specific everything -- drivers, ORMs, application frameworks, etc., etc. and even then you still have a \"[what color is my function](https://journal.stuffwithstuff.com/2015/02/01/what-color-is-your-function/)\" situation.\r\n\r\nUse gevent. Seriously. You can thank me later.",
"A commenter suggested [tortoise orm](https://tortoise-orm.readthedocs.io/en/latest/) - I cannot vouch for it, but wanted to preserve the recommendation for anyone who arrives here via google.",
"@coleifer it's very sad that you ignore the `async/await` syntax. A lot of people/products use it these days and it's not only about `asyncio`. I know about the tortoise ORM, but I prefer Peewee syntax.\r\n\r\nMaybe we have a chance to split the Peewee ORM and make a code that working with DB connections independently. So there will be drivers independent Peewee part which one only is responsible for the conversation Models <-> SQL and another part that implement database connection management. That way people could be available to use Peewee with any sync/async drivers.",
"@klen - I wouldn't say that I ignore it, but I do not like the approach (for a number of reasons) and prefer the gevent approach for Python. The main reason I dislike it is because it requires a special \"asyncio-aware\" version of every piece of software in the stack.\r\n\r\nThis project exists, which might prove useful for people finding this issue in the future:\r\n\r\nhttps://github.com/05bit/peewee-async",
"As an alternative, there is another library: https://github.com/klen/peewee-aio"
] | 2020-05-25T04:10:46 | 2021-09-09T08:24:44 | 2020-05-26T00:57:43 | NONE | null | as the title. Thanks, team | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2189/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2189/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2188 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2188/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2188/comments | https://api.github.com/repos/coleifer/peewee/issues/2188/events | https://github.com/coleifer/peewee/issues/2188 | 623,649,933 | MDU6SXNzdWU2MjM2NDk5MzM= | 2,188 | Request: make table_function to be evaluated during first time Model being instantiated. | {
"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 | [
"Yes, we evaluate it at class-creation time. I'm going to pass on the solutions proposed, as they seem rather specific to whatever you're doing."
] | 2020-05-23T12:27:01 | 2020-05-24T01:44:18 | 2020-05-24T01:44:18 | NONE | null | Rationale
---------
Currently, `table_function` is evaluated as soon as a `Model` class is defined.
However, just like`peewee.DatabaseProxy()`, sometimes table prefix is also not known until the config file is parsed.
Current Workaround
--------------------
I carefully checked imports to make sure no database models are loaded until config file is parsed. But it is kind of difficult to keep track of files as the code base grows. And this separates the program into two separate parts `config` and `main[web handlers, database_models]` which is less than ideal.
Potential Solutions
-------------------
1. make `table_function` to be evaluated during first time `Model` being instantiated.
2. let `Database` carry a `prefix` attribute and peewee read it every time it tries to generate a SQL statement.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2188/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2188/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2187 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2187/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2187/comments | https://api.github.com/repos/coleifer/peewee/issues/2187/events | https://github.com/coleifer/peewee/issues/2187 | 622,067,095 | MDU6SXNzdWU2MjIwNjcwOTU= | 2,187 | A little typo makes using select with several models impossible in seldom cases | {
"login": "navolotsky",
"id": 43314216,
"node_id": "MDQ6VXNlcjQzMzE0MjE2",
"avatar_url": "https://avatars.githubusercontent.com/u/43314216?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/navolotsky",
"html_url": "https://github.com/navolotsky",
"followers_url": "https://api.github.com/users/navolotsky/followers",
"following_url": "https://api.github.com/users/navolotsky/following{/other_user}",
"gists_url": "https://api.github.com/users/navolotsky/gists{/gist_id}",
"starred_url": "https://api.github.com/users/navolotsky/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/navolotsky/subscriptions",
"organizations_url": "https://api.github.com/users/navolotsky/orgs",
"repos_url": "https://api.github.com/users/navolotsky/repos",
"events_url": "https://api.github.com/users/navolotsky/events{/privacy}",
"received_events_url": "https://api.github.com/users/navolotsky/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
">The following code is just an example. It will not throw an exception.\r\n\r\nIf you can produce code that reliably causes problems, I will be happy to investigate... Did you hand-write that traceback, though? I'm confused because you have said that the code does *not* produce an error, but then you have pasted what looks like an error from such code.",
"I am sorry for confusing you. This is the real traceback from my project, I just replaced class names. I wanted to give a clear example because I cannot copy here all of my models.\r\n\r\nAnyway, I found that makes model unhashable. I defined custom `__eq__` without `__hash__`.\r\nNow this code will produce an error.\r\n```python\r\nimport traceback\r\n\r\nfrom peewee import (CharField, ForeignKeyField, Model,\r\n SqliteDatabase)\r\n\r\ndatabase = SqliteDatabase(\":memory:\")\r\n\r\nclass BaseModel(Model):\r\n class Meta:\r\n database = database\r\n def __eq__(self, other):\r\n return super().__eq__(other)\r\n # def __hash__(self):\r\n # \"\"\"If it isn't defined, when __eq__ is defined, object is unhashable\r\n # https://stackoverflow.com/questions/1608842/types-that-define-eq-are-unhashable\"\"\"\r\n # return super().__hash__()\r\n\r\nclass A(BaseModel):\r\n some_str = CharField()\r\n\r\nclass B(BaseModel):\r\n another_str = CharField()\r\n a = ForeignKeyField(model=A)\r\n\r\nif __name__ == \"__main__\":\r\n database.create_tables(models=[A, B])\r\n a = A.create(some_str='s1')\r\n b = B.create(another_str=f's2', a=a)\r\n try:\r\n for b in B.select(B, A).join(A):\r\n print(b)\r\n except:\r\n traceback.print_exc()\r\n```\r\n<details>\r\n<summary>Screenshot</summary>\r\n\r\n</details>",
"Why are you implementing a custom `__eq__()` on a peewee model class? The peewee model class already implements a correct equals (and hash). I suggest you refer to the peewee source code and review the implementations there. This is a Python thing -- you'll need to also implement a hash method if you are overriding equals -- but I'd strongly suggest you just use the default implementations in peewee.",
"> Why are you implementing a custom `__eq__()` on a peewee model class?\r\n\r\nMy code logic with kludges needs this. I check if an instance updated in a DB excluding some fields from a `list` defined in model classes.\r\n\r\nAt the same time, I try to write efficient queries, because I know a little SQL. These I like `peewee` that it is flexible and similar to SQL.\r\n\r\n> This is a Python thing -- you'll need to also implement a hash method if you are overriding equals\r\n\r\nI already understood this as I wrote above.\r\n\r\n> I'd strongly suggest you just use the default implementations \r\n\r\nI will follow your advice and will rename custom `__eq__()` to something like `equal_to()` then it will not affect on the `peewee` default implementation.\r\n\r\n> I suggest you refer to the peewee source code and review the implementations there.\r\n\r\nI read and tried to understand `ModelCursorWrapper.process_row()`. Please take five minutes to look into it. \r\nhttps://github.com/coleifer/peewee/blob/d6318dce0e5149a61511521a7dcb96600bec9b25/peewee.py#L7519-L7523\r\nThis condition in the `if` will never be `True`. `instance` cannot contains in `set_keys` due to the `set_keys` stores model classes and `instance` is a model instance. It looks like `src` must be instead of `instance` there.\r\n\r\nIf you will have time, I am also interesting in cases covered by this `if` because I could not imagine them when I was trying to find cases that would be affected by this typo. Thanks a lot!\r\n",
"The condition is to avoid populating non-selected intermediary models.",
"> This condition in the if will never be True. \r\n\r\nSorry, I made a typo. I mean that the \"`instance not in set_keys`\" part of the `if` condition will never be `False`. The full condition can be both `True` or `False` of course.\r\n",
"I suggest you try removing the clause and running the tests, if you're curious."
] | 2020-05-20T20:34:26 | 2020-05-22T11:50:01 | 2020-05-20T21:43:00 | NONE | null | It looks like `instance` must be `src` because `set_keys` is a `dict` that contains models.
https://github.com/coleifer/peewee/blob/d6318dce0e5149a61511521a7dcb96600bec9b25/peewee.py#L7521
If we do `select` with several models (`B` and `A`) and `B` is unhashable, we will get an exception.
The following code is just an example. It will not throw an exception.
```python
import traceback
from peewee import CharField, ForeignKeyField, Model, PostgresqlDatabase
db_conn_params = {
"dbname": "peewee_fail_test",
"user": "postgres",
"password": "***",
"host": "localhost",
"port": "5433"
}
database = PostgresqlDatabase(
db_conn_params.pop('dbname'), **db_conn_params)
class BaseModel(Model):
class Meta:
database = database
class A(BaseModel):
some_str = CharField()
class B(BaseModel):
another_str = CharField()
a = ForeignKeyField(model=A)
if __name__ == "__main__":
database.create_tables(models=[A, B])
for i in range(10):
a = A.create(some_str='s{i}')
b = B.create(another_str=f'as1_{i}', another_str2=f'as2_{i}', a=a)
try:
for b in B.select(B, A).join(A):
pass
except:
traceback.print_exc()
```
```
Traceback (most recent call last):
File "c:\Projects\Python\project\peewee_models.py", line 1314, in <module>
for b in B.select(B, A).join(A):
File "c:\Projects\Python\project\.venv_3.8.2-64\lib\site-packages\peewee.py", line 4329, in next
self.cursor_wrapper.iterate()
File "c:\Projects\Python\project\.venv_3.8.2-64\lib\site-packages\peewee.py", line 4248, in iterate
result = self.process_row(row)
File "c:\Projects\Python\project\.venv_3.8.2-64\lib\site-packages\peewee.py", line 7516, in process_row
if instance not in set_keys and dest not in set_keys \
TypeError: unhashable type: 'B'
```
Unfortunately, I could not reproduce this on arbitry models because I couldn't find conditions that make model instance unhashable. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2187/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2187/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2186 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2186/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2186/comments | https://api.github.com/repos/coleifer/peewee/issues/2186/events | https://github.com/coleifer/peewee/issues/2186 | 621,504,289 | MDU6SXNzdWU2MjE1MDQyODk= | 2,186 | Postgres TimeFields with timezones | {
"login": "BryceBeagle",
"id": 5437880,
"node_id": "MDQ6VXNlcjU0Mzc4ODA=",
"avatar_url": "https://avatars.githubusercontent.com/u/5437880?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/BryceBeagle",
"html_url": "https://github.com/BryceBeagle",
"followers_url": "https://api.github.com/users/BryceBeagle/followers",
"following_url": "https://api.github.com/users/BryceBeagle/following{/other_user}",
"gists_url": "https://api.github.com/users/BryceBeagle/gists{/gist_id}",
"starred_url": "https://api.github.com/users/BryceBeagle/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/BryceBeagle/subscriptions",
"organizations_url": "https://api.github.com/users/BryceBeagle/orgs",
"repos_url": "https://api.github.com/users/BryceBeagle/repos",
"events_url": "https://api.github.com/users/BryceBeagle/events{/privacy}",
"received_events_url": "https://api.github.com/users/BryceBeagle/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Also related, the [docs](https://github.com/coleifer/peewee/blame/master/docs/peewee/playhouse.rst#L688) mention (and try linking to) `DateTimeTZ` (as opposed to `DateTimeTZField`) resulting in a broken link",
"How can a time have a timezone, when the time's value is dependent on the date it's attached to? At any rate, you can subclass `TimeField` and provide your own field-type. Creating field types is super easy, especially when they are derived from existing field.\r\n\r\nThanks for the note about the docs, I've fixed it.",
"Postgres has a [datatype that's just a time](https://www.postgresql.org/docs/current/datatype-datetime.html) (no date) with a timezone. This makes sense because I can say \"7PM EST\" and convert it to UTC without ever needing to get a date involved.\r\n\r\nPython's `datetime.time` also supports timezones with its `tzinfo` attribute.\r\n\r\nI understand if you don't want to add it, and can go with the custom field, but to me it seems strange to have first class support for the `timestamp with time zone` datatype but not the `time with time zone` one."
] | 2020-05-20T06:46:54 | 2020-05-21T03:49:28 | 2020-05-20T13:02:36 | NONE | null | `DateTimeField` has a timezone-based subclass in `postgres_ext.DateTimeTZField`. Is there a reason why there's no analog for `TimeField` (i.e. `TimeTZField`)? | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2186/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2186/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2185 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2185/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2185/comments | https://api.github.com/repos/coleifer/peewee/issues/2185/events | https://github.com/coleifer/peewee/issues/2185 | 621,179,741 | MDU6SXNzdWU2MjExNzk3NDE= | 2,185 | Can't use Model class as field value | {
"login": "mikemill",
"id": 1652125,
"node_id": "MDQ6VXNlcjE2NTIxMjU=",
"avatar_url": "https://avatars.githubusercontent.com/u/1652125?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/mikemill",
"html_url": "https://github.com/mikemill",
"followers_url": "https://api.github.com/users/mikemill/followers",
"following_url": "https://api.github.com/users/mikemill/following{/other_user}",
"gists_url": "https://api.github.com/users/mikemill/gists{/gist_id}",
"starred_url": "https://api.github.com/users/mikemill/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/mikemill/subscriptions",
"organizations_url": "https://api.github.com/users/mikemill/orgs",
"repos_url": "https://api.github.com/users/mikemill/repos",
"events_url": "https://api.github.com/users/mikemill/events{/privacy}",
"received_events_url": "https://api.github.com/users/mikemill/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"It isn't calling `db_value()` because peewee sees that you're using a model class as a value, which is a recognized AST type. The issue that originated this fix is #2131.",
"Thanks for reporting, this is fixed in master now.",
"Thank you! I just wanted to drop a note saying how much I've enjoyed using peewee and how appreciative I've been have your responsiveness to issues."
] | 2020-05-19T18:04:54 | 2020-05-19T21:32:35 | 2020-05-19T20:54:28 | NONE | null | I have a custom field that stores the import path to a Python class. The `db_value` takes the class object and coverts it to the import path string and the `python_value` takes the string and imports the object giving me back the class. However, as of peewee 3.13.2 this no longer works and instead gives me `peewee.InternalError: (1054, "Unknown column 't1' in 'field list'")` when I try to save.
Field:
```python
class PythonObjectField(CharField):
"""
A custom class for storing a Python object as a reference.
"""
def db_value(self, value):
if value is None:
return None
elif isinstance(value, str):
return value
return get_object_path(value)
def python_value(self, value):
if value is None:
return None
return import_object(value)
```
The usage would be `Model.field = SomeOtherModel`
[Full example script](https://github.com/coleifer/peewee/files/4652313/peewee_example.txt)
When debugging this I found that this affects my `Model` derived classes but not a simple one that only extends `object`. Additionally, I found that `db_value` is never called.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2185/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2185/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2184 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2184/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2184/comments | https://api.github.com/repos/coleifer/peewee/issues/2184/events | https://github.com/coleifer/peewee/issues/2184 | 620,658,494 | MDU6SXNzdWU2MjA2NTg0OTQ= | 2,184 | can't adapt type 'BackrefAccessor' | {
"login": "aparcar",
"id": 16000931,
"node_id": "MDQ6VXNlcjE2MDAwOTMx",
"avatar_url": "https://avatars.githubusercontent.com/u/16000931?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/aparcar",
"html_url": "https://github.com/aparcar",
"followers_url": "https://api.github.com/users/aparcar/followers",
"following_url": "https://api.github.com/users/aparcar/following{/other_user}",
"gists_url": "https://api.github.com/users/aparcar/gists{/gist_id}",
"starred_url": "https://api.github.com/users/aparcar/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/aparcar/subscriptions",
"organizations_url": "https://api.github.com/users/aparcar/orgs",
"repos_url": "https://api.github.com/users/aparcar/repos",
"events_url": "https://api.github.com/users/aparcar/events{/privacy}",
"received_events_url": "https://api.github.com/users/aparcar/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"StackOverflow for questions.\r\n\r\nYou need to properly join on your relation and then array-agg over the result column you are trying to aggregate..."
] | 2020-05-19T03:59:54 | 2020-05-19T13:52:49 | 2020-05-19T13:52:48 | NONE | null | Hi, I'm trying to use `fn.array_agg` on a backref foreign key. However when trying to loop over the returned, model, I get the following error message:
```
Exception has occurred: ProgrammingError
can't adapt type 'BackrefAccessor'
```
My code looks something like that:
```python
sources = target.sources.select(
Sources.name,
Sources.maintainer,
fn.array_agg(Sources.results).alias("results"),
).group_by(Sources.name, Sources.maintainer)
```
Is it possible to *convert* the BackrefAccessor first to a dict or tuple to get this working? Or is there are different approach? | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2184/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2184/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2183 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2183/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2183/comments | https://api.github.com/repos/coleifer/peewee/issues/2183/events | https://github.com/coleifer/peewee/issues/2183 | 620,048,418 | MDU6SXNzdWU2MjAwNDg0MTg= | 2,183 | Peewee generates an SQL query with syntax errors | {
"login": "theosotr",
"id": 6434138,
"node_id": "MDQ6VXNlcjY0MzQxMzg=",
"avatar_url": "https://avatars.githubusercontent.com/u/6434138?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/theosotr",
"html_url": "https://github.com/theosotr",
"followers_url": "https://api.github.com/users/theosotr/followers",
"following_url": "https://api.github.com/users/theosotr/following{/other_user}",
"gists_url": "https://api.github.com/users/theosotr/gists{/gist_id}",
"starred_url": "https://api.github.com/users/theosotr/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/theosotr/subscriptions",
"organizations_url": "https://api.github.com/users/theosotr/orgs",
"repos_url": "https://api.github.com/users/theosotr/repos",
"events_url": "https://api.github.com/users/theosotr/events{/privacy}",
"received_events_url": "https://api.github.com/users/theosotr/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Did you try this?\r\n\r\n```python\r\nmul = ((Listing.sale_price * Listing.yearly_rent)).cast('float')\r\navg = fn.avg(mul).alias('avg')\r\nmul = mul.alias('mul')\r\n```",
"Thank you; yes, this works!\r\nBut, I would expect peewee to implicitly turn off alias when used in irrelevant cases.",
"To do this it would have to recursively inspect every sub-node in the tree... eg. a function call would have to recursively inspect each of it's arguments. Peewee doesn't do this to avoid overhead. The workaround I suggested is the best way to handle it."
] | 2020-05-18T09:20:09 | 2020-05-18T13:30:55 | 2020-05-18T13:30:55 | NONE | null | I have the following query
```python
mul = ((Listing.sale_price * Listing.yearly_rent)).cast('float').alias('mul')
avg = fn.avg(mul).alias('avg')
Listing.select(avg, mul).group_by(mul).where(mul > 100)
```
Peewee generates an SQL query with syntax error on `sqlite3`.
```
peewee.OperationalError: near "AS": syntax error
```
```sql
SELECT avg(CAST(("t1"."sale_price" * "t1"."yearly_rent") AS float) AS "mul") AS "avg", CAST(("t1"."sale_price" * "t1"."sale_price") AS float) AS "mul"
FROM "listing" AS "t1"
WHERE ("mul" > 100) GROUP BY "mul"
```
I would expect the following correct query. Peewee should ignore the alias of a compound column when used on an aggregate function
```sql
SELECT avg(CAST(("t1"."sale_price" * "t1"."yearly_rent") AS float)) AS "avg", CAST(("t1"."sale_price" * "t1"."sale_price") AS float) AS "mul"
FROM "listing" AS "t1"
WHERE ("mul" > 100) GROUP BY "mul"
``` | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2183/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2183/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2182 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2182/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2182/comments | https://api.github.com/repos/coleifer/peewee/issues/2182/events | https://github.com/coleifer/peewee/issues/2182 | 619,702,121 | MDU6SXNzdWU2MTk3MDIxMjE= | 2,182 | peewee.OperationalError: no such column: t2.subforum_id | {
"login": "LuaFan2",
"id": 51294434,
"node_id": "MDQ6VXNlcjUxMjk0NDM0",
"avatar_url": "https://avatars.githubusercontent.com/u/51294434?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/LuaFan2",
"html_url": "https://github.com/LuaFan2",
"followers_url": "https://api.github.com/users/LuaFan2/followers",
"following_url": "https://api.github.com/users/LuaFan2/following{/other_user}",
"gists_url": "https://api.github.com/users/LuaFan2/gists{/gist_id}",
"starred_url": "https://api.github.com/users/LuaFan2/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/LuaFan2/subscriptions",
"organizations_url": "https://api.github.com/users/LuaFan2/orgs",
"repos_url": "https://api.github.com/users/LuaFan2/repos",
"events_url": "https://api.github.com/users/LuaFan2/events{/privacy}",
"received_events_url": "https://api.github.com/users/LuaFan2/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I'm guessing you added that column to your model class without also ensuring it was added to the database. Try dropping and recreating your table, or migrating the schema using the migrate extension.\r\n\r\nPlease post questions on stackoverflow from now on. This is the issue tracker."
] | 2020-05-17T13:21:54 | 2020-05-17T17:06:09 | 2020-05-17T17:06:09 | NONE | null | I have such models. Everything looks good
```
class Cats(db.Model):
name = CharField()
class Forums(db.Model):
cat = ForeignKeyField(Cats)
name = CharField()
class SubForums(db.Model):
forum = ForeignKeyField(Forums)
name = CharField()
description = CharField(default="")
def messages(self):
print("Messages of " + str(self.id))
return Messages.select().where(Messages.topic.subforum == self.id).count()
def topics(self):
print("Topics of " + str(self.id))
return Topics.select().where(Topics.subforum == self.id).count()
#def last(self):
#last = Messages.select().where(Messages.topic.subforum == self.id).order_by(Messages.created.desc()).first()
#return [last.topic.title, last.author.name, last.created.strftime("%m.%d.%Y %H:%M:%S")]
class Topics(db.Model):
author = ForeignKeyField(User)
subforum = ForeignKeyField(SubForums)
title = CharField()
text = CharField()
class Messages(db.Model):
topic = ForeignKeyField(Topics)
author = ForeignKeyField(User)
text = CharField()
created = DateTimeField(default=datetime.datetime.now)
```
But when I call messages() function I got
`peewee.OperationalError: no such column: t2.subforum_id`
Why?Is this my fault or peewee? | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2182/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2182/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2181 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2181/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2181/comments | https://api.github.com/repos/coleifer/peewee/issues/2181/events | https://github.com/coleifer/peewee/issues/2181 | 619,472,464 | MDU6SXNzdWU2MTk0NzI0NjQ= | 2,181 | flask_peewee.auth without password | {
"login": "LuaFan2",
"id": 51294434,
"node_id": "MDQ6VXNlcjUxMjk0NDM0",
"avatar_url": "https://avatars.githubusercontent.com/u/51294434?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/LuaFan2",
"html_url": "https://github.com/LuaFan2",
"followers_url": "https://api.github.com/users/LuaFan2/followers",
"following_url": "https://api.github.com/users/LuaFan2/following{/other_user}",
"gists_url": "https://api.github.com/users/LuaFan2/gists{/gist_id}",
"starred_url": "https://api.github.com/users/LuaFan2/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/LuaFan2/subscriptions",
"organizations_url": "https://api.github.com/users/LuaFan2/orgs",
"repos_url": "https://api.github.com/users/LuaFan2/repos",
"events_url": "https://api.github.com/users/LuaFan2/events{/privacy}",
"received_events_url": "https://api.github.com/users/LuaFan2/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2020-05-16T13:17:23 | 2020-05-17T13:25:06 | 2020-05-17T13:25:06 | NONE | null | Is it possible to make user auth without a password?I wanna to make possibility to login through Steam OpenID, but peewee-flask auth force me to make such column as password | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2181/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2181/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2180 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2180/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2180/comments | https://api.github.com/repos/coleifer/peewee/issues/2180/events | https://github.com/coleifer/peewee/issues/2180 | 618,941,614 | MDU6SXNzdWU2MTg5NDE2MTQ= | 2,180 | Question. Migrations maker | {
"login": "mrkovalchuk",
"id": 18255783,
"node_id": "MDQ6VXNlcjE4MjU1Nzgz",
"avatar_url": "https://avatars.githubusercontent.com/u/18255783?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/mrkovalchuk",
"html_url": "https://github.com/mrkovalchuk",
"followers_url": "https://api.github.com/users/mrkovalchuk/followers",
"following_url": "https://api.github.com/users/mrkovalchuk/following{/other_user}",
"gists_url": "https://api.github.com/users/mrkovalchuk/gists{/gist_id}",
"starred_url": "https://api.github.com/users/mrkovalchuk/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/mrkovalchuk/subscriptions",
"organizations_url": "https://api.github.com/users/mrkovalchuk/orgs",
"repos_url": "https://api.github.com/users/mrkovalchuk/repos",
"events_url": "https://api.github.com/users/mrkovalchuk/events{/privacy}",
"received_events_url": "https://api.github.com/users/mrkovalchuk/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Peewee has a very easy-to-use migrations helper that you can use to modify your schema. At the time of writing, an automatic \"detect changes and generate migrations\" tool is not part of Peewee and likely will not be added at any time. Such tools carry a very large maintenance burden and are buggy, and bugs can have disastrous effects on your db if you aren't careful. I prefer explicit migrations, and Peewee supports that.\r\n\r\nYou're welcome to use a 3rd party tool, but I can't vouch for any of them, not having used them myself."
] | 2020-05-15T12:46:07 | 2020-05-15T13:31:50 | 2020-05-15T13:31:49 | NONE | null | Peewee it's enough popular python ORM library. Have the migrations system. But he hasn't instrument for auto make migrations. Like in django, or Alimbic for SQLAlchemy.
Is any work in this direction? https://pypi.org/project/peewee-migrations/ - like this (but more life full) | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2180/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2180/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2179 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2179/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2179/comments | https://api.github.com/repos/coleifer/peewee/issues/2179/events | https://github.com/coleifer/peewee/issues/2179 | 618,497,119 | MDU6SXNzdWU2MTg0OTcxMTk= | 2,179 | Database.session_start() locking error | {
"login": "hfaua",
"id": 350335,
"node_id": "MDQ6VXNlcjM1MDMzNQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/350335?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/hfaua",
"html_url": "https://github.com/hfaua",
"followers_url": "https://api.github.com/users/hfaua/followers",
"following_url": "https://api.github.com/users/hfaua/following{/other_user}",
"gists_url": "https://api.github.com/users/hfaua/gists{/gist_id}",
"starred_url": "https://api.github.com/users/hfaua/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/hfaua/subscriptions",
"organizations_url": "https://api.github.com/users/hfaua/orgs",
"repos_url": "https://api.github.com/users/hfaua/repos",
"events_url": "https://api.github.com/users/hfaua/events{/privacy}",
"received_events_url": "https://api.github.com/users/hfaua/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Thanks, switched to RLock."
] | 2020-05-14T19:55:55 | 2020-05-15T01:53:10 | 2020-05-15T01:53:01 | NONE | null | Problem:
When `Database.session_start()` is called before opening the connection to the database it tries to acquire the lock recursively first time in the `Database.session_start()` and second time in `Database.begin()`.
```
peewee.py:3195
def session_start(self):
with self._lock:
-> return self.transaction().__enter__()
```
When entering `self.transaction().__enter__()` the lock is already acquired. Then it goes to:
```
peewee.py:4148
def __enter__(self):
if self.db.transaction_depth() == 0:
-> self._begin()
self.db.push_transaction(self)
return self
```
```
peewee.py:4134
def _begin(self):
args, kwargs = self._begin_args
-> self.db.begin(*args, **kwargs)
```
```
peewee.py:3245
def begin(self):
if self.is_closed():
-> self.connect()
```
```
peewee.py:3023
def connect(self, reuse_if_open=False):
-> with self._lock:
[...]
```
And reaches the point where the lock is acquired for the second time and deadlocks.
Solutions:
1. Use `threading.RLock` instead of `threading.Lock`. This fix the issue and still provide thread safety.
2. Open the connection if not opened in `Database.session_start()` before acquiring the lock. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2179/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2179/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2178 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2178/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2178/comments | https://api.github.com/repos/coleifer/peewee/issues/2178/events | https://github.com/coleifer/peewee/issues/2178 | 618,445,371 | MDU6SXNzdWU2MTg0NDUzNzE= | 2,178 | MariaDB 5 | {
"login": "CaffeineLab",
"id": 18175452,
"node_id": "MDQ6VXNlcjE4MTc1NDUy",
"avatar_url": "https://avatars.githubusercontent.com/u/18175452?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/CaffeineLab",
"html_url": "https://github.com/CaffeineLab",
"followers_url": "https://api.github.com/users/CaffeineLab/followers",
"following_url": "https://api.github.com/users/CaffeineLab/following{/other_user}",
"gists_url": "https://api.github.com/users/CaffeineLab/gists{/gist_id}",
"starred_url": "https://api.github.com/users/CaffeineLab/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/CaffeineLab/subscriptions",
"organizations_url": "https://api.github.com/users/CaffeineLab/orgs",
"repos_url": "https://api.github.com/users/CaffeineLab/repos",
"events_url": "https://api.github.com/users/CaffeineLab/events{/privacy}",
"received_events_url": "https://api.github.com/users/CaffeineLab/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"10.0 was released in 2012... So are you using an 8+ year old version of MariaDB?\r\n\r\nYou can also suppress warnings if that's your preference: https://docs.python.org/3/library/warnings.html#temporarily-suppressing-warnings",
"Yes. And I'm not happy about it either :) So at this point, my opinion (and I am probably the only one with it) is that I think your warning is inaccurate and it should thereby be fixed because the MariaDB version **is** known .... it's just seriously outdated and shouldn't be used. Oh - and the reason for it being old is it is what was shipped on the Synology DiskStation and I'm just using it temporarily so don't judge me too harshly. "
] | 2020-05-14T18:25:14 | 2020-05-14T19:56:42 | 2020-05-14T19:22:07 | NONE | null | So I'm using MariaDB 5.?.? and every time I run I get a warning that it's unable to determine the MySQL version.... in the function it appears to only want to identify versions starting with a 1. Not sure if this is an issue or if it's supposed to be a warning that you are using an old version of MariaDB so it's a bit unclear. The function is def _extract_server_version(self, version) and the line in question is:
if 'maria' in version:
match_obj = re.search(r'(1\d\.\d+\.\d+)', version)
For now, I've removed the 1 from the re and it no longer gives me the warning.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2178/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/2178/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2177 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2177/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2177/comments | https://api.github.com/repos/coleifer/peewee/issues/2177/events | https://github.com/coleifer/peewee/issues/2177 | 617,510,009 | MDU6SXNzdWU2MTc1MTAwMDk= | 2,177 | how to prevent inserting NULL values and raising exception instead | {
"login": "soufelhanafi",
"id": 32456103,
"node_id": "MDQ6VXNlcjMyNDU2MTAz",
"avatar_url": "https://avatars.githubusercontent.com/u/32456103?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/soufelhanafi",
"html_url": "https://github.com/soufelhanafi",
"followers_url": "https://api.github.com/users/soufelhanafi/followers",
"following_url": "https://api.github.com/users/soufelhanafi/following{/other_user}",
"gists_url": "https://api.github.com/users/soufelhanafi/gists{/gist_id}",
"starred_url": "https://api.github.com/users/soufelhanafi/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/soufelhanafi/subscriptions",
"organizations_url": "https://api.github.com/users/soufelhanafi/orgs",
"repos_url": "https://api.github.com/users/soufelhanafi/repos",
"events_url": "https://api.github.com/users/soufelhanafi/events{/privacy}",
"received_events_url": "https://api.github.com/users/soufelhanafi/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I commented on your identical issue earlier.\r\n\r\nhttps://github.com/coleifer/peewee/issues/2176#issuecomment-628016499"
] | 2020-05-13T14:44:43 | 2020-05-13T15:40:28 | 2020-05-13T15:40:28 | NONE | null | After running this code, the data will be inserted into the database. when I check the database, I find a row added with values: int_field=0 and other="" (empty string)
My question is how to throw exception in case of Null/empty insert.
import peewee as pw
from datetime import datetime
db = pw.MySQLDatabase('tests', user = 'root', password = 'root', host = 'localhost', port = 3306)
class Model(pw.Model):
name = pw.CharField()
created_at = pw.DateTimeField(default = datetime.now())
other = pw.CharField(null = False)
int_field = pw.IntegerField(null = False)
class Meta:
database = db
db_table = 'nmodel'
Model.create_table()
Model.create(name = "tests")
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2177/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2177/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2176 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2176/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2176/comments | https://api.github.com/repos/coleifer/peewee/issues/2176/events | https://github.com/coleifer/peewee/issues/2176 | 617,472,918 | MDU6SXNzdWU2MTc0NzI5MTg= | 2,176 | Insert data into database even the field are not allowing null values | {
"login": "soufelhanafi",
"id": 32456103,
"node_id": "MDQ6VXNlcjMyNDU2MTAz",
"avatar_url": "https://avatars.githubusercontent.com/u/32456103?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/soufelhanafi",
"html_url": "https://github.com/soufelhanafi",
"followers_url": "https://api.github.com/users/soufelhanafi/followers",
"following_url": "https://api.github.com/users/soufelhanafi/following{/other_user}",
"gists_url": "https://api.github.com/users/soufelhanafi/gists{/gist_id}",
"starred_url": "https://api.github.com/users/soufelhanafi/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/soufelhanafi/subscriptions",
"organizations_url": "https://api.github.com/users/soufelhanafi/orgs",
"repos_url": "https://api.github.com/users/soufelhanafi/repos",
"events_url": "https://api.github.com/users/soufelhanafi/events{/privacy}",
"received_events_url": "https://api.github.com/users/soufelhanafi/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I am unclear what you are asking. Perhaps you have a mysql setting enabled that causes it to use default/empty values instead of raising an exception?\r\n\r\nAt any rate, this is not a peewee issue but a mysql question. Please take it to stackoverflow."
] | 2020-05-13T13:58:20 | 2020-05-13T14:12:35 | 2020-05-13T14:12:35 | NONE | null | I have an issue with inserting data using peewee Model.create method.
after running the code below, the data will be inserted into the database with default values empty string for the **other field** and 0 for the **int_field**.
My question is how can I invoque an exception without inserting data into database.
import peewee as pw
from datetime import datetime
db = pw.MySQLDatabase('tests', user = 'root', password = 'root', host = 'localhost', port = 3306)
class Model(pw.Model):
name = pw.CharField()
created_at = pw.DateTimeField(default = datetime.now())
other = pw.CharField(null = False)
int_field = pw.IntegerField(null = False)
class Meta:
database = db
db_table = 'nmodel'
Mode.create_table()
Model.create(name = "tests")
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2176/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2176/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2175 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2175/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2175/comments | https://api.github.com/repos/coleifer/peewee/issues/2175/events | https://github.com/coleifer/peewee/issues/2175 | 617,247,073 | MDU6SXNzdWU2MTcyNDcwNzM= | 2,175 | psycopg2.ProgrammingError: invalid dsn: invalid connection option "autoconnect" | {
"login": "kmakwana",
"id": 64768985,
"node_id": "MDQ6VXNlcjY0NzY4OTg1",
"avatar_url": "https://avatars.githubusercontent.com/u/64768985?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/kmakwana",
"html_url": "https://github.com/kmakwana",
"followers_url": "https://api.github.com/users/kmakwana/followers",
"following_url": "https://api.github.com/users/kmakwana/following{/other_user}",
"gists_url": "https://api.github.com/users/kmakwana/gists{/gist_id}",
"starred_url": "https://api.github.com/users/kmakwana/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/kmakwana/subscriptions",
"organizations_url": "https://api.github.com/users/kmakwana/orgs",
"repos_url": "https://api.github.com/users/kmakwana/repos",
"events_url": "https://api.github.com/users/kmakwana/events{/privacy}",
"received_events_url": "https://api.github.com/users/kmakwana/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Autoconnect was not present in 3.7.0: https://github.com/coleifer/peewee/blob/3.7.0/peewee.py#L2531-L2532"
] | 2020-05-13T08:23:20 | 2020-05-13T13:33:39 | 2020-05-13T13:33:30 | NONE | null | OS : Ubuntu 20.04
Python version : 3.8.2
Psycopg2 version : 2.8.5
Peewee version : 3.7.0
I am trying to do database connection but it gives me following error:
```
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/peewee.py", line 2600, in connect
self._state.set_connection(self._connect())
File "/usr/lib/python3/dist-packages/playhouse/pool.py", line 155, in _connect
conn = super(PooledDatabase, self)._connect()
File "/usr/lib/python3/dist-packages/playhouse/postgres_ext.py", line 431, in _connect
conn = super(PostgresqlExtDatabase, self)._connect()
File "/usr/lib/python3/dist-packages/peewee.py", line 3227, in _connect
conn = psycopg2.connect(database=self.database, **self.connect_params)
File "/usr/local/lib/python3.8/dist-packages/psycopg2/__init__.py", line 126, in connect
dsn = _ext.make_dsn(dsn, **kwargs)
File "/usr/local/lib/python3.8/dist-packages/psycopg2/extensions.py", line 176, in make_dsn
parse_dsn(dsn)
psycopg2.ProgrammingError: invalid dsn: invalid connection option "autoconnect"
```
But if I remove `autoconnect=False` then there is no error. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2175/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2175/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2174 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2174/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2174/comments | https://api.github.com/repos/coleifer/peewee/issues/2174/events | https://github.com/coleifer/peewee/issues/2174 | 617,012,840 | MDU6SXNzdWU2MTcwMTI4NDA= | 2,174 | Reflection does not identify primary 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 | [
"If you can create a reproducible test-case I would be happy to investigate. As it is, the reflection module is already tested and I can assure you that it is not as fundamentally broken as all that.\r\n\r\nhttps://github.com/coleifer/peewee/blob/3b1181a7cf727cc749a5fbb76f96602a3bb3325b/tests/reflection.py#L77-L443",
"Figure it out. The problem is that I was using a user that doesn't own the tables being reflected. The query that retrieves the primary keys uses the view `table_constraints` which, according to Postgresql\r\n\r\n> The view table_constraints contains all constraints belonging to tables that the current user owns or has some privilege other than SELECT on.\r\n\r\nA possible answer is explained [here](https://stackoverflow.com/questions/39379939/how-to-access-information-schema-foreign-key-constraints-with-read-only-user-in)."
] | 2020-05-12T22:46:35 | 2020-05-13T00:52:34 | 2020-05-13T00:04:38 | NONE | null | It seems that `generate_models` does not identify when a field is the primary key. Instead it creates a composite primary key with all the fields in the model. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2174/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2174/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2173 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2173/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2173/comments | https://api.github.com/repos/coleifer/peewee/issues/2173/events | https://github.com/coleifer/peewee/issues/2173 | 616,736,744 | MDU6SXNzdWU2MTY3MzY3NDQ= | 2,173 | BitField variable name not accepting any name other than "flags" | {
"login": "nisanb",
"id": 20663443,
"node_id": "MDQ6VXNlcjIwNjYzNDQz",
"avatar_url": "https://avatars.githubusercontent.com/u/20663443?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/nisanb",
"html_url": "https://github.com/nisanb",
"followers_url": "https://api.github.com/users/nisanb/followers",
"following_url": "https://api.github.com/users/nisanb/following{/other_user}",
"gists_url": "https://api.github.com/users/nisanb/gists{/gist_id}",
"starred_url": "https://api.github.com/users/nisanb/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/nisanb/subscriptions",
"organizations_url": "https://api.github.com/users/nisanb/orgs",
"repos_url": "https://api.github.com/users/nisanb/repos",
"events_url": "https://api.github.com/users/nisanb/events{/privacy}",
"received_events_url": "https://api.github.com/users/nisanb/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I don't see any such regression: 06c283159fa9917fda8836e2b2973fd38da0a029"
] | 2020-05-12T15:11:30 | 2020-05-12T15:25:07 | 2020-05-12T15:25:07 | NONE | null | Hi,
Given your example:
```
class Post(Model):
content = TextField()
flags = BitField()
is_favorite = flags.flag(1)
is_sticky = flags.flag(2)
is_minimized = flags.flag(4)
is_deleted = flags.flag(8)
```
When changing "flags" variable to any other variable, the fields are effectively not being saved in the database.
When querying to see the data, it always returns 0. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2173/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2173/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2172 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2172/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2172/comments | https://api.github.com/repos/coleifer/peewee/issues/2172/events | https://github.com/coleifer/peewee/issues/2172 | 615,571,386 | MDU6SXNzdWU2MTU1NzEzODY= | 2,172 | pwiz generates non-auto_increment primary key field as AutoField | {
"login": "zqch",
"id": 40731613,
"node_id": "MDQ6VXNlcjQwNzMxNjEz",
"avatar_url": "https://avatars.githubusercontent.com/u/40731613?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/zqch",
"html_url": "https://github.com/zqch",
"followers_url": "https://api.github.com/users/zqch/followers",
"following_url": "https://api.github.com/users/zqch/following{/other_user}",
"gists_url": "https://api.github.com/users/zqch/gists{/gist_id}",
"starred_url": "https://api.github.com/users/zqch/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/zqch/subscriptions",
"organizations_url": "https://api.github.com/users/zqch/orgs",
"repos_url": "https://api.github.com/users/zqch/repos",
"events_url": "https://api.github.com/users/zqch/events{/privacy}",
"received_events_url": "https://api.github.com/users/zqch/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I gather you're using MySQL.\r\n\r\nFor what it's worth, the first example where `user_id` is `AutoField` -- the `info.user_id` stored in the database is still \"10\" in both cases. The reason \"0\" gets assigned, however, is because Peewee thinks this is an auto-increment integer field. So it is trying to read the new pk value from the cursor -- and since this is *not* actually an autoincrement field, this is returned as 0.\r\n\r\nYou can verify that the correct value is still stored in either case, however:\r\n\r\n```python\r\n###\r\n### Here UserInfo.user_id is an AutoField() instance.\r\n###\r\n\r\nIn [2]: u = UserInfo.create(user_id=10, name='bar') \r\n\r\nIn [3]: UserInfo.get().user_id \r\nOut[3]: 10\r\n\r\nIn [4]: u.user_id \r\nOut[4]: 0\r\n```\r\n\r\nIn this case, you should probably go back through the auto-generated code and change the `AutoField()` to `IntegerField(primary_key=True)` where applicable.",
"You can see #2124 for some additional discussion.",
"> You can see #2124 for some additional discussion.\r\n\r\nThanks."
] | 2020-05-11T04:04:11 | 2020-05-12T03:00:03 | 2020-05-11T13:26:19 | NONE | null | I use pwiz to generate model codes, and I got `AutoField` rather than `IntegerField(primaty_key=True)` when the primary key field is not auto_increment, this will cause different results.
for example:
```py
"""
create table user_info (
user_id int unsigned not null,
name varchar(20) not null,
primary key (user_id)
);
"""
class UserInfo(BaseModel):
user_id = AutoField()
name = CharField()
info = UserInfo.create(user_id=10, name='xxx')
print(info.user_id) # 0
# result is different while using IntegerField
class UserInfo(BaseModel):
user_id = IntegerField(primary_key=True)
name = CharField()
info = UserInfo.create(user_id=10, name='xxx')
print(info.user_id) # 10
``` | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2172/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2172/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2171 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2171/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2171/comments | https://api.github.com/repos/coleifer/peewee/issues/2171/events | https://github.com/coleifer/peewee/issues/2171 | 615,203,871 | MDU6SXNzdWU2MTUyMDM4NzE= | 2,171 | Unable to select/update model after migrating ForeignKeyField: RecursionError | {
"login": "arel",
"id": 153497,
"node_id": "MDQ6VXNlcjE1MzQ5Nw==",
"avatar_url": "https://avatars.githubusercontent.com/u/153497?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/arel",
"html_url": "https://github.com/arel",
"followers_url": "https://api.github.com/users/arel/followers",
"following_url": "https://api.github.com/users/arel/following{/other_user}",
"gists_url": "https://api.github.com/users/arel/gists{/gist_id}",
"starred_url": "https://api.github.com/users/arel/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/arel/subscriptions",
"organizations_url": "https://api.github.com/users/arel/orgs",
"repos_url": "https://api.github.com/users/arel/repos",
"events_url": "https://api.github.com/users/arel/events{/privacy}",
"received_events_url": "https://api.github.com/users/arel/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2020-05-09T15:48:10 | 2020-05-13T00:26:48 | 2020-05-13T00:26:48 | NONE | null | I have a migration script that first adds a column and then initializes it. I am using MySQL. However, after adding the column, the model's `ForeignKeyField` is changed in a way that results in a recursion error by simply selecting or updating the new field:
```
RecursionError: maximum recursion depth exceeded
```
To reproduce it, imagine we have the two tables below, and I want to add a `ForeignKeyField` column to the `Rice` table:
```python
from peewee import Model, ForeignKeyField, TextField
class Bean(Model):
name = TextField(default="Red")
class Meta:
database = db
class Rice(Model):
name = TextField(default="Brown")
bean = ForeignKeyField(Bean, null=True, backref='rices') # <-- we want to add this field
class Meta:
database = db
```
Now, let's say I migrate the `Rice` table with something like this:
```python
migrator = MySQLMigrator(db)
migrate(
migrator.add_column(
Rice._meta.table_name,
Rice.bean.column_name,
Rice.bean
),
)
```
As a result of this line: https://github.com/coleifer/peewee/blob/7eb7498018b4265ce7e79c3e2b0b90a93d622d45/playhouse/migrate.py#L237 the value, `Rice.bean.name`, gets changed from `"bean"` to `"bean_id"`. This causes a `RecursionError` the next time we select that field.
```python
Rice.select().first() # FAIL
~/.local/share/virtualenvs/acm-api-UVOmdwT4/lib/python3.7/site-packages/peewee.py in __set__(self, instance, value)
4380
4381 def __set__(self, instance, value):
-> 4382 setattr(instance, self.field.name, value)
4383
4384
RecursionError: maximum recursion depth exceeded
``` | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2171/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2171/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2170 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2170/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2170/comments | https://api.github.com/repos/coleifer/peewee/issues/2170/events | https://github.com/coleifer/peewee/issues/2170 | 614,470,419 | MDU6SXNzdWU2MTQ0NzA0MTk= | 2,170 | TypeError: not enough arguments for format string | {
"login": "kelmore5",
"id": 9361401,
"node_id": "MDQ6VXNlcjkzNjE0MDE=",
"avatar_url": "https://avatars.githubusercontent.com/u/9361401?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/kelmore5",
"html_url": "https://github.com/kelmore5",
"followers_url": "https://api.github.com/users/kelmore5/followers",
"following_url": "https://api.github.com/users/kelmore5/following{/other_user}",
"gists_url": "https://api.github.com/users/kelmore5/gists{/gist_id}",
"starred_url": "https://api.github.com/users/kelmore5/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/kelmore5/subscriptions",
"organizations_url": "https://api.github.com/users/kelmore5/orgs",
"repos_url": "https://api.github.com/users/kelmore5/repos",
"events_url": "https://api.github.com/users/kelmore5/events{/privacy}",
"received_events_url": "https://api.github.com/users/kelmore5/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"As you can see from the traceback:\r\n\r\n```python\r\nFile \"/home/kyle/.local/lib/python3.7/site-packages/pymysql/cursors.py\", line 150, in mogrify\r\n query = query % self._escape_args(args, conn)\r\n```\r\n\r\nThe error is in pymysql, not peewee.",
"No.\r\n\r\nThe error is not because of pymysql. It's because peewee incorrectly passes in the `params` parameter into `cursor.execute`.\r\n\r\nEven if it was, pymysql is not going to change their method, as stated in these issues [here](https://github.com/PyMySQL/PyMySQL/issues/562), [here](https://github.com/PyMySQL/PyMySQL/issues/507), and [here](https://github.com/PyMySQL/PyMySQL/issues/367). Seems easier just to correctly pass in the parameter.",
"Just curious, why r u using pymysql?\r\n\r\nIMO mysql.connector works (and it has C extensions for better performance).",
"No reason really. Never thought about it.\r\n\r\nI probably googled it at some point and picked the first thing that worked.",
"Passing `params=None` does not work with psycopg2.",
"Also I'd like to point out that the whole problem only arises because you are passing the parameters in literally, as part of the query, rather than using placeholders and a parameterized query. There are several reasons why this is bad: sql injection is the most obvious.",
"Hm, well that's fair-ish. Really I brought it up because it seemed like other people were having trouble with it.\r\n\r\n> Passing `params=None` does not work with psycopg2.\r\n\r\nAnd as long as there's a reason for it, I'm satisfied. Hopefully laying out the issue will help people in the future."
] | 2020-05-08T03:04:54 | 2020-05-08T15:09:28 | 2020-05-08T14:30:57 | NONE | null | I believe there's some unexpected behavior that happens when using the `Database.execute_sql` command with an SQL statement but no parameters. The above error occurs in the pymysql project, but it's actually a problem with peewee (in my opinion).
When you run the following code:
```
sql = "INSERT INTO some_table (column_a, column_b) VALUES ('hello_my_name_is_inigo', 'odd_%_percent')
database.execute_sql(sql) # or database.execute_sql(sql, params=None)
```
you receive an error that looks like this:
```
Traceback (most recent call last):
...
models.main_database.execute_sql(sql)
File "/home/kyle/.local/lib/python3.7/site-packages/peewee.py", line 3057, in execute_sql
cursor.execute(sql, params or ())
File "/home/kyle/.local/lib/python3.7/site-packages/pymysql/cursors.py", line 171, in execute
query = self.mogrify(query, args)
File "/home/kyle/.local/lib/python3.7/site-packages/pymysql/cursors.py", line 150, in mogrify
query = query % self._escape_args(args, conn)
TypeError: not enough arguments for format string
```
* Quick note: Anyone reading this can fix the error by 'escaping' the % sign in your SQL statement, from '%' to '%%'
Technically, this happens because there's a percent sign in the SQL statement that needs to be escaped so the line `query = query % self._escape_args(args, conn)` in pymysql can run. However, this puts the burden on the user to figure that out.
I think the real culprit is the params argument in `database.execute_sql` which doesn't seem to be passed correctly into `cursor.execute` at line 3057 in peewee.py. In other words, the line `cursor.execute(sql, params or ())` seems to be the problem. I think we should consider changing the line to this:
`cursor.execute(sql, args=params or None)`
which is more in line with pymysql's documentation, seen [here](https://pymysql.readthedocs.io/en/latest/modules/cursors.html#pymysql.cursors.Cursor.execute).
To give some more context, the line failing in pymysql (within `cursor.execute`) looks like this:
```
# "pymysql/cursors.py", lines 149-150
if args is not None:
query = query % self._escape_args(args, conn)
```
So passing in `params` as an empty tuple really just creates more trouble then it's worth. It should stay as `None`.
It would be different if I was passing in an SQL statement with the expectation that it was a string going to be formatted. Then the error `TypeError: not enough arguments for format string` would make sense, and I could debug it easily. However, I believe passing in only an SQL statement should just execute that SQL statement, without needing to think about formatting or `params` from `cursor.execute`.
Maybe I'm missing something, but is there a reason why `params` is defaulted to an empty tuple in the first place?
Finally, this issue isn't just prevalent [here](https://github.com/coleifer/peewee/issues/1394), but also [Django](https://code.djangoproject.com/ticket/20115), [SQLAlchemy](https://github.com/PyMySQL/PyMySQL/issues/367), and although correct behavior for the package, [pymysql](https://github.com/PyMySQL/PyMySQL/issues/562) itself. So I think it's definitely something that should be fixed as I'm sure more people are having trouble with it.
If anything, we should at least consider updating peewee's documentation for `execute_sql`, seen [here](http://docs.peewee-orm.com/en/latest/peewee/api.html?highlight=execute_sql#Database.execute_sql) to better explain how formatting works, like within pymysql's documentation [here](https://pymysql.readthedocs.io/en/latest/modules/cursors.html#pymysql.cursors.Cursor.execute). Then the error might make more sense after looking it up.
Thanks | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2170/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2170/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2169 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2169/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2169/comments | https://api.github.com/repos/coleifer/peewee/issues/2169/events | https://github.com/coleifer/peewee/issues/2169 | 614,269,594 | MDU6SXNzdWU2MTQyNjk1OTQ= | 2,169 | Join fails on Python3.8 | {
"login": "ayyazdaniaryan",
"id": 1242841,
"node_id": "MDQ6VXNlcjEyNDI4NDE=",
"avatar_url": "https://avatars.githubusercontent.com/u/1242841?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/ayyazdaniaryan",
"html_url": "https://github.com/ayyazdaniaryan",
"followers_url": "https://api.github.com/users/ayyazdaniaryan/followers",
"following_url": "https://api.github.com/users/ayyazdaniaryan/following{/other_user}",
"gists_url": "https://api.github.com/users/ayyazdaniaryan/gists{/gist_id}",
"starred_url": "https://api.github.com/users/ayyazdaniaryan/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/ayyazdaniaryan/subscriptions",
"organizations_url": "https://api.github.com/users/ayyazdaniaryan/orgs",
"repos_url": "https://api.github.com/users/ayyazdaniaryan/repos",
"events_url": "https://api.github.com/users/ayyazdaniaryan/events{/privacy}",
"received_events_url": "https://api.github.com/users/ayyazdaniaryan/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Your example code obviously won't run, as your classes do not extend `Model`. Neither can I tell why you are including a trailing \".\" after your CCC.select() and CCC.select().join(BBB).\r\n\r\nI just ran the following code without any issues on Python 3.8.0:\r\n\r\n```python\r\n\r\ndb = PostgresqlDatabase('peewee_test')\r\n\r\nclass BaseModel(Model):\r\n class Meta:\r\n database = db\r\n\r\nclass A(BaseModel):\r\n a = CharField(unique=True)\r\n\r\nclass B(BaseModel):\r\n a = CharField()\r\n b = ForeignKeyField(A)\r\n\r\nclass C(BaseModel):\r\n a = ForeignKeyField(A)\r\n b = ForeignKeyField(B)\r\n\r\ndb.create_tables([A, B, C])\r\na = A.create(a='1')\r\nb = B.create(a='2', b=a)\r\nC.create(a=a, b=b)\r\n\r\nlist(C.select())\r\nq1 = C.select().join(B)\r\nlist(q1)\r\nq2 = C.select().join(A)\r\nlist(q2)\r\ndb.drop_tables([A, B, C])\r\n```"
] | 2020-05-07T18:49:53 | 2020-05-07T19:03:33 | 2020-05-07T19:02:17 | NONE | null | Hello,
I've recently used `peewee` for a new project, shying away after many years of `SQLAlchemy`. Neat package, works well, is pythonic, and small learning curve. Kudos!
I wanted to see anyone else though has noticed issues on the latest version of Python, 3.8, and peewee. I cannot seem to be able to do a `join` at all. Here's the error:
```
TypeError: 'NoneType' object is not callable
```
Here is how I produced this error:
**Python**: 3.8.2
**OS**: Mac OS X 10.14.6
**DB**: Postgres 9.6.17
**Driver**: Psycopg2 2.8.5
Simple model structures, and a dead-simple join:
```python
class AAA:
a = CharField(unique=True, index=True)
class BBB:
a = CharField(null=False)
b = ForeignKeyField(AAA, null=False)
class CCC:
a = ForeignKeyField(AAA, null=False)
b = ForeignKeyField(BBB, null=False)
entry_a = AAA.create(a="python")
entry_b = BBB.create(a="py", b=entry_a)
entry_c = CCC.create(a=entry_a, b=entry_b)
...
CCC.select(). # This works fine
CCC.select().join(BBB). # Throws the error
CCC.select().join(AAA) # Throws the error
```
My workaround for this was to downgrade my venv to Python3.7, and it's happy days. But it appears that Py3.8 has breaking changes for this package. Let me know if I'm doing something wrong, or if it's a known issue. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2169/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2169/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2168 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2168/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2168/comments | https://api.github.com/repos/coleifer/peewee/issues/2168/events | https://github.com/coleifer/peewee/issues/2168 | 613,926,515 | MDU6SXNzdWU2MTM5MjY1MTU= | 2,168 | update_model_from_dict - ignoring field types | {
"login": "OranShuster",
"id": 1076161,
"node_id": "MDQ6VXNlcjEwNzYxNjE=",
"avatar_url": "https://avatars.githubusercontent.com/u/1076161?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/OranShuster",
"html_url": "https://github.com/OranShuster",
"followers_url": "https://api.github.com/users/OranShuster/followers",
"following_url": "https://api.github.com/users/OranShuster/following{/other_user}",
"gists_url": "https://api.github.com/users/OranShuster/gists{/gist_id}",
"starred_url": "https://api.github.com/users/OranShuster/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/OranShuster/subscriptions",
"organizations_url": "https://api.github.com/users/OranShuster/orgs",
"repos_url": "https://api.github.com/users/OranShuster/repos",
"events_url": "https://api.github.com/users/OranShuster/events{/privacy}",
"received_events_url": "https://api.github.com/users/OranShuster/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Peewee doesn't convert types on assignment. It would convert the type before sending it to the database, e.g., if you used it in a query. But you can assign any value to any field type:\r\n\r\n```python\r\n\r\nIn [1]: from peewee import * \r\n\r\nIn [2]: class Foo(Model): \r\n ...: bar = IntegerField() \r\n ...: \r\n\r\nIn [3]: Foo.bar = 'hello' \r\n\r\nIn [4]: Foo.bar \r\nOut[4]: 'hello'\r\n```",
"This bites hard when the application has to pass JSONs between DB and external sources. The \"custom field + `dict_to_model`\" combo becomes functionally useless in these cases.\r\n\r\nAny plans to alleviate this for custom fields?",
"If you need data validation then I'd suggest using a dedicated (de)serialization layer between your database and whatever json you need to return. Or implement your own conversions.",
"Not validation but just to have the right types coming out of the model in general.\n\nNot having that either makes the custom fields useless or leads to duplication of the conversions. Which also makes it impossible to achieve type-invariant code near the database, where that's really useful.\n\nI guess it's as simple as iterating over the fields and calling `python_value()` where needed, so not a big deal, but it's still a bit of a jarring omission.\n\nPR not necessary I suppose?",
"FTR this is not about conversion on assignment, but the behavior of `dict_to_model`.",
"Gotcha can you provide an example?",
"@coleifer In our code, we use multiple custom fields that convert different enum and compound types to basic database types. We take them from their serialized JSON form - which, BTW, also uses basic types. I.e. there's a 1:1 mapping between the types of values we have in the resulting dict to the basic types that the DB uses.\r\n\r\nJSON —(`json.loads(...)`)→ `dict` — (`dict_to_model`)→ `Model`.\r\n\r\nAfter a bit of processing, the code sends out similar JSON to the next service in line.\r\n\r\n```\r\nfrom peewee import Field, Model\r\nfrom playhouse.shortcuts import dict_to_model\r\n\r\n\r\nclass MyFancyType:\r\n def __bool__(self): # Oversimplified for the sake of an example\r\n return True\r\n\r\n def do_something(self):\r\n return \"something\"\r\n\r\n\r\nclass FancyField(Field):\r\n field_type = \"BOOL\"\r\n\r\n def db_value(self, fancy):\r\n return bool(fancy)\r\n\r\n def python_value(self, value):\r\n return MyFancyType()\r\n\r\n\r\nclass MyModel(Model):\r\n ...\r\n something_fancy = FancyField()\r\n\r\n\r\nm = dict_to_model(MyModel, {\"something_fancy\": True})\r\nm.something_fancy.do_something() # ⊥ - AttributeError: 'bool' object has no attribute 'do_something'\r\n```\r\n\r\nEven if `peewee` does not convert between types on assignment (which I agree with), it would be nice to have `dict_to_model` and `model_to_dict` versions that assume operation on `db_value()` kinds of values.\r\n\r\nCurrent versions imply usage of `python_value` kind, which means that the conversion code from the fields has to be duplicated and applied separately for `dict_to_model` input, negating the value of customs.\r\n\r\nAlmost all basic db types have 1:1 correspondance with Python's basic types. This would make serializing the model with custom fields a breeze.",
"@coleifer any comments on this? Should I create a new issue / send PRs?",
"Doesn't this all boil down to:\r\n\r\n>Peewee doesn't convert types on assignment.\r\n\r\nThe helpers in `shortcuts` (the module name should provide the clue) are just shortcuts. If you want some special behavior, I suggest implementing it yourself in your own module.\r\n\r\nYou can always iterate your fields after assignment, calling each field's `python_value()`. This is trivial:\r\n\r\n```python\r\ndef my_dict_to_model(M, data):\r\n m = dict_to_model(M, data)\r\n for field in M._meta.sorted_fields:\r\n setattr(m, f.name, f.python_value(getattr(m, f.name)))\r\n return m\r\n```",
"> Doesn't this all boil down to: Peewee doesn't convert types on assignment.\r\n\r\nI don't see why this has to be the case for shortcut functions. The model doesn't convert, but why should the shortcuts be limited this way? If this makes it difficult to serialize custom fields - why not just introduce an alternative shortcut that helps with this?\r\n\r\nI certainly don't like the idea of rummaging in model internals just to get that to work, but this is what I use for this now.\r\n\r\nIt just seems like a very odd gap in the user story: Peewee has custom fields, but the shortcuts \"do not care\" about them in any way - so you might as well not use custom fields if you want to use the shortcuts."
] | 2020-05-07T09:56:05 | 2023-02-21T14:05:15 | 2020-05-09T14:44:57 | NONE | null | Example model -
```
class VmSize(Model):
class Meta:
...
id = PrimaryKeyField()
cost= DecimalField()
```
if i would use playhous' `model_to_dict` ->`json.dumps` and then `dict_to_model` the value of the decimal field would containt a float (since thats how the json module reads that value when deserializing)
shouldn't there be some check on the field to type and wrap the float value inside a `Decimal` instance? | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2168/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2168/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2167 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2167/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2167/comments | https://api.github.com/repos/coleifer/peewee/issues/2167/events | https://github.com/coleifer/peewee/issues/2167 | 612,768,536 | MDU6SXNzdWU2MTI3Njg1MzY= | 2,167 | DecimalField wizhout max_digits | {
"login": "daeeros",
"id": 34482855,
"node_id": "MDQ6VXNlcjM0NDgyODU1",
"avatar_url": "https://avatars.githubusercontent.com/u/34482855?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/daeeros",
"html_url": "https://github.com/daeeros",
"followers_url": "https://api.github.com/users/daeeros/followers",
"following_url": "https://api.github.com/users/daeeros/following{/other_user}",
"gists_url": "https://api.github.com/users/daeeros/gists{/gist_id}",
"starred_url": "https://api.github.com/users/daeeros/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/daeeros/subscriptions",
"organizations_url": "https://api.github.com/users/daeeros/orgs",
"repos_url": "https://api.github.com/users/daeeros/repos",
"events_url": "https://api.github.com/users/daeeros/events{/privacy}",
"received_events_url": "https://api.github.com/users/daeeros/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"\r\n",
"Peewee requires that you be explicit w/the decimal field. If you dislike this functionality, then you can subclass it and override the `get_modifiers()` method.\r\n\r\n```python\r\n\r\nclass NumericField(DecimalField):\r\n def get_modifiers(self):\r\n pass\r\n```"
] | 2020-05-05T17:23:07 | 2020-05-05T19:38:33 | 2020-05-05T19:38:32 | NONE | null | Why can not you specify max_digits, etc. In ordinary PhpPgadmin, this can be done and the column is simply called numeric without max_digits, etc. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2167/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2167/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2166 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2166/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2166/comments | https://api.github.com/repos/coleifer/peewee/issues/2166/events | https://github.com/coleifer/peewee/issues/2166 | 610,623,706 | MDU6SXNzdWU2MTA2MjM3MDY= | 2,166 | Support for read slaves | {
"login": "aniljaiswal",
"id": 43805107,
"node_id": "MDQ6VXNlcjQzODA1MTA3",
"avatar_url": "https://avatars.githubusercontent.com/u/43805107?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/aniljaiswal",
"html_url": "https://github.com/aniljaiswal",
"followers_url": "https://api.github.com/users/aniljaiswal/followers",
"following_url": "https://api.github.com/users/aniljaiswal/following{/other_user}",
"gists_url": "https://api.github.com/users/aniljaiswal/gists{/gist_id}",
"starred_url": "https://api.github.com/users/aniljaiswal/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/aniljaiswal/subscriptions",
"organizations_url": "https://api.github.com/users/aniljaiswal/orgs",
"repos_url": "https://api.github.com/users/aniljaiswal/repos",
"events_url": "https://api.github.com/users/aniljaiswal/events{/privacy}",
"received_events_url": "https://api.github.com/users/aniljaiswal/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"The way to do this with Peewee 3 is probably to use the various context-managers:\r\n\r\nhttp://docs.peewee-orm.com/en/latest/peewee/api.html#Database.bind_ctx\r\n\r\nYou can explicitly set `Query._database` as well on a one-off basis, but that's up to you.",
"Yep, I went with `DB.bind(models)`. Thanks for the response.",
"@aniljaiswal \r\nStumbled upon this issue while looking for read slaves in peewee. \r\nmay i do not completely comprehend how to use the context manager in here\r\nHow does `DB.bind(models)` work if you want to use the same model for both read and write operations, where my reads are executed on slaves and write on master ?",
"You basically create two connections, one for read and other for write. For read connection, you can specify the models to bind to the database.",
"Got it. Thanks"
] | 2020-05-01T08:00:48 | 2021-05-21T06:41:23 | 2020-05-01T14:47:38 | NONE | null | Hi @coleifer,
I'm using a master-slave(read-only) setup for our MySQL RDS. Currently, there's no straightforward way to specify the database connection on the basis of `SELECT` vs other query types. I stumbled upon your `read_slave` module from playhouse extension v2.10.0 release of peewee.
Is it possible that I can use the same code to do it myself?
```python
from peewee import *
class ReadSlaveModel(Model):
@classmethod
def _get_read_database(cls):
if not getattr(cls._meta, 'read_slaves', None):
return cls._meta.database
current_idx = getattr(cls, '_read_slave_idx', -1)
cls._read_slave_idx = (current_idx + 1) % len(cls._meta.read_slaves)
return cls._meta.read_slaves[cls._read_slave_idx]
@classmethod
def select(cls, *args, **kwargs):
query = super(ReadSlaveModel, cls).select(*args, **kwargs)
query.database = cls._get_read_database()
return query
@classmethod
def raw(cls, *args, **kwargs):
query = super(ReadSlaveModel, cls).raw(*args, **kwargs)
if query._sql.lower().startswith('select'):
query.database = cls._get_read_database()
return query
```
taken from `https://github.com/coleifer/peewee/blob/2.10.2/playhouse/read_slave.py`
Also, I'd like to know if there are any future plans to bring back the support for read slaves. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2166/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2166/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2165 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2165/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2165/comments | https://api.github.com/repos/coleifer/peewee/issues/2165/events | https://github.com/coleifer/peewee/issues/2165 | 609,748,010 | MDU6SXNzdWU2MDk3NDgwMTA= | 2,165 | delete_instance is atomic? | {
"login": "theruziev",
"id": 32102033,
"node_id": "MDQ6VXNlcjMyMTAyMDMz",
"avatar_url": "https://avatars.githubusercontent.com/u/32102033?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/theruziev",
"html_url": "https://github.com/theruziev",
"followers_url": "https://api.github.com/users/theruziev/followers",
"following_url": "https://api.github.com/users/theruziev/following{/other_user}",
"gists_url": "https://api.github.com/users/theruziev/gists{/gist_id}",
"starred_url": "https://api.github.com/users/theruziev/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/theruziev/subscriptions",
"organizations_url": "https://api.github.com/users/theruziev/orgs",
"repos_url": "https://api.github.com/users/theruziev/repos",
"events_url": "https://api.github.com/users/theruziev/events{/privacy}",
"received_events_url": "https://api.github.com/users/theruziev/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Transaction management is left up to the user. So if you want atomicity, then wrap your operations in the `atomic()` context manager.\r\n\r\nhttp://docs.peewee-orm.com/en/latest/peewee/database.html#managing-transactions",
"Thanks for the answer"
] | 2020-04-30T09:18:43 | 2020-04-30T15:22:05 | 2020-04-30T13:05:40 | NONE | null | is it ok to delete_instance it's not atomic by design or I misunderstood code and documentation? | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2165/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2165/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2164 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2164/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2164/comments | https://api.github.com/repos/coleifer/peewee/issues/2164/events | https://github.com/coleifer/peewee/issues/2164 | 608,921,380 | MDU6SXNzdWU2MDg5MjEzODA= | 2,164 | [Question] How to remove element from ArrayField | {
"login": "daeeros",
"id": 34482855,
"node_id": "MDQ6VXNlcjM0NDgyODU1",
"avatar_url": "https://avatars.githubusercontent.com/u/34482855?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/daeeros",
"html_url": "https://github.com/daeeros",
"followers_url": "https://api.github.com/users/daeeros/followers",
"following_url": "https://api.github.com/users/daeeros/following{/other_user}",
"gists_url": "https://api.github.com/users/daeeros/gists{/gist_id}",
"starred_url": "https://api.github.com/users/daeeros/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/daeeros/subscriptions",
"organizations_url": "https://api.github.com/users/daeeros/orgs",
"repos_url": "https://api.github.com/users/daeeros/repos",
"events_url": "https://api.github.com/users/daeeros/events{/privacy}",
"received_events_url": "https://api.github.com/users/daeeros/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"https://www.postgresql.org/docs/9.3/functions-array.html#ARRAY-FUNCTIONS-TABLE",
"The issue tracker is not for \"how do I...\" questions. Ask those on:\r\n\r\n* StackOverflow\r\n* IRC\r\n* Mailing list\r\n\r\nhttp://docs.peewee-orm.com/en/latest/peewee/contributing.html#questions"
] | 2020-04-29T09:49:06 | 2020-04-29T13:11:42 | 2020-04-29T13:10:45 | NONE | null | Hi, I apologize for the large number of questions. How can I remove an item from an ArrayField?
How to add, I seem to have found the function `from peewee import fn`
`fn.array_append ()`
But I did not find how to remove | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2164/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2164/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2163 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2163/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2163/comments | https://api.github.com/repos/coleifer/peewee/issues/2163/events | https://github.com/coleifer/peewee/issues/2163 | 608,297,839 | MDU6SXNzdWU2MDgyOTc4Mzk= | 2,163 | [Question] How to add new value for ArrayField table | {
"login": "daeeros",
"id": 34482855,
"node_id": "MDQ6VXNlcjM0NDgyODU1",
"avatar_url": "https://avatars.githubusercontent.com/u/34482855?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/daeeros",
"html_url": "https://github.com/daeeros",
"followers_url": "https://api.github.com/users/daeeros/followers",
"following_url": "https://api.github.com/users/daeeros/following{/other_user}",
"gists_url": "https://api.github.com/users/daeeros/gists{/gist_id}",
"starred_url": "https://api.github.com/users/daeeros/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/daeeros/subscriptions",
"organizations_url": "https://api.github.com/users/daeeros/orgs",
"repos_url": "https://api.github.com/users/daeeros/repos",
"events_url": "https://api.github.com/users/daeeros/events{/privacy}",
"received_events_url": "https://api.github.com/users/daeeros/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Read the postgresql array docs: https://www.postgresql.org/docs/9.1/arrays.html\r\n\r\nYou can use the concatenation operator, though it's pretty \"fragile\" and may complain about operators, in which case you'll need to use casts."
] | 2020-04-28T12:59:43 | 2020-04-28T14:43:06 | 2020-04-28T14:43:06 | NONE | null | Hi, how i can add new value for arrayfield column? I try thet
`await db.execute(MarriagePlayer.update({MarriagePlayer.woman_childrens: MarriagePlayer.woman_childrens.append(1)}))`
But its not working(, i don't see in documentation thet funcion | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2163/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2163/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2162 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2162/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2162/comments | https://api.github.com/repos/coleifer/peewee/issues/2162/events | https://github.com/coleifer/peewee/issues/2162 | 607,850,591 | MDU6SXNzdWU2MDc4NTA1OTE= | 2,162 | Cannot use bulk_create to create multiple entities with a foreign key relationship | {
"login": "psahgal",
"id": 2686895,
"node_id": "MDQ6VXNlcjI2ODY4OTU=",
"avatar_url": "https://avatars.githubusercontent.com/u/2686895?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/psahgal",
"html_url": "https://github.com/psahgal",
"followers_url": "https://api.github.com/users/psahgal/followers",
"following_url": "https://api.github.com/users/psahgal/following{/other_user}",
"gists_url": "https://api.github.com/users/psahgal/gists{/gist_id}",
"starred_url": "https://api.github.com/users/psahgal/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/psahgal/subscriptions",
"organizations_url": "https://api.github.com/users/psahgal/orgs",
"repos_url": "https://api.github.com/users/psahgal/repos",
"events_url": "https://api.github.com/users/psahgal/events{/privacy}",
"received_events_url": "https://api.github.com/users/psahgal/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Peewee introduced an efficiency measure in `bulk_create()` to use the object-id descriptor to grab the associated PK of the related object. It seems it has had an unintended side-effect of not reflecting the new primary-key value upon saving the related object. I'll look into this.",
"Fixed. Note that this would only have worked with postgres, thanks to postgres' ability to return autogenerated IDs after a bulk insert query. So this is kinda under \"yeah, it works, but it's a little weird\" category.\r\n\r\nAt any rate it should be working again on master. I've added a regression test which reproduced the issue and now passes.",
"Thanks for the quick turnaround! I tried it out in the example I put together and everything seems to be working."
] | 2020-04-27T21:01:16 | 2020-04-28T14:01:04 | 2020-04-27T21:27:51 | NONE | null | While making some changes to our ETL pipeline, my team and I noticed that some new errors have appeared. It looks like there was an issue that was introduced in version. 3.13.3. It's also possible we were relying on some undocumented behavior.
What we're trying to do is instantiate a set of entities before writing them to the database in a single transaction with the `bulk_create` method. One set of these entities has a foreign key to entities in the second set. On version 3.13.1, we don't see any errors thrown in our code. But on version 3.13.3, there is an error.
Here's a snippet of the example I put together reproducing the issue. You can find the full example [here](https://github.com/psahgal/peeweeError).
```
class Child(Model):
class Meta:
database = database
name = CharField()
class Parent(Model):
class Meta:
database = database
child = ForeignKeyField(Child)
name = CharField()
entities = [Parent, Child]
database.drop_tables([Parent, Child])
database.create_tables([Parent, Child])
child1 = Child(name='Bob')
child2 = Child(name='Alice')
parent1 = Parent(child=child1, name='Martin')
parent2 = Parent(child=child2, name='Suzy')
with database.atomic():
Child.bulk_create([child1, child2])
Parent.bulk_create([parent1, parent2])
```
On 3.13.1, this works without an error. On 3.13.3, I get the following error:
```
Traceback (most recent call last):
File "/Users/praneetsahgal/.pyenv/versions/3.8.2/lib/python3.8/site-packages/peewee.py", line 3099, in execute_sql
cursor.execute(sql, params or ())
psycopg2.errors.NotNullViolation: null value in column "child_id" violates not-null constraint
DETAIL: Failing row contains (1, null, Martin).
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "main.py", line 33, in <module>
Parent.bulk_create([parent1, parent2])
File "/Users/praneetsahgal/.pyenv/versions/3.8.2/lib/python3.8/site-packages/peewee.py", line 6324, in bulk_create
res = cls.insert_many(accum, fields=fields).execute()
File "/Users/praneetsahgal/.pyenv/versions/3.8.2/lib/python3.8/site-packages/peewee.py", line 1886, in inner
return method(self, database, *args, **kwargs)
File "/Users/praneetsahgal/.pyenv/versions/3.8.2/lib/python3.8/site-packages/peewee.py", line 1957, in execute
return self._execute(database)
File "/Users/praneetsahgal/.pyenv/versions/3.8.2/lib/python3.8/site-packages/peewee.py", line 2707, in _execute
return super(Insert, self)._execute(database)
File "/Users/praneetsahgal/.pyenv/versions/3.8.2/lib/python3.8/site-packages/peewee.py", line 2440, in _execute
cursor = self.execute_returning(database)
File "/Users/praneetsahgal/.pyenv/versions/3.8.2/lib/python3.8/site-packages/peewee.py", line 2447, in execute_returning
cursor = database.execute(self)
File "/Users/praneetsahgal/.pyenv/versions/3.8.2/lib/python3.8/site-packages/peewee.py", line 3112, in execute
return self.execute_sql(sql, params, commit=commit)
File "/Users/praneetsahgal/.pyenv/versions/3.8.2/lib/python3.8/site-packages/peewee.py", line 3106, in execute_sql
self.commit()
File "/Users/praneetsahgal/.pyenv/versions/3.8.2/lib/python3.8/site-packages/peewee.py", line 2873, in __exit__
reraise(new_type, new_type(exc_value, *exc_args), traceback)
File "/Users/praneetsahgal/.pyenv/versions/3.8.2/lib/python3.8/site-packages/peewee.py", line 183, in reraise
raise value.with_traceback(tb)
File "/Users/praneetsahgal/.pyenv/versions/3.8.2/lib/python3.8/site-packages/peewee.py", line 3099, in execute_sql
cursor.execute(sql, params or ())
peewee.IntegrityError: null value in column "child_id" violates not-null constraint
DETAIL: Failing row contains (1, null, Martin).
```
Could someone help investigate this error? Our project will be stuck on 3.13.1 until we can find a fix. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2162/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2162/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2161 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2161/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2161/comments | https://api.github.com/repos/coleifer/peewee/issues/2161/events | https://github.com/coleifer/peewee/issues/2161 | 607,513,471 | MDU6SXNzdWU2MDc1MTM0NzE= | 2,161 | Invalid SQL is generated upon multiple joins of a table | {
"login": "intruder777",
"id": 1699706,
"node_id": "MDQ6VXNlcjE2OTk3MDY=",
"avatar_url": "https://avatars.githubusercontent.com/u/1699706?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/intruder777",
"html_url": "https://github.com/intruder777",
"followers_url": "https://api.github.com/users/intruder777/followers",
"following_url": "https://api.github.com/users/intruder777/following{/other_user}",
"gists_url": "https://api.github.com/users/intruder777/gists{/gist_id}",
"starred_url": "https://api.github.com/users/intruder777/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/intruder777/subscriptions",
"organizations_url": "https://api.github.com/users/intruder777/orgs",
"repos_url": "https://api.github.com/users/intruder777/repos",
"events_url": "https://api.github.com/users/intruder777/events{/privacy}",
"received_events_url": "https://api.github.com/users/intruder777/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I'd be happy to look into this, but I'm not digging through all the craziness.\r\n\r\nIf you can produce a *minimal* example using simple models (e.g. my favorites are \"User\" / \"Tweet\") I'll reopen and investigate."
] | 2020-04-27T12:36:20 | 2020-04-27T14:16:49 | 2020-04-27T14:16:49 | NONE | null | I have strange problem with **peewee (v3.13.3)** when joining several tables in **Postgres (v12.2)**.
- DB structure SQL: https://gist.github.com/intruder777/f36a00b2009a1c9a8236c9f641819556
- DB models (generated by pwiz): https://gist.github.com/intruder777/18b800e3758df471d50fdf52cd05ef87
- Python run file: https://gist.github.com/intruder777/74477ace9d7df218f5f43c7368cd8c2b
- Output with traceback: https://gist.github.com/intruder777/8186e40dcf0a7cec4db4569bc1f63165
If I comment out line 27 in `run.py` - it works and generates valid SQL, but if I keep that line it generates invalid SQL.
Those files mentioned above are also attached:
[code_to_replicate_the_issue.zip](https://github.com/coleifer/peewee/files/4539593/code_to_replicate_the_issue.zip)
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2161/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2161/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2160 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2160/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2160/comments | https://api.github.com/repos/coleifer/peewee/issues/2160/events | https://github.com/coleifer/peewee/issues/2160 | 606,765,244 | MDU6SXNzdWU2MDY3NjUyNDQ= | 2,160 | How to set comments for columns | {
"login": "pch18",
"id": 19822708,
"node_id": "MDQ6VXNlcjE5ODIyNzA4",
"avatar_url": "https://avatars.githubusercontent.com/u/19822708?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/pch18",
"html_url": "https://github.com/pch18",
"followers_url": "https://api.github.com/users/pch18/followers",
"following_url": "https://api.github.com/users/pch18/following{/other_user}",
"gists_url": "https://api.github.com/users/pch18/gists{/gist_id}",
"starred_url": "https://api.github.com/users/pch18/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/pch18/subscriptions",
"organizations_url": "https://api.github.com/users/pch18/orgs",
"repos_url": "https://api.github.com/users/pch18/repos",
"events_url": "https://api.github.com/users/pch18/events{/privacy}",
"received_events_url": "https://api.github.com/users/pch18/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Peewee does not add comments to the schema.",
"Is this functionality you would be interested in having as part of peewee? \r\n\r\nI already have code I could easily adapt to a PR.\r\n\r\n@pch18 A solution for you could look something like this:\r\n``` python\r\nimport peewee as pw\r\n\r\n\r\nclass DatabaseComment(pw.Node):\r\n def __init__(self, obj, comment, obj_type):\r\n self.obj = obj\r\n self.comment = comment\r\n self.obj_type = obj_type\r\n\r\n def __sql__(self, ctx):\r\n ctx.literal('COMMENT ON ')\r\n ctx.literal(self.obj_type)\r\n ctx.literal(' ')\r\n with ctx.scope_values():\r\n if isinstance(self.obj, pw.Field):\r\n ctx.sql(self.obj.model).literal('.')\r\n ctx.sql(self.obj)\r\n\r\n ctx.literal(' IS ')\r\n ctx.sql(self.comment)\r\n return ctx\r\n\r\n \r\n# >>> datababase.execute(DatabaseComment(SomeTable, 'Hello world', 'TABLE'))\r\n```"
] | 2020-04-25T13:02:01 | 2020-04-25T14:13:14 | 2020-04-25T13:25:39 | NONE | null | I tried to set the help_text field, it didn't seem to work | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2160/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2160/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2159 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2159/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2159/comments | https://api.github.com/repos/coleifer/peewee/issues/2159/events | https://github.com/coleifer/peewee/issues/2159 | 605,646,768 | MDU6SXNzdWU2MDU2NDY3Njg= | 2,159 | Selecting from a union causes peewee.InterfaceError | {
"login": "8BitMate",
"id": 14078867,
"node_id": "MDQ6VXNlcjE0MDc4ODY3",
"avatar_url": "https://avatars.githubusercontent.com/u/14078867?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/8BitMate",
"html_url": "https://github.com/8BitMate",
"followers_url": "https://api.github.com/users/8BitMate/followers",
"following_url": "https://api.github.com/users/8BitMate/following{/other_user}",
"gists_url": "https://api.github.com/users/8BitMate/gists{/gist_id}",
"starred_url": "https://api.github.com/users/8BitMate/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/8BitMate/subscriptions",
"organizations_url": "https://api.github.com/users/8BitMate/orgs",
"repos_url": "https://api.github.com/users/8BitMate/repos",
"events_url": "https://api.github.com/users/8BitMate/events{/privacy}",
"received_events_url": "https://api.github.com/users/8BitMate/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"The issue is the final `select()` method.\r\n\r\n```python\r\n\r\nq1 = Data.select()\r\nq2 = Data.select()\r\nquery = q1.union(q2)\r\n```",
"I probably wasn't explaining the issue well enough, but focused on giving a minimal example to reproduce the issue.\r\n\r\nWhat I have are two different queries producing two different tables. I then select from the union of these tables, and do some calculations in the select statement. It looks something like this:\r\n\r\n```python\r\ncomplex_query1 = ...\r\ncomplex_query2 = ...\r\ncomplex_query1.union(complex_query2).select(\r\n # Do calculations here based on this union\r\n)\r\n```\r\nI want to be able to select from this union, as it allows me to do the calculations in a nice way. I know there are workarounds, but would be more clean to do something like this.",
"Then use the `select_from()` API instead."
] | 2020-04-23T15:47:16 | 2020-04-23T19:34:28 | 2020-04-23T16:06:21 | NONE | null | Selecting from a union of two tables causes an InterfaceError.
If i write this query:
```python
q = (
Data
.select()
.union(
Data
.select()
).select()
)
```
and call `q.execute()` I get the following error:
```
peewee.InterfaceError: Query must be bound to a database in order to call "execute".
```
If I call execute with a database like this: `q.execute(database)`, then it works fine.
I suspect the issue has something to do with the `select()` method of the `ModelCompoundSelectQuery` class not using the database from the BaseModel, but I don't have enough knowledge about the library to fix it myself. The issue remains for other methods that create a `ModelCompoundSelectQuery` object, like `except_()` and `union_all()` as well.
A fix for this issue would be greatly appreciated. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2159/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2159/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2158 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2158/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2158/comments | https://api.github.com/repos/coleifer/peewee/issues/2158/events | https://github.com/coleifer/peewee/issues/2158 | 605,438,517 | MDU6SXNzdWU2MDU0Mzg1MTc= | 2,158 | How Update the required array in the database column (Integer) | {
"login": "daeeros",
"id": 34482855,
"node_id": "MDQ6VXNlcjM0NDgyODU1",
"avatar_url": "https://avatars.githubusercontent.com/u/34482855?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/daeeros",
"html_url": "https://github.com/daeeros",
"followers_url": "https://api.github.com/users/daeeros/followers",
"following_url": "https://api.github.com/users/daeeros/following{/other_user}",
"gists_url": "https://api.github.com/users/daeeros/gists{/gist_id}",
"starred_url": "https://api.github.com/users/daeeros/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/daeeros/subscriptions",
"organizations_url": "https://api.github.com/users/daeeros/orgs",
"repos_url": "https://api.github.com/users/daeeros/repos",
"events_url": "https://api.github.com/users/daeeros/events{/privacy}",
"received_events_url": "https://api.github.com/users/daeeros/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Released in 3.13.3 https://github.com/coleifer/peewee/releases/tag/3.13.3"
] | 2020-04-23T10:57:27 | 2020-04-24T00:37:15 | 2020-04-24T00:28:04 | NONE | null | ```
await db.execute(MarriagePlayer.update({
MarriagePlayer.statistics[0]: MarriagePlayer.statistics[0] + 1
}).where(
MarriagePlayer.chat_id == msg.receiver_id,
MarriagePlayer.user_id << [msg.sender_id, p.loved]))
```
i try to update 0 array in column but i get error
> MarriagePlayer.statistics[0]: MarriagePlayer.statistics[0] + 1
>
> TypeError: unhashable type: 'ObjectSlice'
how i can update it witzhou error? | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2158/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2158/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2157 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2157/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2157/comments | https://api.github.com/repos/coleifer/peewee/issues/2157/events | https://github.com/coleifer/peewee/issues/2157 | 604,949,428 | MDU6SXNzdWU2MDQ5NDk0Mjg= | 2,157 | sqlite3 random rows by seed | {
"login": "nisanb",
"id": 20663443,
"node_id": "MDQ6VXNlcjIwNjYzNDQz",
"avatar_url": "https://avatars.githubusercontent.com/u/20663443?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/nisanb",
"html_url": "https://github.com/nisanb",
"followers_url": "https://api.github.com/users/nisanb/followers",
"following_url": "https://api.github.com/users/nisanb/following{/other_user}",
"gists_url": "https://api.github.com/users/nisanb/gists{/gist_id}",
"starred_url": "https://api.github.com/users/nisanb/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/nisanb/subscriptions",
"organizations_url": "https://api.github.com/users/nisanb/orgs",
"repos_url": "https://api.github.com/users/nisanb/repos",
"events_url": "https://api.github.com/users/nisanb/events{/privacy}",
"received_events_url": "https://api.github.com/users/nisanb/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Sqlite allows you to write arbitrary user-defined functions. There are examples:\r\n\r\nhttp://docs.peewee-orm.com/en/latest/peewee/database.html#sqlite-user-functions"
] | 2020-04-22T17:53:35 | 2020-04-22T18:20:27 | 2020-04-22T18:20:27 | NONE | null | With using Python, my tool has a randomized seed for each run.
Upon placing the same seed, I would like to receive the same randomized results.
I tried externally-implementing it, but that causes performance degradation for two reasons:
1. I need to build a list out of ModelSelect objects
2. I need to return all rows for a given where() query, even if I know I only need 5 randomized out of them.
The overhead is a pain and the performance penalty is high.
Could peewee provide an interface as such?
Or, is there a better way of doing it, other than what I tried? | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2157/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2157/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2156 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2156/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2156/comments | https://api.github.com/repos/coleifer/peewee/issues/2156/events | https://github.com/coleifer/peewee/issues/2156 | 604,625,096 | MDU6SXNzdWU2MDQ2MjUwOTY= | 2,156 | Slow attribute access in 2.10.2 | {
"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 | [
"Python is slow. Typically the time spent querying the DB will be the bulk of the time spent in any peewee code path... usually orders of magnitude. If attribute access is hurting you, use the tuples method on the query to have the cursor return tuples instead of model instances."
] | 2020-04-22T10:01:26 | 2020-04-22T13:00:09 | 2020-04-22T13:00:09 | NONE | null | We're on version `2.10.2`, with no plans to upgrade in the short term.
From our profiling we've found that `__get__ peewee.py:915` takes a really long time in some of our hot code paths. Any idea why that `FieldDescriptor` is so slow? It seems to be doing just a `get` on a dict. I tried accessing the underlying `._data` directly and thats about 2x the speed.
Any idea why its that slow? I know "python is slow" answers some of it, but not _all_ of it.
Any suggestions to improve attribute access? Would upgrading to `3.x` help? I went through the changelog but found nothing specifically about this. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2156/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2156/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2155 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2155/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2155/comments | https://api.github.com/repos/coleifer/peewee/issues/2155/events | https://github.com/coleifer/peewee/issues/2155 | 603,849,342 | MDU6SXNzdWU2MDM4NDkzNDI= | 2,155 | Error with bulk_update and UUID primary keys | {
"login": "spl0k",
"id": 2974943,
"node_id": "MDQ6VXNlcjI5NzQ5NDM=",
"avatar_url": "https://avatars.githubusercontent.com/u/2974943?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/spl0k",
"html_url": "https://github.com/spl0k",
"followers_url": "https://api.github.com/users/spl0k/followers",
"following_url": "https://api.github.com/users/spl0k/following{/other_user}",
"gists_url": "https://api.github.com/users/spl0k/gists{/gist_id}",
"starred_url": "https://api.github.com/users/spl0k/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/spl0k/subscriptions",
"organizations_url": "https://api.github.com/users/spl0k/orgs",
"repos_url": "https://api.github.com/users/spl0k/repos",
"events_url": "https://api.github.com/users/spl0k/events{/privacy}",
"received_events_url": "https://api.github.com/users/spl0k/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Fixed in 3.13.3"
] | 2020-04-21T09:27:37 | 2020-04-24T00:37:37 | 2020-04-21T17:07:01 | NONE | null | Hello,
It seems peewee doesn't serialize primary keys properly in `bulk_update()` when they're `UUIDField`s.
This code
```python
import logging
import uuid
from peewee import Model, UUIDField, IntegerField, SqliteDatabase
database = SqliteDatabase(":memory:")
class TestModel(Model):
pk = UUIDField(primary_key=True, default=uuid.uuid4)
i = IntegerField()
class Meta:
database = database
database.create_tables((TestModel,))
m1, m2 = [TestModel.create(i=i) for i in (1, 2)]
m1.i = 11
m2.i = 22
logger = logging.getLogger("peewee")
logger.addHandler(logging.StreamHandler())
logger.setLevel(logging.DEBUG)
TestModel.bulk_update((m1, m2), (TestModel.i,))
```
produces the following
```
('UPDATE "testmodel" SET "i" = CASE "testmodel"."pk" WHEN ? THEN ? WHEN ? THEN ? END WHERE ("testmodel"."pk" IN (?, ?))', [UUID('cec16f95-6bbe-4cb7-a4b7-89373dc7c895'), 11, UUID('046b94f6-154b-4f68-b9e8-4e447fd568a1'), 22, 'cec16f956bbe4cb7a4b789373dc7c895', '046b94f6154b4f68b9e84e447fd568a1'])
Traceback (most recent call last):
File "E:\projects\battledawn-server\env\lib\site-packages\peewee.py", line 3090, in execute_sql
cursor.execute(sql, params or ())
sqlite3.InterfaceError: Error binding parameter 0 - probably unsupported type.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "bulk.py", line 27, in <module>
TestModel.bulk_update((m1, m2), (TestModel.i,))
File "E:\projects\battledawn-server\env\lib\site-packages\peewee.py", line 6345, in bulk_update
.where(cls._meta.primary_key.in_(id_list))
File "E:\projects\battledawn-server\env\lib\site-packages\peewee.py", line 1877, in inner
return method(self, database, *args, **kwargs)
File "E:\projects\battledawn-server\env\lib\site-packages\peewee.py", line 1948, in execute
return self._execute(database)
File "E:\projects\battledawn-server\env\lib\site-packages\peewee.py", line 2433, in _execute
cursor = database.execute(self)
File "E:\projects\battledawn-server\env\lib\site-packages\peewee.py", line 3103, in execute
return self.execute_sql(sql, params, commit=commit)
File "E:\projects\battledawn-server\env\lib\site-packages\peewee.py", line 3097, in execute_sql
self.commit()
File "E:\projects\battledawn-server\env\lib\site-packages\peewee.py", line 2864, in __exit__
reraise(new_type, new_type(exc_value, *exc_args), traceback)
File "E:\projects\battledawn-server\env\lib\site-packages\peewee.py", line 183, in reraise
raise value.with_traceback(tb)
File "E:\projects\battledawn-server\env\lib\site-packages\peewee.py", line 3090, in execute_sql
cursor.execute(sql, params or ())
peewee.InterfaceError: Error binding parameter 0 - probably unsupported type.
```
Using peewee version 3.13.2 | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2155/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2155/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2154 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2154/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2154/comments | https://api.github.com/repos/coleifer/peewee/issues/2154/events | https://github.com/coleifer/peewee/issues/2154 | 603,565,773 | MDU6SXNzdWU2MDM1NjU3NzM= | 2,154 | Error when issuing bulk_create with FK to non-primary-key rel field | {
"login": "coleifer",
"id": 119974,
"node_id": "MDQ6VXNlcjExOTk3NA==",
"avatar_url": "https://avatars.githubusercontent.com/u/119974?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/coleifer",
"html_url": "https://github.com/coleifer",
"followers_url": "https://api.github.com/users/coleifer/followers",
"following_url": "https://api.github.com/users/coleifer/following{/other_user}",
"gists_url": "https://api.github.com/users/coleifer/gists{/gist_id}",
"starred_url": "https://api.github.com/users/coleifer/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/coleifer/subscriptions",
"organizations_url": "https://api.github.com/users/coleifer/orgs",
"repos_url": "https://api.github.com/users/coleifer/repos",
"events_url": "https://api.github.com/users/coleifer/events{/privacy}",
"received_events_url": "https://api.github.com/users/coleifer/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"So the `bulk_create()` method just pulls field data off each model and lines it up for insert. When the model being created has a foreign-key, then peewee is pulling off the related model instance. When doing the insert, we don't realize that we want the related model attr that corresponds to the FK and are just blindly grabbing the PK.",
"Fixed by 2944cd21f76282306dc034432d4b9270553883a4"
] | 2020-04-20T22:04:54 | 2020-04-20T22:37:39 | 2020-04-20T22:37:39 | OWNER | null | u1 = BCUser.create(username='u1')
u2 = BCUser.create(username='u2')
BCTweet.bulk_create([
BCTweet(user='u1', content='t%s' % i)
for i in range(4)])
Throws a foreign-key mismatch error. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2154/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2154/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2153 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2153/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2153/comments | https://api.github.com/repos/coleifer/peewee/issues/2153/events | https://github.com/coleifer/peewee/issues/2153 | 601,223,147 | MDU6SXNzdWU2MDEyMjMxNDc= | 2,153 | ManyToMany field no longer has .add, .remove, .clear methods | {
"login": "pylakey",
"id": 56714344,
"node_id": "MDQ6VXNlcjU2NzE0MzQ0",
"avatar_url": "https://avatars.githubusercontent.com/u/56714344?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/pylakey",
"html_url": "https://github.com/pylakey",
"followers_url": "https://api.github.com/users/pylakey/followers",
"following_url": "https://api.github.com/users/pylakey/following{/other_user}",
"gists_url": "https://api.github.com/users/pylakey/gists{/gist_id}",
"starred_url": "https://api.github.com/users/pylakey/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/pylakey/subscriptions",
"organizations_url": "https://api.github.com/users/pylakey/orgs",
"repos_url": "https://api.github.com/users/pylakey/repos",
"events_url": "https://api.github.com/users/pylakey/events{/privacy}",
"received_events_url": "https://api.github.com/users/pylakey/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I am sorry for opening this issue. Already found a stupid mistake",
"The example code runs fine for me on the latest version of Peewee.\r\n\r\nhttps://gist.github.com/coleifer/8dd15da06ed5e390064ff99ae8ef9378\r\n\r\nThe methods you mentioned *are* present. They are exposed on the backref accessor, not the field itself - this is how it has worked for a very long time.",
"@coleifer, thanks for your reply, it was my mistake)"
] | 2020-04-16T16:21:36 | 2020-04-17T08:41:08 | 2020-04-16T16:47:59 | NONE | null | I suppose that http://docs.peewee-orm.com/en/latest/peewee/relationships.html#manytomanyfield is outdated.
Example in docs doesn't work with latest peewee version because of AttributeError
EDIT: This issue is related to ManyToManyField with through_model set. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2153/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2153/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2152 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2152/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2152/comments | https://api.github.com/repos/coleifer/peewee/issues/2152/events | https://github.com/coleifer/peewee/issues/2152 | 599,203,349 | MDU6SXNzdWU1OTkyMDMzNDk= | 2,152 | Support CTE in ModelInsert? | {
"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 | [
"This is now implemented in 21dcc113c28b853544ca1db804750320d934e17e\r\n\r\nExamples can be found in the new tests, reproduced here:\r\n\r\n```python\r\n def test_data_modifying_cte_delete(self):\r\n # delete products whose price is less than 3, simultaneously copying them to\r\n # the archive table.\r\n query = (C_Product.delete()\r\n .where(C_Product.price < 3)\r\n .returning(C_Product.id, C_Product.name, C_Product.price))\r\n cte = query.cte('moved_rows')\r\n\r\n src = Select((cte,), (cte.c.id, cte.c.name, cte.c.price))\r\n res = (C_Archive\r\n .insert_from(src, (C_Archive.id, C_Archive.name, C_Archive.price))\r\n .with_cte(cte)\r\n .execute())\r\n self.assertEqual(len(list(res)), 3) # The 3 products were moved successfully.\r\n\r\n self.assertEqual(\r\n sorted([(p.name, p.price) for p in C_Product.select()]),\r\n [('p3', 3), ('p4', 4)])\r\n self.assertEqual(\r\n sorted([(p.name, p.price) for p in C_Archive.select()]),\r\n [('p0', 0), ('p1', 1), ('p2', 2)])\r\n\r\n # Use a recursive CTE to bulk-delete a set of parts related by a heirarchical\r\n # foreign-key.\r\n base = (C_Part\r\n .select(C_Part.sub_part, C_Part.part)\r\n .where(C_Part.part == 'mp1')\r\n .cte('included_parts', recursive=True,\r\n columns=('sub_part', 'part')))\r\n PA = C_Part.alias('p')\r\n recursive = (PA\r\n .select(PA.sub_part, PA.part)\r\n .join(base, on=(PA.part == base.c.sub_part)))\r\n cte = base.union_all(recursive)\r\n\r\n sq = Select((cte,), (cte.c.part,))\r\n res = (C_Part.delete()\r\n .where(C_Part.part.in_(sq))\r\n .with_cte(cte)\r\n .execute())\r\n\r\n self.assertEqual(sorted([p.part for p in C_Part.select()]),\r\n ['mp2', 'mp2-c', 'mp2-c-g'])\r\n\r\n def test_data_modifying_cte_update(self):\r\n # Populate archive table w/copy of data in product.\r\n C_Archive.insert_from(\r\n C_Product.select(),\r\n (C_Product.id, C_Product.name, C_Product.price)).execute()\r\n\r\n # Double the price on all products in a CTE and select updated results.\r\n query = (C_Product\r\n .update(price=C_Product.price * 2)\r\n .returning(C_Product.id, C_Product.name, C_Product.price))\r\n cte = query.cte('t')\r\n\r\n sq = cte.select_from(cte.c.id, cte.c.name, cte.c.price)\r\n self.assertEqual(sorted([(x.name, x.price) for x in sq]), [\r\n ('p0', 0), ('p1', 2), ('p2', 4), ('p3', 6), ('p4', 8)])\r\n\r\n # Ensure changes were persisted.\r\n self.assertEqual(sorted([(x.name, x.price) for x in C_Product]), [\r\n ('p0', 0), ('p1', 2), ('p2', 4), ('p3', 6), ('p4', 8)])\r\n\r\n # Double the prices again in a CTE, and simultaneously update\r\n # all the prices in the archive table.\r\n sq = Select((cte,), (cte.c.id, cte.c.price))\r\n res = (C_Archive\r\n .update(price=sq.c.price)\r\n .from_(sq)\r\n .where(C_Archive.id == sq.c.id)\r\n .with_cte(cte)\r\n .execute())\r\n\r\n self.assertEqual(sorted([(x.name, x.price) for x in C_Product]), [\r\n ('p0', 0), ('p1', 4), ('p2', 8), ('p3', 12), ('p4', 16)])\r\n self.assertEqual(sorted([(x.name, x.price) for x in C_Archive]), [\r\n ('p0', 0), ('p1', 4), ('p2', 8), ('p3', 12), ('p4', 16)])\r\n\r\n def test_data_modifying_cte_insert(self):\r\n # Insert a new row within a CTE and select the resulting new row data.\r\n query = (C_Product\r\n .insert({'name': 'p5', 'price': 5})\r\n .returning(C_Product.id, C_Product.name, C_Product.price))\r\n cte = query.cte('t')\r\n\r\n sq = cte.select_from(cte.c.id, cte.c.name, cte.c.price)\r\n self.assertEqual([(p.name, p.price) for p in sq], [('p5', 5)])\r\n\r\n # Insert a new row within a CTE and simultaneously insert all rows \r\n # from the product table into the archive.\r\n query = (C_Product\r\n .insert({'name': 'p6', 'price': 6})\r\n .returning(C_Product.id, C_Product.name, C_Product.price))\r\n cte = query.cte('t')\r\n sq = Select((cte,), (cte.c.id, cte.c.name, cte.c.price))\r\n res = (C_Archive\r\n .insert_from(sq, (sq.c.id, sq.c.name, sq.c.price))\r\n .with_cte(cte)\r\n .execute())\r\n self.assertEqual([(p.name, p.price) for p in C_Archive], [('p6', 6)])\r\n\r\n self.assertEqual(sorted([(p.name, p.price) for p in C_Product]), [\r\n ('p0', 0), ('p1', 1), ('p2', 2), ('p3', 3), ('p4', 4), ('p5', 5),\r\n ('p6', 6)])\r\n```",
"@coleifer \r\n\r\nWay to go! This one is great.",
"Hi @coleifer \r\n\r\nHow can we populate a model with a select from a CTE?\r\n\r\nTo take a trivial example:\r\n\r\n```\r\nuser_select = User.select().where(\r\n User.email == email\r\n).cte('user_select')\r\n```\r\n\r\nHow can this be mapped back onto a User model?\r\n\r\nI would like the query to resolve to the following, while the ORM maps it back to User:\r\n\r\n```\r\nWITH user_select AS (select * from user where email = 'foo')\r\nSELECT * from user_select\r\n```",
"This kind of question typically belongs on stackoverflow, as it is covered by the docs already (and is not even related to this github issue!). Docs: http://docs.peewee-orm.com/en/latest/peewee/querying.html#common-table-expressions\r\n\r\nTo your example:\r\n\r\n```python\r\n\r\nclass User(Model):\r\n name = TextField()\r\n class Meta:\r\n database = db\r\n\r\ncte = User.select().where(User.name == 'c').cte('user_select')\r\nsq = User.select(cte.c.name).from_(cte).with_cte(cte)\r\nfor row in sq:\r\n print(row.name)\r\n```"
] | 2020-04-13T23:54:42 | 2022-07-27T14:25:31 | 2022-06-16T15:39:03 | NONE | null | I have the following use case. I have a table `tic_v8` from which I want to get the columns `ra` and `dec` and insert them into a table `catalog`, also assigning a serial primary key (`catalogid`). In the same query I want to retrieve the newly assigned catalogids and `tic_v8.id` and add them to a relational table `catalog_to_tic_v8`. My real query is a bit more complicated but this should illustrate.
The only way I've found to do this (I'd be interested to know if there is a better way) is to first populate the relational table with a sequential `catalogid` and then populate `catalog`. I can do this in SQL with a couple CTEs
```sql
WITH x AS (SELECT * FROM tic_v8 ORDER BY id ASC),
y AS (INSERT INTO catalog_to_tic_v8 (catalogid, target_id) SELECT ROW_NUMBER() OVER(), id FROM x ORDER BY x.id RETURNING catalogid, target_id)
INSERT INTO catalog (catalogid, ra, dec) SELECT catalogid, t.ra, t.dec FROM y join tic_v8 t ON y.target_id = t.id;
```
(I understand that for this one-to-one relationship I would not need a relational table, but in a different query I'll need to populate this table with one-to-many cases).
In Peewee, if I try to do something like this
```python
x = TIC.select().cte('x')
y = CatalogToTIC_v8.insert_from(x.select(fn.row_number().over(), x.c.id).order_by(x.c.id.asc()), [CatalogToTIC_v8.catalogid, CatalogToTIC_v8.target_id]).returning(CatalogToTIC_v8)).cte('y')
q = Catalog.insert_from(y.select(y.c.catalogid, TIC.ra, TIC.dec).join(TIC, on=y.c.target_id==TIC.id), [Catalog.catalogid, Catalog.ra, Catalog.dec]).returning().with_cte(x, y)
```
that would fail because a `ModelInsert` cannot be a CTE. PostgreSQL allows it and actually I can do
```python
y = peewee.CTE('y', CatalogToTIC_v8.insert_from(x.select(fn.row_number().over(), x.c.id).order_by(x.c.id.asc()), [CatalogToTIC_v8.catalogid, CatalogToTIC_v8.target_id]).returning(CatalogToTIC_v8)))
q = Catalog.insert_from(y.select(y.c.catalogid, TIC.ra, TIC.dec).join(TIC, on=y.c.target_id==TIC.id), [Catalog.catalogid, Catalog.ra, Catalog.dec]).returning().with_cte(x, y)
```
Would it make sense to add the `.cte()` method to the `ModelInsert`? | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2152/reactions",
"total_count": 10,
"+1": 9,
"-1": 1,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2152/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2151 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2151/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2151/comments | https://api.github.com/repos/coleifer/peewee/issues/2151/events | https://github.com/coleifer/peewee/issues/2151 | 597,334,022 | MDU6SXNzdWU1OTczMzQwMjI= | 2,151 | Pivot functionality? | {
"login": "bravegag",
"id": 4385408,
"node_id": "MDQ6VXNlcjQzODU0MDg=",
"avatar_url": "https://avatars.githubusercontent.com/u/4385408?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/bravegag",
"html_url": "https://github.com/bravegag",
"followers_url": "https://api.github.com/users/bravegag/followers",
"following_url": "https://api.github.com/users/bravegag/following{/other_user}",
"gists_url": "https://api.github.com/users/bravegag/gists{/gist_id}",
"starred_url": "https://api.github.com/users/bravegag/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/bravegag/subscriptions",
"organizations_url": "https://api.github.com/users/bravegag/orgs",
"repos_url": "https://api.github.com/users/bravegag/repos",
"events_url": "https://api.github.com/users/bravegag/events{/privacy}",
"received_events_url": "https://api.github.com/users/bravegag/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I don't think this is a good fit for a library like Peewee, but I would encourage you, if you think it would be useful, to create your own module."
] | 2020-04-09T14:44:32 | 2020-04-09T16:28:20 | 2020-04-09T16:28:20 | NONE | null | I think a really good feature in Peewee would be pivoting data which is supported up to some extent by different database vendors. Having pivot support would be a welcome abstraction to Peewee for a far common problem. Note that pandas implements pivoting see: https://pandas.pydata.org/Pandas_Cheat_Sheet.pdf
Pivoting means to turn data stored in long (or narrow) format, into wide format i.e. closer to a dataframe. Why saving the data in long format in the first place? because it's more extensible requiring less potential schema updates to extend.
See a relevant SO question here:
[How to pivot in SQLite or i.e. select in wide format a table stored in long format?](https://stackoverflow.com/questions/1237068/how-to-pivot-in-sqlite-or-i-e-select-in-wide-format-a-table-stored-in-long-form) | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2151/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2151/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2150 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2150/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2150/comments | https://api.github.com/repos/coleifer/peewee/issues/2150/events | https://github.com/coleifer/peewee/issues/2150 | 597,206,825 | MDU6SXNzdWU1OTcyMDY4MjU= | 2,150 | [q] Run-time model schema | {
"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 | [
"You can use the `SubclassAwareMetadata` implementation, which tracks all models declared in your app. From that list of models, you should be able to easily iterate through them and change each model's `._meta.schema`.",
"This is exactly covered in this test-case:\r\n\r\nhttps://github.com/coleifer/peewee/blob/4919f5b6ea56969e56abaa5f4e276452e96bc9c9/tests/models.py#L3255-L3287"
] | 2020-04-09T11:10:51 | 2020-04-09T13:29:26 | 2020-04-09T13:28:38 | NONE | null | Hi there!
I'm trying to make a multitenancy application (flask+peewee). I think it possible to change the schema for all models in runtime but can't find the way.
Any example, pls (without context managers)
Thanks! | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2150/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2150/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2149 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2149/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2149/comments | https://api.github.com/repos/coleifer/peewee/issues/2149/events | https://github.com/coleifer/peewee/issues/2149 | 596,803,220 | MDU6SXNzdWU1OTY4MDMyMjA= | 2,149 | OperationalError: PRIMARY KEY missing on table | {
"login": "bravegag",
"id": 4385408,
"node_id": "MDQ6VXNlcjQzODU0MDg=",
"avatar_url": "https://avatars.githubusercontent.com/u/4385408?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/bravegag",
"html_url": "https://github.com/bravegag",
"followers_url": "https://api.github.com/users/bravegag/followers",
"following_url": "https://api.github.com/users/bravegag/following{/other_user}",
"gists_url": "https://api.github.com/users/bravegag/gists{/gist_id}",
"starred_url": "https://api.github.com/users/bravegag/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/bravegag/subscriptions",
"organizations_url": "https://api.github.com/users/bravegag/orgs",
"repos_url": "https://api.github.com/users/bravegag/repos",
"events_url": "https://api.github.com/users/bravegag/events{/privacy}",
"received_events_url": "https://api.github.com/users/bravegag/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"When does that operational error occur? Without the full traceback it's impossible to tell what happened. Operational error typically is raised by your driver - you're violating a constraint implied by something in your schema.\r\n\r\nI believe, looking at the sqlite source code, that it's the use of \"without rowid\" and primary-key = false that are the issue. If you have no primary key, but you are also telling sqlite \"without rowid\" then it's going to complain, in other words. Give it a primary key or remove the \"without rowid\" bit and you should be OK.",
"Oh yes you're totally right. Thanks!"
] | 2020-04-08T19:22:04 | 2020-04-09T07:10:38 | 2020-04-08T21:41:46 | NONE | null | I get the OP title error while creating a table and setting the Meta to `primary_key = False` see the following MCVE sample:
```
from peewee import *
db = SqliteDatabase('market_data.db')
class BaseModel(Model):
"""
Base reusable model.
"""
class Meta:
database = db
legacy_table_names = False
class MarketInstrument(BaseModel):
"""
Market instrument model.
"""
id = BigAutoField(primary_key=True)
name = CharField(max_length=20, null=False, index=True)
class MarketInstrumentData(BaseModel):
"""
Market instrument time series data.
"""
market_instrument = ForeignKeyField(MarketInstrument, backref='data')
timestamp = DateTimeField(null=False, index=True)
value = DecimalField(null=False, decimal_places=10)
class Meta:
"""
Doesn't require a PK
"""
primary_key = False
without_rowid = True
db.create_tables([MarketInstrument, MarketInstrumentData])
```
This leads to the error:
```
peewee.OperationalError: PRIMARY KEY missing on table market_instrument_data`
```
Indeed, I'm explicitly setting the `MarketInstrumentData` table not to have a PK since it isn't only unnecessary but also ER design-wise incorrect. It's a weak entity and it contains a FK to the strong entity `MarketInstrument` and that's all is needed. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2149/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2149/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2148 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2148/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2148/comments | https://api.github.com/repos/coleifer/peewee/issues/2148/events | https://github.com/coleifer/peewee/issues/2148 | 596,447,421 | MDU6SXNzdWU1OTY0NDc0MjE= | 2,148 | [Question] Return FKs with an _id suffix. | {
"login": "dsmurrell",
"id": 4035854,
"node_id": "MDQ6VXNlcjQwMzU4NTQ=",
"avatar_url": "https://avatars.githubusercontent.com/u/4035854?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/dsmurrell",
"html_url": "https://github.com/dsmurrell",
"followers_url": "https://api.github.com/users/dsmurrell/followers",
"following_url": "https://api.github.com/users/dsmurrell/following{/other_user}",
"gists_url": "https://api.github.com/users/dsmurrell/gists{/gist_id}",
"starred_url": "https://api.github.com/users/dsmurrell/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/dsmurrell/subscriptions",
"organizations_url": "https://api.github.com/users/dsmurrell/orgs",
"repos_url": "https://api.github.com/users/dsmurrell/repos",
"events_url": "https://api.github.com/users/dsmurrell/events{/privacy}",
"received_events_url": "https://api.github.com/users/dsmurrell/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"`model_to_dict` is simply a shortcut, provided for convenience. If you need something different, then just implement a simple serialization function.",
"I understand that and have read that elsewhere... just checking that something didn't exist already that I was missing. Thanks!"
] | 2020-04-08T09:43:46 | 2020-04-08T14:34:30 | 2020-04-08T13:13:49 | NONE | null | Right now, even though foreign keys are stored as field names in the database with an `_id` suffix, they are added to the dictionary outputted by `model_to_dict` without the `_id` suffix.
I was wondering, if I want all foreign keys to appear in the output dict of `model_to_dict` with a `_id` suffix, do I have to write custom code to achieve this, or is there a setting in peewee that can achieve this.
The reason I ask is because on the client side, the expectation is to receive the `_id` suffix for FKs and right now I'm adding them on the client side for all keys that match some list of FKs. This is a brittle solution and I'd like to improve it.
For example, if a `post` has a `user` FK, then I'd like `model_to_dict(post)` to output something like:
```
{
id: "xyz",
title: "This is a post",
user_id: "abc"
}
``` | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2148/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2148/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2147 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2147/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2147/comments | https://api.github.com/repos/coleifer/peewee/issues/2147/events | https://github.com/coleifer/peewee/issues/2147 | 596,278,607 | MDU6SXNzdWU1OTYyNzg2MDc= | 2,147 | mysql default sql_mode setting | {
"login": "amchii",
"id": 26922464,
"node_id": "MDQ6VXNlcjI2OTIyNDY0",
"avatar_url": "https://avatars.githubusercontent.com/u/26922464?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/amchii",
"html_url": "https://github.com/amchii",
"followers_url": "https://api.github.com/users/amchii/followers",
"following_url": "https://api.github.com/users/amchii/following{/other_user}",
"gists_url": "https://api.github.com/users/amchii/gists{/gist_id}",
"starred_url": "https://api.github.com/users/amchii/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/amchii/subscriptions",
"organizations_url": "https://api.github.com/users/amchii/orgs",
"repos_url": "https://api.github.com/users/amchii/repos",
"events_url": "https://api.github.com/users/amchii/events{/privacy}",
"received_events_url": "https://api.github.com/users/amchii/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"You're welcome to specify whatever sql mode you wish by passing it in the constructor."
] | 2020-04-08T03:15:12 | 2020-04-08T13:12:14 | 2020-04-08T13:12:13 | NONE | null | Hi,
peewee set the sql_mode to `'PIPES_AS_CONCAT'` when use `MySQLDatabase`, but this will remove the default setted values `'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'`,
```python
import peewee
pwdb=peewee.MySQLDatabase('test',user='root',password='password')
r=pwdb.execute_sql('select @@session.sql_mode')
r.fetchall()
Out[4]: (('PIPES_AS_CONCAT',),)
from MySQLdb import _mysql
db=_mysql.connect(user='root',passwd='password',db='test')
db.query('select @@session.sql_mode')
res=db.use_result()
res.fetch_row()
Out[9]: ((b'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION',),)
```
and this lead to when insert a `not null` field without value(also no default), no error throw, incorrect insert(for normal) see https://github.com/coleifer/peewee/issues/2031
```python
from peewee import *
db = MySQLDatabase(DB_NAME, user=DB_USER, password=DB_PASSWORD)
class M(Model):
value = IntegerField(default=None, null=False)
class Meta:
database = db
db.create_tables([M])
m = M.create()
m_db = M[M.id]
print(m_db.value)
# output:
# /home/bukinpk/.local/lib/python3.7/site-packages/pymysql/cursors.py:170: Warning: (1364, "Field 'value' doesn't have a default value")
# result = self._query(query)
# 0
```
i think the sql_mode setting should append `'PIPES_AS_CONCAT'` to the default setting instead of replace
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2147/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2147/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2146 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2146/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2146/comments | https://api.github.com/repos/coleifer/peewee/issues/2146/events | https://github.com/coleifer/peewee/issues/2146 | 595,227,179 | MDU6SXNzdWU1OTUyMjcxNzk= | 2,146 | no function fts_bm25 | {
"login": "Dawoodkhorsandi",
"id": 23568714,
"node_id": "MDQ6VXNlcjIzNTY4NzE0",
"avatar_url": "https://avatars.githubusercontent.com/u/23568714?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/Dawoodkhorsandi",
"html_url": "https://github.com/Dawoodkhorsandi",
"followers_url": "https://api.github.com/users/Dawoodkhorsandi/followers",
"following_url": "https://api.github.com/users/Dawoodkhorsandi/following{/other_user}",
"gists_url": "https://api.github.com/users/Dawoodkhorsandi/gists{/gist_id}",
"starred_url": "https://api.github.com/users/Dawoodkhorsandi/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/Dawoodkhorsandi/subscriptions",
"organizations_url": "https://api.github.com/users/Dawoodkhorsandi/orgs",
"repos_url": "https://api.github.com/users/Dawoodkhorsandi/repos",
"events_url": "https://api.github.com/users/Dawoodkhorsandi/events{/privacy}",
"received_events_url": "https://api.github.com/users/Dawoodkhorsandi/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Peewee ships with some user-defined functions which provide the bm25 ranking (when using fts3/4). You need to ensure that you're using `SqliteExtDatabase` as your database class and you should be good-to-go, as it will register the rank functions by default.\r\n\r\nYou can register them yourself, too, just check out the code in `playhouse.sqlite_ext` (and the optional C extension) if you're curious."
] | 2020-04-06T15:49:04 | 2020-04-06T15:52:11 | 2020-04-06T15:52:11 | NONE | null | Hi
I tried to use sqlite3 full-text search with peewee when I run this code
```Python
Poets.select().
join(PoetsIndex, on=(Poets.id == PoetsIndex.rowid)).
where(PoetsIndex.match(phrase))
order_by(PoetsIndex.bm25())
```
it's throws error:
cursor.execute(sql, params or ())
peewee.OperationalError: no such function: fts_bm25
the match function works well, I tried raw SQL too, and it was good, so probably my version contains FTS3 and FTS4, why that error occurs?
Thank you for peewee
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2146/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2146/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2145 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2145/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2145/comments | https://api.github.com/repos/coleifer/peewee/issues/2145/events | https://github.com/coleifer/peewee/issues/2145 | 595,174,762 | MDU6SXNzdWU1OTUxNzQ3NjI= | 2,145 | foreign key exist | {
"login": "JPilarr",
"id": 45560120,
"node_id": "MDQ6VXNlcjQ1NTYwMTIw",
"avatar_url": "https://avatars.githubusercontent.com/u/45560120?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/JPilarr",
"html_url": "https://github.com/JPilarr",
"followers_url": "https://api.github.com/users/JPilarr/followers",
"following_url": "https://api.github.com/users/JPilarr/following{/other_user}",
"gists_url": "https://api.github.com/users/JPilarr/gists{/gist_id}",
"starred_url": "https://api.github.com/users/JPilarr/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/JPilarr/subscriptions",
"organizations_url": "https://api.github.com/users/JPilarr/orgs",
"repos_url": "https://api.github.com/users/JPilarr/repos",
"events_url": "https://api.github.com/users/JPilarr/events{/privacy}",
"received_events_url": "https://api.github.com/users/JPilarr/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Questions go on stackoverflow. http://docs.peewee-orm.com/en/latest/peewee/contributing.html#questions"
] | 2020-04-06T14:41:47 | 2020-04-06T14:52:36 | 2020-04-06T14:52:36 | NONE | null | hi,
would like check if foreign key exist do something.
```
if self.printer_type:
result['type_id'] = self.printer_type.id
result['type_name'] = self.printer_type.name
```
like this. I think the example doesn't work | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2145/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2145/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2144 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2144/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2144/comments | https://api.github.com/repos/coleifer/peewee/issues/2144/events | https://github.com/coleifer/peewee/issues/2144 | 595,052,964 | MDU6SXNzdWU1OTUwNTI5NjQ= | 2,144 | Through model with not AutoField primary key (e.g., UUIDField) with the default value problem | {
"login": "Ignisor",
"id": 22328453,
"node_id": "MDQ6VXNlcjIyMzI4NDUz",
"avatar_url": "https://avatars.githubusercontent.com/u/22328453?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/Ignisor",
"html_url": "https://github.com/Ignisor",
"followers_url": "https://api.github.com/users/Ignisor/followers",
"following_url": "https://api.github.com/users/Ignisor/following{/other_user}",
"gists_url": "https://api.github.com/users/Ignisor/gists{/gist_id}",
"starred_url": "https://api.github.com/users/Ignisor/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/Ignisor/subscriptions",
"organizations_url": "https://api.github.com/users/Ignisor/orgs",
"repos_url": "https://api.github.com/users/Ignisor/repos",
"events_url": "https://api.github.com/users/Ignisor/events{/privacy}",
"received_events_url": "https://api.github.com/users/Ignisor/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"This is expected behavior when using a primary-key field whose default-value is calculated in Python.\r\n\r\nBulk-populating a many-to-many using a select query is an optimization. You can see from the traceback that it's doing an `INSERT ... FROM` query, which means we're inserting into the through table directly from the select query (without resolving the rows on the python side).\r\n\r\nWhen you go through the higher-level APIs, peewee will populate your model instances with a new uuid (by calling the `uuid4()` function). But since the `INSERT ... FROM` happens completely in the database, the db has no value for the ids.\r\n\r\nThis is one of the many reasons it's recommended to just use auto-incrementing integer primary keys. Or if you insist on using UUIDs, set up the column default to call a database function rather than a python one. You've hamstrung your code without realizing it, most likely.",
"Ok, thanks. I understand that behaviour but now I understand why it cannot be changed. In my case I will simply use AutoField for through models.\n\nThanks.\nOn 6 Apr 2020, 17:09 +0300, coleifer/peewee <[email protected]>, wrote:\n>\n> You've hamstrung your code without realizing it, most likely\n"
] | 2020-04-06T11:57:11 | 2020-04-07T09:01:07 | 2020-04-06T14:09:21 | NONE | null | Hi.
## Problem description
For example, I have a schema like that:
```python
class _BaseModel(pw.Model):
id = pw.UUIDField(primary_key=True, default=uuid.uuid4)
class Meta:
database = DB
class Cucumber(_BaseModel):
size = pw.CharField()
CucumbersThroughDeferred = pw.DeferredThroughModel()
class Human(_BaseModel):
name = pw.CharField()
cucumbers = pw.ManyToManyField(Cucumber, backref='humans', through_model=CucumbersThroughDeferred)
class CucumberHuman(_BaseModel):
cucumber = pw.ForeignKeyField(Cucumber)
human = pw.ForeignKeyField(Human)
CucumbersThroughDeferred.set_model(CucumberHuman)
```
And when I add model to M2M field like that, it works okay:
```python
cucumber = Cucumber.create(
size='big',
)
human = Human.create(name='coleifer')
human.cucumbers.add(cucumber)
```
But if I try to add it using the query:
```python
human = Human.create(name='Ignisor')
human.cucumbers.add(Cucumber.select())
```
I will get an exception:
```
Traceback (most recent call last):
File "/Users/ignisor/dev/redbud-compliance-entities/.env/lib/python3.8/site-packages/peewee.py", line 3057, in execute_sql
cursor.execute(sql, params or ())
psycopg2.errors.NotNullViolation: null value in column "id" violates not-null constraint
DETAIL: Failing row contains (null, d3a22843-58ff-4d32-9c90-352a53744bdd, 27888182-3305-44ff-b175-919ecace48fb).
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
line 59, in <module>
File "/Users/ignisor/dev/redbud-compliance-entities/.env/lib/python3.8/site-packages/peewee.py", line 7167, in add
accessor.through_model.insert_from(
File "/Users/ignisor/dev/redbud-compliance-entities/.env/lib/python3.8/site-packages/peewee.py", line 1845, in inner
return method(self, database, *args, **kwargs)
File "/Users/ignisor/dev/redbud-compliance-entities/.env/lib/python3.8/site-packages/peewee.py", line 1916, in execute
return self._execute(database)
File "/Users/ignisor/dev/redbud-compliance-entities/.env/lib/python3.8/site-packages/peewee.py", line 2665, in _execute
return super(Insert, self)._execute(database)
File "/Users/ignisor/dev/redbud-compliance-entities/.env/lib/python3.8/site-packages/peewee.py", line 2398, in _execute
cursor = self.execute_returning(database)
File "/Users/ignisor/dev/redbud-compliance-entities/.env/lib/python3.8/site-packages/peewee.py", line 2405, in execute_returning
cursor = database.execute(self)
File "/Users/ignisor/dev/redbud-compliance-entities/.env/lib/python3.8/site-packages/peewee.py", line 3070, in execute
return self.execute_sql(sql, params, commit=commit)
File "/Users/ignisor/dev/redbud-compliance-entities/.env/lib/python3.8/site-packages/peewee.py", line 3064, in execute_sql
self.commit()
File "/Users/ignisor/dev/redbud-compliance-entities/.env/lib/python3.8/site-packages/peewee.py", line 2831, in __exit__
reraise(new_type, new_type(exc_value, *exc_args), traceback)
File "/Users/ignisor/dev/redbud-compliance-entities/.env/lib/python3.8/site-packages/peewee.py", line 183, in reraise
raise value.with_traceback(tb)
File "/Users/ignisor/dev/redbud-compliance-entities/.env/lib/python3.8/site-packages/peewee.py", line 3057, in execute_sql
cursor.execute(sql, params or ())
peewee.IntegrityError: null value in column "id" violates not-null constraint
DETAIL: Failing row contains (null, d3a22843-58ff-4d32-9c90-352a53744bdd, 27888182-3305-44ff-b175-919ecace48fb).
```
It works if I use a model with AutoKey as through-model for the M2M field.
## Workaround
Using a through-model with AutoKey as a primary key.
In my case, I came up with Metaclass for that purpose (so I don't need to make different base classes).
```
class ThroughModelMeta(pw.ModelBase):
def __new__(cls, name, bases, attrs):
new_cls = super().__new__(cls, name, bases, attrs)
new_cls._meta.set_primary_key('id', pw.AutoField())
return new_cls
```
Thanks.
_P.s. And thanks for such a nice ORM_ 😉
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2144/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2144/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2143 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2143/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2143/comments | https://api.github.com/repos/coleifer/peewee/issues/2143/events | https://github.com/coleifer/peewee/issues/2143 | 591,917,732 | MDU6SXNzdWU1OTE5MTc3MzI= | 2,143 | Comparison operations for subqueries | {
"login": "EugeneRymarev",
"id": 6260309,
"node_id": "MDQ6VXNlcjYyNjAzMDk=",
"avatar_url": "https://avatars.githubusercontent.com/u/6260309?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/EugeneRymarev",
"html_url": "https://github.com/EugeneRymarev",
"followers_url": "https://api.github.com/users/EugeneRymarev/followers",
"following_url": "https://api.github.com/users/EugeneRymarev/following{/other_user}",
"gists_url": "https://api.github.com/users/EugeneRymarev/gists{/gist_id}",
"starred_url": "https://api.github.com/users/EugeneRymarev/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/EugeneRymarev/subscriptions",
"organizations_url": "https://api.github.com/users/EugeneRymarev/orgs",
"repos_url": "https://api.github.com/users/EugeneRymarev/repos",
"events_url": "https://api.github.com/users/EugeneRymarev/events{/privacy}",
"received_events_url": "https://api.github.com/users/EugeneRymarev/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"4919f5b6ea56969e56abaa5f4e276452e96bc9c9"
] | 2020-04-01T13:30:11 | 2020-04-01T17:52:42 | 2020-04-01T17:52:41 | NONE | null | Hi, @coleifer!
Again with same problem, but not for **EQ** or **NE** operations.
Other operations not work too. Like **LT** or **GT**.
In _HashableSource class need add more operations from **OP**.
https://github.com/coleifer/peewee/issues/2118#issuecomment-593150353_ | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2143/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2143/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2142 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2142/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2142/comments | https://api.github.com/repos/coleifer/peewee/issues/2142/events | https://github.com/coleifer/peewee/issues/2142 | 591,872,814 | MDU6SXNzdWU1OTE4NzI4MTQ= | 2,142 | SqliteDatabase + DateTimeField not working | {
"login": "COM8",
"id": 11741404,
"node_id": "MDQ6VXNlcjExNzQxNDA0",
"avatar_url": "https://avatars.githubusercontent.com/u/11741404?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/COM8",
"html_url": "https://github.com/COM8",
"followers_url": "https://api.github.com/users/COM8/followers",
"following_url": "https://api.github.com/users/COM8/following{/other_user}",
"gists_url": "https://api.github.com/users/COM8/gists{/gist_id}",
"starred_url": "https://api.github.com/users/COM8/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/COM8/subscriptions",
"organizations_url": "https://api.github.com/users/COM8/orgs",
"repos_url": "https://api.github.com/users/COM8/repos",
"events_url": "https://api.github.com/users/COM8/events{/privacy}",
"received_events_url": "https://api.github.com/users/COM8/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Too much typing...\r\n```Python\r\nexpires: DateTimeField(default=datetime.now(timezone.utc))\r\n```\r\nShould be:\r\n\r\n```Python\r\nexpires: DateTimeField = DateTimeField(default=datetime.now(timezone.utc))\r\n```"
] | 2020-04-01T12:20:21 | 2020-04-01T13:27:30 | 2020-04-01T13:27:29 | NONE | null | When you run the following example, it creates a DB and the `wnstoken` table but without the `expires` field.
```python
from peewee import *
from datetime import datetime, timezone
DB_PATH: str = "peeweeTest.db"
db: SqliteDatabase = SqliteDatabase(DB_PATH)
class WNSToken(Model):
token: CharField = CharField(unique=True)
expires: DateTimeField(default=datetime.now(timezone.utc))
class Meta:
database = db
print("Initalizing the DB...")
db.connect()
db.create_tables([WNSToken])
print("DB initialized.")
```
It looks like it's ignoring `DateTimeField`s. I tested this with multiple different combinations of fields and tables. As soon as a table includes a `DateTimeField`, it won't be created.
Inserting works, but also completely ignores the `DateTimeField`.
### Environment
* peewee: `3.13.2`
* Python3: `3.7.6`
### Resulting DB

| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2142/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2142/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2141 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2141/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2141/comments | https://api.github.com/repos/coleifer/peewee/issues/2141/events | https://github.com/coleifer/peewee/issues/2141 | 590,248,390 | MDU6SXNzdWU1OTAyNDgzOTA= | 2,141 | AttributeError: 'BackrefAccessor' object has no attribute 'replace' | {
"login": "smartstoic",
"id": 30124082,
"node_id": "MDQ6VXNlcjMwMTI0MDgy",
"avatar_url": "https://avatars.githubusercontent.com/u/30124082?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/smartstoic",
"html_url": "https://github.com/smartstoic",
"followers_url": "https://api.github.com/users/smartstoic/followers",
"following_url": "https://api.github.com/users/smartstoic/following{/other_user}",
"gists_url": "https://api.github.com/users/smartstoic/gists{/gist_id}",
"starred_url": "https://api.github.com/users/smartstoic/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/smartstoic/subscriptions",
"organizations_url": "https://api.github.com/users/smartstoic/orgs",
"repos_url": "https://api.github.com/users/smartstoic/repos",
"events_url": "https://api.github.com/users/smartstoic/events{/privacy}",
"received_events_url": "https://api.github.com/users/smartstoic/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Your `Symbol` exchange backref is stomping on your `Exchanges.exchange` field. Try renaming it to something more semantic:\r\n\r\n```python\r\n\r\nclass Symbols(Model):\r\n symbol = TextField(primary_key=True)\r\n # backref changed to \"symbols\", which is more accurate anyways.\r\n exchange = ForeignKeyField(Exchanges, backref='symbols', db_column='exchange')\r\n```",
"Thank you Sir ;)"
] | 2020-03-30T12:23:54 | 2020-03-30T15:16:00 | 2020-03-30T13:10:28 | NONE | null | Hello,
Thanks a lot for the amazing library.
I have the following issue:
```
import json
from peewee import *
def update_exchanges():
text = '{"exchange": "ADS","region": "AE","description": "Abu Dhabi Securities Exchange","mic": "XADS", "exchange_suffix": "-DH"}'
j = json.loads(text)
Exchanges.insert(j).on_conflict(conflict_target=Exchanges.exchange, preserve=[Exchanges.exchange]).execute()
class Exchanges(Model):
exchange = TextField(primary_key=True)
region = TextField(null=True)
description = TextField(null=True)
mic = TextField(null=True)
exchange_suffix = TextField(null=True)
class Symbols(Model):
symbol = TextField(primary_key=True)
exchange = ForeignKeyField(Exchanges, backref='exchange', db_column='exchange')
db = PostgresqlDatabase('test', user='postgres', password='tr1234', host='localhost', port=5432)
db.bind([Exchanges])
db.drop_tables([Exchanges])
db.create_tables([Exchanges])
update_exchanges()
```
The above fails with:
```
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Program Files\JetBrains\PyCharm Community Edition 2018.3.1\helpers\pydev\_pydev_bundle\pydev_umd.py", line 197, in runfile
pydev_imports.execfile(filename, global_vars, local_vars) # execute the script
File "C:\Program Files\JetBrains\PyCharm Community Edition 2018.3.1\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "C:/Users/Ioannis/.PyCharmCE2019.2/config/scratches/scratch_23.py", line 31, in <module>
update_exchanges()
File "C:/Users/Ioannis/.PyCharmCE2019.2/config/scratches/scratch_23.py", line 13, in update_exchanges
Exchanges.insert(j).on_conflict(conflict_target=Exchanges.exchange, preserve=[Exchanges.exchange]).execute()
File "D:\Projects\Trader\venv\lib\site-packages\peewee.py", line 1877, in inner
return method(self, database, *args, **kwargs)
File "D:\Projects\Trader\venv\lib\site-packages\peewee.py", line 1948, in execute
return self._execute(database)
File "D:\Projects\Trader\venv\lib\site-packages\peewee.py", line 2698, in _execute
return super(Insert, self)._execute(database)
File "D:\Projects\Trader\venv\lib\site-packages\peewee.py", line 2431, in _execute
cursor = self.execute_returning(database)
File "D:\Projects\Trader\venv\lib\site-packages\peewee.py", line 2438, in execute_returning
cursor = database.execute(self)
File "D:\Projects\Trader\venv\lib\site-packages\peewee.py", line 3102, in execute
sql, params = ctx.sql(query).query()
File "D:\Projects\Trader\venv\lib\site-packages\peewee.py", line 606, in sql
return obj.__sql__(self)
File "D:\Projects\Trader\venv\lib\site-packages\peewee.py", line 2687, in __sql__
update = self._on_conflict.get_conflict_update(ctx, self)
File "D:\Projects\Trader\venv\lib\site-packages\peewee.py", line 1831, in get_conflict_update
return ctx.state.conflict_update(self, query)
File "D:\Projects\Trader\venv\lib\site-packages\peewee.py", line 3862, in conflict_update
return self._build_on_conflict_update(oc, query)
File "D:\Projects\Trader\venv\lib\site-packages\peewee.py", line 3150, in _build_on_conflict_update
excluded = NodeList((SQL('EXCLUDED'), ensure_entity(column)),
File "D:\Projects\Trader\venv\lib\site-packages\peewee.py", line 384, in ensure_entity
return value if isinstance(value, Node) else Entity(value)
File "D:\Projects\Trader\venv\lib\site-packages\peewee.py", line 1466, in __init__
self._path = [part.replace('"', '""') for part in path if part]
File "D:\Projects\Trader\venv\lib\site-packages\peewee.py", line 1466, in <listcomp>
self._path = [part.replace('"', '""') for part in path if part]
AttributeError: 'BackrefAccessor' object has no attribute 'replace'
```
If I remove the Symbols model, then the operation is successful. It looks like the backref in the Symbols model is causing the problem.
Python 3.7.1 (default, Oct 28 2018, 08:39:03) [MSC v.1912 64 bit (AMD64)] on win32
Latest Postgres 12.2
Any help is appreciated.
Best regards
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2141/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2141/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2140 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2140/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2140/comments | https://api.github.com/repos/coleifer/peewee/issues/2140/events | https://github.com/coleifer/peewee/issues/2140 | 589,784,776 | MDU6SXNzdWU1ODk3ODQ3NzY= | 2,140 | chaining where clauses fails | {
"login": "fredrikchabot",
"id": 4558741,
"node_id": "MDQ6VXNlcjQ1NTg3NDE=",
"avatar_url": "https://avatars.githubusercontent.com/u/4558741?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/fredrikchabot",
"html_url": "https://github.com/fredrikchabot",
"followers_url": "https://api.github.com/users/fredrikchabot/followers",
"following_url": "https://api.github.com/users/fredrikchabot/following{/other_user}",
"gists_url": "https://api.github.com/users/fredrikchabot/gists{/gist_id}",
"starred_url": "https://api.github.com/users/fredrikchabot/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/fredrikchabot/subscriptions",
"organizations_url": "https://api.github.com/users/fredrikchabot/orgs",
"repos_url": "https://api.github.com/users/fredrikchabot/repos",
"events_url": "https://api.github.com/users/fredrikchabot/events{/privacy}",
"received_events_url": "https://api.github.com/users/fredrikchabot/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"There's something wrong with your code/models. Maybe you're using properties or something else? I've added a regression test which shows where-clause chaining works fine:\r\n\r\n9cc0d09c5810d02681ddc68097291e7005a8d13a",
"Running the same queries in cPython work.\r\n\r\nNothing special in the model.\r\n\r\nclass Plrgl(BaseModel):\r\n pln = ForeignKeyField(Plkop, db_column='pln', backref='plrgl')\r\n rgl = IntegerField()\r\n snr = IntegerField()\r\n niv = ForeignKeyField(Plwst, db_column='niv', backref='plrgl')\r\n\r\n ste = IntegerField(null=True)\r\n afd = ForeignKeyField(Dsafd, db_column='afd', backref='plrgl')\r\n dss = IntegerField(null=True)\r\n oms = CharField(null=True)\r\n std = CharField(null=True)\r\n end = CharField(null=True)\r\n frq = IntegerField(null=True)\r\n frs = IntegerField(null=True)\r\n wma = CharField(null=True)\r\n wdi = CharField(null=True)\r\n wwo = CharField(null=True)\r\n wdo = CharField(null=True)\r\n wvr = CharField(null=True)\r\n wza = CharField(null=True)\r\n wzo = CharField(null=True)\r\n mns = IntegerField(null=True)\r\n tyd = IntegerField(null=True)\r\n vla = IntegerField(null=True)\r\n vlb = IntegerField(null=True)\r\n vlc = IntegerField(null=True)\r\n vld = IntegerField(null=True)\r\n vle = IntegerField(null=True)\r\n f6lock = IntegerField(null=True)\r\n recordid = BigIntegerField(unique=True)\r\n\r\n class Meta:\r\n table_name = 'plrgl'\r\n indexes = (\r\n (('niv', 'pln', 'rgl', 'snr'), True),\r\n (('pln', 'dss', 'afd', 'niv', 'snr', 'rgl'), True),\r\n (('pln', 'niv', 'snr', 'rgl'), True),\r\n (('pln', 'rgl', 'snr', 'niv'), True),\r\n (('rgl', 'niv', 'snr', 'pln'), True),\r\n (('rgl', 'pln', 'ste', 'niv', 'snr'), True),\r\n )\r\n primary_key = CompositeKey('niv', 'pln', 'rgl', 'snr')\r\n\r\n",
"> the same queries in cPython work.\r\n\r\nThen I guess it's a bug in pypy."
] | 2020-03-29T12:50:49 | 2020-03-29T13:50:52 | 2020-03-29T13:14:51 | NONE | null | peewee 3.13.1
pypy 7.3.0
With debugging on:
>>> len(list(Plrgl().select().where(Plrgl.pln==14578)))
('SELECT "t1"."f6lock", "t1"."recordid", "t1"."pln", "t1"."rgl", "t1"."snr", "t1"."niv", "t1"."ste", "t1"."afd", "t
1"."dss", "t1"."oms", "t1"."std", "t1"."end", "t1"."frq", "t1"."frs", "t1"."wma", "t1"."wdi", "t1"."wwo", "t1"."wdo", "t1"."wvr", "t1"."wza", "t1"."wzo", "t1"."mns", "t1"."tyd", "t1"."vla", "t1"."vlb", "t1"."vlc", "t1"."vld", "t1"."vle" FROM "plrgl" AS "t1" WHERE ("t1"."pln" = %s)', [14578])
2
>>> len(list(Plrgl().select().where(Plrgl.pln==14578).where(Plrgl.rgl==2)))
('SELECT "t1"."f6lock", "t1"."recordid", "t1"."pln", "t1"."rgl", "t1"."snr", "t1"."niv", "t1"."ste", "t1"."afd", "t
1"."dss", "t1"."oms", "t1"."std", "t1"."end", "t1"."frq", "t1"."frs", "t1"."wma", "t1"."wdi", "t1"."wwo", "t1"."wdo", "t1"."wvr", "t1"."wza", "t1"."wzo", "t1"."mns", "t1"."tyd", "t1"."vla", "t1"."vlb", "t1"."vlc", "t1"."vld", "t1"."vle" FROM "plrgl" AS "t1" WHERE %s', [False])
0
>>> len(list(Plrgl().select().where(Plrgl.pln==14578))
('SELECT "t1"."f6lock", "t1"."recordid", "t1"."pln", "t1"."rgl", "t1"."snr", "t1"."niv", "t1"."ste", "t1"."afd", "t
1"."dss", "t1"."oms", "t1"."std", "t1"."end", "t1"."frq", "t1"."frs", "t1"."wma", "t1"."wdi", "t1"."wwo", "t1"."wdo", "t1"."wvr", "t1"."wza", "t1"."wzo", "t1"."mns", "t1"."tyd", "t1"."vla", "t1"."vlb", "t1"."vlc", "t1"."vld", "t1"."vle" FROM "plrgl" AS "t1" WHERE %s', [False])
0
And **any** query after that fails.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2140/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2140/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2139 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2139/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2139/comments | https://api.github.com/repos/coleifer/peewee/issues/2139/events | https://github.com/coleifer/peewee/issues/2139 | 589,515,367 | MDU6SXNzdWU1ODk1MTUzNjc= | 2,139 | database.execute_sql('PRAGMA foreign_keys = 1;') not working | {
"login": "ldconejo",
"id": 5453372,
"node_id": "MDQ6VXNlcjU0NTMzNzI=",
"avatar_url": "https://avatars.githubusercontent.com/u/5453372?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/ldconejo",
"html_url": "https://github.com/ldconejo",
"followers_url": "https://api.github.com/users/ldconejo/followers",
"following_url": "https://api.github.com/users/ldconejo/following{/other_user}",
"gists_url": "https://api.github.com/users/ldconejo/gists{/gist_id}",
"starred_url": "https://api.github.com/users/ldconejo/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/ldconejo/subscriptions",
"organizations_url": "https://api.github.com/users/ldconejo/orgs",
"repos_url": "https://api.github.com/users/ldconejo/repos",
"events_url": "https://api.github.com/users/ldconejo/events{/privacy}",
"received_events_url": "https://api.github.com/users/ldconejo/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"So some database pragmas have to be executed once, before any tables are created (journal_mode for example). Other pragmas, like \"foreign_keys\", have to be issued at the start of every connection. The recommended way to do this with peewee is to declare your pragmas as part of your db constructor:\r\n\r\n```python\r\n\r\n# Ensure foreign_keys pragma is set on every connection.\r\ndb = SqliteDatabase('my_app.db', pragmas={'foreign_keys': 1})\r\n```\r\n\r\nIn my testing the pragma works just fine when executed manually via `execute_sql()`. See:\r\n\r\n```python\r\n\r\nfrom peewee import *\r\n\r\ndb = SqliteDatabase(':memory:')\r\n\r\nclass User(Model):\r\n username = TextField()\r\n class Meta:\r\n database = db\r\n\r\nclass Tweet(Model):\r\n user = ForeignKeyField(User, backref='tweets', on_delete='cascade')\r\n content = TextField()\r\n class Meta:\r\n database = db\r\n\r\ndb.execute_sql('pragma foreign_keys=0')\r\ndb.create_tables([User, Tweet])\r\n\r\nu1 = User.create(username='u1')\r\nu2 = User.create(username='u2')\r\nTweet.create(user=u1, content='u1-t1')\r\nTweet.create(user=u2, content='u2-t1')\r\n\r\ninvalid_user = User(username='u3', id=999)\r\nTweet.create(user=invalid_user, content='invalid-user')\r\n\r\n# Deleting a user will not delete the referenced tweets.\r\nUser.delete().where(User.username == 'u1').execute()\r\nassert Tweet.select().count() == 3\r\n\r\ndb.execute_sql('pragma foreign_keys=1')\r\n\r\nUser.delete().where(User.username == 'u2').execute()\r\nassert Tweet.select().count() == 2\r\n\r\ntry:\r\n Tweet.create(user=invalid_user, content='this fails')\r\nexcept IntegrityError:\r\n pass\r\nelse:\r\n assert False, 'should not be able to create invalid fk ref'\r\n```"
] | 2020-03-28T05:52:20 | 2020-03-28T15:03:44 | 2020-03-28T15:03:18 | NONE | null | Hi,
I teach a Python class in which we use Peewee for implementing SQL databases in Python, given how straightforward it is to use.
One of my students recently pointed out that the foreign key constraints in one of the class examples were not working.
How to reproduce:
1. Run _personjob_learning_v3_p1.py_: Initializes the database with _person_ and _job_ tables. Populates the _person_ table.
2. Run _personjob_learning_v5_p1.py_: Populates the _job_ table.
3. Run _personjob_learning_v5_p5.py_: Deletes _person_ "Andrew" from the _person_ table, which should fail since there are entries with "Andrew" as a foreign key in the _job_ table. However, the deletion goes through.
The code uses this line to activate foreign key constraints after every _database.connect()_:
`database.execute_sql('PRAGMA foreign_keys = 1;')`
I think the command above no longer works. A workaround is replacing the line above in _person_model.py_ (line 22) with the following:
`database.pragma('foreign_keys', 1, permanent=True)`
I'm selecting _permanent=True_ so that I only need to make the change there, otherwise it needs to be made after every _database.connect()_
[peewee_issue_example.zip](https://github.com/coleifer/peewee/files/4396687/peewee_issue_example.zip)
Regards,
Luis
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2139/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2139/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2138 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2138/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2138/comments | https://api.github.com/repos/coleifer/peewee/issues/2138/events | https://github.com/coleifer/peewee/issues/2138 | 589,016,595 | MDU6SXNzdWU1ODkwMTY1OTU= | 2,138 | About release! | {
"login": "funny-95",
"id": 27837489,
"node_id": "MDQ6VXNlcjI3ODM3NDg5",
"avatar_url": "https://avatars.githubusercontent.com/u/27837489?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/funny-95",
"html_url": "https://github.com/funny-95",
"followers_url": "https://api.github.com/users/funny-95/followers",
"following_url": "https://api.github.com/users/funny-95/following{/other_user}",
"gists_url": "https://api.github.com/users/funny-95/gists{/gist_id}",
"starred_url": "https://api.github.com/users/funny-95/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/funny-95/subscriptions",
"organizations_url": "https://api.github.com/users/funny-95/orgs",
"repos_url": "https://api.github.com/users/funny-95/repos",
"events_url": "https://api.github.com/users/funny-95/events{/privacy}",
"received_events_url": "https://api.github.com/users/funny-95/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Thanks for the nudge.\r\n\r\nhttps://github.com/coleifer/peewee/releases/tag/3.13.2"
] | 2020-03-27T09:57:29 | 2020-03-27T16:52:30 | 2020-03-27T16:52:30 | NONE | null | Excuse me! Can i ask when the latest version will be released! | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2138/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2138/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2137 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2137/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2137/comments | https://api.github.com/repos/coleifer/peewee/issues/2137/events | https://github.com/coleifer/peewee/issues/2137 | 585,316,363 | MDU6SXNzdWU1ODUzMTYzNjM= | 2,137 | Python 3.8.0 : reduce is not defined | {
"login": "caryfitzhugh",
"id": 445848,
"node_id": "MDQ6VXNlcjQ0NTg0OA==",
"avatar_url": "https://avatars.githubusercontent.com/u/445848?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/caryfitzhugh",
"html_url": "https://github.com/caryfitzhugh",
"followers_url": "https://api.github.com/users/caryfitzhugh/followers",
"following_url": "https://api.github.com/users/caryfitzhugh/following{/other_user}",
"gists_url": "https://api.github.com/users/caryfitzhugh/gists{/gist_id}",
"starred_url": "https://api.github.com/users/caryfitzhugh/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/caryfitzhugh/subscriptions",
"organizations_url": "https://api.github.com/users/caryfitzhugh/orgs",
"repos_url": "https://api.github.com/users/caryfitzhugh/repos",
"events_url": "https://api.github.com/users/caryfitzhugh/events{/privacy}",
"received_events_url": "https://api.github.com/users/caryfitzhugh/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"> Running with python 3.8.0 I run into errors where 'reduce is not defined'.\r\n> \r\n> In looking at it peewee.py assumes that if you can\r\n> \r\n> ```python\r\n> from collections.abc import Callable\r\n> ```\r\n> \r\n> then you don't need to import reduce.\r\n> \r\n> In my environment at least, that is not accurate.\r\n> \r\n> At the top of peewee.py (around line 192 in my latest version) - could we drop in this snippet?\r\n> \r\n> ```python\r\n> try:\r\n> reduce\r\n> except NameError:\r\n> from functools import reduce\r\n> ```\r\nin python 3,reduce are moved to functools module.you can use this snippet\r\n",
"You must be using an old version of Peewee. For quite a long time it's had `from functools import reduce`.",
"https://github.com/coleifer/peewee/blob/master/peewee.py#L172",
"apologies.. I checked I was running the latest code, but - in debugging something else in that file I think my auto-save in vim reformatted some imports, and \"fixed\" the indentation on that one line without me knowing... Apologies again. Thanks - all seems to work now."
] | 2020-03-20T20:41:26 | 2020-03-21T23:56:30 | 2020-03-21T12:08:42 | NONE | null | Running with python 3.8.0 I run into errors where 'reduce is not defined'.
In looking at it peewee.py assumes that if you can
```python
from collections.abc import Callable
```
then you don't need to import reduce.
In my environment at least, that is not accurate.
At the top of peewee.py (around line 192 in my latest version) - could we drop in this snippet?
```python
try:
reduce
except NameError:
from functools import reduce
``` | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2137/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2137/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2136 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2136/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2136/comments | https://api.github.com/repos/coleifer/peewee/issues/2136/events | https://github.com/coleifer/peewee/issues/2136 | 583,899,584 | MDU6SXNzdWU1ODM4OTk1ODQ= | 2,136 | Question on INSERT ON DUPLICATE KEY UPDATE | {
"login": "eely22",
"id": 4094985,
"node_id": "MDQ6VXNlcjQwOTQ5ODU=",
"avatar_url": "https://avatars.githubusercontent.com/u/4094985?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/eely22",
"html_url": "https://github.com/eely22",
"followers_url": "https://api.github.com/users/eely22/followers",
"following_url": "https://api.github.com/users/eely22/following{/other_user}",
"gists_url": "https://api.github.com/users/eely22/gists{/gist_id}",
"starred_url": "https://api.github.com/users/eely22/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/eely22/subscriptions",
"organizations_url": "https://api.github.com/users/eely22/orgs",
"repos_url": "https://api.github.com/users/eely22/repos",
"events_url": "https://api.github.com/users/eely22/events{/privacy}",
"received_events_url": "https://api.github.com/users/eely22/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Ok, nevermind, I figured it out. I just had the syntax wrong, this is it: \r\n\r\n```\r\nCarrierRateModel.insert_many([model_to_dict(r) for r in rates[i:i + bulk_size]]).on_conflict(\r\n update={\r\n CarrierRateModel.updated: (CarrierRateModel.rate != fn.VALUES(CarrierRateModel.rate)),\r\n CarrierRateModel.rate: fn.VALUES(CarrierRateModel.rate)\r\n }\r\n ).execute()\r\n```"
] | 2020-03-18T17:44:24 | 2020-03-18T19:38:17 | 2020-03-18T19:38:16 | NONE | null | This is more of a question than an issue as I am unsure of how to do something. I have a simple table like this:
```
class CarrierRateModel(Model):
age = DoubleField(null=True)
rate = DoubleField(null=True)
rate_set_id = CharField(null=False, index=True)
updated = BooleanField(default=False, index=True)
class Meta:
db_table = 'rate'
# each rate should be unique to the rate set and age. this allows us to update rates later
primary_key = CompositeKey('age', 'rate_set_id')
```
I am using the insert function to then upsert into this table. What I want to do is insert many rows and if the rate column changes when there is a duplicate, set the updated flag to True. In SQL, I would do it as such:
```
INSERT INTO rate (age, rate, rate_set_id, updated)
VALUES (1.0, 3.0, 'abc123', 0)
ON DUPLICATE KEY UPDATE updated = (rate != VALUES(rate) ), rate=VALUES(rate);
```
This works. It will insert into the table, if there is a duplicate it sets the rate to the new rate and the update flag to true if the new rate didn't equal the old one.
How would I do this with peewee? Reading through the docs, I had thought the [EXCLUDED helper](http://docs.peewee-orm.com/en/latest/peewee/api.html#EXCLUDED) was the way to go, so I tried this:
```
CarrierRateModel.insert(age=rate.age, rate=rate.rate, rate_set_id=rate.rate_set_id).on_conflict(
update={
CarrierRateModel.rate: EXCLUDED.rate,
CarrierRateModel.updated: CarrierRateModel.rate != EXCLUDED.rate
}
).execute()
```
But I just get the error:
```
pymysql.err.InternalError: (1054, "Unknown column 'EXCLUDED.rate' in 'field list'")
```
I am not quite sure what the EXCLUDED helper is supposed to do or how it works. Am I using this correctly? Is this not the right approach?
I even tried to be more literal and use fn.VALUES, but this just throws a SQL syntax error:
```
CarrierRateModel.insert(age=rate.age, rate=rate.rate, rate_set_id=rate.rate_set_id).on_conflict(
update={
CarrierRateModel.rate: fn.VALUES(rate),
CarrierRateModel.updated: CarrierRateModel.rate != fn.VALUES(rate)
}
).execute()
```
How would I replicate that SQL? If I try to use any of the conflict_* parameters in on_conflict, I just get this:
```
MySQL does not support the specification of where clauses or conflict targets for conflict resolution.
```
I am using MariaDB 10.3.20 and peewee 3.13.1 | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2136/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2136/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2135 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2135/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2135/comments | https://api.github.com/repos/coleifer/peewee/issues/2135/events | https://github.com/coleifer/peewee/pull/2135 | 583,325,637 | MDExOlB1bGxSZXF1ZXN0MzkwMTAwMzU1 | 2,135 | Fix some deprecation warnings when using \s or \w on non-raw strings | {
"login": "kraptor",
"id": 7249728,
"node_id": "MDQ6VXNlcjcyNDk3Mjg=",
"avatar_url": "https://avatars.githubusercontent.com/u/7249728?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/kraptor",
"html_url": "https://github.com/kraptor",
"followers_url": "https://api.github.com/users/kraptor/followers",
"following_url": "https://api.github.com/users/kraptor/following{/other_user}",
"gists_url": "https://api.github.com/users/kraptor/gists{/gist_id}",
"starred_url": "https://api.github.com/users/kraptor/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/kraptor/subscriptions",
"organizations_url": "https://api.github.com/users/kraptor/orgs",
"repos_url": "https://api.github.com/users/kraptor/repos",
"events_url": "https://api.github.com/users/kraptor/events{/privacy}",
"received_events_url": "https://api.github.com/users/kraptor/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Let me know if you want the commit squashed or not..."
] | 2020-03-17T22:02:38 | 2020-03-17T23:46:26 | 2020-03-17T23:46:26 | CONTRIBUTOR | null | Fixes #2134 | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2135/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2135/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/2135",
"html_url": "https://github.com/coleifer/peewee/pull/2135",
"diff_url": "https://github.com/coleifer/peewee/pull/2135.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/2135.patch",
"merged_at": "2020-03-17T23:46:26"
} |
https://api.github.com/repos/coleifer/peewee/issues/2134 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2134/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2134/comments | https://api.github.com/repos/coleifer/peewee/issues/2134/events | https://github.com/coleifer/peewee/issues/2134 | 583,325,265 | MDU6SXNzdWU1ODMzMjUyNjU= | 2,134 | Fix some deprecation warnings on regular expressions | {
"login": "kraptor",
"id": 7249728,
"node_id": "MDQ6VXNlcjcyNDk3Mjg=",
"avatar_url": "https://avatars.githubusercontent.com/u/7249728?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/kraptor",
"html_url": "https://github.com/kraptor",
"followers_url": "https://api.github.com/users/kraptor/followers",
"following_url": "https://api.github.com/users/kraptor/following{/other_user}",
"gists_url": "https://api.github.com/users/kraptor/gists{/gist_id}",
"starred_url": "https://api.github.com/users/kraptor/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/kraptor/subscriptions",
"organizations_url": "https://api.github.com/users/kraptor/orgs",
"repos_url": "https://api.github.com/users/kraptor/repos",
"events_url": "https://api.github.com/users/kraptor/events{/privacy}",
"received_events_url": "https://api.github.com/users/kraptor/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2020-03-17T22:01:52 | 2020-03-17T23:46:26 | 2020-03-17T23:46:26 | CONTRIBUTOR | null | While testing my project, I came across some deprecation warnings in Peewee where \s and \w are used on non-raw strings. Sending a pull request in a minute... | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2134/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2134/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2133 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2133/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2133/comments | https://api.github.com/repos/coleifer/peewee/issues/2133/events | https://github.com/coleifer/peewee/issues/2133 | 583,152,712 | MDU6SXNzdWU1ODMxNTI3MTI= | 2,133 | JSONField.concat always uses json.dumps on parameters | {
"login": "crvv",
"id": 6398635,
"node_id": "MDQ6VXNlcjYzOTg2MzU=",
"avatar_url": "https://avatars.githubusercontent.com/u/6398635?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/crvv",
"html_url": "https://github.com/crvv",
"followers_url": "https://api.github.com/users/crvv/followers",
"following_url": "https://api.github.com/users/crvv/following{/other_user}",
"gists_url": "https://api.github.com/users/crvv/gists{/gist_id}",
"starred_url": "https://api.github.com/users/crvv/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/crvv/subscriptions",
"organizations_url": "https://api.github.com/users/crvv/orgs",
"repos_url": "https://api.github.com/users/crvv/repos",
"events_url": "https://api.github.com/users/crvv/events{/privacy}",
"received_events_url": "https://api.github.com/users/crvv/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Thanks, this is fixed."
] | 2020-03-17T16:48:39 | 2020-03-17T18:00:22 | 2020-03-17T18:00:18 | NONE | null | ```Python
from peewee import Model, PostgresqlDatabase
from playhouse.postgres_ext import BinaryJSONField
database = PostgresqlDatabase(database='postgres', autoconnect=True)
class Test(Model):
x = BinaryJSONField(index=False)
y = BinaryJSONField(index=False)
class Meta:
database = database
q = Test.select(Test.x.concat(Test.y)).dicts()
print(list(q))
```
This raises exception `TypeError: Object of type BinaryJSONField is not JSON serializable`. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2133/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2133/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2132 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2132/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2132/comments | https://api.github.com/repos/coleifer/peewee/issues/2132/events | https://github.com/coleifer/peewee/pull/2132 | 580,650,122 | MDExOlB1bGxSZXF1ZXN0Mzg3ODE3NTgw | 2,132 | ensure extracting Field instance from Function arguments | {
"login": "kamilkozik7",
"id": 26979805,
"node_id": "MDQ6VXNlcjI2OTc5ODA1",
"avatar_url": "https://avatars.githubusercontent.com/u/26979805?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/kamilkozik7",
"html_url": "https://github.com/kamilkozik7",
"followers_url": "https://api.github.com/users/kamilkozik7/followers",
"following_url": "https://api.github.com/users/kamilkozik7/following{/other_user}",
"gists_url": "https://api.github.com/users/kamilkozik7/gists{/gist_id}",
"starred_url": "https://api.github.com/users/kamilkozik7/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/kamilkozik7/subscriptions",
"organizations_url": "https://api.github.com/users/kamilkozik7/orgs",
"repos_url": "https://api.github.com/users/kamilkozik7/repos",
"events_url": "https://api.github.com/users/kamilkozik7/events{/privacy}",
"received_events_url": "https://api.github.com/users/kamilkozik7/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I'm going to pass. If you have complicated nesting and need a special conversion, just specify a `python_value()` converter to the `fn.(...)`."
] | 2020-03-13T14:50:19 | 2020-03-14T23:51:34 | 2020-03-14T23:51:34 | NONE | null | when the Function is nested in another Function in _initialize_columns method of class BaseModelCursorWrapper | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2132/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2132/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/2132",
"html_url": "https://github.com/coleifer/peewee/pull/2132",
"diff_url": "https://github.com/coleifer/peewee/pull/2132.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/2132.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/2131 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2131/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2131/comments | https://api.github.com/repos/coleifer/peewee/issues/2131/events | https://github.com/coleifer/peewee/issues/2131 | 579,232,817 | MDU6SXNzdWU1NzkyMzI4MTc= | 2,131 | How to use composite type as function argument (PostgresQL) | {
"login": "zmwangx",
"id": 4149852,
"node_id": "MDQ6VXNlcjQxNDk4NTI=",
"avatar_url": "https://avatars.githubusercontent.com/u/4149852?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/zmwangx",
"html_url": "https://github.com/zmwangx",
"followers_url": "https://api.github.com/users/zmwangx/followers",
"following_url": "https://api.github.com/users/zmwangx/following{/other_user}",
"gists_url": "https://api.github.com/users/zmwangx/gists{/gist_id}",
"starred_url": "https://api.github.com/users/zmwangx/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/zmwangx/subscriptions",
"organizations_url": "https://api.github.com/users/zmwangx/orgs",
"repos_url": "https://api.github.com/users/zmwangx/repos",
"events_url": "https://api.github.com/users/zmwangx/events{/privacy}",
"received_events_url": "https://api.github.com/users/zmwangx/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I believe this is fixed, thanks for the report.",
"It works now, thanks."
] | 2020-03-11T12:36:03 | 2020-03-12T01:46:44 | 2020-03-11T15:19:13 | CONTRIBUTOR | null | PostgresQL supports composite types (e.g. row types) as function arguments, but I can't figure out how to use a model as an argument of a `peewee.fn.func`.
Say we have this schema
```sql
CREATE TABLE IF NOT EXISTS post (
id INTEGER NOT NULL PRIMARY KEY,
votes INTEGER NOT NULL,
posted TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP
);
```
and a function
```sql
CREATE OR REPLACE FUNCTION score(post)
RETURNS double precision
AS $$ SELECT $1.votes / EXTRACT(EPOCH FROM now() - $1.posted); $$
LANGUAGE SQL
STABLE;
```
we want to build this query:
```sql
SELECT id, score(post) FROM post;
```
How do we approach this?
I cannot use the model `Post` as an argument to `peewee.fn.score`:
```py
Post.select(Post.id, fn.score(Post))
# => peewee.ProgrammingError: can't adapt type 'ModelBase'
```
even `SQL` doesn't work unless I force an alias on the model:
```py
Post.select(Post.id, SQL("score(post)"))
# peewee.ProgrammingError: column "post" does not exist (because 'FROM "post" AS "t1"' in the constructed query)
```
```py
Post_ = Post.alias("post")
Post_.select(Post_.id, SQL("score(post)"))
# This one works.
```
I'm currently using the workaround above. Is there any better way to achieve this? Sorry if I missed something in the docs, I think I scoured every corner. (And sorry for the barrage of issues I've opened recently.) | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2131/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2131/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2130 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2130/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2130/comments | https://api.github.com/repos/coleifer/peewee/issues/2130/events | https://github.com/coleifer/peewee/issues/2130 | 578,821,121 | MDU6SXNzdWU1Nzg4MjExMjE= | 2,130 | Clarify PostgresqlMigrator.set_search_path in docs | {
"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 | [
"Can you give an example of what you mean? I would have thought that the setting of `schema` on models would have been adequate, and that the migration methods would take the schema into consideration, though I may be wrong.",
"I may be misunderstanding how it's supposed to work but I'd guess that if I do\r\n\r\n```python\r\n selected_field = peewee.BooleanField(default=True, null=False)\r\n migrator = PostgresqlMigrator(database)\r\n migrate(migrator.add_column('temp_guide', 'selected', selected_field))\r\n```\r\n\r\nand the `temp_guide` table is in a schema called `sandbox` that won't work because at any point I'm passing the `TempGuide` model to the migrator. Instead, doing\r\n\r\n```python\r\n selected_field = peewee.BooleanField(default=True, null=False)\r\n migrator = PostgresqlMigrator(database)\r\n migrate(\r\n migrator.set_search_path('sandbox'),\r\n migrator.add_column('temp_guide', 'selected', selected_field)\r\n)\r\n```\r\n\r\nworks fine. But it took me a bit to realise that `migrator.set_search_path('sandbox')` had to be inside the `migrate` function.\r\n\r\nNot saying that there's anything wrong per se in the docs, but it could be made a bit clearer.",
"Thanks, added a note."
] | 2020-03-10T19:49:14 | 2020-03-11T16:10:35 | 2020-03-11T16:10:29 | NONE | null | It may be beneficial to make a bit more clear that `PostgresqlMigrator.set_search_path` needs to be added to `migrate` for it to take effect. That may be obvious in hindsight but because of the way it's presented in the docs API it took me a good while to realise that. An example in the main section of the Schema Migration docs would be useful. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2130/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2130/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2129 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2129/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2129/comments | https://api.github.com/repos/coleifer/peewee/issues/2129/events | https://github.com/coleifer/peewee/issues/2129 | 578,484,544 | MDU6SXNzdWU1Nzg0ODQ1NDQ= | 2,129 | Python descriptor protocol support for correct attribute injection | {
"login": "dimma837",
"id": 31541891,
"node_id": "MDQ6VXNlcjMxNTQxODkx",
"avatar_url": "https://avatars.githubusercontent.com/u/31541891?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/dimma837",
"html_url": "https://github.com/dimma837",
"followers_url": "https://api.github.com/users/dimma837/followers",
"following_url": "https://api.github.com/users/dimma837/following{/other_user}",
"gists_url": "https://api.github.com/users/dimma837/gists{/gist_id}",
"starred_url": "https://api.github.com/users/dimma837/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/dimma837/subscriptions",
"organizations_url": "https://api.github.com/users/dimma837/orgs",
"repos_url": "https://api.github.com/users/dimma837/repos",
"events_url": "https://api.github.com/users/dimma837/events{/privacy}",
"received_events_url": "https://api.github.com/users/dimma837/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2020-03-10T10:37:42 | 2020-03-10T13:44:01 | 2020-03-10T13:44:01 | NONE | null | Hi,
I use peewee ORM with python [dependency injection framework](https://github.com/ivankorobkov/python-inject) for database instance injection. But peewee does not implement Python descriptor protocol on class attributes access, so it does not work in conjunction with DI.
I described this problem including code examples and exception traceback to the author of the DI framework, and he said that it's peewee concern.
ivankorobkov/python-inject#49
Can you implement it? Or maybe there are other workarounds? | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2129/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2129/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2128 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2128/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2128/comments | https://api.github.com/repos/coleifer/peewee/issues/2128/events | https://github.com/coleifer/peewee/pull/2128 | 577,751,562 | MDExOlB1bGxSZXF1ZXN0Mzg1NDYwMTM2 | 2,128 | Fix URL to Flask Application Factories and typos. | {
"login": "Jo-Con-El",
"id": 607909,
"node_id": "MDQ6VXNlcjYwNzkwOQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/607909?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/Jo-Con-El",
"html_url": "https://github.com/Jo-Con-El",
"followers_url": "https://api.github.com/users/Jo-Con-El/followers",
"following_url": "https://api.github.com/users/Jo-Con-El/following{/other_user}",
"gists_url": "https://api.github.com/users/Jo-Con-El/gists{/gist_id}",
"starred_url": "https://api.github.com/users/Jo-Con-El/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/Jo-Con-El/subscriptions",
"organizations_url": "https://api.github.com/users/Jo-Con-El/orgs",
"repos_url": "https://api.github.com/users/Jo-Con-El/repos",
"events_url": "https://api.github.com/users/Jo-Con-El/events{/privacy}",
"received_events_url": "https://api.github.com/users/Jo-Con-El/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Thx ghibli bro."
] | 2020-03-09T08:58:50 | 2020-03-09T13:10:20 | 2020-03-09T13:10:08 | CONTRIBUTOR | null | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2128/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2128/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/2128",
"html_url": "https://github.com/coleifer/peewee/pull/2128",
"diff_url": "https://github.com/coleifer/peewee/pull/2128.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/2128.patch",
"merged_at": "2020-03-09T13:10:08"
} |
|
https://api.github.com/repos/coleifer/peewee/issues/2127 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2127/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2127/comments | https://api.github.com/repos/coleifer/peewee/issues/2127/events | https://github.com/coleifer/peewee/issues/2127 | 577,334,232 | MDU6SXNzdWU1NzczMzQyMzI= | 2,127 | KeyError in ModelCursorWrapper.process_row when joining a subquery | {
"login": "zmwangx",
"id": 4149852,
"node_id": "MDQ6VXNlcjQxNDk4NTI=",
"avatar_url": "https://avatars.githubusercontent.com/u/4149852?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/zmwangx",
"html_url": "https://github.com/zmwangx",
"followers_url": "https://api.github.com/users/zmwangx/followers",
"following_url": "https://api.github.com/users/zmwangx/following{/other_user}",
"gists_url": "https://api.github.com/users/zmwangx/gists{/gist_id}",
"starred_url": "https://api.github.com/users/zmwangx/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/zmwangx/subscriptions",
"organizations_url": "https://api.github.com/users/zmwangx/orgs",
"repos_url": "https://api.github.com/users/zmwangx/repos",
"events_url": "https://api.github.com/users/zmwangx/events{/privacy}",
"received_events_url": "https://api.github.com/users/zmwangx/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Thanks for the excellent report. This *should* work, but currently it seems to be running into an edge-case that is proving to be difficult to work around right now.\r\n\r\nI'll work-up a fix, but for now I'd suggest using the \".objects()\" helper, which will patch all the selected values onto a single model instance. Peewee is throwing the error because it sees you've got some User and Entry columns, which are joined by a foreign-key, but it's having trouble resolving the graph because the selected fields are from a subquery rather than the model instance itself... It should work, but I need to dig into it.\r\n\r\nSo for now, I'd suggest:\r\n\r\n```python\r\nUser.select(subquery.c.id, subquery.c.name, Entry.content)\r\n .from_(subquery)\r\n .join(Entry, on=(Entry.user_id == subquery.c.id))\r\n .objects() # <-- this\r\n```",
"Thanks for looking into this and suggesting a workaround. In my case, `.namedtuples()` and `.objects()` work equally well and there was no disruption to my work other than a short period of confusion about the error, so no biggie.",
"As I'm digging into this, I think I may just mark this as a known limitation for the time being. The issue occurs under the following conditions, as far as I can tell:\r\n\r\n* issue a model-select, e.g. `ModelClass.select()`\r\n* explicitly override the `from_()` with a subquery, where the subquery model is the same as the model the `select()` was called using.\r\n* include one or more joins\r\n\r\nIt's tricky because when you select \"from\" a model, Peewee assumes it will be returning instances of that model (e.g., `User` rows). The user rows, however, are mapped to a subquery. Since peewee also supports selecting from subqueries, it is having trouble coordinating the implication that you want the subquery columns to be placed on the \"outer\" user object.\r\n\r\nThe workarounds described are recommended if you need this construction, but depending on your actual query, there are probably other ways or expressing an equivalent query that wouldn't trigger these kinds of edge-cases. If you want help with a particular query, let me know."
] | 2020-03-07T13:22:00 | 2020-03-10T21:34:48 | 2020-03-10T21:34:11 | CONTRIBUTOR | null | I'm getting a strange error with `ModelCursorWrapper.process_row` when joining a subquery. When the select is built from the subquery's "perspective" instead of a model's, the generated SQL is all good but processing the returned results fail. Here's a simplified example:
```python
import logging
import peewee
db = peewee.SqliteDatabase(":memory:")
class _BaseModel(peewee.Model):
class Meta:
database = db
class User(_BaseModel):
name = peewee.TextField()
class Entry(_BaseModel):
user = peewee.ForeignKeyField(User)
content = peewee.TextField()
def main():
db.create_tables([User, Entry])
User.insert(name="foo").execute()
Entry.insert(user_id=1, content="bar").execute()
logger = logging.getLogger("peewee")
logger.addHandler(logging.StreamHandler())
logger.setLevel(logging.DEBUG)
subquery = User.select(User.id, User.name).where(User.name == "foo").alias("blah")
print(
list(
Entry.select(subquery.c.id, subquery.c.name, Entry.content).join(
subquery, on=(Entry.user_id == subquery.c.id)
)
)
) # Works
print(
list(
User.select(subquery.c.id, subquery.c.name, Entry.content)
.from_(subquery)
.join(Entry, on=(Entry.user_id == subquery.c.id))
.namedtuples()
)
) # Works
print(
list(
User.select(subquery.c.id, subquery.c.name, Entry.content)
.from_(subquery)
.join(Entry, on=(Entry.user_id == subquery.c.id))
)
) # Fails in ModelCursorWrapper.process_row
if __name__ == "__main__":
main()
```
Output:
```sql
('SELECT "blah"."id", "blah"."name", "t1"."content" FROM "entry" AS "t1" INNER JOIN (SELECT "t2"."id", "t2"."name" FROM "user" AS "t2" WHERE ("t2"."name" = ?)) AS "blah" ON ("t1"."user_id" = "blah"."id")', ['foo'])
[<Entry: None>]
('SELECT "blah"."id", "blah"."name", "t1"."content" FROM (SELECT "t2"."id", "t2"."name" FROM "user" AS "t2" WHERE ("t2"."name" = ?)) AS "blah" INNER JOIN "entry" AS "t1" ON ("t1"."user_id" = "blah"."id")', ['foo'])
[Row(id=1, name='foo', content='bar')]
('SELECT "blah"."id", "blah"."name", "t1"."content" FROM (SELECT "t2"."id", "t2"."name" FROM "user" AS "t2" WHERE ("t2"."name" = ?)) AS "blah" INNER JOIN "entry" AS "t1" ON ("t1"."user_id" = "blah"."id")', ['foo'])
```
```python-traceback
Traceback (most recent call last):
File "/tmp/q.py", line 58, in <module>
main()
File "/tmp/q.py", line 49, in main
list(
File "/Users/zmwang/.pyenv/versions/3.8.0/lib/python3.8/site-packages/peewee.py", line 1914, in __len__
return len(self._cursor_wrapper)
File "/Users/zmwang/.pyenv/versions/3.8.0/lib/python3.8/site-packages/peewee.py", line 4127, in __len__
self.fill_cache()
File "/Users/zmwang/.pyenv/versions/3.8.0/lib/python3.8/site-packages/peewee.py", line 4168, in fill_cache
iterator.next()
File "/Users/zmwang/.pyenv/versions/3.8.0/lib/python3.8/site-packages/peewee.py", line 4224, in next
self.cursor_wrapper.iterate()
File "/Users/zmwang/.pyenv/versions/3.8.0/lib/python3.8/site-packages/peewee.py", line 4143, in iterate
result = self.process_row(row)
File "/Users/zmwang/.pyenv/versions/3.8.0/lib/python3.8/site-packages/peewee.py", line 7339, in process_row
instance = objects[key]
KeyError: <peewee.ModelSelect object at 0x10b31ce50>
```
Is this a bug or a limitation that I shouldn't have touched? | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2127/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2127/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2126 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2126/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2126/comments | https://api.github.com/repos/coleifer/peewee/issues/2126/events | https://github.com/coleifer/peewee/pull/2126 | 576,279,643 | MDExOlB1bGxSZXF1ZXN0Mzg0Mjk2Njg0 | 2,126 | Improve reflection for AutoField/IntegerField | {
"login": "ilyakamens",
"id": 3293811,
"node_id": "MDQ6VXNlcjMyOTM4MTE=",
"avatar_url": "https://avatars.githubusercontent.com/u/3293811?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/ilyakamens",
"html_url": "https://github.com/ilyakamens",
"followers_url": "https://api.github.com/users/ilyakamens/followers",
"following_url": "https://api.github.com/users/ilyakamens/following{/other_user}",
"gists_url": "https://api.github.com/users/ilyakamens/gists{/gist_id}",
"starred_url": "https://api.github.com/users/ilyakamens/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/ilyakamens/subscriptions",
"organizations_url": "https://api.github.com/users/ilyakamens/orgs",
"repos_url": "https://api.github.com/users/ilyakamens/repos",
"events_url": "https://api.github.com/users/ilyakamens/events{/privacy}",
"received_events_url": "https://api.github.com/users/ilyakamens/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I'm going to pass on this for now, but may reconsider it at some point."
] | 2020-03-05T14:08:38 | 2022-08-23T02:15:20 | 2020-03-10T14:56:52 | CONTRIBUTOR | null | Specifically, don't assume `IntegerField(primary_key=True)` is an `AutoField()` if the database isn't SQLite.
See https://github.com/coleifer/peewee/issues/2124 for more context. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2126/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2126/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/2126",
"html_url": "https://github.com/coleifer/peewee/pull/2126",
"diff_url": "https://github.com/coleifer/peewee/pull/2126.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/2126.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/2125 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2125/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2125/comments | https://api.github.com/repos/coleifer/peewee/issues/2125/events | https://github.com/coleifer/peewee/issues/2125 | 575,570,750 | MDU6SXNzdWU1NzU1NzA3NTA= | 2,125 | Insert Many across multiple tables | {
"login": "phuvp",
"id": 6632710,
"node_id": "MDQ6VXNlcjY2MzI3MTA=",
"avatar_url": "https://avatars.githubusercontent.com/u/6632710?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/phuvp",
"html_url": "https://github.com/phuvp",
"followers_url": "https://api.github.com/users/phuvp/followers",
"following_url": "https://api.github.com/users/phuvp/following{/other_user}",
"gists_url": "https://api.github.com/users/phuvp/gists{/gist_id}",
"starred_url": "https://api.github.com/users/phuvp/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/phuvp/subscriptions",
"organizations_url": "https://api.github.com/users/phuvp/orgs",
"repos_url": "https://api.github.com/users/phuvp/repos",
"events_url": "https://api.github.com/users/phuvp/events{/privacy}",
"received_events_url": "https://api.github.com/users/phuvp/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Sql databases do not support inserting into multiple tables in one *network call*."
] | 2020-03-04T16:52:10 | 2020-03-04T20:44:22 | 2020-03-04T20:44:05 | NONE | null | I'd like to use `insert_many` on multiple tables in one network call. It does not seem possible since `insert_many` is based on the class name. Is that correct? | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2125/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2125/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2124 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2124/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2124/comments | https://api.github.com/repos/coleifer/peewee/issues/2124/events | https://github.com/coleifer/peewee/issues/2124 | 575,427,482 | MDU6SXNzdWU1NzU0Mjc0ODI= | 2,124 | Peewee incorrectly assumes that a column of the form IntegerField(primary_key=True) is an AutoField() | {
"login": "ilyakamens",
"id": 3293811,
"node_id": "MDQ6VXNlcjMyOTM4MTE=",
"avatar_url": "https://avatars.githubusercontent.com/u/3293811?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/ilyakamens",
"html_url": "https://github.com/ilyakamens",
"followers_url": "https://api.github.com/users/ilyakamens/followers",
"following_url": "https://api.github.com/users/ilyakamens/following{/other_user}",
"gists_url": "https://api.github.com/users/ilyakamens/gists{/gist_id}",
"starred_url": "https://api.github.com/users/ilyakamens/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/ilyakamens/subscriptions",
"organizations_url": "https://api.github.com/users/ilyakamens/orgs",
"repos_url": "https://api.github.com/users/ilyakamens/repos",
"events_url": "https://api.github.com/users/ilyakamens/events{/privacy}",
"received_events_url": "https://api.github.com/users/ilyakamens/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Yeah, Peewee uses a heuristic when introspecting the database and assigns the auto-incrementing integer field when it discovers integer primary keys. Known behavior.",
"@coleifer - Understood. Would you accept a PR to fix this case?",
"@ilyakamens - before putting together a patch, how would you go about handling this? My thought was that by far the most common case of using an integer primary key was as an auto-incrementing id. On the other hand, determining if an integer primary-key actually *is* autoincrementing in a cross-db compatible way (without introducing false-negatives, which would be much worse IMO than false-positives), is kinda tricky.\r\n\r\nIt's been a while since I looked into it, though, so maybe you have some ideas? The main things to keep in mind, as far as I'm concerned, are:\r\n\r\n* peewee's reflection has worked this way since the beginning and this is the first issue about this\r\n* it seems much easier to deal with a false-positive than a false-negative. Peewee let's you manually specify the primary key in either case, so i'm kinda pressed to think of when this would even negatively impact someone.\r\n* is there an extremely reliable way to detect autoinc primary keys across the supported dbs? Or conversely, to detect when an integer primary key is definitely not autoinc?",
"I started working on it already before your reply. 🙂 \r\n\r\n> My thought was that by far the most common case of using an integer primary key was as an auto-incrementing id.\r\n\r\nCompletely agree. However, we use peewee's reflection module for automated tests to ensure our migrations work correctly, and this is causing test failures for `IntegerField(primary_key=True)`, which we have a legitimate use for in our case (won't bore you with the details).\r\n\r\nI have a fix with tests passing for PostgreSQL (will look into MySQL later). The tricky one is SQLite, since `PRAGMA` is insufficient to get the data I need. I thought I could update `SqliteDatabase.get_columns()` to use `sqlite_master` to parse out the `AUTOINCREMENT` part of the column via regex, but I'm surprised to not see it for `f11` in the column definitions of [ColTypes](https://github.com/coleifer/peewee/blob/master/tests/reflection.py#L31). Here's what I see from running:\r\n\r\n```python\r\nlist(self.execute_sql('select * from sqlite_master where tbl_name = \\'col_types\\''))\r\n```\r\n\r\n\r\n```[(u'table', u'col_types', u'col_types', 4, u'CREATE TABLE \"col_types\" (\"f11\" INTEGER NOT NULL PRIMARY KEY, \"f1\" INTEGER NOT NULL, \"f2\" BLOB NOT NULL, \"f3\" INTEGER NOT NULL, \"f4\" VARCHAR(50) NOT NULL, \"f5\" DATE NOT NULL, \"f6\" DATETIME NOT NULL, \"f7\" DECIMAL(10, 5) NOT NULL, \"f8\" REAL NOT NULL, \"f9\" REAL NOT NULL, \"f10\" INTEGER NOT NULL, \"f12\" TEXT NOT NULL, \"f13\" TIME NOT NULL)'), (u'index', u'col_types_f1', u'col_types', 5, u'CREATE INDEX \"col_types_f1\" ON \"col_types\" (\"f1\")'), (u'index', u'col_types_f10', u'col_types', 6, u'CREATE UNIQUE INDEX \"col_types_f10\" ON \"col_types\" (\"f10\")'), (u'index', u'col_types_f10_f11', u'col_types', 7, u'CREATE UNIQUE INDEX \"col_types_f10_f11\" ON \"col_types\" (\"f10\", \"f11\")'), (u'index', u'col_types_f11_f8_f13', u'col_types', 8, u'CREATE INDEX \"col_types_f11_f8_f13\" ON \"col_types\" (\"f11\", \"f8\", \"f13\")')]```\r\n\r\nI understand that a column declared `INTEGER PRIMARY KEY` will autoincrement in SQLite, but IIUC, it still needs the `AUTOINCREMENT` directive to autoincrement over the lifetime of the table (source [here](https://www.sqlite.org/faq.html#q1)).\r\n\r\nIn PostgreSQL, an `AutoField()` monotonically increases:\r\n\r\n```python\r\n>>> t = TestModel.create()\r\n>>> t.id\r\n1\r\n>>> t.delete_instance()\r\n1\r\n>>> t = TestModel.create()\r\n>>> t.id\r\n2\r\n```\r\n\r\nSo my questions are:\r\n1) Shouldn't peewee add `AUTOINCREMENT` to the column definition for an `AutoField()` in SQLite to have consistent monotonic behavior across DBs?\r\n2) If so, what do you think of my proposed solution? [Here](https://github.com/coleifer/peewee/pull/2126)'s a stub of what I'm proposing.",
"The reasons for not defaulting sqlite to autoincrement are here: https://www.sqlite.org/autoinc.html\r\n\r\nIt's available if you want it, but most people don't need it.",
"Ah. I see. And what about having a better heuristic for PostgreSQL and MySQL and leaving SQLite as is?",
"Hi @coleifer. After thinking about it more, I would make the case that it's okay to improve the heuristic for MySQL and PostgreSQL and to leave SQLite as-is. My reasoning is that an integer field primary key is effectively an `AutoField()` by definition in SQLite.\r\n\r\nI've adjusted [my PR](https://github.com/coleifer/peewee/pull/2126) to reflect these changes and have all tests passing (including new ones I added). Going back to the three things to keep in mind you mentioned earlier:\r\n\r\n> * peewee's reflection has worked this way since the beginning and this is the first issue about this\r\n\r\nUnderstood.\r\n\r\n> * it seems much easier to deal with a false-positive than a false-negative. Peewee let's you manually specify the primary key in either case, so i'm kinda pressed to think of when this would even negatively impact someone.\r\n\r\nI agree. I believe these small changes reduce the chance of a false-positive without increasing the risk of a false-negative. \r\n\r\n> * is there an extremely reliable way to detect autoinc primary keys across the supported dbs? Or conversely, to detect when an integer primary key is definitely not autoinc?\r\n\r\nMy changes use 1) information that was already available but unused (i.e., `column_default` from `information_schema.columns`), and 2) additional information from `information_schema.columns` (i.e., `extra`). I think this is reliable, but I suppose you'll be the judge of that.\r\n\r\nPlease take a look when you have a chance and let me know what you think.\r\n\r\nThanks!"
] | 2020-03-04T14:05:13 | 2020-03-08T18:02:47 | 2020-03-04T20:41:23 | CONTRIBUTOR | null | - Peewee 3.13.1
- PostgreSQL 9.6.15
- psycopg2 2.8.2
```
class TestModel(db.Model):
id = IntegerField(primary_key=True)
```
```
>>> TestModel.create_table()
>>> models = generate_models(db.database)
>>> models["testmodel"]._meta.columns["id"]
<AutoField: testmodel.id>
```
```
# \d testmodel;
Table "public.testmodel"
Column | Type | Collation | Nullable | Default
--------+---------+-----------+----------+---------
id | integer | | not null |
Indexes:
"testmodel_pkey" PRIMARY KEY, btree (id)
```
This may be the wrong spot, but it looks like Peewee only checks for primary key + IntegerField here: https://github.com/coleifer/peewee/blob/master/playhouse/reflection.py#L166-L179 | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2124/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2124/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2123 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2123/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2123/comments | https://api.github.com/repos/coleifer/peewee/issues/2123/events | https://github.com/coleifer/peewee/issues/2123 | 575,362,776 | MDU6SXNzdWU1NzUzNjI3NzY= | 2,123 | prefetch fails when foreign key field or target primary key field not selected | {
"login": "zmwangx",
"id": 4149852,
"node_id": "MDQ6VXNlcjQxNDk4NTI=",
"avatar_url": "https://avatars.githubusercontent.com/u/4149852?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/zmwangx",
"html_url": "https://github.com/zmwangx",
"followers_url": "https://api.github.com/users/zmwangx/followers",
"following_url": "https://api.github.com/users/zmwangx/following{/other_user}",
"gists_url": "https://api.github.com/users/zmwangx/gists{/gist_id}",
"starred_url": "https://api.github.com/users/zmwangx/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/zmwangx/subscriptions",
"organizations_url": "https://api.github.com/users/zmwangx/orgs",
"repos_url": "https://api.github.com/users/zmwangx/repos",
"events_url": "https://api.github.com/users/zmwangx/events{/privacy}",
"received_events_url": "https://api.github.com/users/zmwangx/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Yeah, prefetch needs those fields to be able to reconstruct the graph. I'll make a note in the docs."
] | 2020-03-04T12:29:31 | 2020-03-04T12:34:07 | 2020-03-04T12:34:07 | CONTRIBUTOR | null | This is not a bug, but rather a minor UX issue. Consider this simple example:
```python
import peewee
db = peewee.SqliteDatabase(":memory:")
class _BaseModel(peewee.Model):
class Meta:
database = db
class User(_BaseModel):
name = peewee.TextField()
class Entry(_BaseModel):
user = peewee.ForeignKeyField(User, backref="entries")
content = peewee.TextField()
def main():
db.create_tables([User, Entry])
User.insert(name="foo").execute()
Entry.insert(user_id=1, content="bar").execute()
user_query = User.select(User.name) # User.id not selected
entry_query = Entry.select(Entry.content) # Entry.user_id not selected
peewee.prefetch(user_query, entry_query)
if __name__ == "__main__":
main()
```
The prefetch fails when either `User.id` or `Entry.user_id` is not selected, as prefetch can't link the models together without either. The errors are slightly cryptic too if one doesn't realize what's going on
```python-traceback
...
File "/Users/zmwang/.pyenv/versions/3.8.0/lib/python3.8/site-packages/peewee.py", line 7421, in store_instance
identity = field.rel_field.python_value(instance.__data__[attname])
KeyError: 'user'
```
```python-traceback
...
File "/Users/zmwang/.pyenv/versions/3.8.0/lib/python3.8/site-packages/peewee.py", line 7412, in populate_instance
identifier = instance.__data__[field.rel_field.name]
KeyError: 'id'
```
(It may seem silly to specify the fields to be selected in this simple example, but in general I refrain from `SELECT *` and only select what I need.)
Maybe `prefetch` could add the relation fields it require automatically? Not sure about feasibility implementation-wise. Failing that, maybe add a little note to the API docs? | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2123/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2123/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2122 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2122/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2122/comments | https://api.github.com/repos/coleifer/peewee/issues/2122/events | https://github.com/coleifer/peewee/issues/2122 | 575,353,858 | MDU6SXNzdWU1NzUzNTM4NTg= | 2,122 | Unable to use dict pragmas with sqliteq | {
"login": "dev-dsp",
"id": 4235552,
"node_id": "MDQ6VXNlcjQyMzU1NTI=",
"avatar_url": "https://avatars.githubusercontent.com/u/4235552?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/dev-dsp",
"html_url": "https://github.com/dev-dsp",
"followers_url": "https://api.github.com/users/dev-dsp/followers",
"following_url": "https://api.github.com/users/dev-dsp/following{/other_user}",
"gists_url": "https://api.github.com/users/dev-dsp/gists{/gist_id}",
"starred_url": "https://api.github.com/users/dev-dsp/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/dev-dsp/subscriptions",
"organizations_url": "https://api.github.com/users/dev-dsp/orgs",
"repos_url": "https://api.github.com/users/dev-dsp/repos",
"events_url": "https://api.github.com/users/dev-dsp/events{/privacy}",
"received_events_url": "https://api.github.com/users/dev-dsp/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2020-03-04T12:13:57 | 2020-03-04T12:28:21 | 2020-03-04T12:28:21 | CONTRIBUTOR | null | Hi
https://github.com/coleifer/peewee/blob/master/playhouse/sqliteq.py#L228
Here for pragmas being dictionary it fails with
```
...
pdict = dict((k.lower(), v) for (k, v) in pragmas)
ValueError: too many values to unpack (expected 2)
```
Not sure how to better fix it in code. Not urgent also, I will just use list of tuples for now. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2122/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2122/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2121 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2121/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2121/comments | https://api.github.com/repos/coleifer/peewee/issues/2121/events | https://github.com/coleifer/peewee/issues/2121 | 574,699,264 | MDU6SXNzdWU1NzQ2OTkyNjQ= | 2,121 | Hybrid expression with JOIN | {
"login": "vltr",
"id": 1540275,
"node_id": "MDQ6VXNlcjE1NDAyNzU=",
"avatar_url": "https://avatars.githubusercontent.com/u/1540275?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/vltr",
"html_url": "https://github.com/vltr",
"followers_url": "https://api.github.com/users/vltr/followers",
"following_url": "https://api.github.com/users/vltr/following{/other_user}",
"gists_url": "https://api.github.com/users/vltr/gists{/gist_id}",
"starred_url": "https://api.github.com/users/vltr/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/vltr/subscriptions",
"organizations_url": "https://api.github.com/users/vltr/orgs",
"repos_url": "https://api.github.com/users/vltr/repos",
"events_url": "https://api.github.com/users/vltr/events{/privacy}",
"received_events_url": "https://api.github.com/users/vltr/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Questions typically go on stackoverflow."
] | 2020-03-03T14:16:31 | 2020-03-03T16:33:00 | 2020-03-03T16:32:59 | CONTRIBUTOR | null | Howdy! I'm fairly new to `peewee`, but have some strong background on SQLAlchemy (and all the vices that come with it). I'm trying to create a custom hybrid expression that correlates to a third (or N) table. I'll try to demonstrate in an example (non-tested) code:
```python
class BaseModel(Model):
class Meta:
database = database
class Person(BaseModel):
id = PrimaryKeyField(column_name="person_id")
name = CharField(max_length=255, column_name="person_name")
username = CharField(max_length=255, column_name="person_username", null=True)
class PersonTree(BaseModel):
id = PrimaryKeyField(column_name="person_tree_id")
name = CharField(max_length=255, column_name="person_tree_name")
code = CharField(max_length=255, column_name="person_tree_code")
person = ForeignKeyField(
column_name="person_id",
model=Person,
field="id",
backref="tree",
)
class Article(BaseModel):
id = PrimaryKeyField(column_name="article_id")
name = CharField(max_length=255, column_name="article_name")
branch = ForeignKeyField(
column_name="person_tree_id",
model=PersonTree,
field="id",
backref="articles",
)
@hybrid_property
def username(self):
"""
This gives me the possibility to grab the direct username of an article
"""
return self.branch.person.username
@username.expression
def username(cls):
"""
What if I wanted to do: Article.query().where(Article.username == "john_doe") ?
"""
pass
```
With the `username` `hybrid_property` on `Article`, I can get the `username` of the `Person` related to an `Article` using the `PersonTree` as a correlation, so far so good, but ... What if I wanted to "create a shortcut" to query all `Articles` created by the `"john_doe"` `Person` username, without declaring the `JOIN`s every time I make the query and without `.filter(branch__person__username="john_doe")`? I know it's possible with SA (to a great extent), but I'm finding this hard to accomplish with `peewee`.
Just for example, here's the SQL I hope to be able to construct:
```sql
SELECT
*
FROM
article a
JOIN person_tree pt ON a.person_tree_id = pt.person_tree_id
JOIN person p ON pt.person_id = p.person_id
WHERE
p.username = 'john_doe';
```
Thanks a lot in advance! | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2121/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2121/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2120 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2120/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2120/comments | https://api.github.com/repos/coleifer/peewee/issues/2120/events | https://github.com/coleifer/peewee/issues/2120 | 574,379,943 | MDU6SXNzdWU1NzQzNzk5NDM= | 2,120 | Field help_text attribute? | {
"login": "jvickroy",
"id": 9497294,
"node_id": "MDQ6VXNlcjk0OTcyOTQ=",
"avatar_url": "https://avatars.githubusercontent.com/u/9497294?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/jvickroy",
"html_url": "https://github.com/jvickroy",
"followers_url": "https://api.github.com/users/jvickroy/followers",
"following_url": "https://api.github.com/users/jvickroy/following{/other_user}",
"gists_url": "https://api.github.com/users/jvickroy/gists{/gist_id}",
"starred_url": "https://api.github.com/users/jvickroy/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/jvickroy/subscriptions",
"organizations_url": "https://api.github.com/users/jvickroy/orgs",
"repos_url": "https://api.github.com/users/jvickroy/repos",
"events_url": "https://api.github.com/users/jvickroy/events{/privacy}",
"received_events_url": "https://api.github.com/users/jvickroy/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"It's available to provide a standard way of adding metadata. `flask-peewee` &co made use of it. To access the help text, just access `field.help_text`. To iterate a model's fields, `ModelClass._meta.sorted_fields` returns the fields in order of declaration."
] | 2020-03-03T02:49:44 | 2020-03-03T11:24:33 | 2020-03-03T11:24:33 | NONE | null | What is the intent of the help_text attribute?
Looking at the code, it seems to only be be listed in the class Field definition.
I would like to be able to access the help_text strings, in my scripts, but do not know how to do so.
Could someone point in the right direction?
Thanks for your time.
P.S. peewee is great! | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2120/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2120/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2119 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2119/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2119/comments | https://api.github.com/repos/coleifer/peewee/issues/2119/events | https://github.com/coleifer/peewee/issues/2119 | 573,702,968 | MDU6SXNzdWU1NzM3MDI5Njg= | 2,119 | How to compare with boolean for PostgreSQL? | {
"login": "EugeneRymarev",
"id": 6260309,
"node_id": "MDQ6VXNlcjYyNjAzMDk=",
"avatar_url": "https://avatars.githubusercontent.com/u/6260309?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/EugeneRymarev",
"html_url": "https://github.com/EugeneRymarev",
"followers_url": "https://api.github.com/users/EugeneRymarev/followers",
"following_url": "https://api.github.com/users/EugeneRymarev/following{/other_user}",
"gists_url": "https://api.github.com/users/EugeneRymarev/gists{/gist_id}",
"starred_url": "https://api.github.com/users/EugeneRymarev/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/EugeneRymarev/subscriptions",
"organizations_url": "https://api.github.com/users/EugeneRymarev/orgs",
"repos_url": "https://api.github.com/users/EugeneRymarev/repos",
"events_url": "https://api.github.com/users/EugeneRymarev/events{/privacy}",
"received_events_url": "https://api.github.com/users/EugeneRymarev/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"`Table.Column == SQL('false')` works fine, but that wrong way",
"Huh? I've added a regression test that shows the full range of boolean comparisons. I could not replicate any problems on my machine: a9ebf6bdf2c7a74a802bd6860d1357b091b332a2"
] | 2020-03-02T04:09:04 | 2020-03-02T12:14:46 | 2020-03-02T12:14:46 | NONE | null | Hello!
`Table.coumn == False` in peewee give me
`Table.column = 0` in sql.
And i receive error "can't compare boolean and int". | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2119/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2119/timeline | null | completed | null | null |
Subsets and Splits