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
unknown
updated_at
unknown
closed_at
unknown
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/2418
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2418/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2418/comments
https://api.github.com/repos/coleifer/peewee/issues/2418/events
https://github.com/coleifer/peewee/issues/2418
899,949,749
MDU6SXNzdWU4OTk5NDk3NDk=
2,418
Inner Select as Operation
{ "login": "josiahlaivins", "id": 55600928, "node_id": "MDQ6VXNlcjU1NjAwOTI4", "avatar_url": "https://avatars.githubusercontent.com/u/55600928?v=4", "gravatar_id": "", "url": "https://api.github.com/users/josiahlaivins", "html_url": "https://github.com/josiahlaivins", "followers_url": "https://api.github.com/users/josiahlaivins/followers", "following_url": "https://api.github.com/users/josiahlaivins/following{/other_user}", "gists_url": "https://api.github.com/users/josiahlaivins/gists{/gist_id}", "starred_url": "https://api.github.com/users/josiahlaivins/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/josiahlaivins/subscriptions", "organizations_url": "https://api.github.com/users/josiahlaivins/orgs", "repos_url": "https://api.github.com/users/josiahlaivins/repos", "events_url": "https://api.github.com/users/josiahlaivins/events{/privacy}", "received_events_url": "https://api.github.com/users/josiahlaivins/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Not really, Peewee does not make an effort to support microsoft tsql.", "@coleifer Thanks for the quick response! I understand that peewee doesnt support tsql. However I am making my own database object to support it. I thought I could just do a similar thing to the SQliteDatabase code. I appreciate any opinions from you on this. I could boil my problem down to the question whether peewee supports this form of operations:\r\n```python\r\noperations={\r\n \"IF NOT EXISTS\": \"IF NOT EXISTS(select * from sysobjects where name='sometable')\"\r\n }\r\n```\r\nWhere there is a select statement with params inside. Unless this is what you mean by `not make an effort to support microsoft tsql.` in that tsql requires the ability to replace simple operations with subqueries?\r\n\r\nIf your response is that the operations field doesnt support something as complex as a subquery, then that helps a lot, I would likely need to do some deeper customization then. Thanks!", "You will want to subclass the `SchemaManager` and override the `_create_table()` method, then instruct your base models to specify your custom SchemaManager implementation. The SchemaManager is where the logic lives for constructing the various DML queries." ]
"2021-05-24T19:39:57"
"2021-05-24T21:56:47"
"2021-05-24T20:59:34"
NONE
null
I am trying to setup a Azure SQL Db connector for peewee. Currently Model's use a local sqlite db for local storage/caching. I would like to connect to Azure SQL DB. I have found that this is not instantly straight forward: When executing a `db.create_tables([table for table in classes if table not in db.get_tables()])` we get a create table failure: ```bash {peewee.py:3132} DEBUG - ('CREATE TABLE IF NOT EXISTS "some_table" \ ("some_table_id" INTEGER NOT NULL PRIMARY KEY, "some_column" TEXT)', []) .... [42000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Incorrect syntax near \ the keyword 'IF'. (156) (SQLExecDirectW)" ``` This is because for whatever reason, ASDB has a different way to checking if a table exists: ```python # peeewee ASDB "IF NOT EXISTS": "IF NOT EXISTS(select * from sysobjects where name='sometable' and xtype='U') ``` My solution is to try operations: ```python class AzureSQLDatabase(Database): operations={ "IF NOT EXISTS": "IF NOT EXISTS(select * from sysobjects where name='sometable' and xtype='U')" } ``` However it doesn't seem like that operation is being applied to a model's create_table execution. There is also the issue that I need to know the model's name in the operation. `SomeTable._meta.database=asdb` ```python ctx = SomeTable._schema._create_context() ctx.literal('IF NOT EXISTS') ``` Is there an easy solution in peewee to solve this? I think the quick and dirty way is to overwrite `execute_sql` to do the replacement, however I assumed that I can use `operations` to solve this. Is there somewhere to look at operations that contain queries? I am also have a hard time finding where `operations` gets used? Like where is the line that does the sql replacement.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2418/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2418/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2417
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2417/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2417/comments
https://api.github.com/repos/coleifer/peewee/issues/2417/events
https://github.com/coleifer/peewee/issues/2417
897,688,382
MDU6SXNzdWU4OTc2ODgzODI=
2,417
Value not getting stored?
{ "login": "Donkere-vader", "id": 34307023, "node_id": "MDQ6VXNlcjM0MzA3MDIz", "avatar_url": "https://avatars.githubusercontent.com/u/34307023?v=4", "gravatar_id": "", "url": "https://api.github.com/users/Donkere-vader", "html_url": "https://github.com/Donkere-vader", "followers_url": "https://api.github.com/users/Donkere-vader/followers", "following_url": "https://api.github.com/users/Donkere-vader/following{/other_user}", "gists_url": "https://api.github.com/users/Donkere-vader/gists{/gist_id}", "starred_url": "https://api.github.com/users/Donkere-vader/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/Donkere-vader/subscriptions", "organizations_url": "https://api.github.com/users/Donkere-vader/orgs", "repos_url": "https://api.github.com/users/Donkere-vader/repos", "events_url": "https://api.github.com/users/Donkere-vader/events{/privacy}", "received_events_url": "https://api.github.com/users/Donkere-vader/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "You're doing some very strange stuff with so many operator overloads and things, so it's hard to tell what is going on. Specifically, overriding getitem / setitem on model classes should probably be avoided.\r\n\r\nI'd suggest simplifying your code as much as possible to track this down, as I'm quite sure it's not a bug in Peewee but rather in your implementation.", "Oh it was a very very stupid problem.\r\n\r\nThe code for my ``ListItem`` class looked like this:\r\n\r\n```py\r\nclass ListItem(Item):\r\n parent = ForeignKeyField(List, backref=\"items\")\r\n value = CharField\r\n```\r\nNotice the last line, I set value to the class CharField instead of an instance of CharField. I forgot the braces 🤦🏻 .\r\nThanks for your response anyways! \r\n\r\nLine should've been:\r\n```py\r\n value = CharField()\r\n```" ]
"2021-05-21T05:23:12"
"2021-05-21T14:15:06"
"2021-05-21T12:40:58"
NONE
null
I'm not really sure if this is a bug or not. But it is very unexpected behavior. So in my code I have two classes ``List`` and ``ListItem``. ```py class Item(Model): # snip def set_value(self, value): pass # snip class ListItem(Item): pass # snip class List(Model): # snip def append(self, value): new_item = ListItem(parent=self) new_item.set_value(value) new_item.save() print("Value from object:", new_item.value) print("Value from queried object: ", ListItem.select().where(ListItem.id == new_item.id).get().value) ``` the ``ListItem.set_value(value)`` function does basically set the field ``value`` to the str of the value and the field ``value_type`` to what type it is. To later convert it back to a python object of the correct type. if for example the parameter ``value`` of the function ``append`` would be ``2``. I would expect the following output: ```bash Value from object: 2 Value from queried object: 2 ``` However, as you might have guessed, that's not the output. The real output is: ```bash Value from object: 2 Value from queried object: <class 'peewee.CharField'> ``` Can this be a bug? Or am I doing something wrong? Any help would be appreciated :) Full code is up on [pastebin](https://pastebin.com/fcSydNai) the ``append`` function is on ln. 127
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2417/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2417/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2416
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2416/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2416/comments
https://api.github.com/repos/coleifer/peewee/issues/2416/events
https://github.com/coleifer/peewee/issues/2416
896,457,706
MDU6SXNzdWU4OTY0NTc3MDY=
2,416
Is JSONPath for postgresql support planned?
{ "login": "DimaKalbfleysh", "id": 39565365, "node_id": "MDQ6VXNlcjM5NTY1MzY1", "avatar_url": "https://avatars.githubusercontent.com/u/39565365?v=4", "gravatar_id": "", "url": "https://api.github.com/users/DimaKalbfleysh", "html_url": "https://github.com/DimaKalbfleysh", "followers_url": "https://api.github.com/users/DimaKalbfleysh/followers", "following_url": "https://api.github.com/users/DimaKalbfleysh/following{/other_user}", "gists_url": "https://api.github.com/users/DimaKalbfleysh/gists{/gist_id}", "starred_url": "https://api.github.com/users/DimaKalbfleysh/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/DimaKalbfleysh/subscriptions", "organizations_url": "https://api.github.com/users/DimaKalbfleysh/orgs", "repos_url": "https://api.github.com/users/DimaKalbfleysh/repos", "events_url": "https://api.github.com/users/DimaKalbfleysh/events{/privacy}", "received_events_url": "https://api.github.com/users/DimaKalbfleysh/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "There is some simple jsonpath support for the `__getitem__()`-type operations on jsonb fields. Because jsonpath is basically an entire language of its own, I've chosen not to implement some kind of python layer for now.\r\n\r\nYou can call the postgres jsonpath functions quite easily from peewee via `fn.jsonpath_XXX()` and pass in the field instance and the desired path as a string.\r\n\r\n```python\r\nfn.jsonb_path_exists(JsonModel.data, '$.owner_user_id ? (@ == 4843)')\r\n```" ]
"2021-05-20T08:10:31"
"2021-05-20T13:02:53"
"2021-05-20T13:02:09"
NONE
null
Colleagues, good afternoon, JSONB has become an integral part of many projects. And I believe that many would like to see the implementation of this functionality (JSONPath) in peewee!
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2416/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2416/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2415
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2415/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2415/comments
https://api.github.com/repos/coleifer/peewee/issues/2415/events
https://github.com/coleifer/peewee/issues/2415
895,342,370
MDU6SXNzdWU4OTUzNDIzNzA=
2,415
[question] Use query alias for group_by/order_by
{ "login": "atanasoff-yordan", "id": 34780301, "node_id": "MDQ6VXNlcjM0NzgwMzAx", "avatar_url": "https://avatars.githubusercontent.com/u/34780301?v=4", "gravatar_id": "", "url": "https://api.github.com/users/atanasoff-yordan", "html_url": "https://github.com/atanasoff-yordan", "followers_url": "https://api.github.com/users/atanasoff-yordan/followers", "following_url": "https://api.github.com/users/atanasoff-yordan/following{/other_user}", "gists_url": "https://api.github.com/users/atanasoff-yordan/gists{/gist_id}", "starred_url": "https://api.github.com/users/atanasoff-yordan/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/atanasoff-yordan/subscriptions", "organizations_url": "https://api.github.com/users/atanasoff-yordan/orgs", "repos_url": "https://api.github.com/users/atanasoff-yordan/repos", "events_url": "https://api.github.com/users/atanasoff-yordan/events{/privacy}", "received_events_url": "https://api.github.com/users/atanasoff-yordan/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Peewee will do the right thing and use the alias if you write it this way:\r\n\r\n```python\r\nct = fn.COUNT(Tweet.id).alias('ct')\r\nquery = (User\r\n .select(User.username, ct)\r\n .join(Tweet, JOIN.LEFT_OUTER)\r\n .group_by(User.username)\r\n .order_by(ct))\r\n```\r\n\r\nProduces:\r\n\r\n```sql\r\nSELECT \"t1\".\"username\", COUNT(\"t2\".\"id\") AS \"ct\" \r\nFROM \"user\" AS \"t1\" \r\nLEFT OUTER JOIN \"tweet\" AS \"t2\" ON (\"t2\".\"user_id\" = \"t1\".\"id\") \r\nGROUP BY \"t1\".\"username\" \r\nORDER BY \"ct\"\r\n```" ]
"2021-05-19T11:47:06"
"2021-05-19T12:38:48"
"2021-05-19T12:38:47"
NONE
null
As the documentation says [here](https://docs.peewee-orm.com/en/latest/peewee/querying.html#sorting-records) we should put the column on the order_by/group_by, for example, here the `.order_by(fn.COUNT(Tweet.id).desc())` My question: since we defined an alias for the count, can we get a reference to that alias to use it in the group_by/order_by? instead of writing again the whole thing? thx ```python query = (User .select(User.username, fn.COUNT(Tweet.id).alias('num_tweets')) .join(Tweet, JOIN.LEFT_OUTER) .group_by(User.username) .order_by(fn.COUNT(Tweet.id).desc())) ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2415/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2415/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2414
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2414/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2414/comments
https://api.github.com/repos/coleifer/peewee/issues/2414/events
https://github.com/coleifer/peewee/issues/2414
895,029,473
MDU6SXNzdWU4OTUwMjk0NzM=
2,414
Conditional query of multiple in
{ "login": "xiaoqge", "id": 8544686, "node_id": "MDQ6VXNlcjg1NDQ2ODY=", "avatar_url": "https://avatars.githubusercontent.com/u/8544686?v=4", "gravatar_id": "", "url": "https://api.github.com/users/xiaoqge", "html_url": "https://github.com/xiaoqge", "followers_url": "https://api.github.com/users/xiaoqge/followers", "following_url": "https://api.github.com/users/xiaoqge/following{/other_user}", "gists_url": "https://api.github.com/users/xiaoqge/gists{/gist_id}", "starred_url": "https://api.github.com/users/xiaoqge/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/xiaoqge/subscriptions", "organizations_url": "https://api.github.com/users/xiaoqge/orgs", "repos_url": "https://api.github.com/users/xiaoqge/repos", "events_url": "https://api.github.com/users/xiaoqge/events{/privacy}", "received_events_url": "https://api.github.com/users/xiaoqge/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Peewee supports multiple IN conditions:\r\n\r\n```python\r\n\r\n# postgres:\r\nin_list = ValuesList([(1, 'u1'), (2, 'u2'), (7, 'u7'), (8, 'u8')])\r\nquery = User.select().where(Tuple(User.id, User.username).in_(in_list))\r\n\r\n\r\n# note sqlite requires additional parentheses:\r\nfrom peewee import EnclosedNodeList\r\nin_list = EnclosedNodeList([in_list])\r\nquery = User.select().where(Tuple(User.id, User.username).in_(in_list))\r\n```", "thank you " ]
"2021-05-19T06:11:12"
"2021-05-20T02:07:21"
"2021-05-19T12:43:53"
NONE
null
Does peewee support multiple in query conditions? Can batch query if not supported? ``` pre_out = Txouts.select(Txouts.tx_id,Txouts.value,Txouts.scriptpubkey)\ .where(Txouts.tx_id==ins["prevout_tx_id"],Txouts.n==ins["prevout_n"]).dicts() ``` such as ``` SQL: SELECT * from M where (R, D) in (("200909","1"),("511904","1"),("200908","4")); ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2414/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2414/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2413
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2413/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2413/comments
https://api.github.com/repos/coleifer/peewee/issues/2413/events
https://github.com/coleifer/peewee/issues/2413
890,999,736
MDU6SXNzdWU4OTA5OTk3MzY=
2,413
Unable to specify custom column name
{ "login": "alexin", "id": 768281, "node_id": "MDQ6VXNlcjc2ODI4MQ==", "avatar_url": "https://avatars.githubusercontent.com/u/768281?v=4", "gravatar_id": "", "url": "https://api.github.com/users/alexin", "html_url": "https://github.com/alexin", "followers_url": "https://api.github.com/users/alexin/followers", "following_url": "https://api.github.com/users/alexin/following{/other_user}", "gists_url": "https://api.github.com/users/alexin/gists{/gist_id}", "starred_url": "https://api.github.com/users/alexin/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/alexin/subscriptions", "organizations_url": "https://api.github.com/users/alexin/orgs", "repos_url": "https://api.github.com/users/alexin/repos", "events_url": "https://api.github.com/users/alexin/events{/privacy}", "received_events_url": "https://api.github.com/users/alexin/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "You have a trailing comma after your peewee.IntegerField() which is probably the issue.\r\n\r\nThis code works fine:\r\n\r\n```python\r\nclass Product(Model):\r\n reference = IntegerField(column_name='reference', primary_key=True)\r\n class Meta:\r\n database = db\r\n```\r\n\r\nProduces:\r\n\r\n```sql\r\nCREATE TABLE IF NOT EXISTS \"product\" (\"reference\" INTEGER NOT NULL PRIMARY KEY)\r\n```\r\n\r\nPlease debug your code a bit more before opening issues.", "Thank you for pointing that out. I am so used to Java-like languages that I easily missed that comma.\r\nI understand it is dumb mistake and I could have avoided it. In my defense, I am dumbfounded I got no error nor warning, that could have saved me hours of figuring what was happening." ]
"2021-05-13T12:30:41"
"2021-05-13T12:55:44"
"2021-05-13T12:48:30"
NONE
null
Hello, I am unable to set a custom column for a primary key. For example, the following model ```python class Product(peewee.Model): reference = peewee.IntegerField(column_name='reference', primary_key=True), ``` results in the following SQL query ```sql CREATE TABLE IF NOT EXISTS "product" ("id" INTEGER NOT NULL PRIMARY KEY) ``` Note that I request the name 'reference', but instead I get 'id'. **Python**: 3.9.4 **Peewee**: 3.14.4 Am I missing something? Thank you, Alexandre Vieira
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2413/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2413/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2412
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2412/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2412/comments
https://api.github.com/repos/coleifer/peewee/issues/2412/events
https://github.com/coleifer/peewee/issues/2412
890,523,149
MDU6SXNzdWU4OTA1MjMxNDk=
2,412
peewee.OperationalError: near "RETURNING": syntax error
{ "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 found [this discussion](https://sqlite.org/forum/info/a4dde39b614ec0b2) and the issue is my version of sqlite3 3.29.0 which is lower than 3.35.x from where the RETURNING clause is supported :(.\r\n\r\nIs there another way to accomplish the same use-case without RETURNING?", ">Is there another way to accomplish the same use-case without RETURNING?\r\n\r\nIf you leave off the `returning()` (which is unsupported in sqlite < 3.35) then Peewee will already return you the last insert rowid, which it seems like is all you want anyways. For multi-row inserts there is no equivalent, however." ]
"2021-05-12T22:05:20"
"2021-05-13T00:51:12"
"2021-05-13T00:50:42"
NONE
null
I'm on peewee 3.14.4 and sqlite, and I'm getting the above error `peewee.OperationalError: near "RETURNING": syntax error` for a simple insert_many query adapted to my context from exactly the same as stated in the docs i.e. ``` query = (User .insert(email='foo@bar.com', created=fn.now()) .returning(User)) ``` I have also tried returning User.id or even leaving returning arguments empty but I get the same error. The generated sql is something like: ``` INSERT INTO table (a, b, c, ...) VALUES (...), (...), (...) RETURNING table.id ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2412/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2412/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2411
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2411/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2411/comments
https://api.github.com/repos/coleifer/peewee/issues/2411/events
https://github.com/coleifer/peewee/issues/2411
890,448,083
MDU6SXNzdWU4OTA0NDgwODM=
2,411
WHERE-IN query missing VALUES keyword leading to sqlite error
{ "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
[ "Sqlite is finnicky about parentheses.\r\n\r\nThis should work:\r\n\r\n```python\r\n\r\nvl = ValuesList([('x1', 'y1'), ('x2', 'y2')])\r\n# wrap in extra parentheses for sqlite\r\nvl_p = EnclosedNodeList([vl])\r\n\r\nq = A.select().where(Tuple(A.a1, A.a2).in_(vl_p))\r\n```" ]
"2021-05-12T20:12:59"
"2021-05-12T21:21:30"
"2021-05-12T21:21:30"
NONE
null
I have the following use case in peewee version 3.14.4: ``` query = A.select().where(Tuple(A.a1, A.a2).in_([('x1', 'y1'), ('x2', 'y2')])) print(query) ``` This will generate for sqlite a query similar to: ``` SELECT ... FROM a WHERE (a1, a2) IN (('x1', 'y1'), ('x2', 'y2')) ``` which leads to the sqlite error: `Error while executing SQL query on database X: row value misused` peewee SQL generator is missing the VALUES keyword like the correct sql code should be: ``` SELECT ... FROM a WHERE (a1, a2) IN (VALUES('x1', 'y1'), ('x2', 'y2')) ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2411/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2411/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2410
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2410/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2410/comments
https://api.github.com/repos/coleifer/peewee/issues/2410/events
https://github.com/coleifer/peewee/pull/2410
890,085,052
MDExOlB1bGxSZXF1ZXN0NjQzMTU4NzQz
2,410
Use Python3 syntax for print
{ "login": "pylipp", "id": 10617122, "node_id": "MDQ6VXNlcjEwNjE3MTIy", "avatar_url": "https://avatars.githubusercontent.com/u/10617122?v=4", "gravatar_id": "", "url": "https://api.github.com/users/pylipp", "html_url": "https://github.com/pylipp", "followers_url": "https://api.github.com/users/pylipp/followers", "following_url": "https://api.github.com/users/pylipp/following{/other_user}", "gists_url": "https://api.github.com/users/pylipp/gists{/gist_id}", "starred_url": "https://api.github.com/users/pylipp/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/pylipp/subscriptions", "organizations_url": "https://api.github.com/users/pylipp/orgs", "repos_url": "https://api.github.com/users/pylipp/repos", "events_url": "https://api.github.com/users/pylipp/events{/privacy}", "received_events_url": "https://api.github.com/users/pylipp/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[]
"2021-05-12T13:21:24"
"2021-05-12T13:52:49"
"2021-05-12T13:52:49"
NONE
null
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2410/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2410/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/2410", "html_url": "https://github.com/coleifer/peewee/pull/2410", "diff_url": "https://github.com/coleifer/peewee/pull/2410.diff", "patch_url": "https://github.com/coleifer/peewee/pull/2410.patch", "merged_at": null }
https://api.github.com/repos/coleifer/peewee/issues/2409
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2409/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2409/comments
https://api.github.com/repos/coleifer/peewee/issues/2409/events
https://github.com/coleifer/peewee/issues/2409
888,559,159
MDU6SXNzdWU4ODg1NTkxNTk=
2,409
[Playhouse.migrator] Implement add_foreign_key_constraint or document solution for sqlite
{ "login": "thigg", "id": 7593137, "node_id": "MDQ6VXNlcjc1OTMxMzc=", "avatar_url": "https://avatars.githubusercontent.com/u/7593137?v=4", "gravatar_id": "", "url": "https://api.github.com/users/thigg", "html_url": "https://github.com/thigg", "followers_url": "https://api.github.com/users/thigg/followers", "following_url": "https://api.github.com/users/thigg/following{/other_user}", "gists_url": "https://api.github.com/users/thigg/gists{/gist_id}", "starred_url": "https://api.github.com/users/thigg/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/thigg/subscriptions", "organizations_url": "https://api.github.com/users/thigg/orgs", "repos_url": "https://api.github.com/users/thigg/repos", "events_url": "https://api.github.com/users/thigg/events{/privacy}", "received_events_url": "https://api.github.com/users/thigg/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "For reference: \r\n\r\nI solved it with this function:\r\n\r\n```python\r\ndef recreate_table(table: Type[Model], tablename: str):\r\n logger.info(\"copying table %s\", tablename)\r\n table_copy_name = tablename + \"_x\"\r\n col_names = \",\".join(col.name for col in db.get_columns(tablename))\r\n db.execute_sql(\"ALTER TABLE %s RENAME TO %s;\" % (tablename, table_copy_name))\r\n db.create_tables([table])\r\n sql = \"INSERT INTO %s (%s) SELECT %s FROM %s;\" % (tablename, col_names, col_names, table_copy_name)\r\n #todo: check for returned sql errors\r\n db.execute_sql(sql)\r\n logger.info(\"deleting copy of table %s\", tablename)\r\n db.execute_sql(\"DROP TABLE %s_x;\" % tablename)\r\n```\r\nNote that you need the column names because the order might change when recreating the table. (E.g. if you replace a deferred constraint with a direct one)\r\n\r\n(Just has the problem, that the alter table also renames already existing constraints. Thus make sure, that you do not run this on a table, that is already referenced by a constraint, because otherwise the constraint is changed to `<table>_x`)", "I've decided to pass on implementing this for Sqlite, but it is possible, as you suggest.", "Maybe this could be mentioned in the documentation then?" ]
"2021-05-11T20:36:15"
"2021-05-12T12:55:01"
"2021-05-12T12:53:46"
NONE
null
`add_foreign_key_constraint` for the sqlite migrator throws a NotImplemented error. A possible solution would be to rename the table, recreate the table, copy the data, drop the copy. (as described in https://www.techonthenet.com/sqlite/foreign_keys/foreign_delete.php) This could either be implemented or at least a comment could be added which points to a possible solution.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2409/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2409/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2408
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2408/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2408/comments
https://api.github.com/repos/coleifer/peewee/issues/2408/events
https://github.com/coleifer/peewee/pull/2408
887,635,063
MDExOlB1bGxSZXF1ZXN0NjQwODU0Mzc2
2,408
Insert operations of models with non-PK foreign keys fail when passing a target object instance
{ "login": "smuething", "id": 1837881, "node_id": "MDQ6VXNlcjE4Mzc4ODE=", "avatar_url": "https://avatars.githubusercontent.com/u/1837881?v=4", "gravatar_id": "", "url": "https://api.github.com/users/smuething", "html_url": "https://github.com/smuething", "followers_url": "https://api.github.com/users/smuething/followers", "following_url": "https://api.github.com/users/smuething/following{/other_user}", "gists_url": "https://api.github.com/users/smuething/gists{/gist_id}", "starred_url": "https://api.github.com/users/smuething/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/smuething/subscriptions", "organizations_url": "https://api.github.com/users/smuething/orgs", "repos_url": "https://api.github.com/users/smuething/repos", "events_url": "https://api.github.com/users/smuething/events{/privacy}", "received_events_url": "https://api.github.com/users/smuething/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[]
"2021-05-11T15:27:09"
"2021-05-11T19:08:55"
"2021-05-11T19:08:55"
NONE
null
I have a model `A` with a `ForeignKeyField` column that uses the `field` parameter to set a non-pk reference column in the target model: ```python class Target(Model): key = FixedCharField(8,unique=True) class A(Model): target = ForeignKeyField(Target,field="key",lazy_load=False) ``` When trying to create instances of `A`, I can do so with `create()`, but not with the `ModelInsert`-based methods: ```python t = Target.create(key="X") A.create(target=t) # works A.insert(target="X").execute() # works A.insert(target=t).execute() # fails ``` In the last case, the generated SQL uses the primary key of `t` instead of `t.key` because the code path in `ModelInsert` does not apply the `field` parameter of the `ForeignKeyField` to the passed-in model instance. The attached patch fixes the problem for me.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2408/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2408/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/2408", "html_url": "https://github.com/coleifer/peewee/pull/2408", "diff_url": "https://github.com/coleifer/peewee/pull/2408.diff", "patch_url": "https://github.com/coleifer/peewee/pull/2408.patch", "merged_at": null }
https://api.github.com/repos/coleifer/peewee/issues/2407
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2407/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2407/comments
https://api.github.com/repos/coleifer/peewee/issues/2407/events
https://github.com/coleifer/peewee/pull/2407
885,554,528
MDExOlB1bGxSZXF1ZXN0NjM4ODczODMx
2,407
[Feature] Add support for the precision parameters to the FLOAT field
{ "login": "enpaul", "id": 24588726, "node_id": "MDQ6VXNlcjI0NTg4NzI2", "avatar_url": "https://avatars.githubusercontent.com/u/24588726?v=4", "gravatar_id": "", "url": "https://api.github.com/users/enpaul", "html_url": "https://github.com/enpaul", "followers_url": "https://api.github.com/users/enpaul/followers", "following_url": "https://api.github.com/users/enpaul/following{/other_user}", "gists_url": "https://api.github.com/users/enpaul/gists{/gist_id}", "starred_url": "https://api.github.com/users/enpaul/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/enpaul/subscriptions", "organizations_url": "https://api.github.com/users/enpaul/orgs", "repos_url": "https://api.github.com/users/enpaul/repos", "events_url": "https://api.github.com/users/enpaul/events{/privacy}", "received_events_url": "https://api.github.com/users/enpaul/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Ehh, I'm going to pass on this, as I think it could be misleading. This is a mysql-only thing, as far as I know, and the data is still stored as a floating-point (e.g. approximate) value anyways. If you want to specify a precision then you would really want to use the DecimalField (numeric type).\r\n\r\nI'd suggest adding your own subclass of FloatField to your libraries if you want this functionality.", "That makes sense, thanks for taking a look at it! I had thought that this was a mysql+postgres feature, but it looks that you're right and it's only mysql. Thanks again for the great library!" ]
"2021-05-11T01:20:42"
"2021-05-12T20:24:24"
"2021-05-11T12:51:03"
NONE
null
Hello, thank you so much for creating and maintaining this library! Peewee has been my go-to for several years now, both at work and on personal projects and it's honestly been a joy to use. Recently I encountered a situation where I needed to specify the [precision parameters](https://dev.mysql.com/doc/refman/8.0/en/floating-point-types.html) for the MySQL `FLOAT` field, and after a search through this repo and the docs I ended up opening a [question on Stackoverflow](https://stackoverflow.com/questions/67475853/specify-float-column-precision-in-peewee-with-mariadb-mysql) where I got a very helpful answer that this patch is based on. --- This patch adds two new init parameters to the `FloatField` class: * `max_digits`, which corresponds to the `M` precision parameter on the MySQL `FLOAT` class and defines the number of digits that can be returned accurately from the column * `decimal_places`, which corresponds to the `D` precision parameter on the MySQL `FLOAT` class and defines the number of digits after the decimal point which can be returned accurately from the column Currently each of these new parameters has a default of `None` and are excluded from the return value of `get_modifiers()` so that the current behavior of the field isn't changed. However, if the defaults were changed to `max_digits=6` and `decimal_places=0` then the current behavior would be changed but the behavior of the field would be consistent across database backends.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2407/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2407/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/2407", "html_url": "https://github.com/coleifer/peewee/pull/2407", "diff_url": "https://github.com/coleifer/peewee/pull/2407.diff", "patch_url": "https://github.com/coleifer/peewee/pull/2407.patch", "merged_at": null }
https://api.github.com/repos/coleifer/peewee/issues/2406
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2406/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2406/comments
https://api.github.com/repos/coleifer/peewee/issues/2406/events
https://github.com/coleifer/peewee/issues/2406
880,338,673
MDU6SXNzdWU4ODAzMzg2NzM=
2,406
LSMTable.get_by_id raises KeyError which breaks __contains__ functionality on ModelBase
{ "login": "vdksoda", "id": 12879372, "node_id": "MDQ6VXNlcjEyODc5Mzcy", "avatar_url": "https://avatars.githubusercontent.com/u/12879372?v=4", "gravatar_id": "", "url": "https://api.github.com/users/vdksoda", "html_url": "https://github.com/vdksoda", "followers_url": "https://api.github.com/users/vdksoda/followers", "following_url": "https://api.github.com/users/vdksoda/following{/other_user}", "gists_url": "https://api.github.com/users/vdksoda/gists{/gist_id}", "starred_url": "https://api.github.com/users/vdksoda/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/vdksoda/subscriptions", "organizations_url": "https://api.github.com/users/vdksoda/orgs", "repos_url": "https://api.github.com/users/vdksoda/repos", "events_url": "https://api.github.com/users/vdksoda/events{/privacy}", "received_events_url": "https://api.github.com/users/vdksoda/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "You bring up a good point about having this be consistent with other models. I've removed the code which was raising the `KeyError` and updated the docs as well. It should behave the same as regular models now." ]
"2021-05-08T05:55:21"
"2021-05-08T14:48:12"
"2021-05-08T14:47:40"
NONE
null
I have a scenario where I need to test for the presence of a key in a `LSMTable`. I noticed that `ModelBase` does support a `__contains__` method. So decided to do something like: ``` app_db = PooledSqliteExtDatabase( database=sqlite_db_filename, max_connections=500, pragmas=[ ("journal_mode", "wal"), ("cache_size", -1024 * 64), ("foreign_keys", 1), ("ignore_check_constraints", 0), ("synchronous", 0), ("page_size", 1024 * 64), ], ) app_db.load_extension('./lsm') key = str(uuid.uuid4()) with app_db as db, db.bind_ctx([KV]): # where KV is an LSM Table is_in_db = key in KV ``` This part `key in KV` raises a `KeyError`. Per your design, would you expect users to handle this error or would you prefer to fix in the peewee library? The potential fixes in peewee could be: 1. Unify `LSMTable` and `ModelBase` by raising `DoesNotExist` in the `get_by_id` method and recast to `KeyError` only in `__getitem__`. The `__getitem__` change could be implemented at `ModelBase` given the interface mirrored is dictionary like; or 2. Overwrite `__contains__` in LSMTables to reflect that `KeyError` is thrown by `LSMTable.get_by_id`. This is what I could come up with in the short time I reviewed the codebase. Would be great to hear your thoughts. PS: Thank you for your blogs; I have learnt a lot from them especially as they cover working with novel datastores.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2406/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2406/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2405
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2405/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2405/comments
https://api.github.com/repos/coleifer/peewee/issues/2405/events
https://github.com/coleifer/peewee/issues/2405
878,832,736
MDU6SXNzdWU4Nzg4MzI3MzY=
2,405
PostgreSQL Autoreconnect / migrations
{ "login": "konradkur", "id": 22791650, "node_id": "MDQ6VXNlcjIyNzkxNjUw", "avatar_url": "https://avatars.githubusercontent.com/u/22791650?v=4", "gravatar_id": "", "url": "https://api.github.com/users/konradkur", "html_url": "https://github.com/konradkur", "followers_url": "https://api.github.com/users/konradkur/followers", "following_url": "https://api.github.com/users/konradkur/following{/other_user}", "gists_url": "https://api.github.com/users/konradkur/gists{/gist_id}", "starred_url": "https://api.github.com/users/konradkur/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/konradkur/subscriptions", "organizations_url": "https://api.github.com/users/konradkur/orgs", "repos_url": "https://api.github.com/users/konradkur/repos", "events_url": "https://api.github.com/users/konradkur/events{/privacy}", "received_events_url": "https://api.github.com/users/konradkur/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Automatic reconnect can be done with the help of the `playhouse.shortcuts.ReconnectMixin`, but you will definitely need to modify the `reconnect_errors` attribute so that it corresponds to Postgres-specific error conditions. The reconnect mixin should not be used with Postgres unless you REALLY know what you are doing. See the source code: https://github.com/coleifer/peewee/blob/master/playhouse/shortcuts.py\r\n\r\nPeewee provides a helper for writing migrations: http://docs.peewee-orm.com/en/latest/peewee/playhouse.html#schema-migrations\r\n\r\nI can't vouch for any of the \"automatic\" migration tools." ]
"2021-05-07T11:35:40"
"2021-05-07T13:22:13"
"2021-05-07T13:22:13"
NONE
null
Hello guys, i try find solutions for postgresql autoreconnect, any ideas? next question, the best migration system for peewee it? thanks, Konrad
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2405/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2405/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2404
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2404/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2404/comments
https://api.github.com/repos/coleifer/peewee/issues/2404/events
https://github.com/coleifer/peewee/issues/2404
878,560,665
MDU6SXNzdWU4Nzg1NjA2NjU=
2,404
The problem of storing timestamps
{ "login": "xiaoqge", "id": 8544686, "node_id": "MDQ6VXNlcjg1NDQ2ODY=", "avatar_url": "https://avatars.githubusercontent.com/u/8544686?v=4", "gravatar_id": "", "url": "https://api.github.com/users/xiaoqge", "html_url": "https://github.com/xiaoqge", "followers_url": "https://api.github.com/users/xiaoqge/followers", "following_url": "https://api.github.com/users/xiaoqge/following{/other_user}", "gists_url": "https://api.github.com/users/xiaoqge/gists{/gist_id}", "starred_url": "https://api.github.com/users/xiaoqge/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/xiaoqge/subscriptions", "organizations_url": "https://api.github.com/users/xiaoqge/orgs", "repos_url": "https://api.github.com/users/xiaoqge/repos", "events_url": "https://api.github.com/users/xiaoqge/events{/privacy}", "received_events_url": "https://api.github.com/users/xiaoqge/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[]
"2021-05-07T07:37:21"
"2021-05-07T08:01:43"
"2021-05-07T08:01:43"
NONE
null
Hello, can't the DateTimeField field store a timestamp without a time zone? Thank you very much for your help every time ``` from peewee import * db = PostgresqlDatabase('peewee_test',user='postgres',host="10.10.17.2",password='111') #db2 = PostgresqlDatabase('peewee_test',user='postgres',host="10.10.17.2",password='111') # 2nd connection class Currnumber(Model): tx_at = DateTimeField() class Meta: database = db db.create_tables([Currnumber]) Currnumber.create(tx_at="1620372845") ``` peewee.DataError: date/time field value out of range: "1620372845" LINE 1: INSERT INTO "currnumber" ("tx_at") VALUES ('1620372845') RET... ^ HINT: Perhaps you need a different "datestyle" setting. I know the following way: **So you should: Use DateTimeField if you want to work with datetime in python and store the data using the datetime data-type in your sql db. Use TimestampField if you want to work with datetime in python and store the data using an integer in your sql db. Use IntegerField if you want to work with timestamps as integers in python and store the data as an integer in your db.** However, timescaledb of postgresql creates supertables to store time series data at intervals of time fields, which makes peewee unable to store supertable data of timescaledb,Below is their documentation, so what can I do to solve?Thanks again https://docs.timescale.com/timescaledb/latest/how-to-guides/hypertables/create/#create-a-hypertable
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2404/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2404/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2403
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2403/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2403/comments
https://api.github.com/repos/coleifer/peewee/issues/2403/events
https://github.com/coleifer/peewee/issues/2403
877,681,739
MDU6SXNzdWU4Nzc2ODE3Mzk=
2,403
About the postgresql update problem
{ "login": "xiaoqge", "id": 8544686, "node_id": "MDQ6VXNlcjg1NDQ2ODY=", "avatar_url": "https://avatars.githubusercontent.com/u/8544686?v=4", "gravatar_id": "", "url": "https://api.github.com/users/xiaoqge", "html_url": "https://github.com/xiaoqge", "followers_url": "https://api.github.com/users/xiaoqge/followers", "following_url": "https://api.github.com/users/xiaoqge/following{/other_user}", "gists_url": "https://api.github.com/users/xiaoqge/gists{/gist_id}", "starred_url": "https://api.github.com/users/xiaoqge/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/xiaoqge/subscriptions", "organizations_url": "https://api.github.com/users/xiaoqge/orgs", "repos_url": "https://api.github.com/users/xiaoqge/repos", "events_url": "https://api.github.com/users/xiaoqge/events{/privacy}", "received_events_url": "https://api.github.com/users/xiaoqge/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Ah, I see the problem.\r\n\r\nWhen Postgresql runs into an IntegrityError (the exception that occurs when you violate the unique constraint, e.g.) then you *have* to rollback the transaction. The connection gets into a bad state and no further queries can be run until you rollback. The problem is you have started your Tx before you insert the first row. So when you are forced to rollback, you are rolling back the insert." ]
"2021-05-06T16:15:31"
"2021-05-06T20:25:18"
"2021-05-06T20:24:30"
NONE
null
I am using pgsql 13.2, I tried to execute the following code, and I commented the commit, but an error occurred after executing the update, may I ask where the problem is, thank you very much ``` from peewee import * db = PostgresqlDatabase('peewee_test',user='postgres',host="10.10.17.2",password='11') db2 = PostgresqlDatabase('peewee_test',user='postgres',host="10.10.17.2",password='11') # 2nd connection class Reg(Model): name = CharField(null=True,unique=True) key = TextField() class Meta: database = db class Reg2(Reg): # model class for accessing table using 2nd conn class Meta: database = db2 table_name = 'reg' class Test(): def test_db(self): db.create_tables([Reg]) with db.manual_commit() as tx: db.begin() for i in range(1,10): try: Reg.create(key='k1',name="test") # create a row using first conn print("11111") except: Reg.update(key='k2').where(Reg.name == "test22").execute() print("22222") db2.connect() # query table using 2nd conn print('is "k1" visible to conn2 BEFORE commit?') print('rows in "reg" table: %s' % Reg2.select().count()) #db.commit() print('is "k1" visible to conn2 AFTER commit?') print('rows in "reg" table: %s' % Reg2.select().count()) db2.close() #db.drop_tables([Reg]) T=Test() T.test_db() ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2403/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2403/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2402
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2402/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2402/comments
https://api.github.com/repos/coleifer/peewee/issues/2402/events
https://github.com/coleifer/peewee/issues/2402
877,539,688
MDU6SXNzdWU4Nzc1Mzk2ODg=
2,402
Postgresql transaction problem
{ "login": "xiaoqge", "id": 8544686, "node_id": "MDQ6VXNlcjg1NDQ2ODY=", "avatar_url": "https://avatars.githubusercontent.com/u/8544686?v=4", "gravatar_id": "", "url": "https://api.github.com/users/xiaoqge", "html_url": "https://github.com/xiaoqge", "followers_url": "https://api.github.com/users/xiaoqge/followers", "following_url": "https://api.github.com/users/xiaoqge/following{/other_user}", "gists_url": "https://api.github.com/users/xiaoqge/gists{/gist_id}", "starred_url": "https://api.github.com/users/xiaoqge/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/xiaoqge/subscriptions", "organizations_url": "https://api.github.com/users/xiaoqge/orgs", "repos_url": "https://api.github.com/users/xiaoqge/repos", "events_url": "https://api.github.com/users/xiaoqge/events{/privacy}", "received_events_url": "https://api.github.com/users/xiaoqge/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[]
"2021-05-06T14:08:51"
"2021-05-06T14:30:36"
"2021-05-06T14:30:35"
NONE
null
In the code below, I commented the commit, but it can still be written to the database. I hope to write to the database after the commit. I used mysql before, but it is not normal to migrate to Postgresql. Could you please tell me where do I do this? is it wrong? thank you very much for your help ``` with db.manual_commit() as tx: db.begin() for b in range(curr_storage_hight, curr_storage_hight + 1000): if b > end_block: print("current wait new block") sleep(20) break self.starttime = datetime.datetime.now() print("Current check_his block scripthash key %s" % b) self.bnumber = b c =Currnumber.get_or_none(name="gradenumber") if c ==None: Currnumber.create(name="gradenumber", number=self.bnumber) else: Currnumber.update(number=self.bnumber).where(Currnumber.name == "gradenumber").execute() # db.commit() ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2402/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2402/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2401
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2401/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2401/comments
https://api.github.com/repos/coleifer/peewee/issues/2401/events
https://github.com/coleifer/peewee/issues/2401
875,083,573
MDU6SXNzdWU4NzUwODM1NzM=
2,401
FastAPI Framework Integration section (seems it) has incorrect information
{ "login": "gondolio", "id": 4338344, "node_id": "MDQ6VXNlcjQzMzgzNDQ=", "avatar_url": "https://avatars.githubusercontent.com/u/4338344?v=4", "gravatar_id": "", "url": "https://api.github.com/users/gondolio", "html_url": "https://github.com/gondolio", "followers_url": "https://api.github.com/users/gondolio/followers", "following_url": "https://api.github.com/users/gondolio/following{/other_user}", "gists_url": "https://api.github.com/users/gondolio/gists{/gist_id}", "starred_url": "https://api.github.com/users/gondolio/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/gondolio/subscriptions", "organizations_url": "https://api.github.com/users/gondolio/orgs", "repos_url": "https://api.github.com/users/gondolio/repos", "events_url": "https://api.github.com/users/gondolio/events{/privacy}", "received_events_url": "https://api.github.com/users/gondolio/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I'm not sure what the correct replacement is, but here is the Peewee page in FastAPI:\r\nhttps://fastapi.tiangolo.com/advanced/sql-databases-peewee/", "I'm not familiar with FastAPI, that section was contributed. Since its async I assume that it is, in fact, rather complicated to use Peewee correctly with it. You would want to have a connection-per-async-context presumably, or a pool of conns that each async context can utilize. For normal python this is easy -- we store the db conn in a threadlocal. This also works for gevent, which monkeypatches threadlocal to be green-thread local. For async stuff like FastAPI you're on your own in terms of figuring that out - you can scope your connection to synchronous blocks and that might work -- I suppose that's what the startup/shutdown event implies.", "@coleifer async APIs become more and more popular. specifically FastAPI use is soaring. \r\nAny plans of supporting async apis which does not follow the thread per web request pattern? \r\n\r\nThanks", "There's no accounting for the multiplicity of developers tastes and opinions. My own view is that the pythonic way of doing async in python is to use gevent. Why?\r\n\r\n* No need to change your codebase or litter it with `async ...`, `await`.\r\n* No confusion around coroutines, tasks, futures, loops, etc.\r\n* Works seamlessly with existing frameworks such as Django, Flask, etc.\r\n* Because it handles switching implicitly, you don't need to worry if you forgot to yield somewhere.\r\n* No need to modify or search for special \"async\" versions of popular libraries or clients.\r\n* Works with database drivers as well, like pymysql and psycopg2.\r\n* Uses the familiar threading APIs and provides a \"greenlet\"-local, locks, events, queues, etc.\r\n* Performance\r\n* https://journal.stuffwithstuff.com/2015/02/01/what-color-is-your-function/\r\n\r\nPeewee supports the standard threading model, and by virtue of this, also supports gevent. At present I have no plans to make an async-aware version.", "Thanks for the quick response @coleifer.\r\n\r\nWell thats very unfortunate. ORMs should not force anything about the API tier. no matter how many benefits gevent has, \r\nI have my own constraints and reasons not to use it. either way as I said the python community is moving really fast toward async await, and it's gonna leave peewee behind.\r\n\r\nAs a peewee user who wants to use FastAPI / async await for my API I am currently in a problem.\r\n\r\nI would really appreciate anything looking into this and supporting / making async-aware version for peewee.\r\n\r\n", ">python community is moving really fast\r\n\r\nYes, it is moving fast (and breaking things). It seems that mindset has infected a lot of web-adjacent languages and communities.\r\n\r\nIt's always been my opinion that one should use the right tool for the job. Golang, for example, has a much better concurrency story by default for web development, as well as offering strong typing (something that Python also is flirting with). There are lots of languages out there. Rather than be all things to all people, Peewee plays to Python's strengths as I see them. Namely:\r\n\r\n* Dynamism\r\n* Simplicity, succintness\r\n* Composability\r\n\r\nThere are various 3rd party libraries that provide async stuff for Peewee, but I cannot vouch for any personally. Google will help you find them." ]
"2021-05-04T04:06:13"
"2022-02-09T15:38:31"
"2021-05-04T12:48:01"
NONE
null
In the [documentation](http://docs.peewee-orm.com/en/latest/peewee/database.html#framework-integration), it says > We’ll open the connection when a request is received, then close it when the response is returned. and it does this using "startup" and "shutdown" events. But if you look at the FastAPI [documentation](https://fastapi.tiangolo.com/advanced/events/), these events are triggered only when the **application** does startup/shutdown: > To add a function that should be run before the application starts, declare it with the event "startup" > To add a function that should be run when the application is shutting down, declare it with the event "shutdown" You can confirm this by launching the server and seeing it only runs the startup() function once when it launches.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2401/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2401/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2400
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2400/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2400/comments
https://api.github.com/repos/coleifer/peewee/issues/2400/events
https://github.com/coleifer/peewee/issues/2400
874,917,846
MDU6SXNzdWU4NzQ5MTc4NDY=
2,400
Free memory from cache?
{ "login": "SamNPowers", "id": 881718, "node_id": "MDQ6VXNlcjg4MTcxOA==", "avatar_url": "https://avatars.githubusercontent.com/u/881718?v=4", "gravatar_id": "", "url": "https://api.github.com/users/SamNPowers", "html_url": "https://github.com/SamNPowers", "followers_url": "https://api.github.com/users/SamNPowers/followers", "following_url": "https://api.github.com/users/SamNPowers/following{/other_user}", "gists_url": "https://api.github.com/users/SamNPowers/gists{/gist_id}", "starred_url": "https://api.github.com/users/SamNPowers/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/SamNPowers/subscriptions", "organizations_url": "https://api.github.com/users/SamNPowers/orgs", "repos_url": "https://api.github.com/users/SamNPowers/repos", "events_url": "https://api.github.com/users/SamNPowers/events{/privacy}", "received_events_url": "https://api.github.com/users/SamNPowers/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Unfortunately, besides `.iterator()` the only other thing you might do would be to explicitly `.select()` all columns except for the large one. You could then implement a property/accessor to load the large column on-demand.\r\n\r\n```python\r\n\r\nclass Post(Model):\r\n title = TextField()\r\n _attachment = BlobField(column_name='attachment') # may have large binary data, e.g.\r\n\r\n @property\r\n def attachment(self):\r\n if self._attachment is None:\r\n post = Post.select(Post._attachment).get(Post.id == self.id)\r\n self._attachment = post._attachment\r\n return self_attachment\r\n```", "I do have a property/accessor to load the large column on demand. The problem is unloading it after I'm done with it. \r\n\r\nWould deleting the object and then re-loading all but the large column be the best way forward?", ">The problem is unloading it after I'm done with it.\r\n\r\nYou can use property deleters to free the memory:\r\n\r\n```python\r\n\r\nclass Post(Model):\r\n @property\r\n def attachment(self):\r\n # same as above...\r\n\r\n @attachment.deleter\r\n def attachment(self):\r\n self.__data__.pop('_attachment', None)\r\n\r\np = Post...\r\np.attachment # load from memory or pull from database\r\ndel p.attachment # frees cached data in model instance\r\n```", "Is there an easy way to do this for an entry in a ManyToManyField?\r\n\r\n```\r\nfrom peewee import SqliteDatabase, Model, TextField, BlobField, ManyToManyField\r\n\r\n\r\nclass Post(Model):\r\n title = TextField()\r\n _attachment = BlobField(column_name='attachment') # may have large binary data, e.g.\r\n\r\n @property\r\n def attachment(self):\r\n if self._attachment is None:\r\n post = Post.select(Post._attachment).get(Post.id == self.id)\r\n self._attachment = post._attachment\r\n return self._attachment\r\n\r\n\r\n @attachment.deleter\r\n def attachment(self):\r\n self.__data__.pop('_attachment', None)\r\n\r\n\r\nclass PostCollector(Model):\r\n post_collection = ManyToManyField(Post)\r\n\r\n\r\nif __name__ == \"__main__\":\r\n db = SqliteDatabase(\"test_db\")\r\n PostCollectionRelationship = PostCollector.post_collection.get_through_model()\r\n db.bind([Post, PostCollector, PostCollectionRelationship])\r\n if not Post.table_exists():\r\n db.create_tables([Post, PostCollector, PostCollectionRelationship])\r\n db.connect(reuse_if_open=True)\r\n\r\n post = Post.create(title=\"foo\", _attachment=\"bar\")\r\n fetched_posts = Post.select().limit(1).execute() # Get an entry (saves us from needing to specify id above)\r\n collector = PostCollector.create()\r\n collector.post_collection.add(fetched_posts[0])\r\n\r\n attachment = collector.post_collection[0].attachment\r\n del collector.post_collection[0].attachment\r\n print(collector.post_collection[0]._attachment)\r\n```\r\n\r\nIt seems to work if you're manipulating the Post directly, but if it was accessed via a ManyToManyField, it doesn't seem to hold. (b'bar' prints after execution of the above code, not \"attribute does not exist\" or something like it.)", "Because you're accessing it through the property, which re-fetches it from the db. Your code:\r\n\r\n1. gets the attachment\r\n2. frees the cached attachment data\r\n3. re-fetches it from the db", "Er, I'm sorry, the code has a typo. The last \"attachment\" is supposed to be \"_attachment\". Fixed it. But it still outputs b\"bar\".\r\n\r\nIn this case, the field shouldn't be getting refetched, since it's not going through the accessor. But nevertheless it is still there.", "Oh, I see - every time you index into that `collector.post_collection` (`collector.post_collection[0]`) you're executing a query and getting a new instance from the db.\r\n\r\nIf you pull it into a variable then it will work:\r\n\r\n```python\r\n post = collector.post_collection[0]\r\n print(post.attachment)\r\n del post.attachment\r\n print(post._attachment)\r\n```", "I do need to be able to manipulate (my version of) post_collection in some ways. My goal was to be able to ignore this specific field on posts except when it's necessary. Is it the case that every action (such as fetching a set of random posts) will re-fetch all attachments? Is there a convenient way to tell the ManyToManyField not to re-fetch its entries in this way? (E.g. if I want to use collector.post_collection.order_by(fn.Rand()).limit(5), will this cause all attachments to be re-fetched? Just the set returned? Either is undesirable, for my use case.)\r\n\r\nRelatedly: is there a recommended way to view the amount of RAM a given model is consuming? I've in general been using `from pympler import asizeof`, then using `asizeof.asizeof(obj)`, but neither adding elements to post_collection nor removing attachment from elements are causing changes in size of post_collection or collector (while a reduction is seen for individual posts). As I can't access elements on post_collection directly to check whether attachment is or is not on them again without ensuring the answer is \"yes\", I'm not sure how to debug this.\r\n\r\nMy essential problem is that even with del'ing these large fields off of my objects, my memory consumption has not been reduced as I would expect.", "Also, it would seem a ManyToManyField can't be pop'd off `__data__` the way other fields can (as `__data__` doesn't seem to contain it). What would the analogy be for a ManyToManyField?" ]
"2021-05-03T21:17:27"
"2021-05-07T05:41:04"
"2021-05-03T21:52:00"
NONE
null
Hi, thanks for the great repo. I have a db Model with one very large field on it that I don't need to access very often. I would like to be able to load it in, then remove it from cache after I'm done with it, to free the RAM for other things. I saw that iterator() exists, but it doesn't quite fit my use case. Could there be a more granular mechanism? (Or if there already is, apologies! I couldn't find it in the documentation.) Thanks!
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2400/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2400/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2399
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2399/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2399/comments
https://api.github.com/repos/coleifer/peewee/issues/2399/events
https://github.com/coleifer/peewee/issues/2399
874,743,598
MDU6SXNzdWU4NzQ3NDM1OTg=
2,399
DataSet "peewee.OperationalError: duplicate column name" raised when unique column name with different case is present in thawed CSV file
{ "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
[ "I don't necessarily agree that this needs to be fixed by Peewee -- presumably you can sanitize or normalize this data." ]
"2021-05-03T17:01:33"
"2021-05-06T15:43:24"
"2021-05-06T15:43:24"
NONE
null
Issue originally reported by @bromleysj Running peewee-3.14.1 on Python 3.9. Consider the following example: ``` # demo.py from playhouse.dataset import DataSet database = "test.db" database = DataSet(f"sqlite:///{database}") users = database["Users"] users.insert(user_id="test") users.create_index(["user_id"], unique=True) users.delete(user_id="test") users.thaw(filename='test_accounts.csv', format="csv") ``` If we try to add data from a .csv file with a column named "USER_ID", all uppercase, a _peewee.OperationalError: duplicate column name_ exception will be raised. The issue only occurs if the affected column has been marked as unique when creating the table and can be worked around by making the affected column in the .csv file match the case of the corresponding column in the existing table. This .csv file will fail: ``` USER_ID,EMAIL,NAME,LASTNAME Larisa.Yesima75,Larisa,Yesima,Larisa.Yesima75@testmail.com ``` This .csv file will pass: ``` user_id,EMAIL,NAME,LASTNAME Larisa.Yesima75,Larisa,Yesima,Larisa.Yesima75@testmail.com ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2399/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2399/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2398
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2398/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2398/comments
https://api.github.com/repos/coleifer/peewee/issues/2398/events
https://github.com/coleifer/peewee/issues/2398
873,860,629
MDU6SXNzdWU4NzM4NjA2Mjk=
2,398
How can I split the table in Peewee?
{ "login": "nic519", "id": 2610741, "node_id": "MDQ6VXNlcjI2MTA3NDE=", "avatar_url": "https://avatars.githubusercontent.com/u/2610741?v=4", "gravatar_id": "", "url": "https://api.github.com/users/nic519", "html_url": "https://github.com/nic519", "followers_url": "https://api.github.com/users/nic519/followers", "following_url": "https://api.github.com/users/nic519/following{/other_user}", "gists_url": "https://api.github.com/users/nic519/gists{/gist_id}", "starred_url": "https://api.github.com/users/nic519/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/nic519/subscriptions", "organizations_url": "https://api.github.com/users/nic519/orgs", "repos_url": "https://api.github.com/users/nic519/repos", "events_url": "https://api.github.com/users/nic519/events{/privacy}", "received_events_url": "https://api.github.com/users/nic519/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "You're going to have a hard time, basically.\r\n\r\nYou might create a VIEW or something that unions together all these tables, and just select from that view for read-only queries.\r\n\r\nFor writing you will need to either\r\n\r\n1. change the `table_name` at runtime (`db_table` is deprecated, it has been renamed to `table_name`)\r\n2. create a model-per-table and pick the right one at runtime" ]
"2021-05-02T06:10:29"
"2021-05-02T17:28:19"
"2021-05-02T17:28:19"
NONE
null
``` class User(Model): id = IntegerField() name = CharField() Class Meta: database = db # db connection db_table = 'user_00' # Here is the problem ``` We have a lot of users, and I have to split the table like user_00,user_01,user_0...user_09. If I use the field db_table, I can't do that, and I also don't want to create more model. BTW, I know the function called db_table_func, but there are no more usage in the doc. How do you use the split table in your project? Thx, I really need help!
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2398/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2398/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2397
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2397/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2397/comments
https://api.github.com/repos/coleifer/peewee/issues/2397/events
https://github.com/coleifer/peewee/pull/2397
873,075,143
MDExOlB1bGxSZXF1ZXN0NjI3OTI0MjUz
2,397
Added two special expressions, for BooleanField
{ "login": "daveusa31", "id": 81916132, "node_id": "MDQ6VXNlcjgxOTE2MTMy", "avatar_url": "https://avatars.githubusercontent.com/u/81916132?v=4", "gravatar_id": "", "url": "https://api.github.com/users/daveusa31", "html_url": "https://github.com/daveusa31", "followers_url": "https://api.github.com/users/daveusa31/followers", "following_url": "https://api.github.com/users/daveusa31/following{/other_user}", "gists_url": "https://api.github.com/users/daveusa31/gists{/gist_id}", "starred_url": "https://api.github.com/users/daveusa31/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/daveusa31/subscriptions", "organizations_url": "https://api.github.com/users/daveusa31/orgs", "repos_url": "https://api.github.com/users/daveusa31/repos", "events_url": "https://api.github.com/users/daveusa31/events{/privacy}", "received_events_url": "https://api.github.com/users/daveusa31/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "You don't even need `.is_true()` honestly, you can just:\r\n\r\n```python\r\n.where(User.is_activated)\r\n```\r\n\r\nOr for false:\r\n\r\n```python\r\n.where(~User.is_activated)\r\n```\r\n\r\nGoing to pass on this change." ]
"2021-04-30T18:46:01"
"2021-04-30T19:04:42"
"2021-04-30T19:04:01"
NONE
null
To write queries like this, ```python User.select().where(User.is_activated.is_true()) ``` And not like this ```python User.select().where(User.is_activated == True) ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2397/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2397/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/2397", "html_url": "https://github.com/coleifer/peewee/pull/2397", "diff_url": "https://github.com/coleifer/peewee/pull/2397.diff", "patch_url": "https://github.com/coleifer/peewee/pull/2397.patch", "merged_at": null }
https://api.github.com/repos/coleifer/peewee/issues/2396
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2396/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2396/comments
https://api.github.com/repos/coleifer/peewee/issues/2396/events
https://github.com/coleifer/peewee/issues/2396
867,122,756
MDU6SXNzdWU4NjcxMjI3NTY=
2,396
Identity Map and Unit of Work Question
{ "login": "mkmoisen", "id": 2534631, "node_id": "MDQ6VXNlcjI1MzQ2MzE=", "avatar_url": "https://avatars.githubusercontent.com/u/2534631?v=4", "gravatar_id": "", "url": "https://api.github.com/users/mkmoisen", "html_url": "https://github.com/mkmoisen", "followers_url": "https://api.github.com/users/mkmoisen/followers", "following_url": "https://api.github.com/users/mkmoisen/following{/other_user}", "gists_url": "https://api.github.com/users/mkmoisen/gists{/gist_id}", "starred_url": "https://api.github.com/users/mkmoisen/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/mkmoisen/subscriptions", "organizations_url": "https://api.github.com/users/mkmoisen/orgs", "repos_url": "https://api.github.com/users/mkmoisen/repos", "events_url": "https://api.github.com/users/mkmoisen/events{/privacy}", "received_events_url": "https://api.github.com/users/mkmoisen/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I dislike identity map and unit of work because they hide too much from the user and require some concept of a \"session\". Are sessions transactions? Connection lifetimes? Are they thread-safe? What kind of error-handling do they provide? Etc.\r\n\r\nI find it easier to think in terms of the abstractions provided by the db itself. A connection, beginning/committing transactions, during which queries are executed. And SQL, which can read row tuples into memory or write new/modified data back to the db.\r\n\r\nSessions, identity maps, unit-of-work all tend to obscure these things rather than simplify them - in my opinion.", "@coleifer Would you be able to comment on the purported benefits of using Identity Map/Unit of Work? \r\n\r\nI agree with you that these tend to just add complexity. However I'm not sure if there is some benefit that I may not be considering.", "The idea of unit-of-work is that the library can do a better job aggregating your queries for you, possibly de-duping things or rolling up small modifications into more efficient operations, as well as other things like dependency-resolution. It goes hand-in-hand with identity-map since maybe you modified some object in several places or there are branches that perform modifications which may or may not be followed.", "Thanks. Do you have an opinion on the Active Record vs Data Mapper argument?\r\n\r\nMy understanding is that those who prefer Data Mapper say that Active Record causes a coupling between business logic and persistence logic, and that this is in general a bad thing. I'm struggling a bit to understand why this is a bad thing, but perhaps I have not worked on any extremely complicated applications where it might be more obvious to understand the benefits.", ">Active Record vs Data Mapper\r\n>...\r\n>extremely complicated applications where it might be more obvious\r\n\r\nI think that's the reasoning. A mapped object may encompass multiple tables and is also more explicit about its relations. As you may be able to infer from Peewee's design, it's not really possible to do \"inheritance\" with multiple tables (Django allows this, but it is a vile hack IMO). Perhaps D/M makes more sense in a statically-typed language, as well.\r\n\r\nConsider also schema changes -- w/activerecord your model class must match the schema. With D/M I suppose you have a little bit more flexibility in being able to \"paper-over\" certain types of discrepancies.\r\n\r\nI prefer active record because I like to think in terms of the row tuples and thus the models as simply being handy containers for manipulating them.", "@coleifer Thank you for the insight." ]
"2021-04-25T21:50:43"
"2021-04-26T15:20:09"
"2021-04-26T00:17:00"
NONE
null
This is not a bug/issue, rather a design question. I've spent quite a lot of time reading about the Active Record vs Identity Map/Unit of Work debates, and it seems like the general consensus is that Identity Map/Unit of Work is a good thing, and superior to Active Record. However, I fundamentally do not understand what benefits I as a developer would get from an Identity Map/Unit of Work. I was hoping you might have some insight, as you designed Peewee as Active Record, and might have thought on this subject. Would you mind explaining what are the real benefits from using Identity Map and Unit of Work in an ORM? ----- What follows is my understanding of some minor benefits. I have a vague suspicion that these are not the real benefits, and that there are some core and fundamental benefits that I am not grasping. **Identity Map** With an Identity Map the primary key of objects are stored in a dict. If you later query the database for the same row, you will receive an identical object from the Identity Map instead of a duplicate object. I don't get why this is a good thing. In fact I can think of situations in which this might be bad, for example if you are polling the database for recent changes from an external source. In SQLAlchemy you have to expire your object and then issue the query. In Peewee it just works. It seems to me like you shouldn't be querying the same row twice unless you had a valid reason (like polling). Otherwise I would call this a bug and would refactor the logic instead of relying on an Identity Map to help. Moreover, it is not like you get to save a trip to the DB - SQLAlchemy for example makes the trip to the DB but then returns the same object from the identity map. So you cannot argue that this Identity Map is like a cache (unless you do session.get()) which will pull the object from the identity map). I think there must be some other fundamental benefit from the Identity Map that I just have not discovered. **Unit of Work** My understanding is that a Unit of Work is like a virtual transaction within the ORM which keeps track of all the modifications you have made to objects. This way you can just call session.commit() and it will figure out which records need to be updated or inserted, without you having to explicitly call the update or insert method on each object. One example I have read is that if you update the same object in two different parts of your code, the Unit of Work is smart enough to only issue one update statement. But I just don't see how it is that difficult for the developer to only call update at the end instead of during the middle of a function. Another example is that if you loop over a parent and its children, and modify each object, you can just call save to persist the object graph, instead of having to individually save each item. Personally I would rather do a single update statement to update in the database directly instead of doing this. Moreover I don't see how it is that inconvenient to explicitly update each object. As with Identity Map, it seems I am missing something fundamental about Unit of Work.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2396/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2396/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2395
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2395/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2395/comments
https://api.github.com/repos/coleifer/peewee/issues/2395/events
https://github.com/coleifer/peewee/issues/2395
863,436,433
MDU6SXNzdWU4NjM0MzY0MzM=
2,395
Postgresql support TimescaleDB ?
{ "login": "xiaoqge", "id": 8544686, "node_id": "MDQ6VXNlcjg1NDQ2ODY=", "avatar_url": "https://avatars.githubusercontent.com/u/8544686?v=4", "gravatar_id": "", "url": "https://api.github.com/users/xiaoqge", "html_url": "https://github.com/xiaoqge", "followers_url": "https://api.github.com/users/xiaoqge/followers", "following_url": "https://api.github.com/users/xiaoqge/following{/other_user}", "gists_url": "https://api.github.com/users/xiaoqge/gists{/gist_id}", "starred_url": "https://api.github.com/users/xiaoqge/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/xiaoqge/subscriptions", "organizations_url": "https://api.github.com/users/xiaoqge/orgs", "repos_url": "https://api.github.com/users/xiaoqge/repos", "events_url": "https://api.github.com/users/xiaoqge/events{/privacy}", "received_events_url": "https://api.github.com/users/xiaoqge/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I don't know anything about TimescaleDB. Peewee supports anything that speaks the postgres protocol via the psycopg2 driver. If psycopg2 supports it, then its likely supported in peewee." ]
"2021-04-21T04:28:25"
"2021-04-24T17:12:17"
"2021-04-24T17:12:17"
NONE
null
Hello, does Postgresql support the extension of TimescaleDB?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2395/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2395/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2394
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2394/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2394/comments
https://api.github.com/repos/coleifer/peewee/issues/2394/events
https://github.com/coleifer/peewee/issues/2394
862,563,007
MDU6SXNzdWU4NjI1NjMwMDc=
2,394
Control result iterator in prefetch
{ "login": "surajrav", "id": 8673958, "node_id": "MDQ6VXNlcjg2NzM5NTg=", "avatar_url": "https://avatars.githubusercontent.com/u/8673958?v=4", "gravatar_id": "", "url": "https://api.github.com/users/surajrav", "html_url": "https://github.com/surajrav", "followers_url": "https://api.github.com/users/surajrav/followers", "following_url": "https://api.github.com/users/surajrav/following{/other_user}", "gists_url": "https://api.github.com/users/surajrav/gists{/gist_id}", "starred_url": "https://api.github.com/users/surajrav/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/surajrav/subscriptions", "organizations_url": "https://api.github.com/users/surajrav/orgs", "repos_url": "https://api.github.com/users/surajrav/repos", "events_url": "https://api.github.com/users/surajrav/events{/privacy}", "received_events_url": "https://api.github.com/users/surajrav/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Prefetch is not designed as a replacement for serialization - it is to help reduce queries in certain cases. The complexity of mapping relations back to instances precludes providing different result-types (like dicts or tuples) -- so models are always returned. Any additional processing can then work on the model instances which have efficiently been loaded into memory.\r\n\r\n>But I'm afraid that this means 2 iterations over the desired set and want to know if I can supply this serializing logic via a hook or something.\r\n\r\nI doubt very much this is as much of a problem as you imagine. I'd suggest profiling if you're in doubt." ]
"2021-04-20T08:29:12"
"2021-04-20T13:50:41"
"2021-04-20T13:50:41"
NONE
null
Hi, I would like to know if there is a way to specify the iterator per row in a prefetch query. Ideally, I would like to add a `.dicts()` to the end of my prefetch query along with specifying which fields to add to the dict that may not be in the base queries select. *Current Model and Query Setup* The scenario I have is as follows: ``` class User(BaseModel): .... //some user fields class Tool(BaseModel): .... //other fields location = peewee.ForeignKeyField(Location, backref='tools') class Location(BaseModel) users = peewee.ManyToManyField(User, backref='locations') ... // other fields LocationUser = Location.users.get_through_model() locations = Location.select(Location.field1, Location.field2, fn.COUNT(Tool.id).alias('tools_count')).join(Tool, JOIN.LEFT_OUTER).group_by(Location) res = prefetch(locations, LocationUser, User) ``` * Current Result*: List of Location Objects *Desired Result* ```[{'id': 'idval', 'field1': 'val1, 'tools_count': 0, 'users': [{user dict fields}, ...]} ,...]``` For now, I'm taking the returned list from prefetch and serializing it by running over this list. But I'm afraid that this means 2 iterations over the desired set and want to know if I can supply this serializing logic via a hook or something. Please let me know if my provided context is insufficient
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2394/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2394/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2393
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2393/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2393/comments
https://api.github.com/repos/coleifer/peewee/issues/2393/events
https://github.com/coleifer/peewee/issues/2393
861,114,230
MDU6SXNzdWU4NjExMTQyMzA=
2,393
bulk_create does not work with bulk created foreignkey
{ "login": "elya5", "id": 4464481, "node_id": "MDQ6VXNlcjQ0NjQ0ODE=", "avatar_url": "https://avatars.githubusercontent.com/u/4464481?v=4", "gravatar_id": "", "url": "https://api.github.com/users/elya5", "html_url": "https://github.com/elya5", "followers_url": "https://api.github.com/users/elya5/followers", "following_url": "https://api.github.com/users/elya5/following{/other_user}", "gists_url": "https://api.github.com/users/elya5/gists{/gist_id}", "starred_url": "https://api.github.com/users/elya5/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/elya5/subscriptions", "organizations_url": "https://api.github.com/users/elya5/orgs", "repos_url": "https://api.github.com/users/elya5/repos", "events_url": "https://api.github.com/users/elya5/events{/privacy}", "received_events_url": "https://api.github.com/users/elya5/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "The bulk create API doesn't set the fk value automatically.\r\n\r\nJust wrap it in a transaction and it will be plenty fast." ]
"2021-04-19T09:40:43"
"2021-04-19T12:57:28"
"2021-04-19T12:57:28"
NONE
null
Hi, I have the following models: ``` class WWW(Model): mdate = CharField(null=True) key = CharField(null=True) title = CharField(null=True) url = CharField(null=True) class Meta: database = d class AuthorField(Model): name = CharField() www = ForeignKeyField(WWW, backref='names') class Meta: database = d ``` I have to insert a lot of entries so I wanted to use bulk insertion. However I'm running into the following error (the first part is just to demonstrate that it works without `bulk_create`) ``` >>> a=WWW(title='test') >>> b=AuthorField(name='testname') >>> b.www = a >>> a.save() 1 >>> b.save() 1 >>> a=WWW(title='test2') >>> b=AuthorField(name='testname2') >>> b.www = a >>> WWW.bulk_create([a]) >>> AuthorField.bulk_create([b]) Traceback (most recent call last): File "/home/user/.local/lib/python3.9/site-packages/peewee.py", line 3144, in execute_sql cursor.execute(sql, params or ()) sqlite3.IntegrityError: NOT NULL constraint failed: authorfield.www_id During handling of the above exception, another exception occurred: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/user/.local/lib/python3.9/site-packages/peewee.py", line 6378, in bulk_create res = cls.insert_many(accum, fields=fields).execute() File "/home/user/.local/lib/python3.9/site-packages/peewee.py", line 1907, in inner return method(self, database, *args, **kwargs) File "/home/user/.local/lib/python3.9/site-packages/peewee.py", line 1978, in execute return self._execute(database) File "/home/user/.local/lib/python3.9/site-packages/peewee.py", line 2745, in _execute return super(Insert, self)._execute(database) File "/home/user/.local/lib/python3.9/site-packages/peewee.py", line 2474, in _execute cursor = database.execute(self) File "/home/user/.local/lib/python3.9/site-packages/peewee.py", line 3157, in execute return self.execute_sql(sql, params, commit=commit) File "/home/user/.local/lib/python3.9/site-packages/peewee.py", line 3151, in execute_sql self.commit() File "/home/user/.local/lib/python3.9/site-packages/peewee.py", line 2917, in __exit__ reraise(new_type, new_type(exc_value, *exc_args), traceback) File "/home/user/.local/lib/python3.9/site-packages/peewee.py", line 190, in reraise raise value.with_traceback(tb) File "/home/user/.local/lib/python3.9/site-packages/peewee.py", line 3144, in execute_sql cursor.execute(sql, params or ()) peewee.IntegrityError: NOT NULL constraint failed: authorfield.www_id >>> ``` It works if I save each of the `WWW`s individually but that is way slower. Is there any way around this?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2393/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2393/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2392
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2392/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2392/comments
https://api.github.com/repos/coleifer/peewee/issues/2392/events
https://github.com/coleifer/peewee/issues/2392
860,869,660
MDU6SXNzdWU4NjA4Njk2NjA=
2,392
Passing max_length to CharField when used in ArrayField
{ "login": "TimothyBramlett", "id": 7890441, "node_id": "MDQ6VXNlcjc4OTA0NDE=", "avatar_url": "https://avatars.githubusercontent.com/u/7890441?v=4", "gravatar_id": "", "url": "https://api.github.com/users/TimothyBramlett", "html_url": "https://github.com/TimothyBramlett", "followers_url": "https://api.github.com/users/TimothyBramlett/followers", "following_url": "https://api.github.com/users/TimothyBramlett/following{/other_user}", "gists_url": "https://api.github.com/users/TimothyBramlett/gists{/gist_id}", "starred_url": "https://api.github.com/users/TimothyBramlett/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/TimothyBramlett/subscriptions", "organizations_url": "https://api.github.com/users/TimothyBramlett/orgs", "repos_url": "https://api.github.com/users/TimothyBramlett/repos", "events_url": "https://api.github.com/users/TimothyBramlett/events{/privacy}", "received_events_url": "https://api.github.com/users/TimothyBramlett/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Please post questions to stackoverflow.\r\n\r\n```python\r\nsome_field = ArrayField(CharField, field_kwargs={'max_length': 20}, null=True)\r\n```\r\n\r\nhttp://docs.peewee-orm.com/en/latest/peewee/playhouse.html#ArrayField" ]
"2021-04-19T03:54:39"
"2021-04-19T12:51:12"
"2021-04-19T12:51:12"
NONE
null
How would I pass max_length here: ``` some_field = ArrayField(peewee.CharField(max_length=20), null=True) ``` When I try to do that I get: ``` TypeError: 'CharField' object is not callable ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2392/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2392/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2391
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2391/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2391/comments
https://api.github.com/repos/coleifer/peewee/issues/2391/events
https://github.com/coleifer/peewee/pull/2391
860,154,238
MDExOlB1bGxSZXF1ZXN0NjE3MTA5MzA2
2,391
Add ability to create an instance from a back reference
{ "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
[ "The patch looks fine, but I have tried to stay away from that particular pandora's box. In the simple case it's straightforward, but it breaks the backref abstraction a bit, and there are just a few too many edge-cases. I prefer to keep it as a naive/simple `Select`.\r\n\r\nIf you really want this in your own app, I've pushed a patch 626b34856eeb842ad27c885f3c1fba95cce78399 that allows you to override the backref accessor class on your foreign-keys - making it hopefully easier to extend and use your own implementation." ]
"2021-04-16T20:40:14"
"2021-04-17T01:45:00"
"2021-04-16T23:43:17"
NONE
null
Allow an instance of a model to be created using the back reference. For example, if I have a `User` and I want to create a `Tweet` for that user then allow it to be used as `user.tweets.create()`. On a practical level this helps a lot when there are logs associated with a user or similar object. Compare the above with having to import the log model and do `Log.create(user=user, otherparam=value)` which can cause circular import issues with large projects. The patch provide is intended to provide an example. I tried to fit the style but am open to any changes needed. Thanks
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2391/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2391/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/2391", "html_url": "https://github.com/coleifer/peewee/pull/2391", "diff_url": "https://github.com/coleifer/peewee/pull/2391.diff", "patch_url": "https://github.com/coleifer/peewee/pull/2391.patch", "merged_at": null }
https://api.github.com/repos/coleifer/peewee/issues/2390
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2390/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2390/comments
https://api.github.com/repos/coleifer/peewee/issues/2390/events
https://github.com/coleifer/peewee/issues/2390
857,282,042
MDU6SXNzdWU4NTcyODIwNDI=
2,390
"can't set attribute" using "Recursive CTEs" on Nuke Python
{ "login": "websterek", "id": 40537787, "node_id": "MDQ6VXNlcjQwNTM3Nzg3", "avatar_url": "https://avatars.githubusercontent.com/u/40537787?v=4", "gravatar_id": "", "url": "https://api.github.com/users/websterek", "html_url": "https://github.com/websterek", "followers_url": "https://api.github.com/users/websterek/followers", "following_url": "https://api.github.com/users/websterek/following{/other_user}", "gists_url": "https://api.github.com/users/websterek/gists{/gist_id}", "starred_url": "https://api.github.com/users/websterek/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/websterek/subscriptions", "organizations_url": "https://api.github.com/users/websterek/orgs", "repos_url": "https://api.github.com/users/websterek/repos", "events_url": "https://api.github.com/users/websterek/events{/privacy}", "received_events_url": "https://api.github.com/users/websterek/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "The code you've highlighted is setting attributes dynamically onto an object, and this is a fairly fundamental thing to Peewee's operation. Possibly this is being prevented because these attributes correspond with the field instances declared on the model class? At any rate, this seems to be something you should bring up with the author of the python implementation you're attempting to use." ]
"2021-04-13T20:05:23"
"2021-04-13T21:27:42"
"2021-04-13T21:27:42"
NONE
null
Hi! I have problem will running peewee using Python built into Nuke software: ``` Python version 2.7.16 (v2.7.16-dirty:413a49145e, Aug 6 2019, 14:37:13) [MSC v.1913 64 bit (AMD64)] Version info. sys.version_info(major=2, minor=7, micro=16, releaselevel='final', serial=0) ``` In "normal" Python installation everything works as expected, only Python inside Nuke is problematic... for some reason :( Here is my code raising error, it's nearly one to one copy of example from [peewee documentation:](http://docs.peewee-orm.com/en/latest/peewee/querying.html#recursive-ctes) ``` def get_categories(category=None): Base = Category.alias() level = Value(1).alias("level") path = Base.name.alias("path") base_case = (Base.select(Base.id, Base.name, Base.icon, Base.parent, level, path).where(Base.parent == category).cte( "base", recursive=True)) RTerm = Category.alias() rlevel = (base_case.c.level + 1).alias("level") rpath = base_case.c.path.concat("/").concat(RTerm.name).alias("path") recursive = RTerm.select(RTerm.id, RTerm.name, RTerm.icon, RTerm.parent, rlevel, rpath).join(base_case, on=(RTerm.parent == base_case.c.id)) cte = base_case.union_all(recursive) query = cte.select_from(cte.c.name, cte.c.icon, cte.c.level, cte.c.path, cte.c.id, cte.c.parent_id).order_by(cte.c.level) return query ``` Category class: ``` class Category(Model): name = CharField() icon = CharField(null=True) parent = ForeignKeyField("self", null=True, backref="children") ``` And last but not least, error message: ``` Traceback (most recent call last): File "<string>", line 28, in <module> File "C:\Users\jp\.nuke\QUAM\Libs\peewee\peewee.py", line 4378, in next self.cursor_wrapper.iterate() File "C:\Users\jp\.nuke\QUAM\Libs\peewee\peewee.py", line 4297, in iterate result = self.process_row(row) File "C:\Users\jp\.nuke\QUAM\Libs\peewee\peewee.py", line 4363, in process_row return self.constructor(**row_dict) File "C:\Users\jp.nuke\QUAM\Libs\peewee\peewee.py", line 6736, in __call__ return self.model(**kwargs) File "C:\Users\jp\.nuke\QUAM\Libs\peewee\peewee.py", line 6260, in __init__ setattr(self, k, kwargs[k]) AttributeError: can't set attribute ``` Greetings, peewee is AWESOME :D
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2390/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2390/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2389
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2389/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2389/comments
https://api.github.com/repos/coleifer/peewee/issues/2389/events
https://github.com/coleifer/peewee/issues/2389
852,394,196
MDU6SXNzdWU4NTIzOTQxOTY=
2,389
Connection Error - peewee.InterfaceError: (0, '')
{ "login": "NeroNekro", "id": 36452325, "node_id": "MDQ6VXNlcjM2NDUyMzI1", "avatar_url": "https://avatars.githubusercontent.com/u/36452325?v=4", "gravatar_id": "", "url": "https://api.github.com/users/NeroNekro", "html_url": "https://github.com/NeroNekro", "followers_url": "https://api.github.com/users/NeroNekro/followers", "following_url": "https://api.github.com/users/NeroNekro/following{/other_user}", "gists_url": "https://api.github.com/users/NeroNekro/gists{/gist_id}", "starred_url": "https://api.github.com/users/NeroNekro/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/NeroNekro/subscriptions", "organizations_url": "https://api.github.com/users/NeroNekro/orgs", "repos_url": "https://api.github.com/users/NeroNekro/repos", "events_url": "https://api.github.com/users/NeroNekro/events{/privacy}", "received_events_url": "https://api.github.com/users/NeroNekro/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Sorry, I'm not familiar with fastapi but presumably it's something to do with sharing connections across threads or processes or some other asyncio-related issue." ]
"2021-04-07T13:10:46"
"2021-04-07T13:26:49"
"2021-04-07T13:26:49"
NONE
null
Hi, I using FastAPI with Peewee and PyMySQL and get the following Error: `[2021-04-07 09:56:38 +0000] [729] [ERROR] Exception in ASGI application Traceback (most recent call last): File "/usr/local/lib/python3.8/site-packages/uvicorn/protocols/http/httptools_impl.py", line 398, in run_asgi result = await app(self.scope, self.receive, self.send) File "/usr/local/lib/python3.8/site-packages/uvicorn/middleware/proxy_headers.py", line 45, in __call__ return await self.app(scope, receive, send) File "/usr/local/lib/python3.8/site-packages/fastapi/applications.py", line 199, in __call__ await super().__call__(scope, receive, send) File "/usr/local/lib/python3.8/site-packages/starlette/applications.py", line 111, in __call__ await self.middleware_stack(scope, receive, send) File "/usr/local/lib/python3.8/site-packages/starlette/middleware/errors.py", line 181, in __call__ raise exc from None File "/usr/local/lib/python3.8/site-packages/starlette/middleware/errors.py", line 159, in __call__ await self.app(scope, receive, _send) File "/usr/local/lib/python3.8/site-packages/starlette/middleware/cors.py", line 78, in __call__ await self.app(scope, receive, send) File "/usr/local/lib/python3.8/site-packages/starlette/exceptions.py", line 82, in __call__ raise exc from None File "/usr/local/lib/python3.8/site-packages/starlette/exceptions.py", line 71, in __call__ await self.app(scope, receive, sender) File "/usr/local/lib/python3.8/site-packages/starlette/routing.py", line 566, in __call__ await route.handle(scope, receive, send) File "/usr/local/lib/python3.8/site-packages/starlette/routing.py", line 227, in handle await self.app(scope, receive, send) File "/usr/local/lib/python3.8/site-packages/starlette/routing.py", line 41, in app response = await func(request) File "/usr/local/lib/python3.8/site-packages/fastapi/routing.py", line 201, in app raw_response = await run_endpoint_function( File "/usr/local/lib/python3.8/site-packages/fastapi/routing.py", line 148, in run_endpoint_function return await dependant.call(**values) File "/app/main.py", line 257, in get_cat cursor = DB.execute_sql('''SELECT * File "/usr/local/lib/python3.8/site-packages/peewee.py", line 3151, in execute_sql self.commit() File "/usr/local/lib/python3.8/site-packages/peewee.py", line 2917, in __exit__ reraise(new_type, new_type(exc_value, *exc_args), traceback) File "/usr/local/lib/python3.8/site-packages/peewee.py", line 190, in reraise raise value.with_traceback(tb) File "/usr/local/lib/python3.8/site-packages/peewee.py", line 3144, in execute_sql cursor.execute(sql, params or ()) File "/usr/local/lib/python3.8/site-packages/pymysql/cursors.py", line 148, in execute result = self._query(query) File "/usr/local/lib/python3.8/site-packages/pymysql/cursors.py", line 310, in _query conn.query(q) File "/usr/local/lib/python3.8/site-packages/pymysql/connections.py", line 547, in query self._execute_command(COMMAND.COM_QUERY, sql) File "/usr/local/lib/python3.8/site-packages/pymysql/connections.py", line 793, in _execute_command raise err.InterfaceError(0, "") peewee.InterfaceError: (0, '')` I have searched for this problem, but nothing helps. I inserted these in my Code, but it doesnt work: ` if DB.is_closed(): DB.connect()` Best Regards
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2389/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2389/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2388
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2388/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2388/comments
https://api.github.com/repos/coleifer/peewee/issues/2388/events
https://github.com/coleifer/peewee/issues/2388
851,191,239
MDU6SXNzdWU4NTExOTEyMzk=
2,388
Thread-safe use of CSqliteExtDatabase update hooks
{ "login": "rokel", "id": 6145874, "node_id": "MDQ6VXNlcjYxNDU4NzQ=", "avatar_url": "https://avatars.githubusercontent.com/u/6145874?v=4", "gravatar_id": "", "url": "https://api.github.com/users/rokel", "html_url": "https://github.com/rokel", "followers_url": "https://api.github.com/users/rokel/followers", "following_url": "https://api.github.com/users/rokel/following{/other_user}", "gists_url": "https://api.github.com/users/rokel/gists{/gist_id}", "starred_url": "https://api.github.com/users/rokel/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/rokel/subscriptions", "organizations_url": "https://api.github.com/users/rokel/orgs", "repos_url": "https://api.github.com/users/rokel/repos", "events_url": "https://api.github.com/users/rokel/events{/privacy}", "received_events_url": "https://api.github.com/users/rokel/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "So first of all: by default peewee stores connection state in a threadlocal. This means each thread has its own connection. Hooks are specific to the connection they are registered on -- peewee takes care of registering them, but just fyi that's how it works.\r\n\r\nSecond of all: sqlite cannot accept writes from multiple threads, and unless you're using WAL mode, readers cannot coexist with a writer.\r\n\r\nThird of all: because of the gil, only one python thread can be running at any given time.\r\n\r\nSo using multiple threads with Sqlite is sometimes a misguided effort unless you have a compelling reason.\r\n\r\nAll that being said, I was able to reproduce a segfault and have a fix ready you can try.", "Thanks for the quick response, and for the additional info. I would like to avoid using threads but it's the concurrency model I've inherited from the service lib I'm using (gRPC), and is largely I/O bound so doesn't suffer too much from the GIL I think. I could segregate it off and add another layer inbetween to serialise db access though, but worried about the boilerplate that might entail. Writes are pretty rare for my application at the moment so I'm hoping I can avoid using WAL; trying to avoid multiple files due to use as an application file format.\r\n\r\nI pulled 5a55993 and built with `pip install --no-cache-dir ---globaloption=build_ext .` but still get the crash with the test script above. Nevertheless I've tested the 'separate `CSqliteExtDatabase` instance & hooks per-thread' approach and that seems viable so far...\r\n\r\n", "Are you able to get a backtrace? I was able to reproduce a segfault using a slightly different approach and resolved the issue (which had to do with attempting to unregister the hook when the underlying sqlite3 pointer was NULL) - and this is the issue that I patched." ]
"2021-04-06T08:40:37"
"2021-04-06T18:41:35"
"2021-04-06T13:35:08"
NONE
null
#### Summary The SQLite hooks like `on_update`, `on_commit` are really useful, thank you for exposing them (and thank you for a fantastic lib!). But I'm not sure how to use the hooks in a multithreaded program. I have a threadpool of workers servicing a gRPC API that I want to give concurrent read access to a SQLite database. Other than the occasional "database is locked" error, sharing one `CSqliteExtDatabase` instance between threads seems to work well. However when I introduce the `on_commit` hook I start getting crashes, so I think I am doing something unsafe here. The only way I've found to circumvent these is to create a fresh `CSqliteExtDatabase` instance on each thread as needed. I'm not sure if there are any ramifications for doing that; I'm using the SQLite database as an application file format so it does become a bit complicated to change the `.db` for each one at runtime. Am I using these hooks in the intended manner? #### Failing Example ```python import logging import random import concurrent.futures import time from playhouse.sqlite_ext import CSqliteExtDatabase database = CSqliteExtDatabase( "test.db", autoconnect=False, thread_safe=True ) @database.on_commit def on_commit(): pass class Worker: def __init__(self, db: CSqliteExtDatabase): self.db = db def query(self, timeout): with self.db: logging.warning(f"starting task (duration={timeout})") time.sleep(timeout) logging.warning("finished task") with concurrent.futures.ThreadPoolExecutor() as executor: # Start a few 'queries' on different threads task_durations = random.sample([d * 0.2 for d in range(1, 10)], 9) for duration in task_durations: worker = Worker(database) executor.submit(worker.query, duration) ``` #### Result * Windows 10 * Python 3.7.5 * Peewee 3.13.3 ``` Windows fatal exception: access violation Current thread 0x00002308 (most recent call first): File "<snip>\venv\lib\site-packages\playhouse\sqlite_ext.py", line 1035 in _close File "<snip>\venv\lib\site-packages\peewee.py", line 3059 in close File "<snip>\venv\lib\site-packages\peewee.py", line 3015 in __exit__ File "<snip>/test/test_concurrency.py", line 29 in query File "C:\Python37\lib\concurrent\futures\thread.py", line 57 in run File "C:\Python37\lib\concurrent\futures\thread.py", line 80 in _worker File "C:\Python37\lib\threading.py", line 870 in run File "C:\Python37\lib\threading.py", line 926 in _bootstrap_inner File "C:\Python37\lib\threading.py", line 890 in _bootstrap ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2388/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2388/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2387
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2387/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2387/comments
https://api.github.com/repos/coleifer/peewee/issues/2387/events
https://github.com/coleifer/peewee/issues/2387
850,402,358
MDU6SXNzdWU4NTA0MDIzNTg=
2,387
Connections fail with: peewee.OperationalError: (1524, "Plugin 'unix_socket' is not loaded")
{ "login": "scjoiner", "id": 4303855, "node_id": "MDQ6VXNlcjQzMDM4NTU=", "avatar_url": "https://avatars.githubusercontent.com/u/4303855?v=4", "gravatar_id": "", "url": "https://api.github.com/users/scjoiner", "html_url": "https://github.com/scjoiner", "followers_url": "https://api.github.com/users/scjoiner/followers", "following_url": "https://api.github.com/users/scjoiner/following{/other_user}", "gists_url": "https://api.github.com/users/scjoiner/gists{/gist_id}", "starred_url": "https://api.github.com/users/scjoiner/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/scjoiner/subscriptions", "organizations_url": "https://api.github.com/users/scjoiner/orgs", "repos_url": "https://api.github.com/users/scjoiner/repos", "events_url": "https://api.github.com/users/scjoiner/events{/privacy}", "received_events_url": "https://api.github.com/users/scjoiner/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Sounds like an issue in your db driver. That error is being propagated up from whatever driver you're using. Presumably you upgraded something else in addition to just peewee. You can diff the last working version with 3.14.4 and see if anything jumps out at you, but it seems unlikely to me." ]
"2021-04-05T14:22:46"
"2021-04-05T21:29:53"
"2021-04-05T21:29:53"
NONE
null
In Peewee 3.14.4 connections are failing with the error message "peewee.OperationalError: (1524, "Plugin 'unix_socket' is not loaded")" on the db.connect() command. OS is Ubuntu 18.04 running Python 3.6 in a virtual environment for a Flask application with uwsgi. This application was previously working and this is a new issue.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2387/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2387/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2386
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2386/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2386/comments
https://api.github.com/repos/coleifer/peewee/issues/2386/events
https://github.com/coleifer/peewee/issues/2386
850,235,617
MDU6SXNzdWU4NTAyMzU2MTc=
2,386
model_to_dict exclude
{ "login": "bronte2k7", "id": 29693866, "node_id": "MDQ6VXNlcjI5NjkzODY2", "avatar_url": "https://avatars.githubusercontent.com/u/29693866?v=4", "gravatar_id": "", "url": "https://api.github.com/users/bronte2k7", "html_url": "https://github.com/bronte2k7", "followers_url": "https://api.github.com/users/bronte2k7/followers", "following_url": "https://api.github.com/users/bronte2k7/following{/other_user}", "gists_url": "https://api.github.com/users/bronte2k7/gists{/gist_id}", "starred_url": "https://api.github.com/users/bronte2k7/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/bronte2k7/subscriptions", "organizations_url": "https://api.github.com/users/bronte2k7/orgs", "repos_url": "https://api.github.com/users/bronte2k7/repos", "events_url": "https://api.github.com/users/bronte2k7/events{/privacy}", "received_events_url": "https://api.github.com/users/bronte2k7/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "http://docs.peewee-orm.com/en/latest/peewee/playhouse.html#model_to_dict\r\n\r\n>exclude – A list (or set) of field instances which should be excluded from the result dictionary.\r\n\r\nYou need to pass the field instance.", "I do not understand something. Please show me an example. I have already tried it in different ways))) ", "Going forward, please post questions to stackoverflow.\r\n\r\n>example\r\n\r\n```python\r\naccount = model_to_dict(account, exclude=[Account.password])\r\n```", "thank you!" ]
"2021-04-05T09:32:04"
"2022-09-24T13:26:51"
"2021-04-05T23:35:37"
NONE
null
Hi ```python class Account(Model): email = CharField(max_length=255, unique=True, index=True) password = PasswordField(index=True) account = Account.get_or_none(Accountl.id == 1) account = model_to_dict(account, exclude=['password']) ``` Password is not excluded
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2386/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2386/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2385
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2385/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2385/comments
https://api.github.com/repos/coleifer/peewee/issues/2385/events
https://github.com/coleifer/peewee/issues/2385
849,750,736
MDU6SXNzdWU4NDk3NTA3MzY=
2,385
contrib a DillField ?
{ "login": "aiqc", "id": 74990642, "node_id": "MDQ6VXNlcjc0OTkwNjQy", "avatar_url": "https://avatars.githubusercontent.com/u/74990642?v=4", "gravatar_id": "", "url": "https://api.github.com/users/aiqc", "html_url": "https://github.com/aiqc", "followers_url": "https://api.github.com/users/aiqc/followers", "following_url": "https://api.github.com/users/aiqc/following{/other_user}", "gists_url": "https://api.github.com/users/aiqc/gists{/gist_id}", "starred_url": "https://api.github.com/users/aiqc/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/aiqc/subscriptions", "organizations_url": "https://api.github.com/users/aiqc/orgs", "repos_url": "https://api.github.com/users/aiqc/repos", "events_url": "https://api.github.com/users/aiqc/events{/privacy}", "received_events_url": "https://api.github.com/users/aiqc/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "`playhouse.fields`\r\nhttps://github.com/coleifer/peewee/blob/a8938588c00ae7ef94f453b8873820419474b4ce/playhouse/fields.py\r\n\r\n`tests.extra_fields`\r\nhttps://github.com/coleifer/peewee/blob/a8938588c00ae7ef94f453b8873820419474b4ce/playhouse/fields.py\r\n", "You're welcome to package this up as your own extension module, but I try to stay within the stdlib where possible." ]
"2021-04-03T22:20:13"
"2021-04-04T01:13:23"
"2021-04-04T01:13:23"
NONE
null
I've been using the `PickleField` a lot, but ran into Pickle's limitations. These are overcome by `dill`, which was written by the `pathos` people. https://dill.readthedocs.io/en/latest/#major-features At first, I thought I would just save my dill-serialized objects as bytes in the `BlobField()`, but then then I realized, "bah, every time I want to read this I'll need to call a method that deserializes it; lame." This was fine for internal fields, but not for user-facing fields. ```python import io import dill as dill def dill_serialize(objekt:object): blob = io.BytesIO() dill.dump(objekt, blob) #regular pickle is `dumps` blob = blob.getvalue() return blob def dill_deserialize(blob:bytes): objekt = io.BytesIO(blob) objekt = dill.load(objekt) #regular pickle is `loads` return objekt # in action on a notorious nested function def funk(): def funkier(): return 'z' return funkier() blob = dill_serialize(funk) unblob = dill_deserialize(blob) unblob() # 'z' ``` Are you open to the idea of a DillField?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2385/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2385/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2384
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2384/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2384/comments
https://api.github.com/repos/coleifer/peewee/issues/2384/events
https://github.com/coleifer/peewee/pull/2384
849,599,993
MDExOlB1bGxSZXF1ZXN0NjA4MzQ1MjAy
2,384
Fix reference to `first` method
{ "login": "Helveg", "id": 28923979, "node_id": "MDQ6VXNlcjI4OTIzOTc5", "avatar_url": "https://avatars.githubusercontent.com/u/28923979?v=4", "gravatar_id": "", "url": "https://api.github.com/users/Helveg", "html_url": "https://github.com/Helveg", "followers_url": "https://api.github.com/users/Helveg/followers", "following_url": "https://api.github.com/users/Helveg/following{/other_user}", "gists_url": "https://api.github.com/users/Helveg/gists{/gist_id}", "starred_url": "https://api.github.com/users/Helveg/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/Helveg/subscriptions", "organizations_url": "https://api.github.com/users/Helveg/orgs", "repos_url": "https://api.github.com/users/Helveg/repos", "events_url": "https://api.github.com/users/Helveg/events{/privacy}", "received_events_url": "https://api.github.com/users/Helveg/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Eh I'll need to look into this some more - not urgent." ]
"2021-04-03T07:22:47"
"2021-04-03T17:41:35"
"2021-04-03T17:41:35"
NONE
null
Not sure that this is the right class but it closes #2383
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2384/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2384/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/2384", "html_url": "https://github.com/coleifer/peewee/pull/2384", "diff_url": "https://github.com/coleifer/peewee/pull/2384.diff", "patch_url": "https://github.com/coleifer/peewee/pull/2384.patch", "merged_at": null }
https://api.github.com/repos/coleifer/peewee/issues/2383
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2383/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2383/comments
https://api.github.com/repos/coleifer/peewee/issues/2383/events
https://github.com/coleifer/peewee/issues/2383
849,599,597
MDU6SXNzdWU4NDk1OTk1OTc=
2,383
`Model.first()` doc reference broken
{ "login": "Helveg", "id": 28923979, "node_id": "MDQ6VXNlcjI4OTIzOTc5", "avatar_url": "https://avatars.githubusercontent.com/u/28923979?v=4", "gravatar_id": "", "url": "https://api.github.com/users/Helveg", "html_url": "https://github.com/Helveg", "followers_url": "https://api.github.com/users/Helveg/followers", "following_url": "https://api.github.com/users/Helveg/following{/other_user}", "gists_url": "https://api.github.com/users/Helveg/gists{/gist_id}", "starred_url": "https://api.github.com/users/Helveg/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/Helveg/subscriptions", "organizations_url": "https://api.github.com/users/Helveg/orgs", "repos_url": "https://api.github.com/users/Helveg/repos", "events_url": "https://api.github.com/users/Helveg/events{/privacy}", "received_events_url": "https://api.github.com/users/Helveg/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[]
"2021-04-03T07:20:11"
"2021-04-03T17:41:28"
"2021-04-03T17:41:28"
NONE
null
In the docs under [Selecting a single record](https://github.com/coleifer/peewee/blob/master/docs/peewee/querying.rst#selecting-a-single-record) there is a broken link to `Model.first`. Using it yields an attribute error that `first` doesn't exist on my model. I fixed this by using `Model.select().first()` and most likely the docs also need to reference the `first` method of the `ModelSelect` class instead?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2383/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2383/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2382
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2382/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2382/comments
https://api.github.com/repos/coleifer/peewee/issues/2382/events
https://github.com/coleifer/peewee/pull/2382
848,881,500
MDExOlB1bGxSZXF1ZXN0NjA3NzQ4NTM3
2,382
Add ModelSelect.get_or_none()
{ "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
[ "Thanks for the patch, looks good and merged." ]
"2021-04-02T00:50:29"
"2021-04-02T16:27:04"
"2021-04-02T13:51:37"
CONTRIBUTOR
null
Mr. Leifer, First, thanks for creating and maintaining such a great library. We've used it at Propel for many years now. This PR adds `get_or_none()` to `ModelSelect` in an effort to make the querying API a little more consistent. `Foo.get_or_none()` is very convenient, and we'd like the same sort of convenience for things like `Foo.select().join(Bar).where(Foo.baz == baz).get_or_none()`.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2382/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2382/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/2382", "html_url": "https://github.com/coleifer/peewee/pull/2382", "diff_url": "https://github.com/coleifer/peewee/pull/2382.diff", "patch_url": "https://github.com/coleifer/peewee/pull/2382.patch", "merged_at": "2021-04-02T13:51:37" }
https://api.github.com/repos/coleifer/peewee/issues/2381
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2381/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2381/comments
https://api.github.com/repos/coleifer/peewee/issues/2381/events
https://github.com/coleifer/peewee/issues/2381
848,287,296
MDU6SXNzdWU4NDgyODcyOTY=
2,381
execute count
{ "login": "leshphonc", "id": 24892968, "node_id": "MDQ6VXNlcjI0ODkyOTY4", "avatar_url": "https://avatars.githubusercontent.com/u/24892968?v=4", "gravatar_id": "", "url": "https://api.github.com/users/leshphonc", "html_url": "https://github.com/leshphonc", "followers_url": "https://api.github.com/users/leshphonc/followers", "following_url": "https://api.github.com/users/leshphonc/following{/other_user}", "gists_url": "https://api.github.com/users/leshphonc/gists{/gist_id}", "starred_url": "https://api.github.com/users/leshphonc/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/leshphonc/subscriptions", "organizations_url": "https://api.github.com/users/leshphonc/orgs", "repos_url": "https://api.github.com/users/leshphonc/repos", "events_url": "https://api.github.com/users/leshphonc/events{/privacy}", "received_events_url": "https://api.github.com/users/leshphonc/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "是我用法的问题吗,请帮帮我", "我本地运行是没问题的,放到服务器上就获取不到count了", "Do not call `.execute()` before count().\r\n\r\nExecute gives you a cursor iterator, not a composable query object.", "```python\r\n\r\n# This gives us a query object.\r\nquery = User.select().where(User.status == 0)\r\n\r\n# Executes a SELECT COUNT(*)\r\ncount = query.count()\r\n\r\n# Not necessary to explicitly call .execute() - as iterating over\r\n# a select query implicitly executes it.\r\nfor user in query:\r\n ...\r\n```" ]
"2021-04-01T09:16:30"
"2021-04-01T13:49:12"
"2021-04-01T12:02:18"
NONE
null
![image](https://user-images.githubusercontent.com/24892968/113272208-f76e7000-930d-11eb-94ec-6dc94a9f4972.png)
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2381/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2381/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2380
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2380/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2380/comments
https://api.github.com/repos/coleifer/peewee/issues/2380/events
https://github.com/coleifer/peewee/pull/2380
841,930,909
MDExOlB1bGxSZXF1ZXN0NjAxNTkzMDkz
2,380
use https links
{ "login": "imba-tjd", "id": 24759802, "node_id": "MDQ6VXNlcjI0NzU5ODAy", "avatar_url": "https://avatars.githubusercontent.com/u/24759802?v=4", "gravatar_id": "", "url": "https://api.github.com/users/imba-tjd", "html_url": "https://github.com/imba-tjd", "followers_url": "https://api.github.com/users/imba-tjd/followers", "following_url": "https://api.github.com/users/imba-tjd/following{/other_user}", "gists_url": "https://api.github.com/users/imba-tjd/gists{/gist_id}", "starred_url": "https://api.github.com/users/imba-tjd/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/imba-tjd/subscriptions", "organizations_url": "https://api.github.com/users/imba-tjd/orgs", "repos_url": "https://api.github.com/users/imba-tjd/repos", "events_url": "https://api.github.com/users/imba-tjd/events{/privacy}", "received_events_url": "https://api.github.com/users/imba-tjd/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[]
"2021-03-26T12:51:11"
"2021-03-26T13:05:34"
"2021-03-26T13:05:34"
NONE
null
`find and replace` these `http://` domains: * docs.peewee-orm.com * charlesleifer.com * media.charlesleifer.com * sqlite.org
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2380/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2380/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/2380", "html_url": "https://github.com/coleifer/peewee/pull/2380", "diff_url": "https://github.com/coleifer/peewee/pull/2380.diff", "patch_url": "https://github.com/coleifer/peewee/pull/2380.patch", "merged_at": null }
https://api.github.com/repos/coleifer/peewee/issues/2379
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2379/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2379/comments
https://api.github.com/repos/coleifer/peewee/issues/2379/events
https://github.com/coleifer/peewee/issues/2379
839,170,661
MDU6SXNzdWU4MzkxNzA2NjE=
2,379
Cannot nest database as context manager in transactions
{ "login": "arjd", "id": 20357504, "node_id": "MDQ6VXNlcjIwMzU3NTA0", "avatar_url": "https://avatars.githubusercontent.com/u/20357504?v=4", "gravatar_id": "", "url": "https://api.github.com/users/arjd", "html_url": "https://github.com/arjd", "followers_url": "https://api.github.com/users/arjd/followers", "following_url": "https://api.github.com/users/arjd/following{/other_user}", "gists_url": "https://api.github.com/users/arjd/gists{/gist_id}", "starred_url": "https://api.github.com/users/arjd/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/arjd/subscriptions", "organizations_url": "https://api.github.com/users/arjd/orgs", "repos_url": "https://api.github.com/users/arjd/repos", "events_url": "https://api.github.com/users/arjd/events{/privacy}", "received_events_url": "https://api.github.com/users/arjd/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "What is the intent of such a construction? Using the database as context manager implies you wish to close the database when it exits. Peewee is correctly telling you it cannot close the database because you have explicitly requested a transaction.\r\n\r\nNot a bug, in my opinion." ]
"2021-03-23T22:22:00"
"2021-03-24T13:20:09"
"2021-03-24T13:20:09"
NONE
null
It seems to me that this should be possible: ``` with db.atomic(): with db: inst = Model.create() ``` But this fails with `OperationalError: Attempting to close database while transaction is open.`. This is pretty similar to https://github.com/coleifer/peewee/issues/1918
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2379/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2379/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2378
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2378/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2378/comments
https://api.github.com/repos/coleifer/peewee/issues/2378/events
https://github.com/coleifer/peewee/issues/2378
838,195,798
MDU6SXNzdWU4MzgxOTU3OTg=
2,378
Constraints not updated
{ "login": "0scarius", "id": 7230152, "node_id": "MDQ6VXNlcjcyMzAxNTI=", "avatar_url": "https://avatars.githubusercontent.com/u/7230152?v=4", "gravatar_id": "", "url": "https://api.github.com/users/0scarius", "html_url": "https://github.com/0scarius", "followers_url": "https://api.github.com/users/0scarius/followers", "following_url": "https://api.github.com/users/0scarius/following{/other_user}", "gists_url": "https://api.github.com/users/0scarius/gists{/gist_id}", "starred_url": "https://api.github.com/users/0scarius/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/0scarius/subscriptions", "organizations_url": "https://api.github.com/users/0scarius/orgs", "repos_url": "https://api.github.com/users/0scarius/repos", "events_url": "https://api.github.com/users/0scarius/events{/privacy}", "received_events_url": "https://api.github.com/users/0scarius/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Erroneous... wrong place" ]
"2021-03-22T23:52:17"
"2021-03-23T00:14:25"
"2021-03-23T00:10:42"
NONE
null
-
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2378/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2378/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2377
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2377/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2377/comments
https://api.github.com/repos/coleifer/peewee/issues/2377/events
https://github.com/coleifer/peewee/issues/2377
836,825,233
MDU6SXNzdWU4MzY4MjUyMzM=
2,377
Not .select()'ed foreign key field raises DoesNotExist with lazy_load=False
{ "login": "AndBondStyle", "id": 18560701, "node_id": "MDQ6VXNlcjE4NTYwNzAx", "avatar_url": "https://avatars.githubusercontent.com/u/18560701?v=4", "gravatar_id": "", "url": "https://api.github.com/users/AndBondStyle", "html_url": "https://github.com/AndBondStyle", "followers_url": "https://api.github.com/users/AndBondStyle/followers", "following_url": "https://api.github.com/users/AndBondStyle/following{/other_user}", "gists_url": "https://api.github.com/users/AndBondStyle/gists{/gist_id}", "starred_url": "https://api.github.com/users/AndBondStyle/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/AndBondStyle/subscriptions", "organizations_url": "https://api.github.com/users/AndBondStyle/orgs", "repos_url": "https://api.github.com/users/AndBondStyle/repos", "events_url": "https://api.github.com/users/AndBondStyle/events{/privacy}", "received_events_url": "https://api.github.com/users/AndBondStyle/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Looks like a regression related to #2328", "Actually scratch that - this is not a regression. There doesn't seem to be a reliable way of differentiating between a model instance you have explicitly chosen *not* to select the foreign-key value and a model instance that is missing a non-null foreign-key. Lazy-load really deals with converting a foreign-key value (e.g. integer id) into a full object.", "That being said, I agree that the error is misplaced and this should just return `None` if lazy-load has been disabled. I've made the patch as you suggested." ]
"2021-03-20T14:41:41"
"2021-03-20T18:29:33"
"2021-03-20T18:29:31"
NONE
null
I have a model with a foreign key field like this: ```python3 related_id = ForeignKeyField(OtherModel, lazy_load=False) ``` If you don't include this field in a select query and then try to access it, you get `DoesNotExist` error: ```python3 x = Model.select(Model.id).get() # related_id field not included print(x.related_id) # raises DoesNotExist ``` ... which is not very expected, considering `lazy_load=False`. The root of exception is in the `ForeignKeyAccessor.get_rel_instance` method, and I believe it should be changed like this: ```diff def get_rel_instance(self, instance): value = instance.__data__.get(self.name) if value is not None or self.name in instance.__rel__: if self.name not in instance.__rel__ and self.field.lazy_load: obj = self.rel_model.get(self.field.rel_field == value) instance.__rel__[self.name] = obj return instance.__rel__.get(self.name, value) - elif not self.field.null: + elif not self.field.null and self.field.lazy_load: raise self.rel_model.DoesNotExist return value ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2377/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2377/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2376
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2376/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2376/comments
https://api.github.com/repos/coleifer/peewee/issues/2376/events
https://github.com/coleifer/peewee/issues/2376
835,005,607
MDU6SXNzdWU4MzUwMDU2MDc=
2,376
Model converter behavior change
{ "login": "vaniakov", "id": 8692788, "node_id": "MDQ6VXNlcjg2OTI3ODg=", "avatar_url": "https://avatars.githubusercontent.com/u/8692788?v=4", "gravatar_id": "", "url": "https://api.github.com/users/vaniakov", "html_url": "https://github.com/vaniakov", "followers_url": "https://api.github.com/users/vaniakov/followers", "following_url": "https://api.github.com/users/vaniakov/following{/other_user}", "gists_url": "https://api.github.com/users/vaniakov/gists{/gist_id}", "starred_url": "https://api.github.com/users/vaniakov/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/vaniakov/subscriptions", "organizations_url": "https://api.github.com/users/vaniakov/orgs", "repos_url": "https://api.github.com/users/vaniakov/repos", "events_url": "https://api.github.com/users/vaniakov/events{/privacy}", "received_events_url": "https://api.github.com/users/vaniakov/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Thanks for the succinct report and isolating the problematic changeset. No, this was a regression that I didn't foresee. I've patched this and will issue a new release.", "This is fixed and I've tagged a new version 3.14.4, which contains the fix and additional tests.", "@coleifer Thank you for such quick response and fix!" ]
"2021-03-18T16:16:25"
"2021-03-19T15:58:25"
"2021-03-19T15:55:30"
NONE
null
Hi! While updating peewee from 3.13.3 to 3.14.3 I noticed model converter behavior change. If model has __str__ method defined, it is used to represent this model's value in the expression instead of primary key: ```python import uuid from peewee import * db = SqliteDatabase(":memory:") class BaseModel(Model): class Meta: database = db class User(BaseModel): id = CharField(max_length=255, primary_key=True) name = CharField(max_length=255) def __str__(self): return f"{self.name}" if __name__ == "__main__": User.create_table() users = [] for i in range(10): users.append(User.create(id=uuid.uuid4(), name=f"User_{i}")) query = User.filter(User.id << users) print(query.sql()) print(list(query)) ``` Output: ``` ('SELECT "t1"."id", "t1"."name" FROM "user" AS "t1" WHERE ("t1"."id" IN (?, ?, ?, ?, ?, ?, ?, ?, ?, ?))', ['User_0', 'User_1', 'User_2', 'User_3', 'User_4', 'User_5', 'User_6', 'User_7', 'User_8', 'User_9']) [] ``` The change was introduced in this commit: https://github.com/coleifer/peewee/commit/ebe3ad5023d60ebf2fb91528d422a01596220cde I'm wondering is this behavior is intentional. Thanks.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2376/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/2376/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2375
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2375/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2375/comments
https://api.github.com/repos/coleifer/peewee/issues/2375/events
https://github.com/coleifer/peewee/issues/2375
834,173,752
MDU6SXNzdWU4MzQxNzM3NTI=
2,375
[Q] Is it possible to mark a model object as "unsave-able"?
{ "login": "NightMachinery", "id": 36224762, "node_id": "MDQ6VXNlcjM2MjI0NzYy", "avatar_url": "https://avatars.githubusercontent.com/u/36224762?v=4", "gravatar_id": "", "url": "https://api.github.com/users/NightMachinery", "html_url": "https://github.com/NightMachinery", "followers_url": "https://api.github.com/users/NightMachinery/followers", "following_url": "https://api.github.com/users/NightMachinery/following{/other_user}", "gists_url": "https://api.github.com/users/NightMachinery/gists{/gist_id}", "starred_url": "https://api.github.com/users/NightMachinery/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/NightMachinery/subscriptions", "organizations_url": "https://api.github.com/users/NightMachinery/orgs", "repos_url": "https://api.github.com/users/NightMachinery/repos", "events_url": "https://api.github.com/users/NightMachinery/events{/privacy}", "received_events_url": "https://api.github.com/users/NightMachinery/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "No, this is not something that is supported in Peewee.", "@coleifer I just thought about simply setting `model.save = None`. I think this will be enough to prevent me from shooting myself in the foot later ...", "You would also want to lock-down the update, delete, delete_instance, etc, etc, presumably. If you're using sqlite it's possible to set the connection read-only and may be ways to do this with other databases as well. That's what I would look into. Or even adding a read-only user to your db and connecting with that user." ]
"2021-03-17T20:59:30"
"2021-03-18T00:14:21"
"2021-03-17T21:26:39"
NONE
null
I have some data analysis code that reads some objects from DB, and mutates them for easier analysis; I want to make sure that these mutated objects are never accidentally saved to the database. Is there a way to enforce this?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2375/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2375/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2374
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2374/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2374/comments
https://api.github.com/repos/coleifer/peewee/issues/2374/events
https://github.com/coleifer/peewee/issues/2374
833,790,147
MDU6SXNzdWU4MzM3OTAxNDc=
2,374
[Documentation] Lost link "Advanced Connection Management"
{ "login": "aferrari94", "id": 70535738, "node_id": "MDQ6VXNlcjcwNTM1NzM4", "avatar_url": "https://avatars.githubusercontent.com/u/70535738?v=4", "gravatar_id": "", "url": "https://api.github.com/users/aferrari94", "html_url": "https://github.com/aferrari94", "followers_url": "https://api.github.com/users/aferrari94/followers", "following_url": "https://api.github.com/users/aferrari94/following{/other_user}", "gists_url": "https://api.github.com/users/aferrari94/gists{/gist_id}", "starred_url": "https://api.github.com/users/aferrari94/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/aferrari94/subscriptions", "organizations_url": "https://api.github.com/users/aferrari94/orgs", "repos_url": "https://api.github.com/users/aferrari94/repos", "events_url": "https://api.github.com/users/aferrari94/events{/privacy}", "received_events_url": "https://api.github.com/users/aferrari94/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[]
"2021-03-17T13:43:18"
"2021-03-17T13:59:54"
"2021-03-17T13:59:54"
NONE
null
Hi, I was reading the documentation about the `connection pool` and I think I have found a missing reference caused by a reorganization of documentation with the new versions. ------------------------- With the doc of the current version (v3.6.0), there is an error about an old link that is pointing to something that is not anymore in the structure documentation. I'm speaking of the actual section of `Connection Pool` into the chapter `Playhous, extensions to Peewee`: at the end of the section missing a link: <img width="1901" alt="connPoll-latest" src="https://user-images.githubusercontent.com/70535738/111475819-c434ba00-872d-11eb-9908-250952a9de6a.png"> In the `doc of the version 2.10.2` it was pointing to this section: <img width="1917" alt="old-AdvConnMng" src="https://user-images.githubusercontent.com/70535738/111475973-efb7a480-872d-11eb-8e39-2410a0f433c1.png"> Actually, the above section doesn't exist anymore because, I think, it was move and update into this new section (actually present in the latest documentation): <img width="1919" alt="new-AdvConnMng" src="https://user-images.githubusercontent.com/70535738/111476275-4c1ac400-872e-11eb-86db-b55dcbb1a6a4.png"> ------------------------- I hope this could be useful. Regards, Ale
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2374/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2374/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2373
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2373/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2373/comments
https://api.github.com/repos/coleifer/peewee/issues/2373/events
https://github.com/coleifer/peewee/issues/2373
831,967,456
MDU6SXNzdWU4MzE5Njc0NTY=
2,373
Question about data joining to the same model
{ "login": "hrekov", "id": 41489462, "node_id": "MDQ6VXNlcjQxNDg5NDYy", "avatar_url": "https://avatars.githubusercontent.com/u/41489462?v=4", "gravatar_id": "", "url": "https://api.github.com/users/hrekov", "html_url": "https://github.com/hrekov", "followers_url": "https://api.github.com/users/hrekov/followers", "following_url": "https://api.github.com/users/hrekov/following{/other_user}", "gists_url": "https://api.github.com/users/hrekov/gists{/gist_id}", "starred_url": "https://api.github.com/users/hrekov/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/hrekov/subscriptions", "organizations_url": "https://api.github.com/users/hrekov/orgs", "repos_url": "https://api.github.com/users/hrekov/repos", "events_url": "https://api.github.com/users/hrekov/events{/privacy}", "received_events_url": "https://api.github.com/users/hrekov/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "The problem is a bad manifestation of a bug that occurs when you have a field named \"model\". I probably need to make Peewee raise an error if this occurs, but this fixes things:\r\n\r\n```python\r\n\r\nclass Car(Model):\r\n model_ = CharField(column_name='model', max_length=50, unique=True)\r\n ...\r\n```", "Thanks. That's worked" ]
"2021-03-15T16:12:25"
"2021-03-15T17:00:57"
"2021-03-15T16:50:52"
NONE
null
I have the following code: ``` from datetime import datetime, date from peewee import * db = SqliteDatabase(':memory:') class Car(Model): model = CharField(max_length=50, unique=True) manufactured = DateField() class Meta: database = db def __str__(self): return f'Car: {self.model}' class Person(Model): name = CharField(max_length=100) main_car = ForeignKeyField(Car) helper_car = ForeignKeyField(Car, on_delete='SET NULL') class Meta: database = db def __str__(self): return f'Person: {self.name}' db.create_tables([Car, Person]) Person.insert( name="test", main_car=Car.create(model='Mitsubishi', manufactured=datetime.today()), helper_car=Car.create(model='BMW', manufactured=date(2001, 12, 12)) ).execute() MainCar = Car.alias() HelperCar = Car.alias() print(tuple( Person. select(Person, MainCar, HelperCar) .join(MainCar, on=Person.main_car) .switch(Person) .join(HelperCar, on=Person.helper_car) ) ) ``` but when i'm trying to execute this i'm getting an empty tuple in results. So i tried to execute generated SQL query from that and everything is OK and data returned ``` sqlite> SELECT "t1"."id", "t1"."name", "t1"."main_car_id", "t1"."helper_car_id", "t2"."id", "car" AS "t3", "t2"."manufactured", "t4"."id", "car" AS "t3", "t4"."manufactured" FROM "person" AS "t1" INNER JOIN "car" AS "t2" ON ("t1"."main_car_id" = "t2"."id") INNER JOIN "car" AS "t4" ON ("t1"."helper_car_id" = "t4"."id"); 1|test|1|2|1|car|2021-03-15|2|car|2001-12-12 sqlite> ``` What am i doing wrong?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2373/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2373/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2372
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2372/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2372/comments
https://api.github.com/repos/coleifer/peewee/issues/2372/events
https://github.com/coleifer/peewee/issues/2372
828,103,390
MDU6SXNzdWU4MjgxMDMzOTA=
2,372
Thread safe DB swapping at runtime
{ "login": "induane", "id": 2320029, "node_id": "MDQ6VXNlcjIzMjAwMjk=", "avatar_url": "https://avatars.githubusercontent.com/u/2320029?v=4", "gravatar_id": "", "url": "https://api.github.com/users/induane", "html_url": "https://github.com/induane", "followers_url": "https://api.github.com/users/induane/followers", "following_url": "https://api.github.com/users/induane/following{/other_user}", "gists_url": "https://api.github.com/users/induane/gists{/gist_id}", "starred_url": "https://api.github.com/users/induane/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/induane/subscriptions", "organizations_url": "https://api.github.com/users/induane/orgs", "repos_url": "https://api.github.com/users/induane/repos", "events_url": "https://api.github.com/users/induane/events{/privacy}", "received_events_url": "https://api.github.com/users/induane/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "There are two ways you might look at doing this:\r\n\r\n1. re-bind the `SqliteDatabase` instance to a different database file\r\n2. re-bind the models to a different `SqliteDatabase` instance\r\n\r\nI'm not aware of any patterns for doing this an arbitrary number of times at run-time, so you'll have to piece it together for yourself a bit.\r\n\r\nProbably the easiest will be #1 since there are fewer moving parts. If you're connecting from multiple threads, because Peewee stores connection state in a thread-local, you'll have to ensure all threads close their connections when you switch database. It seems unlikely you would have connections open across threads, because of sqlite's write locking, but something to watch out for.\r\n\r\nThe only thing that would make me not consider option 1 is if you need to be switching back and forth between databases. In that case you might want to keep the db instances around and rebind the models between them.\r\n\r\nYou can re-initialize the database instance like this (option 1):\r\n\r\n```python\r\n\r\ndb = SqliteDatabase(None) # database is not initialized.\r\n\r\n# db is \"initialized\" - when you call connect() it will use\r\n# /tmp/db1.db\r\ndb.init('/tmp/db1.db')\r\n...\r\n# re-initialize db. if the calling thread has an open connection,\r\n# it is closed. subsequent connections will use /tmp/db2.db.\r\ndb.init('/tmp/db2.db')\r\n```\r\n\r\nRebinding models to a different database instance, as well as general db configuration stuff, is covered in the following links:\r\n\r\n* http://docs.peewee-orm.com/en/latest/peewee/database.html#setting-the-database-at-run-time\r\n* http://docs.peewee-orm.com/en/latest/peewee/database.html#run-time-database-configuration\r\n* http://docs.peewee-orm.com/en/latest/peewee/database.html#testing-peewee-applications - covers re-binding models for testing purposes\r\n\r\nI'm not likely to make any changes in the database apis or connection handling implementation, for what it's worth. ", "Dang you're quick on the response!\r\n\r\nIt has proved fairly tricky to have multiple active document instances and switching the models DB attribute.\r\n\r\nMy first approach was a decorator I applied to all methods in the document class that called db.init(self.file_path) but that was pretty cumbersome and I was able to break it with subprocesses where I was doing large numbers of updates to different documents in parallel (which seemed like a good approach as it was mostly io bound).\r\n\r\nMaybe the right approach is a custom proxy object of some kind that pulls connections from storage on thread local or something. I'll tinker around further." ]
"2021-03-10T17:42:11"
"2021-03-10T18:58:11"
"2021-03-10T18:03:57"
NONE
null
The use case I have is in using sqlite as an application file format. I need to be able to switch databases at runtime, preferably in a thread safe manner. I wouldn't mind using a context manager but I've had some issues with the proxyobject. Namely that once I initialize it, it's done globally. What I'd like to be able to do is something like: with BackendPath("/foo/bar.udf"): # do blar Or alternatively be able create multiple instances of the document abstraction: d = Document("/foo/bar.udf") d2 = Document("/nan/baz.udf") and have operations on each run through the model layer I haven't found a good way to do that yet. Can you suggest one? Or alternatively are you open to me digging around in peewee a bit and taking a stab at a way to do this? - Brant
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2372/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2372/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2371
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2371/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2371/comments
https://api.github.com/repos/coleifer/peewee/issues/2371/events
https://github.com/coleifer/peewee/issues/2371
827,275,167
MDU6SXNzdWU4MjcyNzUxNjc=
2,371
[bug]or where query got a bug not expect sql where
{ "login": "mouday", "id": 24365682, "node_id": "MDQ6VXNlcjI0MzY1Njgy", "avatar_url": "https://avatars.githubusercontent.com/u/24365682?v=4", "gravatar_id": "", "url": "https://api.github.com/users/mouday", "html_url": "https://github.com/mouday", "followers_url": "https://api.github.com/users/mouday/followers", "following_url": "https://api.github.com/users/mouday/following{/other_user}", "gists_url": "https://api.github.com/users/mouday/gists{/gist_id}", "starred_url": "https://api.github.com/users/mouday/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/mouday/subscriptions", "organizations_url": "https://api.github.com/users/mouday/orgs", "repos_url": "https://api.github.com/users/mouday/repos", "events_url": "https://api.github.com/users/mouday/events{/privacy}", "received_events_url": "https://api.github.com/users/mouday/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "it's my logic not clean! not a bug. \r\n\r\nthis code is ok.\r\n\r\n```python\r\nrow = (LibProductDataModel\r\n .select()\r\n .where((LibProductDataModel.product == product_or_company)\r\n | (LibProductDataModel.company == product_or_company))\r\n .first())\r\n\r\n```\r\n" ]
"2021-03-10T07:31:35"
"2021-03-10T09:08:32"
"2021-03-10T09:08:32"
NONE
null
query: ```python LibProductDataModel .select() .where(LibProductDataModel.product == product_or_company | LibProductDataModel.company == product_or_company) .first()) ``` got: ```sql ('SELECT `t1`.`id`, `t1`.`product`, `t1`.`company`, `t1`.`ticket`, `t1`.`update_time` FROM `lib_product_data` AS `t1` WHERE ((%s OR `t1`.`company`) = %s) LIMIT %s', ['腾讯', '腾讯', 1]) ``` expect: ```sql ('SELECT `t1`.`id`, `t1`.`product`, `t1`.`company`, `t1`.`ticket`, `t1`.`update_time` FROM `lib_product_data` AS `t1` WHERE `t1`.`product` = %s OR `t1`.`company` = %s LIMIT %s', ['腾讯', '腾讯', 1]) ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2371/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2371/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2370
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2370/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2370/comments
https://api.github.com/repos/coleifer/peewee/issues/2370/events
https://github.com/coleifer/peewee/issues/2370
826,976,216
MDU6SXNzdWU4MjY5NzYyMTY=
2,370
can i get how long one sql execute time
{ "login": "mouday", "id": 24365682, "node_id": "MDQ6VXNlcjI0MzY1Njgy", "avatar_url": "https://avatars.githubusercontent.com/u/24365682?v=4", "gravatar_id": "", "url": "https://api.github.com/users/mouday", "html_url": "https://github.com/mouday", "followers_url": "https://api.github.com/users/mouday/followers", "following_url": "https://api.github.com/users/mouday/following{/other_user}", "gists_url": "https://api.github.com/users/mouday/gists{/gist_id}", "starred_url": "https://api.github.com/users/mouday/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/mouday/subscriptions", "organizations_url": "https://api.github.com/users/mouday/orgs", "repos_url": "https://api.github.com/users/mouday/repos", "events_url": "https://api.github.com/users/mouday/events{/privacy}", "received_events_url": "https://api.github.com/users/mouday/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Peewee can log all queries. This is documented:\r\n\r\nhttp://docs.peewee-orm.com/en/latest/peewee/database.html#logging-queries\r\n\r\nIf you want to know the sql only for a particular query you can use the `.sql()` method of the query object.\r\n\r\nhttp://docs.peewee-orm.com/en/latest/peewee/api.html#BaseQuery.sql", "> Peewee can log all queries. This is documented:\r\n> \r\n> http://docs.peewee-orm.com/en/latest/peewee/database.html#logging-queries\r\n> \r\n> If you want to know the sql only for a particular query you can use the `.sql()` method of the query object.\r\n> \r\n> http://docs.peewee-orm.com/en/latest/peewee/api.html#BaseQuery.sql\r\n\r\nI known , but i want to see execute time and execute sql\r\n\r\nlike\r\n```\r\ntime: 347.00 ms\r\n```", "You can try monkey-patching `Database.execute_sql()` or subclass your database implementation and override the `execute_sql()` method to add timing information.", "> You can try monkey-patching `Database.execute_sql()` or subclass your database implementation and override the `execute_sql()` method to add timing information.\r\n\r\nthank you, i impl code as :\r\n```python\r\n# -*- coding: utf-8 -*-\r\n\r\nimport math\r\nimport time\r\nfrom functools import wraps\r\n\r\nfrom peewee import MySQLDatabase\r\n\r\nimport logging\r\n\r\n\r\nlogger = logging.getLogger('peewee')\r\n\r\ndef timer(func):\r\n @wraps(func)\r\n def wrapper(*args, **kwargs):\r\n start_time = time.time() * 1000\r\n ret = func(*args, **kwargs)\r\n end_time = time.time() * 1000\r\n logger.debug(\"time: %.2f ms\" % math.ceil(end_time - start_time))\r\n return ret\r\n\r\n return wrapper\r\n\r\n\r\nclass CustomMySQLDatabase(MySQLDatabase):\r\n @timer\r\n def execute_sql(self, sql, params=None, commit=SENTINEL):\r\n return super().execute_sql(sql, params, commit)\r\n\r\n\r\n```", "Just a suggestion: you might try using something like this for the start/end timings:\r\n\r\nhttps://docs.python.org/3.9/library/time.html#time.perf_counter", "> Just a suggestion: you might try using something like this for the start/end timings:\r\n> \r\n> https://docs.python.org/3.9/library/time.html#time.perf_counter\r\n\r\nthank you!" ]
"2021-03-10T02:35:56"
"2021-03-10T03:33:48"
"2021-03-10T02:43:26"
NONE
null
I want to known sql execute time, but logging not show. just like : ``` 10.12 ms SELECT * FROM `person` WHERE `name` = 'Tom' LIMIT 1 ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2370/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2370/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2369
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2369/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2369/comments
https://api.github.com/repos/coleifer/peewee/issues/2369/events
https://github.com/coleifer/peewee/pull/2369
823,023,647
MDExOlB1bGxSZXF1ZXN0NTg1NTQ5OTQz
2,369
Fix _generate_insert for nullable Fields
{ "login": "rafal-jaworski", "id": 28957750, "node_id": "MDQ6VXNlcjI4OTU3NzUw", "avatar_url": "https://avatars.githubusercontent.com/u/28957750?v=4", "gravatar_id": "", "url": "https://api.github.com/users/rafal-jaworski", "html_url": "https://github.com/rafal-jaworski", "followers_url": "https://api.github.com/users/rafal-jaworski/followers", "following_url": "https://api.github.com/users/rafal-jaworski/following{/other_user}", "gists_url": "https://api.github.com/users/rafal-jaworski/gists{/gist_id}", "starred_url": "https://api.github.com/users/rafal-jaworski/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/rafal-jaworski/subscriptions", "organizations_url": "https://api.github.com/users/rafal-jaworski/orgs", "repos_url": "https://api.github.com/users/rafal-jaworski/repos", "events_url": "https://api.github.com/users/rafal-jaworski/events{/privacy}", "received_events_url": "https://api.github.com/users/rafal-jaworski/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I've merged an equivalent patch. Thanks!" ]
"2021-03-05T12:05:56"
"2021-03-05T14:36:49"
"2021-03-05T14:36:49"
NONE
null
I don't know if test is in good file and if the solution is suitable :) Fixes #2368
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2369/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2369/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/2369", "html_url": "https://github.com/coleifer/peewee/pull/2369", "diff_url": "https://github.com/coleifer/peewee/pull/2369.diff", "patch_url": "https://github.com/coleifer/peewee/pull/2369.patch", "merged_at": null }
https://api.github.com/repos/coleifer/peewee/issues/2368
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2368/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2368/comments
https://api.github.com/repos/coleifer/peewee/issues/2368/events
https://github.com/coleifer/peewee/issues/2368
823,010,737
MDU6SXNzdWU4MjMwMTA3Mzc=
2,368
insert_many() does not generate NULL values for fields with null=True
{ "login": "rafal-jaworski", "id": 28957750, "node_id": "MDQ6VXNlcjI4OTU3NzUw", "avatar_url": "https://avatars.githubusercontent.com/u/28957750?v=4", "gravatar_id": "", "url": "https://api.github.com/users/rafal-jaworski", "html_url": "https://github.com/rafal-jaworski", "followers_url": "https://api.github.com/users/rafal-jaworski/followers", "following_url": "https://api.github.com/users/rafal-jaworski/following{/other_user}", "gists_url": "https://api.github.com/users/rafal-jaworski/gists{/gist_id}", "starred_url": "https://api.github.com/users/rafal-jaworski/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/rafal-jaworski/subscriptions", "organizations_url": "https://api.github.com/users/rafal-jaworski/orgs", "repos_url": "https://api.github.com/users/rafal-jaworski/repos", "events_url": "https://api.github.com/users/rafal-jaworski/events{/privacy}", "received_events_url": "https://api.github.com/users/rafal-jaworski/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Thanks, this is fixed now.", "@coleifer Thanks! Could you release a new version with this fix? :)", "3.14.3", "Hey Im still having this issue, and i dont know how to solve it. ", "Works fine for me:\r\n\r\n```python\r\nclass Reg(Model):\r\n key = TextField()\r\n value = IntegerField(null=True)\r\n class Meta:\r\n database = db\r\n\r\ndb.create_tables([Reg])\r\n\r\nl1 = [{'key': 'k1', 'value': None}, {'key': 'k2'}, {'key': 'k3', 'value': 3}]\r\nl2 = [{'key': 'k4'}, {'key': 'k5', 'value': None}, {'key': 'k6', 'value': 6}]\r\n\r\nReg.insert_many(l1, fields=['key', 'value']).execute()\r\nReg.insert_many(l2, fields=['key', 'value']).execute()\r\n\r\nfor r in Reg.select().order_by(Reg.key):\r\n print(r.key, r.value)\r\n# k1 None\r\n# k2 None\r\n# k3 3\r\n# k4 None\r\n# k5 None\r\n# k6 6\r\n```\r\n\r\nIf you don't specify `fields` it will just infer the fields you want from the *first* dict in the list of rows to insert. Alternatively, you can of course provide row tuples.\r\n\r\nhttp://docs.peewee-orm.com/en/latest/peewee/querying.html#bulk-inserts", "You re rigth, the error was mine." ]
"2021-03-05T11:46:39"
"2021-10-28T21:23:55"
"2021-03-05T14:36:35"
NONE
null
Snippet with error. ```python import peewee db = peewee.SqliteDatabase('people.db') class Model(peewee.Model): name = peewee.CharField() x = peewee.IntegerField(null=True) class Meta: database = db db.connect() db.create_tables([Model]) query = Model.insert_many([{"name": "foo", "x": None}, {"name":"bar"}]) query.execute() ``` In a workaround i have to use callable, because of `default=None` is ommited: ```python class Model(peewee.Model): name = peewee.CharField() x = peewee.IntegerField(null=True, default=lambda: None) class Meta: database = db ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2368/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/2368/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2367
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2367/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2367/comments
https://api.github.com/repos/coleifer/peewee/issues/2367/events
https://github.com/coleifer/peewee/issues/2367
822,995,288
MDU6SXNzdWU4MjI5OTUyODg=
2,367
Does peewee create MySQL conn object every time a query execute?
{ "login": "zhuyanxi", "id": 4001245, "node_id": "MDQ6VXNlcjQwMDEyNDU=", "avatar_url": "https://avatars.githubusercontent.com/u/4001245?v=4", "gravatar_id": "", "url": "https://api.github.com/users/zhuyanxi", "html_url": "https://github.com/zhuyanxi", "followers_url": "https://api.github.com/users/zhuyanxi/followers", "following_url": "https://api.github.com/users/zhuyanxi/following{/other_user}", "gists_url": "https://api.github.com/users/zhuyanxi/gists{/gist_id}", "starred_url": "https://api.github.com/users/zhuyanxi/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/zhuyanxi/subscriptions", "organizations_url": "https://api.github.com/users/zhuyanxi/orgs", "repos_url": "https://api.github.com/users/zhuyanxi/repos", "events_url": "https://api.github.com/users/zhuyanxi/events{/privacy}", "received_events_url": "https://api.github.com/users/zhuyanxi/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "If you had spent your time investigating rather than posting this issue, you would find:\r\n\r\nhttp://docs.peewee-orm.com/en/latest/peewee/database.html#connection-management\r\n\r\nIf you want to reuse a connection, then you should use the connection pool, which is mentioned in the above document and also extensively documented:\r\n\r\n* http://docs.peewee-orm.com/en/latest/peewee/database.html#connection-pooling\r\n* http://docs.peewee-orm.com/en/latest/peewee/playhouse.html#pool" ]
"2021-03-05T11:23:17"
"2021-03-05T14:18:01"
"2021-03-05T14:17:48"
NONE
null
https://github.com/coleifer/peewee/blob/ac5126d774d89b07b3e8ccb871897e9a0bf53fde/peewee.py#L3972 I find that in the `MySQLDatabase` class , it will create MySQL conn object every time the function `_connect` executed: ```python def _connect(self): if mysql is None: raise ImproperlyConfigured('MySQL driver not installed!') conn = mysql.connect(db=self.database, **self.connect_params) return conn ``` And now my situation is: I have a MySQL DB in AWS North America, and my frontend app is in China. After I had a test, I found that each time I send a request, there was 2 steps: first connect to the MySQL DB take about 350ms, and then second execute the sql command takes another 350ms, that make my app a little bit slow. So I think may it's better to hold a `conn` object in memory for a while and reuse it than to create a `conn` object every time. And My question is: Is there a way to make the `MySQLDatabase` reuse the `conn` object? Or should I need to extend the `MySQLDatabase` class myself?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2367/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2367/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2366
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2366/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2366/comments
https://api.github.com/repos/coleifer/peewee/issues/2366/events
https://github.com/coleifer/peewee/issues/2366
822,461,288
MDU6SXNzdWU4MjI0NjEyODg=
2,366
Selecting multiple instances of the same model per row
{ "login": "the-vindicar", "id": 2130028, "node_id": "MDQ6VXNlcjIxMzAwMjg=", "avatar_url": "https://avatars.githubusercontent.com/u/2130028?v=4", "gravatar_id": "", "url": "https://api.github.com/users/the-vindicar", "html_url": "https://github.com/the-vindicar", "followers_url": "https://api.github.com/users/the-vindicar/followers", "following_url": "https://api.github.com/users/the-vindicar/following{/other_user}", "gists_url": "https://api.github.com/users/the-vindicar/gists{/gist_id}", "starred_url": "https://api.github.com/users/the-vindicar/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/the-vindicar/subscriptions", "organizations_url": "https://api.github.com/users/the-vindicar/orgs", "repos_url": "https://api.github.com/users/the-vindicar/repos", "events_url": "https://api.github.com/users/the-vindicar/events{/privacy}", "received_events_url": "https://api.github.com/users/the-vindicar/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "In SQL this is natural to return as a tuple, but what you're expressing is represented in Peewee (by default) as a model graph.\r\n\r\nThis hopefully makes it more clear:\r\n\r\n```python\r\n\r\nLiked = Person.alias('liked')\r\n\r\n# Here we are selecting the source person, joining through the Like\r\n# model, and then also selecting the liked person, aliased as \"Liked\".\r\nquery = (Person\r\n .select(Person, Like, Liked)\r\n .join(Like, on=(Like.likes == Person.id))\r\n .join(Liked, on=(Like.liked == Liked.id)))\r\n\r\n# Peewee converts this row-tuple into a graph of the objects\r\n# and relations.\r\nfor person in query:\r\n # To access the \"Liked\"-person's name, we go from the source\r\n # person -> the likes intermediary table -> the liked person instance.\r\n # This does not incur any hidden queries since we selected all the\r\n # data we needed up-front.\r\n print(person.name, person.likes.liked.name)\r\n```\r\n\r\nYou can control the attributes peewee patches the joined instances onto to make it more natural:\r\n\r\n```python\r\n\r\nquery = (Person\r\n .select(Person, Like, Liked)\r\n .join(Like, on=(Like.likes == Person.id), attr='liked')\r\n .join(Liked, on=(Like.liked == Liked.id), attr='person'))\r\n\r\nfor person in query:\r\n print(person.name, person.liked.person.name)\r\n```\r\n\r\nIf you want to skip the whole graph thing, you can use the \".objects()\" method on the query - but you have to alias your columns to avoid name collisions:\r\n\r\n```python\r\nquery = (Person\r\n .select(Person, Liked.name.alias('liked_name'))\r\n .join(Like, on=(Like.likes == Person.id), attr='liked')\r\n .join(Liked, on=(Like.liked == Liked.id), attr='person')\r\n .objects())\r\n\r\nfor person in query:\r\n print(person.name, person.liked_name)\r\n```\r\n\r\nYou may find these documents useful:\r\n\r\n* http://docs.peewee-orm.com/en/latest/peewee/relationships.html#selecting-from-multiple-sources\r\n* http://docs.peewee-orm.com/en/latest/peewee/relationships.html#implementing-many-to-many" ]
"2021-03-04T20:00:32"
"2021-03-05T01:43:33"
"2021-03-05T01:39:56"
NONE
null
Here is a minimal example of what I'm trying to do. ### Model We have a model in many-to-many relation to itself. ```python class BaseModel(peewee.Model): class Meta: database = peewee.SqliteDatabase(':memory:') class Person(BaseModel): id = peewee.AutoField() name = peewee.TextField() class Like(BaseModel): likes = peewee.ForeignKeyField(Person) liked = peewee.ForeignKeyField(Person) class Meta: primary_key = peewee.CompositeKey('likes', 'liked') ``` ### Query I generate some sample data, and then try to select both sides of the relationship in one row. ```python john = Person.create(name='John') jane = Person.create(name='Jane') Like.create(likes=john, liked=jane) Likes = Person.alias('likes') Liked = Person.alias('liked') query = (Likes.select(Likes, Liked) .join(Like, on=Like.likes) .join(Liked, on=Like.liked) ) print(query.tuples()[:]) # [(1, 'John', 2, 'Jane')] print(query[:]) # [<Person: 1>] ??? ``` As you can see, it works fine if I return raw tuples. But I attempt to return models, only the model I'm select()'ing on is returned. Is there a way around that? Can I receive tuples, akin to `(john, jane)`? Or do I have to provide a proxy constructor that will construct the appropriate model objects from the raw tuples? Please keep in mind that this is a simplified example. In the real case, the relationship has multiple "steps" (intermediary tables), even though the ends are still both the same Model in many-to-many relationship. Thus simply performing the select on Like instead is not as easy as it sounds.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2366/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2366/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2365
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2365/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2365/comments
https://api.github.com/repos/coleifer/peewee/issues/2365/events
https://github.com/coleifer/peewee/issues/2365
822,028,438
MDU6SXNzdWU4MjIwMjg0Mzg=
2,365
Connection pool: How to close single connection from pool
{ "login": "kalyanidz", "id": 56637310, "node_id": "MDQ6VXNlcjU2NjM3MzEw", "avatar_url": "https://avatars.githubusercontent.com/u/56637310?v=4", "gravatar_id": "", "url": "https://api.github.com/users/kalyanidz", "html_url": "https://github.com/kalyanidz", "followers_url": "https://api.github.com/users/kalyanidz/followers", "following_url": "https://api.github.com/users/kalyanidz/following{/other_user}", "gists_url": "https://api.github.com/users/kalyanidz/gists{/gist_id}", "starred_url": "https://api.github.com/users/kalyanidz/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/kalyanidz/subscriptions", "organizations_url": "https://api.github.com/users/kalyanidz/orgs", "repos_url": "https://api.github.com/users/kalyanidz/repos", "events_url": "https://api.github.com/users/kalyanidz/events{/privacy}", "received_events_url": "https://api.github.com/users/kalyanidz/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Peewee uses a connection-per-thread, so you get:\r\n\r\n* connect() -> get conn from pool, or if none free create new one\r\n* use connection for a while\r\n* close() -> return connection back to pool\r\n\r\nCalling `db.close()` will close the connection you've been using in the current thread. You use the exact same API when you're using the connection pool as you would when using a non-pooled peewee database implementation.\r\n\r\nI'm not very familiar with fastapi/uvicorn, but for web applications you will use the same pattern I described above:\r\n\r\n* request comes in, thread starts handling request\r\n* open db connection (db.connect())\r\n* do work\r\n* return response\r\n* close db connection (db.close())\r\n\r\nMost web frameworks have some hooks for before/after request. There is a section on the peewee docs about how to do this with FastAPI:\r\n\r\nhttp://docs.peewee-orm.com/en/latest/peewee/database.html#fastapi", "Thank you so much @coleifer ", "@coleifer \r\nOne more query, even if we are passing database instance in peewee basemodel class, do we still need to call db.connect() before the request?", "You should always call `connect()` at the beginning of the connection lifecycle and `close()` at the end. Why? Read here:\r\n\r\nhttp://docs.peewee-orm.com/en/latest/peewee/database.html#using-autoconnect\r\n\r\nPlease read the documentation.", "> You should always call `connect()` at the beginning of the connection lifecycle and `close()` at the end. Why? Read here:\r\n> \r\n> http://docs.peewee-orm.com/en/latest/peewee/database.html#using-autoconnect\r\n> \r\n> Please read the documentation.\r\n\r\nSure. Thanks again. " ]
"2021-03-04T11:12:13"
"2021-03-07T09:25:05"
"2021-03-04T13:52:46"
NONE
null
Hello @coleifer First of all, thank you for developing this simple yet wonderful ORM app peewee. It made the database related coding so well. We are using postgres connection pool with peewee. ``` db = PooledPostgresqlExtDatabase( database=db_secret['name'], user=db_secret['uname'], password=db_secret['pwd'], host=db_secret['host'], port=db_secret['port'], max_connections=30, autocommit=True, autorollback=True) ``` Every time we are done with saving data to database, in finally of that method, we call ``` db.close() ``` I have multiple questions/queries - 1. Will this close the entire pool or just a single connection? 2. In the [documentation](http://docs.peewee-orm.com/en/latest/peewee/playhouse.html#pool) it is mentioned that, > For web applications, this typically means that at the beginning of a request, you will open a connection, and when you return a response, you will close the connection. We are using FastAPI and uvicorn for making it multi-threaded. Considering the above like, do we need to explicitly close the connection?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2365/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2365/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2364
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2364/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2364/comments
https://api.github.com/repos/coleifer/peewee/issues/2364/events
https://github.com/coleifer/peewee/issues/2364
821,602,161
MDU6SXNzdWU4MjE2MDIxNjE=
2,364
ARRAY_AGG not returning expected or consistent results
{ "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
[ "Peewee uses a heuristic on Function objects called with a single field as the argument, where the idea is to use that field's \"python value\" converter to convert the db value into an appropriate python type. As you've found, this is not always what you want.\r\n\r\nTo resolve this for now, you can explicitly tell Peewee not to convert the value by adding `.coerce(False)` after your function invocation:\r\n\r\n```python\r\n\r\nquery = AggregateTest.select(\r\n fn.ARRAY_AGG(AggregateTest.uuid_field).coerce(False).alias('uuid_test'),\r\n fn.ARRAY_AGG(AggregateTest.char_field).coerce(False).alias('char_test'),\r\n fn.ARRAY_AGG(AggregateTest.text_field).coerce(False).alias('text_test'),\r\n fn.ARRAY_AGG(AggregateTest.decimal_field).coerce(False).alias('decimal_test'),\r\n fn.ARRAY_AGG(AggregateTest.integer_field).coerce(False).alias('integer_test'),\r\n)\r\n```\r\n\r\nThis is somewhat covered here:\r\n\r\n* http://docs.peewee-orm.com/en/latest/peewee/api.html#Function\r\n* http://docs.peewee-orm.com/en/latest/peewee/api.html#Function.coerce\r\n\r\nTo get the UUID working you need to register the UUID adapter, which is in psycopg2.extras:\r\n\r\n```python\r\n\r\n# Add at top of file.\r\nfrom psycopg2.extras import register_uuid\r\nregister_uuid()\r\n```\r\n\r\nI've made a small change in Peewee to:\r\n\r\n* blacklist array_agg from using coerce=True by default. This means that Peewee will return the value directly from the cursor without attempting to alter it.\r\n* register the psycopg2 UUID type automatically when peewee is imported\r\n\r\nThose changes should resolve this going forward." ]
"2021-03-03T23:43:05"
"2021-03-04T01:59:18"
"2021-03-04T01:59:18"
NONE
null
[peeweetest.txt](https://github.com/coleifer/peewee/files/6079849/peeweetest.txt) Aggregating rows in postgresql using Peewee gives unexpected results, depending on the field type. _The attached file was used to generate these cases._ ## The results ### UUID Fields `fn.ARRAY_AGG(AggregateTest.uuid_field)` **returns a string** from Peewee: ``` print(repr(record.uuid_field)) # '{314b1cc1-d074-432c-82ba-40864a581806,9e4b271f-d37a-4b59-90ae-12f58abd5636}' ``` ### Char Fields `fn.ARRAY_AGG(AggregateTest.char_field)` **returns a string** from Peewee: ``` print(repr(record.char_test)) # "['CharField', 'CharField2']" ``` Note that this isn't the native postgres format. Postgres returns arrays in curly braces per the UUID field above. ### Integer Fields `fn.ARRAY_AGG(AggregateTest.integer_field)` **returns a list** from Peewee: ``` print(repr(record.integer_test)) # [3, 6] ``` ### Decimal Fields `fn.ARRAY_AGG(AggregateTest.decimal_field)` **raises an exception** from Peewee: ``` ... [peeweetest.txt](https://github.com/coleifer/peewee/files/6079845/peeweetest.txt) File "/usr/local/lib/python3.8/dist-packages/peewee.py", line 4636, in python_value return decimal.Decimal(text_type(value)) decimal.InvalidOperation: [<class 'decimal.ConversionSyntax'>] ``` ## Is it psycopg2? I executed the query generated by peewee directly in psycopg2. It returned the (almost) correct results: ``` '{4350795c-3e1c-4e40-86fa-5a1253a34027,7447bb30-7440-4fe9-9d43-e47ec46d3fc5}' ['CharField', 'CharField2'] ['TextField', 'TextField2'] [3, 6] ``` The only unexpected result here was for the UUID field. I'll come back to that later. Even if I add the Decimal field to the psycopg2 query, I get back the correct result: ``` [Decimal('3.14100'), Decimal('6.28200')] ``` ## Conclusion Somewhere after calling psycopg2 to get the values from the database, Peewee is doing something odd. * For integer fields, it's correctly returning a list. * For char fields, it returns a string representation of a python list. * For UUID fields it's return a string representation of a postgresql list. * For Decimal fields it's throwing an exception. Looking at the source, Peewee is expecting the underlying field type to be returned, not a list. Two examples: * For integer fields peewee [attempts to `int(val)` and on exception just returns `val`](https://github.com/coleifer/peewee/blob/666a7091d5d0893e6f86fced9fb74c308687d66e/peewee.py#L4577) .. thus we get the raw list that came from psycopg2 * For string fields peewee [ultimately calls `str()`](https://github.com/coleifer/peewee/blob/666a7091d5d0893e6f86fced9fb74c308687d66e/peewee.py#L4678) (aliased as text_type) and thus we get back a stringified python list * For decimal fields, peewee attempts to create a Decimal object using the stringified version of the result. So it seems that maybe there needs to be either an understanding that `fn.ARRAY_AGG` returns a list, or if psycopg2 returns a list, Peewee needs to call the handler on each value rather than on the list itself. ## UUID Extra info If I register UUID before making a connection in psycopg2, then I get the correct result from psycopg2: ``` psycopg2.extras.register_uuid() connection = psycopg2.connect(...) # [UUID('bd403fbc-baaa-4b34-b30a-59616b16e0ef'), UUID('9ff379a3-969a-4b87-b71c-b2a57b9b46f2')] ``` But if I register before opening the connection in peewee, the world ends (Or an exception is raised. One or the other.) because psycopg2 is now returning a list of UUID objects and peewee is attempting to create a UUID from the list: ``` ... File "/usr/local/lib/python3.8/dist-packages/peewee.py", line 4833, in python_value return uuid.UUID(value) if value is not None else None File "/usr/lib/python3.8/uuid.py", line 166, in __init__ hex = hex.replace('urn:', '').replace('uuid:', '') AttributeError: 'list' object has no attribute 'replace' ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2364/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2364/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2363
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2363/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2363/comments
https://api.github.com/repos/coleifer/peewee/issues/2363/events
https://github.com/coleifer/peewee/issues/2363
821,076,473
MDU6SXNzdWU4MjEwNzY0NzM=
2,363
CSqliteExtDatabase not available
{ "login": "Nixellion", "id": 20309785, "node_id": "MDQ6VXNlcjIwMzA5Nzg1", "avatar_url": "https://avatars.githubusercontent.com/u/20309785?v=4", "gravatar_id": "", "url": "https://api.github.com/users/Nixellion", "html_url": "https://github.com/Nixellion", "followers_url": "https://api.github.com/users/Nixellion/followers", "following_url": "https://api.github.com/users/Nixellion/following{/other_user}", "gists_url": "https://api.github.com/users/Nixellion/gists{/gist_id}", "starred_url": "https://api.github.com/users/Nixellion/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/Nixellion/subscriptions", "organizations_url": "https://api.github.com/users/Nixellion/orgs", "repos_url": "https://api.github.com/users/Nixellion/repos", "events_url": "https://api.github.com/users/Nixellion/events{/privacy}", "received_events_url": "https://api.github.com/users/Nixellion/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Are you sure cython is installed?\r\nDid you install the python headers? Should be apt install python-dev.\r\nLastly you want sqlite headers. apt install libsqlite3-dev.", "I ran those commands, python3-dev was already installed. Just in case installed python-dev as well.\r\n\r\nran `apt install libsqlite3-dev` as well.\r\n\r\nThen uninstalled and installed peewee again.\r\n\r\nStill nothing.\r\n\r\n```\r\n>>> from playhouse.sqlite_ext import CSqliteExtDatabase\r\nTraceback (most recent call last):\r\n File \"<stdin>\", line 1, in <module>\r\nImportError: cannot import name 'CSqliteExtDatabase' from 'playhouse.sqlite_ext' (/usr/local/lib/python3.7/dist-packages/playhouse/sqlite_ext.py)\r\n```", "Oh okay. I had to install `cython` with `apt` not with `pip`. \r\n\r\nAfter that I had to uninstall and install peewee again with `pip3 install peewee --no-cache-dir`, that did run `setup.py` and it took a few seconds unlike usually, I guess it was compiling it.\r\n\r\nNow importing of that module works.\r\n\r\nHow should I approach this on Windows then? Or should I just bite it and work around it somehow and only use it on lin? Currently I just use try-except and import standard SqliteExtDatabase instead of CSqliteExtDatabase and dont run stuff that requires Cython extensions. But it would be nice to be able to quickly test it while developing, sadly I do use Windows for development.", "It's not necessary to install cython with apt but I suppose something weird is going on with your environment.", "That is a clean Debian 10 install. Also tried on WSL and on Ubuntu 20.04. \r\n\r\nUbuntu 20.04 did not require installing cython with `apt` - that's 100%. But I did not pay attention to that on Debian and WSL.\r\n\r\nSo I suppose it was just the missing `libsqlite3-dev`.\r\n\r\nAnyway it would be great if documentation page actually included these dependencies, here for example: http://docs.peewee-orm.com/en/latest/peewee/installation.html\r\n\r\nOr setup.py could print a warning messaging with instructions. \r\n\r\nWhat do you think?\r\n\r\nAnd thanks for you help.\r\n", "This already exists.\r\n\r\n* http://docs.peewee-orm.com/en/latest/peewee/installation.html#optional-dependencies\r\n* http://docs.peewee-orm.com/en/latest/peewee/installation.html#note-on-the-sqlite-extensions\r\n* https://github.com/coleifer/peewee/blob/d9a58399ba3f55199451d6a612473eafb5c58fe6/setup.py#L96-L103", "I don't see any mention of `libsqlite3-dev` on the page, neither `python-dev`. \r\n\r\nAlso for some reason those warnings were not printed in any of the tests I ran on all 4 systems. If I saw them I would probably not even be here.", "Those are debian-specific package names. The docs and the setup.py script both specify the requirements." ]
"2021-03-03T12:44:07"
"2021-03-03T19:09:57"
"2021-03-03T13:02:04"
NONE
null
Hi! I've been banging my head against this for a few days now, but I can't figure out how to install peewee with pip and make Cython modules work. When I run `pip install Cython` and `pip install peewee` it just goes: ``` Collecting peewee Installing collected packages: peewee Successfully installed peewee-3.14.1 ``` And nothing about building anything. But then using ``` from playhouse.sqlite_ext import CSqliteExtDatabase ``` does not work. Same behavior on Windows and Linux (Debian 10). Python 3.8.x and 3.7.3 What am I missing?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2363/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2363/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2362
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2362/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2362/comments
https://api.github.com/repos/coleifer/peewee/issues/2362/events
https://github.com/coleifer/peewee/issues/2362
820,927,681
MDU6SXNzdWU4MjA5Mjc2ODE=
2,362
how to get execute_sql() result to dict?
{ "login": "mouday", "id": 24365682, "node_id": "MDQ6VXNlcjI0MzY1Njgy", "avatar_url": "https://avatars.githubusercontent.com/u/24365682?v=4", "gravatar_id": "", "url": "https://api.github.com/users/mouday", "html_url": "https://github.com/mouday", "followers_url": "https://api.github.com/users/mouday/followers", "following_url": "https://api.github.com/users/mouday/following{/other_user}", "gists_url": "https://api.github.com/users/mouday/gists{/gist_id}", "starred_url": "https://api.github.com/users/mouday/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/mouday/subscriptions", "organizations_url": "https://api.github.com/users/mouday/orgs", "repos_url": "https://api.github.com/users/mouday/repos", "events_url": "https://api.github.com/users/mouday/events{/privacy}", "received_events_url": "https://api.github.com/users/mouday/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "The `execute_sql` method is a low level method that talks directly to the db-api cursor. If you want dicts then use the query-builder APIs or the various model query APIs. They are documented\r\n\r\n* http://docs.peewee-orm.com/en/latest/peewee/querying.html#retrieving-row-tuples-dictionaries-namedtuples\r\n* http://docs.peewee-orm.com/en/latest/peewee/query_builder.html", "i know , but, some time, i need execute some complex sql. if I see pymysql config\r\n```python\r\nimport pymysql.cursors\r\n\r\n# Connect to the database\r\nconnection = pymysql.connect(host='localhost',\r\n user='user',\r\n password='passwd',\r\n database='db',\r\n cursorclass=pymysql.cursors.DictCursor)\r\n```\r\n\r\nit support `cursorclass` option, but i try it, got a exception\r\n```\r\n File \"/Users/.pyenv/versions/py370/lib/python3.7/site-packages/peewee.py\", line 2161, in scalar\r\n return row[0] if row and not as_tuple else row\r\nKeyError: 0\r\n```\r\n\r\nif use query builder, i think it belong to simple sql, it sql is long and complex, will become to complex and difficulty to fix code.\r\n\r\nnow, i use `mysql_connector_python` got a dict cursor, so i config two mysql db connection.\r\n\r\nso, i will support execute raw sql, and got dict result. it will be wish.\r\n \r\n", "a good message, i support it, convert cursor result to dict\r\n\r\ndemo\r\n```python\r\n# -*- coding: utf-8 -*-\r\nfrom peewee import MySQLDatabase\r\nfrom typing import List, Dict, Union\r\n\r\n\r\ndef dict_factory(cursor, row):\r\n \"\"\"\r\n convert cursor result to dict\r\n \"\"\"\r\n d = {}\r\n for idx, col in enumerate(cursor.description):\r\n d[col[0]] = row[idx]\r\n return d\r\n\r\n\r\nclass DictMySQLDatabase(MySQLDatabase):\r\n\r\n def _execute(self, sql, params):\r\n return self.execute_sql(sql, params)\r\n\r\n def select(self, sql: str, params=()) -> List:\r\n \"\"\"select many row\"\"\"\r\n cursor = self._execute(sql, params)\r\n lst = []\r\n for row in cursor.fetchall():\r\n dct = dict_factory(cursor, row)\r\n lst.append(dct)\r\n\r\n return lst\r\n\r\n def select_one(self, sql: str, params=()) -> Dict:\r\n \"\"\"select one row\"\"\"\r\n cursor = self._execute(sql=sql, params=params)\r\n row = cursor.fetchone()\r\n return dict_factory(cursor, row)\r\n\r\n def update(self, sql: str, params=()) -> int:\r\n \"\"\"update many row\"\"\"\r\n cursor = self._execute(sql=sql, params=params)\r\n return cursor.rowcount\r\n\r\n def delete(self, sql: str, params=()) -> int:\r\n \"\"\"delete many row\"\"\"\r\n cursor = self._execute(sql=sql, params=params)\r\n return cursor.rowcount\r\n\r\n def insert(self, sql: str, params: Union[list, dict]) -> int:\r\n \"\"\"insert many row\"\"\"\r\n cursor = self._execute(sql=sql, params=params)\r\n return cursor.rowcount\r\n\r\n def insert_one(self, sql: str, params: Union[tuple, dict] = ()) -> int:\r\n \"\"\"insert one row\"\"\"\r\n cursor = self._execute(sql=sql, params=params)\r\n return cursor.lastrowid\r\n\r\n```\r\n\r\ntest\r\n```python\r\n\r\ndb = DictMySQLDatabase(**config)\r\n\r\nrows = db.select('select * from person limit 1')\r\nprint(rows)\r\n[{'id': 1, 'name': 'Tom'}]\r\n```", "now i can use cator impl:\r\n```python\r\npip install cator\r\n```\r\n\r\n```python\r\nfrom cator import DatabaseProxy\r\nfrom peewee import MySQLDatabase\r\n\r\ndb = MySQLDatabase(**config)\r\ndb_proxy = DatabaseProxy(db)\r\n# db_proxy can use select/select_one...\r\n```\r\nabout cator DatabaseProxy object see: https://github.com/mouday/cator" ]
"2021-03-03T09:33:16"
"2021-03-10T03:04:10"
"2021-03-03T13:07:53"
NONE
null
by method execute_sql(), got result is tuple, i want to get dict result like: ```python {'id': 1} # or [{'id': 1}, {'id': 2}] ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2362/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2362/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2361
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2361/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2361/comments
https://api.github.com/repos/coleifer/peewee/issues/2361/events
https://github.com/coleifer/peewee/issues/2361
818,395,908
MDU6SXNzdWU4MTgzOTU5MDg=
2,361
Simpler upsert: `updates` on get_or_create
{ "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
[ "For this you should probably be explicit about using the database-specific UPSERT. Because this functionality is not necessarily available across all databases, nor does is it implemented in the same way, Peewee doesn't offer a \"shortcut\" which may mask inefficiencies or gotcha's in the underlying implementation.\r\n\r\nCheck the docs for details on how to issue upsert queries: http://docs.peewee-orm.com/en/latest/peewee/querying.html#upsert" ]
"2021-03-01T02:19:24"
"2021-03-01T16:20:10"
"2021-03-01T16:20:10"
NONE
null
_I acknowledge that this functionality may already exist in a similarly simple form and I just haven't found it_ At the moment if I call `get_or_create` the `defaults` clause is only used when we create the object: ``` model, created = Model.get_or_create( **primary_details, defaults=**secondary_details ) ``` In the case of an "upsert" we don't just want to use those details on a create. We want to update an existing row that matches `primary_details`. Right now, I have this: ``` model, created = Model.get_or_create( **primary_details, defaults=**secondary_details ) if not created: Model.update(**secondary_details).where(Model.id == model).execute() ``` I know postgres has the `on_conflict` extensions but they're both cumbersome and non-transportable. Therefore I would llike to propose an addition to `get_or_create` whereby a new parameter (Eg `updates`) has the same effect on both an existing and new object that `defaults` does on a new object. This would result in the following syntax for users needing an upsert. And as it's handled in python, it would be transportable: ``` model, created = Model.get_or_create( **primary_details, updates=**secondary_details ) ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2361/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2361/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2360
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2360/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2360/comments
https://api.github.com/repos/coleifer/peewee/issues/2360/events
https://github.com/coleifer/peewee/issues/2360
818,223,324
MDU6SXNzdWU4MTgyMjMzMjQ=
2,360
[Q] Do I have to add indexes to peewee if I have manually added them to the table?
{ "login": "NightMachinery", "id": 36224762, "node_id": "MDQ6VXNlcjM2MjI0NzYy", "avatar_url": "https://avatars.githubusercontent.com/u/36224762?v=4", "gravatar_id": "", "url": "https://api.github.com/users/NightMachinery", "html_url": "https://github.com/NightMachinery", "followers_url": "https://api.github.com/users/NightMachinery/followers", "following_url": "https://api.github.com/users/NightMachinery/following{/other_user}", "gists_url": "https://api.github.com/users/NightMachinery/gists{/gist_id}", "starred_url": "https://api.github.com/users/NightMachinery/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/NightMachinery/subscriptions", "organizations_url": "https://api.github.com/users/NightMachinery/orgs", "repos_url": "https://api.github.com/users/NightMachinery/repos", "events_url": "https://api.github.com/users/NightMachinery/events{/privacy}", "received_events_url": "https://api.github.com/users/NightMachinery/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "The only reason you would need to add them to the Peewee model is if you want Peewee to create them whenever you run `database.create_tables([...])` or `MyModel.create_table()`." ]
"2021-02-28T14:44:46"
"2021-02-28T15:14:07"
"2021-02-28T15:14:07"
NONE
null
I have manually added some indexes using Datagrip to my peewee database. Do I have to add these indexes to the peewee model (i.e., add some peewee Python code), or do things just work?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2360/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2360/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2359
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2359/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2359/comments
https://api.github.com/repos/coleifer/peewee/issues/2359/events
https://github.com/coleifer/peewee/issues/2359
817,760,424
MDU6SXNzdWU4MTc3NjA0MjQ=
2,359
Encoding issue on some weird fields
{ "login": "joveice", "id": 14098624, "node_id": "MDQ6VXNlcjE0MDk4NjI0", "avatar_url": "https://avatars.githubusercontent.com/u/14098624?v=4", "gravatar_id": "", "url": "https://api.github.com/users/joveice", "html_url": "https://github.com/joveice", "followers_url": "https://api.github.com/users/joveice/followers", "following_url": "https://api.github.com/users/joveice/following{/other_user}", "gists_url": "https://api.github.com/users/joveice/gists{/gist_id}", "starred_url": "https://api.github.com/users/joveice/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/joveice/subscriptions", "organizations_url": "https://api.github.com/users/joveice/orgs", "repos_url": "https://api.github.com/users/joveice/repos", "events_url": "https://api.github.com/users/joveice/events{/privacy}", "received_events_url": "https://api.github.com/users/joveice/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "```\r\ndb = SqliteDatabase(config.get('save_path'))\r\nconn = db.connection()\r\nconn.text_factory = bytes\r\n```\r\nThis works, would this be a valid way?\r\nSorry for the dumb questions, but this is really new to me.", "Sqlite uses UTF8 (or UTF16) for text. It sounds like you have a weird encoding. I don't know the provenance of this database, but if you're using peewee's `TextField` then this is expressly for storing UTF8-encoded unicode text. If you need to store arbitrary binary data you should use the `BlobField`." ]
"2021-02-27T00:02:38"
"2021-02-27T17:57:06"
"2021-02-27T17:57:06"
NONE
null
Hey, I have some issues trying to read some weird fields. I get this encoding exception: ``` Traceback (most recent call last): File "D:/Projects/autocat-companion/app.py", line 275, in <module> main() File "D:/Projects/autocat-companion/app.py", line 173, in main for x in s: File "D:\Projects\autocat-companion\venv\lib\site-packages\peewee.py", line 6851, in __iter__ python-BaseException self.execute() File "D:\Projects\autocat-companion\venv\lib\site-packages\peewee.py", line 1898, in inner return method(self, database, *args, **kwargs) File "D:\Projects\autocat-companion\venv\lib\site-packages\peewee.py", line 1969, in execute return self._execute(database) File "D:\Projects\autocat-companion\venv\lib\site-packages\peewee.py", line 2141, in _execute cursor = database.execute(self) File "D:\Projects\autocat-companion\venv\lib\site-packages\peewee.py", line 3142, in execute return self.execute_sql(sql, params, commit=commit) File "D:\Projects\autocat-companion\venv\lib\site-packages\peewee.py", line 3136, in execute_sql self.commit() File "D:\Projects\autocat-companion\venv\lib\site-packages\peewee.py", line 2902, in __exit__ reraise(new_type, new_type(exc_value, *exc_args), traceback) File "D:\Projects\autocat-companion\venv\lib\site-packages\peewee.py", line 185, in reraise raise value.with_traceback(tb) File "D:\Projects\autocat-companion\venv\lib\site-packages\peewee.py", line 3129, in execute_sql cursor.execute(sql, params or ()) peewee.OperationalError: Could not decode to UTF-8 column 'RockerSettings' with text '╔T' ``` Now I got the same on sqlite3 and solved it by using [text factory](https://docs.python.org/3/library/sqlite3.html#sqlite3.Connection.text_factory) as bytes I tried to insert it on line 3403 in peewee.py and that seems to sort it out. Is there any ways to do something like this without editing the library? I'm trying to use it with this (which works great with the text_factory insert) ``` class LuabinField(BlobField): def db_value(self, value): return luabins.encode_luabins(value) def python_value(self, value): if value is not None: return luabins.decode_luabins(io.BytesIO(value)) ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2359/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2359/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2358
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2358/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2358/comments
https://api.github.com/repos/coleifer/peewee/issues/2358/events
https://github.com/coleifer/peewee/issues/2358
817,277,636
MDU6SXNzdWU4MTcyNzc2MzY=
2,358
Schema keyword and SQLite
{ "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
[ "A lot of people like to use SQLite as a peer for PostgreSQL for local development.\r\nHowever, I think this approach is not always guaranteed to work, and as much as I love SQLite, PostgreSQL has tons of other features to offer.\r\nSo, my question is: if your production code is running with the latter, why are you not simply developing against it? It's easy enough to start a docker container with PostgreSQL locally even on non Linux machines (Mac and Windows ...).", "This kind of namespacing works differently in sqlite than postgres. To utilize the additional layers of nampespaces in sqlite, you need to use separate database files and then load them into your main database via \"attach\". When you attach a database, you specify it's nampespace, which corresponds to the \"schema\" setting on the model metadata.\r\n\r\nhttp://docs.peewee-orm.com/en/latest/peewee/api.html#SqliteDatabase.attach", "You can make a custom metadata class implementation that has a dynamic schema. This should give you an idea of how to go about it:\r\n\r\nhttp://docs.peewee-orm.com/en/latest/peewee/database.html#thread-safety-and-multiple-databases", "Hi @coleifer, thanks for the details, this is perfect for my use case!" ]
"2021-02-26T11:28:00"
"2021-02-26T13:11:34"
"2021-02-26T12:21:06"
NONE
null
Hi, I am using the `schema` keyword in my models to store the resulting tables in different PostgreSQL schemas. Typical example is: ```python database_proxy = peewee.DatabaseProxy() class Stock(peewee.Model): class Meta: database = database_proxy schema = 'financial-data' symbol = peewee.CharField(max_length=10, primary_key=True) name = peewee.CharField(max_length=255) ``` I also need this code to support SQLite (in a degraded way) to help quick development / deployment. Currently, if ran against a `database_proxy.initialize('sqlite:///data.db')`, I get the following `OperationalError`: ``` peewee.OperationalError: unknown database "financial-data" ``` Is it expected that the `schema` keyword break in this way with an SQLite database? Is it possible to have a dynamic `schema` keyword to remove it when using an SQLite backend? Thanks!
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2358/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2358/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2357
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2357/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2357/comments
https://api.github.com/repos/coleifer/peewee/issues/2357/events
https://github.com/coleifer/peewee/issues/2357
816,556,197
MDU6SXNzdWU4MTY1NTYxOTc=
2,357
Incorrect data saving
{ "login": "sorokousov", "id": 36851598, "node_id": "MDQ6VXNlcjM2ODUxNTk4", "avatar_url": "https://avatars.githubusercontent.com/u/36851598?v=4", "gravatar_id": "", "url": "https://api.github.com/users/sorokousov", "html_url": "https://github.com/sorokousov", "followers_url": "https://api.github.com/users/sorokousov/followers", "following_url": "https://api.github.com/users/sorokousov/following{/other_user}", "gists_url": "https://api.github.com/users/sorokousov/gists{/gist_id}", "starred_url": "https://api.github.com/users/sorokousov/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/sorokousov/subscriptions", "organizations_url": "https://api.github.com/users/sorokousov/orgs", "repos_url": "https://api.github.com/users/sorokousov/repos", "events_url": "https://api.github.com/users/sorokousov/events{/privacy}", "received_events_url": "https://api.github.com/users/sorokousov/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "You have a trailing comma:\r\n\r\n```python\r\n\r\npth.deck_original = bliat,\r\npth.deck_current = bliat,\r\n```", "Oh, my God, this is my mistake)))\r\nThanks you!!!", "somehow i had the exact same mistake. Thank god this issue exist :)\r\n" ]
"2021-02-25T15:44:14"
"2023-04-24T12:29:12"
"2021-02-25T16:16:24"
NONE
null
I apologize in advance for my English. I will describe the problem in a few steps: 1. Creating a model for storing a deck of cards: ``` db = pw.MySQLDatabase(database=db, user=user, password=password, host=host, port=port)` class PTH(pw.Model):` deck_original = pw.TextField(null=True) deck_current = pw.TextField(null=True) cards_left = pw.TextField(null=True) class Meta: database = db ``` 2. Create object: ``` new_deck: list = generate_deck() pth = PTH.create(deck_original=str(new_deck), deck_current=str(new_deck), cards_left=str([])) pth.save() print(type(new_deck), new_deck) # <class 'str'> [[13, 'K', 'd', 'Kd', 'K♦'], [3, '3', 'd', '3d', '3♦'], [14, 'A', ... ``` 3. And then strange things happen: ``` pth = PTH.get_or_none(PTH.id == pth_id) new_deck: list = generate_deck() print('where does the error occur?-1', type(new_deck), new_deck) # where does the error occur?-1 <class 'list'> [[2, '2', 's', '2s', '2♠'], [8, '8', 's', '8s', '8♠'], [6, '6', ... print('where does the error occur?-2', type(pth.deck_original), pth.deck_original) # where does the error occur?-2 <class 'str'> [[13, 'K', 'd', 'Kd', 'K♦'], [3, '3', 'd', '3d', '3♦'], [14, 'A', ... bliat = str(new_deck) print('where does the error occur?-3', type(bliat), bliat) # where does the error occur?-3 <class 'str'> [[2, '2', 's', '2s', '2♠'], [8, '8', ... pth.deck_original = bliat, pth.deck_current = bliat, pth.cards_left = str([]) pth.save() print('where does the error occur?-4', type(pth.deck_original), pth.deck_original) # where does the error occur?-4 <class 'tuple'> ("[[2, '2', 's', '2s', '2♠'], [8, '8', 's', '8s', '8♠'], [6, '6', ... ``` Where does the tuple come from? If I set the bliat variable to 'abcd' (str), the result will be the same. ``` # where does the error occur?-4 <class 'tuple'> ('abcd',) ``` Update: If you apply this approach: ``` pth.__data__['deck_original'] = new_deck # where does the error occur?-4 <class 'tuple'> ([[12, 'Q', 'd', 'Qd', 'Q♦'], [11, 'J', 'c', 'Jc', 'J♣'], [2, '2', ... ``` A list is inserted into the tuple.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2357/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2357/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2356
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2356/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2356/comments
https://api.github.com/repos/coleifer/peewee/issues/2356/events
https://github.com/coleifer/peewee/issues/2356
816,276,322
MDU6SXNzdWU4MTYyNzYzMjI=
2,356
Missing datatype numrange for postgresql
{ "login": "DanielAndreasen", "id": 4519017, "node_id": "MDQ6VXNlcjQ1MTkwMTc=", "avatar_url": "https://avatars.githubusercontent.com/u/4519017?v=4", "gravatar_id": "", "url": "https://api.github.com/users/DanielAndreasen", "html_url": "https://github.com/DanielAndreasen", "followers_url": "https://api.github.com/users/DanielAndreasen/followers", "following_url": "https://api.github.com/users/DanielAndreasen/following{/other_user}", "gists_url": "https://api.github.com/users/DanielAndreasen/gists{/gist_id}", "starred_url": "https://api.github.com/users/DanielAndreasen/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/DanielAndreasen/subscriptions", "organizations_url": "https://api.github.com/users/DanielAndreasen/orgs", "repos_url": "https://api.github.com/users/DanielAndreasen/repos", "events_url": "https://api.github.com/users/DanielAndreasen/events{/privacy}", "received_events_url": "https://api.github.com/users/DanielAndreasen/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I have played around a bit with the source code to get this to work, and found a simple solution that seems to work. I add the following `class` to `playhouse.postgres_ext`\r\n\r\n```python\r\nfrom psycopg2._range import NumericRange\r\n\r\n...\r\n\r\nclass NumericRange(Field, NumericRange):\r\n field_type = 'NUMRANGE'\r\n```\r\n\r\nThe column is now created with all the nice functionality from the `Range` class, which [`NumericRange`](https://github.com/psycopg/psycopg2/blob/master/lib/_range.py#L457-L463) inherits from. Would you like me to open a PR with this simple solution?", "I think this is incorrectly implemented. I would think you would rather do something like this:\r\n\r\n```python\r\n\r\nclass NumericRangeField(Field):\r\n field_type = 'NUMRANGE'\r\n\r\n def adapt(self, value):\r\n if value is not None: return NumericRange(value)\r\n```\r\n\r\nThe idea is that the field retains all the regular field methods/apis while exposing a value to the user which represents the range and can be converted to the appropriate sql by the psycopg2 driver.\r\n\r\nAt any rate, I do not intend to be adding support at the present time.", "Alright, thanks for the answer. I guess I can just implement it directly into my models." ]
"2021-02-25T09:56:03"
"2021-02-25T14:37:42"
"2021-02-25T14:09:42"
NONE
null
I have a case, where I need the datatype [`numrange`](https://www.postgresql.org/docs/9.2/rangetypes.html), however I cannot find it in `playhouse.postgres_ext`. Is it possible to implement this? I know it already exists in `psycopg2._range.NumericRange`. Just for clarification, I have tried making a table like this: ```python from psycopg2._range import NumericRange db = PostgresqlDatabase(...) class Cutoff(BaseModel): parameter = TextField() interval = NumericRange() db.connect() db.create_tables([Cutoff]) ``` but the `interval` does not appear in the generated table, and no errors are thrown either.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2356/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2356/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2355
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2355/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2355/comments
https://api.github.com/repos/coleifer/peewee/issues/2355/events
https://github.com/coleifer/peewee/issues/2355
814,997,780
MDU6SXNzdWU4MTQ5OTc3ODA=
2,355
Enable handling of DB lock collisions
{ "login": "lselker13", "id": 12423842, "node_id": "MDQ6VXNlcjEyNDIzODQy", "avatar_url": "https://avatars.githubusercontent.com/u/12423842?v=4", "gravatar_id": "", "url": "https://api.github.com/users/lselker13", "html_url": "https://github.com/lselker13", "followers_url": "https://api.github.com/users/lselker13/followers", "following_url": "https://api.github.com/users/lselker13/following{/other_user}", "gists_url": "https://api.github.com/users/lselker13/gists{/gist_id}", "starred_url": "https://api.github.com/users/lselker13/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/lselker13/subscriptions", "organizations_url": "https://api.github.com/users/lselker13/orgs", "repos_url": "https://api.github.com/users/lselker13/repos", "events_url": "https://api.github.com/users/lselker13/events{/privacy}", "received_events_url": "https://api.github.com/users/lselker13/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "The error is raised by the sqlite driver you are using -- I'd suggest checking the error message contained in the exception if you want to do special handling of this exception. For general suggestions on how to handle sqlite's write-locking, these posts may help:\r\n\r\n* https://charlesleifer.com/blog/going-fast-with-sqlite-and-python/\r\n* https://charlesleifer.com/blog/multi-threaded-sqlite-without-the-operationalerrors/\r\n\r\nYou can set a timeout on the database instance which controls the busy-timeout sqlite uses for retrying to acquire the lock:\r\n\r\n* http://docs.peewee-orm.com/en/latest/peewee/api.html#SqliteDatabase\r\n\r\nI'd also suggest you familiarize yourself with how sqlite locking works on the sqlite docs website.\r\n\r\nAlso, in case it wasn't clear, sqlite + peewee already specifies a default 5 second busy timeout (if lock is busy, keep attempting to acquire it) - this is a relative eternity in sqlite terms." ]
"2021-02-24T01:38:03"
"2021-02-24T03:21:22"
"2021-02-24T03:20:01"
NONE
null
I'm using Peewee with SQLite DBs. Is there a way to either specify behavior in cases of lock collisions, or to programmatically detect whether a lock collision has occurred, as opposed to some other error? A lock collision seem to result in an `OperationalError`. This is a relatively broad Peewee error (e.g. attempting to use a DB to which a process hasn't connected will cause the same error). As far as I can tell, this means that it's not possible to explicitly handle lock collisions in client code (to, e.g., wait and retry rather than crashing the process). First of all, am I missing some existing approach? A relatively simple solution would be to create a subclass of `OperationalError` (say, a `LockCollisionError`) to be thrown in the case of a lock collision. This would be backwards-compatible with existing error handling and allow users to choose how to handle lock collisions. I'm using Python's asyncio library. So even more useful would be a coroutine allowing client code to wait on the availability of a lock. I realize that this is a more significant project, though. Thanks in advance! -Leo Selker
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2355/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2355/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2354
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2354/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2354/comments
https://api.github.com/repos/coleifer/peewee/issues/2354/events
https://github.com/coleifer/peewee/issues/2354
812,660,415
MDU6SXNzdWU4MTI2NjA0MTU=
2,354
[Feature request] Define foreign key constraint name
{ "login": "ms-lilibeth", "id": 10104959, "node_id": "MDQ6VXNlcjEwMTA0OTU5", "avatar_url": "https://avatars.githubusercontent.com/u/10104959?v=4", "gravatar_id": "", "url": "https://api.github.com/users/ms-lilibeth", "html_url": "https://github.com/ms-lilibeth", "followers_url": "https://api.github.com/users/ms-lilibeth/followers", "following_url": "https://api.github.com/users/ms-lilibeth/following{/other_user}", "gists_url": "https://api.github.com/users/ms-lilibeth/gists{/gist_id}", "starred_url": "https://api.github.com/users/ms-lilibeth/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/ms-lilibeth/subscriptions", "organizations_url": "https://api.github.com/users/ms-lilibeth/orgs", "repos_url": "https://api.github.com/users/ms-lilibeth/repos", "events_url": "https://api.github.com/users/ms-lilibeth/events{/privacy}", "received_events_url": "https://api.github.com/users/ms-lilibeth/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I've gone ahead and added support for this as the changes required were not extensive, although this is honestly the first time this has come up in 10+ years so I don't know it will be of much general benefit. One gotcha: MySQL doesn't seem to support inlining named check constraints into the field definition, but I'll leave this up to the user to sort out for now (again -- seems unlikely that many people will use it and I've put a note in the docs)." ]
"2021-02-20T16:52:57"
"2021-02-21T02:18:08"
"2021-02-21T02:18:08"
NONE
null
I am working with SQLite, and I am really disappointed with the fact that peewee does not assign any name for a foreign key constraint when it builds an SQL query (`peewee.py`: `ForeignKeyField.foreign_key_constraint()`) I have three foreign keys in my model, and the full error message from SQLite is just `FOREIGN KEY constraint failed`. Therefore, I have to guess, which one of these keys is actually wrong. The workaround for same issue with CHECK constraints is to write the full CHECK expression by hand in a field definition: ``` camera_type = TextField( null=True, constraints=[SQL('CONSTRAINT photo_valid_camera_type ' 'CHECK(camera_type IN ("smartphone", "webcam", "terminal", "dome"))')] ) ``` Then the constraint name is included into error message: `peewee.IntegrityError: CHECK constraint failed: photo_valid_camera_type` That is not pretty, but it works. I would like to see the same kind of message for the foreign keys too. P.S. What about adding "name" argument for the function `peewee.Check(constraint)`?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2354/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2354/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2353
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2353/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2353/comments
https://api.github.com/repos/coleifer/peewee/issues/2353/events
https://github.com/coleifer/peewee/pull/2353
812,336,794
MDExOlB1bGxSZXF1ZXN0NTc2NzE5NjA3
2,353
Attempt new connections if the server is not ready
{ "login": "pierky", "id": 6806218, "node_id": "MDQ6VXNlcjY4MDYyMTg=", "avatar_url": "https://avatars.githubusercontent.com/u/6806218?v=4", "gravatar_id": "", "url": "https://api.github.com/users/pierky", "html_url": "https://github.com/pierky", "followers_url": "https://api.github.com/users/pierky/followers", "following_url": "https://api.github.com/users/pierky/following{/other_user}", "gists_url": "https://api.github.com/users/pierky/gists{/gist_id}", "starred_url": "https://api.github.com/users/pierky/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/pierky/subscriptions", "organizations_url": "https://api.github.com/users/pierky/orgs", "repos_url": "https://api.github.com/users/pierky/repos", "events_url": "https://api.github.com/users/pierky/events{/privacy}", "received_events_url": "https://api.github.com/users/pierky/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ ">Not the perfect solution, I know, I'd just like to see if something along this line would be accepted\r\n\r\nI'd suggest putting this into your own subclass of `MySQLDatabase` (or `ReconnectMixin`, whichever you use) as I don't intend to maintain this code or advocate this approach." ]
"2021-02-19T20:48:58"
"2021-02-19T21:53:06"
"2021-02-19T21:53:05"
NONE
null
When using `ReconnectMixin`, the execution of a SQL statement is attempted again if it fails because of "operational issue" (for example when the connection to the DB server is lost). During the reconnection phase, the DB server might not be ready to handle new connections, thus the call to `self.connect()` could also fail. When using `ReconnectMixin`, the execution of a SQL statement is attempted again if it fails because of "operational issue" (for example when the connection to the DB server is lost). During the reconnection phase, the DB server might not be ready to handle new connections, thus the call to `self.connect()` could also fail. With this PR I'm proposing an infinite loop to attempt new connections indefinitely until one is succeeded. Not the perfect solution, I know, I'd just like to see if something along this line would be accepted (I know about some *important* opinions about the disconnection handling). If so, probably some mechanism can be added to the `ReconnectMixin` class to let the developer to specify a limit of attempts or to somehow configure the behaviour.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2353/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2353/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/2353", "html_url": "https://github.com/coleifer/peewee/pull/2353", "diff_url": "https://github.com/coleifer/peewee/pull/2353.diff", "patch_url": "https://github.com/coleifer/peewee/pull/2353.patch", "merged_at": null }
https://api.github.com/repos/coleifer/peewee/issues/2352
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2352/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2352/comments
https://api.github.com/repos/coleifer/peewee/issues/2352/events
https://github.com/coleifer/peewee/issues/2352
812,261,004
MDU6SXNzdWU4MTIyNjEwMDQ=
2,352
add_column only applies default value if column does not allow null
{ "login": "feixie", "id": 394007, "node_id": "MDQ6VXNlcjM5NDAwNw==", "avatar_url": "https://avatars.githubusercontent.com/u/394007?v=4", "gravatar_id": "", "url": "https://api.github.com/users/feixie", "html_url": "https://github.com/feixie", "followers_url": "https://api.github.com/users/feixie/followers", "following_url": "https://api.github.com/users/feixie/following{/other_user}", "gists_url": "https://api.github.com/users/feixie/gists{/gist_id}", "starred_url": "https://api.github.com/users/feixie/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/feixie/subscriptions", "organizations_url": "https://api.github.com/users/feixie/orgs", "repos_url": "https://api.github.com/users/feixie/repos", "events_url": "https://api.github.com/users/feixie/events{/privacy}", "received_events_url": "https://api.github.com/users/feixie/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "The `apply_default()` method is exposed as an operation, just like `add_column()`. Since \"defaults\" specified this way are implemented in Python rather than as a sql default constraint, I've avoided automatically applying them when the field is left nullable (as this implies an UPDATE of every row of the table).\r\n\r\nSo you would:\r\n\r\n```python\r\n\r\nmigrate(\r\n migrator.add_column('my_tbl', 'my_col', field_obj),\r\n migrator.apply_default('my_tbl', 'my_col', field_obj),\r\n)\r\n```" ]
"2021-02-19T18:58:24"
"2021-02-19T22:01:22"
"2021-02-19T22:01:22"
NONE
null
I would like to add columns that allow nulls AND have a default value. While I can define columns with default values and null=True when I create the table, I can't do it via add_column because this line: https://github.com/coleifer/peewee/blob/master/playhouse/migrate.py#L329 only applies the default value when the field is not nullable.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2352/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2352/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2351
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2351/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2351/comments
https://api.github.com/repos/coleifer/peewee/issues/2351/events
https://github.com/coleifer/peewee/issues/2351
811,440,185
MDU6SXNzdWU4MTE0NDAxODU=
2,351
Migrator applies the same value from callable default
{ "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
[ "If it's a python callable what's peewee supposed to do... iterate every single row and update it? That would not work and would cause performance problems for users because it is unexpected.\r\n\r\nIf you want, you can use a sql function - sqlite lets you add user-defined functions quite easily - and even use them for column defaults. Alternatively, you can set it to some placeholder and then iterate every row if you're so inclined." ]
"2021-02-18T20:39:55"
"2021-02-18T23:13:36"
"2021-02-18T23:13:36"
CONTRIBUTOR
null
With value generator like ```python def gen_nanoid(): return nanoid.generate(size=12) ``` and migration definition: ```python def add_permalink(): field = CharField(max_length=20, default=gen_nanoid) migrate( migrator.add_column('quip', 'permalink', field) ) ``` All rows in the table being migrated get the same value: ```console $ sqlite3 db.sqlite SQLite version 3.31.1 2020-01-27 19:55:54 Enter ".help" for usage hints. sqlite> select permalink from quip; Ufwe7VZMiloN Ufwe7VZMiloN Ufwe7VZMiloN Ufwe7VZMiloN sqlite> ``` This makes adding a column with unique constraint not possible without some hacking (add normal non-unique column with static default, update with unique values using raw SQL while iterating over rows, add unique index on new column). Peewee 3.14.1 with SQLite (built-in module, Python 3.8.5).
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2351/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2351/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2350
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2350/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2350/comments
https://api.github.com/repos/coleifer/peewee/issues/2350/events
https://github.com/coleifer/peewee/issues/2350
811,041,784
MDU6SXNzdWU4MTEwNDE3ODQ=
2,350
Extension support check in setup.py needs path to sqlite3.h and sqlite3.lib files on Windows.
{ "login": "cdcadman", "id": 51368516, "node_id": "MDQ6VXNlcjUxMzY4NTE2", "avatar_url": "https://avatars.githubusercontent.com/u/51368516?v=4", "gravatar_id": "", "url": "https://api.github.com/users/cdcadman", "html_url": "https://github.com/cdcadman", "followers_url": "https://api.github.com/users/cdcadman/followers", "following_url": "https://api.github.com/users/cdcadman/following{/other_user}", "gists_url": "https://api.github.com/users/cdcadman/gists{/gist_id}", "starred_url": "https://api.github.com/users/cdcadman/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/cdcadman/subscriptions", "organizations_url": "https://api.github.com/users/cdcadman/orgs", "repos_url": "https://api.github.com/users/cdcadman/repos", "events_url": "https://api.github.com/users/cdcadman/events{/privacy}", "received_events_url": "https://api.github.com/users/cdcadman/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Glad you got it working." ]
"2021-02-18T12:09:52"
"2021-02-18T15:23:49"
"2021-02-18T15:23:49"
NONE
null
Initially, when I ran `python setup.py build_ext -i`, I got the following message. <pre>test_pw_sqlite3.c(1): fatal error C1083: Cannot open include file: 'sqlite3.h': No such file or directory unable to compile sqlite3 C extensions - missing headers? setup.py:100: UserWarning: Could not find libsqlite3, SQLite extensions will not be built. warnings.warn('Could not find libsqlite3, SQLite extensions will not ' running build_ext</pre> After I modified setup.py so that it could find sqlite3.h and sqlite3.lib in the extension support check, the setup worked fine. In '_have_sqlite_extension_support()', I inserted two lines after line 71 (`compiler = new_compiler()`): ` compiler.add_include_dir(r'C:\Program Files (x86)\Python38-32\include')` (location of my sqlite3.h file) ` compiler.add_library_dir(r'C:\Program Files (x86)\Python38-32\libs')` (location of my sqlite3.lib file)
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2350/reactions", "total_count": 1, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 1, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2350/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2349
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2349/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2349/comments
https://api.github.com/repos/coleifer/peewee/issues/2349/events
https://github.com/coleifer/peewee/issues/2349
807,959,540
MDU6SXNzdWU4MDc5NTk1NDA=
2,349
DESC not working in jsonb type
{ "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
[ "It works fine for me:\r\n\r\n```python\r\n\r\nclass T(Model):\r\n data = BinaryJSONField()\r\n class Meta:\r\n database = db\r\n\r\ndb.drop_tables([T])\r\ndb.create_tables([T])\r\nT.create(data={'k1': 'v1', 'k2': 'v2'})\r\nT.create(data={'k1': 'v3', 'k2': 'v4'})\r\nT.create(data={'k1': 'v5', 'k2': 'v6'})\r\n\r\nquery = T.select().order_by(T.data['k1'].desc())\r\nfor row in query:\r\n print(row.data['k1'])\r\n# prints:\r\n# v5\r\n# v3\r\n# v1\r\n```" ]
"2021-02-14T13:18:54"
"2021-02-14T15:13:34"
"2021-02-14T15:13:34"
NONE
null
.desc() not working in jsob table, ``` class Player(BaseModel): user_id = IntegerField() ivent_stats = BinaryJSONField(default={"safe": 0, "bomb": 0, "robbery": 0}) players = await db.execute(Player.select(Player.user_id, Player.ivent_stats).order_by((Player.ivent_stats['robbery']).desc())) ``` I trying to get robbery value from more to less, but it olvays returning less to more, what i do wrong?(
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2349/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2349/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2348
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2348/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2348/comments
https://api.github.com/repos/coleifer/peewee/issues/2348/events
https://github.com/coleifer/peewee/issues/2348
807,937,225
MDU6SXNzdWU4MDc5MzcyMjU=
2,348
Issue on postgres_ext.ArrayField python_value conversion
{ "login": "whisust", "id": 22323709, "node_id": "MDQ6VXNlcjIyMzIzNzA5", "avatar_url": "https://avatars.githubusercontent.com/u/22323709?v=4", "gravatar_id": "", "url": "https://api.github.com/users/whisust", "html_url": "https://github.com/whisust", "followers_url": "https://api.github.com/users/whisust/followers", "following_url": "https://api.github.com/users/whisust/following{/other_user}", "gists_url": "https://api.github.com/users/whisust/gists{/gist_id}", "starred_url": "https://api.github.com/users/whisust/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/whisust/subscriptions", "organizations_url": "https://api.github.com/users/whisust/orgs", "repos_url": "https://api.github.com/users/whisust/repos", "events_url": "https://api.github.com/users/whisust/events{/privacy}", "received_events_url": "https://api.github.com/users/whisust/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I've tried switching the `UUIDField` in a `CharField` for the `course_ids` in the example, and the result of the converter is the following:\r\n![Screenshot 2021-02-14 at 12 19 27](https://user-images.githubusercontent.com/22323709/107875270-43c93200-6ebf-11eb-8166-584be078e693.png)\r\n\r\nTypes are ok because, indeed `{something1,something2}` is a valid string, but then\r\n```\r\n> type(new_program.course_ids) == str\r\nTrue\r\n```\r\n\r\nwhen it's suppose to be a List[str]", "This feels like a psycopg2 bug rather than a peewee issue. Why is the value returned by the cursor a string (`'{}'`) and not an empty list? With other data-types psycopg2 tends to handle this correctly - returning us an empty list. But for the `[]UUID` data-type it returns empty arrays as the literal string `'{}'`.\r\n\r\nHere is an example using an array of varchar, which works fine:\r\n\r\n```python\r\nclass T(Model):\r\n id = UUIDField(primary_key=True, default=uuid.uuid4, constraints=[ \r\n SQL('default gen_random_uuid()')])\r\n vals = ArrayField(CharField, null=False, convert_values=True, \r\n default=[], constraints=[SQL('default array[]::character varying[]')]) \r\n\r\nt = T.create()\r\nprint(t.id, t.vals)\r\n\r\nt = T.insert().execute()\r\nprint(t)\r\n\r\nfor row in T.select():\r\n print(row.id, row.vals)\r\n\r\nt = T.insert().returning(T).execute()[0]\r\nprint(t)\r\n```\r\n\r\nAll of the above work fine, and the output from one run is:\r\n\r\n```\r\n9237cac9-6cf3-479a-84c4-62bdd2ef83f2 []\r\n79aa4346-19fa-4db5-8a36-0663ba405fe3\r\n9237cac9-6cf3-479a-84c4-62bdd2ef83f2 []\r\n79aa4346-19fa-4db5-8a36-0663ba405fe3 []\r\n6984a525-e5b6-41cc-a9b9-ec83afcf5c58\r\n```\r\n\r\nAs you noted, changing this to a UUID causes a problem with the empty array:\r\n\r\n```python\r\n # Change \"vals\" to array of UUID.\r\nclass T...\r\n vals = ArrayField(UUIDField, null=False, convert_values=True,\r\n default=[],\r\n constraints=[SQL('default array[]::uuid[]')])\r\n\r\n# These both work:\r\nt = T.create()\r\nt = T.insert().execute()\r\n\r\n# These both fail with the \"ValueError: badly formed hexadecimal UUID string\":\r\nfor row in T.select():\r\n print(row.id, row.vals)\r\n\r\nt = T.insert().returning(T).execute()[0]\r\n```\r\n\r\nI would raise this with the psycopg2 developers. The driver should be returning us that empty list as a standard python list and definitely not as a string. A workaround you can probably use in the meantime is to subclass `ArrayField`:\r\n\r\n```python\r\n\r\nclass SafeArrayField(ArrayField):\r\n def python_value(self, value):\r\n if isinstance(value, str) and value == '{}':\r\n return []\r\n return super(SafeArrayField, self).python_value(value)\r\n```\r\n\r\nWhen using the above implementation, then all the above code works correctly." ]
"2021-02-14T11:01:32"
"2021-02-14T15:38:03"
"2021-02-14T15:38:02"
NONE
null
The `ArrayField.python_value` functions seems to misuse the conversion function in the case of a `convert_value=True` field: Given: ```python import uuid from uuid import UUID from peewee import * from typing import List class Program(Model): """ SQL: CREATE TABLE IF NOT EXISTS programs ( id UUID PRIMARY KEY DEFAULT uuid_generate_v4(), course_ids UUID[] DEFAULT ARRAY[]::UUID[] ); """ id = UUIDField(primary_key=True, default=uuid.uuid4) course_ids = ArrayField(field_class=UUIDField, null=False, convert_values=True, default=[]) class Meta: primary_key = False def update(program_id: UUID, course_ids: List[UUID]) -> Program: return Program.update(course_ids=course_ids)\ .where(Program.id == program_id)\ .returning(Program)\ .execute()[0] new_program = Program.insert().returning(Program).execute()[0] # fails during the `course_ids` conversion function if convert_value=True, cf capture n1 new_program = update(new_program.id, [uuid.uuid4(), uuid.uuid4()]) # fails DB-side if convert_values=False, cf capture n2 ``` when I create my Program with the defaults, in the function ```python def python_value(self, value): if self.convert_values and value is not None: conv = self.__field.python_value if isinstance(value, list): return self._process(conv, value, self.dimensions) else: return conv(value) else: return value ``` we have those fields: ![Screenshot 2021-02-14 at 11 27 04](https://user-images.githubusercontent.com/22323709/107874451-1f1e8b80-6eba-11eb-9398-abf9febc7c1b.png) which translate in the call of `return conv(value)` as: ![Screenshot 2021-02-14 at 11 51 06](https://user-images.githubusercontent.com/22323709/107874616-0662a580-6ebb-11eb-9219-fb38641e59a5.png) That triggers a ``` ValueError: badly formed hexadecimal UUID string ``` which is expected from a `UUID('{}')` call Reading the 3 returns present in the function, either we return: - from l.198 with an equivalent of `[conv(v) for v in value]`, which gives us a `List[UUID]`, nice - from l.200 with an equivalent of `UUIDField(value)`, which should give us an `UUID`, not nice - from l.202 with the default `value` which is the default, which returns a `str`, ??? So, in the same function, we either return a List[T], T or `str`. There is probably some history that I'm missing here, but I can't understand, in terms of types, the `else: return conv(v)`. My first workaround was to disable the `convert_values`, but then it's also skipped for the `update` call and it translates to an SQL query with: ``` sql = 'UPDATE "programs" SET "course_ids" = %s WHERE "id" = %s params = [[UUID('571df177-0e30-49cc-8a47-276be6a74697'), UUID('11068552-797e-4f09-afdf-c83a4d8ac184')], $program_id] ``` Which raises ```python def execute_sql(self, sql, params=None, commit=SENTINEL): logger.debug((sql, params)) if commit is SENTINEL: if self.in_transaction(): commit = False elif self.commit_select: commit = True else: commit = not sql[:6].lower().startswith('select') with __exception_wrapper__: cursor = self.cursor(commit) try: > cursor.execute(sql, params or ()) E peewee.ProgrammingError: can't adapt type 'UUID' ../../venvs/backend/lib/python3.8/site-packages/peewee.py:3129: ProgrammingError ``` I'll try with the conversion disabled and a bit of custom code in the update function to convert in strings, explicitly casted in UUID[] array after
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2348/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2348/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2347
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2347/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2347/comments
https://api.github.com/repos/coleifer/peewee/issues/2347/events
https://github.com/coleifer/peewee/issues/2347
806,167,748
MDU6SXNzdWU4MDYxNjc3NDg=
2,347
Undocumented conflict with field name "_path"?
{ "login": "alvenhar", "id": 61888606, "node_id": "MDQ6VXNlcjYxODg4NjA2", "avatar_url": "https://avatars.githubusercontent.com/u/61888606?v=4", "gravatar_id": "", "url": "https://api.github.com/users/alvenhar", "html_url": "https://github.com/alvenhar", "followers_url": "https://api.github.com/users/alvenhar/followers", "following_url": "https://api.github.com/users/alvenhar/following{/other_user}", "gists_url": "https://api.github.com/users/alvenhar/gists{/gist_id}", "starred_url": "https://api.github.com/users/alvenhar/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/alvenhar/subscriptions", "organizations_url": "https://api.github.com/users/alvenhar/orgs", "repos_url": "https://api.github.com/users/alvenhar/repos", "events_url": "https://api.github.com/users/alvenhar/events{/privacy}", "received_events_url": "https://api.github.com/users/alvenhar/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Thanks for the report. Not going to take any action on this at the moment, but feel free to open a patch to add a section to the docs." ]
"2021-02-11T08:09:33"
"2021-02-11T15:46:08"
"2021-02-11T15:46:08"
NONE
null
Hi, I recently encountered the problem that peewee's create_tables() call hung indefinitely and started eating up massive RAM for a minuscule database setup. I finally figured out that the "offensive" change was that I named a CharField on one of my models "_path". As soon as I changed that to "_path_str", everything was back to normal, so I guess "_path" conflicts with the underlying peewee implementation. That's fine, it was just hard to find as the docs didn't mention any reserved words/identifiers and this one is not of the usual python "hidden magic". Might look into that?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2347/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2347/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2346
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2346/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2346/comments
https://api.github.com/repos/coleifer/peewee/issues/2346/events
https://github.com/coleifer/peewee/issues/2346
806,011,694
MDU6SXNzdWU4MDYwMTE2OTQ=
2,346
Support for a new db type
{ "login": "pfw", "id": 92163, "node_id": "MDQ6VXNlcjkyMTYz", "avatar_url": "https://avatars.githubusercontent.com/u/92163?v=4", "gravatar_id": "", "url": "https://api.github.com/users/pfw", "html_url": "https://github.com/pfw", "followers_url": "https://api.github.com/users/pfw/followers", "following_url": "https://api.github.com/users/pfw/following{/other_user}", "gists_url": "https://api.github.com/users/pfw/gists{/gist_id}", "starred_url": "https://api.github.com/users/pfw/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/pfw/subscriptions", "organizations_url": "https://api.github.com/users/pfw/orgs", "repos_url": "https://api.github.com/users/pfw/repos", "events_url": "https://api.github.com/users/pfw/events{/privacy}", "received_events_url": "https://api.github.com/users/pfw/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Pretty much. You'll want to use a db-api 2.0 compatible driver, e.g. one of:\r\n\r\nhttps://www.firebirdsql.org/file/documentation/drivers_documentation/python/3.3.0/Python-DB-API-2.0.html\r\n\r\nYou would subclass `Database` and start by implementing the `_connect()` method and go from there. I'm not familiar with Firebird so I am not sure what subtleties you may encounter along the way. The sqlalchemy codebase might provide some helpful hints, as well:\r\n\r\nhttps://github.com/sqlalchemy/sqlalchemy/tree/master/lib/sqlalchemy/dialects/firebird\r\n\r\nSince this is not a bugfix I will close, but feel free to raise any questions you encounter along the way and I'll try to help.", "Good one, thank for the pointers. At the moment it's definitely an experiment but I'll update if we get anywhere with it." ]
"2021-02-11T01:31:15"
"2021-02-11T03:06:43"
"2021-02-11T02:54:46"
NONE
null
I'm interested in peewee since it is lightweight and looks approachable while still supporting what we require. We have some data in FirebirdSQL and I was going to have a look at getting peewee going against it as an experiment and learning experience. To get it up and running would it 'just' require implementing a subclass of Database with all of the methods raising NotImplementedError implemented or are there other places that need attention? Obviously to start with this is just an experiment and to get something correct would require tests.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2346/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2346/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2345
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2345/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2345/comments
https://api.github.com/repos/coleifer/peewee/issues/2345/events
https://github.com/coleifer/peewee/issues/2345
805,352,954
MDU6SXNzdWU4MDUzNTI5NTQ=
2,345
Race condition at class level when dynamically binding the DB
{ "login": "whisust", "id": 22323709, "node_id": "MDQ6VXNlcjIyMzIzNzA5", "avatar_url": "https://avatars.githubusercontent.com/u/22323709?v=4", "gravatar_id": "", "url": "https://api.github.com/users/whisust", "html_url": "https://github.com/whisust", "followers_url": "https://api.github.com/users/whisust/followers", "following_url": "https://api.github.com/users/whisust/following{/other_user}", "gists_url": "https://api.github.com/users/whisust/gists{/gist_id}", "starred_url": "https://api.github.com/users/whisust/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/whisust/subscriptions", "organizations_url": "https://api.github.com/users/whisust/orgs", "repos_url": "https://api.github.com/users/whisust/repos", "events_url": "https://api.github.com/users/whisust/events{/privacy}", "received_events_url": "https://api.github.com/users/whisust/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ ">We select the database dynamically depending on the query to run.\r\n>A read-only query will be run using connections from the read-able pools;\r\n>A write query will be run only on the leader pool.\r\n>Thus, before each query, we model.bind(db) using the correct db\r\n\r\nYou might try storing `Model._meta.database` in a thread-local. I tested and this is working fine for me:\r\n\r\n```python\r\nfrom peewee import Metadata\r\n\r\nclass ThreadSafeDatabaseMetadata(Metadata):\r\n def __init__(self, *args, **kwargs):\r\n self._local = threading.local()\r\n super(ThreadSafeDatabaseMetadata, self).__init__(*args, **kwargs)\r\n\r\n def _get_db(self):\r\n return getattr(self._local, 'database', self._database)\r\n def _set_db(self, db):\r\n self._local.database = self._database = db\r\n database = property(_get_db, _set_db)\r\n\r\nclass BaseModel(Model):\r\n class Meta:\r\n model_metadata_class = ThreadSafeDatabaseMetadata\r\n```\r\n\r\nOverall I do not plan on changing the way binding databases works for the models API." ]
"2021-02-10T09:51:18"
"2021-02-10T15:54:24"
"2021-02-10T15:48:06"
NONE
null
Related to https://github.com/coleifer/peewee/issues/2339 and in a minor way https://github.com/coleifer/peewee/issues/2306 # Context Usage of peewee with - two connection pools to the same database, one being restricted in read-only (read replica or read-only user) - usage in a greenlet environment (here gunicorn running gevent greenlets) # Run Explanation We select the database dynamically depending on the query to run. A read-only query will be run using connections from the read-able pools; A write query will be run only on the leader pool. Thus, before each query, we `model.bind(db)` using the correct db # Issue With the database being tied to the Model class after the `.bind`, plus the Model class reference being shared by both greenlets, the Model._meta.database becomes a mutable, shared, non-synchronized data field. Thus, it's possible to create a race condition if at least two greenlets are doing read and write operations (and so, db bindings) simultaneously on the same model. It is highly unlikely, but under a basic load (let's say a b2c website with a sustained traffic) it happens. In my case, with 1 million requests per day, it happened 5-10 times in 24h. # Propositions - Workaround (me): adding a class-level lock to ensure no db re-bind are done between a db<->model bind and the query execution for write operations in the thread scope [quickfix, hacky, can cause perf issues? but usable] - Upgrade (peewee): proposing a way to select the DB at query time instead of taking the hardbound one (like a `database_provider` at class level instead of the `database`, taking in argument at least the read-only indication as query context). For this one, I know there is already a `database` optional argument in the `execute` method. I can use it if that's your recommended way, but my question would be with the overall coherence of the peewee api's (mix between the presets like `get_or_none` that cannot be customised, and the `Model.select().execute(db?)`. - Upgrade (peewee): not binding the model to a db, or not binding the db and the connection <- huge API change I think Here is an example using a Sentry stack trace, and keep in mind that it's used in a multithreaded environment: ![Screenshot 2021-02-10 at 10 20 23](https://user-images.githubusercontent.com/22323709/107492871-36ddd300-6b8d-11eb-8d15-4f9392ac8b4e.png) ![Screenshot 2021-02-10 at 10 20 50](https://user-images.githubusercontent.com/22323709/107492888-3c3b1d80-6b8d-11eb-8bc5-27285fa2ed52.png) I can do a code snippet to reproduce the error if you want.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2345/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2345/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2344
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2344/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2344/comments
https://api.github.com/repos/coleifer/peewee/issues/2344/events
https://github.com/coleifer/peewee/issues/2344
803,558,603
MDU6SXNzdWU4MDM1NTg2MDM=
2,344
Syntax error near "VALUES" when using ValuesList and Tuple
{ "login": "cvanea", "id": 17099087, "node_id": "MDQ6VXNlcjE3MDk5MDg3", "avatar_url": "https://avatars.githubusercontent.com/u/17099087?v=4", "gravatar_id": "", "url": "https://api.github.com/users/cvanea", "html_url": "https://github.com/cvanea", "followers_url": "https://api.github.com/users/cvanea/followers", "following_url": "https://api.github.com/users/cvanea/following{/other_user}", "gists_url": "https://api.github.com/users/cvanea/gists{/gist_id}", "starred_url": "https://api.github.com/users/cvanea/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/cvanea/subscriptions", "organizations_url": "https://api.github.com/users/cvanea/orgs", "repos_url": "https://api.github.com/users/cvanea/repos", "events_url": "https://api.github.com/users/cvanea/events{/privacy}", "received_events_url": "https://api.github.com/users/cvanea/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "As a workaround you can add parentheses by:\r\n\r\n```python\r\n\r\nfrom peewee import EnclosedNodeList\r\n\r\nvl = ValuesList(coords, columns=('x', 'y'))\r\nrhs = EnclosedNodeList([vl])\r\n...where(Tuple(T.x, T.y).in_(rhs))\r\n```", "If you're using Sqlite, it is very picky about what it accepts. The following approaches all work with Postgres, but not Sqlite for some reason:\r\n\r\n```python\r\n\r\nvl = ValuesList(((1, 2), (2, 3)), columns=('x', 'y'))\r\nq = T.select().from_(T, vl).where(\r\n (T.x == vl.c.x) &\r\n (T.y == vl.c.y))\r\n\r\nq = T.select().from_(T).join(vl, on=(\r\n (T.x == vl.c.x) &\r\n (T.y == vl.c.y)))\r\n```", "The EnclosedNodeList suggestion worked perfectly and sped up a big update query I had quite drastically.\r\n\r\nThanks for looking into this and for the great library!" ]
"2021-02-08T13:19:14"
"2021-02-10T10:20:43"
"2021-02-09T20:37:50"
NONE
null
Hi, I'm trying to select rows from a table where the given row values are in a list of tuples. As I understand it, SQLite can only support this kind of IN operation if the right-hand side is a subquery expression. Therefore, in SQLite the following works: ```sql CREATE TABLE T1(x,y,z); INSERT INTO T1(x,y,z) VALUES(1,2,3),(2,3,4),(1,NULL,5); SELECT * FROM T1 WHERE ((x,y) in (VALUES (1,2), (2,3))); ``` I've tried to implement this using peewee as follows: ```python coords = [(1,2), (2,3)] vl = ValuesList(coords, columns=('x', 'y')) selection = T1.select().where(Tuple(T1.x, T1.y) << vl) ``` However, this leads to the error `{OperationalError}near "VALUES": syntax error` Inspecting the query in the debugger it seems that peewee is trying to do something like: ```sql SELECT * FROM T1 WHERE ((x,y) in VALUES (1,2), (2,3)); ``` I believe the error comes from the lack of brackets around the VALUES clause as running the same in SQLite leads to the same error. Apologies if there's a better way to form this kind of query or I've missed something, I'm fairly new to SQL and peewee. Thanks!
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2344/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2344/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2343
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2343/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2343/comments
https://api.github.com/repos/coleifer/peewee/issues/2343/events
https://github.com/coleifer/peewee/issues/2343
802,782,702
MDU6SXNzdWU4MDI3ODI3MDI=
2,343
Can not add a not null column to a table with CHECK constraint
{ "login": "feixie", "id": 394007, "node_id": "MDQ6VXNlcjM5NDAwNw==", "avatar_url": "https://avatars.githubusercontent.com/u/394007?v=4", "gravatar_id": "", "url": "https://api.github.com/users/feixie", "html_url": "https://github.com/feixie", "followers_url": "https://api.github.com/users/feixie/followers", "following_url": "https://api.github.com/users/feixie/following{/other_user}", "gists_url": "https://api.github.com/users/feixie/gists{/gist_id}", "starred_url": "https://api.github.com/users/feixie/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/feixie/subscriptions", "organizations_url": "https://api.github.com/users/feixie/orgs", "repos_url": "https://api.github.com/users/feixie/repos", "events_url": "https://api.github.com/users/feixie/events{/privacy}", "received_events_url": "https://api.github.com/users/feixie/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Thanks for the report. This is fixed in master." ]
"2021-02-06T20:17:40"
"2021-02-07T14:37:45"
"2021-02-07T14:37:40"
NONE
null
Most of the tables in my sqlite db have CHECK constraints. The schema of one such table looks like this: `CREATE TABLE "study" ("id" INTEGER NOT NULL PRIMARY KEY, "created_at" DATETIME NOT NULL, "uid" TEXT NOT NULL, "patient_id" VARCHAR(255) NOT NULL, "provider_id" VARCHAR(255) NOT NULL, "first_name" VARCHAR(255) NOT NULL, "last_name" VARCHAR(255) NOT NULL, "birthdate" DATE, "gender" VARCHAR(255), CHECK (gender IN ('female','male')), CHECK (patient_id != ''))` When I try to do a: `migrate.migrate( migrator.add_column( 'study', 'visit_id', peewee.CharField(default='', null=True)) ) )` I get this error: `sqlite3.OperationalError: table study__tmp__ has no column named CHECK` I believe this is because CHECK constraints aren't being removed here: https://github.com/coleifer/peewee/blob/master/playhouse/migrate.py#L720 and they are being treated as columns to update. Tested that adding 'check ' to constraint_terms fixes the issue. Can someone with permission submit a PR? Does anyone have thoughts on a workaround in the mean time?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2343/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2343/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2342
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2342/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2342/comments
https://api.github.com/repos/coleifer/peewee/issues/2342/events
https://github.com/coleifer/peewee/issues/2342
802,779,858
MDU6SXNzdWU4MDI3Nzk4NTg=
2,342
Feature request: A Database for testing that just navigates through Model attributes
{ "login": "dmyersturnbull", "id": 3979879, "node_id": "MDQ6VXNlcjM5Nzk4Nzk=", "avatar_url": "https://avatars.githubusercontent.com/u/3979879?v=4", "gravatar_id": "", "url": "https://api.github.com/users/dmyersturnbull", "html_url": "https://github.com/dmyersturnbull", "followers_url": "https://api.github.com/users/dmyersturnbull/followers", "following_url": "https://api.github.com/users/dmyersturnbull/following{/other_user}", "gists_url": "https://api.github.com/users/dmyersturnbull/gists{/gist_id}", "starred_url": "https://api.github.com/users/dmyersturnbull/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/dmyersturnbull/subscriptions", "organizations_url": "https://api.github.com/users/dmyersturnbull/orgs", "repos_url": "https://api.github.com/users/dmyersturnbull/repos", "events_url": "https://api.github.com/users/dmyersturnbull/events{/privacy}", "received_events_url": "https://api.github.com/users/dmyersturnbull/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "A \"fake\"/in-memory system is not going to happen. One would need to implement relational algebra and all the intricacies of a sql storage engine.\r\n\r\nThere are suggestions in the docs for testing: http://docs.peewee-orm.com/en/latest/peewee/database.html#testing-peewee-applications\r\n\r\nThose are the recommended ways. Using a test sqlite database with fixture data being probably one of the more common." ]
"2021-02-06T20:03:56"
"2021-02-07T13:59:39"
"2021-02-07T13:59:38"
NONE
null
I've had a great experience with Peewee so far. Thanks for your work maintaining it! I apologize if this is better suited for StackOverflow -- it seems like more of a feature request, but perhaps it's out of scope or there's an extant solution. My main issue with using Peewee is that it's difficult to abstract away the database for testing. I've tried a few solutions: 1. Have test fixtures instantiate transactions and roll back per test. 2. Have an abstract `QuerySet` containing the needed `SELECT` queries per test, and use dependency injection to swap the database-backed implementations with mocked ones. 3. Write an abstraction of peewee's `Expression`, `ColumnBase`, `Query`, etc., and use dependency injection to swap the databased-backed implementations with ones that navigate through `Model` subclasses by accessing attributes. - (1.) is not a principled solution because it requires a database dependency, and the performance is poor. - (2.) is effective, but requires knowing which queries are needed per test. This exposes part of the implementation (which specific queries are needed), and requires injecting a new query whenever a new query is needed. - (3.) Is what I'm wondering about. See the example below. ```python class Product(peewee.Model): seller = peewee.ForeignKeyField(column_name="seller", field="id", model=Sellers) class Meta: ... class Seller(peewee.Model): name = peewee.CharField() class Meta: ... ``` In the above, a mocked database could just traverse directly a `Product` to the `Seller` via an attribute `seller` (or `_seller`). Then using the new subclass of `Database`, this would immediately work: ```python product = Product(seller=Seller(name="hi")) product.seller.name = "test" ``` I recognize that this is a heavy feature request. I began to write some code, but I'm still not familiar enough with peewee's inner-workings. Unfortunately, I've so far found it quite difficult to write tests (in a moderately large codebase).
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2342/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2342/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2341
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2341/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2341/comments
https://api.github.com/repos/coleifer/peewee/issues/2341/events
https://github.com/coleifer/peewee/issues/2341
802,292,084
MDU6SXNzdWU4MDIyOTIwODQ=
2,341
[Question] Update if existing value is zero
{ "login": "karambaq", "id": 14233969, "node_id": "MDQ6VXNlcjE0MjMzOTY5", "avatar_url": "https://avatars.githubusercontent.com/u/14233969?v=4", "gravatar_id": "", "url": "https://api.github.com/users/karambaq", "html_url": "https://github.com/karambaq", "followers_url": "https://api.github.com/users/karambaq/followers", "following_url": "https://api.github.com/users/karambaq/following{/other_user}", "gists_url": "https://api.github.com/users/karambaq/gists{/gist_id}", "starred_url": "https://api.github.com/users/karambaq/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/karambaq/subscriptions", "organizations_url": "https://api.github.com/users/karambaq/orgs", "repos_url": "https://api.github.com/users/karambaq/repos", "events_url": "https://api.github.com/users/karambaq/events{/privacy}", "received_events_url": "https://api.github.com/users/karambaq/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "First: post questions to stack overflow.\r\n\r\nSecond - this is covered in all the very basic docs. Please consult them:\r\n\r\n```python\r\nwhere((Model.id=id) & (Model.field_name == 0))\r\n```\r\n\r\nhttp://docs.peewee-orm.com/en/latest/peewee/contributing.html#questions" ]
"2021-02-05T16:15:26"
"2021-02-05T16:17:14"
"2021-02-05T16:17:14"
NONE
null
Hey there! I need to update the existing record field if the value of the existing field is equal to zero, how can I do it? I've tried: ``` query = Model.update(field_name=new_value).where(Model.id=id and Model.field_name == 0) query.execute() ``` But it seems like it doesn't work, am I doing something wrong?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2341/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2341/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2340
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2340/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2340/comments
https://api.github.com/repos/coleifer/peewee/issues/2340/events
https://github.com/coleifer/peewee/issues/2340
801,998,123
MDU6SXNzdWU4MDE5OTgxMjM=
2,340
Introspector changes Integer field which is primary key to Serial type (AutoField) in dynamically-generated model from Postgres Database
{ "login": "AlexeyYuNovikov", "id": 45177856, "node_id": "MDQ6VXNlcjQ1MTc3ODU2", "avatar_url": "https://avatars.githubusercontent.com/u/45177856?v=4", "gravatar_id": "", "url": "https://api.github.com/users/AlexeyYuNovikov", "html_url": "https://github.com/AlexeyYuNovikov", "followers_url": "https://api.github.com/users/AlexeyYuNovikov/followers", "following_url": "https://api.github.com/users/AlexeyYuNovikov/following{/other_user}", "gists_url": "https://api.github.com/users/AlexeyYuNovikov/gists{/gist_id}", "starred_url": "https://api.github.com/users/AlexeyYuNovikov/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/AlexeyYuNovikov/subscriptions", "organizations_url": "https://api.github.com/users/AlexeyYuNovikov/orgs", "repos_url": "https://api.github.com/users/AlexeyYuNovikov/repos", "events_url": "https://api.github.com/users/AlexeyYuNovikov/events{/privacy}", "received_events_url": "https://api.github.com/users/AlexeyYuNovikov/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "The reflection stuff is not perfect and uses a heuristic in some cases. If the primary-key is a single integer column, then the reflection assumes it is auto-increment. Similarly, we don't pull the character-length for varchar column types - although this may change in a future version. These are both known limitations." ]
"2021-02-05T09:22:39"
"2021-02-05T13:50:17"
"2021-02-05T13:50:17"
NONE
null
When I'm trying to get dynamically-generated model from existing table in Postgres database, I've found that fields with type Integer become fields with type AutoField in generated model if those fields are primary key. This fields in my DB have unique values which is really key values. I'm getting them from another remote source. Query for creation of the test table ![image](https://user-images.githubusercontent.com/45177856/107012561-3c60a500-67aa-11eb-8f87-494a44c8b5b7.png) Result of the execution of the code for generating model for this table interactively in python console in PyCharm: ```python >>introsp_pub = Introspector.from_database(pg_db, schema='public') >>proba_dynamic_model = introsp_pub.generate_models(table_names=['proba'])['proba'] >>print_model(proba_dynamic_model) proba proba_int AUTO PK proba_txt VARCHAR >>print_table_sql(proba_dynamic_model) CREATE TABLE IF NOT EXISTS "public"."proba" ( "proba_int" SERIAL NOT NULL PRIMARY KEY, "proba_txt" VARCHAR(255) ) ``` This is result afer using pwiz ``` class BaseModel(Model): class Meta: database = database class Proba(BaseModel): proba_int = AutoField() # that is not right!!!! It should be IntegerField() !!! proba_txt = CharField(null=True) class Meta: table_name = 'proba' schema = 'public' ``` And as addition, size of varchar was detected incorrectly. The size of field "proba_txt" is 10 symbols in the database and 255 symbols in the generated model.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2340/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2340/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2339
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2339/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2339/comments
https://api.github.com/repos/coleifer/peewee/issues/2339/events
https://github.com/coleifer/peewee/issues/2339
801,545,143
MDU6SXNzdWU4MDE1NDUxNDM=
2,339
Usage in a replicated Postgres cluster
{ "login": "whisust", "id": 22323709, "node_id": "MDQ6VXNlcjIyMzIzNzA5", "avatar_url": "https://avatars.githubusercontent.com/u/22323709?v=4", "gravatar_id": "", "url": "https://api.github.com/users/whisust", "html_url": "https://github.com/whisust", "followers_url": "https://api.github.com/users/whisust/followers", "following_url": "https://api.github.com/users/whisust/following{/other_user}", "gists_url": "https://api.github.com/users/whisust/gists{/gist_id}", "starred_url": "https://api.github.com/users/whisust/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/whisust/subscriptions", "organizations_url": "https://api.github.com/users/whisust/orgs", "repos_url": "https://api.github.com/users/whisust/repos", "events_url": "https://api.github.com/users/whisust/events{/privacy}", "received_events_url": "https://api.github.com/users/whisust/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Not really, no, it's kind-of up to you how you want to handle that. It's not something that is \"officially\" supported, although there are ways you can do it, as you allude to. I'm not sure what would be making it sporadically fail under-load, either - that seems odd if it works correctly under general circumstances. I don't have enough information to really debug if this even points to the existence of a bug." ]
"2021-02-04T18:47:12"
"2021-02-04T20:54:47"
"2021-02-04T20:54:47"
NONE
null
Hi, I'm using Peewee in prod and recently we set up a read replica. As far as I've seen in the issues and the doc, there is no support to specify a `database` that could be used for read-only queries. I'm using this piece of code for dynamic database binding at run-time since a few months, but under some load (gevent + gunicorn), I get errors linked to Inserts/Updates being done in a Read Only connection if I have a read replica: ```python from playhouse.pool import PooledPostgresqlExtDatabase leader_db = PooledPostgresqlExtDatabase(...) if config.db.read_replica is not None: read_replica = PooledPostgresqlExtDatabase(...) def using_db(db, *models): """Decorator used to specify the db to use, binds the models to the given db before querying""" def using_db_decorator(f): @wraps(f) def wrapper(*args, **kwargs): [m.bind(db) for m in models] try: db.connect(reuse_if_open=True) return f(*args, **kwargs) finally: db.close() return wrapper return using_db_decorator ``` And I'm using the `using_db` as a decorator over my persistence functions: ```python class AuthToken(Model): id = AutoField(primary_key=True) value = CharField(null=False, index=True) created_at = DateTimeField(null=False, default=datetime.now) last_used_at = DateTimeField(null=False, default=datetime.now) @using_db(leader_db, AuthToken) def update(id: int, last_used_at: datetime) -> Optional[AuthToken]: return AuthToken.update(last_used_at=last_used_at).where(AuthToken.id == id).returning(AuthToken).execute()[0] ``` It _can_ trigger this kind of error: ``` ReadOnlySqlTransaction cannot execute UPDATE in a read-only transaction ``` So, Do you have guidance on how to use Peewee with a replicated Postgres system?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2339/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2339/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2338
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2338/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2338/comments
https://api.github.com/repos/coleifer/peewee/issues/2338/events
https://github.com/coleifer/peewee/issues/2338
801,389,785
MDU6SXNzdWU4MDEzODk3ODU=
2,338
Left join doen't work
{ "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
[ "How are you accessing `printfile`? You may need to explicitly specify the target attribute you want your joined `PrintFile` instance to be bound to:\r\n\r\n```python\r\n\r\nquery = (Job.select(Job, Printer, PrintFile)\r\n .where(*conds)\r\n .join(Printer)\r\n .join(PrintFile,\r\n pw.JOIN.LEFT_OUTER,\r\n on=(PrintFile.hash == Job.hash),\r\n attr='printfile')\r\n```\r\n\r\nSee:\r\n\r\n* http://docs.peewee-orm.com/en/latest/peewee/relationships.html#joining-on-arbitrary-fields\r\n* http://docs.peewee-orm.com/en/latest/peewee/relationships.html#selecting-from-multiple-sources", "I read the documentaion more carefull but still doesn't work..\r\nThe join should ceate attribute printfile in Job class like instance of PrintFile.\r\n```\r\n for i in query:\r\n print(\" field job meta>\", i.printfile.meta, i.printfile.preview)\r\n```\r\nThis should be work. I think but....\r\n\r\n```\r\nAttributeError(\"'Job' object has no attribute 'printfile'\") \r\n```\r\n\r\n\r\n", "The join context at that time is `Printer -> PrintFile`. You will want to write the following:\r\n\r\n```python\r\n\r\nquery = (Job.select(Job, Printer, PrintFile)\r\n .where(*conds)\r\n .join(Printer)\r\n .join_from(Job, PrintFile,\r\n pw.JOIN.LEFT_OUTER,\r\n on=(PrintFile.hash == Job.hash),\r\n attr='printfile')\r\n```\r\n\r\nOr alternatively:\r\n\r\n```python\r\nquery = (Job.select(Job, Printer, PrintFile)\r\n .where(*conds)\r\n .join(Printer)\r\n .switch(Job)\r\n .join(PrintFile,\r\n pw.JOIN.LEFT_OUTER,\r\n on=(PrintFile.hash == Job.hash),\r\n attr='printfile')\r\n```", "This is it... thank you for your cooperation." ]
"2021-02-04T15:29:02"
"2021-02-05T08:57:43"
"2021-02-04T15:42:32"
NONE
null
``` query = (Job.select(Job, Printer, PrintFile) .where(*conds) .join(Printer) .join(PrintFile, pw.JOIN.LEFT_OUTER, on=PrintFile.hash == Job.hash) .order_by(-Job.start, Job.printer, -Job.id) .limit(limit) .offset(offset)) ``` The select doen't select PrintFile return only Job and Printer. PrintFile.hash is pw.CharField(max_length=28) and pw.CharField(null=True). Select is created ok. The data doesn't packed into an object. SELECT `t1`.`id`, `t1`.`printer_id`, `t1`.`origin_id`, `t1`.`path`, `t1`.`hash`, `t1`.`user_id`, `t1`.`state`, `t1`.`start`, `t1`.`end`, `t1`.`info_requested`, `t2`.`id`, `t2`.`name`, `t2`.`firmware`, `t2`.`appendix`, `t2`.`created`, `t2`.`location`, `t2`.`sn`, `t2`.`uuid`, `t2`.`registration_code`, `t2`.`printer_type_id`, `t2`.`team_id`, `t2`.`deleted`, `t2`.`sn_status`, `t2`.`settings`, `t3`.`hash`, `t3`.`filename`, `t3`.`uploaded`, `t3`.`size`, `t3`.`team_id`, `t3`.`printer_type_id`, `t3`.`meta`, `t3`.`m_time`, `t3`.`preview`, `t3`.`preview_mimetype` FROM `job` AS `t1` INNER JOIN `printer` AS `t2` ON (`t1`.`printer_id` = `t2`.`id`) LEFT OUTER JOIN `print_file` AS `t3` ON (`t3`.`hash` = `t1`.`hash`) WHERE (`t1`.`printer_id` = 169) ORDER BY `t1`.`start` DESC, `t1`.`printer_id`, `t1`.`id` DESC LIMIT 20 OFFSET 0
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2338/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2338/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2337
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2337/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2337/comments
https://api.github.com/repos/coleifer/peewee/issues/2337/events
https://github.com/coleifer/peewee/issues/2337
800,170,715
MDU6SXNzdWU4MDAxNzA3MTU=
2,337
Different processing of datetime in different databases
{ "login": "ztj1993", "id": 13493380, "node_id": "MDQ6VXNlcjEzNDkzMzgw", "avatar_url": "https://avatars.githubusercontent.com/u/13493380?v=4", "gravatar_id": "", "url": "https://api.github.com/users/ztj1993", "html_url": "https://github.com/ztj1993", "followers_url": "https://api.github.com/users/ztj1993/followers", "following_url": "https://api.github.com/users/ztj1993/following{/other_user}", "gists_url": "https://api.github.com/users/ztj1993/gists{/gist_id}", "starred_url": "https://api.github.com/users/ztj1993/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/ztj1993/subscriptions", "organizations_url": "https://api.github.com/users/ztj1993/orgs", "repos_url": "https://api.github.com/users/ztj1993/repos", "events_url": "https://api.github.com/users/ztj1993/events{/privacy}", "received_events_url": "https://api.github.com/users/ztj1993/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Peewee datetime field exposes properties like `.year` which use a db-specific extract (or equivalent) function. So you can write:\r\n\r\n```python\r\n\r\nquery = (DataModel\r\n .select(DataModel.d_t.year, fn.SUM(DataModel.val))\r\n .where(...)\r\n .group_by(DataModel.d_t.year))\r\n```\r\n\r\nRelevant docs: http://docs.peewee-orm.com/en/latest/peewee/models.html#datetimefield-datefield-and-timefield" ]
"2021-02-03T10:02:36"
"2021-02-03T11:13:13"
"2021-02-03T11:13:13"
NONE
null
I'm writing something related to statistics. I don't want to limit the database. Different databases handle different dates and times. I tested extract_ However, different databases need to be dealt with separately, resulting in the following problems: 1.How to get the database type of the model; 2.If I want to be compatible with all the databases supported by peewee, which date function is better; Here are some code snippets: ``` from peewee import * database_proxy = DatabaseProxy() database = SqliteDatabase(':memory:') class StatisticsDataModel(Model): mid = IntegerField() d_t = DateTimeField() val = IntegerField() class Meta: table_name = 'statistics_data' database = database_proxy def sum_format(mid, start, end): format_d_t = fn.Year(StatisticsDataModel.d_t).alias('format_d_t') query = StatisticsDataModel.select( format_d_t, fn.SUM(StatisticsDataModel.val), ).where( StatisticsDataModel.mid == mid, StatisticsDataModel.d_t >= start, StatisticsDataModel.d_t <= end, ).group_by(format_d_t) return query.execute() ``` ------------ The above is translated by software!
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2337/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2337/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2336
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2336/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2336/comments
https://api.github.com/repos/coleifer/peewee/issues/2336/events
https://github.com/coleifer/peewee/issues/2336
799,031,291
MDU6SXNzdWU3OTkwMzEyOTE=
2,336
ImproperlyConfigured: MySQL connector not installed!
{ "login": "thisnugroho", "id": 49790011, "node_id": "MDQ6VXNlcjQ5NzkwMDEx", "avatar_url": "https://avatars.githubusercontent.com/u/49790011?v=4", "gravatar_id": "", "url": "https://api.github.com/users/thisnugroho", "html_url": "https://github.com/thisnugroho", "followers_url": "https://api.github.com/users/thisnugroho/followers", "following_url": "https://api.github.com/users/thisnugroho/following{/other_user}", "gists_url": "https://api.github.com/users/thisnugroho/gists{/gist_id}", "starred_url": "https://api.github.com/users/thisnugroho/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/thisnugroho/subscriptions", "organizations_url": "https://api.github.com/users/thisnugroho/orgs", "repos_url": "https://api.github.com/users/thisnugroho/repos", "events_url": "https://api.github.com/users/thisnugroho/events{/privacy}", "received_events_url": "https://api.github.com/users/thisnugroho/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "It looks like you're using a virtual environment. You may need to be sure mysql-connector is installed in your venv. Whatever is happening, the problem is that peewee cannot import mysql.connector.\r\n\r\nYou can verify this yourself in your script. Place this at the top:\r\n\r\n```python\r\nimport mysql.connector\r\n```", "> It looks like you're using a virtual environment. You may need to be sure mysql-connector is installed in your venv. Whatever is happening, the problem is that peewee cannot import mysql.connector.\r\n> \r\n> You can verify this yourself in your script. Place this at the top:\r\n> \r\n> ```python\r\n> import mysql.connector\r\n> ```\r\n\r\nthank you so much for your response,\r\nSolved it by doing:\r\n- Install Python wsgi\r\nI started by installing wsgi `sudo apt-get install libapache2-mod-wsgi` but still got the error because i just know it that previous command is installing wsgi for python2, so it's running on python2 that's why my pymysql or other mysql modules that i tried doesn't work, so I run this to fix it `sudo apt-get install libapache2-mod-wsgi-py3` install wsgi for python3\r\n- checking python-path in apache config\r\nadding this line in my app.py.\r\n```python\r\nimport sys\r\nprint(sys.path)\r\n```\r\nand make sure both python paths are equals ( in apache config and from script output )\r\n\r\nand now my apache conf looklike this:\r\n\r\n```\r\npython-path=/home/pg/:/usr/lib/python38.zip:/usr/lib/python3.8:/home/pg/venv/lib/python3.8/site-packages:/home/pg/venv/lib/python3.8/site-packages/gevent-21.1.2-py3.8-linux-x86_64.egg\r\n```\r\n\r\nthat's it, in case someone had the same trouble,thank you~😊" ]
"2021-02-02T07:54:52"
"2021-02-03T06:27:23"
"2021-02-02T14:01:12"
NONE
null
hello, first I wanna thank you guys who made this, it's very helpfull for me who just start learning python, migrating from PHP 😁, I got an error like in this picture below, ![image](https://user-images.githubusercontent.com/49790011/106567870-73964280-656d-11eb-8420-9603d1908171.png) it's said I don't have mysql.connector installed, then i try to import it, but there is no error ![image](https://user-images.githubusercontent.com/49790011/106568309-18188480-656e-11eb-9ba2-3c57a6ed6dd2.png) so I confused about what is happening... can someone explain to me, did i make mistake? I'm trying point number 4 from this answer which is with `playhouse.mysql_ext.MySQLConnectorDatabase` from this: https://github.com/coleifer/peewee/issues/1569#issuecomment-484128525 and the code is looklike this: ```python from peewee import * from playhouse.mysql_ext import MySQLConnectorDatabase dbc = { "db_name":"xxx", "host":"127.0.0.1", "user":"xxx", "password":"xxxx", "port":3306 } db = MySQLConnectorDatabase(dbc['db_name'], user=dbc['user'], password=dbc['password'], host=dbc['host']) ``` I'm using: python:3.8.5 flask:1.1.2 OS: ubuntu 20.04
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2336/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2336/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2335
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2335/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2335/comments
https://api.github.com/repos/coleifer/peewee/issues/2335/events
https://github.com/coleifer/peewee/issues/2335
797,310,452
MDU6SXNzdWU3OTczMTA0NTI=
2,335
distinct() on a ModelCompoundSelectQuery raises an error
{ "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
[ "This is because the convention is different when using UNION and UNION ALL. From which side of the union would you be selecting \"distinct\" from, in your example? You could put distinct on both the left- and right-half of the query, but I think what you want is actually just the regular behavior of UNION.\r\n\r\nSee this answer: https://stackoverflow.com/questions/49925/what-is-the-difference-between-union-and-union-all\r\n\r\nOr https://www.w3schools.com/sql/sql_ref_union.asp" ]
"2021-01-30T02:07:53"
"2021-01-30T22:01:22"
"2021-01-30T22:01:22"
NONE
null
I am using peewee version 3.14.0. A see that `ModelCompoundSelectQuery` does not have a `distinct()` method, and calling it raises the error: ``` AttributeError: 'ModelCompoundSelectQuery' object has no attribute 'distinct' ``` For example: ```python o1 = User.select().where(User.id < 5) o2 = User.select().where(User.id > 1) o3 = o1 | o2 query1 = o1.distinct() # OK query2 = o3.distinct() # Raises error ``` I would expect a compound query to have the same API as any query. If this expected behavior, how should one select distinct rows in a compound query?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2335/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2335/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2334
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2334/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2334/comments
https://api.github.com/repos/coleifer/peewee/issues/2334/events
https://github.com/coleifer/peewee/issues/2334
796,668,028
MDU6SXNzdWU3OTY2NjgwMjg=
2,334
How to set postgres cursor.itersize from peewee?
{ "login": "qacollective", "id": 25289661, "node_id": "MDQ6VXNlcjI1Mjg5NjYx", "avatar_url": "https://avatars.githubusercontent.com/u/25289661?v=4", "gravatar_id": "", "url": "https://api.github.com/users/qacollective", "html_url": "https://github.com/qacollective", "followers_url": "https://api.github.com/users/qacollective/followers", "following_url": "https://api.github.com/users/qacollective/following{/other_user}", "gists_url": "https://api.github.com/users/qacollective/gists{/gist_id}", "starred_url": "https://api.github.com/users/qacollective/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/qacollective/subscriptions", "organizations_url": "https://api.github.com/users/qacollective/orgs", "repos_url": "https://api.github.com/users/qacollective/repos", "events_url": "https://api.github.com/users/qacollective/events{/privacy}", "received_events_url": "https://api.github.com/users/qacollective/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "You can try overriding the `cursor()` method used by Peewee to create the db-api 2 cursor:\r\n\r\n```python\r\n\r\nclass PGDatabase(PostgresqlExtDatabase):\r\n def cursor(self, commit=None):\r\n cursor = super(PGDatabase, self).cursor(commit=commit)\r\n cursor.itersize = 50000\r\n return cursor\r\n\r\ndb = PGDatabase('dbname', ...)\r\n```\r\n\r\nPlease let me know if this does not work, as I didn't test it myself.", "Just writing in to confirm that @coleifer's advice above does work. In my pgAdmin4 console, I'm seeing peewee clients execute statements like:\r\n\r\n FETCH FORWARD 500000 FROM \"dfb9d910-7187-11eb-9f92-ac220bbe7188\"\r\n\r\nThis has helped me to drastically reduce memory consumed by multiple processes retrieving half a billion rows each. :+1: " ]
"2021-01-29T07:59:57"
"2021-02-18T01:29:25"
"2021-01-29T15:36:18"
NONE
null
I am using Peewee with PostgreSQL and server side cursors as per [the documentation](http://docs.peewee-orm.com/en/latest/peewee/playhouse.html#server-side-cursors) and realise that the default row fetch size is 2000. I've verified this by looking at the queries being sent to the server. It works really well, my code is receiving around 200,000 rows per second. However, I am reading hundreds of millions of rows and am aware that the default psycopg2 cursor itersize is 2000 records. I'd like to experiment with changing this default to see if I get a higher throughput of records. Is there a way to set the psycopg2 server side itersize value from Peewee? Can I do this? ``` db = PostgresqlExtDatabase('dbname', user='user', password='pass', host='localhost', port=5432, server_side_cursors=True) db.cursor().itersize = 50000 data = Record.raw("SELECT ...").dicts().iterator(database=db) ``` Looking at the queries sent to the server, I'm still seeing ``` FETCH FORWARD 2000 FROM "64a756a8-61f1-11eb-9154-ac220bbe7188" ``` Any assistance would be greatly appreciated.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2334/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2334/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2333
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2333/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2333/comments
https://api.github.com/repos/coleifer/peewee/issues/2333/events
https://github.com/coleifer/peewee/issues/2333
796,405,043
MDU6SXNzdWU3OTY0MDUwNDM=
2,333
`generate_models` returns empty `dict`
{ "login": "vsheg", "id": 36817377, "node_id": "MDQ6VXNlcjM2ODE3Mzc3", "avatar_url": "https://avatars.githubusercontent.com/u/36817377?v=4", "gravatar_id": "", "url": "https://api.github.com/users/vsheg", "html_url": "https://github.com/vsheg", "followers_url": "https://api.github.com/users/vsheg/followers", "following_url": "https://api.github.com/users/vsheg/following{/other_user}", "gists_url": "https://api.github.com/users/vsheg/gists{/gist_id}", "starred_url": "https://api.github.com/users/vsheg/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/vsheg/subscriptions", "organizations_url": "https://api.github.com/users/vsheg/orgs", "repos_url": "https://api.github.com/users/vsheg/repos", "events_url": "https://api.github.com/users/vsheg/events{/privacy}", "received_events_url": "https://api.github.com/users/vsheg/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I have no idea what might be going on in your setup. This code is covered with unit tests so it is not fundamentally broken:\r\n\r\nhttps://github.com/coleifer/peewee/blob/master/tests/reflection.py#L81\r\n\r\nI'd suggest debugging or providing more information. Possibly some mismatch between what sqlalchemy db connection string you're using and how you're initializing the peewee db?\r\n\r\nPeewee has a `db.get_tables()` method you can use to quickly see if it can detect the tables." ]
"2021-01-28T21:49:11"
"2021-01-28T22:41:10"
"2021-01-28T22:40:01"
NONE
null
Hi, I want to see tables in my predefined database (it was created with `SQLAlchemy` and modified with GUI Beekeeper Studio) 1. When I use `peewee` I get noting: ```python from peewee import PostgresqlDatabase from playhouse.reflection import generate_models db = PostgresqlDatabase('postgres', user=getenv('DB_USER'), password=getenv('DB_PASSWORD'), host='localhost', port=5432 ) print( generate_models(db) ) # {} ``` 2. But when I use `SQLAlchemy` (or GUI Beekeeper Studio), I can see all my tables: ```python from sqlalchemy import create_engine engine = create_engine(getenv('DB_URI')) print( engine.table_names() ) # ['sources', 'channels', 'persons', 'posts'] ``` What's wrong? <details> <summary>Versions</summary> - Python 3.9.1 - pip 21.0 - peewee 3.14.0 - psycopg2-binary 2.8.6 - macOS Big Sur 11.1 </details>
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2333/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2333/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2332
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2332/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2332/comments
https://api.github.com/repos/coleifer/peewee/issues/2332/events
https://github.com/coleifer/peewee/issues/2332
795,943,044
MDU6SXNzdWU3OTU5NDMwNDQ=
2,332
Upsert with Model.save()
{ "login": "tuukkamustonen", "id": 94327, "node_id": "MDQ6VXNlcjk0MzI3", "avatar_url": "https://avatars.githubusercontent.com/u/94327?v=4", "gravatar_id": "", "url": "https://api.github.com/users/tuukkamustonen", "html_url": "https://github.com/tuukkamustonen", "followers_url": "https://api.github.com/users/tuukkamustonen/followers", "following_url": "https://api.github.com/users/tuukkamustonen/following{/other_user}", "gists_url": "https://api.github.com/users/tuukkamustonen/gists{/gist_id}", "starred_url": "https://api.github.com/users/tuukkamustonen/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/tuukkamustonen/subscriptions", "organizations_url": "https://api.github.com/users/tuukkamustonen/orgs", "repos_url": "https://api.github.com/users/tuukkamustonen/repos", "events_url": "https://api.github.com/users/tuukkamustonen/events{/privacy}", "received_events_url": "https://api.github.com/users/tuukkamustonen/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "First, it's not `bulk_insert()` - it's `bulk_create()`. This method takes a list of unsaved models and inserts them into the db, then maps the returned IDs back to the model instances for Postgres. When you add \"on conflict\" into the mix, then you can get the unpredictable scenario of some model pks being returned (for inserted rows) while the already-existing ids are not included. As I said, the best way to handle it is to use `insert_many()` since this does not need to correlate returned ids w/model instances.", "Pardon my mistake, never used that interface.\r\n\r\n> some model pks being returned (for inserted rows) while the already-existing ids are not included\r\n\r\nBut doesn't it make a difference that there would be only single entry here? Only one PK, one row. Either the ID is returned or not. In either case, user can check after the call.\r\n\r\nThat is _assuming_ there are no references and related objects to create on the same go (not sure how that would impact it).", "I think it's just not worth adding -- you can just rely on well-established workflows for create-or-get in the case of a single row.", "http://docs.peewee-orm.com/en/latest/peewee/querying.html#create-or-get", "Get or create ain't suitable here, because it adds one more call to the DB. I'm trying to avoid that.\r\n\r\nThe problem is that violating a constraint generates annoying noise in (at least Postgres) logs:\r\n\r\n```\r\n2021-01-28 12:34:56 UTC:10.97.17.111(45384):stable@stable:[1793]:ERROR: -- duplicate key value violates unique constraint\r\n\"node_unique_client_uuid_and_product\"\r\n2021-01-28 12:34:56 UTC:10.97.17.111(45384):stable@stable:[1793]:DETAIL: Key (client_uuid, product)=(8180774e-e1e8-48fa-b557-98c0e894c00c, foobar) already exists.\r\n```\r\n\r\nWith lots of (unsuccessful) creations, logs get bloated with these. Why do we bump into this so often? Well, we have a system, where components are often clueless about their state in another component, so they send opportunistic calls here and there. I think this is a common problem in distributed systems.\r\n\r\nBeing able to `ON CONFLICT ... IGNORE` would allow to avoid the log entries.", "If you want, you can put something like this:\r\n\r\n```python\r\n\r\nclass BaseModel(Model):\r\n def save_ignore_conflict(self):\r\n pk = self.insert(**self.__data__).on_conflict_ignore().execute()\r\n if pk is not None:\r\n self._pk = pk\r\n return pk is not None\r\n```\r\n\r\nThe problem with this should be evident, though:\r\n\r\n```python\r\n\r\nclass User(BaseModel):\r\n username = TextField(unique=True)\r\n nickname = TextField()\r\n\r\n\r\ndb.create_tables([User])\r\nUser.create(username='u1', nickname='n1')\r\n\r\n# here we will not insert a new row because conflict on username unique.\r\nu2 = User(username='u1', nickname='new-n1')\r\nu2.save_ignore_conflict()\r\n\r\n# the nickname was not updated to \"new-n1\"\r\nu_db = User.get(User.username == 'u1')\r\nprint(u_db.nickname)\r\n```\r\n\r\nThe problem is that you have your \"stateful\" model instance `u2` which has a \"nickname\" value that is not actually stored in the database.", "In this case I will actually do something like:\r\n\r\n```py\r\nclass BaseModel(Model):\r\n def save_ignore_conflict(self):\r\n pk = self.insert(**self.__data__).on_conflict_ignore().execute()\r\n if pk is None:\r\n raise SomeError()\r\n```\r\n\r\nThe HTTP API is behind `POST` method, so I need to return `409 Conflict` in case the entry already exists (instead of `200 OK` if it was `PUT`).\r\n\r\nIt is a bit twisted as I'm telling the database layer to _ignore_ a constraint violation error, yet willing to raise en error to the caller of the same. But, that's just how it needs to go here.\r\n\r\nI'll try that and look closer in the details of `save()`.\r\n\r\nBut yeah, `ON CONFLICT` is not always used for create-or-get, here the idea is to simply create entries _without_ getting them, to simply ignore (and raise) for what was already there.\r\n\r\nThanks for your help and providing this great nifty library, as always." ]
"2021-01-28T12:01:49"
"2021-01-29T06:44:12"
"2021-01-28T14:25:55"
NONE
null
In https://github.com/coleifer/peewee/issues/2275 you explain why `.bulk_insert()` cannot support upsert: > The problem arises w/postgres where the insert cursor returns IDs only for the rows that are created, which can't be mapped back to the actual objects that were inserted. I'm not sure how to interpret that. Could it be done with single-entry: ```py bike = Bike(...) bike.save(on_conflict=OnConflict(...)) ``` Or similar? I guess as a workaround I could maybe: ```py bike.insert(**bike.__data__).on_conflict(...).insert() bike.insert(model_to_dict(bike)).on_conflict(...).insert() ``` (Didn't try, I'm fairly sure what's above is not sufficient...) It's hacky. Docs state that: > If you simply wish to insert data and do not need to create a model instance, you can use `Model.insert()` In this case, I do want to also create the model instance, while being able to use `on_conflict`.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2332/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2332/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2331
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2331/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2331/comments
https://api.github.com/repos/coleifer/peewee/issues/2331/events
https://github.com/coleifer/peewee/issues/2331
792,985,031
MDU6SXNzdWU3OTI5ODUwMzE=
2,331
How to repeat use query?
{ "login": "mouday", "id": 24365682, "node_id": "MDQ6VXNlcjI0MzY1Njgy", "avatar_url": "https://avatars.githubusercontent.com/u/24365682?v=4", "gravatar_id": "", "url": "https://api.github.com/users/mouday", "html_url": "https://github.com/mouday", "followers_url": "https://api.github.com/users/mouday/followers", "following_url": "https://api.github.com/users/mouday/following{/other_user}", "gists_url": "https://api.github.com/users/mouday/gists{/gist_id}", "starred_url": "https://api.github.com/users/mouday/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/mouday/subscriptions", "organizations_url": "https://api.github.com/users/mouday/orgs", "repos_url": "https://api.github.com/users/mouday/repos", "events_url": "https://api.github.com/users/mouday/events{/privacy}", "received_events_url": "https://api.github.com/users/mouday/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "This is a great thing to ask on stackoverflow. The issue tracker is for issues w/peewee, while questions should go on stackoverflow or the #peewee irc on freenode.\r\n\r\n```python\r\n# Did you try this?\r\nquery =UserModel.select()\r\n\r\nif name:\r\n query = query.where(UserModel.name == name)\r\nif age:\r\n query = query.where(UserModel.age == age)\r\n\r\ncount = query.count()\r\nlst = query.dicts()\r\n```", "thank you !" ]
"2021-01-25T03:05:36"
"2021-01-26T02:16:00"
"2021-01-25T14:20:41"
NONE
null
I want to use peewee query like: ```python # query list query =UserModel.select() if name: query = query.where(UserModel.name == name) if age: query = query.where(UserModel.age == age) lst = query.dicts() ``` ```python # query count query =UserModel.select() if name: query = query.where(UserModel.name == name) if age: query = query.where(UserModel.age == age) count = query.count() ``` i found this code is repeat, and i want to combine it ```python query =UserModel.select() if name: query = query.where(UserModel.name == name) if age: query = query.where(UserModel.age == age) ``` what can i do? do you any suggestion?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2331/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2331/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2330
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2330/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2330/comments
https://api.github.com/repos/coleifer/peewee/issues/2330/events
https://github.com/coleifer/peewee/issues/2330
792,417,535
MDU6SXNzdWU3OTI0MTc1MzU=
2,330
How to specify some fields when using the function of replace()?
{ "login": "vba34520", "id": 40198281, "node_id": "MDQ6VXNlcjQwMTk4Mjgx", "avatar_url": "https://avatars.githubusercontent.com/u/40198281?v=4", "gravatar_id": "", "url": "https://api.github.com/users/vba34520", "html_url": "https://github.com/vba34520", "followers_url": "https://api.github.com/users/vba34520/followers", "following_url": "https://api.github.com/users/vba34520/following{/other_user}", "gists_url": "https://api.github.com/users/vba34520/gists{/gist_id}", "starred_url": "https://api.github.com/users/vba34520/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/vba34520/subscriptions", "organizations_url": "https://api.github.com/users/vba34520/orgs", "repos_url": "https://api.github.com/users/vba34520/repos", "events_url": "https://api.github.com/users/vba34520/events{/privacy}", "received_events_url": "https://api.github.com/users/vba34520/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Replace will delete the row and replace it with the data you provide.\r\n\r\nI think what you want is \"update()\"." ]
"2021-01-23T02:50:19"
"2021-01-23T13:07:05"
"2021-01-23T13:07:05"
NONE
null
How to specify some fields when using the function of [`replace()`](http://docs.peewee-orm.com/en/latest/peewee/api.html#Model.replace)? 1. http://docs.peewee-orm.com/en/latest/peewee/api.html#Model.replace 2. http://docs.peewee-orm.com/en/latest/peewee/querying.html#upsert I give a primary key to [`replace()`](http://docs.peewee-orm.com/en/latest/peewee/api.html#Model.replace) and just want to modify one of the field. ```python from peewee import * db = SqliteDatabase('test') class Product(Model): product_id = CharField() product_name = CharField() class Meta: database = db db.connect() db.create_tables([Product]) id = Product(product_id='0001', product_name='apple').save() Product.replace(id=id, product_name='banana').execute() # specify some fields print(id) ``` it will cause peewee.IntegrityError: NOT NULL constraint failed. Looking forward to your reply!
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2330/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2330/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2329
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2329/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2329/comments
https://api.github.com/repos/coleifer/peewee/issues/2329/events
https://github.com/coleifer/peewee/pull/2329
792,161,448
MDExOlB1bGxSZXF1ZXN0NTYwMDkxMjg2
2,329
Allow deferred foreign keys on lazy loading.
{ "login": "conqp", "id": 3766192, "node_id": "MDQ6VXNlcjM3NjYxOTI=", "avatar_url": "https://avatars.githubusercontent.com/u/3766192?v=4", "gravatar_id": "", "url": "https://api.github.com/users/conqp", "html_url": "https://github.com/conqp", "followers_url": "https://api.github.com/users/conqp/followers", "following_url": "https://api.github.com/users/conqp/following{/other_user}", "gists_url": "https://api.github.com/users/conqp/gists{/gist_id}", "starred_url": "https://api.github.com/users/conqp/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/conqp/subscriptions", "organizations_url": "https://api.github.com/users/conqp/orgs", "repos_url": "https://api.github.com/users/conqp/repos", "events_url": "https://api.github.com/users/conqp/events{/privacy}", "received_events_url": "https://api.github.com/users/conqp/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Thanks for this - I've merged an equivalent patch which includes a regression test as well: b34e60154fbb7e2a0aabd271dd55017f1b0af8f0" ]
"2021-01-22T16:58:19"
"2021-01-22T20:22:07"
"2021-01-22T20:22:07"
CONTRIBUTOR
null
Fixes #2328.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2329/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2329/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/2329", "html_url": "https://github.com/coleifer/peewee/pull/2329", "diff_url": "https://github.com/coleifer/peewee/pull/2329.diff", "patch_url": "https://github.com/coleifer/peewee/pull/2329.patch", "merged_at": null }
https://api.github.com/repos/coleifer/peewee/issues/2328
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2328/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2328/comments
https://api.github.com/repos/coleifer/peewee/issues/2328/events
https://github.com/coleifer/peewee/issues/2328
792,161,039
MDU6SXNzdWU3OTIxNjEwMzk=
2,328
Allow deferring of foreign keys when lazy_load is disabled
{ "login": "conqp", "id": 3766192, "node_id": "MDQ6VXNlcjM3NjYxOTI=", "avatar_url": "https://avatars.githubusercontent.com/u/3766192?v=4", "gravatar_id": "", "url": "https://api.github.com/users/conqp", "html_url": "https://github.com/conqp", "followers_url": "https://api.github.com/users/conqp/followers", "following_url": "https://api.github.com/users/conqp/following{/other_user}", "gists_url": "https://api.github.com/users/conqp/gists{/gist_id}", "starred_url": "https://api.github.com/users/conqp/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/conqp/subscriptions", "organizations_url": "https://api.github.com/users/conqp/orgs", "repos_url": "https://api.github.com/users/conqp/repos", "events_url": "https://api.github.com/users/conqp/events{/privacy}", "received_events_url": "https://api.github.com/users/conqp/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Thanks for this - I've merged an equivalent patch which includes a regression test as well: b34e601" ]
"2021-01-22T16:57:42"
"2021-01-22T20:22:16"
"2021-01-22T20:22:16"
CONTRIBUTOR
null
I just encountered a problem when disabling lazy loading on foreign keys. ```python class Referenced(Model): pass class Referencing(Model): ref = ForeignKeyField(Referenced, lazy_load=False) referenced = Referenced() referencing = Referencing() referenging.ref = referenced referenced.save() referencing.save() ``` The above code will result in a `DoesNotExist` exception, because the current `NoQueryForeignKeyAccessor` does not attempt to check `instance.__rel__` I think this should work, since it does not require a query. I will make a pull request, that solves this issue and also gets rid of the `NoQueryForeignKeyAccessor`. This has the beautiful side effect, that changing a `ForeginKeyField`'s `lazy_load` attribute during runtime actually has an effect on the behaviour. Currently, `lazy_load` is only evaluated during `ForeignKeyField.__init__` and then unnecessarily stored on the instance, since subsequent changes to it will not have any effect.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2328/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2328/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2327
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2327/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2327/comments
https://api.github.com/repos/coleifer/peewee/issues/2327/events
https://github.com/coleifer/peewee/issues/2327
791,027,482
MDU6SXNzdWU3OTEwMjc0ODI=
2,327
Add model information to DoesNotExist
{ "login": "conqp", "id": 3766192, "node_id": "MDQ6VXNlcjM3NjYxOTI=", "avatar_url": "https://avatars.githubusercontent.com/u/3766192?v=4", "gravatar_id": "", "url": "https://api.github.com/users/conqp", "html_url": "https://github.com/conqp", "followers_url": "https://api.github.com/users/conqp/followers", "following_url": "https://api.github.com/users/conqp/following{/other_user}", "gists_url": "https://api.github.com/users/conqp/gists{/gist_id}", "starred_url": "https://api.github.com/users/conqp/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/conqp/subscriptions", "organizations_url": "https://api.github.com/users/conqp/orgs", "repos_url": "https://api.github.com/users/conqp/repos", "events_url": "https://api.github.com/users/conqp/events{/privacy}", "received_events_url": "https://api.github.com/users/conqp/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "This seems of somewhat questionable utility as it seems more likely you would want to catch- and handle those exceptions rather than bubbling them all the way up to the web framework to handle generically. I'm going to pass on this for now, but will keep an eye out for other requesters/use-cases for this and re-evaluate then.", "Fair enough. My current code is currently working with separate handlers for each model's exception.\r\nI just see this as a means of reducing duplicated code." ]
"2021-01-21T12:29:30"
"2021-01-21T17:15:45"
"2021-01-21T14:19:41"
CONTRIBUTOR
null
Currently it is hard to extract model context from generic `DoesNotExist` exceptions. It would be nice, if the `DoesNotExist` class would have information about the model, so I can do something like this: ```python from flask import Flask from peewee import DoesNotExist, Model, ModelBase APPLICATION = Flask('myapp') @APPLICATION.errorhandler(DoesNotExist) def no_such_model(exception: DoesNotExist): return (f'Model {exception.model} does not exist.', 404) ``` Currently I have to write such a handlers for every single `Model.DoesNotExist` to have the context of which model was not found.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2327/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2327/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2326
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2326/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2326/comments
https://api.github.com/repos/coleifer/peewee/issues/2326/events
https://github.com/coleifer/peewee/issues/2326
785,380,616
MDU6SXNzdWU3ODUzODA2MTY=
2,326
callback on record insert, delete and update
{ "login": "sugizo", "id": 2418295, "node_id": "MDQ6VXNlcjI0MTgyOTU=", "avatar_url": "https://avatars.githubusercontent.com/u/2418295?v=4", "gravatar_id": "", "url": "https://api.github.com/users/sugizo", "html_url": "https://github.com/sugizo", "followers_url": "https://api.github.com/users/sugizo/followers", "following_url": "https://api.github.com/users/sugizo/following{/other_user}", "gists_url": "https://api.github.com/users/sugizo/gists{/gist_id}", "starred_url": "https://api.github.com/users/sugizo/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/sugizo/subscriptions", "organizations_url": "https://api.github.com/users/sugizo/orgs", "repos_url": "https://api.github.com/users/sugizo/repos", "events_url": "https://api.github.com/users/sugizo/events{/privacy}", "received_events_url": "https://api.github.com/users/sugizo/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "No, this is not really supported by Peewee. Rather, you should probably be implementing your callbacks in your application rather than as part of core peewee (along with your validation, or whatever else you need to do). You can, of course, override the `save()` method and do things in there if you wish:\r\n\r\n```python\r\n\r\nclass User(Model):\r\n first_name = TextField()\r\n last_name = TextField()\r\n full_name = TextField()\r\n\r\n def save(self, force_insert=False, only=None):\r\n self.full_name = self.first_name + ' ' + self.last_name\r\n return super(User, self).save(force_insert, only)\r\n```\r\n\r\nThe above will work when you use the model-level APIs like save() / create() -- but will **not** when you use methods like `insert()` / `update()`.\r\n\r\nAnother way you can handle converting values to database-specific types is by using a custom field class and implementing the `db_value()` / `python_value()` methods. Here are the notes on custom fields: http://docs.peewee-orm.com/en/latest/peewee/models.html#creating-a-custom-field" ]
"2021-01-13T19:25:45"
"2021-01-14T01:33:02"
"2021-01-14T01:33:02"
NONE
null
# Objective before insert table can execute python function to convert data **e.g.** user insert Field intervals in list [2, 2, 1, 2, 2, 2, 1] then base on list above automatically convert and insert into Field intervals_name with [W, W, H, W, W, W, H] on the same table **or** after insert table can send email to user, base on field email stored on another table **e.g.** ``` def after_insert_nav(f, id): query_account_0 = (db.account.product == f['product'] ) rows_account = db(query_account_0).iterselect() for row_account in rows_account: if row_account.investor.notification: mail_to = row_account.investor.email subject = 'NAV %s' % row_account.product.name messages = response.render('templates/mail/nav.html', dict(row = row_account, row_nav = row_nav) ) attachments = '' insert_mail_queue(mail_to, subject, messages, attachments) ``` # question is it possible to use callback on record insert, delete and update in peewee ? **ref** http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#callbacks-on-record-insert-delete-and-update **n.b.** objective above can be achieve in [pydal](https://github.com/web2py/pydal) thanks
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2326/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2326/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2325
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2325/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2325/comments
https://api.github.com/repos/coleifer/peewee/issues/2325/events
https://github.com/coleifer/peewee/issues/2325
785,160,168
MDU6SXNzdWU3ODUxNjAxNjg=
2,325
Sponsor project?
{ "login": "milesgranger", "id": 13764397, "node_id": "MDQ6VXNlcjEzNzY0Mzk3", "avatar_url": "https://avatars.githubusercontent.com/u/13764397?v=4", "gravatar_id": "", "url": "https://api.github.com/users/milesgranger", "html_url": "https://github.com/milesgranger", "followers_url": "https://api.github.com/users/milesgranger/followers", "following_url": "https://api.github.com/users/milesgranger/following{/other_user}", "gists_url": "https://api.github.com/users/milesgranger/gists{/gist_id}", "starred_url": "https://api.github.com/users/milesgranger/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/milesgranger/subscriptions", "organizations_url": "https://api.github.com/users/milesgranger/orgs", "repos_url": "https://api.github.com/users/milesgranger/repos", "events_url": "https://api.github.com/users/milesgranger/events{/privacy}", "received_events_url": "https://api.github.com/users/milesgranger/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Thanks, @milesgranger. I don't seek sponsorships (I'm gratefully employed at this time), but I'm happy to encourage you to donate to a charitable cause.", "Should have clarified this was on behalf of an organization which uses peewee extensively and wanted to \"give back\" a bit. However, I'll take your suggestion you'd rather it go to a charitable cause. 👌" ]
"2021-01-13T14:38:51"
"2021-01-13T17:42:41"
"2021-01-13T16:50:30"
NONE
null
Hi, Just want to say how much I appreciate this project and how tightly maintained it is! :clap: Would you be willing to enable sponsorship for this project and/or for yourself as a developer?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2325/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2325/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2324
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2324/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2324/comments
https://api.github.com/repos/coleifer/peewee/issues/2324/events
https://github.com/coleifer/peewee/issues/2324
781,376,245
MDU6SXNzdWU3ODEzNzYyNDU=
2,324
Many-to-many relations and their entries
{ "login": "thmsklngr", "id": 6360498, "node_id": "MDQ6VXNlcjYzNjA0OTg=", "avatar_url": "https://avatars.githubusercontent.com/u/6360498?v=4", "gravatar_id": "", "url": "https://api.github.com/users/thmsklngr", "html_url": "https://github.com/thmsklngr", "followers_url": "https://api.github.com/users/thmsklngr/followers", "following_url": "https://api.github.com/users/thmsklngr/following{/other_user}", "gists_url": "https://api.github.com/users/thmsklngr/gists{/gist_id}", "starred_url": "https://api.github.com/users/thmsklngr/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/thmsklngr/subscriptions", "organizations_url": "https://api.github.com/users/thmsklngr/orgs", "repos_url": "https://api.github.com/users/thmsklngr/repos", "events_url": "https://api.github.com/users/thmsklngr/events{/privacy}", "received_events_url": "https://api.github.com/users/thmsklngr/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "You would want to use a unique constraint on the two foreign-keys in your intermediate table.\r\n\r\nThen use the `insert into ... on conflict ignore` (or the equivalent) when inserting, to tell the database \"if this insert would violate the unique constraint, then discard it\". Sqlite, MySQL and Postgres all support this:\r\n\r\n* http://docs.peewee-orm.com/en/latest/peewee/api.html#Insert.on_conflict_ignore\r\n* http://docs.peewee-orm.com/en/latest/peewee/querying.html#upsert" ]
"2021-01-07T15:00:47"
"2021-01-07T15:22:05"
"2021-01-07T15:22:05"
NONE
null
Hi, currently I'm switching an application from PonyORM to Peewee, which is somehow a challenge (both ORMs ;) ). One thing which is difficult to me, is the handling of many-to-many relations. I'd like to avoid the ManyToManyField, so I try to implement it with the suggested default solution. Selecting from the intermediate table is easy and also the joins, but I'm struggeling with inserting data to it. I usually treat the data to be unique as set, means, that user1 and his relation to tweet1 is unique and can't be inserted a second time. A relation from user1 to tweet2 is ok. As far as I remember, PonyORM handles this differently and holds combinations as unique (only one user1->tweet1) without any developer intervention. So, how to avoid this with peewee? Or is it necessary to query first the intermediate table if that combination exists or not? Many thanks in advance! Regards, Thomas
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2324/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2324/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2323
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2323/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2323/comments
https://api.github.com/repos/coleifer/peewee/issues/2323/events
https://github.com/coleifer/peewee/issues/2323
780,623,895
MDU6SXNzdWU3ODA2MjM4OTU=
2,323
Query results to json?
{ "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
[ "* http://docs.peewee-orm.com/en/latest/peewee/querying.html#retrieving-row-tuples-dictionaries-namedtuples - specifically `.dicts()`\r\n* http://docs.peewee-orm.com/en/latest/peewee/playhouse.html#shortcuts\r\n* http://docs.peewee-orm.com/en/latest/peewee/playhouse.html#model_to_dict\r\n\r\nPlease post questions to stackoverflow. The issue tracker is for tracking issues." ]
"2021-01-06T15:11:25"
"2021-01-06T15:16:20"
"2021-01-06T15:15:56"
NONE
null
Is there a convenient way to directly convert the query result into json, or into an orjson object?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2323/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2323/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2322
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2322/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2322/comments
https://api.github.com/repos/coleifer/peewee/issues/2322/events
https://github.com/coleifer/peewee/issues/2322
780,557,891
MDU6SXNzdWU3ODA1NTc4OTE=
2,322
Using ESCAPE with Sqlite
{ "login": "mtihlenfield", "id": 15360891, "node_id": "MDQ6VXNlcjE1MzYwODkx", "avatar_url": "https://avatars.githubusercontent.com/u/15360891?v=4", "gravatar_id": "", "url": "https://api.github.com/users/mtihlenfield", "html_url": "https://github.com/mtihlenfield", "followers_url": "https://api.github.com/users/mtihlenfield/followers", "following_url": "https://api.github.com/users/mtihlenfield/following{/other_user}", "gists_url": "https://api.github.com/users/mtihlenfield/gists{/gist_id}", "starred_url": "https://api.github.com/users/mtihlenfield/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/mtihlenfield/subscriptions", "organizations_url": "https://api.github.com/users/mtihlenfield/orgs", "repos_url": "https://api.github.com/users/mtihlenfield/repos", "events_url": "https://api.github.com/users/mtihlenfield/events{/privacy}", "received_events_url": "https://api.github.com/users/mtihlenfield/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Solved this just using `SQL()` like so:\r\n```\r\nSymbol.select().where(SQL(\"name LIKE ? ESCAPE '\\\\'\", (sym_name, )))\r\n```", "Peewee now automatically escapes when you use `.contains()`, `.startswith()` or `.endswith()`. So your example would be:\r\n\r\n```python\r\n\r\nSymbol.select().where(Symbol.name.endswith('_printf'))\r\n```" ]
"2021-01-06T13:37:19"
"2021-01-06T13:51:42"
"2021-01-06T13:50:50"
NONE
null
I'm essentially trying to do the same exact thing as #348, but the solution there recommends using `Clause`, which doesn't seem to exist any longer. There no longer seems to be a way to execute a query like: `select * from symbol where name LIKE "%\_printf" ESCAPE "\"` on an sqlite database without just resorting to `.execute_sql`. Is there a new way to do this, or is `.execute_sql` the way to go?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2322/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2322/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2321
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2321/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2321/comments
https://api.github.com/repos/coleifer/peewee/issues/2321/events
https://github.com/coleifer/peewee/issues/2321
778,067,168
MDU6SXNzdWU3NzgwNjcxNjg=
2,321
Could you tell me how to operating the content of the update only a data?
{ "login": "BarryYBL", "id": 46100874, "node_id": "MDQ6VXNlcjQ2MTAwODc0", "avatar_url": "https://avatars.githubusercontent.com/u/46100874?v=4", "gravatar_id": "", "url": "https://api.github.com/users/BarryYBL", "html_url": "https://github.com/BarryYBL", "followers_url": "https://api.github.com/users/BarryYBL/followers", "following_url": "https://api.github.com/users/BarryYBL/following{/other_user}", "gists_url": "https://api.github.com/users/BarryYBL/gists{/gist_id}", "starred_url": "https://api.github.com/users/BarryYBL/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/BarryYBL/subscriptions", "organizations_url": "https://api.github.com/users/BarryYBL/orgs", "repos_url": "https://api.github.com/users/BarryYBL/repos", "events_url": "https://api.github.com/users/BarryYBL/events{/privacy}", "received_events_url": "https://api.github.com/users/BarryYBL/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "You need to put `.execute()` when you are finished creating your update query.\r\n\r\n```python\r\nUser.update(username='foo').where(id=20).execute()\r\n```\r\n\r\nPlease do not post simple questions on the issue tracker. Use stackoverflow for questions.", "But he has updated my all username key value!\r\nHow do I update only the content with ID =76?\r\n![image](https://user-images.githubusercontent.com/46100874/103543108-f24d8080-4ed8-11eb-9f9d-016fda57edd2.png)\r\n", "You need to write `.where(User.id == 20)`", "Has been solved! \bOK,thankyou!" ]
"2021-01-04T12:40:27"
"2021-01-04T14:38:42"
"2021-01-04T13:30:00"
NONE
null
user.update(username='tudou').where(id='20') There is no effect! He put all the table data keys are updated
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2321/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2321/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2320
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2320/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2320/comments
https://api.github.com/repos/coleifer/peewee/issues/2320/events
https://github.com/coleifer/peewee/issues/2320
777,711,733
MDU6SXNzdWU3Nzc3MTE3MzM=
2,320
KeyError when iterating over query from subquery with CTE
{ "login": "Neirop", "id": 35473102, "node_id": "MDQ6VXNlcjM1NDczMTAy", "avatar_url": "https://avatars.githubusercontent.com/u/35473102?v=4", "gravatar_id": "", "url": "https://api.github.com/users/Neirop", "html_url": "https://github.com/Neirop", "followers_url": "https://api.github.com/users/Neirop/followers", "following_url": "https://api.github.com/users/Neirop/following{/other_user}", "gists_url": "https://api.github.com/users/Neirop/gists{/gist_id}", "starred_url": "https://api.github.com/users/Neirop/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/Neirop/subscriptions", "organizations_url": "https://api.github.com/users/Neirop/orgs", "repos_url": "https://api.github.com/users/Neirop/repos", "events_url": "https://api.github.com/users/Neirop/events{/privacy}", "received_events_url": "https://api.github.com/users/Neirop/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Thanks for the succinct report. This is now resolved." ]
"2021-01-03T20:34:48"
"2021-01-14T16:04:42"
"2021-01-14T16:04:24"
NONE
null
Database: Postgresql 12 Peewee version: 3.14.0 Model: ``` class BaseModel(Model): class Meta: database = database class Channel(BaseModel): channel_id = IntegerField(primary_key=True) channel_name = TextField() class Meta: table_name = 'channel' class UserMessage(BaseModel): message_id = UUIDField(index=True, primary_key=True) channel_id = ForeignKeyField(column_name='channel_id', field='channel_id', model=Channel, on_delete='CASCADE', lazy_load=False, index=False) user_id = IntegerField() timestamp = IntegerField() class Meta: table_name = 'user_message' indexes = ( (('channel_id', 'timestamp'), False), ) ``` Query: ``` UserMessageAlias = UserMessage.alias() subquery = UserMessageAlias \ .select(UserMessageAlias, fn.RANK().over(order_by=[UserMessageAlias.timestamp.desc()]) .alias("rank")) \ .where(UserMessageAlias.channel_id == 26) \ .order_by(UserMessageAlias.timestamp.desc()) \ .limit(200) users = set() for i in range(100): users.add((random.randint(0, 999), random.randint(0, 150))) user_cte = ValuesList(users).cte("user_streamer", columns=["uid", "limit"]) query = UserMessage \ .select(subquery.c.message_id, subquery.c.channel_id, subquery.c.user_id, subquery.c.timestamp, subquery.c.rank) \ .from_(subquery) \ .join(user_cte, on=( (subquery.c.user_id == user_cte.c.uid) & (subquery.c.rank <= user_cte.c.limit))) \ .with_cte(user_cte) for mes in query: print(mes) ``` I got this error: ``` Traceback (most recent call last): File "test.py", line 111, in <module> get_messages() File "test.py", line 100, in test_bug for mes in query: File "/tmp/test/venv/lib/python3.8/site-packages/peewee.py", line 4361, in next self.cursor_wrapper.iterate() File "/tmp/test/venv/lib/python3.8/site-packages/peewee.py", line 4280, in iterate result = self.process_row(row) File "/tmp/test/venv/lib/python3.8/site-packages/peewee.py", line 7548, in process_row instance = objects[key] KeyError: <peewee.ModelSelect object at 0x7fbee0c78d90> ``` But if I use dicts() or tuples(), it works
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2320/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2320/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2319
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2319/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2319/comments
https://api.github.com/repos/coleifer/peewee/issues/2319/events
https://github.com/coleifer/peewee/issues/2319
775,553,513
MDU6SXNzdWU3NzU1NTM1MTM=
2,319
'SqliteDatabase' object has no attribute 'create_index' error when calling create_index() method in Table class
{ "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
[ "Thank you for the report. I've pushed a fix for this.", "Thank you so much!" ]
"2020-12-28T19:29:38"
"2020-12-29T19:07:15"
"2020-12-28T20:20:35"
NONE
null
Operating System: MacOS Python version: 3.9 Peewee version: 3.14.0 It seems the _create_index()_ method in SQLite was deprecated, in turn breaking the _create_index()_ method in the Table class. The method in _dataset.py_ works as a wrapper: ``` def create_index(self, columns, unique=False): self.dataset._database.create_index( self.model_class, columns, unique=unique) ``` I'm trying the following code: db = DataSet('sqlite:///my_database.db') table = db['UsersTable'] table.create_index(['test']) Which returns this error: ``` Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/playhouse/dataset.py", line 210, in create_index self.dataset._database.create_index( AttributeError: 'SqliteDatabase' object has no attribute 'create_index' ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2319/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2319/timeline
null
completed
null
null