url
stringlengths
53
56
repository_url
stringclasses
1 value
labels_url
stringlengths
67
70
comments_url
stringlengths
62
65
events_url
stringlengths
60
63
html_url
stringlengths
41
46
id
int64
450k
1.69B
node_id
stringlengths
18
32
number
int64
1
2.72k
title
stringlengths
1
209
user
dict
labels
list
state
stringclasses
1 value
locked
bool
2 classes
assignee
null
assignees
sequence
milestone
null
comments
sequence
created_at
timestamp[s]
updated_at
timestamp[s]
closed_at
timestamp[s]
author_association
stringclasses
3 values
active_lock_reason
stringclasses
2 values
body
stringlengths
0
104k
reactions
dict
timeline_url
stringlengths
62
65
performed_via_github_app
null
state_reason
stringclasses
2 values
draft
bool
2 classes
pull_request
dict
https://api.github.com/repos/coleifer/peewee/issues/2318
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2318/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2318/comments
https://api.github.com/repos/coleifer/peewee/issues/2318/events
https://github.com/coleifer/peewee/issues/2318
775,076,603
MDU6SXNzdWU3NzUwNzY2MDM=
2,318
DateTimeField should return a datetime instance
{ "login": "yuriescl", "id": 26092447, "node_id": "MDQ6VXNlcjI2MDkyNDQ3", "avatar_url": "https://avatars.githubusercontent.com/u/26092447?v=4", "gravatar_id": "", "url": "https://api.github.com/users/yuriescl", "html_url": "https://github.com/yuriescl", "followers_url": "https://api.github.com/users/yuriescl/followers", "following_url": "https://api.github.com/users/yuriescl/following{/other_user}", "gists_url": "https://api.github.com/users/yuriescl/gists{/gist_id}", "starred_url": "https://api.github.com/users/yuriescl/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/yuriescl/subscriptions", "organizations_url": "https://api.github.com/users/yuriescl/orgs", "repos_url": "https://api.github.com/users/yuriescl/repos", "events_url": "https://api.github.com/users/yuriescl/events{/privacy}", "received_events_url": "https://api.github.com/users/yuriescl/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "You are probably using sqlite and storing the datetimes in some unrecognizable format. If you look at the code you can see what format are supported out of the box. Using these formats is recommended because they allow for lexicographic ordering.\r\n\r\nThis is also explained in detail in the documentation:\r\n\r\nhttp://docs.peewee-orm.com/en/latest/peewee/api.html#DateTimeField", "@coleifer Thanks for the quick response. This is how I'm setting the value:\r\n```\r\nIn [2]: from models import Entry\r\nIn [3]: entry = Entry()\r\nIn [4]: from datetime import datetime, timezone\r\nIn [5]: entry.created_at = datetime.now(timezone.utc)\r\nIn [6]: entry.save()\r\nOut[6]: 1\r\nIn [7]: entry.id\r\nOut[7]: 3\r\nIn [8]: entry = Entry.get(id=3)\r\nIn [9]: entry.created_at\r\nOut[9]: '2020-12-27 20:33:38.411859+00:00'\r\n```\r\n\r\nI'm setting it directly as a `datetime` object and `save()` works, but isn't it inconsistent to allow receiving a `datetime` and returning a `str` later?", "I'm using SQLite, yes.\r\nPeewee converts `datetime` to a string when saving to SQLite, why not convert it back as well?", "Don't store tz info. Just use naive datetimes in utc.", "That worked, thanks.\r\nThere should be an error thrown when trying to save with tzinfo saying it's not supported." ]
2020-12-27T17:25:30
2020-12-27T23:02:00
2020-12-27T18:29:53
NONE
null
`DateTimeField` should return a `datetime` instance when accessed instead of a `str` instance. I imagine one of the main reasons to use a `DateTimeField` instead of `CharField` is to work with the field as a `datetime` instance without worrying about converting to/from `str`. Model: ``` class Entry(Model): created_at = DateTimeField(default=datetime.now(timezone.utc)) ``` Expected behavior: ``` entry = Entry.get() print(type(t.created_at)) <class 'datetime.datetime'> ``` Actual behavior: ``` entry = Entry.get() print(type(t.created_at)) <class 'str'> ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2318/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2318/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2317
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2317/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2317/comments
https://api.github.com/repos/coleifer/peewee/issues/2317/events
https://github.com/coleifer/peewee/issues/2317
773,512,475
MDU6SXNzdWU3NzM1MTI0NzU=
2,317
When a where clause query has any param as None, the query errors at _escape_like_expr
{ "login": "bsodhi", "id": 7951778, "node_id": "MDQ6VXNlcjc5NTE3Nzg=", "avatar_url": "https://avatars.githubusercontent.com/u/7951778?v=4", "gravatar_id": "", "url": "https://api.github.com/users/bsodhi", "html_url": "https://github.com/bsodhi", "followers_url": "https://api.github.com/users/bsodhi/followers", "following_url": "https://api.github.com/users/bsodhi/following{/other_user}", "gists_url": "https://api.github.com/users/bsodhi/gists{/gist_id}", "starred_url": "https://api.github.com/users/bsodhi/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/bsodhi/subscriptions", "organizations_url": "https://api.github.com/users/bsodhi/orgs", "repos_url": "https://api.github.com/users/bsodhi/repos", "events_url": "https://api.github.com/users/bsodhi/events{/privacy}", "received_events_url": "https://api.github.com/users/bsodhi/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Peewee doesn't support \"`<x is None>`\" expressions, for starters. This may have worked in previous versions, but it boils down to concatenating \"%\" with NULL and then performing a LIKE query - which is just gross.\r\n\r\nI suggest that you clean up your code and refactor those expressions. I think I'll mark this wontfix for now." ]
2020-12-23T06:06:52
2020-12-23T21:58:29
2020-12-23T21:57:57
NONE
null
When the params (such the `dept_name, org_id, fname, lname, role` in the following example) are `None`, then the queries like the following (see failing code below) are failing with the error shown next. This code used to work prior to upgrading to 3.14.0 version of peewee. Though it looks a bit ugly, for now I'm thinking to perform the None checks prior to the failing query statement. However, I would like to seek your suggestions on how to fix it properly. Thanks in advance! **Failing code in application:** ``` dept_name, org_id, fname, lname, role = ... query = query.where( ((dept_name is None) | (Person.dept_name.contains(dept_name))) & ((org_id is None) | (Person.org_id.contains(org_id))) & ((role is None) | (User.role == role)) & ((fname is None) | (User.first_name.contains(fname))) & ((lname is None) | (User.last_name.contains(lname))) ).order_by(-User.id) ``` **Error details:** ``` File "/Users/MyUser/.venv/APPS/lib/python3.8/site-packages/peewee.py", line 1190, in _escape_like_expr if s.find('_') >= 0 or s.find('%') >= 0 or s.find('\\') >= 0: AttributeError: 'NoneType' object has no attribute 'find' ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2317/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2317/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2316
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2316/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2316/comments
https://api.github.com/repos/coleifer/peewee/issues/2316/events
https://github.com/coleifer/peewee/issues/2316
771,806,124
MDU6SXNzdWU3NzE4MDYxMjQ=
2,316
How to generate a background management page based on the database
{ "login": "1019157263", "id": 31230637, "node_id": "MDQ6VXNlcjMxMjMwNjM3", "avatar_url": "https://avatars.githubusercontent.com/u/31230637?v=4", "gravatar_id": "", "url": "https://api.github.com/users/1019157263", "html_url": "https://github.com/1019157263", "followers_url": "https://api.github.com/users/1019157263/followers", "following_url": "https://api.github.com/users/1019157263/following{/other_user}", "gists_url": "https://api.github.com/users/1019157263/gists{/gist_id}", "starred_url": "https://api.github.com/users/1019157263/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/1019157263/subscriptions", "organizations_url": "https://api.github.com/users/1019157263/orgs", "repos_url": "https://api.github.com/users/1019157263/repos", "events_url": "https://api.github.com/users/1019157263/events{/privacy}", "received_events_url": "https://api.github.com/users/1019157263/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[]
2020-12-21T03:28:21
2020-12-21T04:05:38
2020-12-21T04:05:38
NONE
null
How to generate a background management page based on the database
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2316/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2316/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2315
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2315/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2315/comments
https://api.github.com/repos/coleifer/peewee/issues/2315/events
https://github.com/coleifer/peewee/issues/2315
767,339,913
MDU6SXNzdWU3NjczMzk5MTM=
2,315
Can't update backref record?
{ "login": "dzpt", "id": 5781080, "node_id": "MDQ6VXNlcjU3ODEwODA=", "avatar_url": "https://avatars.githubusercontent.com/u/5781080?v=4", "gravatar_id": "", "url": "https://api.github.com/users/dzpt", "html_url": "https://github.com/dzpt", "followers_url": "https://api.github.com/users/dzpt/followers", "following_url": "https://api.github.com/users/dzpt/following{/other_user}", "gists_url": "https://api.github.com/users/dzpt/gists{/gist_id}", "starred_url": "https://api.github.com/users/dzpt/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/dzpt/subscriptions", "organizations_url": "https://api.github.com/users/dzpt/orgs", "repos_url": "https://api.github.com/users/dzpt/repos", "events_url": "https://api.github.com/users/dzpt/events{/privacy}", "received_events_url": "https://api.github.com/users/dzpt/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "But if i do this , it works.\r\n```\r\nt = Topic.get_by_id(420426)\r\np = t.post\r\np.content = 'test'\r\np.save(only=[Post.content])\r\n```", "Every time you access `topic.post` using that property you are re-fetching a new instance (and the one you modified is discarded)." ]
2020-12-15T08:53:09
2020-12-15T15:07:33
2020-12-15T15:07:15
NONE
null
``` class Post(BaseModel): content = CharField() topic = ForeignKeyField(Topic, null=True, backref='Posts') class Topic(BaseModel): @property def post(self): return self.posts.get() ``` Then if i do update, it won't work ``` t = Topic.get_by_id(420426) t.post.content = 'test' # post content won't be updated t.post.save(only=[Post.content]) # returns 0 ``` Since `self.posts.get()` returns the the ref record, it supposed to work
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2315/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2315/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2314
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2314/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2314/comments
https://api.github.com/repos/coleifer/peewee/issues/2314/events
https://github.com/coleifer/peewee/issues/2314
764,245,368
MDU6SXNzdWU3NjQyNDUzNjg=
2,314
Model dependencies list with auto-id field and relations
{ "login": "mrkovalchuk", "id": 18255783, "node_id": "MDQ6VXNlcjE4MjU1Nzgz", "avatar_url": "https://avatars.githubusercontent.com/u/18255783?v=4", "gravatar_id": "", "url": "https://api.github.com/users/mrkovalchuk", "html_url": "https://github.com/mrkovalchuk", "followers_url": "https://api.github.com/users/mrkovalchuk/followers", "following_url": "https://api.github.com/users/mrkovalchuk/following{/other_user}", "gists_url": "https://api.github.com/users/mrkovalchuk/gists{/gist_id}", "starred_url": "https://api.github.com/users/mrkovalchuk/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/mrkovalchuk/subscriptions", "organizations_url": "https://api.github.com/users/mrkovalchuk/orgs", "repos_url": "https://api.github.com/users/mrkovalchuk/repos", "events_url": "https://api.github.com/users/mrkovalchuk/events{/privacy}", "received_events_url": "https://api.github.com/users/mrkovalchuk/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "An un-saved model, by definition, will not have any dependencies -- so this does not strike me as a bug." ]
2020-12-12T19:25:57
2020-12-12T19:44:38
2020-12-12T19:44:38
NONE
null
Good day. Model.dependencies method bring some exception for me. Python 3.7 Peewee 3.14.0 Example: ```python from peewee import Model, CharField, ForeignKeyField class A(Model): text = CharField() class B(Model): a = ForeignKeyField(A, backref='bbbs') list(A().dependencies()) ``` Error: ``` Traceback (most recent call last): File "/some-path/some-project/models/tmp.py", line 12, in <module> list(A().dependencies()) File "/some-path/Envs/some-project/lib/python3.7/site-packages/peewee.py", line 6528, in dependencies node = (fk == self.__data__[fk.rel_field.name]) KeyError: 'id' ``` What happens: `A()` object doesn't have a value for ID field. And `Model().__data__` don't return this field. Looks like a bug. Right now, I don't know, what way we should choose for resolve this issue. I'd be happy to create PR with fix, after talk about solution. Thanks.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2314/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2314/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2313
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2313/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2313/comments
https://api.github.com/repos/coleifer/peewee/issues/2313/events
https://github.com/coleifer/peewee/issues/2313
762,383,898
MDU6SXNzdWU3NjIzODM4OTg=
2,313
MySQL ([Errno 111] Connection refused) running inside Docker
{ "login": "sriveros95", "id": 16345170, "node_id": "MDQ6VXNlcjE2MzQ1MTcw", "avatar_url": "https://avatars.githubusercontent.com/u/16345170?v=4", "gravatar_id": "", "url": "https://api.github.com/users/sriveros95", "html_url": "https://github.com/sriveros95", "followers_url": "https://api.github.com/users/sriveros95/followers", "following_url": "https://api.github.com/users/sriveros95/following{/other_user}", "gists_url": "https://api.github.com/users/sriveros95/gists{/gist_id}", "starred_url": "https://api.github.com/users/sriveros95/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/sriveros95/subscriptions", "organizations_url": "https://api.github.com/users/sriveros95/orgs", "repos_url": "https://api.github.com/users/sriveros95/repos", "events_url": "https://api.github.com/users/sriveros95/events{/privacy}", "received_events_url": "https://api.github.com/users/sriveros95/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "The error indicates that you cannot connect to the server, so I fail to see how this is a peewee issue. Probably some docker networking issue on your end.\r\n\r\nCan you connect to the mysql server using the mysql cli on the same host as the code is running? That'd be the best place to start debugging. But yeah -- this does not sound at all like a peewee bug to me. You might also try asking of stackoverflow if you need help debugging your docker configs.", "Yeah tried with just pymysql and still erroring, sorry for the trouble, thank you @coleifer !" ]
2020-12-11T14:18:09
2020-12-11T15:44:37
2020-12-11T15:11:33
NONE
null
Hello and thanks for the amazing work. I'm trying to use Peewee inside Docker but I keep receiving `peewee.OperationalError: (2003, "Can't connect to MySQL server on '127.0.0.1' ([Errno 111] Connection refused)")` DB name, user, port host are all correct (I'm using 127.0.0.1 as host). I don't think the problem is MariaDB's bind-address as I'm able to connect to the DB from other docker containers running GoLang. Any idea? Running Python 3.7.9, peewee 3.14.0
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2313/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2313/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2312
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2312/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2312/comments
https://api.github.com/repos/coleifer/peewee/issues/2312/events
https://github.com/coleifer/peewee/issues/2312
756,682,468
MDU6SXNzdWU3NTY2ODI0Njg=
2,312
Validation in Custom Field Classes? Question - NOT an Issue
{ "login": "jvickroy", "id": 9497294, "node_id": "MDQ6VXNlcjk0OTcyOTQ=", "avatar_url": "https://avatars.githubusercontent.com/u/9497294?v=4", "gravatar_id": "", "url": "https://api.github.com/users/jvickroy", "html_url": "https://github.com/jvickroy", "followers_url": "https://api.github.com/users/jvickroy/followers", "following_url": "https://api.github.com/users/jvickroy/following{/other_user}", "gists_url": "https://api.github.com/users/jvickroy/gists{/gist_id}", "starred_url": "https://api.github.com/users/jvickroy/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/jvickroy/subscriptions", "organizations_url": "https://api.github.com/users/jvickroy/orgs", "repos_url": "https://api.github.com/users/jvickroy/repos", "events_url": "https://api.github.com/users/jvickroy/events{/privacy}", "received_events_url": "https://api.github.com/users/jvickroy/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Putting it in a check constraint means needing to use a database-provided function. Unless you're using sqlite and will always have such a user-defined function available, I'm not sure how you would do this.\r\n\r\nPeewee does not really do validation in the `db_value()` or `python_value()` methods. This should be handled at the layer that is accepting user input, e.g. a web form. The `db_value()` and `python_value()` methods are solely intended for converting between python-native types and whatever the underlying storage engine driver returns. For example, converting a `Path` object to a string instance and vice-versa.\r\n\r\nThe handling of the validation would be better done somewhere up the stack, in my experience, where you will have a better chance of informing the user or caller of the problem and allowing them to fix the issue.", "Thanks for your clarification.\r\nI will always and only be using SQLite for the back-end. These are small projects for my personal use. Based on your feedback, I will move these Path validations to `check` functions managed by `@pre_init` decorators for the tables." ]
2020-12-03T23:54:04
2020-12-04T02:41:06
2020-12-04T01:23:50
NONE
null
A custom field to store/retrieve folder/directory path names is: ``` class FolderField (TextField): """ custom peewee field type for folder (directory) path name """ def db_value (self, name :str) -> Path: """ database string to Python Path converter """ if not ( path := Path (name) ) .is_dir() : raise ValueError ('retrieved {name=} is not an existing folder') return path def python_value (self, path :Path) -> str: """ Python Path to database string converter """ if not path.is_dir() : raise ValueError ('submitted {path=} is not an existing folder') return str (path) ``` which performs validation to ensure the str|Path name refers to an existing directory. Is this bad practice? Would it be better to perform this validation in a `check` function associated with the tables using the `FolderField`? Thanks for this great library!
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2312/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2312/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2311
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2311/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2311/comments
https://api.github.com/repos/coleifer/peewee/issues/2311/events
https://github.com/coleifer/peewee/issues/2311
755,674,184
MDU6SXNzdWU3NTU2NzQxODQ=
2,311
pwiz not importing primary key in model
{ "login": "mudasirmirza", "id": 1905439, "node_id": "MDQ6VXNlcjE5MDU0Mzk=", "avatar_url": "https://avatars.githubusercontent.com/u/1905439?v=4", "gravatar_id": "", "url": "https://api.github.com/users/mudasirmirza", "html_url": "https://github.com/mudasirmirza", "followers_url": "https://api.github.com/users/mudasirmirza/followers", "following_url": "https://api.github.com/users/mudasirmirza/following{/other_user}", "gists_url": "https://api.github.com/users/mudasirmirza/gists{/gist_id}", "starred_url": "https://api.github.com/users/mudasirmirza/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/mudasirmirza/subscriptions", "organizations_url": "https://api.github.com/users/mudasirmirza/orgs", "repos_url": "https://api.github.com/users/mudasirmirza/repos", "events_url": "https://api.github.com/users/mudasirmirza/events{/privacy}", "received_events_url": "https://api.github.com/users/mudasirmirza/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Peewee uses a convention of implicitly assigning an auto-incrementing integer primary key named \"id\" (in the absence of the user explicitly declaring a column as the primary key). Since your table follows this convention, there is no need to explicitly declare the id field." ]
2020-12-02T23:01:55
2020-12-03T01:28:40
2020-12-03T01:28:40
NONE
null
Hey all, I using pwiz to create a model from mysql database and unable to figure out why the primary key column `id` is not being added in the model When I run this command `python -m pwiz -o -e mysql -u root -P myapp -t reviews` I get the below output ``` class UnknownField(object): def __init__(self, *_, **__): pass class BaseModel(Model): class Meta: database = database class Reviews(BaseModel): type = CharField(index=True, null=True) product_owner = IntegerField(constraints=[SQL("DEFAULT 0")], index=True, null=True) product_id = IntegerField(index=True, null=True) userid = CharField(index=True, null=True) rating = CharField(index=True, null=True) name = CharField(null=True) email = CharField(null=True) message = TextField(null=True) status = IntegerField(constraints=[SQL("DEFAULT 1")], null=True) date_time = DateTimeField(constraints=[SQL("DEFAULT CURRENT_TIMESTAMP")], null=True) class Meta: table_name = 'reviews' ``` And when I describe the table with `desc reviews` I get the below output ``` mysql> desc reviews; +---------------+--------------+------+-----+-------------------+----------------+ | Field | Type | Null | Key | Default | Extra | +---------------+--------------+------+-----+-------------------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | type | varchar(255) | YES | MUL | NULL | | | product_owner | int(25) | YES | MUL | 0 | | | product_id | int(11) | YES | MUL | NULL | | | userid | varchar(255) | YES | MUL | NULL | | | rating | varchar(255) | YES | MUL | NULL | | | name | varchar(255) | YES | | NULL | | | email | varchar(255) | YES | | NULL | | | message | longtext | YES | | NULL | | | status | int(11) | YES | | 1 | | | date_time | datetime | YES | | CURRENT_TIMESTAMP | | +---------------+--------------+------+-----+-------------------+----------------+ ``` I can see that there is a primary key named ```id``` which is not being added in the model. How can I get the primary key in the model I can see that [pwiz](https://github.com/coleifer/peewee/blob/da9b941890e9439dd3c20237d51c3dd25b9bb845/pwiz.py#L95) this is where the primary key is being skipped but I don't know why. --- There is another problem here which is not actually related to pwiz, but something that I am running into. This is an old app which was initially written in PHP and I am migrating the API's to python and some column names are reserved words in python like ```type``` and ```list```. What I would like to know that if there is a way in pwiz where I can specify column name substitution.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2311/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2311/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2310
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2310/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2310/comments
https://api.github.com/repos/coleifer/peewee/issues/2310/events
https://github.com/coleifer/peewee/issues/2310
755,177,233
MDU6SXNzdWU3NTUxNzcyMzM=
2,310
Missing timeout on a select() to a crashed MariaDB
{ "login": "davnat", "id": 35222812, "node_id": "MDQ6VXNlcjM1MjIyODEy", "avatar_url": "https://avatars.githubusercontent.com/u/35222812?v=4", "gravatar_id": "", "url": "https://api.github.com/users/davnat", "html_url": "https://github.com/davnat", "followers_url": "https://api.github.com/users/davnat/followers", "following_url": "https://api.github.com/users/davnat/following{/other_user}", "gists_url": "https://api.github.com/users/davnat/gists{/gist_id}", "starred_url": "https://api.github.com/users/davnat/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/davnat/subscriptions", "organizations_url": "https://api.github.com/users/davnat/orgs", "repos_url": "https://api.github.com/users/davnat/repos", "events_url": "https://api.github.com/users/davnat/events{/privacy}", "received_events_url": "https://api.github.com/users/davnat/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Ok, I found that using mysqlclient instead of PyMySQL I can pass a `connect_timeout` option to `MySQLDatabase` that works as expected.", ">I can pass a connect_timeout option to MySQLDatabase that works as expected.\r\n\r\nPerfect." ]
2020-12-02T11:09:33
2020-12-02T14:11:56
2020-12-02T14:11:55
NONE
null
Hi, I'm connecting to a crashed MariaDB 10.5, the log says: ```Dec 01 20:31:29 db2 mysqld[683]: max_threads=102 Dec 01 20:31:29 db2 mysqld[683]: thread_count=3 Dec 01 20:31:29 db2 mysqld[683]: It is possible that mysqld could use up to Dec 01 20:31:29 db2 mysqld[683]: key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = 760299 K bytes of memory Dec 01 20:31:29 db2 mysqld[683]: Hope that's ok; if not, decrease some variables in the equation. Dec 01 20:31:29 db2 mysqld[683]: Thread pointer: 0x7f5d9c5cb308 Dec 01 20:31:29 db2 mysqld[683]: Attempting backtrace. You can use the following information to find out Dec 01 20:31:29 db2 mysqld[683]: where mysqld died. If you see no messages after this, something went Dec 01 20:31:29 db2 mysqld[683]: terribly wrong... Dec 01 20:31:29 db2 mysqld[683]: stack_bottom = 0x7f5da0132d58 thread_stack 0x49000 ``` In this situation, a Model.select() seems to block indefinitely. I'd like to be able to set a timeout, so that my application could point out that something bad happened to the DB. I investigated a bit on this, and found that maybe I could use something like this: https://stackoverflow.com/questions/492519/timeout-on-a-function-call/494273#494273 , but I'm not sure how I could use this approach, maybe a decorator? Or maybe I'm missing something here, I'm definitely not an expert in DB handling. Thank you, cheers
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2310/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2310/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2309
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2309/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2309/comments
https://api.github.com/repos/coleifer/peewee/issues/2309/events
https://github.com/coleifer/peewee/issues/2309
755,017,182
MDU6SXNzdWU3NTUwMTcxODI=
2,309
string_agg / group_concat in a multi-engine environment
{ "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
[ ">But isinstance returns true even when the database is SqliteExtDatabase\r\n\r\nThat doesn't sound correct to me:\r\n\r\n```python\r\nIn [1]: from playhouse.sqlite_ext import SqliteExtDatabase\r\n\r\nIn [2]: from playhouse.postgres_ext import PostgresqlExtDatabase\r\n\r\nIn [3]: d1 = SqliteExtDatabase(':memory:')\r\n\r\nIn [4]: d2 = PostgresqlExtDatabase('peewee_test')\r\n\r\nIn [5]: isinstance(d1, PostgresqlExtDatabase)\r\nOut[5]: False\r\n\r\nIn [6]: isinstance(d2, SqliteExtDatabase)\r\nOut[6]: False\r\n```\r\n\r\nRe: custom aggregate, it seems working fine for me:\r\n\r\n```python\r\[email protected]('string_agg')\r\nclass StringAgg(object):\r\n def __init__(self):\r\n self._data = []\r\n\r\n def step(self, value):\r\n self._data.append(value)\r\n\r\n def finalize(self):\r\n return ', '.join(self._data)\r\n\r\nclass Reg(Model):\r\n key = TextField()\r\n class Meta:\r\n database = db\r\n\r\ndb.create_tables([Reg])\r\n\r\nReg.insert_many([{'key': 'k%02d' % i} for i in range(10)]).execute()\r\n\r\nprint(Reg.select(fn.string_agg(Reg.key)).scalar())\r\n# prints:\r\n#k00, k01, k02, k03, k04, k05, k06, k07, k08, k09\r\n```\r\n\r\nSo, in short, I don't know how to advise you because I cannot reproduce either issue you're describing.", "To follow up, the problem in solution one was that `database` is the initialised database, but my tests are wrapped in a closure. The solution was to use `Model._meta.database` so I had the actual database instance being used. That returned the right answer for `isinstance`.\r\n\r\nAs for the second problem, I'm still not sure why it wasn't working for me, but I ended up not using a string aggregation anyway." ]
2020-12-02T07:18:58
2020-12-05T23:37:54
2020-12-02T14:06:47
NONE
null
I'm running postgres in public, but my unit tests are running sqlite. postgres provides `string_agg(field, 'joiner')` while sqlite (and mysql) has `group_concat(field, 'joiner')` Therefore any queries I write with `fn.GROUP_CONCAT` only work in testing, and any I write with `fn.string_agg` only work in production. To solve this I have tried a number of things, the most sane two are below. ## 1. Check what engine we are using: ``` group_agg = fn.string_agg if isinstance(database, PostgresqlExtDatabase) else fn.GROUP_CONCAT Model.select( group_agg( Model.field, ', ' ) ).where( ... ) ``` But `isinstance` returns true even when the database is `SqliteExtDatabase`. Is there a way to get the database engine reliably? ## 2. Create a custom aggregation function for SQLite This means that `fn.string_agg` exists in both databases. Postgres naturally, and SQLite via the custom function below. ``` @test_db.aggregate('string_agg') class StringAgg(object): def __init__(self): print("Here A") self.string_agg = [] def step(self, value): print("Here B") self.string_agg.append(value) def finalize(self): return ', '.join(self.string_agg) ``` However, this results in an exception: ```peewee.OperationalError: user-defined aggregate's 'step' method raised error``` Even if I wrap the method in a `try` I still get the above exception. ## Questions * Is there a way to get the database engine? * What is wrong with the user-defined aggregate's 'step' method? * Is there a better way to do this? (And once I work it out, is there any interest in a patch so that there's a way to do a string aggregation in all supported engines without knowing/caring what engine it is)
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2309/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2309/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2308
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2308/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2308/comments
https://api.github.com/repos/coleifer/peewee/issues/2308/events
https://github.com/coleifer/peewee/issues/2308
754,284,110
MDU6SXNzdWU3NTQyODQxMTA=
2,308
Error with bulk_update, UUID fields and Postgresql
{ "login": "spl0k", "id": 2974943, "node_id": "MDQ6VXNlcjI5NzQ5NDM=", "avatar_url": "https://avatars.githubusercontent.com/u/2974943?v=4", "gravatar_id": "", "url": "https://api.github.com/users/spl0k", "html_url": "https://github.com/spl0k", "followers_url": "https://api.github.com/users/spl0k/followers", "following_url": "https://api.github.com/users/spl0k/following{/other_user}", "gists_url": "https://api.github.com/users/spl0k/gists{/gist_id}", "starred_url": "https://api.github.com/users/spl0k/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/spl0k/subscriptions", "organizations_url": "https://api.github.com/users/spl0k/orgs", "repos_url": "https://api.github.com/users/spl0k/repos", "events_url": "https://api.github.com/users/spl0k/events{/privacy}", "received_events_url": "https://api.github.com/users/spl0k/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "This came up recently related to array fields: #2292 - I believe this is either the same (or very similar) issue. I can't offer a fix for this at present and suggest the following workarounds:\r\n\r\n* write your Case() explicitly with the appropriate cast\r\n* begin a transaction and issue your updates one-at-a-time - profile this! it very likely may be just as performant", "Ok, I also considered doing single updates, I guess I'll go this way (especially since the app might also be used in SQLite-backed environments) and try to remember to not use such types in `bulk_update`.\r\nThank you for your quick answer and the link to some explanation.", "Yeah, I'm sorry to not be able to offer a fix right now. I think as long as you're using a transaction then updating individually should be fine, however.", "@coleifer Would you add this to the docs please, I have used a lot time to find this issue.\r\nI considered following methods:\r\n1) do not use non-integer primary key\r\n2) change name \"id\"(non-integer primary key) to \"idcard\"\r\nIt's difficult for noobs to know this issue.\r\n\r\nIf a noob saw a note in docs:\r\nNote:\r\nWhen using bulk_update, if there is a DatatypeMismatch error, and you are using postgresql.\r\nYou should use single update.\r\nbecause ...", "@yunlongYoung - those methods you outlined are not quite accurate and are not recommended. Bulk update works perfectly fine with a non-integer primary key (including UUID primary key), as well as any arbitrary pk column name, including \"id\".\r\n\r\nThe bulk-update works well generally across databases and field-types. The issue has to do with updating the UUID value in UUID fields (which seems like an odd thing to do anyways, but that's beside the point...). Postgres doesn't like it when we do something like:\r\n\r\n```sql\r\nSET \"uuid_col\" = (\r\n CASE \"id\" \r\n WHEN 1 THEN <some uuid>\r\n WHEN 2 THEN <some other uuid> \r\n END)\r\n```\r\n\r\nDetails can be read here: https://dba.stackexchange.com/questions/228046/why-do-i-need-to-cast-null-to-column-type/228058#228058\r\n\r\nThe accepted workaround is to simply make individual `UPDATE` queries." ]
2020-12-01T10:49:00
2021-12-09T18:46:14
2020-12-01T14:45:10
NONE
null
Hello Postgres raises an error when using an `UUID` field in a `bulk_update`. The following code ```python import logging import uuid from peewee import Model, UUIDField, IntegerField, PostgresqlDatabase database = PostgresqlDatabase( "test", user="test", password="test", host="192.168.1.84", port=5432 ) class TestModel(Model): pk = UUIDField(primary_key=True, default=uuid.uuid4) uuid = UUIDField(default=uuid.uuid4) class Meta: database = database database.create_tables((TestModel,)) m1, m2 = [TestModel.create() for _ in (1, 2)] m1.uuid = uuid.uuid4() m2.uuid = uuid.uuid4() logger = logging.getLogger("peewee") logger.addHandler(logging.StreamHandler()) logger.setLevel(logging.DEBUG) TestModel.bulk_update((m1, m2), (TestModel.uuid,)) database.drop_tables((TestModel,)) ``` gives this ``` ('UPDATE "testmodel" SET "uuid" = CASE "testmodel"."pk" WHEN %s THEN %s WHEN %s THEN %s END WHERE ("testmodel"."pk" IN (%s, %s))', ['a2fdc19c233b44caa909eff4f878b13f', '3d0a5bfe46ef42d4ab9cc644a15407e5', 'ff76972d6d7d4b9f94ca3c3052d23269', 'ee7ba41da3d741e192512ef0a2071301', 'a2fdc19c233b44caa909eff4f878b13f', 'ff76972d6d7d4b9f94ca3c3052d23269']) Traceback (most recent call last): File "E:\projects\bug\env\lib\site-packages\peewee.py", line 3129, in execute_sql cursor.execute(sql, params or ()) psycopg2.errors.DatatypeMismatch: column "uuid" is of type uuid but expression is of type text LINE 1: UPDATE "testmodel" SET "uuid" = CASE "testmodel"."pk" WHEN '... ^ HINT: You will need to rewrite or cast the expression. During handling of the above exception, another exception occurred: Traceback (most recent call last): File "peewee_bug.py", line 32, in <module> TestModel.bulk_update((m1, m2), (TestModel.uuid,)) File "E:\projects\bug\env\lib\site-packages\peewee.py", line 6411, in bulk_update .where(cls._meta.primary_key.in_(id_list)) File "E:\projects\bug\env\lib\site-packages\peewee.py", line 1898, in inner return method(self, database, *args, **kwargs) File "E:\projects\bug\env\lib\site-packages\peewee.py", line 1969, in execute return self._execute(database) File "E:\projects\bug\env\lib\site-packages\peewee.py", line 2465, in _execute cursor = database.execute(self) File "E:\projects\bug\env\lib\site-packages\peewee.py", line 3142, in execute return self.execute_sql(sql, params, commit=commit) File "E:\projects\bug\env\lib\site-packages\peewee.py", line 3136, in execute_sql self.commit() File "E:\projects\bug\env\lib\site-packages\peewee.py", line 2902, in __exit__ reraise(new_type, new_type(exc_value, *exc_args), traceback) File "E:\projects\bug\env\lib\site-packages\peewee.py", line 185, in reraise raise value.with_traceback(tb) File "E:\projects\bug\env\lib\site-packages\peewee.py", line 3129, in execute_sql cursor.execute(sql, params or ()) peewee.ProgrammingError: column "uuid" is of type uuid but expression is of type text LINE 1: UPDATE "testmodel" SET "uuid" = CASE "testmodel"."pk" WHEN '... ^ HINT: You will need to rewrite or cast the expression. ``` With both PostgreSQL 10 and 11. There is no problem with SQLite, and I haven't tested MySQL/MariaDB. Note that the UUID primary key isn't the problem here, as using another type for the field passed to `bulk_update` yields no error. This is using peewee 3.14.0.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2308/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2308/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2307
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2307/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2307/comments
https://api.github.com/repos/coleifer/peewee/issues/2307/events
https://github.com/coleifer/peewee/issues/2307
753,124,049
MDU6SXNzdWU3NTMxMjQwNDk=
2,307
Does peewee currently support json fields?
{ "login": "zhenzi0322", "id": 34839719, "node_id": "MDQ6VXNlcjM0ODM5NzE5", "avatar_url": "https://avatars.githubusercontent.com/u/34839719?v=4", "gravatar_id": "", "url": "https://api.github.com/users/zhenzi0322", "html_url": "https://github.com/zhenzi0322", "followers_url": "https://api.github.com/users/zhenzi0322/followers", "following_url": "https://api.github.com/users/zhenzi0322/following{/other_user}", "gists_url": "https://api.github.com/users/zhenzi0322/gists{/gist_id}", "starred_url": "https://api.github.com/users/zhenzi0322/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/zhenzi0322/subscriptions", "organizations_url": "https://api.github.com/users/zhenzi0322/orgs", "repos_url": "https://api.github.com/users/zhenzi0322/repos", "events_url": "https://api.github.com/users/zhenzi0322/events{/privacy}", "received_events_url": "https://api.github.com/users/zhenzi0322/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Read the manual\r\n\r\n* http://docs.peewee-orm.com/en/latest/peewee/playhouse.html#pgjson\r\n* http://docs.peewee-orm.com/en/latest/peewee/playhouse.html#mysql-ext\r\n* http://docs.peewee-orm.com/en/latest/peewee/sqlite_ext.html#sqlite-json1" ]
2020-11-30T04:07:59
2020-11-30T12:11:28
2020-11-30T12:11:28
NONE
null
Does peewee currently support json fields?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2307/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2307/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2306
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2306/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2306/comments
https://api.github.com/repos/coleifer/peewee/issues/2306/events
https://github.com/coleifer/peewee/issues/2306
753,056,031
MDU6SXNzdWU3NTMwNTYwMzE=
2,306
Dynamically select Postgres schema
{ "login": "dhnchandan", "id": 1688383, "node_id": "MDQ6VXNlcjE2ODgzODM=", "avatar_url": "https://avatars.githubusercontent.com/u/1688383?v=4", "gravatar_id": "", "url": "https://api.github.com/users/dhnchandan", "html_url": "https://github.com/dhnchandan", "followers_url": "https://api.github.com/users/dhnchandan/followers", "following_url": "https://api.github.com/users/dhnchandan/following{/other_user}", "gists_url": "https://api.github.com/users/dhnchandan/gists{/gist_id}", "starred_url": "https://api.github.com/users/dhnchandan/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/dhnchandan/subscriptions", "organizations_url": "https://api.github.com/users/dhnchandan/orgs", "repos_url": "https://api.github.com/users/dhnchandan/repos", "events_url": "https://api.github.com/users/dhnchandan/events{/privacy}", "received_events_url": "https://api.github.com/users/dhnchandan/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "That data is not stored thread-local and you are advised that it is a bad idea. It's probably better to dynamically generate a model-class with the desired schema than to try swapping it around. Generally this is not going to be well-supported." ]
2020-11-30T00:27:22
2020-11-30T00:45:11
2020-11-30T00:43:05
NONE
null
I am thinking about changing Postgres schema dynamically. Every user will have a schema name in the user database and when he will login his data will be queried from his own named schema. ``` class PublicBaseModel(peewee.Model): class Meta: database = sql_db class BaseModel(peewee.Model): class Meta: database = sql_db schema = 'some_name' # this will be set dynamically according to logged in user ``` I know about dynamically select [database](http://docs.peewee-orm.com/en/latest/peewee/database.html#dynamically-defining-a-database). But is it possible in case of schema?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2306/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2306/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2305
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2305/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2305/comments
https://api.github.com/repos/coleifer/peewee/issues/2305/events
https://github.com/coleifer/peewee/pull/2305
751,507,418
MDExOlB1bGxSZXF1ZXN0NTI4MDA3Mjgz
2,305
Unexpected column names when using fn and .dicts
{ "login": "albatros69", "id": 5740149, "node_id": "MDQ6VXNlcjU3NDAxNDk=", "avatar_url": "https://avatars.githubusercontent.com/u/5740149?v=4", "gravatar_id": "", "url": "https://api.github.com/users/albatros69", "html_url": "https://github.com/albatros69", "followers_url": "https://api.github.com/users/albatros69/followers", "following_url": "https://api.github.com/users/albatros69/following{/other_user}", "gists_url": "https://api.github.com/users/albatros69/gists{/gist_id}", "starred_url": "https://api.github.com/users/albatros69/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/albatros69/subscriptions", "organizations_url": "https://api.github.com/users/albatros69/orgs", "repos_url": "https://api.github.com/users/albatros69/repos", "events_url": "https://api.github.com/users/albatros69/events{/privacy}", "received_events_url": "https://api.github.com/users/albatros69/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I'm OK with adding this, but you should *really* be explicitly aliasing these so that it is not database-dependent and fragile. I believe, furthermore, this example is specific to sqlite - postgres behaves differently (I believe the columns will be named \"min\" and \"max\", at least that's how it behaves on my laptop with postgres 13), and older versions of sqlite behave even differently if I recall correctly.\r\n\r\nI've implemented a similar patch which also adds a test-case and merged.", "Thanks a lot for the answer. You're absolutely right about the aliasing necessity. I discovered this issue as part of some quick&dirty debugging, where i didn't take the time to alias (which I usually do). As it was quite straight forward to correct, I thought it was better to consolidate that in a PR." ]
2020-11-26T11:15:47
2020-11-26T19:37:24
2020-11-26T16:39:51
NONE
null
Consider the following example (I tried to shave it to a minimum): ```python class Test(Model): start_date = DateTimeField(null=True) end_date = DateTimeField(null=True) >>> list(Test.select(fn.MIN(Test.start_date), fn.MAX(Test.end_date)).dicts()) [{'start_date")': datetime.datetime(2020, 9, 11, 9, 56), 'end_date")': datetime.datetime(2020, 11, 29, 16, 0)}] ``` See the extra quote and parenthesis for the column names. One would expect something more like: ```python >>> list(Test.select(fn.MIN(Test.start_date), fn.MAX(Test.end_date)).dicts()) [{'start_date': datetime.datetime(2020, 9, 11, 9, 56), 'end_date': datetime.datetime(2020, 11, 29, 16, 0)}] ``` I'm just proposing here to strip the colum names from the extra right parenthesis.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2305/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2305/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/2305", "html_url": "https://github.com/coleifer/peewee/pull/2305", "diff_url": "https://github.com/coleifer/peewee/pull/2305.diff", "patch_url": "https://github.com/coleifer/peewee/pull/2305.patch", "merged_at": null }
https://api.github.com/repos/coleifer/peewee/issues/2304
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2304/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2304/comments
https://api.github.com/repos/coleifer/peewee/issues/2304/events
https://github.com/coleifer/peewee/issues/2304
751,094,968
MDU6SXNzdWU3NTEwOTQ5Njg=
2,304
Select by foreign key doesn't works as expected
{ "login": "penja", "id": 2717390, "node_id": "MDQ6VXNlcjI3MTczOTA=", "avatar_url": "https://avatars.githubusercontent.com/u/2717390?v=4", "gravatar_id": "", "url": "https://api.github.com/users/penja", "html_url": "https://github.com/penja", "followers_url": "https://api.github.com/users/penja/followers", "following_url": "https://api.github.com/users/penja/following{/other_user}", "gists_url": "https://api.github.com/users/penja/gists{/gist_id}", "starred_url": "https://api.github.com/users/penja/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/penja/subscriptions", "organizations_url": "https://api.github.com/users/penja/orgs", "repos_url": "https://api.github.com/users/penja/repos", "events_url": "https://api.github.com/users/penja/events{/privacy}", "received_events_url": "https://api.github.com/users/penja/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Thanks for the succinct issue report. For now I've made a provisional fix which correctly delegates to the `ForeignKeyField.db_value()` method when a model instance is converted. The fix is not perfect since we still want a way to convert model instances when a converter is present (but is not able to handle the given model instance), so I am catching possible `TypeError` or `ValueError`. I believe this should work in practice and have put some new tests in place.", "Many thanks." ]
2020-11-25T20:20:53
2020-11-25T22:07:34
2020-11-25T21:31:41
NONE
null
Hello. We have the foreign keys with related field that is not equal the primary key to the related model. The following code snippet shows an invalid SELECT query when we use in the select query related model object instead of just identifier. ``` from peewee import * db = SqliteDatabase(':memory:') class Base(Model): class Meta: database = db class A(Base): id = AutoField() a_id = CharField(unique=True, max_length=24) class B(Base): id = AutoField() a = ForeignKeyField(A, field="a_id") db.create_tables([A, B]) a = A.create(a_id="example") b = B.create(a=a) print(B.select().where(B.a == b.a).sql()) print(B.select().where(B.a == b.a_id).sql()) ``` Output: ``` ('SELECT "t1"."id", "t1"."a_id" FROM "b" AS "t1" WHERE ("t1"."a_id" = ?)', [1]) ('SELECT "t1"."id", "t1"."a_id" FROM "b" AS "t1" WHERE ("t1"."a_id" = ?)', ['example']) ``` Thanks
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2304/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2304/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2303
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2303/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2303/comments
https://api.github.com/repos/coleifer/peewee/issues/2303/events
https://github.com/coleifer/peewee/issues/2303
748,720,639
MDU6SXNzdWU3NDg3MjA2Mzk=
2,303
migrator.rename_table doesn't work
{ "login": "tres45", "id": 64437846, "node_id": "MDQ6VXNlcjY0NDM3ODQ2", "avatar_url": "https://avatars.githubusercontent.com/u/64437846?v=4", "gravatar_id": "", "url": "https://api.github.com/users/tres45", "html_url": "https://github.com/tres45", "followers_url": "https://api.github.com/users/tres45/followers", "following_url": "https://api.github.com/users/tres45/following{/other_user}", "gists_url": "https://api.github.com/users/tres45/gists{/gist_id}", "starred_url": "https://api.github.com/users/tres45/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/tres45/subscriptions", "organizations_url": "https://api.github.com/users/tres45/orgs", "repos_url": "https://api.github.com/users/tres45/repos", "events_url": "https://api.github.com/users/tres45/events{/privacy}", "received_events_url": "https://api.github.com/users/tres45/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "This code is covered by unit-tests and I believe it is working properly.\r\n\r\nhttps://github.com/coleifer/peewee/blob/efb41a944e926ea201d120e50d3d864028fbf899/tests/migrations.py#L392-L420" ]
2020-11-23T11:30:24
2020-11-23T13:33:14
2020-11-23T13:33:14
NONE
null
Hi, I use peewee 3.14.0 and can't rename table: peewee.ProgrammingError: relation "test_table_new" does not exist `migrator.rename_table('test_table', 'test_table_new')` ```migration | File "/usr/local/lib/python3.8/site-packages/peewee_migrate/router.py", line 183, in run migration | self.run_one(mname, migrator, fake=fake, force=fake) migration | File "/usr/local/lib/python3.8/site-packages/peewee_migrate/router.py", line 155, in run_one migration | migrator.run() migration | File "/usr/local/lib/python3.8/site-packages/peewee_migrate/migrator.py", line 129, in run migration | op.run() migration | File "/usr/local/lib/python3.8/site-packages/playhouse/migrate.py", line 164, in run migration | self._handle_result(method(*self.args, **kwargs)) migration | File "/usr/local/lib/python3.8/site-packages/playhouse/migrate.py", line 172, in inner migration | return fn(self, *args, **kwargs) migration | File "/usr/local/lib/python3.8/site-packages/playhouse/migrate.py", line 455, in rename_table migration | pk_names = self._primary_key_columns(old_name) migration | File "/usr/local/lib/python3.8/site-packages/playhouse/migrate.py", line 444, in _primary_key_columns migration | cursor = self.database.execute_sql(query % tbl) migration | File "/usr/local/lib/python3.8/site-packages/peewee.py", line 3136, in execute_sql migration | self.commit() migration | File "/usr/local/lib/python3.8/site-packages/peewee.py", line 2902, in __exit__ migration | reraise(new_type, new_type(exc_value, *exc_args), traceback) migration | File "/usr/local/lib/python3.8/site-packages/peewee.py", line 185, in reraise migration | raise value.with_traceback(tb) migration | File "/usr/local/lib/python3.8/site-packages/peewee.py", line 3129, in execute_sql migration | cursor.execute(sql, params or ()) migration | peewee.ProgrammingError: relation "test_table_new" does not exist migration | LINE 5: pg_class.oid = 'test_table_new'::regclass... migration | ^ migration | migration exited with code 1 ``` Pseudo table structure: ``` test_table: id, a_id fk on table_a, b_id fk on table_b, unique index(a_id, b_id) ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2303/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2303/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2302
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2302/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2302/comments
https://api.github.com/repos/coleifer/peewee/issues/2302/events
https://github.com/coleifer/peewee/issues/2302
747,490,030
MDU6SXNzdWU3NDc0OTAwMzA=
2,302
About transaction commit
{ "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 saw the data has been written into the database\r\n\r\nAssuming you mean you were using a separate connection and saw the data before it had been committed by the peewee connection? You might check your read [isolation settings](https://dev.mysql.com/doc/refman/8.0/en/innodb-transaction-isolation-levels.html).\r\n\r\nWhen I run the following script I get the expected output -- the 2nd connection does not see the uncommitted row until I call commit:\r\n\r\n```python\r\nfrom peewee import *\r\n\r\ndb = MySQLDatabase('peewee_test')\r\ndb2 = MySQLDatabase('peewee_test') # 2nd connection\r\n\r\nclass Reg(Model):\r\n key = TextField()\r\n class Meta:\r\n database = db\r\n\r\nclass Reg2(Reg): # model class for accessing table using 2nd conn\r\n class Meta:\r\n database = db2\r\n table_name = 'reg'\r\n\r\n\r\ndb.create_tables([Reg])\r\n\r\nwith db.manual_commit() as tx:\r\n db.begin()\r\n Reg.create(key='k1') # create a row using first conn\r\n\r\n db2.connect() # query table using 2nd conn\r\n print('is \"k1\" visible to conn2 BEFORE commit?')\r\n print('rows in \"reg\" table: %s' % Reg2.select().count())\r\n\r\n db.commit()\r\n print('is \"k1\" visible to conn2 AFTER commit?')\r\n print('rows in \"reg\" table: %s' % Reg2.select().count())\r\n\r\n db2.close()\r\n\r\ndb.drop_tables([Reg])\r\n```\r\n\r\nOutput:\r\n\r\n```\r\nis \"k1\" visible to conn2 BEFORE commit? \r\nrows in \"reg\" table: 0 \r\nis \"k1\" visible to conn2 AFTER commit? \r\nrows in \"reg\" table: 1\r\n```", "@coleifer Thank you very much for your reply. I am sure it is not an isolated problem. After a script has been executed, I entered select * from spead on the mysql command line and found that the data has indeed been written. In order to avoid my MYSQL problem, I tested it with the command line in mysql, and this problem did not appear,Did you execute it on mysql 8.0?", "I will execute these commands in mysql without any problems, but the peewee script will be written into the database without executing the commit.\r\n\r\n```\r\nroot@ubuntu-PowerEdge-R740:~# mysql -h 127.0.0.1 -uroot -pxxxxx\r\nmysql: [Warning] Using a password on the command line interface can be insecure.\r\nWelcome to the MySQL monitor. Commands end with ; or \\g.\r\nYour MySQL connection id is 94\r\nServer version: 8.0.22 MySQL Community Server - GPL\r\n\r\nCopyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.\r\n\r\nOracle is a registered trademark of Oracle Corporation and/or its\r\naffiliates. Other names may be trademarks of their respective\r\nowners.\r\n\r\nType 'help;' or '\\h' for help. Type '\\c' to clear the current input statement.\r\n\r\nmysql> use address;\r\nReading table information for completion of table and column names\r\nYou can turn off this feature to get a quicker startup with -A\r\n\r\nDatabase changed\r\nmysql> set autocommit=0;\r\nQuery OK, 0 rows affected (0.00 sec)\r\n\r\nmysql> begin;\r\nQuery OK, 0 rows affected (0.00 sec)\r\n\r\nmysql> insert into spead values(1,'test1','11','11');\r\nQuery OK, 1 row affected (0.00 sec)\r\n\r\nmysql> select * from spead;\r\n+----+-------+--------+-------+\r\n| id | dis | number | value |\r\n+----+-------+--------+-------+\r\n| 1 | test1 | 11 | 11 |\r\n+----+-------+--------+-------+\r\n1 row in set (0.00 sec)\r\n\r\nmysql> exit;\r\nBye\r\nroot@ubuntu-PowerEdge-R740:~# mysql -h 127.0.0.1 -uroot -pxxxx\r\nmysql: [Warning] Using a password on the command line interface can be insecure.\r\nWelcome to the MySQL monitor. Commands end with ; or \\g.\r\nYour MySQL connection id is 95\r\nServer version: 8.0.22 MySQL Community Server - GPL\r\n\r\nCopyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.\r\n\r\nOracle is a registered trademark of Oracle Corporation and/or its\r\naffiliates. Other names may be trademarks of their respective\r\nowners.\r\n\r\nType 'help;' or '\\h' for help. Type '\\c' to clear the current input statement.\r\n\r\nmysql> use address;\r\nReading table information for completion of table and column names\r\nYou can turn off this feature to get a quicker startup with -A\r\n\r\nDatabase changed\r\nmysql> select * from spead;\r\nEmpty set (0.00 sec)\r\n\r\nmysql> \r\n```\r\n\r\nMy script is just the following lines\r\n\r\n```\r\nfrom peewee import *\r\ndb = MySQLDatabase(\"address\", host=\"127.0.0.1\", port=3306, user=\"root\", passwd=\"xxxx\",autocommit=False,autorollback=True)\r\nclass BaseModel(Model):\r\n class Meta:\r\n database = db\r\n\r\nclass Spead(BaseModel):\r\n dis = CharField(unique=True)\r\n number = IntegerField(null=True)\r\n value = IntegerField(null=True)\r\n\r\n\r\n\r\n```\r\n", "I'm using mariadb 10.4.x. The script I shared clearly shows that the rows are not visible to the 2nd connection before they have been committed. You might try running it and seeing if you get the same output as I do.", "Thanks, my code problem, sorry" ]
2020-11-20T13:27:05
2020-11-20T15:10:12
2020-11-20T14:34:59
NONE
null
I am using mysql 8.0, using the innodb engine, using the version of peewee 3.14, I use peewee transaction commit, without executing commit, I saw the data has been written into the database, but I did not execute db.commit() , I manually execute commands in mysql. If I don’t execute commit, I won’t be able to write. However, there will be inconsistencies when using peewee transaction commit. What is wrong with my code? ``` db =db = MySQLDatabase("address", host="127.0.0.1", port=3306, user="root", passwd="xxx",autocommit=False,autorollback=True) with db.manual_commit(): db.begin() Spead.create(dis="test",number="test",value=333) ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2302/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2302/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2301
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2301/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2301/comments
https://api.github.com/repos/coleifer/peewee/issues/2301/events
https://github.com/coleifer/peewee/pull/2301
745,876,653
MDExOlB1bGxSZXF1ZXN0NTIzMzY1MTcw
2,301
Fix ModelSelect.get() documentation
{ "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
[ "http://docs.peewee-orm.com/en/latest/peewee/api.html#Model.get" ]
2020-11-18T17:48:21
2020-11-18T23:01:39
2020-11-18T23:01:37
CONTRIBUTOR
null
``` In [4]: (Transaction.select().where(Transaction.id == 999999)).get() --------------------------------------------------------------------------- IndexError Traceback (most recent call last) /usr/local/lib/python3.7/site-packages/peewee.py in get(self, database) 6806 try: -> 6807 return clone.execute(database)[0] 6808 except IndexError: /usr/local/lib/python3.7/site-packages/peewee.py in __getitem__(self, item) 4225 self.fill_cache(item if item > 0 else 0) -> 4226 return self.row_cache[item] 4227 else: IndexError: list index out of range During handling of the above exception, another exception occurred: TransactionDoesNotExist Traceback (most recent call last) <ipython-input-4-23b2357d750a> in <module> ----> 1 (Transaction.select().where(Transaction.id == 999999)).get() /usr/local/lib/python3.7/site-packages/peewee.py in get(self, database) 6810 raise self.model.DoesNotExist('%s instance matching query does ' 6811 'not exist:\nSQL: %s\nParams: %s' % -> 6812 (clone.model, sql, params)) 6813 6814 @Node.copy TransactionDoesNotExist: <Model: Transaction> instance matching query does not exist: SQL: SELECT "t1"."id", "t1"."type", "t1"."account_prn", "t1"."cad", "t1"."amount_cents", "t1"."denied_amount_cents", "t1"."event_id", "t1"."network", "t1"."ach_trans_id", "t1"."open_to_buy_cents", "t1"."auth_txn_id", "t1"."activity_type", "t1"."auth_type", "t1"."description", "t1"."mcc", "t1"."passed_fraud_rules", "t1"."fraud_rules_results", "t1"."timestamp_at", "t1"."raw", "t1"."created_at" FROM "transaction" AS "t1" WHERE ("t1"."id" = %s) LIMIT %s OFFSET %s Params: [999999, 1, 0] ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2301/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2301/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/2301", "html_url": "https://github.com/coleifer/peewee/pull/2301", "diff_url": "https://github.com/coleifer/peewee/pull/2301.diff", "patch_url": "https://github.com/coleifer/peewee/pull/2301.patch", "merged_at": null }
https://api.github.com/repos/coleifer/peewee/issues/2300
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2300/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2300/comments
https://api.github.com/repos/coleifer/peewee/issues/2300/events
https://github.com/coleifer/peewee/issues/2300
745,592,118
MDU6SXNzdWU3NDU1OTIxMTg=
2,300
help me BinaryField query
{ "login": "cbingos", "id": 2985444, "node_id": "MDQ6VXNlcjI5ODU0NDQ=", "avatar_url": "https://avatars.githubusercontent.com/u/2985444?v=4", "gravatar_id": "", "url": "https://api.github.com/users/cbingos", "html_url": "https://github.com/cbingos", "followers_url": "https://api.github.com/users/cbingos/followers", "following_url": "https://api.github.com/users/cbingos/following{/other_user}", "gists_url": "https://api.github.com/users/cbingos/gists{/gist_id}", "starred_url": "https://api.github.com/users/cbingos/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/cbingos/subscriptions", "organizations_url": "https://api.github.com/users/cbingos/orgs", "repos_url": "https://api.github.com/users/cbingos/repos", "events_url": "https://api.github.com/users/cbingos/events{/privacy}", "received_events_url": "https://api.github.com/users/cbingos/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Questions belong on stack overflow or you can ask in IRC. This is covered here: http://docs.peewee-orm.com/en/latest/peewee/contributing.html#questions\r\n\r\nI'm not sure what you mean by \"query the gdmc field\", so I'm guessing you mean test it's value?\r\n\r\n```python\r\n\r\n# test if the \"gdmc\" field equals some value.\r\nModelX.select().where(ModelX.sdgdList['gdmc'] == 'some value')\r\n```" ]
2020-11-18T11:50:06
2020-11-18T14:16:04
2020-11-18T14:15:51
NONE
null
Sorry to help here: How to query the “gdmc“ field in List ? **`sdgdList = BinaryJSONField(verbose_name="sdgdList",null=True,)`** **`sdgdList List `** ` [{"x": "1", "cgs": "11.00", "gbxz": "A", "gdmc": "aaa", "zjqk": "0.48", "zzgs": "0.18", "zjqkCss": "red", "gdblockid": "10",}, {"x": "2", "cgs": "10.06", "gbxz": "A", "gdmc": "bbb", "zjqk": "0.32", "zzgs": "0.17", "zjqkCss": "red", "gdblockid": "10", }] ` How to query the “gdmc“ field? ` ModalXXX.sdgdList.contained_by({'gdmc':name}) result None`
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2300/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2300/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2299
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2299/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2299/comments
https://api.github.com/repos/coleifer/peewee/issues/2299/events
https://github.com/coleifer/peewee/issues/2299
742,479,073
MDU6SXNzdWU3NDI0NzkwNzM=
2,299
Parameter validators in fields?
{ "login": "ghost", "id": 10137, "node_id": "MDQ6VXNlcjEwMTM3", "avatar_url": "https://avatars.githubusercontent.com/u/10137?v=4", "gravatar_id": "", "url": "https://api.github.com/users/ghost", "html_url": "https://github.com/ghost", "followers_url": "https://api.github.com/users/ghost/followers", "following_url": "https://api.github.com/users/ghost/following{/other_user}", "gists_url": "https://api.github.com/users/ghost/gists{/gist_id}", "starred_url": "https://api.github.com/users/ghost/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/ghost/subscriptions", "organizations_url": "https://api.github.com/users/ghost/orgs", "repos_url": "https://api.github.com/users/ghost/repos", "events_url": "https://api.github.com/users/ghost/events{/privacy}", "received_events_url": "https://api.github.com/users/ghost/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Going to pass. Presumably you are validating untrusted user input in the input layer, or relying on database constraints for the sql layer." ]
2020-11-13T14:14:30
2020-11-13T14:35:31
2020-11-13T14:35:31
NONE
null
Maybe you should add validators to the fields? To check whether the value added to the database matches the value that is set? Just like Django
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2299/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2299/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2298
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2298/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2298/comments
https://api.github.com/repos/coleifer/peewee/issues/2298/events
https://github.com/coleifer/peewee/issues/2298
740,659,801
MDU6SXNzdWU3NDA2NTk4MDE=
2,298
Support "on_conflict" in bulk_create
{ "login": "albatros69", "id": 5740149, "node_id": "MDQ6VXNlcjU3NDAxNDk=", "avatar_url": "https://avatars.githubusercontent.com/u/5740149?v=4", "gravatar_id": "", "url": "https://api.github.com/users/albatros69", "html_url": "https://github.com/albatros69", "followers_url": "https://api.github.com/users/albatros69/followers", "following_url": "https://api.github.com/users/albatros69/following{/other_user}", "gists_url": "https://api.github.com/users/albatros69/gists{/gist_id}", "starred_url": "https://api.github.com/users/albatros69/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/albatros69/subscriptions", "organizations_url": "https://api.github.com/users/albatros69/orgs", "repos_url": "https://api.github.com/users/albatros69/repos", "events_url": "https://api.github.com/users/albatros69/events{/privacy}", "received_events_url": "https://api.github.com/users/albatros69/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "This came up recently and it is not something I plan to support. See:\r\n\r\nhttps://github.com/coleifer/peewee/issues/2275", "OK, thanks anyway for the answer and support and sorry to have overlooked the existing issue (only looked for the opened ones, I admit).\r\n", "No problem. Like I said in the last issue, the problem is we have no way to map the \"successful\" IDs to the corresponding instances because of how postgres returns the data." ]
2020-11-11T10:37:20
2020-11-11T12:49:06
2020-11-11T12:41:31
NONE
null
Hello, I was trying to take advantage of `bulk_create` (and its batch-support) to insert a lot of new objects. However, unlike `insert_many`, I didn't find a way to specify the `on_conflict` behavior to handle duplicate key errors. Would this be a possible feature to add?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2298/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2298/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2297
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2297/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2297/comments
https://api.github.com/repos/coleifer/peewee/issues/2297/events
https://github.com/coleifer/peewee/issues/2297
740,647,833
MDU6SXNzdWU3NDA2NDc4MzM=
2,297
Select by tuple in values
{ "login": "ak4nv", "id": 73960, "node_id": "MDQ6VXNlcjczOTYw", "avatar_url": "https://avatars.githubusercontent.com/u/73960?v=4", "gravatar_id": "", "url": "https://api.github.com/users/ak4nv", "html_url": "https://github.com/ak4nv", "followers_url": "https://api.github.com/users/ak4nv/followers", "following_url": "https://api.github.com/users/ak4nv/following{/other_user}", "gists_url": "https://api.github.com/users/ak4nv/gists{/gist_id}", "starred_url": "https://api.github.com/users/ak4nv/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/ak4nv/subscriptions", "organizations_url": "https://api.github.com/users/ak4nv/orgs", "repos_url": "https://api.github.com/users/ak4nv/repos", "events_url": "https://api.github.com/users/ak4nv/events{/privacy}", "received_events_url": "https://api.github.com/users/ak4nv/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "See: http://docs.peewee-orm.com/en/latest/peewee/query_operators.html#row-values" ]
2020-11-11T10:19:26
2020-11-11T12:51:04
2020-11-11T12:51:04
NONE
null
Hi there! I haven't found in the docs (maybe missed, sorry). Is it possible to make a query like this: ```sql select * from table where (field1, field2) in (('a', 'b'), ('a', 'c'), ('b', 'c')); ``` Thanks a lot for the greatest library! p.s. Waiting for `asyncio` support out of the box, don't suggest please this [project](https://github.com/05bit/peewee-async) :smile:
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2297/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2297/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2296
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2296/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2296/comments
https://api.github.com/repos/coleifer/peewee/issues/2296/events
https://github.com/coleifer/peewee/issues/2296
740,142,992
MDU6SXNzdWU3NDAxNDI5OTI=
2,296
ImportWarning on PooledPostgresqlExtDatabase
{ "login": "alecgerona", "id": 6406447, "node_id": "MDQ6VXNlcjY0MDY0NDc=", "avatar_url": "https://avatars.githubusercontent.com/u/6406447?v=4", "gravatar_id": "", "url": "https://api.github.com/users/alecgerona", "html_url": "https://github.com/alecgerona", "followers_url": "https://api.github.com/users/alecgerona/followers", "following_url": "https://api.github.com/users/alecgerona/following{/other_user}", "gists_url": "https://api.github.com/users/alecgerona/gists{/gist_id}", "starred_url": "https://api.github.com/users/alecgerona/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/alecgerona/subscriptions", "organizations_url": "https://api.github.com/users/alecgerona/orgs", "repos_url": "https://api.github.com/users/alecgerona/repos", "events_url": "https://api.github.com/users/alecgerona/events{/privacy}", "received_events_url": "https://api.github.com/users/alecgerona/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "That's odd. The line you're referencing, 305, is wrapped in a try/except on `ImportError`, as is the code in `sqlite_ext.py` which attempts to import from the C extension. This doesn't seem to be an error, but rather a warning?\r\n\r\nThe `pyx` file is the cython source file, which gets compiled into a C extension. Is your code trying to read the pyx file, or what is going on there?", "Okay so for more context the error only happens when `pytest` is run since the file in question that imports `PooledPostgresqlExtDatabase ` is imported in `pytest`'s conftest.py. Running it through uvicorn works otherwise. ", "I think this may be the related issue https://github.com/cython/cython/issues/1720 - I'm not sure why this occurs only for 3.14 but not 3.13.3, though?", "Probably? What should be a workaround for this? ", "I don't see anything in the diff that seems relevant to this issue: https://github.com/coleifer/peewee/compare/3.13.3...3.14.0\r\n\r\nAlso, as far as I can tell this isn't a bug, but rather you're receiving a warning during testing. You might try recompiling, or upgrading cython and rebuilding?", "Hmm. This happens on a fresh install/run on a CI though. Still a cython issue? ", "I don't know, honestly. I don't see the issue running the peewee tests https://travis-ci.org/github/coleifer/peewee and I really don't see anything between versions 3.13.3 and 3.14.0 that seems relevant.", "@coleifer found an issue related to this: https://github.com/pytest-dev/pytest/issues/4423 and it seems like it is Cython issue that and he ended up building it with a newer version of Cython to get it working. Might help. ", "@coleifer more info: when I install peewee 3.14.0 from source, it works no problem. So maybe something else happened when 3.14.0 was released in pypi? ", "Final context to those who might stumble upon this: [email protected] works in Python 3.9 and not on 3.8. I haven't tested for lower versions. However, 3.14.1 and 3.14.2 works on both 3.9 and 3.8. I still think that there was something wrong with how 3.14.0 was built. " ]
2020-11-10T18:28:20
2021-03-09T13:00:59
2020-11-10T19:45:17
NONE
null
Hi all so we're using the query builder feature (not the ORM at all) of peewee and it's been great so far. Been using it with fastapi and it's been working great until the 3.14.0 update. Now we're getting the following issue: ``` tests/test_lib/integration/test_pagination.py:3: in <module> from app.user.models import User, UserPagination app/user/models.py:45: in <module> User = __User() lib/table.py:54: in __init__ from app.database import db app/database.py:2: in <module> from lib.database import RetryableDatabase lib/database.py:17: in <module> from playhouse.pool import PooledPostgresqlExtDatabase venv/lib/python3.8/site-packages/playhouse/pool.py:305: in <module> from playhouse.sqlite_ext import SqliteExtDatabase venv/lib/python3.8/site-packages/playhouse/sqlite_ext.py:19: in <module> from playhouse._sqlite_ext import ( playhouse/_sqlite_ext.pyx:1: in init playhouse._sqlite_ext ??? E ImportWarning: can't resolve package from __spec__ or __package__, falling back on __name__ and __path__ ``` Can anyone shed light on this? Rolling back to 3.13 fixes the issue.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2296/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2296/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2295
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2295/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2295/comments
https://api.github.com/repos/coleifer/peewee/issues/2295/events
https://github.com/coleifer/peewee/issues/2295
740,130,116
MDU6SXNzdWU3NDAxMzAxMTY=
2,295
The chain of joins with None fields
{ "login": "andr-04", "id": 2203770, "node_id": "MDQ6VXNlcjIyMDM3NzA=", "avatar_url": "https://avatars.githubusercontent.com/u/2203770?v=4", "gravatar_id": "", "url": "https://api.github.com/users/andr-04", "html_url": "https://github.com/andr-04", "followers_url": "https://api.github.com/users/andr-04/followers", "following_url": "https://api.github.com/users/andr-04/following{/other_user}", "gists_url": "https://api.github.com/users/andr-04/gists{/gist_id}", "starred_url": "https://api.github.com/users/andr-04/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/andr-04/subscriptions", "organizations_url": "https://api.github.com/users/andr-04/orgs", "repos_url": "https://api.github.com/users/andr-04/repos", "events_url": "https://api.github.com/users/andr-04/events{/privacy}", "received_events_url": "https://api.github.com/users/andr-04/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Yes, this was a design decision. If you omit the model how will you traverse the graph?", "I can't continue traversing the graph if some _node_ will have all fields equal to None. But it gives the wrong info that the node (model) _exists_. So, this decision doesn't give benefits.\r\n\r\nFor traversing I use the following helper function:\r\n```\r\ndef get_deep(obj_dic, *keys):\r\n if not keys:\r\n return obj_dic\r\n if obj_dic is None:\r\n return None\r\n if isinstance(obj_dic, dict):\r\n return get_deep(obj_dic.get(keys[0], None), *keys[1:])\r\n else:\r\n return get_deep(getattr(obj_dic, keys[0], None), *keys[1:])\r\n```", "Ok, I follow your point. Not all fields are None, but the chain fields are not None. Anyway, it requires different ways to check the existence of an intermediate and of the last node.\r\n\r\nWhat are your views on adding the last model to the chain as well? It will give the ability to add a helper method that will answer: does the model exists or not? It will also be universal for all nodes in the chain of joins." ]
2020-11-10T18:07:36
2020-11-10T19:09:20
2020-11-10T18:24:27
NONE
null
I've found unexpected behavior due to [this](https://github.com/coleifer/peewee/commit/6bdcd7dc3800654ba034d03b3e7dc01971388e34#r44050928). In case of join to a base model, joined model (but absent; through `LEFT JOIN`) to the field will not be None unless it is the last in the join chain. Models with all fields equal to None is not None originally and requires an additional check for the primary key field to None. It's especially dangerous if you add a new join to the query just, but have to review all places where it is used to change the way of checking to None.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2295/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2295/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2294
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2294/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2294/comments
https://api.github.com/repos/coleifer/peewee/issues/2294/events
https://github.com/coleifer/peewee/issues/2294
739,943,994
MDU6SXNzdWU3Mzk5NDM5OTQ=
2,294
get_id() method returns the foreign key instead of the primary key of model instance
{ "login": "theosotr", "id": 6434138, "node_id": "MDQ6VXNlcjY0MzQxMzg=", "avatar_url": "https://avatars.githubusercontent.com/u/6434138?v=4", "gravatar_id": "", "url": "https://api.github.com/users/theosotr", "html_url": "https://github.com/theosotr", "followers_url": "https://api.github.com/users/theosotr/followers", "following_url": "https://api.github.com/users/theosotr/following{/other_user}", "gists_url": "https://api.github.com/users/theosotr/gists{/gist_id}", "starred_url": "https://api.github.com/users/theosotr/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/theosotr/subscriptions", "organizations_url": "https://api.github.com/users/theosotr/orgs", "repos_url": "https://api.github.com/users/theosotr/repos", "events_url": "https://api.github.com/users/theosotr/events{/privacy}", "received_events_url": "https://api.github.com/users/theosotr/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "You're joining on `B` but you're selecting from `B_al`. The following works just fine for me:\r\n\r\n```python\r\nfrom peewee import *\r\n\r\ndb = SqliteDatabase(':memory:')\r\nclass Base(Model):\r\n class Meta:\r\n database = db\r\n\r\nclass A(Base):\r\n a = IntegerField()\r\n\r\nclass B(Base):\r\n b = IntegerField()\r\n a = ForeignKeyField(A)\r\n\r\ndb.create_tables([A, B])\r\n\r\na1 = A.create(a=1)\r\nb1_1 = B.create(id=100, a=a1, b=11)\r\nb1_2 = B.create(id=101, a=a1, b=12)\r\n\r\nB_a = B.alias()\r\nq = A.select(B_a.id, A.id).join(B_a)\r\nfor row in q:\r\n print(row.get_id(), row.b.id)\r\n\r\n# outputs\r\n# 1 100\r\n# 1 101\r\n```", "I had a typo on my previous text. I meant `join(B_al)` instead of `join(B)`.\r\nThe method `get_id()` still returns the foreign key of the model instance (tested on sqlite).\r\npeewee version: 3.13.3\r\n\r\nI put the corrected query once again here\r\n\r\n```python\r\nB_al = B.alias()\r\nret = A.select(B_al.id, A.id)\r\nret = ret.switch(A).join(B_al).objects()\r\nfor r in ret:\r\n print(r.get_id()) \r\n````\r\n", "You are explicitly asking peewee to patch all attributes onto a single instance by calling `.objects()`, so this is completely expected. Your cursor has 2 values, eached named \"id\" (for A and B). When you call \".objects()\" you're telling peewee to just put all cursor values directly onto a single instance, so you're overwriting A's \"id\" with the \"id\" for B.\r\n\r\nSolutions:\r\n\r\n* do not use .objects()\r\n* alias B's id to some other attribute", "Ah, I see.\r\nThank you!!" ]
2020-11-10T14:12:45
2020-11-10T16:20:30
2020-11-10T14:33:35
NONE
null
I have the following query (simplified for opening the issue) ``` python B_al = B.alias() ret = A.select(B_al.id, A.id) ret = ret.switch(A).join(B).objects() for r in ret: print(r.get_id()) ``` Unfortunately, the method `get_id()` unexpectedly returns the foreign key of the table (i.e., B.id) instead of the primary key (i.e., A.id).
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2294/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2294/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2293
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2293/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2293/comments
https://api.github.com/repos/coleifer/peewee/issues/2293/events
https://github.com/coleifer/peewee/issues/2293
738,220,570
MDU6SXNzdWU3MzgyMjA1NzA=
2,293
positional argument is ignored by `Model.filter()`
{ "login": "Incanus3", "id": 82725, "node_id": "MDQ6VXNlcjgyNzI1", "avatar_url": "https://avatars.githubusercontent.com/u/82725?v=4", "gravatar_id": "", "url": "https://api.github.com/users/Incanus3", "html_url": "https://github.com/Incanus3", "followers_url": "https://api.github.com/users/Incanus3/followers", "following_url": "https://api.github.com/users/Incanus3/following{/other_user}", "gists_url": "https://api.github.com/users/Incanus3/gists{/gist_id}", "starred_url": "https://api.github.com/users/Incanus3/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/Incanus3/subscriptions", "organizations_url": "https://api.github.com/users/Incanus3/orgs", "repos_url": "https://api.github.com/users/Incanus3/repos", "events_url": "https://api.github.com/users/Incanus3/events{/privacy}", "received_events_url": "https://api.github.com/users/Incanus3/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Thanks, this is a bad regression. I've patched this and will make a new release early in the week.", "Scratch that, never put off til tomorrow what you can do today, and all that.\r\n\r\nI've tagged and released a new version 3.14, which contains this fix. Thanks again for the excellent bug report.", "wow, that was fast. thanks for the great work, really appreciate it.", "just tried this after the update and can confirm it works correctly. one question though - the `~DQ(id = orig_bill_item.id)` expression generates this sql fragment: `NOT (\"t1\".\"idriadok\" = %s)`. this makes sense of course, but my question is: is there a way to get `\"t1\".idiriadok\" != %s` using django-style lookups?", "You can do `id__ne=orig_bill_item.id`.", "Oh, cool, thanks. Maybe I missed something, but I couldn't find any documentation for these, so I supposed the lookups will match the ones documented [here](https://docs.djangoproject.com/en/3.1/ref/models/querysets/#field-lookups) and there's no `__ne`." ]
2020-11-07T11:01:59
2020-11-08T09:24:38
2020-11-07T18:28:53
NONE
null
Hi, I've just run into this issue. This is the query building code: ```python BillItem.filter(~DQ(id = orig_bill_item.id), subtable = orig_bill_item.subtable, product_ident = orig_bill_item.product_ident) ``` But when I run this, the first param is completely ignored. This can be easily seen when I run `.sql()` on it - this is what it returns: ```python ['SELECT "t1"."idriadok", "t1"."u_cis", "t1"."id_man", "t1"."blocked_by", "t1"."cena", "t1"."c_karty", "t1"."cidmaster", "t1"."stul", "t1"."kolik", "t1"."pc", "t1"."pr", "t1"."delitel" FROM "food600"."uc_pol" AS "t1" WHERE (("t1"."c_karty" = %s) AND ("t1"."stul" = %s))', [1, '1.1']] ``` When I use `BillItem.select().where()` with explicit expressions built by calling operators on the fields, everything works as expected. I also tried to use `BillItem.id != orig_bill_item.id` as the first param to `.filter()` (don't know if that's supposed to work), but it gets ignored as well. This is a legacy db with terrible column names, here is the `Model` definition: ```python class BillItem(BaseModel): class Meta: schema = 'food600' table_name = 'uc_pol' id = AutoField(column_name = 'idriadok') note = CharField(column_name = 'u_cis', max_length = 7, default = '') id_man = CharField(column_name = 'id_man', max_length = 2, default = '') blocked_by = CharField(column_name = 'blocked_by', max_length = 2, default = '') price_level = CharField(column_name = 'cena', max_length = 1, default = '') product_ident = IntegerField(column_name = 'c_karty') master_kas = IntegerField(column_name = 'cidmaster', default = 0) subtable = DecimalField(column_name = 'stul', max_digits = 6, decimal_places = 1) quantity = DecimalField(column_name = 'kolik', max_digits = 10, decimal_places = 3) unit_price_with_tax = DecimalField(column_name = 'pc', max_digits = 12, decimal_places = 2) tax_rate = DecimalField(column_name = 'pr', max_digits = 5, decimal_places = 3) divisor = DecimalField(column_name = 'delitel', max_digits = 1, decimal_places = 0, default = 0) ``` I'm using peewee version 3.13.3 and python version 3.8.3. Please tell me if I should provide any more info. Also thank you for this amazing library, I simply love it.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2293/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2293/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2292
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2292/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2292/comments
https://api.github.com/repos/coleifer/peewee/issues/2292/events
https://github.com/coleifer/peewee/issues/2292
737,129,149
MDU6SXNzdWU3MzcxMjkxNDk=
2,292
bulk_update throws error when setting array field to None
{ "login": "bdoms", "id": 126839, "node_id": "MDQ6VXNlcjEyNjgzOQ==", "avatar_url": "https://avatars.githubusercontent.com/u/126839?v=4", "gravatar_id": "", "url": "https://api.github.com/users/bdoms", "html_url": "https://github.com/bdoms", "followers_url": "https://api.github.com/users/bdoms/followers", "following_url": "https://api.github.com/users/bdoms/following{/other_user}", "gists_url": "https://api.github.com/users/bdoms/gists{/gist_id}", "starred_url": "https://api.github.com/users/bdoms/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/bdoms/subscriptions", "organizations_url": "https://api.github.com/users/bdoms/orgs", "repos_url": "https://api.github.com/users/bdoms/repos", "events_url": "https://api.github.com/users/bdoms/events{/privacy}", "received_events_url": "https://api.github.com/users/bdoms/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "psycopg2 uses \"%s\" for all parameter placeholders, and automatically converts `None` to `NULL` so I do not believe this is the issue. To be honest this one has me stumped, as entering the following into the postgres shell also fails with the same error:\r\n\r\n```sql\r\nupdate users \r\nset emails = case users.id when 1 then null end\r\nwhere users.id = 1\r\n```\r\n\r\nThe issue is that postgres wants us to explicitly cast the result of `case` expression:\r\n\r\n```sql\r\n-- this works\r\nupdate \"users\" set emails = cast(\r\n case \"users\".\"id\" when 1 then NULL end\r\n as character varying[])\r\nwhere (\"users\".\"id\" in (1));\r\n```\r\n\r\nI think I'm just going to have to mark this for now as wontfix since it works fine when you specify an actual list of names. I won't go so far as to say this is a postgres bug, but it certainly feels like one as it works fine with an actual array of emails and only throws an error if you pass an (equally-valid) NULL value.\r\n\r\nThanks for the helpful report. I will update the issue if anything changes.", "Thanks for the insight. You're right. It appears to be known behavior for Postgres, see for example: https://dba.stackexchange.com/a/228058\r\n\r\nI still think it's something where Peewee or Postgres or maybe even psycopg2 could improve the user experience. I'm just not sure where the best place to ask for an improvement is." ]
2020-11-05T17:31:55
2020-11-06T16:00:42
2020-11-06T02:58:03
NONE
null
Here's the situation: I have a model that has an array field where `null=True`. Something like this: ```python class User(Model): emails = ArrayField(CharField, null=True) ``` That's all good, but when I do this: ```python user = User.create(emails=None) # or get it from a query, etc. User.bulk_update([user], fields=['emails']) ``` It throws this error: ``` Traceback (most recent call last): File ".../peewee.py", line 3099, in execute_sql cursor.execute(sql, params or ()) psycopg2.errors.DatatypeMismatch: column "emails" is of type character varying[] but expression is of type text LINE 1: ... "emails" = CASE "cont... ^ HINT: You will need to rewrite or cast the expression. ``` I investigated and found the SQL it generates looks like this: ``` ('UPDATE "user" SET "emails" = CASE "user"."id" WHEN %s THEN %s END WHERE ("user"."id" IN (%s))', [123, None, 123]) ``` I believe the issue is that the Python "None" is being cast as a string in the generated SQL via the "%s" instead of properly being converted to NULL. Luckily the amount of rows I'm dealing with in this particular case is small so I can work around this by just saving each individually, but I can imagine other situations where it could really impact performance.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2292/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2292/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2291
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2291/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2291/comments
https://api.github.com/repos/coleifer/peewee/issues/2291/events
https://github.com/coleifer/peewee/issues/2291
736,817,549
MDU6SXNzdWU3MzY4MTc1NDk=
2,291
'Expression' object has no attribute 'seconds'
{ "login": "ahvahsky2008", "id": 8035828, "node_id": "MDQ6VXNlcjgwMzU4Mjg=", "avatar_url": "https://avatars.githubusercontent.com/u/8035828?v=4", "gravatar_id": "", "url": "https://api.github.com/users/ahvahsky2008", "html_url": "https://github.com/ahvahsky2008", "followers_url": "https://api.github.com/users/ahvahsky2008/followers", "following_url": "https://api.github.com/users/ahvahsky2008/following{/other_user}", "gists_url": "https://api.github.com/users/ahvahsky2008/gists{/gist_id}", "starred_url": "https://api.github.com/users/ahvahsky2008/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/ahvahsky2008/subscriptions", "organizations_url": "https://api.github.com/users/ahvahsky2008/orgs", "repos_url": "https://api.github.com/users/ahvahsky2008/repos", "events_url": "https://api.github.com/users/ahvahsky2008/events{/privacy}", "received_events_url": "https://api.github.com/users/ahvahsky2008/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "You're overthinking this. It is quite simple:\r\n\r\n```python\r\n\r\ncutoff = datetime.datetime.now() - datetime.timedelta(minutes=60)\r\nquery = Zayavki.select().where(Zayavki.req_data >= cutoff)\r\n```\r\n\r\nAs to why this doesn't work, you cannot access the \".seconds\" attribute on a peewee expression, as the error clearly states. This is because it's not a `timedelta` object, but rather a representation of a SQL expression." ]
2020-11-05T10:40:01
2020-11-05T14:29:44
2020-11-05T14:29:44
NONE
null
I try get data with creation time more 60 mins. But its show error ``` hour = datetime.datetime.now() - datetime.timedelta(minutes = 60) zayavkis =Zayavki.select().where(Zayavki.req_data-hour).seconds/60>60) ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2291/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2291/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2290
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2290/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2290/comments
https://api.github.com/repos/coleifer/peewee/issues/2290/events
https://github.com/coleifer/peewee/issues/2290
736,114,651
MDU6SXNzdWU3MzYxMTQ2NTE=
2,290
Peewee constantly reruns select count in PyCharm REPL
{ "login": "dominusmi", "id": 11195159, "node_id": "MDQ6VXNlcjExMTk1MTU5", "avatar_url": "https://avatars.githubusercontent.com/u/11195159?v=4", "gravatar_id": "", "url": "https://api.github.com/users/dominusmi", "html_url": "https://github.com/dominusmi", "followers_url": "https://api.github.com/users/dominusmi/followers", "following_url": "https://api.github.com/users/dominusmi/following{/other_user}", "gists_url": "https://api.github.com/users/dominusmi/gists{/gist_id}", "starred_url": "https://api.github.com/users/dominusmi/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/dominusmi/subscriptions", "organizations_url": "https://api.github.com/users/dominusmi/orgs", "repos_url": "https://api.github.com/users/dominusmi/repos", "events_url": "https://api.github.com/users/dominusmi/events{/privacy}", "received_events_url": "https://api.github.com/users/dominusmi/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Pycharm is probably calling all kinds of stuff. Specifically it's probably evaluating the truthiness or len(). Definitely not a peewee bug. I'd take it up with the pycharm folks.\r\n\r\nUsing a regular python repl or ipython has no problems at all.", "Alright thanks for the feedback!" ]
2020-11-04T13:27:33
2020-11-04T13:44:14
2020-11-04T13:37:28
NONE
null
In the pycharm REPL, once a database model is imported, it will keep running a select count after each instruction execution. Putting the logger on debug mode, this message appears for each model loaded: ```DEBUG::peewee.py:3087::('SELECT COUNT(1) FROM (SELECT 1 FROM `Model` AS `t1`) AS `_wrapped`', [])``` The problem is that my model are very large database, and so the REPL becomes unuseable since after each instruction it stays stuck for a few seconds. Unfortunately the line number in the log line seems to be wrong (no idea why) but it points to a line with no logging: https://github.com/coleifer/peewee/blob/92494cd9ed01b12826b2fddb25cde221ea34f155/peewee.py#L3087 However, since the only line with `logger.debug` in `peewee.py` is line 3117 (inside `execute_sql`), I would imagine it's an implicit call leading there. I'm not sure if this is a bug or if it's a required decision, but I wouldn't really understand the necessity in the latter case. Running peewee version `3.13.3` The same issue doesn't seem to happen in ipython opened from terminal. Do you have any idea / help for what's going on?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2290/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2290/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2289
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2289/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2289/comments
https://api.github.com/repos/coleifer/peewee/issues/2289/events
https://github.com/coleifer/peewee/issues/2289
733,088,950
MDU6SXNzdWU3MzMwODg5NTA=
2,289
Using CTE in a UNION ALL query
{ "login": "8BitMate", "id": 14078867, "node_id": "MDQ6VXNlcjE0MDc4ODY3", "avatar_url": "https://avatars.githubusercontent.com/u/14078867?v=4", "gravatar_id": "", "url": "https://api.github.com/users/8BitMate", "html_url": "https://github.com/8BitMate", "followers_url": "https://api.github.com/users/8BitMate/followers", "following_url": "https://api.github.com/users/8BitMate/following{/other_user}", "gists_url": "https://api.github.com/users/8BitMate/gists{/gist_id}", "starred_url": "https://api.github.com/users/8BitMate/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/8BitMate/subscriptions", "organizations_url": "https://api.github.com/users/8BitMate/orgs", "repos_url": "https://api.github.com/users/8BitMate/repos", "events_url": "https://api.github.com/users/8BitMate/events{/privacy}", "received_events_url": "https://api.github.com/users/8BitMate/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Can you share the SQL for the query you're trying to write? It might be easier for me to help you work backwards from that.", "Sure, I'm trying to write something like this:\r\n\r\n```SQL\r\nWITH vehicle_insert (id) AS (\r\n INSERT INTO vehicle (uid, type_id, provider_id)\r\n VALUES ('Some:ID', 2, 3)\r\n ON CONFLICT DO NOTHING RETURNING id\r\n)\r\nSELECT id\r\nFROM vehicle\r\nWHERE ((uid = 'Some:ID') AND (provider_id = 3))\r\nUNION ALL\r\nSELECT id\r\nFROM vehicle_insert\r\n```\r\nI have a unique index on ```uid``` and ```provider_id```, so the query will get the id from the vehicle table if a matching row exists, or it will return the result from the returning clause if it doesn't exist.\r\n\r\nI also noticed from my example above that the call to ```union_all``` should be:\r\n```Python\r\nunion_all(vehicle_insert.select(vehicle_insert.c.id))\r\n```\r\nBut it doesn't solve the problem.", "I needed to add a small patch to the `CompoundSelectQuery` implementation to properly handle cte's bound to the union itself. I was able to get an *almost* correct query except for the parentheses, but now I've got a working query and the syntax isn't too awkward. The main takeaways are:\r\n\r\n1. the cte needs to be declared explicitly (as you are doing in your code), since I don't have `cte()` method support on the data modifying queries yet (see #2152).\r\n2. the cte needs to be bound to the union so that it ends up in the outermost layer\r\n3. we need to also explicitly create the bit that selects from the CTE since peewee's `CTE.select_from()` assumes you want to bind the cte to the select.\r\n\r\nHere is the code:\r\n\r\n```python\r\n\r\niq = (Vehicle\r\n .insert(uid=1, type='car', provider='p1')\r\n .on_conflict_ignore()\r\n .returning(Vehicle.id))\r\n\r\ncte = CTE('vehicle_iq', iq, columns=('id',))\r\n\r\nq1 = (Vehicle\r\n .select(Vehicle.id)\r\n .where((Vehicle.uid == 1) & (Vehicle.provider == 'p1')))\r\nq2 = Select([cte], [cte.c.id])\r\n\r\nu = q1.union_all(q2).with_cte(cte)\r\n```\r\n\r\nThis patch is needed as well: 92494cd9ed01b12826b2fddb25cde221ea34f155\r\n\r\nI'm going to close this for now and will look at reducing some of these clumsier pieces as part of #2152." ]
2020-10-30T11:13:27
2020-10-31T03:31:42
2020-10-31T03:31:42
NONE
null
I'm trying to use a CTE on the top level of a UNION ALL query, but I can't figure out how to do it in peewee. The functionality I'm trying to achieve is an "INSERT INTO ... ON CONFLICT DO NOTHING RETURNING ..." query where it always returns the value(s) even when it already exists. The peewee code I'm using looks something like this: ```Python vehicle_insert = pw.CTE("vehicle_insert", meta.Vehicle.insert( uid=result.vehicle_ref, type=vehicle_type, provider=transport_provider, ).on_conflict_ignore().returning(meta.Vehicle.id), columns=("id",) ) vehicle = ( meta.Vehicle.select( meta.Vehicle.id, ) .where( (meta.Vehicle.uid == result.vehicle_ref) & (meta.Vehicle.provider == transport_provider) ) .union_all( vehicle_insert ) .with_cte( vehicle_insert ) ) ``` When I execute this query, peewee doesn't generate the WITH clause. I've tried moving the ```with_cte``` function inside the ```union_all``` like this: ```Python .union_all( vehicle_insert.select(vehicle_insert.c.id).with_cte(vehicle_insert) ) ``` but then I get another error: ``` peewee.NotSupportedError: WITH clause containing a data-modifying statement must be at the top level ``` Is there any way to generate a WITH clause on the top level of a UNION ALL in peewee?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2289/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2289/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2288
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2288/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2288/comments
https://api.github.com/repos/coleifer/peewee/issues/2288/events
https://github.com/coleifer/peewee/pull/2288
730,664,165
MDExOlB1bGxSZXF1ZXN0NTEwOTMxNTU3
2,288
Fix typo in querying docs
{ "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
[ "merged an equivalent patch" ]
2020-10-27T17:26:55
2020-10-27T18:29:25
2020-10-27T18:29:25
NONE
null
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2288/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2288/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/2288", "html_url": "https://github.com/coleifer/peewee/pull/2288", "diff_url": "https://github.com/coleifer/peewee/pull/2288.diff", "patch_url": "https://github.com/coleifer/peewee/pull/2288.patch", "merged_at": null }
https://api.github.com/repos/coleifer/peewee/issues/2287
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2287/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2287/comments
https://api.github.com/repos/coleifer/peewee/issues/2287/events
https://github.com/coleifer/peewee/issues/2287
730,294,359
MDU6SXNzdWU3MzAyOTQzNTk=
2,287
peewee AttributeError 'datetime.datetime' object has no attribute 'get_sort_key'
{ "login": "hungter007", "id": 32872324, "node_id": "MDQ6VXNlcjMyODcyMzI0", "avatar_url": "https://avatars.githubusercontent.com/u/32872324?v=4", "gravatar_id": "", "url": "https://api.github.com/users/hungter007", "html_url": "https://github.com/hungter007", "followers_url": "https://api.github.com/users/hungter007/followers", "following_url": "https://api.github.com/users/hungter007/following{/other_user}", "gists_url": "https://api.github.com/users/hungter007/gists{/gist_id}", "starred_url": "https://api.github.com/users/hungter007/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/hungter007/subscriptions", "organizations_url": "https://api.github.com/users/hungter007/orgs", "repos_url": "https://api.github.com/users/hungter007/repos", "events_url": "https://api.github.com/users/hungter007/events{/privacy}", "received_events_url": "https://api.github.com/users/hungter007/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I don't have enough information to help debug this. Can you provide the query?", "('INSERT INTO `t_group` (`c_id`, `c_group_name`, `c_group_code`, `c_doc_ids`, `c_company_id`, `c_is_delete`, `c_add_by`, `c_add_dt`, `c_update_dt`) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)', ['185ede639b654695869c87b28d31b28d', 'data', '02', '', 'cdf49474297c4454aa2d410ba5eacf60', False, 'user_id', datetime.datetime(2020, 10, 27, 19, 2, 35, 675031), datetime.datetime(2020, 10, 27, 19, 2, 35, 675045)])\r\n", "when running insert_many get error.\r\n\r\nawait db_manager.execute(\r\n Group.insert_many(group_list)\r\n)\r\n", "This looks like possibly a issue with peewee async? If you can provide a reproducible test that fails I will look into this some more, but `insert_many()` and all this is covered by existing (passing) tests, so I don't think there is anything fundamentally broken here." ]
2020-10-27T09:57:58
2020-10-27T12:05:29
2020-10-27T12:05:28
NONE
null
peewee version: 3.13.3 python version: py3.8 error: ![image](https://user-images.githubusercontent.com/32872324/97285859-b9ac7d80-187d-11eb-93aa-1bafec0024ca.png) model: add_dt = peewee.DateTimeField(null=False, default=datetime_now, column_name="c_add_dt")
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2287/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2287/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2286
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2286/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2286/comments
https://api.github.com/repos/coleifer/peewee/issues/2286/events
https://github.com/coleifer/peewee/issues/2286
729,413,268
MDU6SXNzdWU3Mjk0MTMyNjg=
2,286
Database(autoconnect=True) is not thread-safe
{ "login": "notEvil", "id": 4567628, "node_id": "MDQ6VXNlcjQ1Njc2Mjg=", "avatar_url": "https://avatars.githubusercontent.com/u/4567628?v=4", "gravatar_id": "", "url": "https://api.github.com/users/notEvil", "html_url": "https://github.com/notEvil", "followers_url": "https://api.github.com/users/notEvil/followers", "following_url": "https://api.github.com/users/notEvil/following{/other_user}", "gists_url": "https://api.github.com/users/notEvil/gists{/gist_id}", "starred_url": "https://api.github.com/users/notEvil/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/notEvil/subscriptions", "organizations_url": "https://api.github.com/users/notEvil/orgs", "repos_url": "https://api.github.com/users/notEvil/repos", "events_url": "https://api.github.com/users/notEvil/events{/privacy}", "received_events_url": "https://api.github.com/users/notEvil/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "By default peewee databases use a connection-per-thread." ]
2020-10-26T09:47:58
2020-10-26T12:53:02
2020-10-26T12:53:02
NONE
null
In `Database.cursor`, `self.connect()` may be attempted by multiple threads and even though the first one will create the connection, all others will get an `OperationalError` due to `connect(reuse_if_open=False)`. I'm not familiar enough with the code to say that this is the only place where `reuse_if_open` should be `True`.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2286/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2286/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2285
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2285/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2285/comments
https://api.github.com/repos/coleifer/peewee/issues/2285/events
https://github.com/coleifer/peewee/issues/2285
728,952,429
MDU6SXNzdWU3Mjg5NTI0Mjk=
2,285
peewee.ImproperlyConfigured: database attribute does not appear to be set on the model: <Model: Branch>
{ "login": "medoosh79", "id": 72854950, "node_id": "MDQ6VXNlcjcyODU0OTUw", "avatar_url": "https://avatars.githubusercontent.com/u/72854950?v=4", "gravatar_id": "", "url": "https://api.github.com/users/medoosh79", "html_url": "https://github.com/medoosh79", "followers_url": "https://api.github.com/users/medoosh79/followers", "following_url": "https://api.github.com/users/medoosh79/following{/other_user}", "gists_url": "https://api.github.com/users/medoosh79/gists{/gist_id}", "starred_url": "https://api.github.com/users/medoosh79/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/medoosh79/subscriptions", "organizations_url": "https://api.github.com/users/medoosh79/orgs", "repos_url": "https://api.github.com/users/medoosh79/repos", "events_url": "https://api.github.com/users/medoosh79/events{/privacy}", "received_events_url": "https://api.github.com/users/medoosh79/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "First off, please take the time to format your code properly. GitHub has links and controls in the editor that will show you how to do this.\r\n\r\nSecond, please see the documentation. This is covered in all the basic examples.\r\n\r\nhttp://docs.peewee-orm.com/en/latest/peewee/quickstart.html#model-definition\r\n\r\n```python\r\nclass SomeModel(Model):\r\n ...\r\n class Meta:\r\n database = db_instance\r\n```" ]
2020-10-25T06:26:38
2020-10-25T11:22:19
2020-10-25T11:21:52
NONE
null
from peewee import * db = MySQLDatabase('library',user='root', password= '', host='localhost', port=3306 ) class Branch(Model): name = CharField() code = CharField(null=True,unique=True) location = CharField(null=True) db.connect() db.create_tables([Branch]) how to solve this issue? Traceback (most recent call last): File "C:/Users/Mohammed/OneDrive - Office 365/Python Projects/Library/test.py", line 20, in <module> db.create_tables([Branch]) File "C:\Users\Mohammed\AppData\Local\Programs\Python\Python38\lib\site-packages\peewee.py", line 3286, in create_tables model.create_table(**options) File "C:\Users\Mohammed\AppData\Local\Programs\Python\Python38\lib\site-packages\peewee.py", line 6590, in create_table if safe and not cls._schema.database.safe_create_index \ File "C:\Users\Mohammed\AppData\Local\Programs\Python\Python38\lib\site-packages\peewee.py", line 5520, in database raise ImproperlyConfigured('database attribute does not appear to ' peewee.ImproperlyConfigured: database attribute does not appear to be set on the model: <Model: Branch>
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2285/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2285/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2284
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2284/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2284/comments
https://api.github.com/repos/coleifer/peewee/issues/2284/events
https://github.com/coleifer/peewee/pull/2284
727,541,905
MDExOlB1bGxSZXF1ZXN0NTA4NDE1MDEz
2,284
Use link_shared_object instead of link_executable in SQLite detection
{ "login": "sboisson", "id": 238806, "node_id": "MDQ6VXNlcjIzODgwNg==", "avatar_url": "https://avatars.githubusercontent.com/u/238806?v=4", "gravatar_id": "", "url": "https://api.github.com/users/sboisson", "html_url": "https://github.com/sboisson", "followers_url": "https://api.github.com/users/sboisson/followers", "following_url": "https://api.github.com/users/sboisson/following{/other_user}", "gists_url": "https://api.github.com/users/sboisson/gists{/gist_id}", "starred_url": "https://api.github.com/users/sboisson/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/sboisson/subscriptions", "organizations_url": "https://api.github.com/users/sboisson/orgs", "repos_url": "https://api.github.com/users/sboisson/repos", "events_url": "https://api.github.com/users/sboisson/events{/privacy}", "received_events_url": "https://api.github.com/users/sboisson/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Excellent, thank you!" ]
2020-10-22T16:27:19
2020-10-22T16:44:57
2020-10-22T16:44:57
CONTRIBUTOR
null
`link_executable` doesn't use environment variable `LDFLAGS`, only environment variable `CC` (which usually only contains the name of the compiler, not the linking options)… which can be problematic and cause false negative on setups where SQLite is not installed in system path, but on a custom path. Also the setup is not attempting to build an executable, but shared objects.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2284/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2284/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/2284", "html_url": "https://github.com/coleifer/peewee/pull/2284", "diff_url": "https://github.com/coleifer/peewee/pull/2284.diff", "patch_url": "https://github.com/coleifer/peewee/pull/2284.patch", "merged_at": "2020-10-22T16:44:57" }
https://api.github.com/repos/coleifer/peewee/issues/2283
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2283/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2283/comments
https://api.github.com/repos/coleifer/peewee/issues/2283/events
https://github.com/coleifer/peewee/issues/2283
724,693,259
MDU6SXNzdWU3MjQ2OTMyNTk=
2,283
foreign key with "_id" in the migrate.add_index
{ "login": "alpo", "id": 977573, "node_id": "MDQ6VXNlcjk3NzU3Mw==", "avatar_url": "https://avatars.githubusercontent.com/u/977573?v=4", "gravatar_id": "", "url": "https://api.github.com/users/alpo", "html_url": "https://github.com/alpo", "followers_url": "https://api.github.com/users/alpo/followers", "following_url": "https://api.github.com/users/alpo/following{/other_user}", "gists_url": "https://api.github.com/users/alpo/gists{/gist_id}", "starred_url": "https://api.github.com/users/alpo/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/alpo/subscriptions", "organizations_url": "https://api.github.com/users/alpo/orgs", "repos_url": "https://api.github.com/users/alpo/repos", "events_url": "https://api.github.com/users/alpo/events{/privacy}", "received_events_url": "https://api.github.com/users/alpo/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I cannot replicate this problem:\r\n\r\n```python\r\n\r\nfrom peewee import *\r\n\r\ndb = SqliteDatabase(':memory:')\r\n\r\nclass Base(Model):\r\n class Meta:\r\n database = db\r\n\r\nclass User(Base):\r\n username = TextField()\r\n\r\nclass Tweet(Base):\r\n user_id = ForeignKeyField(User, backref='tweets')\r\n\r\ndb.create_tables([User, Tweet])\r\ndb.execute_sql('drop index \"tweet_user_id\"')\r\n\r\nfrom playhouse.migrate import *\r\nmigrator = SchemaMigrator.from_database(db)\r\nmigrate(\r\n migrator.add_index('tweet', ('user_id',), unique=True)\r\n)\r\n```\r\n\r\nThe SQL being generated is correct in the above example:\r\n\r\n```sql\r\nCREATE TABLE IF NOT EXISTS \"user\" (\"id\" INTEGER NOT NULL PRIMARY KEY, \"username\" TEXT NOT NULL)\r\nCREATE TABLE IF NOT EXISTS \"tweet\" (\"id\" INTEGER NOT NULL PRIMARY KEY, \"user_id\" INTEGER NOT NULL, FOREIGN KEY (\"user_id\") REFERENCES \"user\" (\"id\"))\r\n-- this is added automatically by peewee --\r\nCREATE INDEX IF NOT EXISTS \"tweet_user_id\" ON \"tweet\" (\"user_id\")\r\n-- we'll drop the automatically-added index explicitly --\r\ndrop index \"tweet_user_id\"\r\n\r\n-- this is generated by the migrator --\r\nCREATE UNIQUE INDEX \"tweet_user_id\" ON \"tweet\" (\"user_id\")\r\n```\r\n\r\nAlso, for what it's worth, using \"master_id\" is a bit of an anti-pattern, since the field accessor returns an `AnotherThing` instance and not a numeric/unique ID." ]
2020-10-19T14:41:04
2020-10-19T15:57:07
2020-10-19T15:57:06
NONE
null
I have a foreign key in the ORM object and in the database with name ending with '_id'. Like this: ``` class Thing(BaseThing): master_id = ForeignKeyField(AnotherThing, backref='details', index=True) other_field = BigIntegerField(index=True) ... ``` and I'm trying to create an index in migration using add_index Attempt 1 ``` def migrate(migrator, database, fake=False, **kwargs): migrator.add_index('thing', 'master', 'other_field', unique=True) ``` fails with message: `peewee.InternalError: (1072, "Key column 'master' doesn't exist in table")` Attempt 2 ``` def migrate(migrator, database, fake=False, **kwargs): migrator.add_index('thing', 'master_id', 'other_field', unique=True) ``` fails with message: `peewee.InternalError: (1072, "Key column 'master_id_id' doesn't exist in table")` Is it possible to make a `migrate.add_index` work in this situation?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2283/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2283/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2282
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2282/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2282/comments
https://api.github.com/repos/coleifer/peewee/issues/2282/events
https://github.com/coleifer/peewee/issues/2282
723,141,094
MDU6SXNzdWU3MjMxNDEwOTQ=
2,282
JSON/dict integer keys getting converted to strings when read.
{ "login": "pydatasci-repos", "id": 71051965, "node_id": "MDQ6VXNlcjcxMDUxOTY1", "avatar_url": "https://avatars.githubusercontent.com/u/71051965?v=4", "gravatar_id": "", "url": "https://api.github.com/users/pydatasci-repos", "html_url": "https://github.com/pydatasci-repos", "followers_url": "https://api.github.com/users/pydatasci-repos/followers", "following_url": "https://api.github.com/users/pydatasci-repos/following{/other_user}", "gists_url": "https://api.github.com/users/pydatasci-repos/gists{/gist_id}", "starred_url": "https://api.github.com/users/pydatasci-repos/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/pydatasci-repos/subscriptions", "organizations_url": "https://api.github.com/users/pydatasci-repos/orgs", "repos_url": "https://api.github.com/users/pydatasci-repos/repos", "events_url": "https://api.github.com/users/pydatasci-repos/events{/privacy}", "received_events_url": "https://api.github.com/users/pydatasci-repos/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Just going to read it with `folds = {int(k):v for k,v in folds.items()}` when I need that attribute.\r\n\r\nMakes me think of this:\r\n![image](https://user-images.githubusercontent.com/71051965/96255136-6a647400-0f84-11eb-9590-7d7185976284.png)", "What database are you using? Postgres, Sqlite or MySQL?", "@coleifer Sqlite\r\n```\r\nfrom playhouse.sqlite_ext import SqliteExtDatabase, JSONField\r\n```", "I think this comes down to sqlite interpreting object keys as strings. I'd suggest following it up on the sqlite forums if you have more questions on it. https://sqlite.org/forum/forummain\r\n\r\n```\r\nsqlite> select json_valid('{1: \"k1\"}');\r\n0\r\nsqlite> select json_valid('{\"1\": \"k1\"}');\r\n1\r\n```", "@coleifer Thanks for taking a look. Your `json_valid` test got me on the right track. There are several posts out there pointing to the JSON spec saying that keys must be strings. E.g. https://stackoverflow.com/a/8758771/5739514\r\n\r\nLet's see what the sqlite folks say. Surprised it allows it to be stored.\r\nhttps://sqlite.org/forum/forumpost/28863dcedf\r\n\r\nTaking a look at MongoDB, they use a lot of this pattern, but it results in `TypeError: unhashable type: 'list'`. Will keep thinking on a workaround apart from another rel/table.\r\n```\r\n{[\r\n {\r\n \"_id\": 1,\r\n \"attribute1\": \"beep\"\r\n },\r\n {\r\n \"_id\": 2,\r\n \"attribute2\": \"boop\"\r\n }\r\n]}\r\n```", "Workaround for future humans\r\n```\r\nfolds = {\"folds\": [{\"id\":1, \"name\":\"a\", \"other\":\"beep\"}, {\"id\":2, \"name\":\"b\", \"other:\"boop\"}]}\r\n# or\r\nfolds = {\"folds\": [{\"name\":\"a\", \"other\":\"beep\"}, {\"name\":\"b\", \"other\":\"boop\"}]}\r\n```\r\nKinda stinks but at least the inner list can be accessed via index in python. `Foldset.folds[\"folds\"][0]`" ]
2020-10-16T11:34:03
2020-10-16T18:38:54
2020-10-16T15:41:55
NONE
null
Here, I have provided a dictionary with integer-based keys `{0:_,1:_,2:_}` to a `JSONField()` attribute named 'folds'. When I create the object and return it, the folds attribute still serializes with integer keys as expected. However, when I fetch the object using `get_by_id()`, the `folds.keys()` are now strings. Is this expected behavior? Maybe a json.loads or python dict problem rather than a peewee problem, but I just wanted to report it so it's known. ![image](https://user-images.githubusercontent.com/71051965/96254397-3ccafb00-0f83-11eb-81d4-006f75aa70b8.png)
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2282/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2282/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2281
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2281/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2281/comments
https://api.github.com/repos/coleifer/peewee/issues/2281/events
https://github.com/coleifer/peewee/issues/2281
719,177,130
MDU6SXNzdWU3MTkxNzcxMzA=
2,281
peewee.ModelBase has no attribute 'bulk_update'
{ "login": "instantrad", "id": 66900828, "node_id": "MDQ6VXNlcjY2OTAwODI4", "avatar_url": "https://avatars.githubusercontent.com/u/66900828?v=4", "gravatar_id": "", "url": "https://api.github.com/users/instantrad", "html_url": "https://github.com/instantrad", "followers_url": "https://api.github.com/users/instantrad/followers", "following_url": "https://api.github.com/users/instantrad/following{/other_user}", "gists_url": "https://api.github.com/users/instantrad/gists{/gist_id}", "starred_url": "https://api.github.com/users/instantrad/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/instantrad/subscriptions", "organizations_url": "https://api.github.com/users/instantrad/orgs", "repos_url": "https://api.github.com/users/instantrad/repos", "events_url": "https://api.github.com/users/instantrad/events{/privacy}", "received_events_url": "https://api.github.com/users/instantrad/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "```python\r\nIn [1]: from peewee import * \r\n\r\nIn [2]: class MyModel(Model): \r\n ...: pass \r\n ...: \r\n\r\nIn [3]: MyModel.bulk_update \r\nOut[3]: <bound method Model.bulk_update of <Model: MyModel>>\r\n```" ]
2020-10-12T08:23:59
2020-10-12T12:45:21
2020-10-12T12:45:21
NONE
null
As you can see below, when l print type of the peewee model, l get **<class 'peewee.ModelBase'>** However, it complains bulk_update does not exist. Also running dir on the Model class, does not contain the **bulk_update** [2020-10-12 08:20:36,241] {test.py:250} INFO - <class 'peewee.ModelBase'> [2020-10-12 08:30:35,533] {test.py:251} INFO - ['DoesNotExist', '__class__', '__data__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__rel__', '__repr__', '__setattr__', '__sizeof__', '__sql__', '__str__', '__subclasshook__', '__weakref__', '_as_dict', '_coerce', '_meta', '_normalize_data', '_pk', '_pk_expr', '_populate_unsaved_relations', '_prune_fields', '_schema', "'bulk_create''] [2020-10-12 08:30:35,533] {taskinstance.py:1150} ERROR - type object 'Study' has no attribute 'bulk_update' [2020-10-12 08:20:36,241] {test.py:1150} ERROR - type object 'Study' has no attribute 'bulk_update' What could be the issue?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2281/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2281/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2280
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2280/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2280/comments
https://api.github.com/repos/coleifer/peewee/issues/2280/events
https://github.com/coleifer/peewee/issues/2280
717,468,715
MDU6SXNzdWU3MTc0Njg3MTU=
2,280
Spurious SQL queries when creating tables
{ "login": "acepace", "id": 231135, "node_id": "MDQ6VXNlcjIzMTEzNQ==", "avatar_url": "https://avatars.githubusercontent.com/u/231135?v=4", "gravatar_id": "", "url": "https://api.github.com/users/acepace", "html_url": "https://github.com/acepace", "followers_url": "https://api.github.com/users/acepace/followers", "following_url": "https://api.github.com/users/acepace/following{/other_user}", "gists_url": "https://api.github.com/users/acepace/gists{/gist_id}", "starred_url": "https://api.github.com/users/acepace/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/acepace/subscriptions", "organizations_url": "https://api.github.com/users/acepace/orgs", "repos_url": "https://api.github.com/users/acepace/repos", "events_url": "https://api.github.com/users/acepace/events{/privacy}", "received_events_url": "https://api.github.com/users/acepace/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "```python\r\n\r\nfrom peewee import * \r\n\r\ndb = SqliteDatabase(':memory:')\r\n\r\nimport logging\r\nlogger = logging.getLogger('peewee')\r\nlogger.addHandler(logging.StreamHandler())\r\nlogger.setLevel(logging.DEBUG)\r\n\r\nclass Base(Model):\r\n class Meta:\r\n database = db\r\n\r\nclass A(Base):\r\n a = TextField()\r\nclass B(Base):\r\n a = ForeignKeyField(A)\r\n b = TextField()\r\nclass C(Base):\r\n b = ForeignKeyField(B)\r\n c = TextField()\r\n\r\nall_tables = [A, B, C]\r\nfor table in all_tables:\r\n table._meta.sorted_fields\r\n table._meta.add_field('test', TextField())\r\n\r\ndb.create_tables(all_tables)\r\n```\r\n\r\nOutput:\r\n\r\n```\r\n('CREATE TABLE IF NOT EXISTS \"a\" (\"id\" INTEGER NOT NULL PRIMARY KEY, \"a\" TEXT NOT NULL, \"test\" TEXT NOT NULL)', []) \r\n('CREATE TABLE IF NOT EXISTS \"b\" (\"id\" INTEGER NOT NULL PRIMARY KEY, \"a_id\" INTEGER NOT NULL, \"b\" TEXT NOT NULL, \"test\" TEXT NOT NULL, FOREIGN KEY (\"a_id\") REFERENCES \"a\" (\"id\"))', [])\r\n('CREATE INDEX IF NOT EXISTS \"b_a_id\" ON \"b\" (\"a_id\")', []) \r\n('CREATE TABLE IF NOT EXISTS \"c\" (\"id\" INTEGER NOT NULL PRIMARY KEY, \"b_id\" INTEGER NOT NULL, \"c\" TEXT NOT NULL, \"test\" TEXT NOT NULL, FOREIGN KEY (\"b_id\") REFERENCES \"b\" (\"id\"))', [])\r\n('CREATE INDEX IF NOT EXISTS \"c_b_id\" ON \"c\" (\"b_id\")', [])\r\n```" ]
2020-10-08T15:55:08
2020-10-08T16:21:08
2020-10-08T16:21:08
NONE
null
The following code snippet creates an invalid SELECT query before creating tables, causing create_tables to fail. ``` psycopg2.extras.register_default_jsonb() database = PostgresqlExtDatabase('postgres', user=options.username, password=options.password, host=options.database_host) # hack to handle JSONB properly and handle sqlite DBs :( for entity in all_tables: # peewee author says this is the best way to iterate over a models fields fields = entity._meta.sorted_fields for field in fields: if isinstance(field, JSONField): new_field = BinaryJSONField(null=True) entity._meta.add_field(field.name, new_field) ext_db.initialize(database) database.create_tables([CIRun, Application, ApplicationRun]) ``` Before the create table queries are run, the following queries are run, the second causes the transaction to be aborted. ``` peewee.execute_sql: ('SELECT tablename FROM pg_catalog.pg_tables WHERE schemaname = %s ORDER BY tablename', ('public',)) peewee.execute_sql: ('SELECT COUNT(1) FROM (SELECT 1 FROM "application" AS "t1") AS "_wrapped"', []) peewee.execute_sql: ('SELECT COUNT(1) FROM (SELECT 1 FROM "application" AS "t1") AS "_wrapped"', []) peewee.execute_sql: ('SELECT COUNT(1) FROM (SELECT 1 FROM "application" AS "t1") AS "_wrapped"', []) peewee.execute_sql: ('SELECT COUNT(1) FROM (SELECT 1 FROM "application" AS "t1") AS "_wrapped"', []) ``` The query seems to originate from `sort_models` ``` names = lambda m: (m._meta.name, m._meta.table_name) for m in sorted(models, key=names): ``` But I'm not sure why
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2280/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2280/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2279
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2279/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2279/comments
https://api.github.com/repos/coleifer/peewee/issues/2279/events
https://github.com/coleifer/peewee/pull/2279
716,498,792
MDExOlB1bGxSZXF1ZXN0NDk5MjI0NTE2
2,279
Enable use of range for IN filters in python 3
{ "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
[ "I've merged an equivalent patch. I had hoped to also support `map` but that's more like a generator and doesn't support multiple iterations, so that doesn't work. At any rate, thanks for the suggestion." ]
2020-10-07T12:47:41
2020-10-07T13:43:56
2020-10-07T13:43:27
CONTRIBUTOR
null
While it is currently possible to do something like `Model.select().where(Model.id << range(42, 256))` in Python 2, this is not possible in Python3. The reason being, that `range()` returns a `list` in Python 2, which is currently a member of `Value._multi_types`, but is of type `range` in Python 3. Therefor I used the existing Python 2/3 branch logic to declare `multi_types` globally with other version-specific constants and used it in `Value` instead. I did not yet add a test case for this, since `test_select_in_list_of_values` in `sql.py` currently only handles strings.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2279/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2279/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/2279", "html_url": "https://github.com/coleifer/peewee/pull/2279", "diff_url": "https://github.com/coleifer/peewee/pull/2279.diff", "patch_url": "https://github.com/coleifer/peewee/pull/2279.patch", "merged_at": null }
https://api.github.com/repos/coleifer/peewee/issues/2278
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2278/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2278/comments
https://api.github.com/repos/coleifer/peewee/issues/2278/events
https://github.com/coleifer/peewee/pull/2278
716,411,268
MDExOlB1bGxSZXF1ZXN0NDk5MTUyODM5
2,278
GeneratedHashField
{ "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
[ "F-Strings are not supported in Python 2.x and Python 3 < 3.6.\r\nThis is why the check fails.", "I see that, thanks! :+1: Didn't think it was worth fixing right away since I imagine changes will be needed anyway, if this is at all even wanted. ", "I'm not interested in maintaining or supporting this, but feel free to offer it as a 3rd-party extension.", "Thank you for your input.\r\n\r\nI don't see anything similar to [Computed](https://docs.sqlalchemy.org/en/13/core/defaults.html?highlight=server#computed-generated-always-as-columns) offered by Peewee (at least I couldn't locate anything in the docs), or is this the right approach?", "No but since Postgres, MySQL and Sqlite have roughly the same syntax it's probably worth adding. I will look into this.", "As I was implementing this, I ran into a number of subtle differences between the Sqlite, MySQL, MariaDB and Postgres implementations. For now, I think users will be best-off using the existing `constraints=` parameter to specify a generated column definition, although the code is in `feature/computed` branch if you want to fork it.\r\n\r\n```python\r\n\r\nconstraint = SQL(\"generated always as (first || ' ' || last)\")\r\nfull_name = CharField(constraints=[constraint])\r\n```", "Lovely! Thanks for the tip, I really appreciate it. " ]
2020-10-07T10:38:54
2020-10-09T07:44:57
2020-10-07T13:34:42
NONE
null
Hi! :wave: First, thank you so much for such a great library. :+1: Feature request :ribbon: --- I would like to make use of PostgreSQL's `GENERATED ALWAYS AS` statement, for computing a hashed key based on one or more other fields. Specifically for a generating a hash Solution :question: --- I've provided a prototype which accomplishes this, but it could use some updates for generalization (maybe not hash, different types, etc). Do you think this is worth pursuing or maybe best left as a custom implementation for private use? I suppose it is similar to SqlAlchemy's [Computed](https://docs.sqlalchemy.org/en/13/core/defaults.html?highlight=server#computed-generated-always-as-columns)
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2278/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2278/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/2278", "html_url": "https://github.com/coleifer/peewee/pull/2278", "diff_url": "https://github.com/coleifer/peewee/pull/2278.diff", "patch_url": "https://github.com/coleifer/peewee/pull/2278.patch", "merged_at": null }
https://api.github.com/repos/coleifer/peewee/issues/2277
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2277/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2277/comments
https://api.github.com/repos/coleifer/peewee/issues/2277/events
https://github.com/coleifer/peewee/issues/2277
716,402,167
MDU6SXNzdWU3MTY0MDIxNjc=
2,277
delete().execute() on model object deletes all records from the table.
{ "login": "p1v2", "id": 13005815, "node_id": "MDQ6VXNlcjEzMDA1ODE1", "avatar_url": "https://avatars.githubusercontent.com/u/13005815?v=4", "gravatar_id": "", "url": "https://api.github.com/users/p1v2", "html_url": "https://github.com/p1v2", "followers_url": "https://api.github.com/users/p1v2/followers", "following_url": "https://api.github.com/users/p1v2/following{/other_user}", "gists_url": "https://api.github.com/users/p1v2/gists{/gist_id}", "starred_url": "https://api.github.com/users/p1v2/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/p1v2/subscriptions", "organizations_url": "https://api.github.com/users/p1v2/orgs", "repos_url": "https://api.github.com/users/p1v2/repos", "events_url": "https://api.github.com/users/p1v2/events{/privacy}", "received_events_url": "https://api.github.com/users/p1v2/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "To delete a single model instance, you should use `.delete_instance()`.\r\n\r\nThe documentation covers this in detail: http://docs.peewee-orm.com/en/latest/peewee/querying.html#deleting-records" ]
2020-10-07T10:25:06
2020-10-07T13:33:31
2020-10-07T13:33:31
NONE
null
Hey. Recently I ran into issue, when accidentally dropping all records from the table. if we have: ``` from peewee import Model class Entity(Model): # fields list pass # entity is single record from DB entity = Entity.select()[0] # entity delete is query that deletes all records in table # next code line returns: # ('DELETE FROM "entity"', []) entity.delete().sql() # And this code will actually do delete entity.delete().execute() # woop, no more any entity in DB ``` Any chance to change it, that delete method will delete single record. This feels much more obvious. Also Django-ORM does delete single record, when you call delete on single model object.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2277/reactions", "total_count": 1, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 1, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2277/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2276
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2276/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2276/comments
https://api.github.com/repos/coleifer/peewee/issues/2276/events
https://github.com/coleifer/peewee/issues/2276
715,871,477
MDU6SXNzdWU3MTU4NzE0Nzc=
2,276
KeyError when trying to dynamically add pre-existing field with a new default
{ "login": "bdoms", "id": 126839, "node_id": "MDQ6VXNlcjEyNjgzOQ==", "avatar_url": "https://avatars.githubusercontent.com/u/126839?v=4", "gravatar_id": "", "url": "https://api.github.com/users/bdoms", "html_url": "https://github.com/bdoms", "followers_url": "https://api.github.com/users/bdoms/followers", "following_url": "https://api.github.com/users/bdoms/following{/other_user}", "gists_url": "https://api.github.com/users/bdoms/gists{/gist_id}", "starred_url": "https://api.github.com/users/bdoms/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/bdoms/subscriptions", "organizations_url": "https://api.github.com/users/bdoms/orgs", "repos_url": "https://api.github.com/users/bdoms/repos", "events_url": "https://api.github.com/users/bdoms/events{/privacy}", "received_events_url": "https://api.github.com/users/bdoms/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "The default is only removed if the original field instance has a default, so this seems like something that only would come about in a very weird way. Going to pass on any changes." ]
2020-10-06T17:16:31
2020-10-06T20:02:02
2020-10-06T20:02:02
NONE
null
This is a funny situation, but essentially I'm trying to dynamically rebuild a database. It starts with a call to `generate_models` (which is totally amazing, thank you!) but that does not include any defaults. In order to add them back in, I'm looping through the fields and adding the default on the fly. Rather than manually messing with the `_meta` properties like `defaults`, `_default_callables`, etc. I decided to use `Metadata.add_field`, like so: ```python for name, field in list(model_class._meta.fields.items()): field.default = datetime.utcnow model_class._meta.add_field(name, field) ``` I noticed that `add_field` starts by removing the old one if it exists, so I figured this was safe to use. But it generates a key error because the old field didn't have a default on it: ```python File ".../python3.8/site-packages/peewee.py", line 5912, in add_field self.remove_field(field_name) File ".../python3.8/site-packages/peewee.py", line 5961, in remove_field del self.defaults[original] KeyError: <Field: model_name.field_name> ``` It seems like it'd be an easy fix to just add a single line to `remove_field` right before that, so it becomes: ```python if original in self.defaults: del self.defaults[original] ``` Or even turn it into a `pop` like the line below. If for some reason you don't think this is something you want to support then I did find a pretty easy and logical workaround: ```python for name, field in list(model_class._meta.fields.items()): model_class._meta.remove_field(name) field.default = datetime.utcnow model_class._meta.add_field(name, field) ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2276/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2276/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2275
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2275/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2275/comments
https://api.github.com/repos/coleifer/peewee/issues/2275/events
https://github.com/coleifer/peewee/issues/2275
708,880,331
MDU6SXNzdWU3MDg4ODAzMzE=
2,275
on_conflict support in bulk_create
{ "login": "AntonioL", "id": 13491207, "node_id": "MDQ6VXNlcjEzNDkxMjA3", "avatar_url": "https://avatars.githubusercontent.com/u/13491207?v=4", "gravatar_id": "", "url": "https://api.github.com/users/AntonioL", "html_url": "https://github.com/AntonioL", "followers_url": "https://api.github.com/users/AntonioL/followers", "following_url": "https://api.github.com/users/AntonioL/following{/other_user}", "gists_url": "https://api.github.com/users/AntonioL/gists{/gist_id}", "starred_url": "https://api.github.com/users/AntonioL/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/AntonioL/subscriptions", "organizations_url": "https://api.github.com/users/AntonioL/orgs", "repos_url": "https://api.github.com/users/AntonioL/repos", "events_url": "https://api.github.com/users/AntonioL/events{/privacy}", "received_events_url": "https://api.github.com/users/AntonioL/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I'm going to pass on implementing this as part of `bulk_create()` since this can be easily handled by:\r\n\r\n```python\r\nModel.insert_many([....]).on_conflict_ignore()\r\n```\r\n\r\nThe 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." ]
2020-09-25T11:59:27
2020-09-25T18:49:14
2020-09-25T18:49:13
NONE
null
Please provide mechanism to ignore conflicts when calling bulk_create. My target database is PostgreSQL. At th moment I am handrolling my own query.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2275/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2275/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2274
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2274/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2274/comments
https://api.github.com/repos/coleifer/peewee/issues/2274/events
https://github.com/coleifer/peewee/issues/2274
708,427,993
MDU6SXNzdWU3MDg0Mjc5OTM=
2,274
Documentation - Example of `choices` parameter.
{ "login": "ghost", "id": 10137, "node_id": "MDQ6VXNlcjEwMTM3", "avatar_url": "https://avatars.githubusercontent.com/u/10137?v=4", "gravatar_id": "", "url": "https://api.github.com/users/ghost", "html_url": "https://github.com/ghost", "followers_url": "https://api.github.com/users/ghost/followers", "following_url": "https://api.github.com/users/ghost/following{/other_user}", "gists_url": "https://api.github.com/users/ghost/gists{/gist_id}", "starred_url": "https://api.github.com/users/ghost/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/ghost/subscriptions", "organizations_url": "https://api.github.com/users/ghost/orgs", "repos_url": "https://api.github.com/users/ghost/repos", "events_url": "https://api.github.com/users/ghost/events{/privacy}", "received_events_url": "https://api.github.com/users/ghost/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "That's not the correct way. An iterable of 2-tuples looks like this:\r\n\r\n```python\r\n[('key1', 'Label 1'), ('key2', 'Label 2')]\r\n```" ]
2020-09-24T19:42:48
2020-09-24T22:26:48
2020-09-24T22:26:48
NONE
null
Hey there. Thank you for the simple ORM! It's ideal for a pypi package I am building that has no django/flask gui. Do have an example of `choices=[(),()]` that could be added to the docs? It is not clear to me. ``` choices (list) – An iterable of 2-tuples mapping column values to display labels. http://docs.peewee-orm.com/en/latest/peewee/api.html#fields ``` I swear I saw an example of this somewhere, but looking back through the ReadTheDocs and the `/examples` folder on GitHub I cannot find it.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2274/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2274/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2273
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2273/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2273/comments
https://api.github.com/repos/coleifer/peewee/issues/2273/events
https://github.com/coleifer/peewee/issues/2273
706,403,507
MDU6SXNzdWU3MDY0MDM1MDc=
2,273
peewee saves value of foreign key field wrongly
{ "login": "hamidb80", "id": 33871336, "node_id": "MDQ6VXNlcjMzODcxMzM2", "avatar_url": "https://avatars.githubusercontent.com/u/33871336?v=4", "gravatar_id": "", "url": "https://api.github.com/users/hamidb80", "html_url": "https://github.com/hamidb80", "followers_url": "https://api.github.com/users/hamidb80/followers", "following_url": "https://api.github.com/users/hamidb80/following{/other_user}", "gists_url": "https://api.github.com/users/hamidb80/gists{/gist_id}", "starred_url": "https://api.github.com/users/hamidb80/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/hamidb80/subscriptions", "organizations_url": "https://api.github.com/users/hamidb80/orgs", "repos_url": "https://api.github.com/users/hamidb80/repos", "events_url": "https://api.github.com/users/hamidb80/events{/privacy}", "received_events_url": "https://api.github.com/users/hamidb80/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I think you've got some issue with your code, your base model class, or something. What you're suggesting is that peewee is somehow fundamentally broken, and the tests are all passing:\r\n\r\nhttps://travis-ci.org/github/coleifer/peewee" ]
2020-09-22T13:50:32
2020-09-23T03:25:30
2020-09-22T20:19:27
NONE
null
Hello. I think peewee saves the value of foreign key wrongly. Because: user.id is an integer but in the token records, `user_id` saves as "t<user_id>". ```python class User(BaseModel): name = CharField() identifier = CharField(index=True, unique=True) email = CharField(unique=True) password = CharField() registered_at = DateTimeField() """ back ref fields: -- tokens """ class Token(BaseModel): user = ForeignKeyField(User, backref='tokens') code = CharField() created_at = DateTimeField() will_expire_at = DateTimeField() ``` data saves like: ``` USER TABLE id | name | ... 1 | hamid RECORD TABLE id | user_id | ... 1 | t1 | ... ``` Also I have problem with this: ```python token = Token.get_or_none(code=token_key) print(token.user) ``` output of following code: ` UserDoesNotExist('<Model: User> instance matching query does not exist:\nSQL: SELECT "t1"."id", "t1"."name", "t1"."identifier", "t1"."email", "t1"."password", "t1"."registered_at" FROM "user" AS "t1" WHERE ("t1"."id" = ?) LIMIT ? OFFSET ?\nParams: [\'t1\', 1, 0]') ` But if I modify the `user_id` in the token table manually, everything works great. python 3.8.2 database: sqlite peewee: last stable version at the time of opening the issue ubunru mate 20
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2273/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2273/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2272
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2272/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2272/comments
https://api.github.com/repos/coleifer/peewee/issues/2272/events
https://github.com/coleifer/peewee/issues/2272
706,283,272
MDU6SXNzdWU3MDYyODMyNzI=
2,272
Join multiple foreign keys on same table.
{ "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
[ "You should not call `.select()` twice. Just build up your joins. I suggest you familiarize yourself with the documentation, which covers many topics like querying and joins:\r\n\r\n* http://docs.peewee-orm.com/en/latest/peewee/querying.html\r\n* http://docs.peewee-orm.com/en/latest/peewee/relationships.html\r\n\r\nReferencing the same table twice, but in different contexts, is done with an alias:\r\n\r\n```python\r\nDA = Deployment.alias()\r\n\r\nquery = (System\r\n .select() # If you want all columns, use \".select(System, Deployment, DA)\" instead\r\n .join(Deployment, on=(System.deployment == Deployment.id), attr='deployment')\r\n .join_from(System, DA, JOIN.LEFT_OUTER, on=(System.dataset == DA.id), attr='dataset'))\r\n```" ]
2020-09-22T11:04:34
2020-09-22T20:17:42
2020-09-22T20:16:40
CONTRIBUTOR
null
I have a use case, where I need to join a table that has two foreign keys on another table to this table: ``` COND_DEPLOYMENT = (System.deployment == Deployment.id).alias('deployment') COND_DATASET = (System.dataset == Deployment.id).alias('dataset') SYSTEMS = System.select().join( Deployment, on=COND_DEPLOYMENT, join_type=JOIN.LEFT_OUTER ).select(System).join( Deployment, on=COND_DATASET, join_type=JOIN.LEFT_OUTER ) ``` I later want to select records, that either match fields of deployment, either when referenced by `System.deployment` or `System.dataset`. Unfortunately, this query does not execute correctly: ``` Traceback (most recent call last): File "/usr/local/lib/python3.7/dist-packages/peewee.py", line 3099, in execute_sql cursor.execute(sql, params or ()) File "/usr/lib/python3/dist-packages/pymysql/cursors.py", line 170, in execute result = self._query(query) File "/usr/lib/python3/dist-packages/pymysql/cursors.py", line 328, in _query conn.query(q) File "/usr/lib/python3/dist-packages/pymysql/connections.py", line 517, in query self._affected_rows = self._read_query_result(unbuffered=unbuffered) File "/usr/lib/python3/dist-packages/pymysql/connections.py", line 732, in _read_query_result result.read() File "/usr/lib/python3/dist-packages/pymysql/connections.py", line 1075, in read first_packet = self.connection._read_packet() File "/usr/lib/python3/dist-packages/pymysql/connections.py", line 684, in _read_packet packet.check_error() File "/usr/lib/python3/dist-packages/pymysql/protocol.py", line 220, in check_error err.raise_mysql_exception(self._data) File "/usr/lib/python3/dist-packages/pymysql/err.py", line 109, in raise_mysql_exception raise errorclass(errno, errval) pymysql.err.InternalError: (1066, "Not unique table/alias: 't2'") During handling of the above exception, another exception occurred: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/lib/python3.7/dist-packages/peewee.py", line 6797, in __iter__ self.execute() File "/usr/local/lib/python3.7/dist-packages/peewee.py", line 1886, in inner return method(self, database, *args, **kwargs) File "/usr/local/lib/python3.7/dist-packages/peewee.py", line 1957, in execute return self._execute(database) File "/usr/local/lib/python3.7/dist-packages/peewee.py", line 2129, in _execute cursor = database.execute(self) File "/usr/local/lib/python3.7/dist-packages/peewee.py", line 3112, in execute return self.execute_sql(sql, params, commit=commit) File "/usr/local/lib/python3.7/dist-packages/peeweeplus/database.py", line 44, in execute_sql return super().execute_sql(*args, **kwargs) File "/usr/local/lib/python3.7/dist-packages/peewee.py", line 3106, in execute_sql self.commit() File "/usr/local/lib/python3.7/dist-packages/peewee.py", line 2873, in __exit__ reraise(new_type, new_type(exc_value, *exc_args), traceback) File "/usr/local/lib/python3.7/dist-packages/peewee.py", line 183, in reraise raise value.with_traceback(tb) File "/usr/local/lib/python3.7/dist-packages/peewee.py", line 3099, in execute_sql cursor.execute(sql, params or ()) File "/usr/lib/python3/dist-packages/pymysql/cursors.py", line 170, in execute result = self._query(query) File "/usr/lib/python3/dist-packages/pymysql/cursors.py", line 328, in _query conn.query(q) File "/usr/lib/python3/dist-packages/pymysql/connections.py", line 517, in query self._affected_rows = self._read_query_result(unbuffered=unbuffered) File "/usr/lib/python3/dist-packages/pymysql/connections.py", line 732, in _read_query_result result.read() File "/usr/lib/python3/dist-packages/pymysql/connections.py", line 1075, in read first_packet = self.connection._read_packet() File "/usr/lib/python3/dist-packages/pymysql/connections.py", line 684, in _read_packet packet.check_error() File "/usr/lib/python3/dist-packages/pymysql/protocol.py", line 220, in check_error err.raise_mysql_exception(self._data) File "/usr/lib/python3/dist-packages/pymysql/err.py", line 109, in raise_mysql_exception raise errorclass(errno, errval) peewee.InternalError: (1066, "Not unique table/alias: 't2'") ``` The query string-serializes to: ``` SELECT `t1`.`id`, `t1`.`deployment`, `t1`.`dataset`, `t1`.`openvpn`, `t1`.`wireguard`, `t1`.`manufacturer`, `t1`.`created`, `t1`.`configured`, `t1`.`operating_system`, `t1`.`monitor`, `t1`.`serial_number`, `t1`.`model`, `t1`.`last_sync` FROM `hwdb`.`system` AS `t1` LEFT OUTER JOIN `hwdb`.`deployment` AS `t2` ON (`t1`.`deployment` = `t2`.`id`) LEFT OUTER JOIN `hwdb`.`deployment` AS `t2` ON (`t1`.`dataset` = `t2`.`id`) ``` As you can see, peewee assigned `t2` two times. If I manually edit the query to change the second definition of `t2` to `t3` it works as intended. How can I make this join work in peewee? As a follow-up question: How can I write the subsequent `WHERE` clause to match either `t2` or `t3`? A simple `.where(Deployment.attribute == value)` won't suffice, since I want to match explicitely either the deployment from `System.deployment` or `System.dataset`. Thank you.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2272/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2272/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2271
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2271/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2271/comments
https://api.github.com/repos/coleifer/peewee/issues/2271/events
https://github.com/coleifer/peewee/issues/2271
704,614,498
MDU6SXNzdWU3MDQ2MTQ0OTg=
2,271
Request: Option to disable numbered table name aliases (t1, t2, t3... etc)
{ "login": "ibushong", "id": 9298422, "node_id": "MDQ6VXNlcjkyOTg0MjI=", "avatar_url": "https://avatars.githubusercontent.com/u/9298422?v=4", "gravatar_id": "", "url": "https://api.github.com/users/ibushong", "html_url": "https://github.com/ibushong", "followers_url": "https://api.github.com/users/ibushong/followers", "following_url": "https://api.github.com/users/ibushong/following{/other_user}", "gists_url": "https://api.github.com/users/ibushong/gists{/gist_id}", "starred_url": "https://api.github.com/users/ibushong/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/ibushong/subscriptions", "organizations_url": "https://api.github.com/users/ibushong/orgs", "repos_url": "https://api.github.com/users/ibushong/repos", "events_url": "https://api.github.com/users/ibushong/events{/privacy}", "received_events_url": "https://api.github.com/users/ibushong/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I don't have any plans to add such, but you are welcome to write a monkey-patch for AliasManager.add and maintain it separately for your own debugging purposes." ]
2020-09-18T19:46:15
2020-09-18T20:13:45
2020-09-18T20:13:45
NONE
null
Is it possible to add an option to disable the automatic mapping of table names to numbered aliases? When debugging/reading raw queries, it's much easier to read something like ``WHERE (`mytable`.`name` == 'foo')`` instead of ``WHERE (`t3`.`name` == 'foo')`` quick hack: ```python class AliasManager(object): ... def add(self, source): if source not in self.mapping: self._counter += 1 # ORIGINAL self[source] = 't%d' % self._counter self[source] = source.__name__ return self.mapping[source] ``` The only side effect of this (in my application at least, which is by no means exhaustive) is that I have to add an explicit alias for any uses of `Table.alias()`, e.g. `Table.alias('mytable_alias'`) (which I think is probably a good practice anyway).
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2271/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2271/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2270
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2270/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2270/comments
https://api.github.com/repos/coleifer/peewee/issues/2270/events
https://github.com/coleifer/peewee/issues/2270
702,460,602
MDU6SXNzdWU3MDI0NjA2MDI=
2,270
Next result cached in Select.iterator()
{ "login": "jacobian91", "id": 26308586, "node_id": "MDQ6VXNlcjI2MzA4NTg2", "avatar_url": "https://avatars.githubusercontent.com/u/26308586?v=4", "gravatar_id": "", "url": "https://api.github.com/users/jacobian91", "html_url": "https://github.com/jacobian91", "followers_url": "https://api.github.com/users/jacobian91/followers", "following_url": "https://api.github.com/users/jacobian91/following{/other_user}", "gists_url": "https://api.github.com/users/jacobian91/gists{/gist_id}", "starred_url": "https://api.github.com/users/jacobian91/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/jacobian91/subscriptions", "organizations_url": "https://api.github.com/users/jacobian91/orgs", "repos_url": "https://api.github.com/users/jacobian91/repos", "events_url": "https://api.github.com/users/jacobian91/events{/privacy}", "received_events_url": "https://api.github.com/users/jacobian91/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "If you read the peewee code for `CursorWrapper` you will see that peewee is not eagerly fetching anything. The behavior you are seeing is a side-effect of the interaction between pysqlite (the stdlib sqlite driver) and how sqlite operates. You can see that [here](https://github.com/coleifer/pysqlite3/blob/master/src/cursor.c#L710-L772) pysqlite fetches the next row.\r\n\r\nI'd suggest that you're doing something weird and should probably a) read all rows first, or b) not modify them while iterating over the cursor. Ordinarily this isn't a problem if you are using separate connections to do the reading/modifying because this is either completely prevented or, if using wal-mode, the read operates on a snapshot. It only can occur if you're modifying the table and iterating at the same time, which seems problematic for what I hope are obvious reasons.", "Thank you for the quick response! I figured it was something wrong with my understanding of this.\r\n\r\nThankfully I was not building actual code, just experimenting with the details of how the .iterator() worked. I was essentially wanting to see what would happen using different processes, and I didn't know about the other ways this is prevented. Thank you, and great work on this package!" ]
2020-09-16T05:20:54
2020-09-16T15:56:24
2020-09-16T13:19:19
NONE
null
I ran into an unexpected behavior that didn't seem to match what _I assume_ the documentation is saying. In the documentation under [Iterating over large result-sets](http://docs.peewee-orm.com/en/latest/peewee/querying.html#iterating-over-large-result-sets) it states: > To reduce the amount of memory used by peewee when iterating over a query, use the `iterator()` method. This method allows you to iterate without caching each model returned, using much less memory when iterating over large result sets. The way I read that, which may be wrong, is that any changes made to the dataset will be taken into account when the `next()` call is made. However, the result I'm getting is that value produced by `next()` is _cached_ from the previous call, not _retrieved_ during the current call. Here is some minimal code to reproduce and `assert` the values. ```python import peewee database = peewee.SqliteDatabase(":memory:") class BaseModel(peewee.Model): class Meta: database = database class A(BaseModel): """test""" database.create_tables((A,)) # Create three records. for _ in range(3): A.create() assert len(A) == 3 # Sanity check. # Create the generator object. iter_query = A.select().iterator() # Deleting more than 1-next() away doesn't return the record. A.delete_by_id(3) # Deleting record right before next still returns the deleted record. A.delete_by_id(1) assert next(iter_query).id == 1 # Next record returned even though the table is empty. A.delete_by_id(2) assert len(A) == 0 assert next(iter_query).id == 2 # Deleted more than 1-next() away, the record isn't retrieved. try: next(iter_query) assert 0 except StopIteration: print("Stop Reached") ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2270/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2270/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2269
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2269/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2269/comments
https://api.github.com/repos/coleifer/peewee/issues/2269/events
https://github.com/coleifer/peewee/issues/2269
702,460,112
MDU6SXNzdWU3MDI0NjAxMTI=
2,269
Saving `only` no fields saves all fields.
{ "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
[ "Thanks, I've made the change as suggested (although it is `if only is not None`). Peewee is active-record so calling save with no data will raise a `ValueError`." ]
2020-09-16T05:19:45
2020-09-16T12:53:08
2020-09-16T12:52:41
NONE
null
## The issue I use the pattern of saving only fields that have changed in a model, as such: ```python obj.save(only=obj.dirty_fields) ``` However, if the `dirty_fields` value is an empty list, I would expect `save()` to save _no_ fields (i.e., be a no-op.) Instead, it saves _all_ the fields, which is counter-intuitive and can lead to problems if I don't explicitly check for an empty list. I believe the issue is in the line below: https://github.com/coleifer/peewee/blob/ce9375cb4b3fa64560e400932d86e2632c4a0586/peewee.py#L6521 Instead of checking the falseness of `only`, it might be more appropriate to check if it is None: ```python if only is None: ... ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2269/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2269/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2268
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2268/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2268/comments
https://api.github.com/repos/coleifer/peewee/issues/2268/events
https://github.com/coleifer/peewee/issues/2268
701,290,544
MDU6SXNzdWU3MDEyOTA1NDQ=
2,268
Please add support for enums
{ "login": "emdete", "id": 3251523, "node_id": "MDQ6VXNlcjMyNTE1MjM=", "avatar_url": "https://avatars.githubusercontent.com/u/3251523?v=4", "gravatar_id": "", "url": "https://api.github.com/users/emdete", "html_url": "https://github.com/emdete", "followers_url": "https://api.github.com/users/emdete/followers", "following_url": "https://api.github.com/users/emdete/following{/other_user}", "gists_url": "https://api.github.com/users/emdete/gists{/gist_id}", "starred_url": "https://api.github.com/users/emdete/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/emdete/subscriptions", "organizations_url": "https://api.github.com/users/emdete/orgs", "repos_url": "https://api.github.com/users/emdete/repos", "events_url": "https://api.github.com/users/emdete/events{/privacy}", "received_events_url": "https://api.github.com/users/emdete/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I have no plans at present to support this. It should be easy, if you so desire, to implement an `EnumField` as a separate class." ]
2020-09-14T17:29:55
2020-09-14T19:49:21
2020-09-14T19:49:21
NONE
null
Postgresql allows to create enum-types like ``` CREATE TYPE colors AS ENUM ('red', 'green', 'blue'); ``` which is quite useful. Its a feature i really would like to see supported in peewee. Thank you! :)
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2268/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2268/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2267
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2267/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2267/comments
https://api.github.com/repos/coleifer/peewee/issues/2267/events
https://github.com/coleifer/peewee/pull/2267
699,684,538
MDExOlB1bGxSZXF1ZXN0NDg1NDAxMDU3
2,267
Update SQLite max_variable_number info
{ "login": "jonashaag", "id": 175722, "node_id": "MDQ6VXNlcjE3NTcyMg==", "avatar_url": "https://avatars.githubusercontent.com/u/175722?v=4", "gravatar_id": "", "url": "https://api.github.com/users/jonashaag", "html_url": "https://github.com/jonashaag", "followers_url": "https://api.github.com/users/jonashaag/followers", "following_url": "https://api.github.com/users/jonashaag/following{/other_user}", "gists_url": "https://api.github.com/users/jonashaag/gists{/gist_id}", "starred_url": "https://api.github.com/users/jonashaag/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/jonashaag/subscriptions", "organizations_url": "https://api.github.com/users/jonashaag/orgs", "repos_url": "https://api.github.com/users/jonashaag/repos", "events_url": "https://api.github.com/users/jonashaag/events{/privacy}", "received_events_url": "https://api.github.com/users/jonashaag/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Thanks merged an equivalent patch w/slightly different wording." ]
2020-09-11T19:45:50
2020-09-12T00:18:20
2020-09-12T00:18:20
CONTRIBUTOR
null
Missed in #2263
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2267/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2267/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/2267", "html_url": "https://github.com/coleifer/peewee/pull/2267", "diff_url": "https://github.com/coleifer/peewee/pull/2267.diff", "patch_url": "https://github.com/coleifer/peewee/pull/2267.patch", "merged_at": null }
https://api.github.com/repos/coleifer/peewee/issues/2266
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2266/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2266/comments
https://api.github.com/repos/coleifer/peewee/issues/2266/events
https://github.com/coleifer/peewee/issues/2266
699,515,231
MDU6SXNzdWU2OTk1MTUyMzE=
2,266
Support Meta inheritance
{ "login": "jonashaag", "id": 175722, "node_id": "MDQ6VXNlcjE3NTcyMg==", "avatar_url": "https://avatars.githubusercontent.com/u/175722?v=4", "gravatar_id": "", "url": "https://api.github.com/users/jonashaag", "html_url": "https://github.com/jonashaag", "followers_url": "https://api.github.com/users/jonashaag/followers", "following_url": "https://api.github.com/users/jonashaag/following{/other_user}", "gists_url": "https://api.github.com/users/jonashaag/gists{/gist_id}", "starred_url": "https://api.github.com/users/jonashaag/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/jonashaag/subscriptions", "organizations_url": "https://api.github.com/users/jonashaag/orgs", "repos_url": "https://api.github.com/users/jonashaag/repos", "events_url": "https://api.github.com/users/jonashaag/events{/privacy}", "received_events_url": "https://api.github.com/users/jonashaag/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "The meta class is a weird kind of a hack inspired by similar deal in Django. The meta class is not what gets inherited, but instead the \"inheritable\" settings of the Meta class are inherited by the model.\r\n\r\nEx:\r\n\r\n```python\r\n\r\nclass BaseModel(Model):\r\n class Meta:\r\n database = db\r\n\r\nclass Foo(BaseModel):\r\n class Meta:\r\n table_name = 'foo_tbl'\r\n # \"database\" setting is inherited from BaseModel.\r\n```\r\n\r\nThis is described in the documentation for model options and table metadata:\r\n\r\nhttp://docs.peewee-orm.com/en/latest/peewee/models.html#model-options-and-table-metadata", "OK, that works for me, but it's different from Django. https://docs.djangoproject.com/en/3.1/topics/db/models/#meta-inheritance" ]
2020-09-11T16:34:10
2020-09-11T19:09:22
2020-09-11T18:24:52
CONTRIBUTOR
null
Would be nice if this worked: ```py class DefaultMeta: database = db ... class Foo(Model): ... class Meta(DefaultMeta): ... ``` Right now it silently ignores the `DefaultMeta` fields.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2266/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2266/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2265
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2265/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2265/comments
https://api.github.com/repos/coleifer/peewee/issues/2265/events
https://github.com/coleifer/peewee/issues/2265
699,482,941
MDU6SXNzdWU2OTk0ODI5NDE=
2,265
Add support for select clause in bulk_update
{ "login": "jonashaag", "id": 175722, "node_id": "MDQ6VXNlcjE3NTcyMg==", "avatar_url": "https://avatars.githubusercontent.com/u/175722?v=4", "gravatar_id": "", "url": "https://api.github.com/users/jonashaag", "html_url": "https://github.com/jonashaag", "followers_url": "https://api.github.com/users/jonashaag/followers", "following_url": "https://api.github.com/users/jonashaag/following{/other_user}", "gists_url": "https://api.github.com/users/jonashaag/gists{/gist_id}", "starred_url": "https://api.github.com/users/jonashaag/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/jonashaag/subscriptions", "organizations_url": "https://api.github.com/users/jonashaag/orgs", "repos_url": "https://api.github.com/users/jonashaag/repos", "events_url": "https://api.github.com/users/jonashaag/events{/privacy}", "received_events_url": "https://api.github.com/users/jonashaag/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Since you are already explicitly specifying the `model_list` this seems redundant.", "It's not – think of my use case as \"defensive\" bulk updating of an attribute, for example allow only changes to `x` if `x` wasn't ever set and still has its default value of 0.\r\n\r\nI *think* this can be done in Django as follows, but I'm not entirely sure (haven't tried):\r\n\r\n```py\r\nFoo.objects.filter(x=0).bulk_update(foos, ['x'])\r\n```\r\n\r\nAs an alternative, what do you think about factoring out the `Case` builder logic from `bulk_update` into a public helper method so it's easier for people to write their own custom bulk update logic?", "I'm not clear why you would be using bulk_update in that case? Presumably a regular-old update() query would work better?", "Because the `x` may be different for each `Foo`. Say we start with 3 `Foo` in the database, with `x`=0. We do some work that computes 3 new (different!) `x` values, and we want to update all of the `Foo`s with the new `x` values, with a single SQL update statement and in a way that never updates any `x` that were updated by something else while we were computing the new `x` values (race conditions).", "A relational database provides atomicity and isolation, so presumably there's a different way to handle that. I think this is a rather obscure usage because it implies that you are updating values from a list of models, but also that some of those models may be \"out-of-sync\". This, to me, is not an API failure but rather a result of trying to shoehorn some logic into a process that would be better handled another way.", "Isn't the scenario simply a case of a more general version of optimistic locking as described in the docs? http://docs.peewee-orm.com/en/latest/peewee/hacks.html#optimistic-locking There we have a version column, and no bulk update; here we have a non-version column with bulk update." ]
2020-09-11T15:59:56
2020-09-11T19:31:54
2020-09-11T19:07:30
CONTRIBUTOR
null
Add support for optional select clause in `bulk_update`, for example to allow for something like ```py foos = [... list of Foos ...] # Only allow updates to x when x=0. nchanged = Foo.bulk_update(foos, [Foo.x], q=(Foo.x == 0)) if nchanged != len(foos): raise Error("Some Foos had x != 0") ``` I quickly hacked this together like this, and it seems to work. ```py def bulk_update(cls, model_list, fields, batch_size=None, q=None): ... query = ( cls.update(update) .where(cls._meta.primary_key.in_(id_list)) ) if q is not None: query = query.where(q) n += query.execute() return n ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2265/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2265/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2264
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2264/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2264/comments
https://api.github.com/repos/coleifer/peewee/issues/2264/events
https://github.com/coleifer/peewee/issues/2264
698,467,451
MDU6SXNzdWU2OTg0Njc0NTE=
2,264
Limit on backrefs ?
{ "login": "hrishikeshrt", "id": 62871, "node_id": "MDQ6VXNlcjYyODcx", "avatar_url": "https://avatars.githubusercontent.com/u/62871?v=4", "gravatar_id": "", "url": "https://api.github.com/users/hrishikeshrt", "html_url": "https://github.com/hrishikeshrt", "followers_url": "https://api.github.com/users/hrishikeshrt/followers", "following_url": "https://api.github.com/users/hrishikeshrt/following{/other_user}", "gists_url": "https://api.github.com/users/hrishikeshrt/gists{/gist_id}", "starred_url": "https://api.github.com/users/hrishikeshrt/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/hrishikeshrt/subscriptions", "organizations_url": "https://api.github.com/users/hrishikeshrt/orgs", "repos_url": "https://api.github.com/users/hrishikeshrt/repos", "events_url": "https://api.github.com/users/hrishikeshrt/events{/privacy}", "received_events_url": "https://api.github.com/users/hrishikeshrt/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Just define which models or foreign-keys to exclude and they won't be traversed. Alternatively, you can explicitly implement your serialization strategy.", "Oh wait, I think I understand now -- no, this is something you will probably want to implement in a custom serializer if you want to control how the back-references are also queried.", "Alright, thank you.\r\nI am currently doing it as follows,\r\n\r\n`occurrences` is my `backref`\r\n\r\n```\r\n _result = MyModel.select().where(conditions).limit(limit)\r\n results = []\r\n for _result in _results:\r\n result = model_to_dict(_result)\r\n result['occurences'] = [\r\n model_to_dict(occurence, backrefs=True)\r\n for occurence in _result.occurences.limit(limit)\r\n ]\r\n results.append(result)\r\n```\r\n\r\nI suppose this is the proper / (only?) way then?", "That's perfectly fine way, and what I would probably do as well. The next step up would be a dedicated serialization library." ]
2020-09-10T20:39:47
2020-09-10T21:46:24
2020-09-10T20:54:37
NONE
null
When using `model_to_dict on` a model with possibly a large number of `backrefs`, could there be an argument to `model_to_dict` which limits the number of entries in any back reference to the given value? (or any alternate way to achieve the same.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2264/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2264/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2263
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2263/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2263/comments
https://api.github.com/repos/coleifer/peewee/issues/2263/events
https://github.com/coleifer/peewee/pull/2263
697,913,966
MDExOlB1bGxSZXF1ZXN0NDgzODA5NDM5
2,263
Update SQLite max_variable_number info
{ "login": "jonashaag", "id": 175722, "node_id": "MDQ6VXNlcjE3NTcyMg==", "avatar_url": "https://avatars.githubusercontent.com/u/175722?v=4", "gravatar_id": "", "url": "https://api.github.com/users/jonashaag", "html_url": "https://github.com/jonashaag", "followers_url": "https://api.github.com/users/jonashaag/followers", "following_url": "https://api.github.com/users/jonashaag/following{/other_user}", "gists_url": "https://api.github.com/users/jonashaag/gists{/gist_id}", "starred_url": "https://api.github.com/users/jonashaag/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/jonashaag/subscriptions", "organizations_url": "https://api.github.com/users/jonashaag/orgs", "repos_url": "https://api.github.com/users/jonashaag/repos", "events_url": "https://api.github.com/users/jonashaag/events{/privacy}", "received_events_url": "https://api.github.com/users/jonashaag/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[]
2020-09-10T12:50:58
2020-09-10T13:58:03
2020-09-10T13:58:02
CONTRIBUTOR
null
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2263/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2263/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/2263", "html_url": "https://github.com/coleifer/peewee/pull/2263", "diff_url": "https://github.com/coleifer/peewee/pull/2263.diff", "patch_url": "https://github.com/coleifer/peewee/pull/2263.patch", "merged_at": "2020-09-10T13:58:02" }
https://api.github.com/repos/coleifer/peewee/issues/2262
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2262/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2262/comments
https://api.github.com/repos/coleifer/peewee/issues/2262/events
https://github.com/coleifer/peewee/issues/2262
697,050,414
MDU6SXNzdWU2OTcwNTA0MTQ=
2,262
'Playhouse" Feature request: Add support for Postgresql Range types
{ "login": "bjmc", "id": 328557, "node_id": "MDQ6VXNlcjMyODU1Nw==", "avatar_url": "https://avatars.githubusercontent.com/u/328557?v=4", "gravatar_id": "", "url": "https://api.github.com/users/bjmc", "html_url": "https://github.com/bjmc", "followers_url": "https://api.github.com/users/bjmc/followers", "following_url": "https://api.github.com/users/bjmc/following{/other_user}", "gists_url": "https://api.github.com/users/bjmc/gists{/gist_id}", "starred_url": "https://api.github.com/users/bjmc/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/bjmc/subscriptions", "organizations_url": "https://api.github.com/users/bjmc/orgs", "repos_url": "https://api.github.com/users/bjmc/repos", "events_url": "https://api.github.com/users/bjmc/events{/privacy}", "received_events_url": "https://api.github.com/users/bjmc/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "No plans to support this, but feel free to implement as a 3rd-party extension." ]
2020-09-09T18:33:12
2020-09-09T19:00:27
2020-09-09T19:00:27
NONE
null
Postgresql range types [are fantastic](https://wiki.postgresql.org/images/7/73/Range-types-pgopen-2012.pdf) and it would be great to be able to use them directly in Peewee.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2262/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2262/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2261
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2261/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2261/comments
https://api.github.com/repos/coleifer/peewee/issues/2261/events
https://github.com/coleifer/peewee/issues/2261
690,955,225
MDU6SXNzdWU2OTA5NTUyMjU=
2,261
Question: get chagnes
{ "login": "mrquokka", "id": 36193265, "node_id": "MDQ6VXNlcjM2MTkzMjY1", "avatar_url": "https://avatars.githubusercontent.com/u/36193265?v=4", "gravatar_id": "", "url": "https://api.github.com/users/mrquokka", "html_url": "https://github.com/mrquokka", "followers_url": "https://api.github.com/users/mrquokka/followers", "following_url": "https://api.github.com/users/mrquokka/following{/other_user}", "gists_url": "https://api.github.com/users/mrquokka/gists{/gist_id}", "starred_url": "https://api.github.com/users/mrquokka/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/mrquokka/subscriptions", "organizations_url": "https://api.github.com/users/mrquokka/orgs", "repos_url": "https://api.github.com/users/mrquokka/repos", "events_url": "https://api.github.com/users/mrquokka/events{/privacy}", "received_events_url": "https://api.github.com/users/mrquokka/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I'm not sure how to answer this, but I'd suggest providing examples and asking on stackoverflow. This sounds more like a question rather than a peewee-specific issue." ]
2020-09-02T11:49:26
2020-09-02T12:41:30
2020-09-02T12:41:30
NONE
null
I look for orm with work with save steps to apply it later. I need to get all changes what happend on python, but dont sended to database. Can i get simular of this?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2261/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2261/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2260
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2260/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2260/comments
https://api.github.com/repos/coleifer/peewee/issues/2260/events
https://github.com/coleifer/peewee/issues/2260
690,886,126
MDU6SXNzdWU2OTA4ODYxMjY=
2,260
bulk_update() generated SQL with high number of SQL variables
{ "login": "CarstenGrohmann", "id": 4849907, "node_id": "MDQ6VXNlcjQ4NDk5MDc=", "avatar_url": "https://avatars.githubusercontent.com/u/4849907?v=4", "gravatar_id": "", "url": "https://api.github.com/users/CarstenGrohmann", "html_url": "https://github.com/CarstenGrohmann", "followers_url": "https://api.github.com/users/CarstenGrohmann/followers", "following_url": "https://api.github.com/users/CarstenGrohmann/following{/other_user}", "gists_url": "https://api.github.com/users/CarstenGrohmann/gists{/gist_id}", "starred_url": "https://api.github.com/users/CarstenGrohmann/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/CarstenGrohmann/subscriptions", "organizations_url": "https://api.github.com/users/CarstenGrohmann/orgs", "repos_url": "https://api.github.com/users/CarstenGrohmann/repos", "events_url": "https://api.github.com/users/CarstenGrohmann/events{/privacy}", "received_events_url": "https://api.github.com/users/CarstenGrohmann/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "This is why the `batch_size` is exposed. Performing bulk updates necessarily involves a lot of variables because you essentially have to provide a mapping from each primary-key to the values that are to be updated. I don't know of any other way to do this when each row may have a different value.\r\n\r\nNot a bug, that's simply how it works.\r\n\r\nWith sqlite you can probably just as efficiently open a transaction and apply the updates one-at-a-time." ]
2020-09-02T09:57:25
2020-09-02T12:49:35
2020-09-02T12:49:34
NONE
null
Hello Charles, I'm still working on my mass updates. Now I've trouble with the maximum numbers of variables in a SQLite statement. If I use `Model.bulk_update(batch_size=800)` my code raises ```OperationalError: too many SQL variables```. If I use `Model.update()` with same number of items all works fine. I looked at the generated SQL statements and found that `bulk_update()` uses 9 SQL variables and `update()` only three. I'm surprised about the difference even if I'm about that I work with programatically generated SQL statements. Currently `bulk_update()` is usable in show scenario with small chunk sizes only. Is this behavior desired? Is it possible to rework the query with `bulk_update()` so that it needs significantly less variables? ## Statement with Model.update() ``` >>> query = TestInStmt.update(num=2).where(TestInStmt.text.in_(['A', 'B', 'C'])) DEBUG:peewee:('UPDATE "testinstmt" SET "num" = ? WHERE ("testinstmt"."text" IN (?, ?, ?))', [2, u'A', u'B', u'C']) ``` ## Statement with Model.bulk_update() ``` >>> TestInStmt.bulk_update([b1, b2, b3], [TestInStmt.num]) DEBUG:peewee:('UPDATE "testinstmt" SET "num" = CASE "testinstmt"."id" WHEN ? THEN ? WHEN ? THEN ? WHEN ? THEN ? END WHERE ("testinstmt"."id" IN (?, ?, ?))', [16, 42, 17, 4711, 18, 1111, 16, 17, 18]) ``` ## Minimal example: ``` from peewee import * import logging logging.basicConfig(level=logging.DEBUG) db = SqliteDatabase('test.sqlite') class TestInStmt(Model): class Meta: database = db num = IntegerField() text = TextField() db.create_tables([TestInStmt]) b1 = TestInStmt.create(num=1, text='A') b2 = TestInStmt.create(num=2, text='B') b3 = TestInStmt.create(num=3, text='C') query = TestInStmt.update(num=2).where(TestInStmt.text.in_(['A', 'B', 'C'])) query.execute() b1.num = 42 b2.num = 4711 b3.num = 1111 TestInStmt.bulk_update([b1, b2, b3], [TestInStmt.num]) ``` ``` DEBUG:peewee:('CREATE TABLE IF NOT EXISTS "testinstmt" ("id" INTEGER NOT NULL PRIMARY KEY, "num" INTEGER NOT NULL, "text" TEXT NOT NULL)', []) DEBUG:peewee:('INSERT INTO "testinstmt" ("num", "text") VALUES (?, ?)', [1, u'A']) DEBUG:peewee:('INSERT INTO "testinstmt" ("num", "text") VALUES (?, ?)', [2, u'B']) DEBUG:peewee:('INSERT INTO "testinstmt" ("num", "text") VALUES (?, ?)', [3, u'C']) DEBUG:peewee:('UPDATE "testinstmt" SET "num" = ? WHERE ("testinstmt"."text" IN (?, ?, ?))', [2, u'A', u'B', u'C']) DEBUG:peewee:('UPDATE "testinstmt" SET "num" = CASE "testinstmt"."id" WHEN ? THEN ? WHEN ? THEN ? WHEN ? THEN ? END WHERE ("testinstmt"."id" IN (?, ?, ?))', [19, 42, 20, 4711, 21, 1111, 19, 20, 21]) ``` Regards, Carsten
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2260/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2260/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2259
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2259/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2259/comments
https://api.github.com/repos/coleifer/peewee/issues/2259/events
https://github.com/coleifer/peewee/issues/2259
690,141,053
MDU6SXNzdWU2OTAxNDEwNTM=
2,259
Hybrid properties and insert_many
{ "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
[ "Can you produce a test-case that illustrates what you believe to be the problem? Without seeing what the order dicts look like it's hard to say.", "I'm a little confused as to how to reproduce this bug or what exactly your intent is. The whole reason to use a hybrid property is to express a computation (or scalar function) that would be useful both on a model instance and when querying against a model class. A setter is only assignable on an instance, not on a class. So what you really want is just a regular property, if I understand correctly. A reason this seems to work on `create()` but not `insert_many()` (I'm inferring this is why you're confused) is because when a model is instantiated the keyword args are applied to the instance, which has the effect (in your example) of setting the value.\r\n\r\nSince you are storing your timestamp in the database as a date-time field, then it seems to me that you are going through all this trouble just to set the field to a datetime during creation. This isn't at all the purpose of hybrid properties. See the [documentation](http://docs.peewee-orm.com/en/latest/peewee/playhouse.html#hybrid-attributes) for examples.", "Apologies, I posted this and went to bed, which is why I didn't respond until many hours later. Clearly you run a very tight ship here! :blush: \r\n\r\n> So what you really want is just a regular property, if I understand correctly.\r\n\r\nYes, I think you have understood correctly and I may have misunderstood the purpose of a **hybrid** property needing to be useful both on a model instance and class.\r\n\r\n> A reason this seems to work on `create()` but not `insert_many()` (I'm inferring this is why you're confused) is because when a model is instantiated the keyword args are applied to the instance, which has the effect (in your example) of setting the value.\r\n\r\nCorrect again. So if I define a regular property, will `insert_many()` invoke it when attempting to insert each row?\r\n\r\nMy intent here is hopefully clear by now: to house simple conversion logic in the peewee model, as it is clearly the best place to implement an abstraction layer between code using millisecond epoch integers and a database requiring timestamps. Obviously this is possible with model by model instantiation, but I'm wondering if the **bulk** operations in peewee would see it work the same way?\r\n\r\nThe reasoning behind this is that my data processing code doesn't deal with the specifics of any model - its purpose is largely to receive data from one source and put it in the database - so it is written generically to handle multiple arbitrary source/model pairs. I planned to put the small conversion logic needed between source and database format in the peewee models as properties. I receive data in blocks of 100,000 rows so figured it was most efficient to use `insert_many` under `with db.atomic():`. Now I realise that `insert_many` won't invoke the property logic?\r\n\r\nShould it?\r\n\r\nIn short, I am trying to combine the convenience of 'upsert' type functionality with properties and the speed improvements suggested in the documentation at https://docs.peewee-orm.com/en/3.4.0/peewee/querying.html#bulk-inserts ... perhaps that's not possible?", "It seems like the most important thing you want to achieve is simply converting a ms timestamp to a datetime. This can be done by:\r\n\r\n1. subclassing a field and implementing a `db_value()` method that converts the timestamp to a datetime\r\n2. pre-processing your data\r\n\r\nSince it's specific to your data-source, it seems to me that you're better of pre-processing these timestamps - but that's up to you. See how `TimestampField` is implemented if you're curious.", "Of course you are right in this scenario, however the example I gave was just a small one. \r\n\r\nIt reality, the task is far greater - for example a lot of the input data needs simple changes (like this one) or code lookups. \r\n\r\nI can appreciate your thinking \"why don't you simply pre-process your data?!\", but for me it is about design elegance and common sense co-location of code: if I already have to enumerate a data model for Peewee, the most sensible place to perform minor field specific tranformations is in that same space - as opposed to having a code block someplace else that picks through fields and does transformations before data gets to peewee.\r\n\r\nIn my view of things, if peewee related code can do 'all things data', code in my other files can simply focus on using peewee at the model level, without bloating over field manipulations.\r\n\r\nJust my view.\r\n\r\nThanks for your help! I may end up subclassing fields as you say, and detecting the field name and selectively transforming it based on model name and field name outsourced to a YAML config file or similar ... sounds more complicated / less elegant than what I was originally thinking but ... ", "Tightly coupling my bulk-loading code (a 1-time operation) with my model code is exactly the kind of thing I would avoid. I'd write a function to process the data.", "Oh I see, you see your bulk loading code as a 1 time operation, which is likely true for a lot of cases. In my case, its happening every couple of minutes...which is why my original code had an `on_conflict` part. So for me that processing has to happen somewhere, it's just a matter of where. \r\n\r\nI see your point of view-I may just end up writing a simple configurable transformation engine then.", "It's a write-once operation." ]
2020-09-01T13:25:09
2020-09-05T00:33:07
2020-09-01T20:05:19
NONE
null
Hello, Peewee **rocks**. I use it everywhere I go! Really hoping this isn't a facepalm moment for me but here goes ... I have a model with a hybrid property: ``` class Order(BaseModel): id = IntegerField(primary_key = True) _time_setup_msc = DateTimeField() @hybrid.hybrid_property def time_setup_msc(self): return self._time_setup_msc @time_setup_msc.setter def set_time_setup_msc(self, time_setup_msc): self._time_setup_msc = datetime.utcfromtimestamp(time_setup_msc/1000) ``` With data stored in a list of dicts in `orders`, I then attempt to do: ``` Order.insert_many(orders).on_conflict(conflict_target=[Order.id], update=Order._meta.fields).execute() ``` Peewee returns an error from the postgres database: ``` peewee.IntegrityError: null value in column "_time_setup_msc" violates not-null constraint ``` So it appears that `insert_many` is not invoking the hybrid property setter to generate each insertion? I was kinda expecting this to be done for me in this situation, but perhaps its up to me to use `dict_to_model`? Will that properly invoke the setter method? Perhaps I've missed or stuffed something? :worried:
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2259/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2259/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2258
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2258/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2258/comments
https://api.github.com/repos/coleifer/peewee/issues/2258/events
https://github.com/coleifer/peewee/issues/2258
689,496,029
MDU6SXNzdWU2ODk0OTYwMjk=
2,258
Is it possible to modify the columns for a TableFunction in SQLite at runtime?
{ "login": "pacuna", "id": 1724136, "node_id": "MDQ6VXNlcjE3MjQxMzY=", "avatar_url": "https://avatars.githubusercontent.com/u/1724136?v=4", "gravatar_id": "", "url": "https://api.github.com/users/pacuna", "html_url": "https://github.com/pacuna", "followers_url": "https://api.github.com/users/pacuna/followers", "following_url": "https://api.github.com/users/pacuna/following{/other_user}", "gists_url": "https://api.github.com/users/pacuna/gists{/gist_id}", "starred_url": "https://api.github.com/users/pacuna/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/pacuna/subscriptions", "organizations_url": "https://api.github.com/users/pacuna/orgs", "repos_url": "https://api.github.com/users/pacuna/repos", "events_url": "https://api.github.com/users/pacuna/events{/privacy}", "received_events_url": "https://api.github.com/users/pacuna/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Not really, look at the docs for the sqlite virtual table interface if you're curious how it works:\r\n\r\nhttps://sqlite.org/vtab.html\r\n\r\nThe virtual table, when registered, has to declare it's structure." ]
2020-08-31T20:47:20
2020-08-31T20:51:04
2020-08-31T20:51:03
NONE
null
I'm trying to create a table function that generates columns depending on the input. For example if the input is `("a", 1, "b", 2)` it should generate columns **a** and **b** with values **1** and **2**. My code is working but I have to hardcode the columns in the class variable `columns` and I can't modify it after. Is there a way to accomplish this? Thanks.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2258/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2258/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2257
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2257/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2257/comments
https://api.github.com/repos/coleifer/peewee/issues/2257/events
https://github.com/coleifer/peewee/issues/2257
688,678,285
MDU6SXNzdWU2ODg2NzgyODU=
2,257
Model.update() fails for BitFields if using flags
{ "login": "CarstenGrohmann", "id": 4849907, "node_id": "MDQ6VXNlcjQ4NDk5MDc=", "avatar_url": "https://avatars.githubusercontent.com/u/4849907?v=4", "gravatar_id": "", "url": "https://api.github.com/users/CarstenGrohmann", "html_url": "https://github.com/CarstenGrohmann", "followers_url": "https://api.github.com/users/CarstenGrohmann/followers", "following_url": "https://api.github.com/users/CarstenGrohmann/following{/other_user}", "gists_url": "https://api.github.com/users/CarstenGrohmann/gists{/gist_id}", "starred_url": "https://api.github.com/users/CarstenGrohmann/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/CarstenGrohmann/subscriptions", "organizations_url": "https://api.github.com/users/CarstenGrohmann/orgs", "repos_url": "https://api.github.com/users/CarstenGrohmann/repos", "events_url": "https://api.github.com/users/CarstenGrohmann/events{/privacy}", "received_events_url": "https://api.github.com/users/CarstenGrohmann/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "The flags is a descriptor which, when no instance is present (e.g. accessing `BitTest.F_4`) returns an expression equivalent to `BitTest.flags & 4 != 0` which is useful for testing truthiness. What we would need to support your example is to detect that the flag bit is being used in the left-hand side of a set operation -- and this is going to be quite tricky I think.\r\n\r\nFor now, what you want is:\r\n\r\n```python\r\n\r\n# clear bit\r\nBitTest.update(flags=BitTest.flags & ~8)\r\n\r\n# set bit\r\nBitTest.update(flags=BitTest.flags | 8)\r\n```\r\n\r\nI'm going to think about this, thanks for the report.", "The API I have come up with is:\r\n\r\n```python\r\n\r\n# Set the \"is_8\" bit:\r\nBitTest.update(flags=BitTest.is_8.set())\r\n\r\n# Clear the \"is_8\" bit:\r\nBitTest.update(flags=BitTest.is_8.clear())\r\n```\r\n\r\nThis change is merged into master.", "The changes are great. \r\n\r\nThank you!" ]
2020-08-30T08:31:41
2020-09-01T13:56:28
2020-08-31T13:50:54
NONE
null
I use peewee in an application with millions of objects. I would use `Model.update()` for an effective mass update instead of creating objects and running `Model.bulk_update()`. Currently peewee generates wrong SQL statements for BitFields with flags: ``` >>> queue = BitTest.update(is_8=False) >>> queue.sql() ('UPDATE "bittest" SET (("flags" & ?) != ?) = ?', [8, 0, True]) >>> queue.execute() peewee.OperationalError: near "(": syntax error ``` ## Test with SQLite CLI ``` # sqlite3 test.sqlite SQLite version 3.7.17 2013-05-20 00:56:22 Enter ".help" for instructions Enter SQL statements terminated with a ";" sqlite> SELECT * FROM "bittest"; 1|4 2|2 sqlite> UPDATE "bittest" SET (("flags" & 8) != 0) = True; Error: near "(": syntax error sqlite> UPDATE "bittest" SET flags = flags | 8; sqlite> SELECT * FROM "bittest"; 1|12 2|10 sqlite> ``` ## Complete example ``` from peewee import * db = SqliteDatabase('test.sqlite') class BitTest(Model): class Meta: database = db id = IntegerField() F_0 = 0 F_1 = 2 ** 0 F_2 = 2 ** 1 F_4 = 2 ** 2 F_8 = 2 ** 3 flags = BitField(default=0) is_0 = flags.flag(F_0) is_1 = flags.flag(F_1) is_2 = flags.flag(F_2) is_4 = flags.flag(F_4) is_8 = flags.flag(F_8) db.create_tables([BitTest]) b1 = BitTest.create(id=1, flags=BitTest.F_1) b2 = BitTest.create(id=2, flags=BitTest.F_1) print "\n" print """Test 1 run: "BitTest.update(flags=BitTest.F_2)" """ query = BitTest.update(flags=BitTest.F_2) print "Generated SQL: ", query.sql() try: query.execute() except OperationalError as e: print "Update failed: %s" % e else: print "Update executed" print "\n" print """Test 2 run: "BitTest.update(flags=BitTest.F_4).where(BitTest.id == 1)" """ query = BitTest.update(flags=BitTest.F_4).where(BitTest.id == 1) print "Generated SQL: ", query.sql() try: query.execute() except OperationalError as e: print "Update failed: %s" % e else: print "Update executed" print "\n" print """Test 3 run: "BitTest.update(is_8=True)" """ query = BitTest.update(is_8=True) print "Generated SQL: ", query.sql() try: query.execute() except OperationalError as e: print "Update failed: %s" % e else: print "Update executed" print "\n" print """Test 4 run: "BitTest.update(is_8=False)" """ query = BitTest.update(is_8=False) print "Generated SQL: ", query.sql() try: query.execute() except OperationalError as e: print "Update failed: %s" % e else: print "Update executed" ``` ## Output example ``` # ./test_syntax.py Test 1 run: "BitTest.update(flags=BitTest.F_2)" Generated SQL: ('UPDATE "bittest" SET "flags" = ?', [2]) Update executed Test 2 run: "BitTest.update(flags=BitTest.F_4).where(BitTest.id == 1)" Generated SQL: ('UPDATE "bittest" SET "flags" = ? WHERE ("bittest"."id" = ?)', [4, 1]) Update executed Test 3 run: "BitTest.update(is_8=True)" Generated SQL: ('UPDATE "bittest" SET (("flags" & ?) != ?) = ?', [8, 0, True]) Update failed: near "(": syntax error Test 4 run: "BitTest.update(is_8=False)" Generated SQL: ('UPDATE "bittest" SET (("flags" & ?) != ?) = ?', [8, 0, False]) Update failed: near "(": syntax error ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2257/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2257/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2256
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2256/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2256/comments
https://api.github.com/repos/coleifer/peewee/issues/2256/events
https://github.com/coleifer/peewee/issues/2256
688,109,705
MDU6SXNzdWU2ODgxMDk3MDU=
2,256
Adding a new ForeignKeyField to an existing model gives an error
{ "login": "fmors", "id": 1216208, "node_id": "MDQ6VXNlcjEyMTYyMDg=", "avatar_url": "https://avatars.githubusercontent.com/u/1216208?v=4", "gravatar_id": "", "url": "https://api.github.com/users/fmors", "html_url": "https://github.com/fmors", "followers_url": "https://api.github.com/users/fmors/followers", "following_url": "https://api.github.com/users/fmors/following{/other_user}", "gists_url": "https://api.github.com/users/fmors/gists{/gist_id}", "starred_url": "https://api.github.com/users/fmors/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/fmors/subscriptions", "organizations_url": "https://api.github.com/users/fmors/orgs", "repos_url": "https://api.github.com/users/fmors/repos", "events_url": "https://api.github.com/users/fmors/events{/privacy}", "received_events_url": "https://api.github.com/users/fmors/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Peewee does not have any automatic schema migration when you change a model definition. You can write migrations quite easily using the playhouse extension:\r\n\r\nhttp://docs.peewee-orm.com/en/latest/peewee/playhouse.html#migrate\r\n\r\nDo I understand correctly that you're describing:\r\n\r\n1. changed your model definition\r\n2. ran `create_tables()`\r\n3. table already existed, but then the index is attempted to be added\r\n4. error occurs because the column does not exist\r\n\r\nIf that's the case then I'd propose this isn't a bug, but rather that you should migrate your schema up beforehand.", "That's right, indeed by migrating the schema before anything (including creating any new tables beforehand), the create_tables() thing will when work correctly. Thanks!" ]
2020-08-28T14:19:55
2020-08-28T15:21:17
2020-08-28T15:21:17
NONE
null
I've noticed that, when you add a new field to an already existing model, it will try to do all steps to create a table: 1. create sequences 2. create table (proper) 3. create indexes However, the "safe" parameter will make sure that the schema of the table itself will not be changed (after all, the table exists). As a result, the new field will not be created. The migrator does a good job creating the fields that you need. But, if the field is a ForeignKeyField, it will try to create an index for that field (step 3 above). Because the field was not created on step 2, we will have an SQL error about a non-existing field. Maybe there should be a check if the field exists before trying to create the index. Because it is a new field that will be dealt by the migration steps (using the SchemaMigrator), the index creation should also be done at around this moment.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2256/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2256/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2255
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2255/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2255/comments
https://api.github.com/repos/coleifer/peewee/issues/2255/events
https://github.com/coleifer/peewee/issues/2255
688,070,320
MDU6SXNzdWU2ODgwNzAzMjA=
2,255
question: Aborted transaction is not being rolled back and connection closed after conflict handling
{ "login": "madMathematician971", "id": 63659861, "node_id": "MDQ6VXNlcjYzNjU5ODYx", "avatar_url": "https://avatars.githubusercontent.com/u/63659861?v=4", "gravatar_id": "", "url": "https://api.github.com/users/madMathematician971", "html_url": "https://github.com/madMathematician971", "followers_url": "https://api.github.com/users/madMathematician971/followers", "following_url": "https://api.github.com/users/madMathematician971/following{/other_user}", "gists_url": "https://api.github.com/users/madMathematician971/gists{/gist_id}", "starred_url": "https://api.github.com/users/madMathematician971/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/madMathematician971/subscriptions", "organizations_url": "https://api.github.com/users/madMathematician971/orgs", "repos_url": "https://api.github.com/users/madMathematician971/repos", "events_url": "https://api.github.com/users/madMathematician971/events{/privacy}", "received_events_url": "https://api.github.com/users/madMathematician971/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I cannot replicate this and I believe it is peculiar to aws lambda. Also I'm not sure why you have autocommit/autorollback enabled -- autocommit is deprecated (no-op) and displays a warning. If you have auto-rollback enabled then you don't need to roll-back in the except block (although doing so won't hurt anything, it's unnecessary). If you're catching the IntegrityError then the try/except properly goes outside the transaction.\r\n\r\nThat being said, I've tried to replicate your script, as well as some things you didn't cover, and everything works fine for me:\r\n\r\n```python\r\n\r\ndb = PostgresqlDatabase('peewee_test', autocommit=True, autorollback=True)\r\n\r\nclass Reg(Model):\r\n key = TextField(unique=True)\r\n class Meta:\r\n database = db\r\n\r\ndb.connect()\r\ndb.create_tables([Reg])\r\n\r\nwith db.atomic():\r\n Reg.create(key='k1')\r\n\r\ntry:\r\n with db.atomic():\r\n Reg.create(key='k1')\r\nexcept IntegrityError:\r\n print('received integrity error as expected')\r\n\r\n# try/except inside tx block\r\nwith db.atomic():\r\n try:\r\n Reg.create(key='k1')\r\n except IntegrityError:\r\n print('received 2nd integrity error as expected')\r\n\r\n# Explicit rollback.\r\nwith db.atomic() as tx:\r\n Reg.create(key='k2')\r\n tx.rollback()\r\n\r\n# Implicit commit.\r\nwith db.atomic() as tx:\r\n Reg.create(key='k3')\r\n\r\n# Should print k1, k3\r\nfor row in Reg:\r\n print(row.key)\r\n\r\ndb.drop_tables([Reg])\r\n```\r\n\r\nOutput:\r\n\r\n```\r\nreceived integrity error as expected\r\nreceived 2nd integrity error as expected\r\nk1\r\nk3 \r\n```", "Solved the issue.\r\n\r\nIf anyone comes across such behavior on AWS Lambda and **using OOP** - **just delete your class instances that initiated the connection to the database** after you've handled the IntegtityError raised by peewee. For some reason if a class instance is not deleted explicitly by calling `del instance_name` - the connection will be held open and blocking you from establishing new ones untill a complete update of Lambda code. The session with an aborted transaction will get dropped and database will be no longer locked for new connections/transactions.\r\n\r\nNOT A LIBRARY ISSUE" ]
2020-08-28T13:19:45
2020-08-29T12:34:31
2020-08-28T14:04:47
NONE
null
Hello there, I am facing an issue that has been talked over a few times already, but none of your suggestions helped. I am trying to handle insert_many conflict and do some logic afterwards. My API is hosted on AWS Lambda. DB init: `self.__db = pw.PostgresqlDatabase(**DB_CREDENTIALS, autocommit=True, autorollback=True)` logic: ` def __bulk_create(self): with self.__db.atomic(): try: query = Website.insert_many(self.data).returning(*self.__RETURNING) query.execute() self.__response = list(query) except IntegrityError as err: self.__db.rollback() self.__response = [{'error_message': f'DB conflict has occurred: {err}. Please check the field'}] self.conflict = True` when I run this function for the first time after updating Lambda it handles the exception just fine, but when I try to run any other query on the db - it fails with "errorMessage": "current transaction is aborted, commands ignored until end of transaction block\n", moving try\except outside the transaction does not help either. Tried using explicit transactions - no luck either. db.close() does not help. In PGADMIN for this connection I have the following after first run of the function: State: idle in transaction (aborted) Any help would be appreciated * using peewee==3.13.3 and Python 3.8.0
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2255/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2255/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2254
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2254/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2254/comments
https://api.github.com/repos/coleifer/peewee/issues/2254/events
https://github.com/coleifer/peewee/issues/2254
686,712,851
MDU6SXNzdWU2ODY3MTI4NTE=
2,254
Problems with Peewee and Python 3.8
{ "login": "Petesta", "id": 1114813, "node_id": "MDQ6VXNlcjExMTQ4MTM=", "avatar_url": "https://avatars.githubusercontent.com/u/1114813?v=4", "gravatar_id": "", "url": "https://api.github.com/users/Petesta", "html_url": "https://github.com/Petesta", "followers_url": "https://api.github.com/users/Petesta/followers", "following_url": "https://api.github.com/users/Petesta/following{/other_user}", "gists_url": "https://api.github.com/users/Petesta/gists{/gist_id}", "starred_url": "https://api.github.com/users/Petesta/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/Petesta/subscriptions", "organizations_url": "https://api.github.com/users/Petesta/orgs", "repos_url": "https://api.github.com/users/Petesta/repos", "events_url": "https://api.github.com/users/Petesta/events{/privacy}", "received_events_url": "https://api.github.com/users/Petesta/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "You probably need to re-install psycopg2. Peewee is reporting that it found psycopg2 but that json support was not present. https://www.psycopg.org/docs/extras.html#json-adaptation", "@coleifer I have already tried reinstalling the packages `psycopg2` and `psycopg2-binary` together and separately, prior to opening up an issue, to see if it would help and nothing changed. I've spun up new instances and still have the same problem. Again this only happens once the runtime is changed from `3.6` to `3.8` and new environments have been tried.\r\n\r\nPeewee says to use this [class PostgresqlExtDatabase](http://docs.peewee-orm.com/en/latest/peewee/playhouse.html#PostgresqlExtDatabase) and it has server side cursors readily available for json. The version that is running at runtime is `2.8.5` for `psycopg2`.\r\n\r\nI've been using this library with no problem for over four years, thanks for the work, and it seemed odd to me that an upgrade of the runtime would cause an issue. We can see at runtime the necessary libraries are loaded and on the load path.", "Something doesn't add up in what you're describing. You stated that all you changed is your python runtime, but I'm telling you that I think you're missing something on your end.\r\n\r\nPeewee only reports that error if your psycopg2 does not export the Json helper. You can verify:\r\n\r\n```python\r\n\r\nIn [1]: import sys; sys.version_info \r\nOut[1]: sys.version_info(major=3, minor=8, micro=0, releaselevel='final', serial=0)\r\n\r\nIn [2]: from playhouse.postgres_ext import Json \r\n\r\nIn [3]: Json \r\nOut[3]: psycopg2._json.Json\r\n```" ]
2020-08-26T22:41:34
2020-08-27T16:15:39
2020-08-27T00:30:17
NONE
null
I currently have a working implementation running on `Python 3.6` running `peewee 3.13.3` and `psycopg2-binary 2.8.5` with `Postgres 9.6`. I upgraded the Python runtime to `Python 3.8` and started receiving this error. ``` [ERROR] Exception: Your version of psycopg2 does not support JSON. Traceback (most recent call last): File "/var/lang/lib/python3.8/imp.py", line 234, in load_module return load_source(name, filename, file) File "/var/lang/lib/python3.8/imp.py", line 171, in load_source module = _load(spec) File "<frozen importlib._bootstrap>", line 702, in _load File "<frozen importlib._bootstrap>", line 671, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 783, in exec_module File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed File "/var/task/db/models.py", line 25, in <module> class MyModel(ModelBase): File "/var/task/db/models.py", line 31, in MyModel response = BinaryJSONField(null=True) File "/var/task/playhouse/postgres_ext.py", line 163, in __init__ super(IndexedFieldMixin, self).__init__(*args, **kwargs) File "/var/task/playhouse/postgres_ext.py", line 300, in __init__ raise Exception('Your version of psycopg2 does not support JSON.') ``` Here is the code. ```python from playhouse.postgres_ext import BinaryJSONField class MyModel(ModelBase): class Meta: table_name = "my_models" response = BinaryJSONField(null=True) ``` I checked the source code inside of `postgres_ext.py` and from what I can see it looks like it should work based on this [import statement](https://github.com/coleifer/peewee/blob/master/playhouse/postgres_ext.py#L29-L32). Have any idea why this would cause an issue? I reverted back to `Python 3.6` and the problem was resolved.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2254/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2254/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2253
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2253/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2253/comments
https://api.github.com/repos/coleifer/peewee/issues/2253/events
https://github.com/coleifer/peewee/issues/2253
684,332,926
MDU6SXNzdWU2ODQzMzI5MjY=
2,253
Custom SQL
{ "login": "ghost", "id": 10137, "node_id": "MDQ6VXNlcjEwMTM3", "avatar_url": "https://avatars.githubusercontent.com/u/10137?v=4", "gravatar_id": "", "url": "https://api.github.com/users/ghost", "html_url": "https://github.com/ghost", "followers_url": "https://api.github.com/users/ghost/followers", "following_url": "https://api.github.com/users/ghost/following{/other_user}", "gists_url": "https://api.github.com/users/ghost/gists{/gist_id}", "starred_url": "https://api.github.com/users/ghost/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/ghost/subscriptions", "organizations_url": "https://api.github.com/users/ghost/orgs", "repos_url": "https://api.github.com/users/ghost/repos", "events_url": "https://api.github.com/users/ghost/events{/privacy}", "received_events_url": "https://api.github.com/users/ghost/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "That syntax is not currently supported out of the box. I'd suggest looking at the query builder internals.\r\n\r\nIf you have more questions feel free to ask on the mailing list or #peewee on freenode and I'll try to help.", "ok, thanks." ]
2020-08-24T03:30:33
2020-08-24T14:11:09
2020-08-24T12:24:12
NONE
null
Hello... Who to change? SELECT "t1"."id", "t1"."text" FROM "fields" AS "t1" WHERE ("t1"."id" = 1) LIMIT 1 For: SELECT FIRST 1 "t1"."id", "t1"."text" FROM "fields" AS "t1" WHERE ("t1"."id" = 1) Thanks
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2253/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2253/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2252
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2252/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2252/comments
https://api.github.com/repos/coleifer/peewee/issues/2252/events
https://github.com/coleifer/peewee/issues/2252
684,262,996
MDU6SXNzdWU2ODQyNjI5OTY=
2,252
Found some potential code quality issues in peewee
{ "login": "pnijhara", "id": 40136154, "node_id": "MDQ6VXNlcjQwMTM2MTU0", "avatar_url": "https://avatars.githubusercontent.com/u/40136154?v=4", "gravatar_id": "", "url": "https://api.github.com/users/pnijhara", "html_url": "https://github.com/pnijhara", "followers_url": "https://api.github.com/users/pnijhara/followers", "following_url": "https://api.github.com/users/pnijhara/following{/other_user}", "gists_url": "https://api.github.com/users/pnijhara/gists{/gist_id}", "starred_url": "https://api.github.com/users/pnijhara/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/pnijhara/subscriptions", "organizations_url": "https://api.github.com/users/pnijhara/orgs", "repos_url": "https://api.github.com/users/pnijhara/repos", "events_url": "https://api.github.com/users/pnijhara/events{/privacy}", "received_events_url": "https://api.github.com/users/pnijhara/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[]
2020-08-23T21:52:42
2020-08-23T22:08:43
2020-08-23T22:08:43
NONE
null
I was reading peewee's documentation last month and so I thought of forking this repo and running a code quality analysis on it. In that analysis, [DeepSource](https://deepsource.io/) found somewhat around 1000 code quality issues. Some interesting issues found in the source code: - [(Bug-risk) Multiple imports for an import name detected](https://deepsource.io/gh/pnijhara/peewee/issue/PYL-W0404/) - [(Bug-risk) `hasattr` used to check if the object is callable](https://deepsource.io/gh/pnijhara/peewee/issue/PTC-W0035/) - [(Performance) Built-in function `len` used as a condition](https://deepsource.io/gh/pnijhara/peewee/issue/PYL-C1801/) - [(Security) Assert statement used outside of tests](https://deepsource.io/gh/pnijhara/peewee/issue/BAN-B101/) What's so good? All the above-stated issues can be automatically fixed by autofix tool of DeepSource. Look at this autofix session &rarr; https://deepsource.io/gh/pnijhara/peewee/autofix/54d8d678-156a-4aa1-aea3-9fb63ebe4f89/ and the [PR](https://github.com/pnijhara/peewee/pull/3) > Code that conforms stylistically with the rest of the Peewee codebase. Quoting from peewee's documentation Since there is no coding style followed in the project, I decided to run a Transformer as well. Since the last release, DeepSource can automatically do that and create a PR on the project. - [ Automated transformation](https://deepsource.io/gh/pnijhara/peewee/transform/34b7ba8d-23af-456f-bcd7-b36f7cd97713/) using Black, and [the subsequent PR](https://github.com/pnijhara/peewee/pull/1). Please let me know what issues you'd like to focus on fixing and I'd be happy to take a look into it. Also, you can choose to hide certain types of issues too (if you wish to ignore them or you believe it is a false positive). I'd also be happy to send a patch with the DeepSource configuration file with the required fixes. You can find the required configuration file for DeepSource [here](https://github.com/pnijhara/peewee/blob/pnijhara-patch-1/.deepsource.toml).
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2252/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2252/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2251
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2251/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2251/comments
https://api.github.com/repos/coleifer/peewee/issues/2251/events
https://github.com/coleifer/peewee/pull/2251
681,140,283
MDExOlB1bGxSZXF1ZXN0NDY5NTc5MzIy
2,251
Update hacks.rst
{ "login": "vltr", "id": 1540275, "node_id": "MDQ6VXNlcjE1NDAyNzU=", "avatar_url": "https://avatars.githubusercontent.com/u/1540275?v=4", "gravatar_id": "", "url": "https://api.github.com/users/vltr", "html_url": "https://github.com/vltr", "followers_url": "https://api.github.com/users/vltr/followers", "following_url": "https://api.github.com/users/vltr/following{/other_user}", "gists_url": "https://api.github.com/users/vltr/gists{/gist_id}", "starred_url": "https://api.github.com/users/vltr/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/vltr/subscriptions", "organizations_url": "https://api.github.com/users/vltr/orgs", "repos_url": "https://api.github.com/users/vltr/repos", "events_url": "https://api.github.com/users/vltr/events{/privacy}", "received_events_url": "https://api.github.com/users/vltr/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[]
2020-08-18T15:37:58
2020-08-18T16:40:43
2020-08-18T16:40:42
CONTRIBUTOR
null
fix to a minimal typo that was messing up RST formatting
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2251/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2251/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/2251", "html_url": "https://github.com/coleifer/peewee/pull/2251", "diff_url": "https://github.com/coleifer/peewee/pull/2251.diff", "patch_url": "https://github.com/coleifer/peewee/pull/2251.patch", "merged_at": "2020-08-18T16:40:42" }
https://api.github.com/repos/coleifer/peewee/issues/2250
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2250/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2250/comments
https://api.github.com/repos/coleifer/peewee/issues/2250/events
https://github.com/coleifer/peewee/issues/2250
680,594,385
MDU6SXNzdWU2ODA1OTQzODU=
2,250
TypeError: <lambda>() takes 1 positional argument but 2 were given
{ "login": "feelingnothing", "id": 47575622, "node_id": "MDQ6VXNlcjQ3NTc1NjIy", "avatar_url": "https://avatars.githubusercontent.com/u/47575622?v=4", "gravatar_id": "", "url": "https://api.github.com/users/feelingnothing", "html_url": "https://github.com/feelingnothing", "followers_url": "https://api.github.com/users/feelingnothing/followers", "following_url": "https://api.github.com/users/feelingnothing/following{/other_user}", "gists_url": "https://api.github.com/users/feelingnothing/gists{/gist_id}", "starred_url": "https://api.github.com/users/feelingnothing/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/feelingnothing/subscriptions", "organizations_url": "https://api.github.com/users/feelingnothing/orgs", "repos_url": "https://api.github.com/users/feelingnothing/repos", "events_url": "https://api.github.com/users/feelingnothing/events{/privacy}", "received_events_url": "https://api.github.com/users/feelingnothing/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I shared a working example of this code, did you not see it? You are replacing methods with lambdas but they need to take the implicit \"self\" when called on the instance.\r\n\r\n```python\r\n# e.g.\r\npython_value = lambda self, v: int(v)\r\n```\r\n\r\nPlease do not post this kind of question on the issue tracker. It belongs on stackoverflow or you can ask on IRC. This is for peewee issues." ]
2020-08-17T23:59:45
2020-08-18T12:46:10
2020-08-18T12:46:10
NONE
null
My model: ```python class Notification(BaseModel): id = CharField(default=uuid4, max_length=36) created_at = DateTimeField(default=datetime.now) channel = BigIntField() time = TimeField() title = CharField(max_length=256, null=True) description = CharField(max_length=2048, null=True) color = CharField(max_length=6, default='2f3136') image = CharField(null=True) ``` How im trying to save data: ```python for h, m in self.data['intervals']: data = {k: v for k, v in deepcopy(self.data).items() if v is not None and k != 'intervals'} # data = {'channel': 742158931408846859, 'title': 'title'} # time is datetime.time # time = time(hour=2, minute=31) Notification.create(**data, time=time(hour=h, minute=m)).save() ``` Error I got ```python Traceback (most recent call last): File "C:\Users\dolabaeb\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\ext\menus\__init__.py", line 638, in update await button(self, payload) File "c:\Users\dolabaeb\Desktop\paid projects\notifications\menus\notification.py", line 145, in end Notification.create(**data, time=time(hour=h, minute=m)).save() File "C:\Users\dolabaeb\AppData\Local\Programs\Python\Python38\lib\site-packages\peewee.py", line 6292, in create inst.save(force_insert=True) File "C:\Users\dolabaeb\AppData\Local\Programs\Python\Python38\lib\site-packages\peewee.py", line 6499, in save pk = self.insert(**field_dict).execute() File "C:\Users\dolabaeb\AppData\Local\Programs\Python\Python38\lib\site-packages\peewee.py", line 1886, in inner return method(self, database, *args, **kwargs) File "C:\Users\dolabaeb\AppData\Local\Programs\Python\Python38\lib\site-packages\peewee.py", line 1957, in execute return self._execute(database) File "C:\Users\dolabaeb\AppData\Local\Programs\Python\Python38\lib\site-packages\peewee.py", line 2707, in _execute return super(Insert, self)._execute(database) File "C:\Users\dolabaeb\AppData\Local\Programs\Python\Python38\lib\site-packages\peewee.py", line 2442, in _execute cursor = database.execute(self) File "C:\Users\dolabaeb\AppData\Local\Programs\Python\Python38\lib\site-packages\peewee.py", line 3111, in execute sql, params = ctx.sql(query).query() File "C:\Users\dolabaeb\AppData\Local\Programs\Python\Python38\lib\site-packages\peewee.py", line 606, in sql return obj.__sql__(self) File "C:\Users\dolabaeb\AppData\Local\Programs\Python\Python38\lib\site-packages\peewee.py", line 2684, in __sql__ self._simple_insert(ctx) File "C:\Users\dolabaeb\AppData\Local\Programs\Python\Python38\lib\site-packages\peewee.py", line 2544, in _simple_insert return self._generate_insert((self._insert,), ctx) File "C:\Users\dolabaeb\AppData\Local\Programs\Python\Python38\lib\site-packages\peewee.py", line 2656, in _generate_insert return ctx.sql(CommaNodeList(all_values)) File "C:\Users\dolabaeb\AppData\Local\Programs\Python\Python38\lib\site-packages\peewee.py", line 606, in sql return obj.__sql__(self) File "C:\Users\dolabaeb\AppData\Local\Programs\Python\Python38\lib\site-packages\peewee.py", line 1752, in __sql__ ctx.sql(self.nodes[n_nodes - 1]) File "C:\Users\dolabaeb\AppData\Local\Programs\Python\Python38\lib\site-packages\peewee.py", line 606, in sql return obj.__sql__(self) File "C:\Users\dolabaeb\AppData\Local\Programs\Python\Python38\lib\site-packages\peewee.py", line 1750, in __sql__ ctx.sql(self.nodes[i]) File "C:\Users\dolabaeb\AppData\Local\Programs\Python\Python38\lib\site-packages\peewee.py", line 606, in sql return obj.__sql__(self) File "C:\Users\dolabaeb\AppData\Local\Programs\Python\Python38\lib\site-packages\peewee.py", line 1364, in __sql__ return ctx.value(self.value, self.converter) File "C:\Users\dolabaeb\AppData\Local\Programs\Python\Python38\lib\site-packages\peewee.py", line 618, in value value = converter(value) TypeError: <lambda>() takes 1 positional argument but 2 were given ``` And my `BigIntField` and `BaseModel` ```python class BigIntField(TextField): python_value = lambda v: int(v) db_value = lambda v: str(v) class BaseModel(Model): class Meta: database = db ``` (Just to clear some questions) - [x] I tried to google it - [x] I tried to sort out None's Also, I tried to find an example of using 'TimeField`, but didn't find it version: peewee==3.13.3
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2250/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2250/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2249
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2249/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2249/comments
https://api.github.com/repos/coleifer/peewee/issues/2249/events
https://github.com/coleifer/peewee/issues/2249
679,468,473
MDU6SXNzdWU2Nzk0Njg0NzM=
2,249
OverflowError: Python int too large to convert to SQLite INTEGER
{ "login": "feelingnothing", "id": 47575622, "node_id": "MDQ6VXNlcjQ3NTc1NjIy", "avatar_url": "https://avatars.githubusercontent.com/u/47575622?v=4", "gravatar_id": "", "url": "https://api.github.com/users/feelingnothing", "html_url": "https://github.com/feelingnothing", "followers_url": "https://api.github.com/users/feelingnothing/followers", "following_url": "https://api.github.com/users/feelingnothing/following{/other_user}", "gists_url": "https://api.github.com/users/feelingnothing/gists{/gist_id}", "starred_url": "https://api.github.com/users/feelingnothing/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/feelingnothing/subscriptions", "organizations_url": "https://api.github.com/users/feelingnothing/orgs", "repos_url": "https://api.github.com/users/feelingnothing/repos", "events_url": "https://api.github.com/users/feelingnothing/events{/privacy}", "received_events_url": "https://api.github.com/users/feelingnothing/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Have a look at the [docs](http://docs.peewee-orm.com/en/latest/peewee/models.html#field-types-table) there is a `BigIntegerField`, it should be sufficient for your use:\r\n```\r\n>>> v = 735095020402769941\r\n>>> (v/(2**31-1) > 1)\r\nTrue\r\n>>> (v/(2**63-1) > 1)\r\nFalse\r\n```", "This works fine for me, I'm not sure what you've omitted but probably something important:\r\n\r\n```python\r\nfrom peewee import * \r\n\r\ndb = SqliteDatabase(':memory:')\r\n\r\nclass BigIntField(TextField):\r\n def python_value(self, value):\r\n return int(value)\r\n\r\nclass Reg(Model):\r\n key = TextField()\r\n value = BigIntField()\r\n class Meta:\r\n database = db\r\n\r\ndb.create_tables([Reg])\r\n\r\nr1 = Reg.create(key='k1', value=10)\r\nr2 = Reg.create(key='k2', value=735095020402769941)\r\nr2.value = r2.value + 1 # works fine.\r\nr2.save()\r\n\r\nquery = Reg.select()\r\nfor row in query:\r\n print(row.key, row.value, type(row.value))\r\n```\r\n\r\nOutput:\r\n\r\n```\r\nk1 10 <class 'int'> \r\nk2 735095020402769942 <class 'int'>\r\n```" ]
2020-08-15T00:53:08
2020-08-15T16:03:15
2020-08-15T16:02:08
NONE
null
Error: ``` {'name': 'VIP1', 'description': 'TEST1', 'price': 1.0, 'currency': 'rub', 'role_id': '735095020402769941'} Traceback (most recent call last): File "C:\Users\dolabaeb\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\ext\menus\__init__.py", line 638, in update await button(self, payload) File "c:\Users\dolabaeb\Desktop\paid projects\platezka-sample\menus\products.py", line 259, in select await self.pages[self.current_page - 1]['func']() File "c:\Users\dolabaeb\Desktop\paid projects\platezka-sample\menus\products.py", line 238, in role await self._complete_check() File "c:\Users\dolabaeb\Desktop\paid projects\platezka-sample\menus\products.py", line 162, in _complete_check Product( File "C:\Users\dolabaeb\AppData\Local\Programs\Python\Python38\lib\site-packages\peewee.py", line 6497, in save rows = self.update(**field_dict).where(self._pk_expr()).execute() File "C:\Users\dolabaeb\AppData\Local\Programs\Python\Python38\lib\site-packages\peewee.py", line 1886, in inner return method(self, database, *args, **kwargs) File "C:\Users\dolabaeb\AppData\Local\Programs\Python\Python38\lib\site-packages\peewee.py", line 1957, in execute return self._execute(database) File "C:\Users\dolabaeb\AppData\Local\Programs\Python\Python38\lib\site-packages\peewee.py", line 2442, in _execute cursor = database.execute(self) File "C:\Users\dolabaeb\AppData\Local\Programs\Python\Python38\lib\site-packages\peewee.py", line 3112, in execute return self.execute_sql(sql, params, commit=commit) File "C:\Users\dolabaeb\AppData\Local\Programs\Python\Python38\lib\site-packages\peewee.py", line 3099, in execute_sql cursor.execute(sql, params or ()) OverflowError: Python int too large to convert to SQLite INTEGER ``` I tried to insert into `IntegerField` value `735095020402769941`, but got Python int too large to convert to SQLite INTEGER After stackoverflow session I did create a ReallyBigIntegerField ```python class ReallyBigIntegerField(Field): field_type = 'text' def db_value(self, value): return str(value) def python_value(self, value): return int(value) ``` but got the same error After that I set up CharField instead of my custom one and got SAME error *Every time I made changes, I deleted the database for migration Forgot about my model ```python class Product(BaseModel): id = CharField(default=uuid4) type = CharField(default=ROLE, choices=[ROLE]) created_at = DateTimeField(default=datetime.now) name = CharField(max_length=256) description = CharField(max_length=2048) price = FloatField() currency = CharField(default=USD, choices=CURRENCY_TYPES) role_id = CharField(max_length=18) ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2249/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2249/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2248
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2248/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2248/comments
https://api.github.com/repos/coleifer/peewee/issues/2248/events
https://github.com/coleifer/peewee/issues/2248
679,211,665
MDU6SXNzdWU2NzkyMTE2NjU=
2,248
Lost type of aliased column from subquery
{ "login": "Nurbel", "id": 7353807, "node_id": "MDQ6VXNlcjczNTM4MDc=", "avatar_url": "https://avatars.githubusercontent.com/u/7353807?v=4", "gravatar_id": "", "url": "https://api.github.com/users/Nurbel", "html_url": "https://github.com/Nurbel", "followers_url": "https://api.github.com/users/Nurbel/followers", "following_url": "https://api.github.com/users/Nurbel/following{/other_user}", "gists_url": "https://api.github.com/users/Nurbel/gists{/gist_id}", "starred_url": "https://api.github.com/users/Nurbel/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/Nurbel/subscriptions", "organizations_url": "https://api.github.com/users/Nurbel/orgs", "repos_url": "https://api.github.com/users/Nurbel/repos", "events_url": "https://api.github.com/users/Nurbel/events{/privacy}", "received_events_url": "https://api.github.com/users/Nurbel/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "That's correct, and peewee will figure it out correctly most of the time, but when you're pulling stuff up from subqueries you may need to explicitly tell peewee how to coerce it.\r\n\r\nDid you try:\r\n\r\n```python\r\n\r\n.select(MyModel.date, sub.c.date, sub.c.date, sub.c.aliased.coerce(MyModel.date.db_value))\r\n```", "Your proposition does not seem to work.\r\n\r\nthe best thing I managed to do was to use MyModel.date.python_value on the result\r\n```python\r\nMyModel.date.python_value(row['aliased'])\r\n```", "Whoops, I meant `.coerce(MyModel.date.python_value)` -- did you try that?", "Yes,I tried it did not work either", "Sorry, I had my APIs mixed-up. I've added a new API for this case, which *may* change somewhat before the next release -- but this should provide a way forward for these cases that aren't covered by the existing heuristics.\r\n\r\nThe new API would be:\r\n\r\n```python\r\n\r\n.select(..., subq.c.aliased.converter(callable))\r\n```\r\n\r\nAnd `callable()` would be called on the corresponding row value taken from the cursor.", "Now I don`t use subquery . But after used cast sting to int,I use alias I get string not a int value", "Possibly you are aliasing it to the same name as used by an existing char/text field on your model?", "> Possibly you are aliasing it to the same name as used by an existing char/text field on your model?\r\n\r\nYou are right, now i use round function to cast string to decimal", "If you alias an expression to the name of an existing column, peewee assumes you want to use that column's conversions for the data. So you might try also just using a different name - one that doesn't coincide with an existing field." ]
2020-08-14T14:52:40
2021-01-11T10:41:07
2020-08-14T19:42:46
NONE
null
Hi, when using aliased colums in a subquery, peewee seems to loose the type of the column In the following script, I access a date from a subquery, with and without an alias. Without the alias, I get a python date as expected, but with the alias, I get a string ```python from peewee import * from datetime import date DB = SqliteDatabase('/tmp/test_subquery.db') class MyModel(Model): date = DateField() class Meta: database = DB DB.create_tables([MyModel]) MyModel.replace(date=date(2020, 1, 1)).execute() mod2 = MyModel.alias() sub = mod2.select(mod2.date, mod2.date.alias('aliased')) q = (MyModel.select(MyModel.date, sub.c.date, sub.c.aliased) .join(sub, on=(sub.c.aliased == MyModel.date)) ) print(q.dicts().get()) ``` > {'date': datetime.date(2020, 1, 1), 'aliased': '2020-01-01'} Am I doing something wrong? From the doc, using aliases seemed to be the recommended way to access the subquery columns
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2248/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2248/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2247
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2247/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2247/comments
https://api.github.com/repos/coleifer/peewee/issues/2247/events
https://github.com/coleifer/peewee/issues/2247
679,163,947
MDU6SXNzdWU2NzkxNjM5NDc=
2,247
Misleading query generated on SQLite
{ "login": "theosotr", "id": 6434138, "node_id": "MDQ6VXNlcjY0MzQxMzg=", "avatar_url": "https://avatars.githubusercontent.com/u/6434138?v=4", "gravatar_id": "", "url": "https://api.github.com/users/theosotr", "html_url": "https://github.com/theosotr", "followers_url": "https://api.github.com/users/theosotr/followers", "following_url": "https://api.github.com/users/theosotr/following{/other_user}", "gists_url": "https://api.github.com/users/theosotr/gists{/gist_id}", "starred_url": "https://api.github.com/users/theosotr/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/theosotr/subscriptions", "organizations_url": "https://api.github.com/users/theosotr/orgs", "repos_url": "https://api.github.com/users/theosotr/repos", "events_url": "https://api.github.com/users/theosotr/events{/privacy}", "received_events_url": "https://api.github.com/users/theosotr/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Sqlite does not support parentheses on union queries, nor does it support ORDER BY or LIMIT on the individual queries that comprise the union. Read the sqlite docs:\r\n\r\nhttps://sqlite.org/lang_select.html#compound_select_statements\r\n\r\n>As the components of a compound SELECT must be simple SELECT statements, they may not contain ORDER BY or LIMIT clauses.", "Thanks\r\nYes, I figured out what happened here. However, peewee's result was misleading because someone would expect peewee to produce a query that would fail on SQLite (since ORDER_BY and LIMIT are not supported on individual queries)." ]
2020-08-14T13:39:01
2020-08-14T14:45:56
2020-08-14T14:39:55
NONE
null
I run the following query on SQLite. ```python q1 = Table1.select(Table1.colA).objects() q2 = Table2.select(Table2.colB).order_by(Table2.colB).limit(1).objects() q1.union(q2) ``` the query generated by `peewee` is misleading, and not equivalent to the initial one ```sql SELECT "t1"."colA" FROM "table1" AS "t1" UNION SELECT "t2"."colB" FROM "table2" AS "t2" ORDER BY "t2"."colB" LIMIT 1 ``` In particular, the `ORDER BY` and `LIMIT` clauses are applied to the combined query produced by the `UNION` clause, and *not* to the second sub-query as intended.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2247/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2247/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2246
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2246/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2246/comments
https://api.github.com/repos/coleifer/peewee/issues/2246/events
https://github.com/coleifer/peewee/issues/2246
679,054,792
MDU6SXNzdWU2NzkwNTQ3OTI=
2,246
Query with Syntax Error on MySQL
{ "login": "theosotr", "id": 6434138, "node_id": "MDQ6VXNlcjY0MzQxMzg=", "avatar_url": "https://avatars.githubusercontent.com/u/6434138?v=4", "gravatar_id": "", "url": "https://api.github.com/users/theosotr", "html_url": "https://github.com/theosotr", "followers_url": "https://api.github.com/users/theosotr/followers", "following_url": "https://api.github.com/users/theosotr/following{/other_user}", "gists_url": "https://api.github.com/users/theosotr/gists{/gist_id}", "starred_url": "https://api.github.com/users/theosotr/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/theosotr/subscriptions", "organizations_url": "https://api.github.com/users/theosotr/orgs", "repos_url": "https://api.github.com/users/theosotr/repos", "events_url": "https://api.github.com/users/theosotr/events{/privacy}", "received_events_url": "https://api.github.com/users/theosotr/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "If you want your ORDER BY or LIMIT to be applied to an individual query within the union, then you need to apply that ordering before you union them together. Otherwise peewee thinks you're trying to apply that to the overall compound result set. It's complicated because the ordering can be either applied to the individual query, or the overall result-set. So if you want the former, you apply it before union-ing.\r\n\r\nYou can fix this by:\r\n\r\n```python\r\nq1 = Table1.select(Table1.colA).order_by(Table1.colA).limit(10)\r\nq2 = Table2.select(Table2.colB)\r\nq3 = Table3.select(Table3.colC).order_by(Table3.colC)\r\n\r\nunion = q1.union(q2).union(q3)\r\n```", "Thanks.\r\nWhat happens if I want to apply `order_by` to the result of the union? similar to my example above? I think the semantics of the proposed fix is different from that of the initial query. Am I wrong?", "You can do that. Just once you've unioned everything together, specify ordering by column number (since they have different names):\r\n\r\n```python\r\n\r\nunion.order_by(SQL('1'))\r\n```", "No, I meant what happens if I want to apply `order_by` to the result of a *sub-union*. This has different semantics from applying order_by to the individual sub-query (e.g., q1).\r\n\r\n```\r\ncomb = q1.union(q2).order_by(SQL('1')).limit(10)\r\nq3.union(comb).order_by(SQL('1'))\r\n```\r\nthe query above still fails on MySQL (note that in Postgres runs fine!)", "I'm not sure how well supported that will be, in that case.", "So, this kind of query is not supported by peewee. Thanks!", ">So, this kind of query is not supported by peewee. Thanks!\r\n\r\nThat doesn't seem correct to me.\r\n\r\nDoes MySQL even support doing that? I believe that MySQL **does not** support nested parentheses on UNION queries - thus there's no way to clearly specify the ordering for the sub-union. Postgres does, which is why it works on Postgres.\r\n\r\nYou can try to force Peewee to put the extra parentheses there by specifying\r\n\r\n```python\r\n\r\ndb.compound_select_parentheses = CSQ_PARENTHESES_ALWAYS # 1\r\n```\r\n\r\nAlternatively, make your first UNION, then SELECT FROM it.\r\n\r\n```python\r\n\r\nu1 = q1.union(q2)\r\nu1 = u1.order_by(SQL('1'))\r\n\r\nsub_union = Select(SQL('1')).from_(u1)\r\ntotal = sub_union.union(q3)\r\n```\r\n\r\nI'm sure there are other ways, if you just put your mind to it.\r\n\r\nI notice you are using lots of different databases -- what exactly are you trying to do? You've brought up sqlite, postgres and mysql so far.", "\r\n> \r\n> Alternatively, make your first UNION, then SELECT FROM it.\r\n> \r\n> ```python\r\n> u1 = q1.union(q2)\r\n> u1 = u1.order_by(SQL('1'))\r\n> \r\n> sub_union = Select(SQL('1')).from_(u1)\r\n> total = sub_union.union(q3)\r\n> ```\r\n\r\nThanks again.\r\nI've just tried this solution, and peewee seems to reach an infinite loop (it never terminates). You can check it on your own if you want.\r\n\r\n\r\n> \r\n> I notice you are using lots of different databases -- what exactly are you trying to do? You've brought up sqlite, postgres and mysql so far.\r\n\r\nI and my research team differentially test well-established ORMs (e.g., Django, peewee, SQLAalchemy, and more) for finding bugs.\r\n\r\n", "I didn't test that, the correct syntax was:\r\n\r\n```python\r\n\r\nsub_union = Select(from_list=[u1], columns=[SQL('1')])\r\n```", "that works." ]
2020-08-14T10:12:51
2020-08-14T15:56:53
2020-08-14T14:37:33
NONE
null
I have the following peewee query (over-simplified for opening the issue). ```python q1 = Table1.select(Table1.colA).objects() q2 = Table2.select(Table2.colB).objects() q3 = Table3.select(Table3.colC).objects() comb = q1.union(q2).order_by(Table1.colA).limit(10) q3.union(comb).order_by(Table3.colC) ``` this crashes with the following exception on MySQL ``` Traceback (most recent call last): File "/home/.env/lib/python3.6/site-packages/peewee-3.13.3-py3.6.egg/peewee.py", line 3119, in execute_sql cursor.execute(sql, params or ()) File "/home/.env/lib/python3.6/site-packages/MySQLdb/cursors.py", line 206, in execute res = self._query(query) File "/home/.env/lib/python3.6/site-packages/MySQLdb/cursors.py", line 319, in _query db.query(q) File "/home/.env/lib/python3.6/site-packages/MySQLdb/connections.py", line 259, in query _mysql.connection.query(self, query) MySQLdb._exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY `col`' at line 1") During handling of the above exception, another exception occurred: Traceback (most recent call last): File "tmp.py", line 31, in <module> for r in ret5: File "/home/.env/lib/python3.6/site-packages/peewee-3.13.3-py3.6.egg/peewee.py", line 6833, in __iter__ self.execute() File "/home/.env/lib/python3.6/site-packages/peewee-3.13.3-py3.6.egg/peewee.py", line 1891, in inner return method(self, database, *args, **kwargs) File "/home/.env/lib/python3.6/site-packages/peewee-3.13.3-py3.6.egg/peewee.py", line 1962, in execute return self._execute(database) File "/home/.env/lib/python3.6/site-packages/peewee-3.13.3-py3.6.egg/peewee.py", line 2134, in _execute cursor = database.execute(self) File "/home/.env/lib/python3.6/site-packages/peewee-3.13.3-py3.6.egg/peewee.py", line 3132, in execute return self.execute_sql(sql, params, commit=commit) File "/home/.env/lib/python3.6/site-packages/peewee-3.13.3-py3.6.egg/peewee.py", line 3126, in execute_sql self.commit() File "/home/.env/lib/python3.6/site-packages/peewee-3.13.3-py3.6.egg/peewee.py", line 2892, in __exit__ reraise(new_type, new_type(exc_value, *exc_args), traceback) File "/home/.env/lib/python3.6/site-packages/peewee-3.13.3-py3.6.egg/peewee.py", line 183, in reraise raise value.with_traceback(tb) File "/home/.env/lib/python3.6/site-packages/peewee-3.13.3-py3.6.egg/peewee.py", line 3119, in execute_sql cursor.execute(sql, params or ()) File "/home/.env/lib/python3.6/site-packages/MySQLdb/cursors.py", line 206, in execute res = self._query(query) File "/home/.env/lib/python3.6/site-packages/MySQLdb/cursors.py", line 319, in _query db.query(q) File "/home/.env/lib/python3.6/site-packages/MySQLdb/connections.py", line 259, in query _mysql.connection.query(self, query) peewee.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY `colC`' at line 1") ``` the generated SQL is ```sql (SELECT `t1`.`colC` FROM `table3` AS `t1`) UNION (SELECT `t2`.`colA` FROM `table1` AS `t2`) UNION (SELECT `t3`.`colB` FROM `table2` AS `t3`) ORDER BY `colA` LIMIT 10 ORDER BY `colC` ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2246/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2246/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2245
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2245/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2245/comments
https://api.github.com/repos/coleifer/peewee/issues/2245/events
https://github.com/coleifer/peewee/issues/2245
677,060,555
MDU6SXNzdWU2NzcwNjA1NTU=
2,245
doc website seems to be hacked
{ "login": "azs0309", "id": 40914458, "node_id": "MDQ6VXNlcjQwOTE0NDU4", "avatar_url": "https://avatars.githubusercontent.com/u/40914458?v=4", "gravatar_id": "", "url": "https://api.github.com/users/azs0309", "html_url": "https://github.com/azs0309", "followers_url": "https://api.github.com/users/azs0309/followers", "following_url": "https://api.github.com/users/azs0309/following{/other_user}", "gists_url": "https://api.github.com/users/azs0309/gists{/gist_id}", "starred_url": "https://api.github.com/users/azs0309/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/azs0309/subscriptions", "organizations_url": "https://api.github.com/users/azs0309/orgs", "repos_url": "https://api.github.com/users/azs0309/repos", "events_url": "https://api.github.com/users/azs0309/events{/privacy}", "received_events_url": "https://api.github.com/users/azs0309/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "It seems to be working fine for me. This is the output of `curl http://docs.peewee-orm.com/en/3.6.0/peewee/quickstart.html`:\r\n\r\nhttps://gist.github.com/coleifer/d6450e6d5bdcb4460cd6bbf36b8dcb4c" ]
2020-08-11T17:31:31
2020-08-11T18:07:10
2020-08-11T18:07:10
NONE
null
The document website http://docs.peewee-orm.com/en/3.6.0/peewee/quickstart.html seems to be hacked and whenever I click a link pointing me to fryruejoust.cam
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2245/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2245/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2244
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2244/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2244/comments
https://api.github.com/repos/coleifer/peewee/issues/2244/events
https://github.com/coleifer/peewee/issues/2244
677,042,818
MDU6SXNzdWU2NzcwNDI4MTg=
2,244
left_outer_join doesn't works as expected
{ "login": "slavkoja", "id": 5506544, "node_id": "MDQ6VXNlcjU1MDY1NDQ=", "avatar_url": "https://avatars.githubusercontent.com/u/5506544?v=4", "gravatar_id": "", "url": "https://api.github.com/users/slavkoja", "html_url": "https://github.com/slavkoja", "followers_url": "https://api.github.com/users/slavkoja/followers", "following_url": "https://api.github.com/users/slavkoja/following{/other_user}", "gists_url": "https://api.github.com/users/slavkoja/gists{/gist_id}", "starred_url": "https://api.github.com/users/slavkoja/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/slavkoja/subscriptions", "organizations_url": "https://api.github.com/users/slavkoja/orgs", "repos_url": "https://api.github.com/users/slavkoja/repos", "events_url": "https://api.github.com/users/slavkoja/events{/privacy}", "received_events_url": "https://api.github.com/users/slavkoja/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "The `left_outer_join()` method is implemented on a lower-level of the query-builder and does not take into account important aspects of the model layer.\r\n\r\nYou should stick to using the standard ways of doing things, namely `.join()` when using models." ]
2020-08-11T17:03:20
2021-08-02T13:03:31
2020-08-11T18:09:35
NONE
null
I do not know, if i am doing something wrong, but query with `left_outer_join()` doesn't work for me. I can reproduce it with this simple example: ```python import peewee as pw DBFILE = ":memory:" db = pw.SqliteDatabase(DBFILE, pragmas={'foreign_keys': 1,}) class BaseModel(pw.Model): class Meta: database = db class Domains(BaseModel): id = pw.PrimaryKeyField(null=True) dname = pw.TextField() class DAliases(BaseModel): dalias = pw.TextField() domain = pw.ForeignKeyField(Domains) ``` Simple `join()` works without problems: ```python q = (Domains .select() .join(DAliases, pw.JOIN.LEFT_OUTER) .where(Domains.id==1) ) ``` But when i replace `join()` with `left_outer_join()`: ```python oq = (Domains .select() .left_outer_join(DAliases) .where(Domains.id==1) ) ``` It throws exception: ```python Traceback (most recent call last): File "pwerr.py", line 36, in <module> oq = (Domains AttributeError: 'Join' object has no attribute 'where' ``` I am surprised, because in source i see, that `left_outer_join()` returns the same object as `join()`, the difference is only in predefined `join_type`... Am i doing something wrong or problem is elsewhere?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2244/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/2244/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2243
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2243/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2243/comments
https://api.github.com/repos/coleifer/peewee/issues/2243/events
https://github.com/coleifer/peewee/issues/2243
677,019,062
MDU6SXNzdWU2NzcwMTkwNjI=
2,243
Fatal Python error: GC object already tracked
{ "login": "simpassi", "id": 38055305, "node_id": "MDQ6VXNlcjM4MDU1MzA1", "avatar_url": "https://avatars.githubusercontent.com/u/38055305?v=4", "gravatar_id": "", "url": "https://api.github.com/users/simpassi", "html_url": "https://github.com/simpassi", "followers_url": "https://api.github.com/users/simpassi/followers", "following_url": "https://api.github.com/users/simpassi/following{/other_user}", "gists_url": "https://api.github.com/users/simpassi/gists{/gist_id}", "starred_url": "https://api.github.com/users/simpassi/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/simpassi/subscriptions", "organizations_url": "https://api.github.com/users/simpassi/orgs", "repos_url": "https://api.github.com/users/simpassi/repos", "events_url": "https://api.github.com/users/simpassi/events{/privacy}", "received_events_url": "https://api.github.com/users/simpassi/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I'd take it up with the cpython / pysqlite folks. Sharing sqlite connections across python threads is weird, and peewee uses a connection-per-thread model anyways so I am not even sure how that is working for you.", "You probably need a minimal repro using threads and stdlib sqlite3." ]
2020-08-11T16:27:47
2020-08-11T18:02:25
2020-08-11T18:02:03
NONE
null
I'm having a weird intermittent error when all of the following conditions are met: * Using an in-memory sqlite3 database initialized with thread_safe=False, check_same_thread=False * Running in a different thread than the one that initialized the database * Accessing an object's _meta.backrefs values Running inside the debugger in vs.code will make this occur much more frequently. The actual Python error is: ``` Fatal Python error: GC object already tracked ``` When the crash happens, all the other threads are in wait() and the crashed one is here: ``` File "/opt/conda3/lib/python3.7/site-packages/peewee.py", line 4395 in __get__ ``` I realize these conditions are somewhat obscure - I'm talking through a REST API to a backend that is running with the same data model but with a Postgres database, and using the same model on the client end and updating the responses into the local sqlite3 in-memory database. The data travels over using *playhouse.shortcuts.model_to_dict* and reversed using dict_to_model. Just wondering if this is something easily resolved or if I need to bring all database queries back to the main thread... Peewee version: 3.13.2 Python version: 3.7.6 (Anaconda, MacOS)
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2243/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2243/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2242
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2242/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2242/comments
https://api.github.com/repos/coleifer/peewee/issues/2242/events
https://github.com/coleifer/peewee/issues/2242
676,606,899
MDU6SXNzdWU2NzY2MDY4OTk=
2,242
MariaDB/Mysql index type
{ "login": "chewvader", "id": 7836093, "node_id": "MDQ6VXNlcjc4MzYwOTM=", "avatar_url": "https://avatars.githubusercontent.com/u/7836093?v=4", "gravatar_id": "", "url": "https://api.github.com/users/chewvader", "html_url": "https://github.com/chewvader", "followers_url": "https://api.github.com/users/chewvader/followers", "following_url": "https://api.github.com/users/chewvader/following{/other_user}", "gists_url": "https://api.github.com/users/chewvader/gists{/gist_id}", "starred_url": "https://api.github.com/users/chewvader/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/chewvader/subscriptions", "organizations_url": "https://api.github.com/users/chewvader/orgs", "repos_url": "https://api.github.com/users/chewvader/repos", "events_url": "https://api.github.com/users/chewvader/events{/privacy}", "received_events_url": "https://api.github.com/users/chewvader/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Thank you for the report, I'll see about putting together a fix." ]
2020-08-11T06:01:54
2020-08-11T18:51:22
2020-08-11T18:51:22
NONE
null
I believe peewee isn't creating the correct "create index" syntax for mysql index_types. This was tested with mariadb==10.5.4, peewee==3.13.3. ``` import logging from peewee import * pwlogger = logging.getLogger('peewee') pwlogger.addHandler(logging.StreamHandler()) pwlogger.setLevel(logging.DEBUG) db = MySQLDatabase('<db>', user='<user>', password='<password>', host='<host>', port=3306) class testmodel(Model): timestamp = IntegerField(index=True, index_type='BTREE') class Meta: database = db with db: db.create_tables([testmodel]) ``` Results in: ``` ('SELECT table_name FROM information_schema.tables WHERE table_schema = DATABASE() AND table_type != %s ORDER BY table_name', ('VIEW',)) ('CREATE TABLE IF NOT EXISTS `testmodel` (`id` INTEGER AUTO_INCREMENT NOT NULL PRIMARY KEY, `timestamp` INTEGER NOT NULL)', []) ('CREATE INDEX `testmodel_timestamp` ON `testmodel` USING BTREE (`timestamp`)', []) Traceback (most recent call last): File "/home/<user>/.pyenv/versions/3.8.3/lib/python3.8/site-packages/peewee.py", line 3099, in execute_sql cursor.execute(sql, params or ()) File "/home/<user>/.pyenv/versions/3.8.3/lib/python3.8/site-packages/pymysql/cursors.py", line 163, in execute result = self._query(query) File "/home/<user>/.pyenv/versions/3.8.3/lib/python3.8/site-packages/pymysql/cursors.py", line 321, in _query conn.query(q) File "/home/<user>/.pyenv/versions/3.8.3/lib/python3.8/site-packages/pymysql/connections.py", line 505, in query self._affected_rows = self._read_query_result(unbuffered=unbuffered) File "/home/<user>/.pyenv/versions/3.8.3/lib/python3.8/site-packages/pymysql/connections.py", line 724, in _read_query_result result.read() File "/home/<user>/.pyenv/versions/3.8.3/lib/python3.8/site-packages/pymysql/connections.py", line 1069, in read first_packet = self.connection._read_packet() File "/home/<user>/.pyenv/versions/3.8.3/lib/python3.8/site-packages/pymysql/connections.py", line 676, in _read_packet packet.raise_for_error() File "/home/<user>/.pyenv/versions/3.8.3/lib/python3.8/site-packages/pymysql/protocol.py", line 223, in raise_for_error err.raise_mysql_exception(self._data) File "/home/<user>/.pyenv/versions/3.8.3/lib/python3.8/site-packages/pymysql/err.py", line 107, in raise_mysql_exception raise errorclass(errno, errval) pymysql.err.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'USING BTREE (`timestamp`)' at line 1") ``` The documentation for "CREATE INDEX" for [mysql ](https://dev.mysql.com/doc/refman/8.0/en/create-index.html) shows ``` CREATE [UNIQUE | FULLTEXT | SPATIAL] INDEX index_name [index_type] ON tbl_name (key_part,...) [index_option] [algorithm_option | lock_option] ``` or: `create index <index name> using <index type> on <table> (<field(s)>)` While on [postgres](https://www.postgresql.org/docs/current/sql-createindex.html) ``` CREATE [ UNIQUE ] INDEX [ CONCURRENTLY ] [ [ IF NOT EXISTS ] name ] ON [ ONLY ] table_name [ USING method ] ( { column_name | ( expression ) } [ COLLATE collation ] [ opclass ] [ ASC | DESC ] [ NULLS { FIRST | LAST } ] [, ...] ) [ INCLUDE ( column_name [, ...] ) ] [ WITH ( storage_parameter = value [, ... ] ) ] [ TABLESPACE tablespace_name ] [ WHERE predicate ] ``` or: `create index <index name> on <table> using <index type> (<field(s)>)` The executed statement looks like postgres syntax as opposed to mysql. ```CREATE INDEX `testmodel_timestamp` ON `testmodel` USING BTREE (`timestamp`)``` which bombs. If I manually execute: ``` CREATE INDEX `testmodel_timestamp` USING BTREE ON `testmodel` (`timestamp`); -- or CREATE INDEX `testmodel_timestamp` ON `testmodel` (`timestamp`) USING BTREE; ``` it succeeds.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2242/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2242/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2241
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2241/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2241/comments
https://api.github.com/repos/coleifer/peewee/issues/2241/events
https://github.com/coleifer/peewee/issues/2241
675,763,352
MDU6SXNzdWU2NzU3NjMzNTI=
2,241
After upgrading from version 2.x to 3.x getting, TypeError: _connect() missing 1 ...
{ "login": "wilberh", "id": 6799242, "node_id": "MDQ6VXNlcjY3OTkyNDI=", "avatar_url": "https://avatars.githubusercontent.com/u/6799242?v=4", "gravatar_id": "", "url": "https://api.github.com/users/wilberh", "html_url": "https://github.com/wilberh", "followers_url": "https://api.github.com/users/wilberh/followers", "following_url": "https://api.github.com/users/wilberh/following{/other_user}", "gists_url": "https://api.github.com/users/wilberh/gists{/gist_id}", "starred_url": "https://api.github.com/users/wilberh/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/wilberh/subscriptions", "organizations_url": "https://api.github.com/users/wilberh/orgs", "repos_url": "https://api.github.com/users/wilberh/repos", "events_url": "https://api.github.com/users/wilberh/events{/privacy}", "received_events_url": "https://api.github.com/users/wilberh/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "`_connect()` does not take a database parameter in 3.x. It is `self.database`." ]
2020-08-09T20:07:58
2020-08-10T14:06:25
2020-08-10T14:06:14
NONE
null
After upgrading from version 2.x to 3.x getting, I'm getting the error below. It worked fine in version 2.x ``` File "/.../lib/python3.6/site-packages/peewee.py", line 403, in inner with self: File "/.../lib/python3.6/site-packages/peewee.py", line 2936, in __enter__ self.db.connect() File "/.../lib/python3.6/site-packages/peewee.py", line 3035, in connect self._state.set_connection(self._connect()) TypeError: _connect() missing 1 required positional argument: 'database ``` http://docs.peewee-orm.com/en/latest/peewee/database.html?highlight=Adding%20a%20new%20Database%20Driver#adding-a-new-database-driver ``` from peewee import Database import foodb # Our fictional DB-API 2.0 driver. class FooDatabase(Database): def _connect(self, database, **kwargs): return foodb.connect(database, **kwargs) def get_database_connection(): return FooDatabase(database, **db_config) ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2241/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2241/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2240
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2240/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2240/comments
https://api.github.com/repos/coleifer/peewee/issues/2240/events
https://github.com/coleifer/peewee/issues/2240
675,551,419
MDU6SXNzdWU2NzU1NTE0MTk=
2,240
SQLite database generates GLOB for %, however GLOB is not LIKE…
{ "login": "zx80", "id": 8624205, "node_id": "MDQ6VXNlcjg2MjQyMDU=", "avatar_url": "https://avatars.githubusercontent.com/u/8624205?v=4", "gravatar_id": "", "url": "https://api.github.com/users/zx80", "html_url": "https://github.com/zx80", "followers_url": "https://api.github.com/users/zx80/followers", "following_url": "https://api.github.com/users/zx80/following{/other_user}", "gists_url": "https://api.github.com/users/zx80/gists{/gist_id}", "starred_url": "https://api.github.com/users/zx80/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/zx80/subscriptions", "organizations_url": "https://api.github.com/users/zx80/orgs", "repos_url": "https://api.github.com/users/zx80/repos", "events_url": "https://api.github.com/users/zx80/events{/privacy}", "received_events_url": "https://api.github.com/users/zx80/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "This has been this way for many years and I've no plans to change it. I do understand that it may have been confusing.", "Hmmm… Indeed it is pretty confusing.", "![s1597080267 5538623](https://user-images.githubusercontent.com/119974/89811582-7fe09c00-db04-11ea-9d0f-d01e1900180d.png)\r\n" ]
2020-08-08T16:29:33
2020-08-10T17:24:59
2020-08-10T14:05:08
NONE
null
The documentation says that `%` stands for `LIKE` in query expressions, but the traces shows a `GLOB` instead with SQLite, hoewever the regexp syntax is not the same between the two operators, eg `LIKE 'h%'` is `GLOB 'h*'`. Version affected: *3.13.3* Code: ```Python res = Store.select().where(Store.key % PARAMS['filter']).order_by(Store.key) ``` Trace: INFO:root:db = <peewee.SqliteDatabase object at 0x7ffac44c0c10> DEBUG:peewee:('SELECT "t1"."key", "t1"."val" FROM "store" AS "t1" WHERE ("t1"."key" GLOB ?) ORDER BY "t1"."key"', ['%h']) In the [source](https://github.com/coleifer/peewee/blob/master/peewee.py) on line 3347: ```Python operations = { 'LIKE': 'GLOB', 'ILIKE': 'LIKE' } ``` Indeed, SQLite `LIKE` is case insensitive, however `GLOB` is not `LIKE` at all. ISTM that it would be more helpful to generate a not implemented exception than switching to another operator which breaks the portability.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2240/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2240/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2239
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2239/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2239/comments
https://api.github.com/repos/coleifer/peewee/issues/2239/events
https://github.com/coleifer/peewee/issues/2239
674,076,608
MDU6SXNzdWU2NzQwNzY2MDg=
2,239
Using bitwise (&|~)in a query
{ "login": "TaceyWong", "id": 5282810, "node_id": "MDQ6VXNlcjUyODI4MTA=", "avatar_url": "https://avatars.githubusercontent.com/u/5282810?v=4", "gravatar_id": "", "url": "https://api.github.com/users/TaceyWong", "html_url": "https://github.com/TaceyWong", "followers_url": "https://api.github.com/users/TaceyWong/followers", "following_url": "https://api.github.com/users/TaceyWong/following{/other_user}", "gists_url": "https://api.github.com/users/TaceyWong/gists{/gist_id}", "starred_url": "https://api.github.com/users/TaceyWong/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/TaceyWong/subscriptions", "organizations_url": "https://api.github.com/users/TaceyWong/orgs", "repos_url": "https://api.github.com/users/TaceyWong/repos", "events_url": "https://api.github.com/users/TaceyWong/events{/privacy}", "received_events_url": "https://api.github.com/users/TaceyWong/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Since it's a unary operator, you can probably get it working with something like:\r\n\r\n```python\r\n\r\ndef bin_not(value):\r\n return NodeList((SQL('~'), value))\r\n```" ]
2020-08-06T07:09:00
2020-08-06T12:55:11
2020-08-06T12:55:11
NONE
null
IN http://docs.peewee-orm.com/en/latest/peewee/query_operators.html .bin_and(value) -> Binary AND .bin_or(value) -> Binary OR but,I can not find the replace of Binary NOT .How can I write a peewee-style c=a&(~b)?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2239/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2239/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2238
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2238/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2238/comments
https://api.github.com/repos/coleifer/peewee/issues/2238/events
https://github.com/coleifer/peewee/issues/2238
672,162,214
MDU6SXNzdWU2NzIxNjIyMTQ=
2,238
CTE executed multiple times
{ "login": "frafra", "id": 4068, "node_id": "MDQ6VXNlcjQwNjg=", "avatar_url": "https://avatars.githubusercontent.com/u/4068?v=4", "gravatar_id": "", "url": "https://api.github.com/users/frafra", "html_url": "https://github.com/frafra", "followers_url": "https://api.github.com/users/frafra/followers", "following_url": "https://api.github.com/users/frafra/following{/other_user}", "gists_url": "https://api.github.com/users/frafra/gists{/gist_id}", "starred_url": "https://api.github.com/users/frafra/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/frafra/subscriptions", "organizations_url": "https://api.github.com/users/frafra/orgs", "repos_url": "https://api.github.com/users/frafra/repos", "events_url": "https://api.github.com/users/frafra/events{/privacy}", "received_events_url": "https://api.github.com/users/frafra/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Please see the docs for cte usage. I get the sense you're missing something:\r\n\r\nhttp://docs.peewee-orm.com/en/latest/peewee/querying.html#common-table-expressions\r\n\r\nThe tests also have numerous examples.", "My misunderstanding was based on the assumption that `.with_cte(...)` should have been added to each [sub]query which refers to the CTE, while it just adds a `WITH ... AS` at the beginning of the [sub]query.\r\n\r\nMy problem has been fixed by using `.with_cte(...)` just once, at the very end of the main query." ]
2020-08-03T15:34:32
2020-08-04T08:23:44
2020-08-03T15:53:30
NONE
null
Hi, Peewee defines CTE in subqueries, even if that means to compute the same thing twice. For example: `SELECT ... FROM ... JOIN (WITH cte ... SELECT ... FROM cte) JOIN (WITH cte ... SELECT ... FROM cte) ...` I have a rather complex example I can show, but it surprises me that the CTE is not placed at the beginning, as that has been defined once.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2238/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2238/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2237
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2237/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2237/comments
https://api.github.com/repos/coleifer/peewee/issues/2237/events
https://github.com/coleifer/peewee/issues/2237
671,566,605
MDU6SXNzdWU2NzE1NjY2MDU=
2,237
Add the auto_now parameter to the TimestampField field
{ "login": "ghost", "id": 10137, "node_id": "MDQ6VXNlcjEwMTM3", "avatar_url": "https://avatars.githubusercontent.com/u/10137?v=4", "gravatar_id": "", "url": "https://api.github.com/users/ghost", "html_url": "https://github.com/ghost", "followers_url": "https://api.github.com/users/ghost/followers", "following_url": "https://api.github.com/users/ghost/following{/other_user}", "gists_url": "https://api.github.com/users/ghost/gists{/gist_id}", "starred_url": "https://api.github.com/users/ghost/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/ghost/subscriptions", "organizations_url": "https://api.github.com/users/ghost/orgs", "repos_url": "https://api.github.com/users/ghost/repos", "events_url": "https://api.github.com/users/ghost/events{/privacy}", "received_events_url": "https://api.github.com/users/ghost/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "You can already do this by overloading the default datetime class, something like:\r\n``` python\r\nfrom datetime import datetime\r\n\r\nimport peewee as pw\r\n\r\n\r\n# pylint: disable=locally-disabled, invalid-name\r\ndef NowDateTimeField(**kwargs):\r\n \"\"\" A peewee DateTimeField which defaults to 'now'\r\n \"\"\"\r\n constraints = kwargs.pop('constraints', [])\r\n if not kwargs.get('null'): # also default to 'now' on insert\r\n constraints.append(pw.SQL('DEFAULT CURRENT_TIMESTAMP'))\r\n\r\n return pw.DateTimeField(\r\n default=datetime.now,\r\n constraints=constraints,\r\n **kwargs,\r\n )\r\n\r\n```", "There are a couple options:\r\n\r\n* Specify default=datetime.datetime.now (no parens!!)\r\n* Override the save() method\r\n* Use a constraint\r\n* Create a trigger to set new value on update" ]
2020-08-02T07:08:14
2020-08-02T14:39:10
2020-08-02T14:39:10
NONE
null
I want to add this parameter, when set to True, the database entry will be updated and changed to the current time
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2237/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2237/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2236
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2236/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2236/comments
https://api.github.com/repos/coleifer/peewee/issues/2236/events
https://github.com/coleifer/peewee/pull/2236
669,738,844
MDExOlB1bGxSZXF1ZXN0NDYwMDc1Njk0
2,236
Added JSONField
{ "login": "ghost", "id": 10137, "node_id": "MDQ6VXNlcjEwMTM3", "avatar_url": "https://avatars.githubusercontent.com/u/10137?v=4", "gravatar_id": "", "url": "https://api.github.com/users/ghost", "html_url": "https://github.com/ghost", "followers_url": "https://api.github.com/users/ghost/followers", "following_url": "https://api.github.com/users/ghost/following{/other_user}", "gists_url": "https://api.github.com/users/ghost/gists{/gist_id}", "starred_url": "https://api.github.com/users/ghost/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/ghost/subscriptions", "organizations_url": "https://api.github.com/users/ghost/orgs", "repos_url": "https://api.github.com/users/ghost/repos", "events_url": "https://api.github.com/users/ghost/events{/privacy}", "received_events_url": "https://api.github.com/users/ghost/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I'm going to pass. There are vendor-specific JSON field implementations, which are recommended. Those who wish to just store json in a textfield can subclass the existing TextField implementation or use a 3rd party package." ]
2020-07-31T11:55:03
2020-07-31T14:05:31
2020-07-31T14:05:31
NONE
null
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2236/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2236/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/2236", "html_url": "https://github.com/coleifer/peewee/pull/2236", "diff_url": "https://github.com/coleifer/peewee/pull/2236.diff", "patch_url": "https://github.com/coleifer/peewee/pull/2236.patch", "merged_at": null }
https://api.github.com/repos/coleifer/peewee/issues/2235
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2235/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2235/comments
https://api.github.com/repos/coleifer/peewee/issues/2235/events
https://github.com/coleifer/peewee/issues/2235
668,759,799
MDU6SXNzdWU2Njg3NTk3OTk=
2,235
What does the `gametight` tag mean?
{ "login": "pxeger", "id": 67427173, "node_id": "MDQ6VXNlcjY3NDI3MTcz", "avatar_url": "https://avatars.githubusercontent.com/u/67427173?v=4", "gravatar_id": "", "url": "https://api.github.com/users/pxeger", "html_url": "https://github.com/pxeger", "followers_url": "https://api.github.com/users/pxeger/followers", "following_url": "https://api.github.com/users/pxeger/following{/other_user}", "gists_url": "https://api.github.com/users/pxeger/gists{/gist_id}", "starred_url": "https://api.github.com/users/pxeger/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/pxeger/subscriptions", "organizations_url": "https://api.github.com/users/pxeger/orgs", "repos_url": "https://api.github.com/users/pxeger/repos", "events_url": "https://api.github.com/users/pxeger/events{/privacy}", "received_events_url": "https://api.github.com/users/pxeger/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "https://www.youtube.com/watch?v=McnTeuKtmfg&t=1m24s" ]
2020-07-30T13:59:47
2020-07-30T14:14:00
2020-07-30T14:14:00
NONE
null
Random question - the tag `gametight` is used on only two other repos - kt and ukt, both by you (coleifer). What does it mean?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2235/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2235/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2234
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2234/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2234/comments
https://api.github.com/repos/coleifer/peewee/issues/2234/events
https://github.com/coleifer/peewee/pull/2234
668,718,838
MDExOlB1bGxSZXF1ZXN0NDU5MTcwNjQ2
2,234
Add ping reconnect mysql connection
{ "login": "bagel", "id": 706788, "node_id": "MDQ6VXNlcjcwNjc4OA==", "avatar_url": "https://avatars.githubusercontent.com/u/706788?v=4", "gravatar_id": "", "url": "https://api.github.com/users/bagel", "html_url": "https://github.com/bagel", "followers_url": "https://api.github.com/users/bagel/followers", "following_url": "https://api.github.com/users/bagel/following{/other_user}", "gists_url": "https://api.github.com/users/bagel/gists{/gist_id}", "starred_url": "https://api.github.com/users/bagel/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/bagel/subscriptions", "organizations_url": "https://api.github.com/users/bagel/orgs", "repos_url": "https://api.github.com/users/bagel/repos", "events_url": "https://api.github.com/users/bagel/events{/privacy}", "received_events_url": "https://api.github.com/users/bagel/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "See: https://github.com/coleifer/peewee/blob/master/playhouse/shortcuts.py#L174-L229", "I use like this before, Why not use ping auto reconnect?" ]
2020-07-30T13:24:08
2020-07-30T13:49:31
2020-07-30T13:40:18
CONTRIBUTOR
null
When mysql server restart or lost connection, connection not reconnect and database.is_closed is False. Add ping(reconnect=True) auto reconnect. Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/lib/python3.8/dist-packages/peewee.py", line 1987, in __len__ self._ensure_execution() File "/usr/local/lib/python3.8/dist-packages/peewee.py", line 1969, in _ensure_execution self.execute() File "/usr/local/lib/python3.8/dist-packages/peewee.py", line 1886, in inner return method(self, database, *args, **kwargs) File "/usr/local/lib/python3.8/dist-packages/peewee.py", line 1957, in execute return self._execute(database) File "/usr/local/lib/python3.8/dist-packages/peewee.py", line 2129, in _execute cursor = database.execute(self) File "/usr/local/lib/python3.8/dist-packages/peewee.py", line 3112, in execute return self.execute_sql(sql, params, commit=commit) File "/usr/local/lib/python3.8/dist-packages/peewee.py", line 3106, in execute_sql self.commit() File "/usr/local/lib/python3.8/dist-packages/peewee.py", line 2873, in __exit__ reraise(new_type, new_type(exc_value, *exc_args), traceback) File "/usr/local/lib/python3.8/dist-packages/peewee.py", line 183, in reraise raise value.with_traceback(tb) File "/usr/local/lib/python3.8/dist-packages/peewee.py", line 3099, in execute_sql cursor.execute(sql, params or ()) File "/usr/local/lib/python3.8/dist-packages/pymysql/cursors.py", line 170, in execute result = self._query(query) File "/usr/local/lib/python3.8/dist-packages/pymysql/cursors.py", line 328, in _query conn.query(q) File "/usr/local/lib/python3.8/dist-packages/pymysql/connections.py", line 516, in query self._execute_command(COMMAND.COM_QUERY, sql) File "/usr/local/lib/python3.8/dist-packages/pymysql/connections.py", line 750, in _execute_command raise err.InterfaceError("(0, '')") peewee.InterfaceError: (0, '') >>> database.is_closed() False
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2234/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2234/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/2234", "html_url": "https://github.com/coleifer/peewee/pull/2234", "diff_url": "https://github.com/coleifer/peewee/pull/2234.diff", "patch_url": "https://github.com/coleifer/peewee/pull/2234.patch", "merged_at": null }
https://api.github.com/repos/coleifer/peewee/issues/2233
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2233/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2233/comments
https://api.github.com/repos/coleifer/peewee/issues/2233/events
https://github.com/coleifer/peewee/issues/2233
667,905,729
MDU6SXNzdWU2Njc5MDU3Mjk=
2,233
Inconsistency in treatment of '\' character
{ "login": "theosotr", "id": 6434138, "node_id": "MDQ6VXNlcjY0MzQxMzg=", "avatar_url": "https://avatars.githubusercontent.com/u/6434138?v=4", "gravatar_id": "", "url": "https://api.github.com/users/theosotr", "html_url": "https://github.com/theosotr", "followers_url": "https://api.github.com/users/theosotr/followers", "following_url": "https://api.github.com/users/theosotr/following{/other_user}", "gists_url": "https://api.github.com/users/theosotr/gists{/gist_id}", "starred_url": "https://api.github.com/users/theosotr/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/theosotr/subscriptions", "organizations_url": "https://api.github.com/users/theosotr/orgs", "repos_url": "https://api.github.com/users/theosotr/repos", "events_url": "https://api.github.com/users/theosotr/events{/privacy}", "received_events_url": "https://api.github.com/users/theosotr/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Depending on your database, you may need to double-up the backslash, as many databases treat it as the default escape.\r\n\r\nJust use four: '\\\\\\\\\\\\\\\\'.", "I think this behaviour needs to be hidden from the programmer. Besides, an ORM is abstraction layer over databases.\r\nBecause adding `\\\\\\\\` in the first query will make peewee to return nothing.\r\n\r\nSo when mixing `\\` with '_', I suggest peewee add the following in its logic.\r\n```python\r\nstr.replace('\\\\', '\\\\\\\\')\r\n```", "What database are you using?", "Also: are you running the latest version from master branch?", "I am using sqlite, and I am using the mater version of peewee.", ">I am using the mater version of peewee.\r\n\r\nI think I know what the issue is, in that case. I made a recent change to the \"contains()\" method so that \"_\" and \"%\" within the search-string are properly escaped -- as you may know, these are wildcards that have special meaning for partial-string search. So if a string contains \"_\" or \"%\", the expression is converted somewhat. I believe I can fix this with a small addition. Thanks for reporting.", "Thanks!" ]
2020-07-29T14:49:14
2020-07-29T15:19:10
2020-07-29T15:19:10
NONE
null
I have the following database schema ```sql CREATE TABLE "table" ( "id" integer, "str" varchar(50), PRIMARY KEY (id) ); INSERT INTO "table"("id","str") VALUES (1,'bar_foo\baz'); INSERT INTO "table"("id","str") VALUES (2,'bar'); INSERT INTO "table"("id","str") VALUES (3,'bar\foo'); ``` and the following query ```python ret = Table.select(Table.id).where(Table.str.contains('\\')) for r in ret: print(r.id) ``` This prints the following as expected ``` 1 3 ``` However, when I have this query ```python ret = Table.select(Table.id).where(Table.str.contains('_foo\\')) for r in ret: print(r.id) ``` I expect peewee to dump ``` 1 ``` but, peewee dumps nothing.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2233/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2233/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2232
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2232/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2232/comments
https://api.github.com/repos/coleifer/peewee/issues/2232/events
https://github.com/coleifer/peewee/pull/2232
667,668,594
MDExOlB1bGxSZXF1ZXN0NDU4MjkxNzgw
2,232
Support queries of all types of pkey in `get()`
{ "login": "wooparadog", "id": 1130984, "node_id": "MDQ6VXNlcjExMzA5ODQ=", "avatar_url": "https://avatars.githubusercontent.com/u/1130984?v=4", "gravatar_id": "", "url": "https://api.github.com/users/wooparadog", "html_url": "https://github.com/wooparadog", "followers_url": "https://api.github.com/users/wooparadog/followers", "following_url": "https://api.github.com/users/wooparadog/following{/other_user}", "gists_url": "https://api.github.com/users/wooparadog/gists{/gist_id}", "starred_url": "https://api.github.com/users/wooparadog/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/wooparadog/subscriptions", "organizations_url": "https://api.github.com/users/wooparadog/orgs", "repos_url": "https://api.github.com/users/wooparadog/repos", "events_url": "https://api.github.com/users/wooparadog/events{/privacy}", "received_events_url": "https://api.github.com/users/wooparadog/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I'm going to pass, but thanks." ]
2020-07-29T08:51:23
2020-07-29T13:32:12
2020-07-29T13:32:12
NONE
null
In https://github.com/coleifer/peewee/issues/1835 get by primary key is added for `int`, but there're cases when primary key is other than integer, especially in analytics domain. Using `Node` to exclude `Expression` seems a good idea, need more insight though.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2232/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2232/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/2232", "html_url": "https://github.com/coleifer/peewee/pull/2232", "diff_url": "https://github.com/coleifer/peewee/pull/2232.diff", "patch_url": "https://github.com/coleifer/peewee/pull/2232.patch", "merged_at": null }
https://api.github.com/repos/coleifer/peewee/issues/2231
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2231/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2231/comments
https://api.github.com/repos/coleifer/peewee/issues/2231/events
https://github.com/coleifer/peewee/issues/2231
667,420,609
MDU6SXNzdWU2Njc0MjA2MDk=
2,231
Unable to pass database parameter to mysql-connector-python through peewee
{ "login": "dshefman1", "id": 25602097, "node_id": "MDQ6VXNlcjI1NjAyMDk3", "avatar_url": "https://avatars.githubusercontent.com/u/25602097?v=4", "gravatar_id": "", "url": "https://api.github.com/users/dshefman1", "html_url": "https://github.com/dshefman1", "followers_url": "https://api.github.com/users/dshefman1/followers", "following_url": "https://api.github.com/users/dshefman1/following{/other_user}", "gists_url": "https://api.github.com/users/dshefman1/gists{/gist_id}", "starred_url": "https://api.github.com/users/dshefman1/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/dshefman1/subscriptions", "organizations_url": "https://api.github.com/users/dshefman1/orgs", "repos_url": "https://api.github.com/users/dshefman1/repos", "events_url": "https://api.github.com/users/dshefman1/events{/privacy}", "received_events_url": "https://api.github.com/users/dshefman1/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "You need to use `playhouse.mysql_ext.MySQLConnectorDatabase` to connect using the mysql-connector driver. That will resolve your issue." ]
2020-07-28T22:23:54
2020-07-29T13:33:46
2020-07-29T13:33:46
NONE
null
The database parameter 'tls_versions' does not appear to be getting passed through to mysql-connector-python. The [documentation ](http://docs.peewee-orm.com/en/latest/peewee/database.html#initializing-a-database) says, "Subsequent keyword arguments are passed to the underlying database driver when establishing the connection, allowing you to pass vendor-specific parameters easily". This does not appear to be the behavior I am witnessing when I pass the "tls_versions" parameter through peewee to mysql-connector-python. When I connect directly with mysql-connector-python using the code below, I am able to connect successfully: ``` import mysql.connector config = {'database': 'dbname', 'user': 'username_so', 'password': 'psswrd', 'host': 'maria####-##-###-##.###.####.com', 'port': 3307, 'tls_versions': ['TLSv1.1', 'TLSv1.2']} cnx = mysql.connector.connect(**config) print(cnx.is_connected()) cnx.close() ``` Output: > True However, when I pass in the same configuration to peewee.MySQLDatabase() then I get an error message: ``` db = MySQLDatabase(**config) db.get_tables() # This function and any other that connects to the db returns the same error message specified below ``` Error Message: > ImproperlyConfigured: MySQL driver not installed! I am pretty sure that the problem is with specifying the tls versions in peewee because I was getting the same error message with mysql.connector before I added in the additional 'tls_versions' parameter. Also, I get the same error message with peewee if I do not include the 'tls_versions' parameter at all. My Setup: Linux Python 3.7 peewee==3.13.3 mysql-connector-python==8.0.21
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2231/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2231/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2230
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2230/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2230/comments
https://api.github.com/repos/coleifer/peewee/issues/2230/events
https://github.com/coleifer/peewee/issues/2230
665,368,056
MDU6SXNzdWU2NjUzNjgwNTY=
2,230
passing custom/additonal metadata
{ "login": "wilberh", "id": 6799242, "node_id": "MDQ6VXNlcjY3OTkyNDI=", "avatar_url": "https://avatars.githubusercontent.com/u/6799242?v=4", "gravatar_id": "", "url": "https://api.github.com/users/wilberh", "html_url": "https://github.com/wilberh", "followers_url": "https://api.github.com/users/wilberh/followers", "following_url": "https://api.github.com/users/wilberh/following{/other_user}", "gists_url": "https://api.github.com/users/wilberh/gists{/gist_id}", "starred_url": "https://api.github.com/users/wilberh/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/wilberh/subscriptions", "organizations_url": "https://api.github.com/users/wilberh/orgs", "repos_url": "https://api.github.com/users/wilberh/repos", "events_url": "https://api.github.com/users/wilberh/events{/privacy}", "received_events_url": "https://api.github.com/users/wilberh/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "No this is not supported" ]
2020-07-24T19:23:35
2020-07-24T19:51:20
2020-07-24T19:51:20
NONE
null
Is there any way to pass additional metada when creating a table (in class Meta or some other way)? Meaning, adding additional information after table creation section - see bold section below. Example: CREATE TABLE testing ( name VARCHAR ) **COMMENT 'This is an internal table' ROW FORMAT DELIMITED NULL DEFINED AS '' STORED AS AVRO**
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2230/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2230/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2229
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2229/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2229/comments
https://api.github.com/repos/coleifer/peewee/issues/2229/events
https://github.com/coleifer/peewee/issues/2229
664,677,651
MDU6SXNzdWU2NjQ2Nzc2NTE=
2,229
How to handle 'Duplicate entry' warnings when using `on_conflict_ignore()`?
{ "login": "SilentGene", "id": 15141939, "node_id": "MDQ6VXNlcjE1MTQxOTM5", "avatar_url": "https://avatars.githubusercontent.com/u/15141939?v=4", "gravatar_id": "", "url": "https://api.github.com/users/SilentGene", "html_url": "https://github.com/SilentGene", "followers_url": "https://api.github.com/users/SilentGene/followers", "following_url": "https://api.github.com/users/SilentGene/following{/other_user}", "gists_url": "https://api.github.com/users/SilentGene/gists{/gist_id}", "starred_url": "https://api.github.com/users/SilentGene/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/SilentGene/subscriptions", "organizations_url": "https://api.github.com/users/SilentGene/orgs", "repos_url": "https://api.github.com/users/SilentGene/repos", "events_url": "https://api.github.com/users/SilentGene/events{/privacy}", "received_events_url": "https://api.github.com/users/SilentGene/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "The warning is not raised by peewee. The warning is not generated by pymysql. The warning is coming directly from the sql database.\r\n\r\nFor general information about warnings, check here:\r\n\r\nhttps://docs.python.org/3/library/warnings.html#module-warnings\r\n\r\nNext time please spend more time looking into it before just immediately opening an issue.", "Thank you @coleifer . I have been struggling for this issue for some time, but didn't know this is coming from SQL database with my little experience in SQL. I thought this originated from pymysql or peewee, so I've spent much time looking for solutions there.\r\n\r\nWith your suggestion, now I have successfully used the following code to suppress the warnings:\r\n```python\r\nimport warnings\r\n\r\ndef save_entries(d):\r\n with warnings.catch_warnings():\r\n warnings.filterwarnings('ignore', '.*Duplicate entry.*')\r\n \r\n with mysql_db.atomic():\r\n PaperInfo.insert_many(d).on_conflict_ignore().execute()\r\n```\r\n\r\nThanks again for your time." ]
2020-07-23T18:22:26
2020-07-24T16:47:33
2020-07-23T21:44:58
NONE
null
Hello, when using `insert.on_conflict_ignore().execute()` method to insert new entries, there are always warnings shown as below: ```bash C:\Users\...\AppData\Local\Programs\Python\Python37\lib\site-packages\pymysql\cursors.py:170: Warning: (1062, "Duplicate entry 'http://link.aps.org/doi/10.1103/RevModPhys.90.015006' for key 'IX_link'") result = self._query(query) ``` Could I know how to hide or filter out these warnings?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2229/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2229/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2228
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2228/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2228/comments
https://api.github.com/repos/coleifer/peewee/issues/2228/events
https://github.com/coleifer/peewee/issues/2228
664,307,679
MDU6SXNzdWU2NjQzMDc2Nzk=
2,228
Drop Constraint Syntax Error in MySQL 8.0.18
{ "login": "hfudev", "id": 23117153, "node_id": "MDQ6VXNlcjIzMTE3MTUz", "avatar_url": "https://avatars.githubusercontent.com/u/23117153?v=4", "gravatar_id": "", "url": "https://api.github.com/users/hfudev", "html_url": "https://github.com/hfudev", "followers_url": "https://api.github.com/users/hfudev/followers", "following_url": "https://api.github.com/users/hfudev/following{/other_user}", "gists_url": "https://api.github.com/users/hfudev/gists{/gist_id}", "starred_url": "https://api.github.com/users/hfudev/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/hfudev/subscriptions", "organizations_url": "https://api.github.com/users/hfudev/orgs", "repos_url": "https://api.github.com/users/hfudev/repos", "events_url": "https://api.github.com/users/hfudev/events{/privacy}", "received_events_url": "https://api.github.com/users/hfudev/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "For MySQL you would use the `drop_foreign_key_constraint` migrator method.", "I couldn't find it in peewee's documentation. Maybe could add it later. Thanks!", "Oh, it's spent a lot of time to find `drop_foreign_key_constraint` method... It will be very usefull to add it to the docs.", "The foreign-key constraint should be dropped automatically when dropping a foreign-key column." ]
2020-07-23T08:55:47
2020-09-10T13:22:02
2020-07-23T13:23:28
NONE
null
Hi, I'm using `peewee.playhouse.migrate.drop_constraint` to do some migrations on MySQL 8.0.18. If failed with error message: <pre> `Error in query (1064): Syntax error near 'CONSTRAINT `constraint_name`' at line 1` </pre> I've checked the SQL. This will fail: <pre>ALTER TABLE xxx DROP CONSTRAINTS `XXX`</pre> This will succeed: <pre>ALTER TABLE xxx DROP FOREIGN KEY `XXX`</pre> Is there anything peewee can improve? Or configurations in MySQL I ignored? Thanks for your help!
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2228/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2228/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2227
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2227/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2227/comments
https://api.github.com/repos/coleifer/peewee/issues/2227/events
https://github.com/coleifer/peewee/issues/2227
663,189,053
MDU6SXNzdWU2NjMxODkwNTM=
2,227
Is there a way to join across databases?
{ "login": "skjbulcher", "id": 16672299, "node_id": "MDQ6VXNlcjE2NjcyMjk5", "avatar_url": "https://avatars.githubusercontent.com/u/16672299?v=4", "gravatar_id": "", "url": "https://api.github.com/users/skjbulcher", "html_url": "https://github.com/skjbulcher", "followers_url": "https://api.github.com/users/skjbulcher/followers", "following_url": "https://api.github.com/users/skjbulcher/following{/other_user}", "gists_url": "https://api.github.com/users/skjbulcher/gists{/gist_id}", "starred_url": "https://api.github.com/users/skjbulcher/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/skjbulcher/subscriptions", "organizations_url": "https://api.github.com/users/skjbulcher/orgs", "repos_url": "https://api.github.com/users/skjbulcher/repos", "events_url": "https://api.github.com/users/skjbulcher/events{/privacy}", "received_events_url": "https://api.github.com/users/skjbulcher/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "You can use the `Meta.schema` to achieve an extra layer of namespacing." ]
2020-07-21T17:34:40
2020-07-21T19:36:40
2020-07-21T19:36:39
NONE
null
I have a MySQL server with a number of databases, e.g. `customer`, `dba_company_a`, `dba_company_b`. I need to join across databases to execute queries that include customer information from either dba_company database. I haven't been able to figure out how to do that with peewee. I've tried using different `Meta` classes indicating it belongs to a different database ``` db = MySQLDatabase('customer') class Customer(Model): id = AutoField() .... class Meta: database = db ``` as well as binding ``` db = MySQLDatabase('customer') class Customer(Model): id = AutoField() Customer.bind(db) ``` but in either case when I try to perform a join, _(something like `Orders.select(Orders, Customers).join(Customers).select()`, where Orders is a table on dba_company_a/b)_, I get a message like: ``` peewee.ProgrammingError: (1146, "Table 'dba_company_a.customer' doesn't exist") ``` Is there anyway to do joins across databases? Am I missing something simple?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2227/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2227/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2226
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2226/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2226/comments
https://api.github.com/repos/coleifer/peewee/issues/2226/events
https://github.com/coleifer/peewee/issues/2226
663,177,547
MDU6SXNzdWU2NjMxNzc1NDc=
2,226
.switch() and .join_from() for CTE's
{ "login": "BigPictures", "id": 63026741, "node_id": "MDQ6VXNlcjYzMDI2NzQx", "avatar_url": "https://avatars.githubusercontent.com/u/63026741?v=4", "gravatar_id": "", "url": "https://api.github.com/users/BigPictures", "html_url": "https://github.com/BigPictures", "followers_url": "https://api.github.com/users/BigPictures/followers", "following_url": "https://api.github.com/users/BigPictures/following{/other_user}", "gists_url": "https://api.github.com/users/BigPictures/gists{/gist_id}", "starred_url": "https://api.github.com/users/BigPictures/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/BigPictures/subscriptions", "organizations_url": "https://api.github.com/users/BigPictures/orgs", "repos_url": "https://api.github.com/users/BigPictures/repos", "events_url": "https://api.github.com/users/BigPictures/events{/privacy}", "received_events_url": "https://api.github.com/users/BigPictures/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "The join context only really has meaning for model-select, where peewee utilizes the structure of the model relationships to infer predicates and other things. A CTE can join multiple times, you just need to specify the appropriate predicate in the `on=` clause.", "That makes sense.\r\n\r\nWouldn't join context also be helpful for chains of joins from a CTE? In those cases you'd also be able to take advantage of the structure of intermediate models.\r\n\r\nThis is definitely less important than the original issue I thought I'd found, though I did actually run into it in my code just now.", "Well, the way you create a cte in the first place is using the regular model select apis:\r\n\r\nhttp://docs.peewee-orm.com/en/latest/peewee/query_examples.html#find-the-upward-recommendation-chain-for-member-id-27", "This doc section also shows how CTE is commonly used. In short, you write your select query regularly, and at the end you use the `cte()` method:\r\n\r\nhttp://docs.peewee-orm.com/en/latest/peewee/querying.html#common-table-expressions", "It’s okay, I got my thing working. Thanks!" ]
2020-07-21T17:14:53
2020-07-22T20:55:44
2020-07-21T19:35:56
NONE
null
It looks to me like the `.switch()` and `.join_from()` methods are only defined on the `ModelSelect` class, meaning it's impossible to join from a CTE to multiple other tables. It might be good to move the join context stuff up the class hierarchy to `Select`, unless there's some reason doing so would be tricky. Is there a workaround for this? I could join starting from one of the other tables, but I think that can have bad performance implications. Maybe making a new CTE for each join would work.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2226/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2226/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2225
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2225/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2225/comments
https://api.github.com/repos/coleifer/peewee/issues/2225/events
https://github.com/coleifer/peewee/issues/2225
661,603,413
MDU6SXNzdWU2NjE2MDM0MTM=
2,225
Support postgres polygon type?
{ "login": "andrewerf", "id": 26378793, "node_id": "MDQ6VXNlcjI2Mzc4Nzkz", "avatar_url": "https://avatars.githubusercontent.com/u/26378793?v=4", "gravatar_id": "", "url": "https://api.github.com/users/andrewerf", "html_url": "https://github.com/andrewerf", "followers_url": "https://api.github.com/users/andrewerf/followers", "following_url": "https://api.github.com/users/andrewerf/following{/other_user}", "gists_url": "https://api.github.com/users/andrewerf/gists{/gist_id}", "starred_url": "https://api.github.com/users/andrewerf/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/andrewerf/subscriptions", "organizations_url": "https://api.github.com/users/andrewerf/orgs", "repos_url": "https://api.github.com/users/andrewerf/repos", "events_url": "https://api.github.com/users/andrewerf/events{/privacy}", "received_events_url": "https://api.github.com/users/andrewerf/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "http://docs.peewee-orm.com/en/latest/peewee/models.html#custom-fields" ]
2020-07-20T09:38:53
2020-07-20T12:58:26
2020-07-20T12:58:26
NONE
null
What about support of postgres point, line, path and polygon types?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2225/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2225/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2224
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2224/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2224/comments
https://api.github.com/repos/coleifer/peewee/issues/2224/events
https://github.com/coleifer/peewee/issues/2224
658,277,401
MDU6SXNzdWU2NTgyNzc0MDE=
2,224
Contains does not work as expected with % and _
{ "login": "StefanosChaliasos", "id": 15054312, "node_id": "MDQ6VXNlcjE1MDU0MzEy", "avatar_url": "https://avatars.githubusercontent.com/u/15054312?v=4", "gravatar_id": "", "url": "https://api.github.com/users/StefanosChaliasos", "html_url": "https://github.com/StefanosChaliasos", "followers_url": "https://api.github.com/users/StefanosChaliasos/followers", "following_url": "https://api.github.com/users/StefanosChaliasos/following{/other_user}", "gists_url": "https://api.github.com/users/StefanosChaliasos/gists{/gist_id}", "starred_url": "https://api.github.com/users/StefanosChaliasos/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/StefanosChaliasos/subscriptions", "organizations_url": "https://api.github.com/users/StefanosChaliasos/orgs", "repos_url": "https://api.github.com/users/StefanosChaliasos/repos", "events_url": "https://api.github.com/users/StefanosChaliasos/events{/privacy}", "received_events_url": "https://api.github.com/users/StefanosChaliasos/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "What database are you using?", "Ι've tested it on sqlite and mysql", "This is working fine for me on both Sqlite and Postgresql:\r\n\r\n```\r\nIn [1]: from peewee import * \r\n\r\nIn [2]: db = SqliteDatabase(':memory:') \r\n\r\nIn [3]: class User(Model): \r\n ...: username = TextField() \r\n ...: class Meta: \r\n ...: database = db \r\n ...: table_name = 'users' \r\n ...: \r\n\r\nIn [4]: db.create_tables([User]) \r\n\r\nIn [5]: usernames = ['foo', 'foo%', 'foo%bar', 'foobar'] \r\n\r\nIn [6]: User.insert_many([(u,) for u in usernames], [User.username]).execute() \r\nOut[6]: 4\r\n\r\nIn [7]: User.select().where(User.username.contains('%'))[:] \r\nOut[7]: [<User: 2>, <User: 3>]\r\n\r\nIn [8]: db = PostgresqlDatabase('peewee_test') \r\n\r\nIn [9]: User._meta.set_database(db) \r\n\r\nIn [10]: db.create_tables([User]) \r\n\r\nIn [11]: User.insert_many([(u,) for u in usernames], [User.username]).execute() \r\nOut[11]: <peewee.ModelTupleCursorWrapper at 0x7f17a8da8160>\r\n\r\nIn [12]: User.select().where(User.username.contains('%'))[:] \r\nOut[12]: [<User: 2>, <User: 3>]\r\n```", "For MySQL, simply use a backslash to escape the wildcard characters:\r\n\r\n```python\r\n.where(User.username.contains('\\\\%'))\r\n```", "Strange, I run the following:\r\n\r\n```\r\nIn [1]: from peewee import *\r\n\r\nIn [2]: db = SqliteDatabase(':memory:')\r\n\r\nIn [3]: class User(Model):\r\n ...: username = TextField()\r\n ...: class Meta:\r\n ...: database = db\r\n ...: table_name = 'users'\r\n ...:\r\n\r\nIn [4]: usernames = ['foo', 'foo%', 'foo%bar', 'foobar']\r\n\r\nIn [5]: db.create_tables([User])\r\n\r\nIn [6]: User.insert_many([(u,) for u in usernames], [User.username]).execute()\r\nOut[6]: 4\r\n\r\nIn [7]: query = User.select().where(User.username.contains('%'))\r\n\r\nIn [8]: print(query)\r\nSELECT \"t1\".\"id\", \"t1\".\"username\" FROM \"users\" AS \"t1\" WHERE (\"t1\".\"username\" LIKE '%%%')\r\n\r\nIn [9]: print(query[:])\r\n[<User: 1>, <User: 2>, <User: 3>, <User: 4>]\r\n```\r\n\r\nI use peewee-3.13.3 and sqlite 3.32.3.\r\n\r\nThe generated SQL query is not equivalent to what I expect. \r\n\r\nThe correct query should be something like the following\r\n\r\n```\r\nSELECT \"t1\".\"id\", \"t1\".\"username\" FROM \"users\" AS \"t1\" WHERE (\"t1\".\"username\" LIKE '%\\%%' ESCAPE '\\')\r\n```", "I must be insane. I think I put in a tiny code-change and had loaded *that* into memory when I generated that output, because now I'm replicating your output. I will fix this for the common case, thanks for reporting." ]
2020-07-16T14:56:39
2020-07-17T00:22:33
2020-07-17T00:22:33
NONE
null
Consider a table with the following values: ``` id | name -- | ------- 1 | foo 2 | foo% 3 | foo%bar 4 | foobar ``` When I use the contains method with "%" as an argument, I expect to return foo% and foo%bar, but peewee returns all the columns of the table. Example query: ```python Table1.select(Table1.name).where(Table1.name.contains("'%")).objects() ``` I expected that `contains` abstracts the semantics of SQL and properly handles the special characters.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2224/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2224/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2223
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2223/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2223/comments
https://api.github.com/repos/coleifer/peewee/issues/2223/events
https://github.com/coleifer/peewee/issues/2223
654,479,525
MDU6SXNzdWU2NTQ0Nzk1MjU=
2,223
Removing trailing square-brackets
{ "login": "wilberh", "id": 6799242, "node_id": "MDQ6VXNlcjY3OTkyNDI=", "avatar_url": "https://avatars.githubusercontent.com/u/6799242?v=4", "gravatar_id": "", "url": "https://api.github.com/users/wilberh", "html_url": "https://github.com/wilberh", "followers_url": "https://api.github.com/users/wilberh/followers", "following_url": "https://api.github.com/users/wilberh/following{/other_user}", "gists_url": "https://api.github.com/users/wilberh/gists{/gist_id}", "starred_url": "https://api.github.com/users/wilberh/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/wilberh/subscriptions", "organizations_url": "https://api.github.com/users/wilberh/orgs", "repos_url": "https://api.github.com/users/wilberh/repos", "events_url": "https://api.github.com/users/wilberh/events{/privacy}", "received_events_url": "https://api.github.com/users/wilberh/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "You may be confusing the representation of the SQL statement with what actually gets sent to the database.\r\n\r\nThose brackets are the representation of an empty list. The list is used to pass parameters to the driver, which handles escaping and all that (note to Always use parameterized queries)." ]
2020-07-10T03:19:03
2020-07-10T15:42:12
2020-07-10T15:42:12
NONE
null
Is there a way of removing the square-brackets from getting added into sql queries? I'm getting this sql statement - SELECT t1.rname, t1.mrole, t1.rmaterial FROM stg.instruments AS t1 []
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2223/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2223/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2222
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2222/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2222/comments
https://api.github.com/repos/coleifer/peewee/issues/2222/events
https://github.com/coleifer/peewee/issues/2222
652,624,172
MDU6SXNzdWU2NTI2MjQxNzI=
2,222
Question: is comma equivalent to & in where clause?
{ "login": "dsmurrell", "id": 4035854, "node_id": "MDQ6VXNlcjQwMzU4NTQ=", "avatar_url": "https://avatars.githubusercontent.com/u/4035854?v=4", "gravatar_id": "", "url": "https://api.github.com/users/dsmurrell", "html_url": "https://github.com/dsmurrell", "followers_url": "https://api.github.com/users/dsmurrell/followers", "following_url": "https://api.github.com/users/dsmurrell/following{/other_user}", "gists_url": "https://api.github.com/users/dsmurrell/gists{/gist_id}", "starred_url": "https://api.github.com/users/dsmurrell/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/dsmurrell/subscriptions", "organizations_url": "https://api.github.com/users/dsmurrell/orgs", "repos_url": "https://api.github.com/users/dsmurrell/repos", "events_url": "https://api.github.com/users/dsmurrell/events{/privacy}", "received_events_url": "https://api.github.com/users/dsmurrell/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Yes, multiple expressions passed to `where()` are `AND`-ed together. It's typically cleaner to use parentheses, though, since python operator precedence seems to trip up a lot of people. Forcing the habit of using parentheses helps ensure they don't make a mistake.", "Great, thanks for clarifying.", "I think it should have mentioned it in the document this " ]
2020-07-07T20:38:18
2022-07-17T03:11:22
2020-07-07T21:58:35
NONE
null
In this example in the docs: http://docs.peewee-orm.com/en/latest/peewee/querying.html#filtering-records `.where(Tweet.user == user, Tweet.is_published == True)` Is this the same as `.where((Tweet.user == user) & (Tweet.is_published == True))` ? I can't seem to find this comma syntax documented anywhere else.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2222/reactions", "total_count": 3, "+1": 3, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2222/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2221
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2221/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2221/comments
https://api.github.com/repos/coleifer/peewee/issues/2221/events
https://github.com/coleifer/peewee/issues/2221
651,762,730
MDU6SXNzdWU2NTE3NjI3MzA=
2,221
Calling db.atomic() for a transaction with a new or existing database fails
{ "login": "rmskinsa", "id": 64798846, "node_id": "MDQ6VXNlcjY0Nzk4ODQ2", "avatar_url": "https://avatars.githubusercontent.com/u/64798846?v=4", "gravatar_id": "", "url": "https://api.github.com/users/rmskinsa", "html_url": "https://github.com/rmskinsa", "followers_url": "https://api.github.com/users/rmskinsa/followers", "following_url": "https://api.github.com/users/rmskinsa/following{/other_user}", "gists_url": "https://api.github.com/users/rmskinsa/gists{/gist_id}", "starred_url": "https://api.github.com/users/rmskinsa/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/rmskinsa/subscriptions", "organizations_url": "https://api.github.com/users/rmskinsa/orgs", "repos_url": "https://api.github.com/users/rmskinsa/repos", "events_url": "https://api.github.com/users/rmskinsa/events{/privacy}", "received_events_url": "https://api.github.com/users/rmskinsa/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "MySQL does not support transactional DDL. If you had checked your database first, you probably would have found:\r\n\r\nhttps://dev.mysql.com/doc/refman/8.0/en/atomic-ddl.html\r\n\r\nNote the big **NOTE** section at the top.\r\n\r\nFor reference, Peewee is tested across all databases, including the use of transactions and savepoints...", "Wow, I didn't realize MySQL didn't automatically allow rollbacks! Looks like one must specifically disable autocommit as per [here](https://dev.mysql.com/doc/refman/8.0/en/innodb-autocommit-commit-rollback.html).\r\n\r\nDigging more in your SO post, I found this link for how to disable auto-commit: http://docs.peewee-orm.com/en/3.6.0/peewee/database.html?highlight=autocommit#autocommit-mode. Will give that a shot. I just want to note that the language there is a bit misleading. \"To group multiple statements into a transaction, Peewee provides the atomic() context-manager/decorator. This should cover all use-cases ...\" and \"Again – I don’t anticipate anyone needing this, but it’s here just in case.\" aren't entirely accurate since lots of people use MySQL, and it looks like this work-around is required if they want the ability to roll back their commits. Or perhaps I'm missing something? Additionally, PeeWee's documentation doesn't call out that the `db.atomic()` feature being unsupported by MySQL. It may be helpful to note that in the \"Transactions\" section linked to in the initial post above and to provide the work-around of using `db.manual_commit()`.", "I think you're misunderstanding completely.\r\n\r\nThe point is that mysql does not allow transactions and DDL. It looks like somewhere in code (probably not included in this example) you're creating tables inside an `atomic()` block.\r\n\r\nMySQL works fine with transactions, savepoints, commits and rollbacks, etc, etc., which is covered thoroughly in the tests as well." ]
2020-07-06T19:16:55
2020-07-06T21:01:57
2020-07-06T19:33:21
NONE
null
In `my_models.py`: ``` class RegionType(db.Model): name = CharField(unique=True, null=False) ``` In `my_flask_app.py`: ``` db = MySQLDatabase( app.config.get('DATABASE_NAME'), user=app.config.get('DATABASE_USER'), password=app.config.get('DATABASE_PASSWORD'), host=app.config.get('DATABASE_HOST'), port=int(app.config.get('DATABASE_PORT')) ) ``` In `migrations.py`: ``` from my_models import RegionType from my_flask_app import db, app with db.atomic() as transaction: try: all_region_type = RegionType.create(name='all') except Exception as e: transaction.rollback() app.logger.error(e) ``` I spin the database up in a Docker container. The docker-compose for that looks like: ``` local_db: container_name: local_db image: mysql:5.7 restart: always environment: MYSQL_ROOT_PASSWORD: xxxxx MYSQL_DATABASE: xxxxx MYSQL_USER: xxxxx MYSQL_PASSWORD: xxxxx ports: - '3306:3306' expose: - '3306' volumes: - ./local_db_data:/var/lib/mysql ``` Have confirmed my application can talk to/interact with the database using the config info given above and that the database is running. When I run the migration above I get: ``` File "/Users/ryanschuster/envs/DataSvc-jeQi5N6I/lib/python3.6/site-packages/peewee.py", line 3099, in execute_sql cursor.execute(sql, params or ()) File "/Users/ryanschuster/envs/DataSvc-jeQi5N6I/lib/python3.6/site-packages/pymysql/cursors.py", line 170, in execute result = self._query(query) File "/Users/ryanschuster/envs/DataSvc-jeQi5N6I/lib/python3.6/site-packages/pymysql/cursors.py", line 328, in _query conn.query(q) File "/Users/ryanschuster/envs/DataSvc-jeQi5N6I/lib/python3.6/site-packages/pymysql/connections.py", line 517, in query self._affected_rows = self._read_query_result(unbuffered=unbuffered) File "/Users/ryanschuster/envs/DataSvc-jeQi5N6I/lib/python3.6/site-packages/pymysql/connections.py", line 732, in _read_query_result result.read() File "/Users/ryanschuster/envs/DataSvc-jeQi5N6I/lib/python3.6/site-packages/pymysql/connections.py", line 1075, in read first_packet = self.connection._read_packet() File "/Users/ryanschuster/envs/DataSvc-jeQi5N6I/lib/python3.6/site-packages/pymysql/connections.py", line 684, in _read_packet packet.check_error() File "/Users/ryanschuster/envs/DataSvc-jeQi5N6I/lib/python3.6/site-packages/pymysql/protocol.py", line 220, in check_error err.raise_mysql_exception(self._data) File "/Users/ryanschuster/envs/DataSvc-jeQi5N6I/lib/python3.6/site-packages/pymysql/err.py", line 109, in raise_mysql_exception raise errorclass(errno, errval) pymysql.err.InternalError: (1305, 'SAVEPOINT s1d7433f1e863451e99871f44bdaa795c does not exist') ``` I see an unanswered 4-year-old Stack Overflow question about this: https://stackoverflow.com/questions/37870898/peewee-savepoint-does-not-exist When searching for "mysql savepoint does not exist" I'm led to: https://stackoverflow.com/a/19672316 I also saw [this](https://stackoverflow.com/a/42264410) SO post about another way to do transactions with PeeWee. But `set_autocommit` doesn't appear to be an option on `db` anymore as it gives me an error. Any ideas what's causing this? It _seems_ like a bug to me as I'm doing this exactly the way it's stated in the [docs](https://docs.peewee-orm.com/en/3.4.0/peewee/transactions.html#transactions). But I could've borked something somewhere along the line.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2221/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2221/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2220
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2220/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2220/comments
https://api.github.com/repos/coleifer/peewee/issues/2220/events
https://github.com/coleifer/peewee/issues/2220
651,644,596
MDU6SXNzdWU2NTE2NDQ1OTY=
2,220
Peewee crashes when applying distinct to an expression
{ "login": "StefanosChaliasos", "id": 15054312, "node_id": "MDQ6VXNlcjE1MDU0MzEy", "avatar_url": "https://avatars.githubusercontent.com/u/15054312?v=4", "gravatar_id": "", "url": "https://api.github.com/users/StefanosChaliasos", "html_url": "https://github.com/StefanosChaliasos", "followers_url": "https://api.github.com/users/StefanosChaliasos/followers", "following_url": "https://api.github.com/users/StefanosChaliasos/following{/other_user}", "gists_url": "https://api.github.com/users/StefanosChaliasos/gists{/gist_id}", "starred_url": "https://api.github.com/users/StefanosChaliasos/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/StefanosChaliasos/subscriptions", "organizations_url": "https://api.github.com/users/StefanosChaliasos/orgs", "repos_url": "https://api.github.com/users/StefanosChaliasos/repos", "events_url": "https://api.github.com/users/StefanosChaliasos/events{/privacy}", "received_events_url": "https://api.github.com/users/StefanosChaliasos/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Thanks, this is now fixed." ]
2020-07-06T15:50:58
2020-07-07T13:39:49
2020-07-07T13:39:32
NONE
null
**Describe the bug** When applying `distinct` to an expression peewee crashes with `TypeError`. Beyond a table's column, in postgres distinct gets an [arbitrary expression](https://www.postgresql.org/docs/9.5/sql-select.html) **Expected behavior** ```python expr = (Model.column_a + Model.column_b).alias('expr') Model.select(expr).order_by(expr).distinct(expr.alias()) ``` I expect the following query: ```sql SELECT DISTINCT ON ("t1"."column_a" + "t1"."column_b") "t1"."column_a" + "t1"."column_b" AS "expr" FROM "model" AS "t1" ORDER BY "t1"."column_a" + "t1"."column_b"; ``` Instead I get the following exception: ``` Traceback (most recent call last): File "program.py", line 22, in <module> print(Model.select(expr).order_by(expr).distinct(expr.alias())) File "/home/.env/lib/python3.8/site-packages/peewee-3.13.3-py3.8.egg/peewee.py", line 1885, in inner return method(self, database, *args, **kwargs) File "/home/.env/lib/python3.8/site-packages/peewee-3.13.3-py3.8.egg/peewee.py", line 2143, in first return self.peek(database, n=n) File "/home/.env/lib/python3.8/site-packages/peewee-3.13.3-py3.8.egg/peewee.py", line 1885, in inner return method(self, database, *args, **kwargs) File "/home/.env/lib/python3.8/site-packages/peewee-3.13.3-py3.8.egg/peewee.py", line 2134, in peek rows = self.execute(database)[:n] File "/home/.env/lib/python3.8/site-packages/peewee-3.13.3-py3.8.egg/peewee.py", line 1885, in inner return method(self, database, *args, **kwargs) File "/home/.env/lib/python3.8/site-packages/peewee-3.13.3-py3.8.egg/peewee.py", line 1956, in execute return self._execute(database) File "/home/.env/lib/python3.8/site-packages/peewee-3.13.3-py3.8.egg/peewee.py", line 2128, in _execute cursor = database.execute(self) File "/home/.env/lib/python3.8/site-packages/peewee-3.13.3-py3.8.egg/peewee.py", line 3118, in execute sql, params = ctx.sql(query).query() File "/home/.env/lib/python3.8/site-packages/peewee-3.13.3-py3.8.egg/peewee.py", line 606, in sql return obj.__sql__(self) File "/home/.env/lib/python3.8/site-packages/peewee-3.13.3-py3.8.egg/peewee.py", line 2383, in __sql__ .sql(EnclosedNodeList(self._distinct)) File "/home/.env/lib/python3.8/site-packages/peewee-3.13.3-py3.8.egg/peewee.py", line 1760, in EnclosedNodeList return NodeList(nodes, ', ', True) File "/home/.env/lib/python3.8/site-packages/peewee-3.13.3-py3.8.egg/peewee.py", line 1740, in __init__ self.nodes[0] = self.nodes[0].clone() TypeError: 'tuple' object does not support item assignment ``` I assume that there is a programing error because peewee tries to assign something to a tuple object, although tuples in Python are immutable
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2220/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2220/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/2219
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/2219/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/2219/comments
https://api.github.com/repos/coleifer/peewee/issues/2219/events
https://github.com/coleifer/peewee/issues/2219
651,251,740
MDU6SXNzdWU2NTEyNTE3NDA=
2,219
Override select()
{ "login": "wilberh", "id": 6799242, "node_id": "MDQ6VXNlcjY3OTkyNDI=", "avatar_url": "https://avatars.githubusercontent.com/u/6799242?v=4", "gravatar_id": "", "url": "https://api.github.com/users/wilberh", "html_url": "https://github.com/wilberh", "followers_url": "https://api.github.com/users/wilberh/followers", "following_url": "https://api.github.com/users/wilberh/following{/other_user}", "gists_url": "https://api.github.com/users/wilberh/gists{/gist_id}", "starred_url": "https://api.github.com/users/wilberh/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/wilberh/subscriptions", "organizations_url": "https://api.github.com/users/wilberh/orgs", "repos_url": "https://api.github.com/users/wilberh/repos", "events_url": "https://api.github.com/users/wilberh/events{/privacy}", "received_events_url": "https://api.github.com/users/wilberh/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Please quit spamming the same question. This is the third time you've posted some variation of this question. Asked and answered.", "Apologies; just trying to figure out any other way of removing double quotes. \r\nI'm using Impyla which is fully DB API v2.0 compiant. And the HiveServer2 (Hive) gives an error when it sees double quoted column-names." ]
2020-07-06T05:14:29
2020-07-06T18:01:35
2020-07-06T13:28:54
NONE
null
How can I override the select() method from the Model class? I need to remove remove the double quotes from the sql strings created by peewee so my DBAPI v2.0 compliant driver database can take it.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/2219/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/2219/timeline
null
completed
null
null