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/1518
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1518/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1518/comments
https://api.github.com/repos/coleifer/peewee/issues/1518/events
https://github.com/coleifer/peewee/issues/1518
300,175,206
MDU6SXNzdWUzMDAxNzUyMDY=
1,518
Alias does not preserve schema
{ "login": "Karel-van-de-Plassche", "id": 6404167, "node_id": "MDQ6VXNlcjY0MDQxNjc=", "avatar_url": "https://avatars.githubusercontent.com/u/6404167?v=4", "gravatar_id": "", "url": "https://api.github.com/users/Karel-van-de-Plassche", "html_url": "https://github.com/Karel-van-de-Plassche", "followers_url": "https://api.github.com/users/Karel-van-de-Plassche/followers", "following_url": "https://api.github.com/users/Karel-van-de-Plassche/following{/other_user}", "gists_url": "https://api.github.com/users/Karel-van-de-Plassche/gists{/gist_id}", "starred_url": "https://api.github.com/users/Karel-van-de-Plassche/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/Karel-van-de-Plassche/subscriptions", "organizations_url": "https://api.github.com/users/Karel-van-de-Plassche/orgs", "repos_url": "https://api.github.com/users/Karel-van-de-Plassche/repos", "events_url": "https://api.github.com/users/Karel-van-de-Plassche/events{/privacy}", "received_events_url": "https://api.github.com/users/Karel-van-de-Plassche/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Maybe related `netAlias.select().get()` fails too with the same error, although `netAlias.get()` works.", "Fixed in d7f0350, thanks so much for reporting." ]
2018-02-26T10:03:17
2018-02-26T16:19:54
2018-02-26T16:19:39
NONE
null
Using peewee 3.1.0. I'm trying to use an alias in a self-join to create a common table expression. However, I get an error that the aliased table name does not exists. I think this is because alias does not preserve the schema. Minimal example: ``` Python netAlias = Network.alias('net') cte = Network.select(Network.id, netAlias.networks).from_(Network, netAlias).cte('nets') query = net.select().with_cte(cte) query.sql() ('WITH "nets" AS (SELECT "t1"."id", "net"."networks" FROM "develop"."network" AS "t1", "network" AS "net") SELECT "t2"."id", "t2"."feature_names", "t2"."target_names", "t2"."recipe", "t2"."networks" FROM "develop"."network" AS "t2"', []) query.get() ProgrammingError: relation "network" does not exist LINE 1: ...net"."networks" FROM "develop"."network" AS "t1", "network" ... ``` I would expect from_ in the cte to generate `"develop"."network" AS "net"`, not `"network" as "net"`. However, I'm an SQL noob and might be using cte's wrong.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1518/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1518/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1517
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1517/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1517/comments
https://api.github.com/repos/coleifer/peewee/issues/1517/events
https://github.com/coleifer/peewee/issues/1517
300,122,871
MDU6SXNzdWUzMDAxMjI4NzE=
1,517
why does rawquery not support iterator
{ "login": "m358807551", "id": 14256423, "node_id": "MDQ6VXNlcjE0MjU2NDIz", "avatar_url": "https://avatars.githubusercontent.com/u/14256423?v=4", "gravatar_id": "", "url": "https://api.github.com/users/m358807551", "html_url": "https://github.com/m358807551", "followers_url": "https://api.github.com/users/m358807551/followers", "following_url": "https://api.github.com/users/m358807551/following{/other_user}", "gists_url": "https://api.github.com/users/m358807551/gists{/gist_id}", "starred_url": "https://api.github.com/users/m358807551/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/m358807551/subscriptions", "organizations_url": "https://api.github.com/users/m358807551/orgs", "repos_url": "https://api.github.com/users/m358807551/repos", "events_url": "https://api.github.com/users/m358807551/events{/privacy}", "received_events_url": "https://api.github.com/users/m358807551/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Is there a very compelling reason for using `raw()` in your case? The above could simply be written as `Article.select()`.\r\n\r\nRaw queries *do* support iterator in 3.x:\r\n\r\n```python\r\n\r\nquery = Article.raw('select * from article')\r\nfor article in query.iterator():\r\n # do something with article.\r\n```", "In 3.x raw queries support `iterator()`.", "Thank you." ]
2018-02-26T06:25:22
2018-02-27T03:20:37
2018-02-26T16:04:39
NONE
null
I want to execute some codes like: `Article.raw("select * from article").iterator()`. However, I got: `{AttributeError}'RawQuery' object has no attribute 'iterator'`
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1517/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1517/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1516
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1516/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1516/comments
https://api.github.com/repos/coleifer/peewee/issues/1516/events
https://github.com/coleifer/peewee/issues/1516
300,074,860
MDU6SXNzdWUzMDAwNzQ4NjA=
1,516
Peewee+PSQL: create_tables for complex object relationships broken when DeferredRelations in play
{ "login": "josefdlange", "id": 1062835, "node_id": "MDQ6VXNlcjEwNjI4MzU=", "avatar_url": "https://avatars.githubusercontent.com/u/1062835?v=4", "gravatar_id": "", "url": "https://api.github.com/users/josefdlange", "html_url": "https://github.com/josefdlange", "followers_url": "https://api.github.com/users/josefdlange/followers", "following_url": "https://api.github.com/users/josefdlange/following{/other_user}", "gists_url": "https://api.github.com/users/josefdlange/gists{/gist_id}", "starred_url": "https://api.github.com/users/josefdlange/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/josefdlange/subscriptions", "organizations_url": "https://api.github.com/users/josefdlange/orgs", "repos_url": "https://api.github.com/users/josefdlange/repos", "events_url": "https://api.github.com/users/josefdlange/events{/privacy}", "received_events_url": "https://api.github.com/users/josefdlange/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I'm not sure about the answer to 1, but I'm pretty sure that before the only approach that worked was to substitute the circular instance of the `ForeignKeyField` with an `IntegerField` (or whatever), e.g.:\r\n\r\n```python\r\n\r\nclass User(Model):\r\n favorite_tweet_id = IntegerField()\r\n\r\nclass Tweet(Model):\r\n user = ForeignKeyField(User)\r\n```\r\n\r\nIn the above instance no constraint is created for the \"favorite_tweet_id\" column.\r\n\r\nThe approach described in the docs for 2.10 allows you to declare the foreign-key *and* create the constraint:\r\n\r\n```python\r\n\r\n# Create a reference object to stand in for our as-yet-undefined Tweet model.\r\nDeferredTweet = DeferredRelation()\r\n\r\nclass User(Model):\r\n username = CharField()\r\n # Tweet has not been defined yet so use the deferred reference.\r\n favorite_tweet = ForeignKeyField(DeferredTweet, null=True)\r\n\r\nclass Tweet(Model):\r\n message = TextField()\r\n user = ForeignKeyField(User, related_name='tweets')\r\n\r\n# Now that Tweet is defined, we can initialize the reference.\r\nDeferredTweet.set_model(Tweet)\r\n\r\n# Foreign key constraint from User -> Tweet will NOT be created because the\r\n# Tweet table does not exist yet. `favorite_tweet` will just be a regular\r\n# integer field:\r\nUser.create_table()\r\n\r\n# Foreign key constraint from Tweet -> User will be created normally.\r\nTweet.create_table()\r\n\r\n# Now that both tables exist, we can create the foreign key from User -> Tweet:\r\n# NOTE: this will not work in SQLite!\r\ndb.create_foreign_key(User, User.favorite_tweet)\r\n```\r\n\r\nIn 3.0 it has gotten somewhat easier:\r\n\r\n```python\r\n\r\nclass User(Model):\r\n username = CharField()\r\n # Tweet has not been defined yet so use the deferred reference.\r\n favorite_tweet = DeferredForeignKey('Tweet', null=True)\r\n\r\nclass Tweet(Model):\r\n message = TextField()\r\n user = ForeignKeyField(User, backref='tweets')\r\n\r\ndb.create_tables([User, Tweet])\r\nUser._schema.create_foreign_key(User.favorite_tweet)\r\n```", "I think I'll reopen this to add the \"create_foreign_key()\" API back.", "See commit c0c5a0af9ee985bbcb1c4350d992925c1d5b7799 -- updated above comments to reflect changes.", "Documentation for 3.x updated:\r\n\r\n* http://docs.peewee-orm.com/en/latest/peewee/models.html#circular-foreign-key-dependencies\r\n* http://docs.peewee-orm.com/en/latest/peewee/api.html#SchemaManager.create_foreign_key", "My goodness you're fantastic. Thanks for the quick turnaround and thoughts. Any thoughts as to why it was just working before? \r\n\r\nI was using the `test_database` context manager / decorator from `playhouse` which in turn uses `create_model_tables`. It hadn't had any problems or complaints until I upgraded from `2.8.0` (woah, just realized how far behind I'd been; that's like 2 years!) just recently.", "By \"working before\" do you mean that the constraints were all set-up in the database schema? I'm not sure that that's the case. I'm also not sure what specific problems/complaints you ran into after upgrading?", "Sorry, to clarify:\n\n2.8.0: using `test_database` decorator had no problem building the entire graph of tables (circular FK relationships included) from scratch in my test suite, for each test.\n\n>2.8.0: some tables just fail to create because their depended-upon tables don't yet exist.\n\n> On Feb 26, 2018, at 4:03 PM, Charles Leifer <[email protected]> wrote:\n> \n> By \"working before\" do you mean that the constraints were all set-up in the database schema? I'm not sure that that's the case. I'm also not sure what specific problems/complaints you ran into after upgrading?\n> \n> —\n> You are receiving this because you authored the thread.\n> Reply to this email directly, view it on GitHub <https://github.com/coleifer/peewee/issues/1516#issuecomment-368696079>, or mute the thread <https://github.com/notifications/unsubscribe-auth/ABA3s8ahuaZcJIQ7DsBbxAi1rm-DjhYwks5tY0ZEgaJpZM4SShgX>.\n> \n\n", "You're positive that *both* foreign key constraints are being created? Hmm... and what version are you using now? It'd be great if you could show me the versions you're using and the exact issues you're experiencing with each.", "I'll have to pull together an example for you without proprietary info. I'm not certain the actual FK constraint is being generated, frankly, but at least the tables get successfully created. I am certain that `2.8.0` it \"works\" on -- insofar that at least the tables don't fail to be created.\r\n\r\nIf you're okay with waiting a bit, I'll try to come up with a simplified example and find the version breakpoint.", "Thanks, that'd be great. I'm willing to bet that the constraint isn't being created in the 2.8 example, so it appears to work, but if you wanted you would be able to break referential integrity.\r\n\r\nYou could test this with your existing code:\r\n\r\n```python\r\nclass User(Model):\r\n favorite_tweet = DeferredForeignKey('Tweet')\r\n username = TextField()\r\n\r\nclass Tweet(Model):\r\n user = ForeignKeyField(User, backref='tweets')\r\n content = TextField()\r\n\r\ndb.create_tables([User, Tweet])\r\n# If the constraint exists, the following will raise an error since the\r\n# tweet with the corresponding ID (12345 in the example) wouldn't exist:\r\nu = User.create(favorite_tweet=12345, username='foo')\r\n```", "Re-reading the issue, I'm a little unclear what exact issue you're encountering? Is there a specific error you're running into after upgrading? Is this error related to `create_tables()` or does it only happen when using some test setup?\r\n\r\nFor what it's worth, peewee 3.x removes `test_database`. There are a few alternatives described in #1440 and the peewee tests themselves.", "Okay, after more monkeying around, I've narrowed it down to `2.10.x`, here's the difference of what occurs.\r\n\r\nWhen using `create_model_tables` (in my case the usage of it embedded within `test_database`), I have determined that, given models `Foo` and `Bar` with a circular FK dependency:\r\n\r\n* `< 2.10.x`: tables create okay, but as you suspect, `Foo`'s FK to `Bar` doesn't actually have the constraint (but at least the table gets created with the right type on the column for `bar_id`).\r\n\r\n* `>= 2.10.x`: tables fail to create right away; creation of `Foo` complains that relation `bar` doesn't yet exist.\r\n\r\nI'll poke around the 2.10.x changelog and commits to see what might have happened, but I'd guess we're zeroing in on some change that more strictly enforces the creation of the constraint straightaway.", "Hmm... it looks like changes to the way deferred foreign-keys were resolved, although there are quite a few changes so I'm not positive.\r\n\r\nAt any rate, I don't think there's a whole lot I can offer, as Peewee is now at 3.x and any fixes would pertain to how the code functions in 3.x (which is somewhat different from 2.10). Sorry not to be of more help.", "I appreciate your help with the investigation. I'm looking to get to 3.x eventually, but wanted to understand what was going wrong here before I opened that can of worms." ]
2018-02-25T23:58:34
2018-02-27T17:57:25
2018-02-27T17:56:09
CONTRIBUTOR
null
As in the docs, circular FK dependencies are a code smell, and I agree, but here we are. I've got a big object domain with some of these objects having circular foreign keys. In `peewee` versions in the 2.8 line, `create_tables` seemed to be able to resolve any `DeferredRelation`s used for circular FK relationships and tell PSQL to create the tables appropriately. I see in the [docs](http://docs.peewee-orm.com/en/2.10.2/peewee/models.html#circular-foreign-key-dependencies) that there's a more manual approach documented, but I've never encountered need for it until upgrading from 2.8.x to 2.10.x. Two questions: 1) Am I correct in finding that the behavior of automatically doing this was done by `peewee` prior, and is now no longer supported? (otherwise, what magic could it have been that made this work before?) 2) Do you have any recommended methods for enabling a more opinionated methodology to creating tables in this way, or automating the process as documented? My CI environment does a build/teardown of tables every run (sometimes every test) and I'm thinking that having a special codepath for each `DeferredRelation`'s setup is a little unclean. I know it's a way uncommon use-case (and a noncurrent version on top of that), but I'm hoping you might have some top-of-the-head insight as to what in particular changed; the changelog between the versions don't really show anything that appears related. As always, thanks for your continued work and support on this tool -- it's a wonderful piece of tech.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1516/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1516/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1515
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1515/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1515/comments
https://api.github.com/repos/coleifer/peewee/issues/1515/events
https://github.com/coleifer/peewee/issues/1515
300,039,510
MDU6SXNzdWUzMDAwMzk1MTA=
1,515
Add `column_exists` method to `Database` class
{ "login": "stanislavkozlovski", "id": 13639618, "node_id": "MDQ6VXNlcjEzNjM5NjE4", "avatar_url": "https://avatars.githubusercontent.com/u/13639618?v=4", "gravatar_id": "", "url": "https://api.github.com/users/stanislavkozlovski", "html_url": "https://github.com/stanislavkozlovski", "followers_url": "https://api.github.com/users/stanislavkozlovski/followers", "following_url": "https://api.github.com/users/stanislavkozlovski/following{/other_user}", "gists_url": "https://api.github.com/users/stanislavkozlovski/gists{/gist_id}", "starred_url": "https://api.github.com/users/stanislavkozlovski/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/stanislavkozlovski/subscriptions", "organizations_url": "https://api.github.com/users/stanislavkozlovski/orgs", "repos_url": "https://api.github.com/users/stanislavkozlovski/repos", "events_url": "https://api.github.com/users/stanislavkozlovski/events{/privacy}", "received_events_url": "https://api.github.com/users/stanislavkozlovski/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I don't plan on adding that API, you can very easily use the `get_columns()`, as you've indicated, to achieve equivalent results." ]
2018-02-25T16:28:23
2018-02-26T15:01:54
2018-02-26T15:01:54
NONE
null
Currently, when running migrations, I'd like to check if a column exists. My current solution is the following: ```python3 column_name = 'name' table_name = 'users' if any(column_data.name == column_name for column_data in db.get_columns(table_name)): pass ``` This also produces the following query (PostgreSQL) which is overkill: ```sql SELECT column_name, is_nullable, data_type FROM information_schema.columns WHERE table_name = 'users' AND table_schema = 'public' ORDER BY ordinal_position ``` What I'd like to have is: ```python3 column_name = 'name' table_name = 'users' if db.column_exists(table_name, column_name): pass ``` And it could produce something like the following query: ```sql EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name = 'users' AND table_schema = 'public' AND column_name='name') ``` I could implement this myself, I'd just like somebody to approve it.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1515/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1515/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1514
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1514/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1514/comments
https://api.github.com/repos/coleifer/peewee/issues/1514/events
https://github.com/coleifer/peewee/issues/1514
299,984,978
MDU6SXNzdWUyOTk5ODQ5Nzg=
1,514
Default order in 3.x
{ "login": "phryk", "id": 1021513, "node_id": "MDQ6VXNlcjEwMjE1MTM=", "avatar_url": "https://avatars.githubusercontent.com/u/1021513?v=4", "gravatar_id": "", "url": "https://api.github.com/users/phryk", "html_url": "https://github.com/phryk", "followers_url": "https://api.github.com/users/phryk/followers", "following_url": "https://api.github.com/users/phryk/following{/other_user}", "gists_url": "https://api.github.com/users/phryk/gists{/gist_id}", "starred_url": "https://api.github.com/users/phryk/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/phryk/subscriptions", "organizations_url": "https://api.github.com/users/phryk/orgs", "repos_url": "https://api.github.com/users/phryk/repos", "events_url": "https://api.github.com/users/phryk/events{/privacy}", "received_events_url": "https://api.github.com/users/phryk/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "The feature was dropped due to it's perceived smelliness... If you want to achieve something similar in 3.x, you can always:\r\n\r\n```python\r\nclass User(Model):\r\n username = TextField()\r\n\r\n @classmethod\r\n def ordered(cls, *args):\r\n return cls.select(*args).order_by(cls.username)\r\n\r\nunordered = User.select().where(...)\r\nordered = User.ordered().where(...)\r\n```", "I miss this feature too, though I do agree that it's a bit smelly. Nevertheless, it can be very handy, especially when you're trying to get a quick and dirty web app put together. One notable example is in flask-admin, where you want the dropdown menus for automatically scaffolded foreign key fields to be in a sane order.\r\n\r\nJust wanted to share my quick re-implementation of this feature for anyone else that might be looking for it:\r\n\r\n```python\r\nclass BaseModel(ModelBase):\r\n\r\n class Meta:\r\n order_by = [] # override this value in subclasses, e.g. `order_by = ['name']`\r\n\r\n # Simple re-implementation of default ordering that was removed in peewee 3.x\r\n # Ideally, ordering should always be explicitly set in query, but this can be\r\n # very handy, esp. for auto-scaffolding frameworks like flask-admin\r\n @classmethod\r\n def select(cls, *fields):\r\n order_by = []\r\n\r\n for field_name in cls._meta.order_by:\r\n if field_name.startswith('-'):\r\n order_by.append(getattr(cls, field_name[1:]).desc())\r\n else:\r\n order_by.append(getattr(cls, field_name))\r\n\r\n return super(BaseModel, cls).select(*fields).order_by(*order_by)\r\n```", "I would think `flask-admin` doesn't provide a way to define or override the query of related objects, but *shrug*?" ]
2018-02-25T00:23:26
2019-08-09T16:39:23
2018-02-26T16:24:49
NONE
null
The "Changes in 3.0" documentation page states that `_meta.order_by` has been removed, but it doesn't state anything on how to set a default ordering in 3.x and I haven't found anything on this in the code either. Is there now a better way of doing this or was this feature just dropped without a substitute? If the latter is true, would you consider bringing it back? I always considered `_meta.order_by` to be a good DX boon. :<
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1514/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1514/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1513
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1513/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1513/comments
https://api.github.com/repos/coleifer/peewee/issues/1513/events
https://github.com/coleifer/peewee/issues/1513
299,949,956
MDU6SXNzdWUyOTk5NDk5NTY=
1,513
pip install peewee fails on Windows
{ "login": "Mastergalen", "id": 1261152, "node_id": "MDQ6VXNlcjEyNjExNTI=", "avatar_url": "https://avatars.githubusercontent.com/u/1261152?v=4", "gravatar_id": "", "url": "https://api.github.com/users/Mastergalen", "html_url": "https://github.com/Mastergalen", "followers_url": "https://api.github.com/users/Mastergalen/followers", "following_url": "https://api.github.com/users/Mastergalen/following{/other_user}", "gists_url": "https://api.github.com/users/Mastergalen/gists{/gist_id}", "starred_url": "https://api.github.com/users/Mastergalen/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/Mastergalen/subscriptions", "organizations_url": "https://api.github.com/users/Mastergalen/orgs", "repos_url": "https://api.github.com/users/Mastergalen/repos", "events_url": "https://api.github.com/users/Mastergalen/events{/privacy}", "received_events_url": "https://api.github.com/users/Mastergalen/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "+1 This error is often due to dependency of GCC, however for me it still fails on WSL (GCC installed via `sudo apt-get install build-essentials`)", "I don't understand that traceback. What file is missing? Is this a recent regression or common to all 3.x?", "Do you have a C compiler and Cython installed? Have you tried installing different versions?", "https://www.microsoft.com/en-us/download/details.aspx?id=44266", "My guess is that you have Cython installed, but perhaps it was installed as a binary package, and that you don't actually have a C compiler? The setup.py for peewee checks if you have Cython, and only if you have Cython, will it include instructions for building the C extensions... So my guess is that Cython is there, but somehow the build_ext command is failing when attempting to compile the actual extension?", "@coleifer \r\n\r\nI am running WSL (Windows subsystem linux) which in my case using Ubuntu distro so no, there is no need for Cython.\r\n\r\nThe build essential should be enough for a C and C++ compiler\r\n```bash\r\nsudo apt-get install build-essential\r\n```\r\n\r\n## Linux (WSL) Error\r\nThe WSL is similar to @Mastergalen's error interestingly.\r\n\r\n```\r\npip install peewee\r\nCollecting peewee\r\n Using cached peewee-3.1.0.tar.gz\r\nBuilding wheels for collected packages: peewee\r\n Running setup.py bdist_wheel for peewee ... error\r\n Complete output from command /home/keto/anaconda3/bin/python -u -c \"import setuptools, tokenize;__file__='/tmp/pip-build-t_5tqb83/peewee/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\\r\\n', '\\n');f.close();exec(compile(code, __file__, 'exec'))\" bdist_wheel -d /tmp/tmproueelbcpip-wheel- --python-tag cp36:\r\n running bdist_wheel\r\n running build\r\n running build_py\r\n creating build\r\n creating build/lib.linux-x86_64-3.6\r\n copying peewee.py -> build/lib.linux-x86_64-3.6\r\n copying pwiz.py -> build/lib.linux-x86_64-3.6\r\n creating build/lib.linux-x86_64-3.6/playhouse\r\n copying playhouse/__init__.py -> build/lib.linux-x86_64-3.6/playhouse\r\n copying playhouse/apsw_ext.py -> build/lib.linux-x86_64-3.6/playhouse\r\n copying playhouse/dataset.py -> build/lib.linux-x86_64-3.6/playhouse\r\n copying playhouse/db_url.py -> build/lib.linux-x86_64-3.6/playhouse\r\n copying playhouse/fields.py -> build/lib.linux-x86_64-3.6/playhouse\r\n copying playhouse/flask_utils.py -> build/lib.linux-x86_64-3.6/playhouse\r\n copying playhouse/hybrid.py -> build/lib.linux-x86_64-3.6/playhouse\r\n copying playhouse/migrate.py -> build/lib.linux-x86_64-3.6/playhouse\r\n copying playhouse/pool.py -> build/lib.linux-x86_64-3.6/playhouse\r\n copying playhouse/postgres_ext.py -> build/lib.linux-x86_64-3.6/playhouse\r\n copying playhouse/reflection.py -> build/lib.linux-x86_64-3.6/playhouse\r\n copying playhouse/shortcuts.py -> build/lib.linux-x86_64-3.6/playhouse\r\n copying playhouse/signals.py -> build/lib.linux-x86_64-3.6/playhouse\r\n copying playhouse/sqlcipher_ext.py -> build/lib.linux-x86_64-3.6/playhouse\r\n copying playhouse/sqlite_ext.py -> build/lib.linux-x86_64-3.6/playhouse\r\n copying playhouse/sqlite_udf.py -> build/lib.linux-x86_64-3.6/playhouse\r\n copying playhouse/sqliteq.py -> build/lib.linux-x86_64-3.6/playhouse\r\n copying playhouse/test_utils.py -> build/lib.linux-x86_64-3.6/playhouse\r\n running build_ext\r\n cythoning playhouse/_speedups.pyx to playhouse/_speedups.c\r\n building 'playhouse._speedups' extension\r\n creating build/temp.linux-x86_64-3.6\r\n creating build/temp.linux-x86_64-3.6/playhouse\r\n gcc -pthread -B /home/keto/anaconda3/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/home/keto/anaconda3/include/python3.6m -c playhouse/_speedups.c -o build/temp.linux-x86_64-3.6/playhouse/_speedups.o\r\n gcc -pthread -shared -B /home/keto/anaconda3/compiler_compat -L/home/keto/anaconda3/lib -Wl,-rpath=/home/keto/anaconda3/lib -Wl,--no-as-needed -Wl,--sysroot=/ build/temp.linux-x86_64-3.6/playhouse/_speedups.o -L/home/keto/anaconda3/lib -lpython3.6m -o build/lib.linux-x86_64-3.6/playhouse/_speedups.cpython-36m-x86_64-linux-gnu.so\r\n cythoning playhouse/_sqlite_udf.pyx to playhouse/_sqlite_udf.c\r\n building 'playhouse._sqlite_udf' extension\r\n gcc -pthread -B /home/keto/anaconda3/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/home/keto/anaconda3/include/python3.6m -c playhouse/_sqlite_udf.c -o build/temp.linux-x86_64-3.6/playhouse/_sqlite_udf.o\r\n gcc -pthread -shared -B /home/keto/anaconda3/compiler_compat -L/home/keto/anaconda3/lib -Wl,-rpath=/home/keto/anaconda3/lib -Wl,--no-as-needed -Wl,--sysroot=/ build/temp.linux-x86_64-3.6/playhouse/_sqlite_udf.o -L/home/keto/anaconda3/lib -lpython3.6m -o build/lib.linux-x86_64-3.6/playhouse/_sqlite_udf.cpython-36m-x86_64-linux-gnu.so\r\n cythoning playhouse/_sqlite_ext.pyx to playhouse/_sqlite_ext.c\r\n warning: playhouse/_sqlite_ext.pyx:313:57: local variable 'pNew' referenced before assignment\r\n warning: playhouse/_sqlite_ext.pyx:341:55: local variable 'pCur' referenced before assignment\r\n warning: playhouse/_sqlite_ext.pyx:1017:48: local variable 'bf' referenced before assignment\r\n building 'playhouse._sqlite_ext' extension\r\n gcc -pthread -B /home/keto/anaconda3/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/home/keto/anaconda3/include/python3.6m -c playhouse/_sqlite_ext.c -o build/temp.linux-x86_64-3.6/playhouse/_sqlite_ext.o\r\n playhouse/_sqlite_ext.c:531:21: fatal error: sqlite3.h: No such file or directory\r\n compilation terminated.\r\n error: command 'gcc' failed with exit status 1\r\n\r\n ----------------------------------------\r\n Failed building wheel for peewee\r\n Running setup.py clean for peewee\r\nFailed to build peewee\r\nInstalling collected packages: peewee\r\n Running setup.py install for peewee ... error\r\n Complete output from command /home/keto/anaconda3/bin/python -u -c \"import setuptools, tokenize;__file__='/tmp/pip-build-t_5tqb83/peewee/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\\r\\n', '\\n');f.close();exec(compile(code, __file__, 'exec'))\" install --record /tmp/pip-jszvpzby-record/install-record.txt --single-version-externally-managed --compile:\r\n running install\r\n running build\r\n running build_py\r\n creating build\r\n creating build/lib.linux-x86_64-3.6\r\n copying peewee.py -> build/lib.linux-x86_64-3.6\r\n copying pwiz.py -> build/lib.linux-x86_64-3.6\r\n creating build/lib.linux-x86_64-3.6/playhouse\r\n copying playhouse/__init__.py -> build/lib.linux-x86_64-3.6/playhouse\r\n copying playhouse/apsw_ext.py -> build/lib.linux-x86_64-3.6/playhouse\r\n copying playhouse/dataset.py -> build/lib.linux-x86_64-3.6/playhouse\r\n copying playhouse/db_url.py -> build/lib.linux-x86_64-3.6/playhouse\r\n copying playhouse/fields.py -> build/lib.linux-x86_64-3.6/playhouse\r\n copying playhouse/flask_utils.py -> build/lib.linux-x86_64-3.6/playhouse\r\n copying playhouse/hybrid.py -> build/lib.linux-x86_64-3.6/playhouse\r\n copying playhouse/migrate.py -> build/lib.linux-x86_64-3.6/playhouse\r\n copying playhouse/pool.py -> build/lib.linux-x86_64-3.6/playhouse\r\n copying playhouse/postgres_ext.py -> build/lib.linux-x86_64-3.6/playhouse\r\n copying playhouse/reflection.py -> build/lib.linux-x86_64-3.6/playhouse\r\n copying playhouse/shortcuts.py -> build/lib.linux-x86_64-3.6/playhouse\r\n copying playhouse/signals.py -> build/lib.linux-x86_64-3.6/playhouse\r\n copying playhouse/sqlcipher_ext.py -> build/lib.linux-x86_64-3.6/playhouse\r\n copying playhouse/sqlite_ext.py -> build/lib.linux-x86_64-3.6/playhouse\r\n copying playhouse/sqlite_udf.py -> build/lib.linux-x86_64-3.6/playhouse\r\n copying playhouse/sqliteq.py -> build/lib.linux-x86_64-3.6/playhouse\r\n copying playhouse/test_utils.py -> build/lib.linux-x86_64-3.6/playhouse\r\n running build_ext\r\n skipping 'playhouse/_speedups.c' Cython extension (up-to-date)\r\n building 'playhouse._speedups' extension\r\n creating build/temp.linux-x86_64-3.6\r\n creating build/temp.linux-x86_64-3.6/playhouse\r\n gcc -pthread -B /home/keto/anaconda3/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/home/keto/anaconda3/include/python3.6m -c playhouse/_speedups.c -o build/temp.linux-x86_64-3.6/playhouse/_speedups.o\r\n gcc -pthread -shared -B /home/keto/anaconda3/compiler_compat -L/home/keto/anaconda3/lib -Wl,-rpath=/home/keto/anaconda3/lib -Wl,--no-as-needed -Wl,--sysroot=/ build/temp.linux-x86_64-3.6/playhouse/_speedups.o -L/home/keto/anaconda3/lib -lpython3.6m -o build/lib.linux-x86_64-3.6/playhouse/_speedups.cpython-36m-x86_64-linux-gnu.so\r\n skipping 'playhouse/_sqlite_udf.c' Cython extension (up-to-date)\r\n building 'playhouse._sqlite_udf' extension\r\n gcc -pthread -B /home/keto/anaconda3/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/home/keto/anaconda3/include/python3.6m -c playhouse/_sqlite_udf.c -o build/temp.linux-x86_64-3.6/playhouse/_sqlite_udf.o\r\n gcc -pthread -shared -B /home/keto/anaconda3/compiler_compat -L/home/keto/anaconda3/lib -Wl,-rpath=/home/keto/anaconda3/lib -Wl,--no-as-needed -Wl,--sysroot=/ build/temp.linux-x86_64-3.6/playhouse/_sqlite_udf.o -L/home/keto/anaconda3/lib -lpython3.6m -o build/lib.linux-x86_64-3.6/playhouse/_sqlite_udf.cpython-36m-x86_64-linux-gnu.so\r\n skipping 'playhouse/_sqlite_ext.c' Cython extension (up-to-date)\r\n building 'playhouse._sqlite_ext' extension\r\n gcc -pthread -B /home/keto/anaconda3/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/home/keto/anaconda3/include/python3.6m -c playhouse/_sqlite_ext.c -o build/temp.linux-x86_64-3.6/playhouse/_sqlite_ext.o\r\n playhouse/_sqlite_ext.c:531:21: fatal error: sqlite3.h: No such file or directory\r\n compilation terminated.\r\n error: command 'gcc' failed with exit status 1\r\n\r\n ----------------------------------------\r\nCommand \"/home/keto/anaconda3/bin/python -u -c \"import setuptools, tokenize;__file__='/tmp/pip-build-t_5tqb83/peewee/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\\r\\n', '\\n');f.close();exec(compile(code, __file__, 'exec'))\" install --record /tmp/pip-jszvpzby-record/install-record.txt --single-version-externally-managed --compile\" failed with error code 1 in /tmp/pip-build-t_5tqb83/peewee/\r\n```\r\n", "Cython is installed\r\n```\r\n$ pip show cython\r\nName: Cython\r\nVersion: 0.27.3\r\nLocation: c:\\programdata\\anaconda3\\lib\\site-packages\r\n```\r\n\r\nInstalling the latest Visual Studio Build Tools produces the same error as before.\r\n\r\nI'm temporarily working around this by just setting `cython_installed = False` in `setup.py`", "Thanks for sharing the traceback, this is the problem:\r\n\r\n```\r\nplayhouse/_sqlite_ext.c:531:21: fatal error: sqlite3.h: No such file or directory\r\n```\r\n\r\nIt looks like you've got Cython and a C compiler installed, but are missing the SQLite3 headers. You should be able to:\r\n\r\n```\r\nsudo apt-get install libsqlite3-dev\r\n```\r\n\r\nI wonder if there's a way, in setup.py, to test for the existence of the appropriate headers?", "Regarding checking for the existence of the appropriate headers, just look at the lengths one has to go to:\r\n\r\nhttps://github.com/PyTables/PyTables/blob/develop/setup.py\r\n\r\nUnfortunately, I don't think this is one I'm going to be able to fix... If you have a compiler and Cython, you'll need libsqlite3 as well.\r\n\r\nI'm open to fixing if there's a clean way of doing it... I'm not very keen on setup.py so someone may have good ideas.", "Got this error again and forgot `sudo apt-get install libsqlite3-dev`, would it be possible to print a reminder note on pip installs?", "I'm not sure how one would know to display a warning.", "> `sudo apt-get install libsqlite3-dev`\r\n\r\nThanks!\r\nMaybe it should be specified in the [installation docs](http://docs.peewee-orm.com/en/latest/peewee/installation.html#installing-and-testing)?" ]
2018-02-24T15:45:31
2018-07-15T09:28:20
2018-02-27T00:22:28
NONE
null
`pip install peewee` in an administrator PowerShell fails due to `error: [WinError 2] The system cannot find the file specified` * OS: Windows 10 * Python: 3.6.4 Anaconda 64 bit * Cython v0.27.3 The same error occurs when installing via git: ``` git clone https://github.com/coleifer/peewee.git cd peewee python setup.py install ``` ## Full error ``` PS C:\WINDOWS\system32> pip install peewee Collecting peewee Using cached peewee-3.1.0.tar.gz Building wheels for collected packages: peewee Running setup.py bdist_wheel for peewee ... error Complete output from command c:\programdata\anaconda3\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\MASTER~1\\AppData\\Local\\Temp\\pip-build-t74nv3gg\\peewee\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d C:\Users\MASTER~1\AppData\Local\Temp\tmp9jj2p59dpip-wheel- --python-tag cp36: running bdist_wheel running build running build_py creating build creating build\lib.win-amd64-3.6 copying peewee.py -> build\lib.win-amd64-3.6 copying pwiz.py -> build\lib.win-amd64-3.6 creating build\lib.win-amd64-3.6\playhouse copying playhouse\apsw_ext.py -> build\lib.win-amd64-3.6\playhouse copying playhouse\dataset.py -> build\lib.win-amd64-3.6\playhouse copying playhouse\db_url.py -> build\lib.win-amd64-3.6\playhouse copying playhouse\fields.py -> build\lib.win-amd64-3.6\playhouse copying playhouse\flask_utils.py -> build\lib.win-amd64-3.6\playhouse copying playhouse\hybrid.py -> build\lib.win-amd64-3.6\playhouse copying playhouse\migrate.py -> build\lib.win-amd64-3.6\playhouse copying playhouse\pool.py -> build\lib.win-amd64-3.6\playhouse copying playhouse\postgres_ext.py -> build\lib.win-amd64-3.6\playhouse copying playhouse\reflection.py -> build\lib.win-amd64-3.6\playhouse copying playhouse\shortcuts.py -> build\lib.win-amd64-3.6\playhouse copying playhouse\signals.py -> build\lib.win-amd64-3.6\playhouse copying playhouse\sqlcipher_ext.py -> build\lib.win-amd64-3.6\playhouse copying playhouse\sqliteq.py -> build\lib.win-amd64-3.6\playhouse copying playhouse\sqlite_ext.py -> build\lib.win-amd64-3.6\playhouse copying playhouse\sqlite_udf.py -> build\lib.win-amd64-3.6\playhouse copying playhouse\test_utils.py -> build\lib.win-amd64-3.6\playhouse copying playhouse\__init__.py -> build\lib.win-amd64-3.6\playhouse running build_ext error: [WinError 2] The system cannot find the file specified ---------------------------------------- Failed building wheel for peewee Running setup.py clean for peewee Failed to build peewee Installing collected packages: peewee Running setup.py install for peewee ... error Complete output from command c:\programdata\anaconda3\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\MASTER~1\\AppData\\Local\\Temp\\pip-build-t74nv3gg\\peewee\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\MASTER~1\AppData\Local\Temp\pip-i4m4596t-record\install-record.txt --single-version-externally-managed --compile: running install running build running build_py creating build creating build\lib.win-amd64-3.6 copying peewee.py -> build\lib.win-amd64-3.6 copying pwiz.py -> build\lib.win-amd64-3.6 creating build\lib.win-amd64-3.6\playhouse copying playhouse\apsw_ext.py -> build\lib.win-amd64-3.6\playhouse copying playhouse\dataset.py -> build\lib.win-amd64-3.6\playhouse copying playhouse\db_url.py -> build\lib.win-amd64-3.6\playhouse copying playhouse\fields.py -> build\lib.win-amd64-3.6\playhouse copying playhouse\flask_utils.py -> build\lib.win-amd64-3.6\playhouse copying playhouse\hybrid.py -> build\lib.win-amd64-3.6\playhouse copying playhouse\migrate.py -> build\lib.win-amd64-3.6\playhouse copying playhouse\pool.py -> build\lib.win-amd64-3.6\playhouse copying playhouse\postgres_ext.py -> build\lib.win-amd64-3.6\playhouse copying playhouse\reflection.py -> build\lib.win-amd64-3.6\playhouse copying playhouse\shortcuts.py -> build\lib.win-amd64-3.6\playhouse copying playhouse\signals.py -> build\lib.win-amd64-3.6\playhouse copying playhouse\sqlcipher_ext.py -> build\lib.win-amd64-3.6\playhouse copying playhouse\sqliteq.py -> build\lib.win-amd64-3.6\playhouse copying playhouse\sqlite_ext.py -> build\lib.win-amd64-3.6\playhouse copying playhouse\sqlite_udf.py -> build\lib.win-amd64-3.6\playhouse copying playhouse\test_utils.py -> build\lib.win-amd64-3.6\playhouse copying playhouse\__init__.py -> build\lib.win-amd64-3.6\playhouse running build_ext error: [WinError 2] The system cannot find the file specified ---------------------------------------- Command "c:\programdata\anaconda3\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\MASTER~1\\AppData\\Local\\Temp\\pip-build-t74nv3gg\\peewee\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\MASTER~1\AppData\Local\Temp\pip-i4m4596t-record\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\MASTER~1\AppData\Local\Temp\pip-build-t74nv3gg\peewee\ PS C:\WINDOWS\system32> python --version Python 3.6.4 :: Anaconda custom (64-bit) ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1513/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1513/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1512
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1512/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1512/comments
https://api.github.com/repos/coleifer/peewee/issues/1512/events
https://github.com/coleifer/peewee/issues/1512
299,445,102
MDU6SXNzdWUyOTk0NDUxMDI=
1,512
Postgres on_conflict quirks
{ "login": "rammie", "id": 554792, "node_id": "MDQ6VXNlcjU1NDc5Mg==", "avatar_url": "https://avatars.githubusercontent.com/u/554792?v=4", "gravatar_id": "", "url": "https://api.github.com/users/rammie", "html_url": "https://github.com/rammie", "followers_url": "https://api.github.com/users/rammie/followers", "following_url": "https://api.github.com/users/rammie/following{/other_user}", "gists_url": "https://api.github.com/users/rammie/gists{/gist_id}", "starred_url": "https://api.github.com/users/rammie/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/rammie/subscriptions", "organizations_url": "https://api.github.com/users/rammie/orgs", "repos_url": "https://api.github.com/users/rammie/repos", "events_url": "https://api.github.com/users/rammie/events{/privacy}", "received_events_url": "https://api.github.com/users/rammie/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Thanks for reporting. Fucking stupid-ass postgres with it's janky raggedy-ass overly-complicated upsert and rules for using aliases in insert queries...grumble grumble.\r\n\r\nWorking on a fix.", "Thanks again for the very helpful report -- added tests and have it working: e642ab9e35603a565d89240b62e0e93c532e569e", "Wow, thanks for the quick fix as always. Very excited to start using it, can't wait to port my raw upsert queries to peewee 3.0. And yeah, fuck their stupid rules for using aliases in insert queries.", "Cool, keep me posted if you run into issues. Pushed 3.0.20 which contains this latest fix.", "Hello, I have the same issue with insert_from method.\r\nDo you know how to fix this?\r\n\r\n```\r\nTraceback (most recent call last):\r\n File \"...\\venv\\lib\\site-packages\\peewee.py\", line 2484, in execute_sql\r\n cursor.execute(sql, params or ())\r\npsycopg2.ProgrammingError: la referencia a la columna «source_cd» es ambigua\r\nLINE 1: ..._name\", \"source_cd\" = EXCLUDED.\"source_cd\" WHERE (\"source_cd...\r\n```", "Can you provide an example?", "I need update rows only when source_cd is different than 1\r\n\r\n*Code*\r\n```\r\n person_alias = Person.alias('x')\r\n inst = person_alias.insert_from(\r\n person_raw_ext.select(person_raw_ext.ext_person_cd,\r\n person_raw_ext.ext_person_formatted_cd,\r\n person_raw_ext.ext_person_name,\r\n person_raw_ext.ext_source_cd),\r\n [person_alias.code, person_alias.formatted,\r\n person_alias.name, person_alias.source_cd]) \\\r\n .on_conflict(conflict_target=Person.code,\r\n preserve=[Person.name, Person.source_cd],\r\n where=(person_alias.source_cd != 1))\r\n\r\n print(inst.sql())\r\n inst.execute()\r\n```\r\n\r\n*Output*\r\n```\r\n('INSERT INTO \"public\".\"person\" (\"person_cd\", \"person_formatted_cd\", \"person_name\", \"source_cd\") SELECT \"t1\".\"ext_person_cd\", \"t1\".\"ext_person_formatted_cd\", \"t1\".\"ext_person_name\", \"t1\".\"ext_source_cd\" FROM \"lnd_sii\".\"vw_person_ext\" AS \"t1\" ON CONFLICT (\"person_cd\") DO UPDATE SET \"person_name\" = EXCLUDED.\"person_name\", \"source_cd\" = EXCLUDED.\"source_cd\" WHERE (\"source_cd\" != %s) RETURNING \"person_cd\"', [1])\r\nTraceback (most recent call last):\r\n File \"C:\\Users\\ah250065\\Documents\\Personal\\bidding\\bidding-etl\\venv\\lib\\site-packages\\peewee.py\", line 2484, in execute_sql\r\n cursor.execute(sql, params or ())\r\npsycopg2.ProgrammingError: la referencia a la columna «source_cd» es ambigua\r\nLINE 1: ..._name\", \"source_cd\" = EXCLUDED.\"source_cd\" WHERE (\"source_cd...\r\n ^\r\n```\r\n", "muchas gracias, I'll put together a failing test and see if I can work out a solution.", "You might try a couple things:\r\n\r\n* upgrade to the latest peewee if you haven't already\r\n* looks like you're using `person_alias` in some places and `Person` in others -- try just using `Person` throughout as the alias doesn't seem necessary in the example given\r\n\r\nAttempted to replicate the query here: 7946037c40030ea5dd7539b054562bf19f57c317 -- the test is passing, though the sql looks a bit different than in your example -- namely, the where clause column reference is fully-qualified." ]
2018-02-22T17:41:16
2018-11-19T04:12:15
2018-02-22T20:06:03
NONE
null
First off, many thanks for supporting upsert functionality in peewee 3.0! I'm using postgres as the db engine and ran into a quirk: ```python class Model(Model): a = CharField(index=True) c = IntegerField(default=0) cls = Model # Does not work # Produces error: # ProgrammingError: column reference "c" is ambiguous cls.insert({ cls.a: "Hello world", cls.c: 5 }).on_conflict( conflict_target=(cls.a, ), update={cls.c: cls.c + 5} ).execute() # works! cls.insert({ cls.a: "Hello world", cls.c: 5 }).on_conflict( conflict_target=(cls.a, ), update={cls.c: SQL("%s.c" % cls._meta.table_name) + 5} ).execute() ``` The same issue affects the where clause of the on_conflict statements in postgres as well. For example, ```python # Does not work cls.insert({ cls.a: "Hello world", cls.c: 5 }).on_conflict( conflict_target=(cls.a, ), update={cls.c: 5}, where=(cls.c < 5) ).execute() # works! cls.insert({ cls.a: "Hello world", cls.c: 5 }).on_conflict( conflict_target=(cls.a, ), update={cls.c: 5}, where=(SQL("%s.c" % cls._meta.table_name) < 5) ).execute() ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1512/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1512/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1511
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1511/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1511/comments
https://api.github.com/repos/coleifer/peewee/issues/1511/events
https://github.com/coleifer/peewee/issues/1511
299,401,156
MDU6SXNzdWUyOTk0MDExNTY=
1,511
Undefined symbol ReverseRelationDescriptor in peewee.py
{ "login": "rammie", "id": 554792, "node_id": "MDQ6VXNlcjU1NDc5Mg==", "avatar_url": "https://avatars.githubusercontent.com/u/554792?v=4", "gravatar_id": "", "url": "https://api.github.com/users/rammie", "html_url": "https://github.com/rammie", "followers_url": "https://api.github.com/users/rammie/followers", "following_url": "https://api.github.com/users/rammie/following{/other_user}", "gists_url": "https://api.github.com/users/rammie/gists{/gist_id}", "starred_url": "https://api.github.com/users/rammie/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/rammie/subscriptions", "organizations_url": "https://api.github.com/users/rammie/orgs", "repos_url": "https://api.github.com/users/rammie/repos", "events_url": "https://api.github.com/users/rammie/events{/privacy}", "received_events_url": "https://api.github.com/users/rammie/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Thanks for reporting, I must've missed this during the rewrite. Fixed in master now.", "Looks like there are still issues with the `filter()` API...looking into it." ]
2018-02-22T15:40:33
2018-02-22T16:20:27
2018-02-22T16:20:27
NONE
null
The symbol `ReverseRelationDescriptor` does not seem to appear anywhere in peewee.py except here: https://github.com/coleifer/peewee/blob/94aee08a1fee79622148cb1fcd3d2af81a834e04/peewee.py#L5724 Just thought I'd point it out as it seems to have been left behind in error (or I'm missing something).
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1511/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1511/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1510
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1510/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1510/comments
https://api.github.com/repos/coleifer/peewee/issues/1510/events
https://github.com/coleifer/peewee/issues/1510
299,399,677
MDU6SXNzdWUyOTkzOTk2Nzc=
1,510
Error if user closes database inside transaction.
{ "login": "vikt0rs", "id": 5230490, "node_id": "MDQ6VXNlcjUyMzA0OTA=", "avatar_url": "https://avatars.githubusercontent.com/u/5230490?v=4", "gravatar_id": "", "url": "https://api.github.com/users/vikt0rs", "html_url": "https://github.com/vikt0rs", "followers_url": "https://api.github.com/users/vikt0rs/followers", "following_url": "https://api.github.com/users/vikt0rs/following{/other_user}", "gists_url": "https://api.github.com/users/vikt0rs/gists{/gist_id}", "starred_url": "https://api.github.com/users/vikt0rs/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/vikt0rs/subscriptions", "organizations_url": "https://api.github.com/users/vikt0rs/orgs", "repos_url": "https://api.github.com/users/vikt0rs/repos", "events_url": "https://api.github.com/users/vikt0rs/events{/privacy}", "received_events_url": "https://api.github.com/users/vikt0rs/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Out of curiosity, why are you closing the database inside a transaction? That seems incorrect.\r\n\r\nFYI: you ought to change that `db_column=\"document_uuid\"` to `column_name=\"document_uuid\"`.", "> Out of curiosity, why are you closing the database inside a transaction? That seems incorrect.\r\n\r\nWell, this logic was implemented a long time ago and I'm pretty sure, that some reasons exist :) Basically, it depends on `cleanup()`/`on_finish()`/`after_request()` methods inside of the application, and in some cases transaction closes after DB connection has already gone.\r\nPlease, suggest if peewee 3.X can handle this case (2.X version could).\r\n\r\n> FYI: you ought to change that db_column=\"document_uuid\" to column_name=\"document_uuid\".\r\n\r\nthanks for the suggestion, will do\r\n\r\n", "I'm not quite sure how to handle this... I kind of think that Peewee *should* report an error if you close the DB while a transaction is open (although if that's the case, the error message should indicate the problem).", "ok, thanks for suggestions", "f40ec035d2b6f13f4bb5f517ff71e08cf66a1ea1", "FYI `ReconnectMixin` can attempt to close and reopen a DB connection while being inside a transaction, I've had this situation:\r\n\r\n```python\r\nTraceback (most recent call last):\r\n …\r\n File \"/usr/local/lib/python3.9/site-packages/peewee.py\", line 6884, in get\r\n return clone.execute(database)[0]\r\n File \"/usr/local/lib/python3.9/site-packages/peewee.py\", line 1907, in inner\r\n return method(self, database, *args, **kwargs)\r\n File \"/usr/local/lib/python3.9/site-packages/peewee.py\", line 1978, in execute\r\n return self._execute(database)\r\n File \"/usr/local/lib/python3.9/site-packages/peewee.py\", line 2150, in _execute\r\n cursor = database.execute(self)\r\n File \"/usr/local/lib/python3.9/site-packages/peewee.py\", line 3157, in execute\r\n return self.execute_sql(sql, params, commit=commit)\r\n File \"/usr/local/lib/python3.9/site-packages/playhouse/shortcuts.py\", line 226, in execute_sql\r\n self.close()\r\n File \"/usr/local/lib/python3.9/site-packages/peewee.py\", line 3098, in close\r\n raise OperationalError('Attempting to close database while '\r\npeewee.OperationalError: Attempting to close database while transaction is open.\r\n```\r\n\r\nThe funny thing is that it then tries to rollback, but fails because the connection is not working:\r\n\r\n```python\r\nTraceback (most recent call last):\r\n File \"/usr/local/lib/python3.9/site-packages/peewee.py\", line 3301, in rollback\r\n return self._state.conn.rollback()\r\nMySQLdb._exceptions.OperationalError: (2006, 'MySQL server has gone away')\r\n```\r\n\r\nI don't know how to properly handle mid-transaction connection errors. I will probably have to reconnect to the SQL server for each request (even if it seems inefficient to not re-use a connection).", ">I don't know how to properly handle mid-transaction connection errors. I will probably have to reconnect to the SQL server for each request (even if it seems inefficient to not re-use a connection).\r\n\r\nYou have to reconnect and rerun all your queries. If the connection is lost, so is any TX you had open." ]
2018-02-22T15:36:51
2021-09-23T18:35:26
2018-02-22T19:15:41
NONE
null
If a user tries to close database inside a transaction it gets an `IndexError: pop from empty list` in 3X version, not in 2X Please, check console output below and suggest if I do something wrong. Thanks! ``` (postman) macmini987:docs-api vserhei$ pip freeze | grep peewee peewee==2.10.2 peewee-async==0.5.10 (postman) macmini987:docs-api vserhei$ python test_schema_change.py ('SELECT "t1"."document_uuid", "t1"."name" FROM "user_1"."documents_metadata" AS t1 WHERE ("t1"."name" = %s)', ['test']) (postman) macmini987:docs-api vserhei$ (postman) macmini987:docs-api vserhei$ pip install peewee==3.0.18 Collecting peewee==3.0.18 Installing collected packages: peewee Found existing installation: peewee 2.10.2 Uninstalling peewee-2.10.2: Successfully uninstalled peewee-2.10.2 Successfully installed peewee-3.0.18 (postman) macmini987:docs-api vserhei$ (postman) macmini987:docs-api vserhei$ python test_schema_change.py ('SELECT "t1"."document_uuid", "t1"."name" FROM "user_1"."documents_metadata" AS "t1" WHERE ("t1"."name" = %s)', ['test']) Traceback (most recent call last): File "test_schema_change.py", line 33, in <module> DB.close() File "/usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/contextlib.py", line 88, in __exit__ next(self.gen) File "test_schema_change.py", line 27, in context DocumentsModel._meta.schema = None File "/Users/vserhei/src/docs-api/.tox/postman/lib/python3.6/site-packages/peewee.py", line 3251, in __exit__ return self._helper.__exit__(exc_type, exc_val, exc_tb) File "/Users/vserhei/src/docs-api/.tox/postman/lib/python3.6/site-packages/peewee.py", line 3292, in __exit__ self.db.pop_transaction() File "/Users/vserhei/src/docs-api/.tox/postman/lib/python3.6/site-packages/peewee.py", line 2540, in pop_transaction return self._state.transactions.pop() IndexError: pop from empty list (postman) macmini987:docs-api vserhei$ (postman) macmini987:docs-api vserhei$ cat test_schema_change.py from contextlib import contextmanager import peewee DB = peewee.PostgresqlDatabase( "my_documents", user="test_user", password="top_secret" ) class DocumentsModel(peewee.Model): uuid = peewee.UUIDField(primary_key=True, db_column="document_uuid") name = peewee.CharField(256) class Meta: db_table = "documents_metadata" database = DB @contextmanager def context(schema_name): with DB.atomic() as transaction: DocumentsModel._meta.schema = schema_name yield transaction DocumentsModel._meta.schema = None with context('user_1'): print(DocumentsModel.filter(name="test").sql()) if not DB.is_closed(): DB.close() (postman) macmini987:docs-api vserhei$```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1510/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1510/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1509
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1509/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1509/comments
https://api.github.com/repos/coleifer/peewee/issues/1509/events
https://github.com/coleifer/peewee/issues/1509
299,300,867
MDU6SXNzdWUyOTkzMDA4Njc=
1,509
Using 'limit' with 'count' throws ProgrammingError
{ "login": "Karel-van-de-Plassche", "id": 6404167, "node_id": "MDQ6VXNlcjY0MDQxNjc=", "avatar_url": "https://avatars.githubusercontent.com/u/6404167?v=4", "gravatar_id": "", "url": "https://api.github.com/users/Karel-van-de-Plassche", "html_url": "https://github.com/Karel-van-de-Plassche", "followers_url": "https://api.github.com/users/Karel-van-de-Plassche/followers", "following_url": "https://api.github.com/users/Karel-van-de-Plassche/following{/other_user}", "gists_url": "https://api.github.com/users/Karel-van-de-Plassche/gists{/gist_id}", "starred_url": "https://api.github.com/users/Karel-van-de-Plassche/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/Karel-van-de-Plassche/subscriptions", "organizations_url": "https://api.github.com/users/Karel-van-de-Plassche/orgs", "repos_url": "https://api.github.com/users/Karel-van-de-Plassche/repos", "events_url": "https://api.github.com/users/Karel-van-de-Plassche/events{/privacy}", "received_events_url": "https://api.github.com/users/Karel-van-de-Plassche/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "The resulting query looks like this, which doesn't quite make sense:\r\n\r\n```sql\r\nSELECT COUNT(1) FROM (\r\n SELECT \"t1\".\"id\" FROM \"whatever\" AS \"t1\"\r\n INTERSECT \r\n SELECT \"t2\".\"id\" FROM \"whatever\" AS \"t2\"\r\n) LIMIT 3 AS \"_wrapped\"\r\n```\r\n\r\nWhy are you applying a LIMIT and also using COUNT?", "Looks like this query works, however:\r\n\r\n```sql\r\nSELECT COUNT(1) FROM (\r\n SELECT \"t1\".\"id\" FROM \"whatever\" AS \"t1\"\r\n INTERSECT \r\n SELECT \"t2\".\"id\" FROM \"whatever\" AS \"t2\"\r\n LIMIT 3\r\n) AS \"_wrapped\"\r\n```", "Fixed by 42d9642b54a8242bc1ab86497d943177bf95dff2" ]
2018-02-22T10:35:17
2018-02-22T15:53:10
2018-02-22T15:53:02
NONE
null
I have a long SQL query that throws a `ProgrammingError`. I've isolated it to the following query: ``` Python (Network.select() & Network.select()).limit(10).count() ``` Throws: ``` Python --------------------------------------------------------------------------- ProgrammingError Traceback (most recent call last) ~/working/peewee/peewee.py in execute_sql(self, sql, params, commit) 2481 try: -> 2482 cursor.execute(sql, params or ()) 2483 except Exception: ProgrammingError: subquery in FROM must have an alias LINE 1: SELECT COUNT(1) FROM ((SELECT "t1"."id", "t1"."feature_names... ^ HINT: For example, FROM (SELECT ...) [AS] foo. During handling of the above exception, another exception occurred: ProgrammingError Traceback (most recent call last) ~/working/QLKNN-develop/qlknn/plots/slicer.py in <module>() ----> 1 (Network.select() & Network.select()).alias('foo').limit(10).count() ~/working/peewee/peewee.py in inner(self, database, *args, **kwargs) 1443 raise Exception('Query must be bound to a database in order ' 1444 'to call "%s".' % method.__name__) -> 1445 return method(self, database, *args, **kwargs) 1446 return inner 1447 ~/working/peewee/peewee.py in count(self, database, clear_limit) 1701 except AttributeError: 1702 pass -> 1703 return Select([clone], [fn.COUNT(SQL('1'))]).scalar(database) 1704 1705 @database_required ~/working/peewee/peewee.py in inner(self, database, *args, **kwargs) 1443 raise Exception('Query must be bound to a database in order ' 1444 'to call "%s".' % method.__name__) -> 1445 return method(self, database, *args, **kwargs) 1446 return inner 1447 ~/working/peewee/peewee.py in scalar(self, database, as_tuple) 1687 @database_required 1688 def scalar(self, database, as_tuple=False): -> 1689 row = self.tuples().peek(database) 1690 return row[0] if row and not as_tuple else row 1691 ~/working/peewee/peewee.py in inner(self, database, *args, **kwargs) 1443 raise Exception('Query must be bound to a database in order ' 1444 'to call "%s".' % method.__name__) -> 1445 return method(self, database, *args, **kwargs) 1446 return inner 1447 ~/working/peewee/peewee.py in peek(self, database, n) 1674 @database_required 1675 def peek(self, database, n=1): -> 1676 rows = self.execute(database)[:n] 1677 if rows: 1678 return rows[0] if n == 1 else rows ~/working/peewee/peewee.py in inner(self, database, *args, **kwargs) 1443 raise Exception('Query must be bound to a database in order ' 1444 'to call "%s".' % method.__name__) -> 1445 return method(self, database, *args, **kwargs) 1446 return inner 1447 ~/working/peewee/peewee.py in execute(self, database) 1514 @database_required 1515 def execute(self, database): -> 1516 return self._execute(database) 1517 1518 def _execute(self, database): ~/working/peewee/peewee.py in _execute(self, database) 1668 def _execute(self, database): 1669 if self._cursor_wrapper is None: -> 1670 cursor = database.execute(self) 1671 self._cursor_wrapper = self._get_cursor_wrapper(cursor) 1672 return self._cursor_wrapper ~/working/peewee/playhouse/postgres_ext.py in execute(self, query, commit, named_cursor, array_size, **context_options) 424 if named_cursor: 425 commit = __named_cursor__ --> 426 cursor = self.execute_sql(sql, params, commit=commit) 427 if named_cursor: 428 cursor = FetchManyCursor(cursor, array_size) ~/working/peewee/peewee.py in execute_sql(self, sql, params, commit) 2487 else: 2488 if commit and not self.in_transaction(): -> 2489 self.commit() 2490 return cursor 2491 ~/working/peewee/peewee.py in __exit__(self, exc_type, exc_value, traceback) 2283 new_type = self.exceptions[exc_type.__name__] 2284 exc_args = exc_value if PY26 else exc_value.args -> 2285 reraise(new_type, new_type(*exc_args), traceback) 2286 2287 EXCEPTIONS = { ~/working/peewee/peewee.py in reraise(tp, value, tb) 166 def reraise(tp, value, tb=None): 167 if value.__traceback__ is not tb: --> 168 raise value.with_traceback(tb) 169 raise value 170 ~/working/peewee/peewee.py in execute_sql(self, sql, params, commit) 2480 cursor = self.cursor(commit) 2481 try: -> 2482 cursor.execute(sql, params or ()) 2483 except Exception: 2484 if self.autorollback and not self.in_transaction(): ProgrammingError: subquery in FROM must have an alias LINE 1: SELECT COUNT(1) FROM ((SELECT "t1"."id", "t1"."feature_names... ^ HINT: For example, FROM (SELECT ...) [AS] foo. ``` Tested on peewee-3.0.18 and peewee-3.0.19. PS. This works correctly: ``` len((Network.select() & Network.select()).limit(10)) ``` Is `len()` the canonical way to view the amount of rows returned?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1509/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1509/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1508
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1508/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1508/comments
https://api.github.com/repos/coleifer/peewee/issues/1508/events
https://github.com/coleifer/peewee/issues/1508
299,278,355
MDU6SXNzdWUyOTkyNzgzNTU=
1,508
Field class no more supports add_to_class(class, name) method
{ "login": "skyhound", "id": 3735102, "node_id": "MDQ6VXNlcjM3MzUxMDI=", "avatar_url": "https://avatars.githubusercontent.com/u/3735102?v=4", "gravatar_id": "", "url": "https://api.github.com/users/skyhound", "html_url": "https://github.com/skyhound", "followers_url": "https://api.github.com/users/skyhound/followers", "following_url": "https://api.github.com/users/skyhound/following{/other_user}", "gists_url": "https://api.github.com/users/skyhound/gists{/gist_id}", "starred_url": "https://api.github.com/users/skyhound/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/skyhound/subscriptions", "organizations_url": "https://api.github.com/users/skyhound/orgs", "repos_url": "https://api.github.com/users/skyhound/repos", "events_url": "https://api.github.com/users/skyhound/events{/privacy}", "received_events_url": "https://api.github.com/users/skyhound/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "You can use `Model._meta.add_field(field_name, field)`.", "> You can use `Model._meta.add_field(field_name, field)`.\r\n\r\nNot able to add field in database using this. How can I do it??", "> Not able to add field in database using this. How can I do it??\r\n\r\nProbably you need to use a schema migration? http://docs.peewee-orm.com/en/latest/peewee/playhouse.html#schema-migrations", "Is any way to get only fields of class ??\r\nEx - \r\nclass Test1(BaseModel):\r\n name = CharField(default = 'Test')\r\n new_column = peewee.IntegerField(default = 0)\r\n new_column1 = IntegerField(default = 0)\r\n new_column2 = IntegerField(default = 0)\r\n new_column3 = IntegerField(default = 0)\r\n new_column4 = IntegerField(default = 0)\r\n\r\noutput expected - \r\n['name', 'new_column', 'new_column1', 'new_column2', 'new_column3', 'new_column4 ']\r\n--\r\n\r\n\r\n", "> > Not able to add field in database using this. How can I do it??\r\n> \r\n> Probably you need to use a schema migration? http://docs.peewee-orm.com/en/latest/peewee/playhouse.html#schema-migrations\r\n\r\nThanks coleifer, It worked...", "@jayashreesathe http://lmgtfy.com/?q=Get+fields+on+model+Peewee+python\r\n" ]
2018-02-22T09:30:20
2019-04-24T11:45:25
2018-02-22T15:38:58
NONE
null
In peewee 2.x it was possible to dynamically define fileds in model using this method, like it's described here: https://stackoverflow.com/questions/22358489/dynamically-define-fields-in-a-peewee-model However, in 3.x this method doesn't work. Is there some alternative?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1508/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1508/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1507
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1507/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1507/comments
https://api.github.com/repos/coleifer/peewee/issues/1507/events
https://github.com/coleifer/peewee/issues/1507
299,070,024
MDU6SXNzdWUyOTkwNzAwMjQ=
1,507
Documentation issues for 3.0
{ "login": "phryk", "id": 1021513, "node_id": "MDQ6VXNlcjEwMjE1MTM=", "avatar_url": "https://avatars.githubusercontent.com/u/1021513?v=4", "gravatar_id": "", "url": "https://api.github.com/users/phryk", "html_url": "https://github.com/phryk", "followers_url": "https://api.github.com/users/phryk/followers", "following_url": "https://api.github.com/users/phryk/following{/other_user}", "gists_url": "https://api.github.com/users/phryk/gists{/gist_id}", "starred_url": "https://api.github.com/users/phryk/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/phryk/subscriptions", "organizations_url": "https://api.github.com/users/phryk/orgs", "repos_url": "https://api.github.com/users/phryk/repos", "events_url": "https://api.github.com/users/phryk/events{/privacy}", "received_events_url": "https://api.github.com/users/phryk/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "The APIs you're referring to were not ever public APIs, hence the changes to them are not documented. I'll update the \"Hacks\" page to correct the reference to `Clause` (which is now `NodeList`).\r\n\r\n`Model.prepared` has been removed -- depends on what you're trying to do. You can always override the `__init__()` method.", "a309831f50e1a090204024f2a738c3c6f333b6fc", "Adding or removing a field can now be done using `Model._meta.add_field` or `Model._meta.remove_field`.", "I'm using it in a bunch of places, mostly for adding some extra properties to model instances that depend on the data from the db.\r\n\r\nMaybe I should just make these things `@property`s…" ]
2018-02-21T18:01:07
2018-02-21T18:13:14
2018-02-21T18:04:22
NONE
null
I'm currently porting my project over from peewee 2 to 3 and stumbled upon a few things already. A few renames not listed on the "Changes in 3.0" page that affected me: * `Field.add_to_class` has apparently been reworked to `Field.bind`? * `Model._[get|set]_pk_value` has been replaced with the dynamic `Model._pk` property * `FieldDescriptor` has been renamed `FieldAccessor`, similar renames for all child-classes Also, `Clause` has been dropped (or reworked into `NodeList`?) but is still referenced on the "Hacks" page. Lastly, `Model.prepared` has been completely dropped and I don't see any substitute for it, do you have any recommendations on what to use?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1507/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1507/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1506
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1506/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1506/comments
https://api.github.com/repos/coleifer/peewee/issues/1506/events
https://github.com/coleifer/peewee/pull/1506
299,014,068
MDExOlB1bGxSZXF1ZXN0MTcwNTAyNjgx
1,506
Model.table_exists() now checks whether table exists in its schema
{ "login": "skyhound", "id": 3735102, "node_id": "MDQ6VXNlcjM3MzUxMDI=", "avatar_url": "https://avatars.githubusercontent.com/u/3735102?v=4", "gravatar_id": "", "url": "https://api.github.com/users/skyhound", "html_url": "https://github.com/skyhound", "followers_url": "https://api.github.com/users/skyhound/followers", "following_url": "https://api.github.com/users/skyhound/following{/other_user}", "gists_url": "https://api.github.com/users/skyhound/gists{/gist_id}", "starred_url": "https://api.github.com/users/skyhound/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/skyhound/subscriptions", "organizations_url": "https://api.github.com/users/skyhound/orgs", "repos_url": "https://api.github.com/users/skyhound/repos", "events_url": "https://api.github.com/users/skyhound/events{/privacy}", "received_events_url": "https://api.github.com/users/skyhound/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Thank you!", "You're welcome. Great ORM, btw." ]
2018-02-21T15:28:14
2018-02-21T16:09:24
2018-02-21T15:55:56
NONE
null
Model.table_exists() with safe=True was checking whether table exists in default schema('public') instead of Model schema.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1506/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1506/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/1506", "html_url": "https://github.com/coleifer/peewee/pull/1506", "diff_url": "https://github.com/coleifer/peewee/pull/1506.diff", "patch_url": "https://github.com/coleifer/peewee/pull/1506.patch", "merged_at": "2018-02-21T15:55:56" }
https://api.github.com/repos/coleifer/peewee/issues/1505
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1505/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1505/comments
https://api.github.com/repos/coleifer/peewee/issues/1505/events
https://github.com/coleifer/peewee/issues/1505
298,686,425
MDU6SXNzdWUyOTg2ODY0MjU=
1,505
Create DB Transaction manually (without a context manager)
{ "login": "stanislavkozlovski", "id": 13639618, "node_id": "MDQ6VXNlcjEzNjM5NjE4", "avatar_url": "https://avatars.githubusercontent.com/u/13639618?v=4", "gravatar_id": "", "url": "https://api.github.com/users/stanislavkozlovski", "html_url": "https://github.com/stanislavkozlovski", "followers_url": "https://api.github.com/users/stanislavkozlovski/followers", "following_url": "https://api.github.com/users/stanislavkozlovski/following{/other_user}", "gists_url": "https://api.github.com/users/stanislavkozlovski/gists{/gist_id}", "starred_url": "https://api.github.com/users/stanislavkozlovski/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/stanislavkozlovski/subscriptions", "organizations_url": "https://api.github.com/users/stanislavkozlovski/orgs", "repos_url": "https://api.github.com/users/stanislavkozlovski/repos", "events_url": "https://api.github.com/users/stanislavkozlovski/events{/privacy}", "received_events_url": "https://api.github.com/users/stanislavkozlovski/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Peewee provides such nice facilities for transaction management (and rollback) ... It's a shame you're not using them.\r\n\r\nIf you want to open a \"manual\" block without using the context manager, just:\r\n\r\n```python\r\nmanual = db.manual_commit()\r\nmanual.__enter__()\r\n```\r\n\r\nTo close:\r\n\r\n```python\r\nmanual.__exit__(None, None, None)\r\n```", "Thank you, this should work. I feel ashamed I missed this yesterday", "No worries!" ]
2018-02-20T17:44:02
2018-02-21T15:56:54
2018-02-20T17:52:29
NONE
null
Hey-o. I've been trying to wrap all my pytest unit tests in a transaction and then roll them back but have failed in doing so. The guide I've been trying to follow has been this one: http://techblog.thescore.com/2015/06/25/database-transactions-with-pytest/ The problem here is that I write my transaction creating code in a `pytest_fixture` but the context manager exits before we manage to call the `fin()` function to close the transaction ``` @pytest.fixture(autouse=True) def _wrap_test_in_transaction(self, request): with db.manual_commit(): db.begin() def fin(): db.rollback() request.addfinalizer(fin) ``` The ability to open a transaction without a context manager would fix this problem for me
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1505/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1505/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1504
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1504/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1504/comments
https://api.github.com/repos/coleifer/peewee/issues/1504/events
https://github.com/coleifer/peewee/issues/1504
298,673,655
MDU6SXNzdWUyOTg2NzM2NTU=
1,504
Postgres HStore column type "can't adapt type 'dict'" in peewee 3.0.18
{ "login": "dtpxl", "id": 600983, "node_id": "MDQ6VXNlcjYwMDk4Mw==", "avatar_url": "https://avatars.githubusercontent.com/u/600983?v=4", "gravatar_id": "", "url": "https://api.github.com/users/dtpxl", "html_url": "https://github.com/dtpxl", "followers_url": "https://api.github.com/users/dtpxl/followers", "following_url": "https://api.github.com/users/dtpxl/following{/other_user}", "gists_url": "https://api.github.com/users/dtpxl/gists{/gist_id}", "starred_url": "https://api.github.com/users/dtpxl/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/dtpxl/subscriptions", "organizations_url": "https://api.github.com/users/dtpxl/orgs", "repos_url": "https://api.github.com/users/dtpxl/repos", "events_url": "https://api.github.com/users/dtpxl/events{/privacy}", "received_events_url": "https://api.github.com/users/dtpxl/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "You need to pass `register_hstore=True` when instantiating your `PostgresqlExtDatabase`.\r\n\r\nhttp://docs.peewee-orm.com/en/latest/peewee/playhouse.html#postgres-ext-api-notes" ]
2018-02-20T17:06:26
2018-02-20T17:48:21
2018-02-20T17:48:21
NONE
null
Steps to reproduce: Install Docker and Python 3.6, run the following: `docker run --name some-postgres -p 5432:5432 -e POSTGRES_PASSWORD=mysecretpassword -d postgres` (Alternatively, use a local postgres install matching the spec) `pip3.6 install peewee==2.8.2` ```python from playhouse.postgres_ext import ( PostgresqlExtDatabase, Model, HStoreField ) try: from playhouse.postgres_ext import AutoField as AutoIncField except: from playhouse.postgres_ext import PrimaryKeyField as AutoIncField db = PostgresqlExtDatabase(None) class BaseModel(Model): class Meta: database = db class Test(BaseModel): id = AutoIncField(primary_key=True) stuff = HStoreField() db.init('postgres', host='localhost', user='postgres', password='mysecretpassword') Test.create_table(fail_silently=True) Test.create(stuff={"hello": "world"}) type(Test.select().first().stuff) ``` This successfully inserts a row into the table, and the type of the HStore column data when returned from a query is 'dict' as you'd expect. Now run: `pip3.6 uninstall peewee` `pip3.6 install peewee` And run the above code again. The error seen on Test.create() is: ``` Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/peewee.py", line 2484, in execute_sql cursor.execute(sql, params or ()) psycopg2.ProgrammingError: can't adapt type 'dict' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/peewee.py", line 5068, in create inst.save(force_insert=True) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/peewee.py", line 5191, in save pk_from_cursor = self.insert(**field_dict).execute() File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/peewee.py", line 1447, in inner return method(self, database, *args, **kwargs) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/peewee.py", line 1518, in execute return self._execute(database) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/peewee.py", line 2151, in _execute return super(Insert, self)._execute(database) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/peewee.py", line 1926, in _execute cursor = self.execute_returning(database) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/peewee.py", line 1933, in execute_returning cursor = database.execute(self) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/playhouse/postgres_ext.py", line 426, in execute cursor = self.execute_sql(sql, params, commit=commit) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/peewee.py", line 2491, in execute_sql self.commit() File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/peewee.py", line 2287, in __exit__ reraise(new_type, new_type(*exc_args), traceback) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/peewee.py", line 170, in reraise raise value.with_traceback(tb) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/peewee.py", line 2484, in execute_sql cursor.execute(sql, params or ()) peewee.ProgrammingError: can't adapt type 'dict' ``` When querying for an existing row, the data in the HStore column is returned as a string, e.g.: `'"hello"=>"world"'` Expected behaviour is that inserting or retrieving HStore data works as it did in 2.8.2, where Python dictionaries can be supplied as the value for a HStore column on insert. Similarly, HStore data should be returned as a Python dictionary.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1504/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1504/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1503
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1503/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1503/comments
https://api.github.com/repos/coleifer/peewee/issues/1503/events
https://github.com/coleifer/peewee/issues/1503
298,223,077
MDU6SXNzdWUyOTgyMjMwNzc=
1,503
Document gevent at one place
{ "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
[ "I'm not sure I understand what your question is. gevent+flask+peewee is my preferred setup for all my projects...the thing I like about gevent is that you don't really need to change your code.\r\n\r\nIf you're using gevent and Postgresql, you can register a wait callback. Here is the code from the [psycogreen](https://bitbucket.org/dvarrazzo/psycogreen) project (see project for license and details):\r\n\r\n```python\r\n\"\"\"A wait callback to allow psycopg2 cooperation with gevent.\r\n\r\nUse `patch_psycopg()` to enable gevent support in Psycopg.\r\n\"\"\"\r\n\r\n# Copyright (C) 2010-2012 Daniele Varrazzo <[email protected]>\r\n# All rights reserved. See COPYING file for details.\r\n\r\n\r\nfrom __future__ import absolute_import\r\n\r\nimport psycopg2\r\nfrom psycopg2 import extensions\r\n\r\nfrom gevent.socket import wait_read, wait_write\r\n\r\ndef patch_psycopg():\r\n \"\"\"Configure Psycopg to be used with gevent in non-blocking way.\"\"\"\r\n if not hasattr(extensions, 'set_wait_callback'):\r\n raise ImportError(\r\n \"support for coroutines not available in this Psycopg version (%s)\"\r\n % psycopg2.__version__)\r\n\r\n extensions.set_wait_callback(gevent_wait_callback)\r\n\r\ndef gevent_wait_callback(conn, timeout=None):\r\n \"\"\"A wait callback useful to allow gevent to work with Psycopg.\"\"\"\r\n while 1:\r\n state = conn.poll()\r\n if state == extensions.POLL_OK:\r\n break\r\n elif state == extensions.POLL_READ:\r\n wait_read(conn.fileno(), timeout=timeout)\r\n elif state == extensions.POLL_WRITE:\r\n wait_write(conn.fileno(), timeout=timeout)\r\n else:\r\n raise psycopg2.OperationalError(\r\n \"Bad result from poll: %r\" % state)\r\n```\r\n\r\ngevent monkey-patches socket (and threading) so pure python database drivers like pymysql should automatically work fine with gevent.", "I am sorry, my English is not best and sometime my writings are not clear, i will try to be more verbose.\r\n\r\nConsider, that i am new to `gevent` and relative new to `peewee` and i wan to to know, if are peewee's DB adapters safe to use (nonblocking). It is not explicitly declared (at least i not found this) in docs and i have basically two options: go into sources or try it. But i am not sure, if i will able to distinguish it in sources. I did some tests, but again, i am not sure if i choose the right test case for it.\r\n\r\nYou provided example with Postgresql, and mentioned `pymysql`, but what about SQLite, or APSW, or ...? Somewhere in your docs i read about `SqliteQueueDatabase` and `gevent`, then have i to choose this if i want use `gevent` with SQLIte? Etc, etc.\r\n\r\nThe `flask-peewee` doc (linked from peewee's doc) has dedicated page for `gevent` usage. But `flask-peewee` is no more developed, then one cannot know, if the information there is still valid and if it is valid for `peewee` itself.\r\n\r\nYou (the author) know these nuances best, then i ask to collect all related information at one place, where the new users can read it (and do not bother you with questions or waste time on internet search, where is near nothing about this) and then they can choose right tools for it needing.", "So `gevent` uses an event loop, meaning when a socket wants to do some blocking operation, it registers with the event loop, which will wake it up when data is ready for it to read/write. Currently gevent does not work with disk i/o, only socket i/o, so you will only need to be concerned about your peewee database when you're talking to a db over a socket. For this reason, sqlite will always be blocking, since it runs in the same address space as your application. If you're talking to a remote postgres database (or mysql), you can use gevent to make the db sockets cooperative. This will happen automatically if the driver is python, but in the case of psycopg2, you are best off registering a wait callback, as shown in the above code.\r\n\r\nRegarding SqliteQueueDatabase, this module exists to work around the fact that SQLite locks the database for writes. You can read [more about the problem here](http://charlesleifer.com/blog/multi-threaded-sqlite-without-the-operationalerrors/). If you are writing a multi-threaded (or multi-green-thread) application, you want to avoid locking the db from multiple threads. The SqliteQueueDatabase works by using a single dedicated worker thread for processing all writes, ensuring that there's never more than one connection writing to the db. The SqliteQueueDatabase accepts a parameter, `use_gevent`, which uses gevent threading primitives instead of the standard lib threading primitives, so you can easily use the library in an application that uses gevent. If you're using gevent and monkey-patching everything already, then technically you don't need to specify use_gevent, because the standard lib threading implementation will have been monkeypatched already. The bottom line, however, is that you should only use SqliteQueueDatabase if you thoroughly understand the issue, the implementation and the trade-offs, as it's designed for a rather narrow use-case and carries a significant trade-off -- no transactional support.\r\n\r\nTo make a long story short, if you're writing a web app with flask, peewee and gevent, and want to use sqlite, you probably don't need to do anything special. Just use `peewee.SqliteDatabase` (or `playhouse.sqlite_ext.SqliteExtDatabase`).", "Very thanks, that i exactly what i want to know now, and slightly more than i was asking to exactly mention in dedicated doc's `gevent` section. ;-)" ]
2018-02-19T10:19:49
2018-02-19T16:15:53
2018-02-19T14:33:35
NONE
null
I search your docs and found here and there some `gevent` related information. The most one is from retired `flask-peewee` project (i am mostly interested in `peewee` + `flask`). I did heavy search on internet, but i was no able to find any reliable information and most of the found are Django related, where the reliable sources strongly suggests against use of Django ORM with `gevent`. I am not able to decide, if they can/have to be applied to `peewee` too. Please, can you add separate section in docs, and clarify usage of the `peewee` with `gevent` and all related settings at one place? regards
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1503/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1503/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1502
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1502/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1502/comments
https://api.github.com/repos/coleifer/peewee/issues/1502/events
https://github.com/coleifer/peewee/issues/1502
298,129,248
MDU6SXNzdWUyOTgxMjkyNDg=
1,502
Not failing silently when creating tables on attached SQLite databases
{ "login": "maurosilber", "id": 9124827, "node_id": "MDQ6VXNlcjkxMjQ4Mjc=", "avatar_url": "https://avatars.githubusercontent.com/u/9124827?v=4", "gravatar_id": "", "url": "https://api.github.com/users/maurosilber", "html_url": "https://github.com/maurosilber", "followers_url": "https://api.github.com/users/maurosilber/followers", "following_url": "https://api.github.com/users/maurosilber/following{/other_user}", "gists_url": "https://api.github.com/users/maurosilber/gists{/gist_id}", "starred_url": "https://api.github.com/users/maurosilber/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/maurosilber/subscriptions", "organizations_url": "https://api.github.com/users/maurosilber/orgs", "repos_url": "https://api.github.com/users/maurosilber/repos", "events_url": "https://api.github.com/users/maurosilber/events{/privacy}", "received_events_url": "https://api.github.com/users/maurosilber/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Never mind. It works after updating from 2.8.5 to 3.0.18." ]
2018-02-18T23:25:39
2018-02-18T23:31:24
2018-02-18T23:31:24
NONE
null
Here's minimal example reproducing the issue: ```python from playhouse.apsw_ext import * db = APSWDatabase('main.db') db.execute_sql('attach database "other.db" as other') class MainTable(Model): field1 = IntegerField() class Meta: database = db class AttachedTable(Model): field1 = IntegerField() class Meta: database = db schema = 'other' MainTable.create_table(fail_silently=True) AttachedTable.create_table(fail_silently=True) ``` ```python File "<ipython-input-5-002497356290>", line 22, in <module> AttachedTable.create_table(fail_silently=True) File "python3.5/site-packages/peewee.py", line 4857, in create_table db.create_table(cls) File "python3.5/site-packages/playhouse/sqlite_ext.py", line 948, in create_table return self.execute_sql(sql, params) File "python3.5/site-packages/playhouse/apsw_ext.py", line 116, in execute_sql self._execute_sql(cursor, sql, params) File "python3.5/site-packages/playhouse/apsw_ext.py", line 109, in _execute_sql cursor.execute(sql, params or ()) File "src/cursor.c", line 1019, in APSWCursor_execute.sqlite3_prepare File "src/statementcache.c", line 386, in sqlite3_prepare SQLError: SQLError: table "attachedtable" already exists ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1502/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1502/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1501
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1501/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1501/comments
https://api.github.com/repos/coleifer/peewee/issues/1501/events
https://github.com/coleifer/peewee/issues/1501
297,982,754
MDU6SXNzdWUyOTc5ODI3NTQ=
1,501
Why does not peewee support mysql-connector-python?
{ "login": "polikeiji", "id": 1539285, "node_id": "MDQ6VXNlcjE1MzkyODU=", "avatar_url": "https://avatars.githubusercontent.com/u/1539285?v=4", "gravatar_id": "", "url": "https://api.github.com/users/polikeiji", "html_url": "https://github.com/polikeiji", "followers_url": "https://api.github.com/users/polikeiji/followers", "following_url": "https://api.github.com/users/polikeiji/following{/other_user}", "gists_url": "https://api.github.com/users/polikeiji/gists{/gist_id}", "starred_url": "https://api.github.com/users/polikeiji/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/polikeiji/subscriptions", "organizations_url": "https://api.github.com/users/polikeiji/orgs", "repos_url": "https://api.github.com/users/polikeiji/repos", "events_url": "https://api.github.com/users/polikeiji/events{/privacy}", "received_events_url": "https://api.github.com/users/polikeiji/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I'm not familiar with mysql-connector-python, but Peewee should work with any DB-API 2.0-compatible driver. If the mysql-connector-python library is fully DB-API 2.0 compatible, you should be able to simply subclass `MySQLDatabase` and override the `_connect()` method so it uses the mysql connector.\r\n\r\nYou can refer to this document for more information: http://docs.peewee-orm.com/en/latest/peewee/database.html#adding-a-new-database-driver", "You can always use PyMySQL", "Peewee supports mysql-connector via `playhouse.mysql_ext.MySQLConnectorDatabase`." ]
2018-02-17T06:06:24
2021-05-26T12:36:39
2018-02-17T15:03:42
NONE
null
I think peewee support currently only MySQLdb and pymsql as drivers for MySQL. I have not compared MySQL drivers in details, but I want to use the mysql-connector-python because I think it is the driver Oracle is maintaining officially.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1501/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1501/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1500
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1500/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1500/comments
https://api.github.com/repos/coleifer/peewee/issues/1500/events
https://github.com/coleifer/peewee/issues/1500
297,632,359
MDU6SXNzdWUyOTc2MzIzNTk=
1,500
delete triggers firing with on_conflict('replace')
{ "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 think you might be confusing triggers with the `ON DELETE` behavior, which I don't believe falls under the same rules as triggers (recursive or otherwise). To avoid the issue, it should be sufficient to remove either the \"on delete cascade\" bit, or to disable the foreign_keys pragma.\r\n\r\nI was able to replicate the behavior you've described using just the sqlite shell, so this definitely isn't a peewee issue. Whether it's a bug in sqlite is probably worth bringing up on the mailing list.", "Would there be a way to replace rows without deleting them first or is it necessary to disable `ON DELETE`/the `foreign_keys` pragma to avoid this problem?", "I'm not sure, that's a good question for the SQLite mailing list. It does seem like the combination of:\r\n\r\n1. Pragma foreign_keys = on\r\n2. On delete cascade\r\n3. Insert or Replace\r\n\r\nCan lead to rows in the related table being deleted.\r\n\r\nAn alternative, if you don't want to change the first 2, would be to execute a normal INSERT and then, if that fails with an IntegrityError, to do an update instead." ]
2018-02-15T23:20:23
2018-02-17T14:57:55
2018-02-16T18:11:07
NONE
null
Hello. I encountered this problem while inserting a new row, which violated a UNIQUE constraint, either through `Model.insert()` or `Model.insert_many()`. I didn't expect this behavior, since the [SQLite documentation](https://sqlite.org/lang_conflict.html) states that > When the REPLACE conflict resolution strategy deletes rows in order to satisfy a constraint, delete triggers fire if and only if recursive triggers are enabled. I doubled checked to see if `recursive_triggers` was disabled, but it doesn't even seem to be enabled by default. Explicitly setting `recursive_triggers` by saying `db.pragma('recursive_triggers', 0, permanent=True)` also seems to have no effect. Is my understanding of SQLite wrong or would this be a bug on peewee's side? [Here](https://gist.github.com/Jovito/b2ad9a448a3d226d04c2d5b3c54d64b1) is an example.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1500/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1500/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1499
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1499/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1499/comments
https://api.github.com/repos/coleifer/peewee/issues/1499/events
https://github.com/coleifer/peewee/issues/1499
297,492,684
MDU6SXNzdWUyOTc0OTI2ODQ=
1,499
Generalize Autofield test between sqlite and postgresql
{ "login": "Karel-van-de-Plassche", "id": 6404167, "node_id": "MDQ6VXNlcjY0MDQxNjc=", "avatar_url": "https://avatars.githubusercontent.com/u/6404167?v=4", "gravatar_id": "", "url": "https://api.github.com/users/Karel-van-de-Plassche", "html_url": "https://github.com/Karel-van-de-Plassche", "followers_url": "https://api.github.com/users/Karel-van-de-Plassche/followers", "following_url": "https://api.github.com/users/Karel-van-de-Plassche/following{/other_user}", "gists_url": "https://api.github.com/users/Karel-van-de-Plassche/gists{/gist_id}", "starred_url": "https://api.github.com/users/Karel-van-de-Plassche/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/Karel-van-de-Plassche/subscriptions", "organizations_url": "https://api.github.com/users/Karel-van-de-Plassche/orgs", "repos_url": "https://api.github.com/users/Karel-van-de-Plassche/repos", "events_url": "https://api.github.com/users/Karel-van-de-Plassche/events{/privacy}", "received_events_url": "https://api.github.com/users/Karel-van-de-Plassche/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Yes, it was a bad commit, the test is fixed in master now." ]
2018-02-15T15:43:35
2018-02-15T17:00:27
2018-02-15T17:00:27
NONE
null
In sqlite the `AutoField` used for `PrimaryKeys` is 'INTEGER', while in postgresql its 'SERIAL'. This breaks test `test_db_table` of `TestModelDDL` in `tests/schema.py`. Either this test, or the underlying AutoField has to be generalized.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1499/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1499/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1498
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1498/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1498/comments
https://api.github.com/repos/coleifer/peewee/issues/1498/events
https://github.com/coleifer/peewee/pull/1498
297,489,213
MDExOlB1bGxSZXF1ZXN0MTY5NDA0MTU5
1,498
Fixed testcases broken by bugfix 9edf260
{ "login": "Karel-van-de-Plassche", "id": 6404167, "node_id": "MDQ6VXNlcjY0MDQxNjc=", "avatar_url": "https://avatars.githubusercontent.com/u/6404167?v=4", "gravatar_id": "", "url": "https://api.github.com/users/Karel-van-de-Plassche", "html_url": "https://github.com/Karel-van-de-Plassche", "followers_url": "https://api.github.com/users/Karel-van-de-Plassche/followers", "following_url": "https://api.github.com/users/Karel-van-de-Plassche/following{/other_user}", "gists_url": "https://api.github.com/users/Karel-van-de-Plassche/gists{/gist_id}", "starred_url": "https://api.github.com/users/Karel-van-de-Plassche/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/Karel-van-de-Plassche/subscriptions", "organizations_url": "https://api.github.com/users/Karel-van-de-Plassche/orgs", "repos_url": "https://api.github.com/users/Karel-van-de-Plassche/repos", "events_url": "https://api.github.com/users/Karel-van-de-Plassche/events{/privacy}", "received_events_url": "https://api.github.com/users/Karel-van-de-Plassche/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "For sqlite the autofield IS an INTEGER, so this solves nothing. Opened issue #1499" ]
2018-02-15T15:34:31
2018-02-15T15:43:45
2018-02-15T15:43:44
NONE
null
I think this test has to be changed, as primary keys are an AutoField, and Postgress' AutoField is SERIAL. This expected behaviour somehow only surfaces after 9edf260.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1498/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1498/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/1498", "html_url": "https://github.com/coleifer/peewee/pull/1498", "diff_url": "https://github.com/coleifer/peewee/pull/1498.diff", "patch_url": "https://github.com/coleifer/peewee/pull/1498.patch", "merged_at": null }
https://api.github.com/repos/coleifer/peewee/issues/1497
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1497/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1497/comments
https://api.github.com/repos/coleifer/peewee/issues/1497/events
https://github.com/coleifer/peewee/issues/1497
297,459,330
MDU6SXNzdWUyOTc0NTkzMzA=
1,497
peewee.OperationalError: unable to open database file
{ "login": "kitten77", "id": 11948741, "node_id": "MDQ6VXNlcjExOTQ4NzQx", "avatar_url": "https://avatars.githubusercontent.com/u/11948741?v=4", "gravatar_id": "", "url": "https://api.github.com/users/kitten77", "html_url": "https://github.com/kitten77", "followers_url": "https://api.github.com/users/kitten77/followers", "following_url": "https://api.github.com/users/kitten77/following{/other_user}", "gists_url": "https://api.github.com/users/kitten77/gists{/gist_id}", "starred_url": "https://api.github.com/users/kitten77/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/kitten77/subscriptions", "organizations_url": "https://api.github.com/users/kitten77/orgs", "repos_url": "https://api.github.com/users/kitten77/repos", "events_url": "https://api.github.com/users/kitten77/events{/privacy}", "received_events_url": "https://api.github.com/users/kitten77/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I've edited your comment to include code formatting...please take the time to format your issues. It takes two seconds.", "Wontfix, peewee won't magically create directories for you.", "Thank you for fixing my post I will put more attention into the formatting in the future 😊" ]
2018-02-15T14:11:41
2018-02-15T19:49:08
2018-02-15T16:58:48
NONE
null
Dont know if this is a bug or not but reporting it anyway this happens when i try to create a db without having the subdir where the file is placed ``` File "/usr/home/user/project/todo.py", line 12, in __init__ DB = todoDB() File "/usr/home/admin/ragnhild/models/todoDB.py", line 35, in __init__ with db, dbfile: File "/usr/local/lib/python3.6/site-packages/peewee.py", line 2405, in __enter__ self.connect() File "/usr/local/lib/python3.6/site-packages/peewee.py", line 2435, in connect self._initialize_connection(self._state.conn) File "/usr/local/lib/python3.6/site-packages/peewee.py", line 2287, in __exit__ reraise(new_type, new_type(*exc_args), traceback) File "/usr/local/lib/python3.6/site-packages/peewee.py", line 170, in reraise raise value.with_traceback(tb) File "/usr/local/lib/python3.6/site-packages/peewee.py", line 2434, in connect self._state.set_connection(self._connect()) File "/usr/local/lib/python3.6/site-packages/peewee.py", line 2654, in _connect **self.connect_params) peewee.OperationalError: unable to open database file ``` i made a quick and dirty workaround: ``` path = '/home/user/data/' File = 'todo.db' if os.path.isdir(path): pass else: os.makedirs(path) dbFile = path + File db = SqliteDatabase(dbFile) ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1497/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1497/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1496
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1496/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1496/comments
https://api.github.com/repos/coleifer/peewee/issues/1496/events
https://github.com/coleifer/peewee/pull/1496
297,437,485
MDExOlB1bGxSZXF1ZXN0MTY5MzY0OTg5
1,496
Create schema when 'creating all' if it doesn't exist
{ "login": "Karel-van-de-Plassche", "id": 6404167, "node_id": "MDQ6VXNlcjY0MDQxNjc=", "avatar_url": "https://avatars.githubusercontent.com/u/6404167?v=4", "gravatar_id": "", "url": "https://api.github.com/users/Karel-van-de-Plassche", "html_url": "https://github.com/Karel-van-de-Plassche", "followers_url": "https://api.github.com/users/Karel-van-de-Plassche/followers", "following_url": "https://api.github.com/users/Karel-van-de-Plassche/following{/other_user}", "gists_url": "https://api.github.com/users/Karel-van-de-Plassche/gists{/gist_id}", "starred_url": "https://api.github.com/users/Karel-van-de-Plassche/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/Karel-van-de-Plassche/subscriptions", "organizations_url": "https://api.github.com/users/Karel-van-de-Plassche/orgs", "repos_url": "https://api.github.com/users/Karel-van-de-Plassche/repos", "events_url": "https://api.github.com/users/Karel-van-de-Plassche/events{/privacy}", "received_events_url": "https://api.github.com/users/Karel-van-de-Plassche/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I am going to pass on this, but thanks for the patch." ]
2018-02-15T13:00:36
2018-02-15T17:01:05
2018-02-15T17:01:05
NONE
null
As it says in the table. Not sure if we want to use the safe version of this method in `_create_table` itself, which is also possible. Also, I was not sure where to put Unit Tests for this. If you give me a location, I can write them if you want. PS. One test fails for PostgreSQL, but it also fails without my pull request. ``` python ====================================================================== FAIL: test_db_table (tests.schema.TestModelDDL) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/karel/working/peewee/tests/schema.py", line 126, in test_db_table 'CREATE TABLE "A_tbl" ("id" INTEGER NOT NULL PRIMARY KEY)']) File "/home/karel/working/peewee/tests/schema.py", line 83, in assertCreateTable self.assertEqual([sql] + indexes, expected) AssertionError: Lists differ: ['CREATE TABLE "A_tbl" ("id" SERIAL NOT NULL PRIMARY KEY)'] != ['CREATE TABLE "A_tbl" ("id" INTEGER NOT NULL PRIMARY KEY)'] First differing element 0: 'CREATE TABLE "A_tbl" ("id" SERIAL NOT NULL PRIMARY KEY)' 'CREATE TABLE "A_tbl" ("id" INTEGER NOT NULL PRIMARY KEY)' - ['CREATE TABLE "A_tbl" ("id" SERIAL NOT NULL PRIMARY KEY)'] ? ^ --- + ['CREATE TABLE "A_tbl" ("id" INTEGER NOT NULL PRIMARY KEY)'] ? ^^^^^ ---------------------------------------------------------------------- ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1496/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1496/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/1496", "html_url": "https://github.com/coleifer/peewee/pull/1496", "diff_url": "https://github.com/coleifer/peewee/pull/1496.diff", "patch_url": "https://github.com/coleifer/peewee/pull/1496.patch", "merged_at": null }
https://api.github.com/repos/coleifer/peewee/issues/1495
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1495/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1495/comments
https://api.github.com/repos/coleifer/peewee/issues/1495/events
https://github.com/coleifer/peewee/issues/1495
297,258,366
MDU6SXNzdWUyOTcyNTgzNjY=
1,495
insert_many throws ValueError with list of collections.Mapping instances
{ "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
[ "Fix pushed. It's not necessary to check both Mapping and MutableMapping, since MutableMappings are Mappings." ]
2018-02-14T21:52:31
2018-02-15T01:53:44
2018-02-15T01:53:11
NONE
null
Hello. I've been using peewee in my latest project and I'm enjoying it quite a bit. Recently, I came across a problem when trying to pass instances of collections.Mapping to `insert_many()`, namely, it throws an ValueError exception. Here's an [example](https://gist.github.com/Jovito/2adbc33d7d60ddc6b6ebadccb750e8d6). From what I gathered, it seems that the offending line is: `is_dict = isinstance(row, dict)` in `insert_many()`. Changing it to `is_mapping = isinstance(row, (Mapping, MutableMapping))` solves the problem and still works if `row` is a regular dictionary.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1495/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1495/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1494
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1494/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1494/comments
https://api.github.com/repos/coleifer/peewee/issues/1494/events
https://github.com/coleifer/peewee/issues/1494
297,029,458
MDU6SXNzdWUyOTcwMjk0NTg=
1,494
SQLITE_DATE_TRUNC_MAPPING undefined variable?
{ "login": "oz123", "id": 1083045, "node_id": "MDQ6VXNlcjEwODMwNDU=", "avatar_url": "https://avatars.githubusercontent.com/u/1083045?v=4", "gravatar_id": "", "url": "https://api.github.com/users/oz123", "html_url": "https://github.com/oz123", "followers_url": "https://api.github.com/users/oz123/followers", "following_url": "https://api.github.com/users/oz123/following{/other_user}", "gists_url": "https://api.github.com/users/oz123/gists{/gist_id}", "starred_url": "https://api.github.com/users/oz123/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/oz123/subscriptions", "organizations_url": "https://api.github.com/users/oz123/orgs", "repos_url": "https://api.github.com/users/oz123/repos", "events_url": "https://api.github.com/users/oz123/events{/privacy}", "received_events_url": "https://api.github.com/users/oz123/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Made a quick fix, the method was out-of-date. This commit fixes the issue: 0416786d56f770c6cec3b9c7493fae7ffd6a75ec", "Pushed a new version, 3.0.18, which includes the fix.", "@coleifer thank you for the quick response!", "No problems, you should have no issues vendoring the peewee.py module, as that's one of the goals for the project -- to make it easy to drop in where you need it." ]
2018-02-14T09:39:52
2018-02-14T15:48:18
2018-02-14T15:05:17
NONE
null
When using vim I encountered this: ``` F821 undefined name 'SQLITE_DATE_TRUNC_MAPPING'. ``` ``` $ git checkout 2.9.2 $ grep -n SQLITE_DATE_TRUNC_MAPPING * grep: docs: Is a directory grep: examples: Is a directory peewee.py:287:SQLITE_DATE_TRUNC_MAPPING = { peewee.py:294:MYSQL_DATE_TRUNC_MAPPING = SQLITE_DATE_TRUNC_MAPPING.copy() peewee.py:299: assert lookup_type in SQLITE_DATE_TRUNC_MAPPING peewee.py:303: return dt.strftime(SQLITE_DATE_TRUNC_MAPPING[lookup_type]) peewee.py:4056: return fn.strftime(SQLITE_DATE_TRUNC_MAPPING[date_part], date_field) $ grep -nr SQLITE_DATE_TRUNC_MAPPING * peewee.py:287:SQLITE_DATE_TRUNC_MAPPING = { peewee.py:294:MYSQL_DATE_TRUNC_MAPPING = SQLITE_DATE_TRUNC_MAPPING.copy() peewee.py:299: assert lookup_type in SQLITE_DATE_TRUNC_MAPPING peewee.py:303: return dt.strftime(SQLITE_DATE_TRUNC_MAPPING[lookup_type]) peewee.py:4056: return fn.strftime(SQLITE_DATE_TRUNC_MAPPING[date_part], date_field) playhouse/_speedups.pyx:51:cdef dict SQLITE_DATE_TRUNC_MAPPING = { playhouse/_sqlite_ext.pyx:15:cdef dict SQLITE_DATE_TRUNC_MAPPING = { playhouse/_sqlite_ext.pyx:29: if lookup not in SQLITE_DATE_TRUNC_MAPPING: playhouse/_sqlite_ext.pyx:57: return result[0].strftime(SQLITE_DATE_TRUNC_MAPPING[result[1]]) ``` So in version 2.9.2 it is both in peewee and playhouse ... In version 3.0.17 it is only defined in the playhouse module: ``` $ grep -nr SQLITE_DATE_TRUNC_MAPPING * peewee.py:2888: return fn.strftime(SQLITE_DATE_TRUNC_MAPPING[date_part], date_field) playhouse/_sqlite_ext.pyx:641:cdef dict SQLITE_DATE_TRUNC_MAPPING = { playhouse/_sqlite_ext.pyx:655: if lookup not in SQLITE_DATE_TRUNC_MAPPING: ``` If I have some projects which only include `peewee.py` via a local copy, is this going to cause a problem for me ?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1494/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1494/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1493
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1493/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1493/comments
https://api.github.com/repos/coleifer/peewee/issues/1493/events
https://github.com/coleifer/peewee/issues/1493
297,006,068
MDU6SXNzdWUyOTcwMDYwNjg=
1,493
Broken Docs
{ "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
[ "Cheers, had those lines indented by an extra 2 spaces on accident. Should be fixed." ]
2018-02-14T08:03:26
2018-02-14T14:44:06
2018-02-14T14:44:06
NONE
null
Broken Docs, Easy to Fix. ![broken-doc0](https://user-images.githubusercontent.com/1189414/36193338-47f6fbea-1144-11e8-8653-4b25a930dc54.png) http://docs.peewee-orm.com/en/latest/peewee/api.html#ModelIndex :cat:
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1493/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1493/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1492
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1492/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1492/comments
https://api.github.com/repos/coleifer/peewee/issues/1492/events
https://github.com/coleifer/peewee/issues/1492
296,989,233
MDU6SXNzdWUyOTY5ODkyMzM=
1,492
.get() results in RecursionError
{ "login": "HassanTariqSLX", "id": 35286391, "node_id": "MDQ6VXNlcjM1Mjg2Mzkx", "avatar_url": "https://avatars.githubusercontent.com/u/35286391?v=4", "gravatar_id": "", "url": "https://api.github.com/users/HassanTariqSLX", "html_url": "https://github.com/HassanTariqSLX", "followers_url": "https://api.github.com/users/HassanTariqSLX/followers", "following_url": "https://api.github.com/users/HassanTariqSLX/following{/other_user}", "gists_url": "https://api.github.com/users/HassanTariqSLX/gists{/gist_id}", "starred_url": "https://api.github.com/users/HassanTariqSLX/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/HassanTariqSLX/subscriptions", "organizations_url": "https://api.github.com/users/HassanTariqSLX/orgs", "repos_url": "https://api.github.com/users/HassanTariqSLX/repos", "events_url": "https://api.github.com/users/HassanTariqSLX/events{/privacy}", "received_events_url": "https://api.github.com/users/HassanTariqSLX/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Can you share the model definition with me? Is the primary key of `AdwordsClient` a foreign-key to some other model?\r\n\r\nThe recursion error is occurring during the save operation when you're creating the new `client` instance. It's attempting to access the model class' `_pk` property, which obtains the value of the primary key. It seems that this is triggering a foreign-key lookup which is self-referential.", "@coleifer Yeah, that was the issue. The foreign relation was configured incorrectly. Thanks a lot for your help." ]
2018-02-14T06:26:49
2018-02-16T00:56:01
2018-02-16T00:56:01
NONE
null
Hi, I'm looping through some adwords MCCs and for each MCC there are customer accounts. If I iterate through these customer accounts and try to retrieve the model, it throws the following: ``` Traceback (most recent call last): File "C:\Users\USERNAME\PycharmProjects\PROJECT_NAME\venv\lib\site-packages\peewee.py", line 5458, in get return clone.execute()[0] File "C:\Users\USERNAME\PycharmProjects\PROJECT_NAME\venv\lib\site-packages\peewee.py", line 3350, in __getitem__ return self.row_cache[item] IndexError: list index out of range During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:/Users/USERNAME/PycharmProjects/PROJECT_NAME/main.py", line 58, in main client = AdwordsClient.get(AdwordsClient.adwordsid == customer['customerId']) File "C:\Users\USERNAME\PycharmProjects\PROJECT_NAME\venv\lib\site-packages\peewee.py", line 5077, in get return sq.get() File "C:\Users\USERNAME\PycharmProjects\PROJECT_NAME\venv\lib\site-packages\peewee.py", line 5463, in get (clone.model, sql, params)) database.models.AdwordsClientDoesNotExist: <class 'database.models.AdwordsClient'> instance matching query does not exist: SQL: SELECT `t1`.`id`, `t1`.`created`, `t1`.`modified`, `t1`.`name`, `t1`.`adwordsemail`, `t1`.`adwordsid`, `t1`.`adwords_client_status_id`, `t1`.`adwords_sync_status_id`, `t1`.`conversion_tracking`, `t1`.`disapproved_ads` FROM `adwords_clients` AS `t1` WHERE (`t1`.`adwordsid` = %s) LIMIT 1 OFFSET 0 Params: ['ADWORD_ID'] During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:/Users/USERNAME/PycharmProjects/PROJECT_NAME/main.py", line 74, in <module> main() File "C:/Users/USERNAME/PycharmProjects/PROJECT_NAME/main.py", line 60, in main client = AdwordsClient.create(created=datetime.datetime.now()) File "C:\Users\USERNAME\PycharmProjects\PROJECT_NAME\venv\lib\site-packages\peewee.py", line 5063, in create inst.save(force_insert=True) File "C:\Users\USERNAME\PycharmProjects\PROJECT_NAME\venv\lib\site-packages\peewee.py", line 5163, in save pk_value = self._pk File "C:\Users\USERNAME\PycharmProjects\PROJECT_NAME\venv\lib\site-packages\peewee.py", line 5128, in get_id return getattr(self, self._meta.primary_key.name) File "C:\Users\USERNAME\PycharmProjects\PROJECT_NAME\venv\lib\site-packages\peewee.py", line 3521, in __get__ .where(self.field == getattr(instance, dest))) File "C:\Users\USERNAME\PycharmProjects\PROJECT_NAME\venv\lib\site-packages\peewee.py", line 3521, in __get__ .where(self.field == getattr(instance, dest))) File "C:\Users\USERNAME\PycharmProjects\PROJECT_NAME\venv\lib\site-packages\peewee.py", line 3521, in __get__ .where(self.field == getattr(instance, dest))) [Previous line repeated 483 more times] File "C:\Users\USERNAME\PycharmProjects\PROJECT_NAME\venv\lib\site-packages\peewee.py", line 3519, in __get__ return (self.model File "C:\Users\USERNAME\PycharmProjects\PROJECT_NAME\venv\lib\site-packages\peewee.py", line 4997, in select return ModelSelect(cls, fields, is_default=is_default) File "C:\Users\USERNAME\PycharmProjects\PROJECT_NAME\venv\lib\site-packages\peewee.py", line 5504, in __init__ super(ModelSelect, self).__init__([model], fields) File "C:\Users\USERNAME\PycharmProjects\PROJECT_NAME\venv\lib\site-packages\peewee.py", line 5393, in __init__ super(_ModelQueryHelper, self).__init__(*args, **kwargs) File "C:\Users\USERNAME\PycharmProjects\PROJECT_NAME\venv\lib\site-packages\peewee.py", line 1766, in __init__ super(Select, self).__init__(**kwargs) File "C:\Users\USERNAME\PycharmProjects\PROJECT_NAME\venv\lib\site-packages\peewee.py", line 652, in __init__ super(_HashableSource, self).__init__(*args, **kwargs) File "C:\Users\USERNAME\PycharmProjects\PROJECT_NAME\venv\lib\site-packages\peewee.py", line 614, in __init__ super(Source, self).__init__() File "C:\Users\USERNAME\PycharmProjects\PROJECT_NAME\venv\lib\site-packages\peewee.py", line 1579, in __init__ super(Query, self).__init__(**kwargs) RecursionError: maximum recursion depth exceeded Process finished with exit code 1 ``` I've tried setting the recursion limit using `sys.setrecursionlimit()` but the script just crashes. Here's the code that causes the exception: ```python try: client = AdwordsClient.get(AdwordsClient.adwordsid == customer['customerId']) except peewee.DoesNotExist: client = AdwordsClient.create(created=datetime.datetime.now()) ``` I can do other operations without RecursionError just fine. Any help would be much appreciated.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1492/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1492/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1491
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1491/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1491/comments
https://api.github.com/repos/coleifer/peewee/issues/1491/events
https://github.com/coleifer/peewee/issues/1491
296,723,050
MDU6SXNzdWUyOTY3MjMwNTA=
1,491
foreign key constraint incorrectly formed
{ "login": "MNCODE", "id": 31220124, "node_id": "MDQ6VXNlcjMxMjIwMTI0", "avatar_url": "https://avatars.githubusercontent.com/u/31220124?v=4", "gravatar_id": "", "url": "https://api.github.com/users/MNCODE", "html_url": "https://github.com/MNCODE", "followers_url": "https://api.github.com/users/MNCODE/followers", "following_url": "https://api.github.com/users/MNCODE/following{/other_user}", "gists_url": "https://api.github.com/users/MNCODE/gists{/gist_id}", "starred_url": "https://api.github.com/users/MNCODE/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/MNCODE/subscriptions", "organizations_url": "https://api.github.com/users/MNCODE/orgs", "repos_url": "https://api.github.com/users/MNCODE/repos", "events_url": "https://api.github.com/users/MNCODE/events{/privacy}", "received_events_url": "https://api.github.com/users/MNCODE/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Solved by replacing db_table with table_name \r\ndb_table is from an older version (2.x.x). Probably it also caused the foreignKeyConstraint Error" ]
2018-02-13T12:40:13
2018-02-13T14:55:17
2018-02-13T14:55:17
NONE
null
When I want to create a table I get the error foreign_key > ERROR session[5924]: (1005, 'Can\'t create table `example_database`.`example_table` (errno: 150 "Foreign key constraint is incorrectly formed")') example_table is specified as: ```python class Example_Table(BaseModel): id = PrimaryKeyField() example_table2 = ForeignKeyField(Modul) class Meta: db_table = 'Example_Table' ``` after i defined BaseModel: ```python class BaseModel(Model): class Meta: database = database ``` and database is my MySQLDatabase Object. The Problem is, why doesnt the foreign key constraint work and why are the tables all saved in Lowercase, but I defined them in Uppercase If I run the program again, It creates the tables but gives me a duplicate key_name error Version: peewee==3.0.17
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1491/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1491/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1490
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1490/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1490/comments
https://api.github.com/repos/coleifer/peewee/issues/1490/events
https://github.com/coleifer/peewee/issues/1490
296,628,719
MDU6SXNzdWUyOTY2Mjg3MTk=
1,490
the mod op has problem in string formatting
{ "login": "Twwy", "id": 998191, "node_id": "MDQ6VXNlcjk5ODE5MQ==", "avatar_url": "https://avatars.githubusercontent.com/u/998191?v=4", "gravatar_id": "", "url": "https://api.github.com/users/Twwy", "html_url": "https://github.com/Twwy", "followers_url": "https://api.github.com/users/Twwy/followers", "following_url": "https://api.github.com/users/Twwy/following{/other_user}", "gists_url": "https://api.github.com/users/Twwy/gists{/gist_id}", "starred_url": "https://api.github.com/users/Twwy/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/Twwy/subscriptions", "organizations_url": "https://api.github.com/users/Twwy/orgs", "repos_url": "https://api.github.com/users/Twwy/repos", "events_url": "https://api.github.com/users/Twwy/events{/privacy}", "received_events_url": "https://api.github.com/users/Twwy/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Final I get the code passed, but I need to change something.\r\n\r\n```\r\n--- a/test/package/peewee.py\r\n+++ b/test/package/peewee.py\r\n@@ -315,7 +315,7 @@ OP = attrdict(\r\n BIN_AND='&',\r\n BIN_OR='|',\r\n XOR='^',\r\n- MOD='%',\r\n+ MOD='%%',\r\n EQ='=',\r\n LT='<',\r\n LTE='<=',\r\n@@ -1557,7 +1557,7 @@ class QueryCompiler(object):\r\n OP.XOR: '#',\r\n OP.AND: 'AND',\r\n OP.OR: 'OR',\r\n- OP.MOD: '%',\r\n+ OP.MOD: '%%',\r\n OP.REGEXP: 'REGEXP',\r\n OP.CONCAT: '||',\r\n }\r\n\r\n--- a/test/library/peewee_ext.py\r\n+++ b/test/library/peewee_ext.py\r\n@@ -48,3 +48,6 @@ def result_to_dict(obj):\r\n ele[key] = value\r\n return ele\r\n\r\n+def mod(lhs, rhs):\r\n+ return peewee.Expression(lhs, '%%', rhs)\r\n```", "It appears that you're using Peewee 2.x?", "I've added a test-case in ba8b72a which seems to me to indicate that the code is correct on 3.x" ]
2018-02-13T06:36:19
2018-02-13T20:29:48
2018-02-13T20:29:48
NONE
null
I use the mod like docs. ``` from peewee import * from peewee import Expression # the building block for expressions def mod(lhs, rhs): return Expression(lhs, '%', rhs) ``` but this code has error ``` TypeError: not all arguments converted during string formatting ``` when I use ```%% ``` replace the ```%```, also get error ``` File "/home/test/..//package/peewee.py", line 1748, in parse_node sql, params, unknown = self._parse(node, alias_map, conv) File "/home/test/..//package/peewee.py", line 1717, in _parse sql, params = self._parse_map[node_type](node, alias_map, conv) File "/home/test/..//package/peewee.py", line 1620, in _parse_expression sql = template % (lhs, self.get_op(node.op), rhs) File "/home/test/..//package/peewee.py", line 1606, in get_op return self._op_map[q] KeyError: '%% ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1490/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1490/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1489
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1489/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1489/comments
https://api.github.com/repos/coleifer/peewee/issues/1489/events
https://github.com/coleifer/peewee/issues/1489
296,590,549
MDU6SXNzdWUyOTY1OTA1NDk=
1,489
DateTimeTZField returns datetimes in other timezone
{ "login": "dswah", "id": 11619412, "node_id": "MDQ6VXNlcjExNjE5NDEy", "avatar_url": "https://avatars.githubusercontent.com/u/11619412?v=4", "gravatar_id": "", "url": "https://api.github.com/users/dswah", "html_url": "https://github.com/dswah", "followers_url": "https://api.github.com/users/dswah/followers", "following_url": "https://api.github.com/users/dswah/following{/other_user}", "gists_url": "https://api.github.com/users/dswah/gists{/gist_id}", "starred_url": "https://api.github.com/users/dswah/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/dswah/subscriptions", "organizations_url": "https://api.github.com/users/dswah/orgs", "repos_url": "https://api.github.com/users/dswah/repos", "events_url": "https://api.github.com/users/dswah/events{/privacy}", "received_events_url": "https://api.github.com/users/dswah/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "From: https://www.postgresql.org/docs/current/static/datatype-datetime.html\r\n\r\n> For timestamp with time zone, the internally stored value is always in UTC (Universal Coordinated Time, traditionally known as Greenwich Mean Time, GMT). An input value that has an explicit time zone specified is converted to UTC using the appropriate offset for that time zone. If no time zone is stated in the input string, then it is assumed to be in the time zone indicated by the system's TimeZone parameter, and is converted to UTC using the offset for the timezone zone.\r\n>\r\n> When a timestamp with time zone value is output, **it is always converted from UTC to the current timezone zone, and displayed as local time in that zone. To see the time in another time zone, either change timezone or use the AT TIME ZONE construct (see Section 9.9.3).**", "Thank you for the link to the documentation.\r\nIs there a way to tell peewee to output a DateTimeTZField in a desired tz, as suggested in [1]?\r\nThis would be very useful.\r\n\r\nDani\r\n\r\n[1](https://www.postgresql.org/docs/current/static/runtime-config-client.html#GUC-TIMEZONE)", "If you bothered to read the linked documentation, you would have found:\r\n\r\n> The TimeZone configuration parameter can be set in the file postgresql.conf, or in any of the other standard ways described in Chapter 19. There are also some special ways to set it:\r\n>\r\n> The SQL command `SET TIME ZONE` sets the time zone for the session. This is an alternative spelling of `SET TIMEZONE TO` with a more SQL-spec-compatible syntax.\r\n>\r\n> The `PGTZ` environment variable is used by libpq clients to send a `SET TIME ZONE` command to the server upon connection.\r\n\r\nSo, you can run: `db.execute_sql('SET TIME ZONE ...')`." ]
2018-02-13T02:10:43
2018-02-13T17:23:10
2018-02-13T16:38:06
NONE
null
Hi there. Thank you for the very useful library. I've used it a ton. However, ive recently run into something annoying with DateTimeTZField. when i select records with a DateTimeTZField, i always see this field in timezone A (local tz of db), even though the datetimes were originally in timezone B. why is this? how can i avoid this?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1489/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1489/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1488
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1488/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1488/comments
https://api.github.com/repos/coleifer/peewee/issues/1488/events
https://github.com/coleifer/peewee/issues/1488
296,435,863
MDU6SXNzdWUyOTY0MzU4NjM=
1,488
Cannot prefetch on MySQL when using limit
{ "login": "Webovani", "id": 2682406, "node_id": "MDQ6VXNlcjI2ODI0MDY=", "avatar_url": "https://avatars.githubusercontent.com/u/2682406?v=4", "gravatar_id": "", "url": "https://api.github.com/users/Webovani", "html_url": "https://github.com/Webovani", "followers_url": "https://api.github.com/users/Webovani/followers", "following_url": "https://api.github.com/users/Webovani/following{/other_user}", "gists_url": "https://api.github.com/users/Webovani/gists{/gist_id}", "starred_url": "https://api.github.com/users/Webovani/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/Webovani/subscriptions", "organizations_url": "https://api.github.com/users/Webovani/orgs", "repos_url": "https://api.github.com/users/Webovani/repos", "events_url": "https://api.github.com/users/Webovani/events{/privacy}", "received_events_url": "https://api.github.com/users/Webovani/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "The way prefetch is implemented, it does not use joins. Instead, it nests dependent clauses in subqueries. So your example would:\r\n\r\n```sql\r\n-- Get branches corresponding to shops in the outer query.\r\nSELECT \"t1\".\"id\", \"t1\".\"shop_id\" \r\nFROM \"branch\" AS \"t1\" \r\nWHERE (\"t1\".\"shop_id\" IN (SELECT \"t2\".\"id\" FROM \"shop\" AS \"t2\" LIMIT 10));\r\n\r\n-- Get the shops themselves.\r\nSELECT \"t1\".\"id\", \"t1\".\"name\" FROM \"shop\" AS \"t1\" LIMIT 10;\r\n```\r\n\r\nIt should be possible to write it instead as:\r\n\r\n```sql\r\nSELECT \"t1\".\"id\", \"t1\".\"shop_id\"\r\nFROM \"branch\" AS \"t1\"\r\nINNER JOIN \"shop\" AS \"t2\" ON (\"t1\".\"shop_id\" = \"t2\".\"id\")\r\n-- but what do we do with the limit?\r\n-- if there were tons of branches we could end up reading way more data than we need\r\n-- given the LIMIT on the outer query.\r\n```\r\n\r\nSo instead, maybe something like:\r\n\r\n```sql\r\nSELECT \"t1\".\"id\", \"t1\".\"shop_id\"\r\nFROM \"branch\" AS \"t1\"\r\nINNER JOIN (SELECT \"t2\".\"id\" FROM \"shop\" AS \"t2\" LIMIT 10) as subq ON (subq.id = t1.shop_id)\r\n```\r\n\r\nBut I'm thinking if MySQL doesn't support the first form, it probably doesn't support this form either?", "```sql\r\nSELECT \"t1\".\"id\", \"t1\".\"shop_id\"\r\nFROM \"branch\" AS \"t1\"\r\nINNER JOIN (SELECT \"t2\".\"id\" FROM \"shop\" AS \"t2\" LIMIT 10) as subq ON (subq.id = t1.shop_id)\r\n```\r\n\r\nThis form IS supported and works as expected. \r\n\r\nIt is equivalent to the `IN subq`, but sadly MySQL query planner is really lame and doesn't get it... Just MySQL things." ]
2018-02-12T16:22:26
2018-02-15T12:45:33
2018-02-13T17:23:40
NONE
null
```python from peewee import * database = MySQLDatabase(...) class BaseModel(Model): class Meta: database = database class Shop(BaseModel): name = CharField() class Branch(BaseModel): shop = ForeignKeyField(Shop, backref='branches') shops = Shop.select().limit(10) shops = prefetch(shops, Branch) ``` This will fail with error: `peewee.NotSupportedError: (1235, "This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'")` It doesn't seem to be supported even on MySQL 8. This could be solved by using JOIN on subquery, but I don't see how to do that in a reasonable way.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1488/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/1488/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1487
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1487/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1487/comments
https://api.github.com/repos/coleifer/peewee/issues/1487/events
https://github.com/coleifer/peewee/issues/1487
296,243,502
MDU6SXNzdWUyOTYyNDM1MDI=
1,487
Cannot connect using postgres.
{ "login": "mtairu", "id": 4996264, "node_id": "MDQ6VXNlcjQ5OTYyNjQ=", "avatar_url": "https://avatars.githubusercontent.com/u/4996264?v=4", "gravatar_id": "", "url": "https://api.github.com/users/mtairu", "html_url": "https://github.com/mtairu", "followers_url": "https://api.github.com/users/mtairu/followers", "following_url": "https://api.github.com/users/mtairu/following{/other_user}", "gists_url": "https://api.github.com/users/mtairu/gists{/gist_id}", "starred_url": "https://api.github.com/users/mtairu/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/mtairu/subscriptions", "organizations_url": "https://api.github.com/users/mtairu/orgs", "repos_url": "https://api.github.com/users/mtairu/repos", "events_url": "https://api.github.com/users/mtairu/events{/privacy}", "received_events_url": "https://api.github.com/users/mtairu/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Install psycopg2 yo.", "Thanks bro." ]
2018-02-12T00:48:43
2018-02-12T01:24:27
2018-02-12T01:23:13
NONE
null
Cannot connect using postgres. ``` db = PostgresqlDatabase('extra', user='extra', password='GBQ9x%@S', host='localhost') def connect(): try: db._connect() except BaseException as e: return e connect() ``` _AttributeError("'NoneType' object has no attribute 'connect'")_
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1487/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1487/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1486
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1486/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1486/comments
https://api.github.com/repos/coleifer/peewee/issues/1486/events
https://github.com/coleifer/peewee/issues/1486
296,146,726
MDU6SXNzdWUyOTYxNDY3MjY=
1,486
NoneType object has no attribute 'connect' while connecting to MySQL server
{ "login": "eliaperantoni", "id": 6002855, "node_id": "MDQ6VXNlcjYwMDI4NTU=", "avatar_url": "https://avatars.githubusercontent.com/u/6002855?v=4", "gravatar_id": "", "url": "https://api.github.com/users/eliaperantoni", "html_url": "https://github.com/eliaperantoni", "followers_url": "https://api.github.com/users/eliaperantoni/followers", "following_url": "https://api.github.com/users/eliaperantoni/following{/other_user}", "gists_url": "https://api.github.com/users/eliaperantoni/gists{/gist_id}", "starred_url": "https://api.github.com/users/eliaperantoni/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/eliaperantoni/subscriptions", "organizations_url": "https://api.github.com/users/eliaperantoni/orgs", "repos_url": "https://api.github.com/users/eliaperantoni/repos", "events_url": "https://api.github.com/users/eliaperantoni/events{/privacy}", "received_events_url": "https://api.github.com/users/eliaperantoni/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "You need to install a MySQL python driver like pymysql.\r\n\r\n pip install pymysql", "It worked! Thanks :grinning:" ]
2018-02-11T00:19:39
2020-03-17T17:09:06
2018-02-11T00:45:40
NONE
null
I've created a MySQL server on my server but whenever I try to connect to it in PeeWee I get this error: ``` >>> from peewee import * >>> db = MySQLDatabase('tormecapp', user='tormecapp', password='************') >>> db.connect() Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/eliap/.local/lib/python3.5/site-packages/peewee.py", line 2434, in connect self._state.set_connection(self._connect()) File "/home/eliap/.local/lib/python3.5/site-packages/peewee.py", line 3108, in _connect return mysql.connect(db=self.database, **self.connect_params) AttributeError: 'NoneType' object has no attribute 'connect' ``` I'm doing this on the same machine as the MySQL server This works: `mysql -u tormecapp -p tormecapp` so why doesn't peewee as well?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1486/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1486/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1485
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1485/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1485/comments
https://api.github.com/repos/coleifer/peewee/issues/1485/events
https://github.com/coleifer/peewee/issues/1485
296,129,687
MDU6SXNzdWUyOTYxMjk2ODc=
1,485
Setting schema in Meta class does not propagate
{ "login": "Karel-van-de-Plassche", "id": 6404167, "node_id": "MDQ6VXNlcjY0MDQxNjc=", "avatar_url": "https://avatars.githubusercontent.com/u/6404167?v=4", "gravatar_id": "", "url": "https://api.github.com/users/Karel-van-de-Plassche", "html_url": "https://github.com/Karel-van-de-Plassche", "followers_url": "https://api.github.com/users/Karel-van-de-Plassche/followers", "following_url": "https://api.github.com/users/Karel-van-de-Plassche/following{/other_user}", "gists_url": "https://api.github.com/users/Karel-van-de-Plassche/gists{/gist_id}", "starred_url": "https://api.github.com/users/Karel-van-de-Plassche/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/Karel-van-de-Plassche/subscriptions", "organizations_url": "https://api.github.com/users/Karel-van-de-Plassche/orgs", "repos_url": "https://api.github.com/users/Karel-van-de-Plassche/repos", "events_url": "https://api.github.com/users/Karel-van-de-Plassche/events{/privacy}", "received_events_url": "https://api.github.com/users/Karel-van-de-Plassche/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Fixed and pushed new version, 3.0.17. Added more tests to hopefully prevent this (or similar regressions) from recurring." ]
2018-02-10T20:09:05
2018-02-10T21:49:27
2018-02-10T21:44:46
NONE
null
I usually set a schema in my main class, but it doesn't propagate to subclasses since `3.0.16`. This causes any select to fail because the schema is not set in the raw SQL. Probably caused by #1483, commit 5cfc311eea8adb0d8aa836f493c3f9faf615b745. ``` Python db = PostgresqlExtDatabase(database='test', host='example.org') class BaseModel(Model): """A base model that will use our Postgresql database""" class Meta: database = db schema = 'develop' class TrainScript(BaseModel): script = TextField() version = TextField() ``` 3.0.15: ``` Python In [1]: BaseModel._meta.schema Out[1]: 'develop' In [2]: TrainScript._meta.schema Out[2]: 'develop' ``` 3.0.16: ``` Python In [1]: BaseModel._meta.schema Out[1]: 'develop' In [2]: TrainScript._meta.schema In [3]: TrainScript.select().get() --------------------------------------------------------------------------- ProgrammingError Traceback (most recent call last) /usr/lib/python3.6/site-packages/peewee.py in execute_sql(self, sql, params, commit) 2483 try: -> 2484 cursor.execute(sql, params or ()) 2485 except Exception: ProgrammingError: relation "trainscript" does not exist LINE 1: ...ECT "t1"."id", "t1"."script", "t1"."version" FROM "trainscri... ^ During handling of the above exception, another exception occurred: ProgrammingError Traceback (most recent call last) ~/working/QLKNN-develop/NNDB/model.py in <module>() ----> 1 TrainScript.select().get() /usr/lib/python3.6/site-packages/peewee.py in get(self) 5454 clone._cursor_wrapper = None 5455 try: -> 5456 return clone.execute()[0] 5457 except IndexError: 5458 sql, params = clone.sql() /usr/lib/python3.6/site-packages/peewee.py in inner(self, database, *args, **kwargs) 1445 raise Exception('Query must be bound to a database in order ' 1446 'to call "%s".' % method.__name__) -> 1447 return method(self, database, *args, **kwargs) 1448 return inner 1449 /usr/lib/python3.6/site-packages/peewee.py in execute(self, database) 1516 @database_required 1517 def execute(self, database): -> 1518 return self._execute(database) 1519 1520 def _execute(self, database): /usr/lib/python3.6/site-packages/peewee.py in _execute(self, database) 1670 def _execute(self, database): 1671 if self._cursor_wrapper is None: -> 1672 cursor = database.execute(self) 1673 self._cursor_wrapper = self._get_cursor_wrapper(cursor) 1674 return self._cursor_wrapper /usr/lib/python3.6/site-packages/playhouse/postgres_ext.py in execute(self, query, commit, named_cursor, array_size, **context_options) 424 if named_cursor: 425 commit = __named_cursor__ --> 426 cursor = self.execute_sql(sql, params, commit=commit) 427 if named_cursor: 428 cursor = FetchManyCursor(cursor, array_size) /usr/lib/python3.6/site-packages/peewee.py in execute_sql(self, sql, params, commit) 2489 else: 2490 if commit and not self.in_transaction(): -> 2491 self.commit() 2492 return cursor 2493 /usr/lib/python3.6/site-packages/peewee.py in __exit__(self, exc_type, exc_value, traceback) 2285 new_type = self.exceptions[exc_type.__name__] 2286 exc_args = exc_value if PY26 else exc_value.args -> 2287 reraise(new_type, new_type(*exc_args), traceback) 2288 2289 EXCEPTIONS = { /usr/lib/python3.6/site-packages/peewee.py in reraise(tp, value, tb) 168 def reraise(tp, value, tb=None): 169 if value.__traceback__ is not tb: --> 170 raise value.with_traceback(tb) 171 raise value 172 /usr/lib/python3.6/site-packages/peewee.py in execute_sql(self, sql, params, commit) 2482 cursor = self.cursor(commit) 2483 try: -> 2484 cursor.execute(sql, params or ()) 2485 except Exception: 2486 if self.autorollback and not self.in_transaction(): ProgrammingError: relation "trainscript" does not exist LINE 1: ...ECT "t1"."id", "t1"."script", "t1"."version" FROM "trainscri... ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1485/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1485/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1484
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1484/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1484/comments
https://api.github.com/repos/coleifer/peewee/issues/1484/events
https://github.com/coleifer/peewee/issues/1484
295,991,028
MDU6SXNzdWUyOTU5OTEwMjg=
1,484
[Feature Request] Support Signals in `insert`/`update`/`delete` in Postgres using `returning`
{ "login": "logannc", "id": 2867206, "node_id": "MDQ6VXNlcjI4NjcyMDY=", "avatar_url": "https://avatars.githubusercontent.com/u/2867206?v=4", "gravatar_id": "", "url": "https://api.github.com/users/logannc", "html_url": "https://github.com/logannc", "followers_url": "https://api.github.com/users/logannc/followers", "following_url": "https://api.github.com/users/logannc/following{/other_user}", "gists_url": "https://api.github.com/users/logannc/gists{/gist_id}", "starred_url": "https://api.github.com/users/logannc/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/logannc/subscriptions", "organizations_url": "https://api.github.com/users/logannc/orgs", "repos_url": "https://api.github.com/users/logannc/repos", "events_url": "https://api.github.com/users/logannc/events{/privacy}", "received_events_url": "https://api.github.com/users/logannc/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I'm unsure that this can be done cleanly and correctly, so I'm not inclined to implement or merge an implementation.", "Briefly, what are your concerns?", "Where would you install the signal hooks? What would they do? How would you make them work on SQLite and MySQL, which do not have `returning` clause support?", "They can be installed the same way they are now. They could function the same way, by mapping the signal handler over the iterable or providing a hook for passing the collection. \r\n\r\nThey wouldn't work on SQLite or MySQL, just like `returning` doesn't work on them.", "Going to close this as I'm not interested in the feature, but feel free to implement it in a third-party module." ]
2018-02-09T19:49:08
2018-02-10T21:50:31
2018-02-10T21:50:31
NONE
null
It would appear that Postgres can support signals using `returning`. It should be able to easily support `post_*` signals using returning. The performance penalty should be worth the consistency in `update` vs. `save`. Supporting `pre_*` signals would be a bit painful as you'd need to execute the save/insert using returning in an atomic block, reverting it before the block ends, fire the `pre_*` signal, replay the query, and then finally fire the `post_*` signal. The performance penalty here has the potential to be severe. Thoughts? Would a PR be welcomed?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1484/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1484/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1483
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1483/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1483/comments
https://api.github.com/repos/coleifer/peewee/issues/1483/events
https://github.com/coleifer/peewee/issues/1483
295,556,946
MDU6SXNzdWUyOTU1NTY5NDY=
1,483
Can't change schema via `Model._meta.schema` (regression from 2.X)
{ "login": "vikt0rs", "id": 5230490, "node_id": "MDQ6VXNlcjUyMzA0OTA=", "avatar_url": "https://avatars.githubusercontent.com/u/5230490?v=4", "gravatar_id": "", "url": "https://api.github.com/users/vikt0rs", "html_url": "https://github.com/vikt0rs", "followers_url": "https://api.github.com/users/vikt0rs/followers", "following_url": "https://api.github.com/users/vikt0rs/following{/other_user}", "gists_url": "https://api.github.com/users/vikt0rs/gists{/gist_id}", "starred_url": "https://api.github.com/users/vikt0rs/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/vikt0rs/subscriptions", "organizations_url": "https://api.github.com/users/vikt0rs/orgs", "repos_url": "https://api.github.com/users/vikt0rs/repos", "events_url": "https://api.github.com/users/vikt0rs/events{/privacy}", "received_events_url": "https://api.github.com/users/vikt0rs/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "For now, can you try this change for 3.x?\r\n\r\n```python\r\n@contextmanager\r\ndef context(schema_name):\r\n with DB.atomic() as transaction:\r\n del DocumentsModel._meta.table # Don't worry, this won't delete any data.\r\n DocumentsModel._meta.schema = schema_name\r\n yield transaction\r\n DocumentsModel._meta.schema = None\r\n```", "yes, this works for peewee==3.0.15 and fails on 2.X, thanks for suggestion", "Pushed 3.0.16, which contains fix for this issue.", "Thanks!" ]
2018-02-08T15:34:56
2018-02-09T13:07:35
2018-02-08T19:58:56
NONE
null
I'm working to work with several DB schemas and use `Model._meta.schema` to switch them, as shown in attached script. But for some reasons schema switch doesn't work in peewee 3.X. See console output. Please, suggest is it a bug or there is a better way to do it. Thanks! Console output ``` $ pip freeze | grep peewee peewee==2.10.2 peewee-async==0.5.10 $ python test_schema_change.py ('SELECT "t1"."document_uuid", "t1"."name" FROM "user_1"."documents_metadata" AS t1 WHERE ("t1"."name" = %s)', ['test']) ('SELECT "t1"."document_uuid", "t1"."name" FROM "user_2"."documents_metadata" AS t1 WHERE ("t1"."name" = %s)', ['test']) $ pip install peewee==3.0.15 Collecting peewee==3.0.15 Installing collected packages: peewee Found existing installation: peewee 2.10.2 Uninstalling peewee-2.10.2: Successfully uninstalled peewee-2.10.2 Successfully installed peewee-3.0.15 $ python test_schema_change.py ('SELECT "t1"."document_uuid", "t1"."name" FROM "user_1"."documents_metadata" AS "t1" WHERE ("t1"."name" = %s)', ['test']) ('SELECT "t1"."document_uuid", "t1"."name" FROM "user_1"."documents_metadata" AS "t1" WHERE ("t1"."name" = %s)', ['test']) ``` Executed script ``` from contextlib import contextmanager import peewee DB = peewee.PostgresqlDatabase( "my_documents", user="username", password="top_secret" ) class DocumentsModel(peewee.Model): uuid = peewee.UUIDField(primary_key=True, db_column="document_uuid") name = peewee.CharField(256) class Meta: db_table = "documents_metadata" database = DB @contextmanager def context(schema_name): with DB.atomic() as transaction: DocumentsModel._meta.schema = schema_name yield transaction DocumentsModel._meta.schema = None with context('user_1'): print(DocumentsModel.filter(name="test").sql()) with context('user_2'): print(DocumentsModel.filter(name="test").sql()) ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1483/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1483/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1482
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1482/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1482/comments
https://api.github.com/repos/coleifer/peewee/issues/1482/events
https://github.com/coleifer/peewee/issues/1482
295,510,860
MDU6SXNzdWUyOTU1MTA4NjA=
1,482
Foreign key field is None when joining on multiple tables with CompositeKey
{ "login": "Tiscs", "id": 2810237, "node_id": "MDQ6VXNlcjI4MTAyMzc=", "avatar_url": "https://avatars.githubusercontent.com/u/2810237?v=4", "gravatar_id": "", "url": "https://api.github.com/users/Tiscs", "html_url": "https://github.com/Tiscs", "followers_url": "https://api.github.com/users/Tiscs/followers", "following_url": "https://api.github.com/users/Tiscs/following{/other_user}", "gists_url": "https://api.github.com/users/Tiscs/gists{/gist_id}", "starred_url": "https://api.github.com/users/Tiscs/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/Tiscs/subscriptions", "organizations_url": "https://api.github.com/users/Tiscs/orgs", "repos_url": "https://api.github.com/users/Tiscs/repos", "events_url": "https://api.github.com/users/Tiscs/events{/privacy}", "received_events_url": "https://api.github.com/users/Tiscs/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "What am I looking at here? What is the output of this on your computer? What's going wrong?", "Possibly related commit: 6bdcd7dc3800654ba034d03b3e7dc01971388e34\r\n\r\n-------------------\r\n\r\nNote: you're joining on several models unnecessarily...or, you've forgotten to add them to the `select()`:\r\n\r\n```python\r\n# e.g.\r\nquery = OAuth2Account.select(OAuth2Account, UserAccount, OAuth2Client).join(...)\r\n```", "I've taken your code and modified it slightly w/some test data to run locally. I see the problem -- when you include the join on `Tenant` then the `UserAccount` is empty.\r\n\r\nFailing test case\r\n\r\n```python\r\n @requires_models(A, B, C)\r\n def test_join_issue_1482(self):\r\n a1 = A.create(a='a1')\r\n b1 = B.create(a=a1, b='b1')\r\n c1 = C.create(b=b1, c='c1')\r\n\r\n query = (C\r\n .select()\r\n .join(B)\r\n .join(A)\r\n .where(A.a == 'a1'))\r\n with self.assertQueryCount(3):\r\n accum = [(c.c, c.b.b, c.b.a.a) for c in query]\r\n\r\n self.assertEqual(accum, [('c1', 'b1', 'a1')])\r\n```\r\n\r\nThe thing I'm confused about in your queries is why, if you're joining on those models and wish to access joined instances, you aren't also selecting the columns from those models? In other words, do you realize you're doing O(n) queries?", "Fixed by c76f07b", "Upgrade to peewee==3.0.16, the issue is fixed.\r\n\r\nThanks!", "Actually, I want to find a `OAuth2Account` by `UserAccount.id` and `Tenant.id`, so I tried to join `Tenant` into the query.\r\n``` python\r\nquery = OAuth2Account.select().join(OAuth2Client).switch(OAuth2Account).join(UserAccount).join(Tenant).where(UserAccount.id == 1).where(Tenant.id == 1)\r\n```" ]
2018-02-08T13:25:53
2018-02-09T02:29:27
2018-02-08T16:38:47
NONE
null
Works fine with peewee<3.0.12., may be something wrong at line 5968 in peewee.py. Test codes below. ``` python import peewee database = peewee.MySQLDatabase('auth.py', **{ 'charset': 'utf8', 'use_unicode': True, 'host': 'localhost', 'port': 3306, 'user': 'root', 'password': '********' }) class BaseModel(peewee.Model): class Meta: database = database class Tenant(BaseModel): id = peewee.BigIntegerField(primary_key=True) class Meta: table_name = 'tenants' class UserAccount(BaseModel): id = peewee.BigIntegerField(primary_key=True) tenant = peewee.ForeignKeyField(column_name='tenant_id', model=Tenant, field='id') username = peewee.CharField() class Meta: table_name = 'user_accounts' class OAuth2Client(BaseModel): id = peewee.BigIntegerField(primary_key=True) name = peewee.CharField() class Meta: table_name = 'oauth2_clients' class OAuth2Account(BaseModel): oauth2_client = peewee.ForeignKeyField(column_name='oauth2_client_id', model=OAuth2Client, field='id') user_account = peewee.ForeignKeyField(column_name='user_account_id', model=UserAccount, field='id') class Meta: table_name = 'oauth2_accounts' primary_key = peewee.CompositeKey('oauth2_client', 'user_account') if __name__ == '__main__': query = OAuth2Account.select().join(OAuth2Client).switch(OAuth2Account).join(UserAccount).where(UserAccount.id == 1) for oa in query: print((oa.oauth2_client_id, oa.oauth2_client.name)) print((oa.user_account_id, oa.user_account.username)) query = OAuth2Account.select().join(OAuth2Client).switch(OAuth2Account).join(UserAccount).join(Tenant).where( UserAccount.id == 1) for oa in query: print((oa.oauth2_client_id, oa.oauth2_client.name)) print((oa.user_account_id, oa.user_account.username)) ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1482/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1482/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1481
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1481/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1481/comments
https://api.github.com/repos/coleifer/peewee/issues/1481/events
https://github.com/coleifer/peewee/issues/1481
295,359,966
MDU6SXNzdWUyOTUzNTk5NjY=
1,481
Pragmas gets unset on init
{ "login": "codito", "id": 28766, "node_id": "MDQ6VXNlcjI4NzY2", "avatar_url": "https://avatars.githubusercontent.com/u/28766?v=4", "gravatar_id": "", "url": "https://api.github.com/users/codito", "html_url": "https://github.com/codito", "followers_url": "https://api.github.com/users/codito/followers", "following_url": "https://api.github.com/users/codito/following{/other_user}", "gists_url": "https://api.github.com/users/codito/gists{/gist_id}", "starred_url": "https://api.github.com/users/codito/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/codito/subscriptions", "organizations_url": "https://api.github.com/users/codito/orgs", "repos_url": "https://api.github.com/users/codito/repos", "events_url": "https://api.github.com/users/codito/events{/privacy}", "received_events_url": "https://api.github.com/users/codito/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Thanks for reporting.", "Fixed, pushed new version to PyPI - 3.0.15. Thanks again for letting me know.", "Thanks a ton! Confirmed the issue is fixed with 3.0.15." ]
2018-02-08T02:05:09
2018-02-08T13:34:25
2018-02-08T04:00:24
NONE
null
This scenario uses runtime database configuration. The `pragmas` configuration is reset to empty upon doing a `SqliteDatabase.init(name)`. It's happening since `init` now takes `pragmas` as an input argument which defaults to `None`. It's a behavior change from peewee 2. Is it by design? ### Peewee 3.0.13 ```python Python 3.6.4 (default, Jan 5 2018, 02:35:40) [GCC 7.2.1 20171224] on linux Type "help", "copyright", "credits" or "license" for more information. >>> from peewee import SqliteDatabase >>> db = SqliteDatabase(None, pragmas=(('foreign_keys', 'on'),)) >>> print(db._pragmas) (('foreign_keys', 'on'),) >>> db.init(':memory:') >>> print(db._pragmas) () ``` ### Peewee 2.10.2 ```python Python 3.6.4 (default, Jan 5 2018, 02:35:40) [GCC 7.2.1 20171224] on linux Type "help", "copyright", "credits" or "license" for more information. >>> from peewee import SqliteDatabase >>> db = SqliteDatabase(None, pragmas=(('foreign_keys', 'on'),)) >>> print(db._pragmas) (('foreign_keys', 'on'),) >>> db.init(':memory:') >>> print(db._pragmas) (('foreign_keys', 'on'),) >>> ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1481/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1481/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1480
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1480/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1480/comments
https://api.github.com/repos/coleifer/peewee/issues/1480/events
https://github.com/coleifer/peewee/issues/1480
295,257,280
MDU6SXNzdWUyOTUyNTcyODA=
1,480
Can't create model instance without primary key
{ "login": "aachurin", "id": 680329, "node_id": "MDQ6VXNlcjY4MDMyOQ==", "avatar_url": "https://avatars.githubusercontent.com/u/680329?v=4", "gravatar_id": "", "url": "https://api.github.com/users/aachurin", "html_url": "https://github.com/aachurin", "followers_url": "https://api.github.com/users/aachurin/followers", "following_url": "https://api.github.com/users/aachurin/following{/other_user}", "gists_url": "https://api.github.com/users/aachurin/gists{/gist_id}", "starred_url": "https://api.github.com/users/aachurin/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/aachurin/subscriptions", "organizations_url": "https://api.github.com/users/aachurin/orgs", "repos_url": "https://api.github.com/users/aachurin/repos", "events_url": "https://api.github.com/users/aachurin/events{/privacy}", "received_events_url": "https://api.github.com/users/aachurin/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Ewww, thank you.", "thx", "3.0.14 on PyPI." ]
2018-02-07T19:09:55
2018-02-07T19:43:27
2018-02-07T19:41:12
NONE
null
```python class Model1(TestModel): test1 = CharField(max_length=10) class Meta: primary_key = False Model1.create(test1='1') # fails. ``` ``` Traceback (most recent call last): File "tests.py", line 412, in test_add_primary_key Model1.create(test1='1') File "/Users/peewee_test/lib/python3.6/site-packages/peewee-3.0.11-py3.6.egg/peewee.py", line 5049, in create inst.save(force_insert=True) File "/Users/peewee_test/lib/python3.6/site-packages/peewee-3.0.11-py3.6.egg/peewee.py", line 5165, in save self.insert(**field_dict).execute() File "/Users/peewee_test/lib/python3.6/site-packages/peewee-3.0.11-py3.6.egg/peewee.py", line 1447, in inner return method(self, database, *args, **kwargs) File "/Users/peewee_test/lib/python3.6/site-packages/peewee-3.0.11-py3.6.egg/peewee.py", line 1518, in execute return self._execute(database) File "/Users/peewee_test/lib/python3.6/site-packages/peewee-3.0.11-py3.6.egg/peewee.py", line 2150, in _execute return super(Insert, self)._execute(database) File "/Users/peewee_test/lib/python3.6/site-packages/peewee-3.0.11-py3.6.egg/peewee.py", line 1929, in _execute return self.handle_result(database, cursor) File "/Users/peewee_test/lib/python3.6/site-packages/peewee-3.0.11-py3.6.egg/peewee.py", line 2153, in handle_result return database.last_insert_id(cursor, self._query_type) File "/Users/peewee_test/lib/python3.6/site-packages/peewee-3.0.11-py3.6.egg/peewee.py", line 2931, in last_insert_id return cursor if query_type else cursor[0][0] File "/Users/peewee_test/lib/python3.6/site-packages/peewee-3.0.11-py3.6.egg/peewee.py", line 3345, in __getitem__ self.fill_cache(item if item > 0 else 0) File "/Users/peewee_test/lib/python3.6/site-packages/peewee-3.0.11-py3.6.egg/peewee.py", line 3390, in fill_cache iterator.next() File "/Users/peewee_test/lib/python3.6/site-packages/peewee-3.0.11-py3.6.egg/peewee.py", line 3446, in next self.cursor_wrapper.iterate() File "/Users/peewee_test/lib/python3.6/site-packages/peewee-3.0.11-py3.6.egg/peewee.py", line 3365, in iterate self.initialize() # Lazy initialization. File "/Users/peewee_test/lib/python3.6/site-packages/peewee-3.0.11-py3.6.egg/peewee.py", line 5842, in _initialize_columns node = node.unwrap() AttributeError: 'bool' object has no attribute 'unwrap' ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1480/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1480/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1479
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1479/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1479/comments
https://api.github.com/repos/coleifer/peewee/issues/1479/events
https://github.com/coleifer/peewee/issues/1479
295,239,729
MDU6SXNzdWUyOTUyMzk3Mjk=
1,479
Alternative for prepared()
{ "login": "faisalraja", "id": 3916729, "node_id": "MDQ6VXNlcjM5MTY3Mjk=", "avatar_url": "https://avatars.githubusercontent.com/u/3916729?v=4", "gravatar_id": "", "url": "https://api.github.com/users/faisalraja", "html_url": "https://github.com/faisalraja", "followers_url": "https://api.github.com/users/faisalraja/followers", "following_url": "https://api.github.com/users/faisalraja/following{/other_user}", "gists_url": "https://api.github.com/users/faisalraja/gists{/gist_id}", "starred_url": "https://api.github.com/users/faisalraja/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/faisalraja/subscriptions", "organizations_url": "https://api.github.com/users/faisalraja/orgs", "repos_url": "https://api.github.com/users/faisalraja/repos", "events_url": "https://api.github.com/users/faisalraja/events{/privacy}", "received_events_url": "https://api.github.com/users/faisalraja/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "There isn't really a comparable API anymore.", "I was about to submit a new issue but found this one, which seems to be the same, so I'll post mine here: \r\n\r\nI had implemented a decently functional change-tracking system to my peewee v2 integration, which allows me to log/record any changes made to models that this feature is enabled for. In order to do this, I leveraged the `post_init` signal (though for reasons I can't remember, I basically merged the `playhouse.signals` code into my base model to call instance methods (e.g. `self._post_init()`) rather than signals).\r\n\r\nI recently started migrating to peewee v3 and I found that this signal was removed, and I can't find a convenient way to replicate it. \r\n\r\nThis signal is important because I use it to store the initial data of the model, by copying `self._data` (or `self.__data__` in v3) to a separate dict. Then when the model is saved, I compare these old/original values against the current `self._data`/`self.__data__` to determine the differences, generating any relevant \"change history\" records.\r\n\r\nWould it be possible to restore this signal or similar functionality (e.g. `self.prepared()`)? Or do you have any suggestions on how I could build this out? This is the only thing holding me back from migrating to v3 (I'm a big fan of all the other changes/updates). ", "Well, as I wrote, there isn't really a comparable API anymore. You should probably isolate the places in your codebase where changes can occur and do the tracking there. Implementing a service layer is one option.", "Ok bummer. Definitely not a fan of separate service layers. I like having only one way to CRUD (e.g. [wicked domain models](https://vimeo.com/43598193)), which is why hooking into these signals made change tracking so easy/transparent. I will think of something...", "I can't remember how exactly I did it since I left the company that I used it for. But the way I did it is I override __setattr__ (again not 100% sure I haven't used peewee & python in a while) with my BaseAuditModel that inherits ndb.Model. Then when a set happens, I check if __originalValue__ is None then copy __data__ to __originalValue__ then call parent set.", "> I can't remember how exactly I did it since I left the company that I used it for. But the way I did it is I override **setattr** (again not 100% sure I haven't used peewee & python in a while) with my BaseAuditModel that inherits ndb.Model. Then when a set happens, I check if **originalValue** is None then copy **data** to **originalValue** then call parent set.\r\n\r\nAh that's a good approach. Thanks!" ]
2018-02-07T18:12:40
2018-12-04T22:20:19
2018-02-07T18:14:32
NONE
null
What should I be using for prepared on version 3? I noticed it's not available anymore and I didn't see it in backwards breaking changes docs. I use it to copy the _data now __data__ whenever prepared is called. Thanks
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1479/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1479/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1478
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1478/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1478/comments
https://api.github.com/repos/coleifer/peewee/issues/1478/events
https://github.com/coleifer/peewee/pull/1478
295,148,220
MDExOlB1bGxSZXF1ZXN0MTY3NzAwNDc1
1,478
Scheme resolution for database urls
{ "login": "mguillau", "id": 3710154, "node_id": "MDQ6VXNlcjM3MTAxNTQ=", "avatar_url": "https://avatars.githubusercontent.com/u/3710154?v=4", "gravatar_id": "", "url": "https://api.github.com/users/mguillau", "html_url": "https://github.com/mguillau", "followers_url": "https://api.github.com/users/mguillau/followers", "following_url": "https://api.github.com/users/mguillau/following{/other_user}", "gists_url": "https://api.github.com/users/mguillau/gists{/gist_id}", "starred_url": "https://api.github.com/users/mguillau/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/mguillau/subscriptions", "organizations_url": "https://api.github.com/users/mguillau/orgs", "repos_url": "https://api.github.com/users/mguillau/repos", "events_url": "https://api.github.com/users/mguillau/events{/privacy}", "received_events_url": "https://api.github.com/users/mguillau/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "> I added recursive resolution without allowing two resolutions of the same scheme.\r\n\r\nI'm not sure I understand the need for this. So your overall db-url would be something like `env://sqlite:///:memory:`?", "The idea is to support the chaining of resolution schemes. Because of the scheme loop constraint, this would only work if at least two resolution schemes are available.\r\n\r\nSo, imagine we have added support for two or more resolution schemes, say, the `env://` resolution scheme as above (which replaces an url of the form `env://#ENVVAR` with the url contained _inside_ the \"$ENVVAR\" environment variable) and also an `rds://` resolution scheme as in the PR #1359 (which provides the endpoint, port, login, db engine, etc. from an AWS RDS cluster id provided as `rds://rds-db-cluster-id`).\r\n\r\nWithout recursive resolution, one would not be able to use an environment variable and the `env://` scheme to store an `rds://` db-url to obtain the real db connection information. One would only be able to store urls that are already supported by playhouse. With recursive resolution, instead, a chain like this is possible:\r\n\r\n`env://#ENVVAR` -> (reads the content of `$ENVVAR`) -> `rds://rds-db-cluster-id` -> (uses boto3 to get endpoint connection information for `rds-db-cluster-id`) -> `mysql://[email protected]:1234/dbname` -> (resolution is finished since `mysql://` is not a resolution scheme) -> the corresponding `MysqlDatabase` is instantiated.\r\n\r\nOne could imagine further resolution schemes, such as parsing a config file or obtaining database connection information from a credential management service. The `env://` scheme is just the simplest possible example I could think of to demonstrate the feature.", "I think this conflates the idea of url scheme handling with configuration.\r\n\r\nTo my thinking, the proper way to handle environment variables is:\r\n\r\n```python\r\ndef configure_database():\r\n connection_string = os.environ['DATABASE']\r\n return db_url.connect(connection_string)\r\n```", "I'm not 100% sure if by \"this\" you mean (1) env:// as a proposed scheme, (2) the chaining of url resolutions or (3) the entire idea of url resolution.\r\n\r\n(1) Handling environment variables was just an illustration here, it's not part of what I propose for playhouse. I agree with you that what you suggest is a simpler way to handle this.\r\n\r\n(2) It's true that the idea of chaining came to me while considering the env:// case, but I also see the generality behind it. You might have a credential/configuration manager providing you an url that you have to resolve again (e.g. the rds:// example) to get the actual endpoint.\r\n\r\n(3) To be brief, my team has a couple of use cases at work where we retrieve database connection information via an API by providing an identifier string. It is only after the API request that we know, what is the database engine type (and thus the right peewee Database subclass to use), the username, the password, etc. This \"dynamic\" mapping from id string to Database subclass and other connection information seemed to fit the whole db-url spirit quite well, but we need more than just urlparse to deduce the class and also a way to inject the login/password obtained from the API response into the `connect_kwargs` dict. The simple idea of generating a new (parsed) url from another url seemed like a reasonably elegant solution. We're open to suggestions, though.", "Having given this some additional thought, I'm going to pass on the proposed change." ]
2018-02-07T14:01:39
2018-02-08T20:02:57
2018-02-08T20:02:57
NONE
null
Following the feedback on #1359, here's a minimal patch to allow extensions for resolving database urls. Below is an example of how one would create a simple standalone extension for reading database URLs stored in environment variables: db_url_env_ext.py : ``` import os from urlparse import urlparse from playhouse.db_url import register_resolver def parse_from_env(parsed): env_var = parsed.fragment # using the fragment component as it is case sensitive return urlparse(os.environ[env_var]) register_resolver(parse_from_env, 'env') ``` which could be used like this: ``` $ export DBURL="sqlite:///:memory:" $ python >>> import playhouse.db_url as db_url >>> import db_url_env_ext >>> d = db_url.connect('env://#DBURL') ``` Compared to #1359, I added recursive resolution without allowing two resolutions of the same scheme. This prevents infinite loops such as: ``` $ export DBURL="env://#DBURL" $ python >>> import playhouse.db_url as db_url >>> import db_url_env_ext >>> d = db_url.connect('env://#DBURL') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "playhouse/db_url.py", line 106, in connect parsed = resolve(urlparse(url)) File "playhouse/db_url.py", line 49, in resolve '{}'.format(parsed.scheme, seen_schemes)) playhouse.db_url.ResolutionLoop: Scheme env has already been used: set(['env']) ``` Looking forward to your feedback!
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1478/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1478/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/1478", "html_url": "https://github.com/coleifer/peewee/pull/1478", "diff_url": "https://github.com/coleifer/peewee/pull/1478.diff", "patch_url": "https://github.com/coleifer/peewee/pull/1478.patch", "merged_at": null }
https://api.github.com/repos/coleifer/peewee/issues/1477
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1477/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1477/comments
https://api.github.com/repos/coleifer/peewee/issues/1477/events
https://github.com/coleifer/peewee/issues/1477
295,046,385
MDU6SXNzdWUyOTUwNDYzODU=
1,477
Feature: Type annotation
{ "login": "cLupus", "id": 2326244, "node_id": "MDQ6VXNlcjIzMjYyNDQ=", "avatar_url": "https://avatars.githubusercontent.com/u/2326244?v=4", "gravatar_id": "", "url": "https://api.github.com/users/cLupus", "html_url": "https://github.com/cLupus", "followers_url": "https://api.github.com/users/cLupus/followers", "following_url": "https://api.github.com/users/cLupus/following{/other_user}", "gists_url": "https://api.github.com/users/cLupus/gists{/gist_id}", "starred_url": "https://api.github.com/users/cLupus/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/cLupus/subscriptions", "organizations_url": "https://api.github.com/users/cLupus/orgs", "repos_url": "https://api.github.com/users/cLupus/repos", "events_url": "https://api.github.com/users/cLupus/events{/privacy}", "received_events_url": "https://api.github.com/users/cLupus/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "@cLupus this would limit the versions of Python which peewee can run on ...\r\nThis should probably be added after 3.5 and 3.4 are EOL.", "Does that include [snubs (mypy)](http://mypy.readthedocs.io/en/stable/basics.html#library-stubs-and-the-typeshed-repo) as well, @oz123 ?", "I'm of the opinion that type annotation/hinting is absolutely un-pythonic and just adds noise to what would otherwise be very clean/readable code. Python's a dynamic language. If you want Python + types, there's other, statically-typed languages available...but I'm not interested in them.", "Type annotations do not make the code statically typed, and they are absolutely not noise. For example they let me save hours every day at work by virtue of letting me check what to give to any parameter without leaving the editor instead of having to switch to the browser to read the documentation (because docstrings are sadly also missing), and type checkers have also spared me hours of debugging by letting me find mistakes well before they could become bugs. Type annotations help massively with auto-completion too.\r\n\r\nThe situation since 2018 has changed dramatically and annotations are a tried and true, useful tool at this point, and pretty much considered an expected luxury by active, popular libraries. I think Peewee's API is nice enough that it deserves to be (more) popular, and type annotations can be a deal maker for many.\r\n\r\nOn the topic of compatibility, there is the possibility of publishing type annotations through a separate package (e.g. `peewee-stubs`) by following [PEP 561](https://peps.python.org/pep-0561/), if for some reason placing them directly in the code isn't deemed feasible.\r\n\r\nI propose reopening this issue and I'm willing to help with the implementation myself." ]
2018-02-07T08:27:54
2022-08-23T17:55:28
2018-02-07T14:33:09
NONE
null
Hi, Is there any plans of adding type annotation (hinting) to peewee?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1477/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/1477/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1476
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1476/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1476/comments
https://api.github.com/repos/coleifer/peewee/issues/1476/events
https://github.com/coleifer/peewee/issues/1476
294,978,455
MDU6SXNzdWUyOTQ5Nzg0NTU=
1,476
Broken backward compatibility: missing **playhouse.shortcuts.RetryOperationalError**
{ "login": "nad2000", "id": 177266, "node_id": "MDQ6VXNlcjE3NzI2Ng==", "avatar_url": "https://avatars.githubusercontent.com/u/177266?v=4", "gravatar_id": "", "url": "https://api.github.com/users/nad2000", "html_url": "https://github.com/nad2000", "followers_url": "https://api.github.com/users/nad2000/followers", "following_url": "https://api.github.com/users/nad2000/following{/other_user}", "gists_url": "https://api.github.com/users/nad2000/gists{/gist_id}", "starred_url": "https://api.github.com/users/nad2000/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/nad2000/subscriptions", "organizations_url": "https://api.github.com/users/nad2000/orgs", "repos_url": "https://api.github.com/users/nad2000/repos", "events_url": "https://api.github.com/users/nad2000/events{/privacy}", "received_events_url": "https://api.github.com/users/nad2000/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I don't see it in the documentation, it's been removed.", "My old code run on peewee 3.1.5 raise ImportError: cannot import name RetryOperationalError\r\nhow to use RetryOperationalError on 3.1.5, the docs can't find anything about it", "It was removed in 3.0." ]
2018-02-07T01:50:41
2018-03-21T11:59:16
2018-02-07T14:31:39
NONE
null
``` File "/home/rcir178/NZ-ORCID-Hub/orcid_hub/__init__.py", line 28, in <module> from playhouse.shortcuts import RetryOperationalError ImportError: cannot import name 'RetryOperationalError' ERROR: could not load /home/rcir178/NZ-ORCID-Hub/tests/conftest.py ``` The documentation still refers to it:
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1476/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1476/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1475
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1475/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1475/comments
https://api.github.com/repos/coleifer/peewee/issues/1475/events
https://github.com/coleifer/peewee/issues/1475
294,805,119
MDU6SXNzdWUyOTQ4MDUxMTk=
1,475
slight change needed for flask-admin/contrib/peewee/forms.py
{ "login": "jefmud", "id": 3975684, "node_id": "MDQ6VXNlcjM5NzU2ODQ=", "avatar_url": "https://avatars.githubusercontent.com/u/3975684?v=4", "gravatar_id": "", "url": "https://api.github.com/users/jefmud", "html_url": "https://github.com/jefmud", "followers_url": "https://api.github.com/users/jefmud/followers", "following_url": "https://api.github.com/users/jefmud/following{/other_user}", "gists_url": "https://api.github.com/users/jefmud/gists{/gist_id}", "starred_url": "https://api.github.com/users/jefmud/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/jefmud/subscriptions", "organizations_url": "https://api.github.com/users/jefmud/orgs", "repos_url": "https://api.github.com/users/jefmud/repos", "events_url": "https://api.github.com/users/jefmud/events{/privacy}", "received_events_url": "https://api.github.com/users/jefmud/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I'm not sure why `flask-admin` was importing `BaseModel`...it's changed in 3.0 to `ModelBase`. So the following should work:\r\n\r\n```python\r\nfrom peewee import (CharField, DateTimeField, DateField, TimeField,\r\n PrimaryKeyField, ForeignKeyField)\r\ntry:\r\n from peewee import BaseModel\r\nexcept ImportError:\r\n from peewee import ModelBase as BaseModel\r\n```", "`peewee.BaseModel` (and latterly `peewee.ModelBase`) is the metaclass that is used to create `Model` classes. It's an internal implementation thing, so I'm not sure why it's being imported by flask-admin.", "They are checking something with \"is_instance()\" against the BaseModel\n\nOn Tue, Feb 6, 2018 at 10:56 AM, Charles Leifer <[email protected]>\nwrote:\n\n> peewee.BaseModel (and latterly peewee.ModelBase) is the metaclass that is\n> used to create Model classes. It's an internal implementation thing, so\n> I'm not sure why it's being imported by flask-admin.\n>\n> —\n> You are receiving this because you authored the thread.\n> Reply to this email directly, view it on GitHub\n> <https://github.com/coleifer/peewee/issues/1475#issuecomment-363467201>,\n> or mute the thread\n> <https://github.com/notifications/unsubscribe-auth/ADyqBIioDqlqVzFdl_10Q4_EguxmbPiDks5tSHYjgaJpZM4R7QH4>\n> .\n>\n\n\n\n-- \nJeff Muday\nInstructional Technology Analyst\nWake Forest University\n1834 Wake Forest Rd.\nWinston Hall Rm. 27\nWinston Salem, NC 27106\nmudayja @ wfu . edu\np 336.758.6171\nf 336.758.6004\n" ]
2018-02-06T15:39:32
2018-02-06T15:57:25
2018-02-06T15:55:02
NONE
null
Charles-- Peewee is great; simple and expressive (it was introduced to me by Kenneth Love). I noticed this small issue with interoperability with flask-admin, see below. Issue: (flask-admin) slight change needed for flask-admin/contrib/peewee/form.py The latest version of peewee (3.0) no longer includes BaseModel. So... this import should be changed for compatibility or simply substitute Model for BaseModel. Do you agree? ```python ### original #### from peewee import (CharField, DateTimeField, DateField, TimeField, PrimaryKeyField, ForeignKeyField, BaseModel) ``` ```python ### change to ##### from peewee import (CharField, DateTimeField, DateField, TimeField, PrimaryKeyField, ForeignKeyField) from peewee import Model as BaseModel ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1475/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1475/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1474
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1474/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1474/comments
https://api.github.com/repos/coleifer/peewee/issues/1474/events
https://github.com/coleifer/peewee/issues/1474
294,678,958
MDU6SXNzdWUyOTQ2Nzg5NTg=
1,474
`instance.save()` returns zero.
{ "login": "ShipraShalini", "id": 9088430, "node_id": "MDQ6VXNlcjkwODg0MzA=", "avatar_url": "https://avatars.githubusercontent.com/u/9088430?v=4", "gravatar_id": "", "url": "https://api.github.com/users/ShipraShalini", "html_url": "https://github.com/ShipraShalini", "followers_url": "https://api.github.com/users/ShipraShalini/followers", "following_url": "https://api.github.com/users/ShipraShalini/following{/other_user}", "gists_url": "https://api.github.com/users/ShipraShalini/gists{/gist_id}", "starred_url": "https://api.github.com/users/ShipraShalini/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/ShipraShalini/subscriptions", "organizations_url": "https://api.github.com/users/ShipraShalini/orgs", "repos_url": "https://api.github.com/users/ShipraShalini/repos", "events_url": "https://api.github.com/users/ShipraShalini/events{/privacy}", "received_events_url": "https://api.github.com/users/ShipraShalini/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Apologies. My mistake.\r\nChanging `AutoFloatField` to the following fixed it.\r\n\r\n```Python\r\nclass AutoFloatField(AutoField):\r\n\r\n def python_value(self, value):\r\n return value/10\r\n```\r\nBut with `PostgresqlExtDatabase` both `python_value` and `db_value` are required. :/" ]
2018-02-06T09:00:21
2018-02-06T14:26:46
2018-02-06T10:27:17
NONE
null
I am using `peewee` 3.0.8/3.0.13 and sqlite3 with [fabric](https://github.com/fabric/fabric/), to store build data. My model is: ```Python class AutoFloatField(AutoField): def db_value(self, value): return value * 10 def python_value(self, value): return value/10 class Build(BaseModel): id = AutoFloatField() deployed_by = CharField(null=True) started_at = DateTimeField(default=datetime.utcnow) finished_at = DateTimeField(null=True) success = BooleanField(default=False) ``` First I create the instance with `deployed_by` and `started_at`, ```Python instance = Build.create(deployed_by='abc') ``` then I update it with `finished_at` and `success`: ```Python instance.success = True instance.finished_at = datetime.utcnow() instance.save() ``` `model_to_dict` and `instance.dirty_fields` just before `.save()` returns: ``` { 'deployed_by': 'abc', 'finished_at': datetime.datetime(2018, 2, 6, 8, 47, 29, 313833), 'id': 10, 'started_at': datetime.datetime(2018, 2, 6, 8, 47, 11, 633645), 'success': True } [<peewee.DateTimeField object at 0x7f2d2e7dee10>, <peewee.BooleanField object at 0x7f2d2e7dedd0>] ``` But ` instance.save()` returns zero and the instance is not updated but `instance.dirty_fields` returns empty list. ` instance.save()` works fine in console.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1474/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1474/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1473
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1473/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1473/comments
https://api.github.com/repos/coleifer/peewee/issues/1473/events
https://github.com/coleifer/peewee/issues/1473
294,599,512
MDU6SXNzdWUyOTQ1OTk1MTI=
1,473
alias() not reflected in get()
{ "login": "rw102", "id": 9958815, "node_id": "MDQ6VXNlcjk5NTg4MTU=", "avatar_url": "https://avatars.githubusercontent.com/u/9958815?v=4", "gravatar_id": "", "url": "https://api.github.com/users/rw102", "html_url": "https://github.com/rw102", "followers_url": "https://api.github.com/users/rw102/followers", "following_url": "https://api.github.com/users/rw102/following{/other_user}", "gists_url": "https://api.github.com/users/rw102/gists{/gist_id}", "starred_url": "https://api.github.com/users/rw102/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/rw102/subscriptions", "organizations_url": "https://api.github.com/users/rw102/orgs", "repos_url": "https://api.github.com/users/rw102/repos", "events_url": "https://api.github.com/users/rw102/events{/privacy}", "received_events_url": "https://api.github.com/users/rw102/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Wrote a failing test, will work up a fix.", "Pushed a new release 3.0.13." ]
2018-02-06T01:18:53
2018-02-06T02:00:29
2018-02-06T01:56:24
NONE
null
`Table.select(Table.column.alias('alias')).where(Table.id == 1).dicts().get()` Until 3.0.2 this correctly returns : `{'alias' : value}` From 3.0.3 onwards, it returns : `{'column': value}` The same also happens when returning objects.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1473/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1473/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1472
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1472/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1472/comments
https://api.github.com/repos/coleifer/peewee/issues/1472/events
https://github.com/coleifer/peewee/issues/1472
294,582,817
MDU6SXNzdWUyOTQ1ODI4MTc=
1,472
A replacement for playhouse.shortcuts.RetryOperationalError?
{ "login": "cubranic", "id": 600891, "node_id": "MDQ6VXNlcjYwMDg5MQ==", "avatar_url": "https://avatars.githubusercontent.com/u/600891?v=4", "gravatar_id": "", "url": "https://api.github.com/users/cubranic", "html_url": "https://github.com/cubranic", "followers_url": "https://api.github.com/users/cubranic/followers", "following_url": "https://api.github.com/users/cubranic/following{/other_user}", "gists_url": "https://api.github.com/users/cubranic/gists{/gist_id}", "starred_url": "https://api.github.com/users/cubranic/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/cubranic/subscriptions", "organizations_url": "https://api.github.com/users/cubranic/orgs", "repos_url": "https://api.github.com/users/cubranic/repos", "events_url": "https://api.github.com/users/cubranic/events{/privacy}", "received_events_url": "https://api.github.com/users/cubranic/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "The code should work with a few modifications...the signature for `execute_sql()` is slightly different. `exception_wrapper` is now `__exception_wrapper__`. `get_cursor()` is just `cursor()`...\r\n\r\nYou'll have to experiment, but look at the way `execute_sql()` is implemented and I'm sure you can sort it out.", "Can you tell us why RetryOperationalError is removed? @coleifer ", "Removed as I have no intention of continuing to maintain it...also, it's my opinion that it's a gross hack.", "This should work if you have legacy code.\r\n\r\n```python\r\nfrom peewee import MySQLDatabase\r\nfrom peewee import OperationalError\r\n\r\n\r\nclass RetryOperationalError(object):\r\n\r\n def execute_sql(self, sql, params=None, commit=True):\r\n try:\r\n cursor = super(RetryOperationalError, self).execute_sql(\r\n sql, params, commit)\r\n except OperationalError:\r\n if not self.is_closed():\r\n self.close()\r\n with __exception_wrapper__:\r\n cursor = self.cursor()\r\n cursor.execute(sql, params or ())\r\n if commit and not self.in_transaction():\r\n self.commit()\r\n return cursor\r\n\r\n\r\nclass MyRetryDB(RetryOperationalError, MySQLDatabase):\r\n pass\r\n\r\n```", "Small note:\r\n\r\n``__exception_wrapper__`` should not have parentheses afterwards -- you don't need to call it. I went ahead and edited your code snippet to make the change.", "The work around seems to have broken. Was `self.__exception_wrapper__` renamed to something else, or removed entirely?\r\n", "Sorry, ``__exception_wrapper__`` is just at module scope.\r\n\r\nSo,\r\n\r\n```python\r\nimport peewee\r\n\r\nwith peewee.__exception_wrapper__:\r\n ...\r\n```" ]
2018-02-05T23:47:14
2018-09-29T04:06:41
2018-02-06T01:29:18
NONE
null
Commit 54a672547f549eb381cd9578a2b19310bcf5ef1d removed the class `playhouse.shortcuts.RetryOperationalError`. Is there a new recommended way to automatically reconnect and retry on failed queries?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1472/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1472/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1471
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1471/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1471/comments
https://api.github.com/repos/coleifer/peewee/issues/1471/events
https://github.com/coleifer/peewee/pull/1471
294,547,040
MDExOlB1bGxSZXF1ZXN0MTY3MjU4MjIx
1,471
Fix formatting and spelling issues
{ "login": "stenci", "id": 5955495, "node_id": "MDQ6VXNlcjU5NTU0OTU=", "avatar_url": "https://avatars.githubusercontent.com/u/5955495?v=4", "gravatar_id": "", "url": "https://api.github.com/users/stenci", "html_url": "https://github.com/stenci", "followers_url": "https://api.github.com/users/stenci/followers", "following_url": "https://api.github.com/users/stenci/following{/other_user}", "gists_url": "https://api.github.com/users/stenci/gists{/gist_id}", "starred_url": "https://api.github.com/users/stenci/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/stenci/subscriptions", "organizations_url": "https://api.github.com/users/stenci/orgs", "repos_url": "https://api.github.com/users/stenci/repos", "events_url": "https://api.github.com/users/stenci/events{/privacy}", "received_events_url": "https://api.github.com/users/stenci/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Danke" ]
2018-02-05T21:24:00
2018-02-05T21:27:04
2018-02-05T21:27:00
CONTRIBUTOR
null
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1471/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1471/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/1471", "html_url": "https://github.com/coleifer/peewee/pull/1471", "diff_url": "https://github.com/coleifer/peewee/pull/1471.diff", "patch_url": "https://github.com/coleifer/peewee/pull/1471.patch", "merged_at": "2018-02-05T21:27:00" }
https://api.github.com/repos/coleifer/peewee/issues/1470
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1470/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1470/comments
https://api.github.com/repos/coleifer/peewee/issues/1470/events
https://github.com/coleifer/peewee/issues/1470
294,484,420
MDU6SXNzdWUyOTQ0ODQ0MjA=
1,470
pwiz doesn't properly generate models for postgresql array columns
{ "login": "james-lawrence", "id": 2835871, "node_id": "MDQ6VXNlcjI4MzU4NzE=", "avatar_url": "https://avatars.githubusercontent.com/u/2835871?v=4", "gravatar_id": "", "url": "https://api.github.com/users/james-lawrence", "html_url": "https://github.com/james-lawrence", "followers_url": "https://api.github.com/users/james-lawrence/followers", "following_url": "https://api.github.com/users/james-lawrence/following{/other_user}", "gists_url": "https://api.github.com/users/james-lawrence/gists{/gist_id}", "starred_url": "https://api.github.com/users/james-lawrence/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/james-lawrence/subscriptions", "organizations_url": "https://api.github.com/users/james-lawrence/orgs", "repos_url": "https://api.github.com/users/james-lawrence/repos", "events_url": "https://api.github.com/users/james-lawrence/events{/privacy}", "received_events_url": "https://api.github.com/users/james-lawrence/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "This is a known limitation of the introspection tools. I'm not sure how to go from the OID returned by the cursor description to a suitable definition of an ArrayField object.", "then leave this issue open. =)\r\n\r\nside note: each array type has its own OID, you just need to map them:\r\nhere is an example list of OIDs pulled from https://github.com/jackc/pgx/blob/master/pgtype/pgtype.go,\r\nthere is a query you can run to pull the list from the DB as well.\r\n```\r\n\tBoolOID = 16\r\n\tByteaOID = 17\r\n\tCharOID = 18\r\n\tNameOID = 19\r\n\tInt8OID = 20\r\n\tInt2OID = 21\r\n\tInt4OID = 23\r\n\tTextOID = 25\r\n\tOIDOID = 26\r\n\tTIDOID = 27\r\n\tXIDOID = 28\r\n\tCIDOID = 29\r\n\tJSONOID = 114\r\n\tCIDROID = 650\r\n\tCIDRArrayOID = 651\r\n\tFloat4OID = 700\r\n\tFloat8OID = 701\r\n\tUnknownOID = 705\r\n\tInetOID = 869\r\n\tBoolArrayOID = 1000\r\n\tInt2ArrayOID = 1005\r\n\tInt4ArrayOID = 1007\r\n\tTextArrayOID = 1009\r\n\tByteaArrayOID = 1001\r\n\tBPCharArrayOID = 1014\r\n VarcharArrayOID = 1015\r\n```", "also if the problem is figuring out the OID of the table columns there is a query for that as well.", ":+1: ", "Support for arrayfield added in: c6b17b59cb491470b975c83ab23fd6e28311a4d2" ]
2018-02-05T17:52:40
2018-02-06T17:23:41
2018-02-06T17:23:29
CONTRIBUTOR
null
given a table with an text array column pwiz generates `UnknownField #ARRAY` instead of `ArrayField(TextField)`.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1470/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1470/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1469
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1469/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1469/comments
https://api.github.com/repos/coleifer/peewee/issues/1469/events
https://github.com/coleifer/peewee/issues/1469
294,472,140
MDU6SXNzdWUyOTQ0NzIxNDA=
1,469
Cannot nest select within insert in 3.0.11
{ "login": "tboz203", "id": 1491427, "node_id": "MDQ6VXNlcjE0OTE0Mjc=", "avatar_url": "https://avatars.githubusercontent.com/u/1491427?v=4", "gravatar_id": "", "url": "https://api.github.com/users/tboz203", "html_url": "https://github.com/tboz203", "followers_url": "https://api.github.com/users/tboz203/followers", "following_url": "https://api.github.com/users/tboz203/following{/other_user}", "gists_url": "https://api.github.com/users/tboz203/gists{/gist_id}", "starred_url": "https://api.github.com/users/tboz203/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/tboz203/subscriptions", "organizations_url": "https://api.github.com/users/tboz203/orgs", "repos_url": "https://api.github.com/users/tboz203/repos", "events_url": "https://api.github.com/users/tboz203/events{/privacy}", "received_events_url": "https://api.github.com/users/tboz203/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Committed 8131847467a7be0f44e22f5ceb64470bb8586f93, which fixes the issue. Thank you for reporting, I've also pushed version 3.0.12 to PyPI, which includes the fix.", "Fantastic! many thanks." ]
2018-02-05T17:13:51
2018-02-09T15:16:27
2018-02-05T19:31:10
NONE
null
Using python 3.5.1 (with pysqlite 2.6.0, sqlite 3.8.11) and peewee 3.0.11 Using an `INSERT` statement like the one below generates sql where the nested `SELECT` expression is not enclosed in parentheses: ```python query_id = Table.select(Table.id).where(Table.value == "whatever") Table.insert(id=query_id, value="whatever (improved!)").on_conflict_replace() ``` ```sql INSERT OR REPLACE INTO "Table" ("id", "value") VALUES (SELECT "Table"."id" FROM "Table" AS "Table" WHERE ("Table"."value" = 'whatever'), 'whatever (improved!)'); ``` The exception this throws is `peewee.OperationalError: near "SELECT": syntax error` Attaching a test script, with (lightly scrubbed) output. [peewee_insert_select_test.py.txt](https://github.com/coleifer/peewee/files/1696070/peewee_insert_select_test.py.txt) [output.txt](https://github.com/coleifer/peewee/files/1696063/output.txt)
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1469/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1469/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1468
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1468/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1468/comments
https://api.github.com/repos/coleifer/peewee/issues/1468/events
https://github.com/coleifer/peewee/issues/1468
294,417,107
MDU6SXNzdWUyOTQ0MTcxMDc=
1,468
Missing post_init from playhouse.signals
{ "login": "michael-ball", "id": 4253793, "node_id": "MDQ6VXNlcjQyNTM3OTM=", "avatar_url": "https://avatars.githubusercontent.com/u/4253793?v=4", "gravatar_id": "", "url": "https://api.github.com/users/michael-ball", "html_url": "https://github.com/michael-ball", "followers_url": "https://api.github.com/users/michael-ball/followers", "following_url": "https://api.github.com/users/michael-ball/following{/other_user}", "gists_url": "https://api.github.com/users/michael-ball/gists{/gist_id}", "starred_url": "https://api.github.com/users/michael-ball/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/michael-ball/subscriptions", "organizations_url": "https://api.github.com/users/michael-ball/orgs", "repos_url": "https://api.github.com/users/michael-ball/repos", "events_url": "https://api.github.com/users/michael-ball/events{/privacy}", "received_events_url": "https://api.github.com/users/michael-ball/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Ahhh...I believe you're right. Let me look.", "Yeah, that's no longer provided. Updated the docs and pushed a commit." ]
2018-02-05T14:44:45
2018-02-05T14:51:58
2018-02-05T14:51:54
NONE
null
It looks like the post_init signal is no longer defined in playhouse.signals. Is this intentional?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1468/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1468/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1467
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1467/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1467/comments
https://api.github.com/repos/coleifer/peewee/issues/1467/events
https://github.com/coleifer/peewee/issues/1467
294,166,497
MDU6SXNzdWUyOTQxNjY0OTc=
1,467
Document peewee 3 change of `register_fields`.
{ "login": "kdart", "id": 33999, "node_id": "MDQ6VXNlcjMzOTk5", "avatar_url": "https://avatars.githubusercontent.com/u/33999?v=4", "gravatar_id": "", "url": "https://api.github.com/users/kdart", "html_url": "https://github.com/kdart", "followers_url": "https://api.github.com/users/kdart/followers", "following_url": "https://api.github.com/users/kdart/following{/other_user}", "gists_url": "https://api.github.com/users/kdart/gists{/gist_id}", "starred_url": "https://api.github.com/users/kdart/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/kdart/subscriptions", "organizations_url": "https://api.github.com/users/kdart/orgs", "repos_url": "https://api.github.com/users/kdart/repos", "events_url": "https://api.github.com/users/kdart/events{/privacy}", "received_events_url": "https://api.github.com/users/kdart/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "It looks like you now pass in the `field_types` keyword argument when first creating the database. Is that right? ", "Trying the above might work, but now I'm seeing the following when trying to import my models.\r\n\r\n # OUT: Traceback (most recent call last):\r\n # OUT: File \"<input>\", line 1, in <module>\r\n # OUT: from devtest.db import models\r\n # OUT: File \"/home/keith/src/devtest/devtest/db/models.py\", line 81, in <module>\r\n # OUT: class EquipmentModel(BaseModel):\r\n # OUT: File \"/usr/local/lib/python3.6/site-packages/peewee.py\", line 4888, in __new__\r\n # OUT: cls._meta.add_field(name, field)\r\n # OUT: File \"/usr/local/lib/python3.6/site-packages/peewee.py\", line 4689, in add_field\r\n # OUT: field.bind(self.model, field_name, set_attribute)\r\n # OUT: File \"/usr/local/lib/python3.6/site-packages/peewee.py\", line 3750, in bind\r\n # OUT: self._constructor = model._meta.database.get_binary_type()\r\n # OUT: File \"/usr/local/lib/python3.6/site-packages/peewee.py\", line 388, in __getattr__\r\n # OUT: raise AttributeError('Cannot use uninitialized Proxy.')\r\n # OUT: AttributeError: Cannot use uninitialized Proxy.\r\n", "Thanks for reporting. What kind of special field-types are you trying to register?\r\n\r\nIt looks like that traceback you posted is a result of a `BlobField` trying to interrogate the database object for it's \"binary_type\". Since the db isn't initialized, the lookup fails. Let me see about a fix.\r\n\r\nRegarding custom field types, yep, you pass a dict mapping field type to db-specific data-type.", "You might try this commit: 32d9ca7787e8634aba63f216bb7993160f34fc51", "I've pushed a new release, 3.0.11, if you're interested.", "Thanks! I have custom fields for Postgres, some map to `inet`, `cidr`, and `macaddr` special fields. ", "In case you're interested in the custom fields:\r\n\r\nhttps://github.com/kdart/devtest/blob/master/devtest/db/fields.py\r\n\r\n", "Kool, thanks for sharing!", "Hi! \r\n\r\nCould you please share how-to declare a `cidr` field in a peewee model ?\r\n\r\nBTW, the link above handles only IPv4 networks if I am not mistaken.", "Probably depends on your database driver. Postgres has a native data-type for CIDR network. You could probably use an integer column and the Python 3 `ipaddress` module:\r\n\r\n```python\r\nimport ipaddress\r\nnet = ipaddress.ip_network('192.168.1.0/28')\r\nnetmask = net.netmask\r\nfour_bytes = netmask.packed\r\nto_int = struct.unpack('!I', four_bytes)[0]\r\n```", "actually I was wondering if there is sth similar to `JSONField`, `ArrayField`, etc. that I could use in the case of type `CIDR`:\r\n\r\n```\r\nfrom peewee import *\r\nfrom playhouse.postgres_ext import PostgresqlExtDatabase, ArrayField, JSONField\r\nimport psycopg2\r\nimport psycopg2.extras\r\n\r\nclass Interconnect(BaseModel):\r\n as_set = ArrayField(field_class=TextField)\r\n pulse = JSONField(null=True)\r\n prefix = CIDRField()\r\n ...\r\n```\r\n\r\nwhere `prefix` in PostgreSQL is defined already as:\r\n```\r\n prefix CIDR NOT NULL,\r\n```", "@coleifer I just upgraded to peewee 3 and don't see documentation for the missing `register_fields` and `register_ops`. Could some documentation be added on how to proceed? I believe, as kdart mentioned, that there is no classmethod anymore, but we can use `field_types` and `register_function` on the instance. Is that right?", "You don't need to register anything anymore.\r\n\r\n```python\r\nclass MyMagicalField(Field):\r\n field_type = 'column_data_type'\r\n\r\n def special_field_expression(self, value):\r\n return Expression(self, 'operator', value)\r\n```" ]
2018-02-04T03:31:22
2019-02-22T22:04:03
2018-02-04T18:48:01
NONE
null
I'm just getting around to updating my project to use peewee 3. I got most of what is in the differences page, but it doesn't mention `register_fields` class method of PostgresExtDatabase is also now missing. How should I handle that?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1467/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1467/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1466
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1466/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1466/comments
https://api.github.com/repos/coleifer/peewee/issues/1466/events
https://github.com/coleifer/peewee/issues/1466
294,138,153
MDU6SXNzdWUyOTQxMzgxNTM=
1,466
Pylint: "No value for argument 'database' in method call" on count() call
{ "login": "mikekeda", "id": 4765088, "node_id": "MDQ6VXNlcjQ3NjUwODg=", "avatar_url": "https://avatars.githubusercontent.com/u/4765088?v=4", "gravatar_id": "", "url": "https://api.github.com/users/mikekeda", "html_url": "https://github.com/mikekeda", "followers_url": "https://api.github.com/users/mikekeda/followers", "following_url": "https://api.github.com/users/mikekeda/following{/other_user}", "gists_url": "https://api.github.com/users/mikekeda/gists{/gist_id}", "starred_url": "https://api.github.com/users/mikekeda/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/mikekeda/subscriptions", "organizations_url": "https://api.github.com/users/mikekeda/orgs", "repos_url": "https://api.github.com/users/mikekeda/repos", "events_url": "https://api.github.com/users/mikekeda/events{/privacy}", "received_events_url": "https://api.github.com/users/mikekeda/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "This is python, a dynamic language. The linter is, quite simply, wrong. Not fixing because there's no bug here. Just silly tools." ]
2018-02-03T19:26:05
2018-02-04T00:07:35
2018-02-04T00:07:35
NONE
null
In my code I have `User.select().count()`, after upgrading Peewee from 2.10.2 to 3.0.10 I'm getting pylint error: > [E1120(no-value-for-parameter), users_page] No value for argument 'database' in method call Can we add default value None for database in count method? ``` @database_required def count(self, database=None, clear_limit=False): ``` https://github.com/coleifer/peewee/blob/master/peewee.py#L1695 P.S. As I see a lot of methods now have `database` argument with `@database_required` decorator, so there will be pylint errors too. P.P.S `count()` can be called as `User.select().count(None)` without Pylint error, this issue can be closed.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1466/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1466/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1465
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1465/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1465/comments
https://api.github.com/repos/coleifer/peewee/issues/1465/events
https://github.com/coleifer/peewee/pull/1465
294,038,506
MDExOlB1bGxSZXF1ZXN0MTY2OTE0ODMy
1,465
Fix not_in with empty list
{ "login": "aconz2", "id": 3137597, "node_id": "MDQ6VXNlcjMxMzc1OTc=", "avatar_url": "https://avatars.githubusercontent.com/u/3137597?v=4", "gravatar_id": "", "url": "https://api.github.com/users/aconz2", "html_url": "https://github.com/aconz2", "followers_url": "https://api.github.com/users/aconz2/followers", "following_url": "https://api.github.com/users/aconz2/following{/other_user}", "gists_url": "https://api.github.com/users/aconz2/gists{/gist_id}", "starred_url": "https://api.github.com/users/aconz2/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/aconz2/subscriptions", "organizations_url": "https://api.github.com/users/aconz2/orgs", "repos_url": "https://api.github.com/users/aconz2/repos", "events_url": "https://api.github.com/users/aconz2/events{/privacy}", "received_events_url": "https://api.github.com/users/aconz2/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Postgresql treats `IN ()` (and incidentally `NOT IN ()`) as invalid SQL expressions. Because the semantics of `IN ()` are equivalent to false, Peewee replaces `IN ()` with `1 = 0`. I suppose it should do similar rewriting for `NOT IN ()`, converting it to `1 = 1` since it is always true.\r\n\r\nThat being said, it seems like the proposed change may be correct.", "Replaced your patch with bc61d3fa515c462cb86714e00ffdf728121a90f7 -- which handles the IN/NOT IN special-case correctly. I **did**, however, choose to keep your changes to `NodeList.__sql__` as I think they're semantically correct." ]
2018-02-02T22:08:17
2018-02-02T22:42:29
2018-02-02T22:34:51
CONTRIBUTOR
null
Using `not_in` with an empty list produces malformed SQL ```python import peewee from peewee import * class MyBase(Model): class Meta: database = SqliteDatabase(':memory:') class Foo(MyBase): name = CharField() print(peewee.__version__) print(Foo.select().where(Foo.name.not_in([])).sql()) ``` ``` 2.10.2 ('SELECT "t1"."id", "t1"."name" FROM "foo" AS t1 WHERE ("t1"."name" NOT IN ())', []) ``` ``` 3.0.10 ('SELECT "t1"."id", "t1"."name" FROM "foo" AS "t1" WHERE ("t1"."name" NOT IN )', []) ``` I think (?) that is the right fix. And added a new test to cover it
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1465/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1465/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/1465", "html_url": "https://github.com/coleifer/peewee/pull/1465", "diff_url": "https://github.com/coleifer/peewee/pull/1465.diff", "patch_url": "https://github.com/coleifer/peewee/pull/1465.patch", "merged_at": null }
https://api.github.com/repos/coleifer/peewee/issues/1464
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1464/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1464/comments
https://api.github.com/repos/coleifer/peewee/issues/1464/events
https://github.com/coleifer/peewee/issues/1464
293,955,150
MDU6SXNzdWUyOTM5NTUxNTA=
1,464
Database.get_cursor missed in 3.X version
{ "login": "vikt0rs", "id": 5230490, "node_id": "MDQ6VXNlcjUyMzA0OTA=", "avatar_url": "https://avatars.githubusercontent.com/u/5230490?v=4", "gravatar_id": "", "url": "https://api.github.com/users/vikt0rs", "html_url": "https://github.com/vikt0rs", "followers_url": "https://api.github.com/users/vikt0rs/followers", "following_url": "https://api.github.com/users/vikt0rs/following{/other_user}", "gists_url": "https://api.github.com/users/vikt0rs/gists{/gist_id}", "starred_url": "https://api.github.com/users/vikt0rs/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/vikt0rs/subscriptions", "organizations_url": "https://api.github.com/users/vikt0rs/orgs", "repos_url": "https://api.github.com/users/vikt0rs/repos", "events_url": "https://api.github.com/users/vikt0rs/events{/privacy}", "received_events_url": "https://api.github.com/users/vikt0rs/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "It's `Database.cursor()` now. Updated docs to reflect this." ]
2018-02-02T16:57:00
2018-02-02T18:14:32
2018-02-02T18:14:21
NONE
null
Class Database has a "get_cursor" method in peewee 2.X versions, see [0] for example. But for some reason, it missed in 3.X versions. Documentation and changelog say nothing about this change. Please, suggest. Thanks! [0] - https://github.com/coleifer/peewee/blob/2.10.2/peewee.py#L3773
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1464/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1464/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1463
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1463/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1463/comments
https://api.github.com/repos/coleifer/peewee/issues/1463/events
https://github.com/coleifer/peewee/pull/1463
293,893,552
MDExOlB1bGxSZXF1ZXN0MTY2ODA2MzEx
1,463
Pass kwargs through Function decorator. Fixes #1462
{ "login": "Karel-van-de-Plassche", "id": 6404167, "node_id": "MDQ6VXNlcjY0MDQxNjc=", "avatar_url": "https://avatars.githubusercontent.com/u/6404167?v=4", "gravatar_id": "", "url": "https://api.github.com/users/Karel-van-de-Plassche", "html_url": "https://github.com/Karel-van-de-Plassche", "followers_url": "https://api.github.com/users/Karel-van-de-Plassche/followers", "following_url": "https://api.github.com/users/Karel-van-de-Plassche/following{/other_user}", "gists_url": "https://api.github.com/users/Karel-van-de-Plassche/gists{/gist_id}", "starred_url": "https://api.github.com/users/Karel-van-de-Plassche/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/Karel-van-de-Plassche/subscriptions", "organizations_url": "https://api.github.com/users/Karel-van-de-Plassche/orgs", "repos_url": "https://api.github.com/users/Karel-van-de-Plassche/repos", "events_url": "https://api.github.com/users/Karel-van-de-Plassche/events{/privacy}", "received_events_url": "https://api.github.com/users/Karel-van-de-Plassche/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I've restricted the kwargs to just \"coerce\" and merged a similar patch. Thank you for pointing this out: 51cb6bdc25f62916fbc1f9bc471f1a1bccc1a7da" ]
2018-02-02T13:47:24
2018-02-02T14:32:36
2018-02-02T14:32:36
NONE
null
This enables the user to do for example ``` python fn.ARRAY_AGG(Some.thing, coerce=False) ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1463/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1463/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/1463", "html_url": "https://github.com/coleifer/peewee/pull/1463", "diff_url": "https://github.com/coleifer/peewee/pull/1463.diff", "patch_url": "https://github.com/coleifer/peewee/pull/1463.patch", "merged_at": null }
https://api.github.com/repos/coleifer/peewee/issues/1462
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1462/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1462/comments
https://api.github.com/repos/coleifer/peewee/issues/1462/events
https://github.com/coleifer/peewee/issues/1462
293,870,679
MDU6SXNzdWUyOTM4NzA2Nzk=
1,462
fn.ARRAY_AGG in select query tries to re-cast result
{ "login": "Karel-van-de-Plassche", "id": 6404167, "node_id": "MDQ6VXNlcjY0MDQxNjc=", "avatar_url": "https://avatars.githubusercontent.com/u/6404167?v=4", "gravatar_id": "", "url": "https://api.github.com/users/Karel-van-de-Plassche", "html_url": "https://github.com/Karel-van-de-Plassche", "followers_url": "https://api.github.com/users/Karel-van-de-Plassche/followers", "following_url": "https://api.github.com/users/Karel-van-de-Plassche/following{/other_user}", "gists_url": "https://api.github.com/users/Karel-van-de-Plassche/gists{/gist_id}", "starred_url": "https://api.github.com/users/Karel-van-de-Plassche/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/Karel-van-de-Plassche/subscriptions", "organizations_url": "https://api.github.com/users/Karel-van-de-Plassche/orgs", "repos_url": "https://api.github.com/users/Karel-van-de-Plassche/repos", "events_url": "https://api.github.com/users/Karel-van-de-Plassche/events{/privacy}", "received_events_url": "https://api.github.com/users/Karel-van-de-Plassche/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Specify ``coerce=False`` in the call to the function.\r\n\r\n```python\r\nfn.ARRAY_AGG(Some.thing, coerce=False)\r\n```\r\n\r\nhttp://docs.peewee-orm.com/en/latest/peewee/api.html#Function" ]
2018-02-02T12:20:10
2018-02-02T13:34:14
2018-02-02T13:34:14
NONE
null
The `ARRAY_AGG` function combines the result of multiple row in a single ArrayField. Peewee doesn't expect that and tries to re-cast to the original field type. For example: ``` python Network.select(fn.ARRAY_AGG(Network.id)).get() ``` Which returns a int[] in PostgreSQL, but peewee tries to recast to int ``` python --------------------------------------------------------------------------- TypeError Traceback (most recent call last) ~/working/QLKNN-develop/NNDB/model.py in <module>() ----> 1 Network.select(fn.ARRAY_AGG(Network.id).alias('wut')).get() ~/working/peewee/peewee.py in get(self) 5429 clone._cursor_wrapper = None 5430 try: -> 5431 return clone.execute()[0] 5432 except IndexError: 5433 sql, params = clone.sql() ~/working/peewee/peewee.py in __getitem__(self, item) 3338 return self.row_cache[item] 3339 elif isinstance(item, int): -> 3340 self.fill_cache(item if item > 0 else 0) 3341 return self.row_cache[item] 3342 else: ~/working/peewee/peewee.py in fill_cache(self, n) 3383 while not self.populated and (n > self.count): 3384 try: -> 3385 iterator.next() 3386 except StopIteration: 3387 break ~/working/peewee/peewee.py in next(self) 3439 obj = self.cursor_wrapper.row_cache[self.index] 3440 elif not self.cursor_wrapper.populated: -> 3441 self.cursor_wrapper.iterate() 3442 obj = self.cursor_wrapper.row_cache[self.index] 3443 else: ~/working/peewee/peewee.py in iterate(self, cache) 3361 self.initialized = True 3362 self.count += 1 -> 3363 result = self.process_row(row) 3364 if cache: 3365 self.row_cache.append(result) ~/working/peewee/peewee.py in process_row(self, row) 5913 5914 def process_row(self, row): -> 5915 data = super(ModelObjectCursorWrapper, self).process_row(row) 5916 if self.is_model: 5917 # Clear out any dirty fields before returning to the user. ~/working/peewee/peewee.py in process_row(self, row) 5876 attr = fields[i].name if fields[i] is not None else columns[i] 5877 if converters[i] is not None: -> 5878 result[attr] = converters[i](row[i]) 5879 else: 5880 result[attr] = row[i] ~/working/peewee/peewee.py in python_value(self, value) 3588 3589 def python_value(self, value): -> 3590 return value if value is None else self.coerce(value) 3591 3592 def get_sort_key(self, ctx): TypeError: int() argument must be a string, a bytes-like object or a number, not 'list' ``` Can this be worked around (for example by using the equivalent of `AsIs`) or fixed?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1462/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1462/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1461
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1461/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1461/comments
https://api.github.com/repos/coleifer/peewee/issues/1461/events
https://github.com/coleifer/peewee/issues/1461
293,865,143
MDU6SXNzdWUyOTM4NjUxNDM=
1,461
Equality check on postgreSQL ArrayField clarification
{ "login": "Karel-van-de-Plassche", "id": 6404167, "node_id": "MDQ6VXNlcjY0MDQxNjc=", "avatar_url": "https://avatars.githubusercontent.com/u/6404167?v=4", "gravatar_id": "", "url": "https://api.github.com/users/Karel-van-de-Plassche", "html_url": "https://github.com/Karel-van-de-Plassche", "followers_url": "https://api.github.com/users/Karel-van-de-Plassche/followers", "following_url": "https://api.github.com/users/Karel-van-de-Plassche/following{/other_user}", "gists_url": "https://api.github.com/users/Karel-van-de-Plassche/gists{/gist_id}", "starred_url": "https://api.github.com/users/Karel-van-de-Plassche/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/Karel-van-de-Plassche/subscriptions", "organizations_url": "https://api.github.com/users/Karel-van-de-Plassche/orgs", "repos_url": "https://api.github.com/users/Karel-van-de-Plassche/repos", "events_url": "https://api.github.com/users/Karel-van-de-Plassche/events{/privacy}", "received_events_url": "https://api.github.com/users/Karel-van-de-Plassche/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "> Isn't it possible for peewee to detect a PostgreSQL ArrayField is involved, and thus the operands should not be unpacked?\r\n\r\nWhat behavior are you seeing in relation to ArrayField?", "I get:\r\n``` python\r\nIn [1]: Network.target_names.__class__\r\nOut[1]: playhouse.postgres_ext.ArrayField\r\n\r\nIn [2]: Network.select().where(Network.target_names == ['efeITG_GB']).sql()\r\nOut[2]:\r\n('SELECT \"t1\".\"id\", \"t1\".\"filter_id\", \"t1\".\"train_script_id\", \"t1\".\"feature_prescale_bias\", \"t1\".\"feature_prescale_factor\", \"t1\".\"target_prescale_bias\", \"t1\".\"target_prescale_factor\", \"t1\".\"feature_names\", \"t1\".\"feature_min\", \"t1\".\"feature_max\", \"t1\".\"target_names\", \"t1\".\"target_min\", \"t1\".\"target_max\", \"t1\".\"timestamp\" FROM \"develop\".\"network\" AS \"t1\" WHERE (\"t1\".\"target_names\" = (%s))',\r\n [['e', 'f', 'e', 'I', 'T', 'G', '_', 'G', 'B']])\r\n```\r\nWhere I would expect the SQL as generated by the mentioned workaround:\r\n``` python\r\nIn [4]: Network.select().where(Network.target_names == AsIs(['efeITG_GB'])).sql()\r\nOut[4]:\r\n('SELECT \"t1\".\"id\", \"t1\".\"filter_id\", \"t1\".\"train_script_id\", \"t1\".\"feature_prescale_bias\", \"t1\".\"feature_prescale_factor\", \"t1\".\"target_prescale_bias\", \"t1\".\"target_prescale_factor\", \"t1\".\"feature_names\", \"t1\".\"feature_min\", \"t1\".\"feature_max\", \"t1\".\"target_names\", \"t1\".\"target_min\", \"t1\".\"target_max\", \"t1\".\"timestamp\" FROM \"develop\".\"network\" AS \"t1\" WHERE (\"t1\".\"target_names\" = %s)',\r\n [['efeITG_GB']])\r\n```\r\nI'm not sure if this should be natively handled by peewee, but I think equality check with an ArrayField is a common thing to do.", "Postgresql array equality is fixed in 4a14174 (and inequality/gt/lt/ge/le).", "More commonly, though, folks use the containment operators when working with arrays. So this hasn't really come up before.", "Thanks! I did not notice this in the howto's/guides, but to be honest it has been a while since I read them thoroughly." ]
2018-02-02T11:57:24
2018-02-02T16:08:54
2018-02-02T15:41:08
NONE
null
Continuation of https://github.com/coleifer/peewee/issues/1311 > When doing a SELECT, peewee doesn't know if the list you are passing should be unpacked (as it would for an IN query, for example). To work around, when passing lists in this situation you should wrap it in Param: Isn't it possible for peewee to detect a PostgreSQL ArrayField is involved, and thus the operands should not be unpacked? This would give a more consistent user experience. Alternatively, maybe it's good to document this workaround somewhere (or include it in the unit tests, as that is a place people will look for examples)
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1461/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1461/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1460
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1460/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1460/comments
https://api.github.com/repos/coleifer/peewee/issues/1460/events
https://github.com/coleifer/peewee/issues/1460
293,862,144
MDU6SXNzdWUyOTM4NjIxNDQ=
1,460
count() on ModelCompoundSelectQuery raises error
{ "login": "Karel-van-de-Plassche", "id": 6404167, "node_id": "MDQ6VXNlcjY0MDQxNjc=", "avatar_url": "https://avatars.githubusercontent.com/u/6404167?v=4", "gravatar_id": "", "url": "https://api.github.com/users/Karel-van-de-Plassche", "html_url": "https://github.com/Karel-van-de-Plassche", "followers_url": "https://api.github.com/users/Karel-van-de-Plassche/followers", "following_url": "https://api.github.com/users/Karel-van-de-Plassche/following{/other_user}", "gists_url": "https://api.github.com/users/Karel-van-de-Plassche/gists{/gist_id}", "starred_url": "https://api.github.com/users/Karel-van-de-Plassche/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/Karel-van-de-Plassche/subscriptions", "organizations_url": "https://api.github.com/users/Karel-van-de-Plassche/orgs", "repos_url": "https://api.github.com/users/Karel-van-de-Plassche/repos", "events_url": "https://api.github.com/users/Karel-van-de-Plassche/events{/privacy}", "received_events_url": "https://api.github.com/users/Karel-van-de-Plassche/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Ahhh, interesting. Will get this fixed.", "Fixed and added a test-case." ]
2018-02-02T11:45:22
2018-02-02T13:25:41
2018-02-02T13:25:34
NONE
null
I'm rewriting code from 2.10.1 to 3.0.9. One used to be able to do a .count() on a combined query, but now it raises an `AttributeError`. For example: ``` python (Network.select().where(Network.id == 301) | Network.select().where(Network.id == 300)).count() ``` ``` python ~/working/peewee/peewee.py in inner(self, database, *args, **kwargs) 1440 raise Exception('Query must be bound to a database in order ' 1441 'to call "%s".' % method.__name__) -> 1442 return method(self, database, *args, **kwargs) 1443 return inner 1444 ~/working/peewee/peewee.py in count(self, database, clear_limit) 1695 clone._limit = clone._offset = None 1696 try: -> 1697 if clone._having is None and clone._windows is None and \ 1698 clone._distinct is None and clone._simple_distinct is not True: 1699 clone = clone.select(SQL('1')) AttributeError: 'ModelCompoundSelectQuery' object has no attribute '_having' ``` A working workaround is to wrap the offending boolean check in a `try: except:` clause, but I suppose the `CompoundSelectQuery` class should just initialize these attributes, as I feel it should call the initializer from `Select`. PS. This works without issues: ``` python len(Network.select().where(Network.id == 301) | Network.select().where(Network.id == 300)) ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1460/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1460/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1459
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1459/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1459/comments
https://api.github.com/repos/coleifer/peewee/issues/1459/events
https://github.com/coleifer/peewee/pull/1459
293,839,582
MDExOlB1bGxSZXF1ZXN0MTY2NzY1NDU5
1,459
Fixed unsaved relation population
{ "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
[ "Very nice! Thank you and apologies for the oversight." ]
2018-02-02T10:22:17
2018-02-02T13:13:04
2018-02-02T13:12:53
CONTRIBUTOR
null
Fixes #1457 1) The keys in the respective dicts is the foreign key's name, not the field itself. 2) According to `ForeignKeyAccessor.__set__`, foreign key fields are never marked as dirty.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1459/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1459/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/1459", "html_url": "https://github.com/coleifer/peewee/pull/1459", "diff_url": "https://github.com/coleifer/peewee/pull/1459.diff", "patch_url": "https://github.com/coleifer/peewee/pull/1459.patch", "merged_at": "2018-02-02T13:12:53" }
https://api.github.com/repos/coleifer/peewee/issues/1458
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1458/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1458/comments
https://api.github.com/repos/coleifer/peewee/issues/1458/events
https://github.com/coleifer/peewee/issues/1458
293,814,247
MDU6SXNzdWUyOTM4MTQyNDc=
1,458
Orphaned code in peewee-3.0
{ "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
[ "Yipes, I was scared for a sec that I had a glaring gap in the tests. Looking closer I think the `ForeignKeyAccessor` should handle setting the value so that this code is, indeed, dead. But for now I've simply updated the method to \".get_id()\", which is the correct name." ]
2018-02-02T08:50:12
2018-02-02T13:10:24
2018-02-02T13:10:24
CONTRIBUTOR
null
While debugging some problems with peewee-3.0 I discovered some strange code, e.g. https://github.com/coleifer/peewee/blob/406eb5865d72f1c74f48abd67bb8f4c9ccc1391a/peewee.py#L4095 The `_get_pk_value()` method was part of peewee < 3.0, but is no longer defined on peewee-3.0's `Model`. Heck, it isn't even defined anywhere in `peewee.py`. Is this orphaned code or am I missing something?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1458/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1458/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1457
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1457/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1457/comments
https://api.github.com/repos/coleifer/peewee/issues/1457/events
https://github.com/coleifer/peewee/issues/1457
293,812,791
MDU6SXNzdWUyOTM4MTI3OTE=
1,457
Setting of models onto foreign key fields yields NULL value
{ "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
[ "Okay, I think I understand the error now.\r\n\r\nAssuming:\r\n\r\n class Parent(Model):\r\n pass\r\n\r\n class Child(Model):\r\n mom = ForeignKeyField(Parent)\r\n dad = ForeignKeyField(Parent)\r\n\r\nIn peewee < 3.0 it was possible to do this:\r\n\r\n mom = Parent()\r\n dad = Parent()\r\n daughter = Child()\r\n daughter.mom = mom # (1)\r\n daughter.dad = dad # (2)\r\n\r\n for model in (mom, dad, daughter):\r\n model.save()\r\n\r\nThis will not work in peewee 3.0 any longer, since in `(1)` and `(2)` the respective `ForeignKeyAccessor` will immediately add the not yet set primary key of `mom` resp. `dad` to `daughter.__data__['mom']` resp. `daughter.__data__['dad']` as per https://github.com/coleifer/peewee/blob/406eb5865d72f1c74f48abd67bb8f4c9ccc1391a/peewee.py#L3490\r\n\r\nCan you fix this to allow deferring of saving the models (and thus assigning foreign keys)?\r\n\r\nMaybe you could check for `instance.__rel__[self.name]._pk` if and only if `instance.__data__[self.name]` is None on `Model.save()`?\r\n\r\nBecause this totally breaks my workflow. :(", "Thanks for the patch. Added a test to help prevent regressions." ]
2018-02-02T08:44:21
2018-02-02T13:16:44
2018-02-02T13:12:53
CONTRIBUTOR
null
I have a strange problem with the new peewee-3.0. When I set a model instance onto a `ForeignKeyField` descriptor of another model instance and try to save the latter model, I get the an error. Debug code in question (excerpt): for model in record: try: model.save() except: print('Data:', model.__data__) print('Rel:', model.__rel__) print('Model.immobilie:', model.immobilie) print('Model.immobilie.id:', model.immobilie.id) print(format_exc(), flush=True) raise Output: Data: {'immobilie': None, 'klasse': 'wohnung', 'typ': 'DACHGESCHOSS'} Rel: {'immobilie': <openimmodb.Immobilie object at 0x7f9d63fd8710>} Model.immobilie: <openimmodb.Immobilie object at 0x7f9d63fd8710> Model.immobilie.id: 276731 Traceback (most recent call last): File "/usr/local/lib/python3.4/dist-packages/peewee.py", line 2475, in execute_sql cursor.execute(sql, params or ()) File "/usr/local/lib/python3.4/dist-packages/pymysql/cursors.py", line 165, in execute result = self._query(query) File "/usr/local/lib/python3.4/dist-packages/pymysql/cursors.py", line 321, in _query conn.query(q) File "/usr/local/lib/python3.4/dist-packages/pymysql/connections.py", line 860, in query self._affected_rows = self._read_query_result(unbuffered=unbuffered) File "/usr/local/lib/python3.4/dist-packages/pymysql/connections.py", line 1061, in _read_query_result result.read() File "/usr/local/lib/python3.4/dist-packages/pymysql/connections.py", line 1349, in read first_packet = self.connection._read_packet() File "/usr/local/lib/python3.4/dist-packages/pymysql/connections.py", line 1018, in _read_packet packet.check_error() File "/usr/local/lib/python3.4/dist-packages/pymysql/connections.py", line 384, in check_error err.raise_mysql_exception(self._data) File "/usr/local/lib/python3.4/dist-packages/pymysql/err.py", line 107, in raise_mysql_exception raise errorclass(errno, errval) pymysql.err.IntegrityError: (1048, "Column 'immobilie' cannot be null") During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/local/lib/python3.4/dist-packages/homie/mods/oidb/interface.py", line 74, in update model.save() File "/usr/local/lib/python3.4/dist-packages/peewee.py", line 5154, in save pk_from_cursor = self.insert(**field_dict).execute() File "/usr/local/lib/python3.4/dist-packages/peewee.py", line 1442, in inner return method(self, database, *args, **kwargs) File "/usr/local/lib/python3.4/dist-packages/peewee.py", line 1513, in execute return self._execute(database) File "/usr/local/lib/python3.4/dist-packages/peewee.py", line 2142, in _execute return super(Insert, self)._execute(database) File "/usr/local/lib/python3.4/dist-packages/peewee.py", line 1920, in _execute cursor = database.execute(self) File "/usr/local/lib/python3.4/dist-packages/peewee.py", line 2488, in execute return self.execute_sql(sql, params, commit=commit) File "/usr/local/lib/python3.4/dist-packages/peeweeplus/database.py", line 22, in execute_sql return super().execute_sql(*args, **kwargs) File "/usr/local/lib/python3.4/dist-packages/peewee.py", line 2482, in execute_sql self.commit() File "/usr/local/lib/python3.4/dist-packages/peewee.py", line 2278, in __exit__ reraise(new_type, new_type(*exc_args), traceback) File "/usr/local/lib/python3.4/dist-packages/peewee.py", line 169, in reraise raise value.with_traceback(tb) File "/usr/local/lib/python3.4/dist-packages/peewee.py", line 2475, in execute_sql cursor.execute(sql, params or ()) File "/usr/local/lib/python3.4/dist-packages/pymysql/cursors.py", line 165, in execute result = self._query(query) File "/usr/local/lib/python3.4/dist-packages/pymysql/cursors.py", line 321, in _query conn.query(q) File "/usr/local/lib/python3.4/dist-packages/pymysql/connections.py", line 860, in query self._affected_rows = self._read_query_result(unbuffered=unbuffered) File "/usr/local/lib/python3.4/dist-packages/pymysql/connections.py", line 1061, in _read_query_result result.read() File "/usr/local/lib/python3.4/dist-packages/pymysql/connections.py", line 1349, in read first_packet = self.connection._read_packet() File "/usr/local/lib/python3.4/dist-packages/pymysql/connections.py", line 1018, in _read_packet packet.check_error() File "/usr/local/lib/python3.4/dist-packages/pymysql/connections.py", line 384, in check_error err.raise_mysql_exception(self._data) File "/usr/local/lib/python3.4/dist-packages/pymysql/err.py", line 107, in raise_mysql_exception raise errorclass(errno, errval) peewee.IntegrityError: (1048, "Column 'immobilie' cannot be null") What is the problem here?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1457/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1457/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1456
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1456/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1456/comments
https://api.github.com/repos/coleifer/peewee/issues/1456/events
https://github.com/coleifer/peewee/issues/1456
293,810,077
MDU6SXNzdWUyOTM4MTAwNzc=
1,456
Allow updating existing model via dict_to_model
{ "login": "tuukkamustonen", "id": 94327, "node_id": "MDQ6VXNlcjk0MzI3", "avatar_url": "https://avatars.githubusercontent.com/u/94327?v=4", "gravatar_id": "", "url": "https://api.github.com/users/tuukkamustonen", "html_url": "https://github.com/tuukkamustonen", "followers_url": "https://api.github.com/users/tuukkamustonen/followers", "following_url": "https://api.github.com/users/tuukkamustonen/following{/other_user}", "gists_url": "https://api.github.com/users/tuukkamustonen/gists{/gist_id}", "starred_url": "https://api.github.com/users/tuukkamustonen/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/tuukkamustonen/subscriptions", "organizations_url": "https://api.github.com/users/tuukkamustonen/orgs", "repos_url": "https://api.github.com/users/tuukkamustonen/repos", "events_url": "https://api.github.com/users/tuukkamustonen/events{/privacy}", "received_events_url": "https://api.github.com/users/tuukkamustonen/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I implemented something like that some time ago:\r\nhttps://github.com/HOMEINFO/peeweeplus/blob/055be28cc1ce75210772a4c097be1361fe7db6dc/peeweeplus/json.py#L172", "Implemented it as a separate function. `dict_to_model` works the same as it did previously and to update an existing instance, you can use:\r\n\r\n`update_model_from_dict(instance, data[, ignore_unknown=False])`.\r\n\r\nDocumentation has been added, see: http://docs.peewee-orm.com/en/latest/peewee/playhouse.html#shortcuts" ]
2018-02-02T08:32:45
2018-02-02T14:47:12
2018-02-02T14:43:27
NONE
null
Hosting a HTTP API, `PATCH` requests update existing data. Adding `instance` or similar to `dict_to_model` would allow to update the loaded model: ```python def dict_to_model(model_class, data, ignore_unknown=False): instance = model_class() ``` As in: ```python def dict_to_model(..., instance=None, ...): instance = instance if instance else model_class() ... obj = Foo.get(id=...) dict_to_model(Foo, payload, instance=obj) ``` I guess `model_class` would not be needed in case `instance` is passed in?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1456/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1456/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1455
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1455/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1455/comments
https://api.github.com/repos/coleifer/peewee/issues/1455/events
https://github.com/coleifer/peewee/issues/1455
293,737,247
MDU6SXNzdWUyOTM3MzcyNDc=
1,455
from playhouse.shortcuts import case
{ "login": "ra-esmith", "id": 24212262, "node_id": "MDQ6VXNlcjI0MjEyMjYy", "avatar_url": "https://avatars.githubusercontent.com/u/24212262?v=4", "gravatar_id": "", "url": "https://api.github.com/users/ra-esmith", "html_url": "https://github.com/ra-esmith", "followers_url": "https://api.github.com/users/ra-esmith/followers", "following_url": "https://api.github.com/users/ra-esmith/following{/other_user}", "gists_url": "https://api.github.com/users/ra-esmith/gists{/gist_id}", "starred_url": "https://api.github.com/users/ra-esmith/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/ra-esmith/subscriptions", "organizations_url": "https://api.github.com/users/ra-esmith/orgs", "repos_url": "https://api.github.com/users/ra-esmith/repos", "events_url": "https://api.github.com/users/ra-esmith/events{/privacy}", "received_events_url": "https://api.github.com/users/ra-esmith/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Ah I see\r\nThe Case() helper has moved from the playhouse.shortcuts module into the main peewee module.\r\n\r\nNot sure what that import is, but great I will find it", "If you use `from peewee import *` then the Case helper is automatically imported. `Case` is the same as `case` was in 2.x, so it should be as simple as removing the old imports and switching from \"case\" to \"Case\".", " from peewee import case\r\nTraceback (most recent call last):\r\n File \"<stdin>\", line 1, in <module>\r\nImportError: cannot import name case\r\n", "ok \r\nwill try import *, though I tend to avoid * when I can\r\nthanks!!", "It's \"Case\" (upper-case \"c\").", "Re: \"from peewee import *\", Peewee defines `__all__` at module-scope so the things that are imported are limited to a subset of everything in the peewee module namespace. It's a matter of preference, tho, so whatever works." ]
2018-02-02T00:55:00
2018-02-02T01:07:57
2018-02-02T01:04:02
NONE
null
I am porting up from peewee 2 to 3 and use the case statement. I get an import error now ... What is the work around for case? Thanks, Evan
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1455/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1455/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1454
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1454/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1454/comments
https://api.github.com/repos/coleifer/peewee/issues/1454/events
https://github.com/coleifer/peewee/issues/1454
293,733,372
MDU6SXNzdWUyOTM3MzMzNzI=
1,454
TypeError: unhashable type: 'SQL'
{ "login": "several27", "id": 3248329, "node_id": "MDQ6VXNlcjMyNDgzMjk=", "avatar_url": "https://avatars.githubusercontent.com/u/3248329?v=4", "gravatar_id": "", "url": "https://api.github.com/users/several27", "html_url": "https://github.com/several27", "followers_url": "https://api.github.com/users/several27/followers", "following_url": "https://api.github.com/users/several27/following{/other_user}", "gists_url": "https://api.github.com/users/several27/gists{/gist_id}", "starred_url": "https://api.github.com/users/several27/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/several27/subscriptions", "organizations_url": "https://api.github.com/users/several27/orgs", "repos_url": "https://api.github.com/users/several27/repos", "events_url": "https://api.github.com/users/several27/events{/privacy}", "received_events_url": "https://api.github.com/users/several27/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I've fixed the docs, the correct way in 3.x is:\r\n\r\n```python\r\ndef mod(lhs, rhs):\r\n return Expression(lhs, '%', rhs) # No need for \"SQL()\" around '%'.\r\n```" ]
2018-02-02T00:32:51
2018-02-02T01:05:37
2018-02-02T01:05:00
NONE
null
Hi all, I'm trying to run the examples from the docs on sqlite database: http://docs.peewee-orm.com/en/latest/peewee/querying.html?highlight=modulo#adding-user-defined-operators . Creating an exact modulo operator as shown there with just those few lines: ``` from peewee import * from peewee import Expression # the building block for expressions def mod(lhs, rhs): return Expression(lhs, SQL('%'), rhs) # Users with even ids. User.select().where(mod(User.id, 2) == 0) ``` But I'm getting the following error: ``` File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/peewee.py", line 3240, in __iter__ return iter(self.execute()) File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/peewee.py", line 3233, in execute self._qr = ResultWrapper(model_class, self._execute(), query_meta) File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/peewee.py", line 2911, in _execute sql, params = self.sql() File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/peewee.py", line 3201, in sql return self.compiler().generate_select(self) File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/peewee.py", line 2026, in generate_select return self.build_query(clauses, alias_map) File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/peewee.py", line 1912, in build_query return self.parse_node(Clause(*clauses), alias_map) File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/peewee.py", line 1865, in parse_node sql, params, unknown = self._parse(node, alias_map, conv) File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/peewee.py", line 1831, in _parse sql, params = self._parse_map[node_type](node, alias_map, conv) File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/peewee.py", line 1757, in _parse_clause node.nodes, alias_map, conv, node.glue) File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/peewee.py", line 1890, in parse_node_list node_sql, node_params = self.parse_node(node, alias_map, conv) File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/peewee.py", line 1865, in parse_node sql, params, unknown = self._parse(node, alias_map, conv) File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/peewee.py", line 1831, in _parse sql, params = self._parse_map[node_type](node, alias_map, conv) File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/peewee.py", line 1727, in _parse_expression lhs, lparams = self.parse_node(node.lhs, alias_map, conv) File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/peewee.py", line 1865, in parse_node sql, params, unknown = self._parse(node, alias_map, conv) File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/peewee.py", line 1831, in _parse sql, params = self._parse_map[node_type](node, alias_map, conv) File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/peewee.py", line 1732, in _parse_expression sql = template % (lhs, self.get_op(node.op), rhs) File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/peewee.py", line 1716, in get_op return self._op_map[q] TypeError: unhashable type: 'SQL' ``` Am I doing something wrong (importing the wrong module) or is it a bug?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1454/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1454/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1453
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1453/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1453/comments
https://api.github.com/repos/coleifer/peewee/issues/1453/events
https://github.com/coleifer/peewee/issues/1453
293,726,711
MDU6SXNzdWUyOTM3MjY3MTE=
1,453
cascade with drop_table
{ "login": "ra-esmith", "id": 24212262, "node_id": "MDQ6VXNlcjI0MjEyMjYy", "avatar_url": "https://avatars.githubusercontent.com/u/24212262?v=4", "gravatar_id": "", "url": "https://api.github.com/users/ra-esmith", "html_url": "https://github.com/ra-esmith", "followers_url": "https://api.github.com/users/ra-esmith/followers", "following_url": "https://api.github.com/users/ra-esmith/following{/other_user}", "gists_url": "https://api.github.com/users/ra-esmith/gists{/gist_id}", "starred_url": "https://api.github.com/users/ra-esmith/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/ra-esmith/subscriptions", "organizations_url": "https://api.github.com/users/ra-esmith/orgs", "repos_url": "https://api.github.com/users/ra-esmith/repos", "events_url": "https://api.github.com/users/ra-esmith/events{/privacy}", "received_events_url": "https://api.github.com/users/ra-esmith/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "ahh looks like you just fixed it in 3.0.9\r\nhttps://github.com/coleifer/peewee/commit/d49784c2d6e525d882aab702fe0d2cf8163e4c18\r\n\r\nwill see if i can grab that", "hmm, tried 3.0.9 and even took what is in git, still get unexpected keyword. Though looks like it should work ... ", "Let me look into it some more.", "Fixed." ]
2018-02-01T23:56:15
2018-02-02T01:02:57
2018-02-02T01:02:48
NONE
null
Porting up from 2 to 3 looking for cascade option .db.database.drop_tables(ALL_MODELS, safe=True, cascade=True) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/peewee.py", line 2579, in drop_tables model.drop_table(**kwargs) TypeError: drop_table() got an unexpected keyword argument 'cascade'
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1453/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1453/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1452
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1452/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1452/comments
https://api.github.com/repos/coleifer/peewee/issues/1452/events
https://github.com/coleifer/peewee/issues/1452
293,666,311
MDU6SXNzdWUyOTM2NjYzMTE=
1,452
MySQL nested atomic bug in 3.X
{ "login": "aconz2", "id": 3137597, "node_id": "MDQ6VXNlcjMxMzc1OTc=", "avatar_url": "https://avatars.githubusercontent.com/u/3137597?v=4", "gravatar_id": "", "url": "https://api.github.com/users/aconz2", "html_url": "https://github.com/aconz2", "followers_url": "https://api.github.com/users/aconz2/followers", "following_url": "https://api.github.com/users/aconz2/following{/other_user}", "gists_url": "https://api.github.com/users/aconz2/gists{/gist_id}", "starred_url": "https://api.github.com/users/aconz2/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/aconz2/subscriptions", "organizations_url": "https://api.github.com/users/aconz2/orgs", "repos_url": "https://api.github.com/users/aconz2/repos", "events_url": "https://api.github.com/users/aconz2/events{/privacy}", "received_events_url": "https://api.github.com/users/aconz2/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I'm not sure about all that... This stuff is all tested (with sqlite, mysql and postgres):\r\n\r\nhttps://github.com/coleifer/peewee/blob/41180d6354adcb61280bd4cbf122bd1e5aaa3154/tests/transactions.py#L9-L48", "I whipped up a test-case and ran it using Python 3.6 and pymysql, connected to MariaDB 10.0.33. Test passes:\r\n\r\n```python\r\n def test_bare(self):\r\n with db.atomic():\r\n with db.atomic():\r\n self.assertEqual(Register.select().count(), 0)\r\n\r\n try:\r\n with db.atomic():\r\n with db.atomic():\r\n self.assertEqual(Register.select().count(), 0)\r\n 4 / 0\r\n except ZeroDivisionError:\r\n pass\r\n```", "On a closer look, why are you setting `autocommit=True` in your database constructor? Have you tried removing that?", "Issue resolved removing `autcommit=True`. I inherited this code so I didn't think twice about that. I'm guessing they meant that to be for peewee and not the underlying database connection.\r\n\r\nThank you!", "Ah yes! That's actually a very good point. Peewee removed that parameter in 3.0 so now it's getting passed to the underlying driver. I'll add a warning for this and push a new release so it doesn't bite anyone else. Thank you so much for pointing that out." ]
2018-02-01T20:07:31
2018-02-01T20:50:28
2018-02-01T20:47:32
CONTRIBUTOR
null
I have come across a bug involving savepoints from the use of nested atomic blocks. ``` import peewee from peewee import * import os import logging logging.basicConfig(level=logging.DEBUG) db = MySQLDatabase( os.getenv('db_name'), host = os.getenv('db_host'), user = os.getenv('db_username'), password = os.getenv('db_password'), port = 3306, autocommit = True, ) class MyBase(Model): class Meta: database = db class Foo(MyBase): name = CharField() print(peewee.__version__) if not Foo.table_exists(): Foo.create_table() with db.atomic(): with db.atomic(): Foo.select().count() ``` And the output ```DEBUG:peewee:('SHOW TABLES', None) DEBUG:peewee:('SAVEPOINT `sf880ebb457fd410e95d2053a5d173731`;', None) DEBUG:peewee:('SELECT Count(*) FROM `foo` AS t1', []) DEBUG:peewee:('RELEASE SAVEPOINT `sf880ebb457fd410e95d2053a5d173731`;', None) 2.10.2 DEBUG:peewee:('SHOW TABLES', None) DEBUG:peewee:('SAVEPOINT `s288f7ba54907478e977443cab3435824`;', None) DEBUG:peewee:('SELECT COUNT(1) FROM (SELECT 1 FROM `foo` AS `t1`) AS `_wrapped`', []) DEBUG:peewee:('RELEASE SAVEPOINT `s288f7ba54907478e977443cab3435824`;', None) DEBUG:peewee:('ROLLBACK TO SAVEPOINT `s288f7ba54907478e977443cab3435824`;', None) 3.0.8 Traceback (most recent call last): File "/home/andrew/.local/share/virtualenvs/3--EvudULI/lib/python3.6/site-packages/peewee.py", line 2465, in execute_sql cursor.execute(sql, params or ()) File "/home/andrew/.local/share/virtualenvs/3--EvudULI/lib/python3.6/site-packages/pymysql/cursors.py", line 165, in execute result = self._query(query) File "/home/andrew/.local/share/virtualenvs/3--EvudULI/lib/python3.6/site-packages/pymysql/cursors.py", line 321, in _query conn.query(q) File "/home/andrew/.local/share/virtualenvs/3--EvudULI/lib/python3.6/site-packages/pymysql/connections.py", line 860, in query self._affected_rows = self._read_query_result(unbuffered=unbuffered) File "/home/andrew/.local/share/virtualenvs/3--EvudULI/lib/python3.6/site-packages/pymysql/connections.py", line 1061, in _read_query_result result.read() File "/home/andrew/.local/share/virtualenvs/3--EvudULI/lib/python3.6/site-packages/pymysql/connections.py", line 1349, in read first_packet = self.connection._read_packet() File "/home/andrew/.local/share/virtualenvs/3--EvudULI/lib/python3.6/site-packages/pymysql/connections.py", line 1018, in _read_packet packet.check_error() File "/home/andrew/.local/share/virtualenvs/3--EvudULI/lib/python3.6/site-packages/pymysql/connections.py", line 384, in check_error err.raise_mysql_exception(self._data) File "/home/andrew/.local/share/virtualenvs/3--EvudULI/lib/python3.6/site-packages/pymysql/err.py", line 107, in raise_mysql_exception raise errorclass(errno, errval) pymysql.err.InternalError: (1305, 'SAVEPOINT s288f7ba54907478e977443cab3435824 does not exist') During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/andrew/.local/share/virtualenvs/3--EvudULI/lib/python3.6/site-packages/peewee.py", line 3293, in __exit__ self.commit(begin=False) File "/home/andrew/.local/share/virtualenvs/3--EvudULI/lib/python3.6/site-packages/peewee.py", line 3278, in commit self.db.execute_sql('RELEASE SAVEPOINT %s;' % self.quoted_sid) File "/home/andrew/.local/share/virtualenvs/3--EvudULI/lib/python3.6/site-packages/peewee.py", line 2472, in execute_sql self.commit() File "/home/andrew/.local/share/virtualenvs/3--EvudULI/lib/python3.6/site-packages/peewee.py", line 2278, in __exit__ reraise(new_type, new_type(*exc_args), traceback) File "/home/andrew/.local/share/virtualenvs/3--EvudULI/lib/python3.6/site-packages/peewee.py", line 169, in reraise raise value.with_traceback(tb) File "/home/andrew/.local/share/virtualenvs/3--EvudULI/lib/python3.6/site-packages/peewee.py", line 2465, in execute_sql cursor.execute(sql, params or ()) File "/home/andrew/.local/share/virtualenvs/3--EvudULI/lib/python3.6/site-packages/pymysql/cursors.py", line 165, in execute result = self._query(query) File "/home/andrew/.local/share/virtualenvs/3--EvudULI/lib/python3.6/site-packages/pymysql/cursors.py", line 321, in _query conn.query(q) File "/home/andrew/.local/share/virtualenvs/3--EvudULI/lib/python3.6/site-packages/pymysql/connections.py", line 860, in query self._affected_rows = self._read_query_result(unbuffered=unbuffered) File "/home/andrew/.local/share/virtualenvs/3--EvudULI/lib/python3.6/site-packages/pymysql/connections.py", line 1061, in _read_query_result result.read() File "/home/andrew/.local/share/virtualenvs/3--EvudULI/lib/python3.6/site-packages/pymysql/connections.py", line 1349, in read first_packet = self.connection._read_packet() File "/home/andrew/.local/share/virtualenvs/3--EvudULI/lib/python3.6/site-packages/pymysql/connections.py", line 1018, in _read_packet packet.check_error() File "/home/andrew/.local/share/virtualenvs/3--EvudULI/lib/python3.6/site-packages/pymysql/connections.py", line 384, in check_error err.raise_mysql_exception(self._data) File "/home/andrew/.local/share/virtualenvs/3--EvudULI/lib/python3.6/site-packages/pymysql/err.py", line 107, in raise_mysql_exception raise errorclass(errno, errval) peewee.InternalError: (1305, 'SAVEPOINT s288f7ba54907478e977443cab3435824 does not exist') During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/andrew/.local/share/virtualenvs/3--EvudULI/lib/python3.6/site-packages/peewee.py", line 2465, in execute_sql cursor.execute(sql, params or ()) File "/home/andrew/.local/share/virtualenvs/3--EvudULI/lib/python3.6/site-packages/pymysql/cursors.py", line 165, in execute result = self._query(query) File "/home/andrew/.local/share/virtualenvs/3--EvudULI/lib/python3.6/site-packages/pymysql/cursors.py", line 321, in _query conn.query(q) File "/home/andrew/.local/share/virtualenvs/3--EvudULI/lib/python3.6/site-packages/pymysql/connections.py", line 860, in query self._affected_rows = self._read_query_result(unbuffered=unbuffered) File "/home/andrew/.local/share/virtualenvs/3--EvudULI/lib/python3.6/site-packages/pymysql/connections.py", line 1061, in _read_query_result result.read() File "/home/andrew/.local/share/virtualenvs/3--EvudULI/lib/python3.6/site-packages/pymysql/connections.py", line 1349, in read first_packet = self.connection._read_packet() File "/home/andrew/.local/share/virtualenvs/3--EvudULI/lib/python3.6/site-packages/pymysql/connections.py", line 1018, in _read_packet packet.check_error() File "/home/andrew/.local/share/virtualenvs/3--EvudULI/lib/python3.6/site-packages/pymysql/connections.py", line 384, in check_error err.raise_mysql_exception(self._data) File "/home/andrew/.local/share/virtualenvs/3--EvudULI/lib/python3.6/site-packages/pymysql/err.py", line 107, in raise_mysql_exception raise errorclass(errno, errval) pymysql.err.InternalError: (1305, 'SAVEPOINT s288f7ba54907478e977443cab3435824 does not exist') During handling of the above exception, another exception occurred: Traceback (most recent call last): File "../test.py", line 31, in <module> Foo.select().count() File "/home/andrew/.local/share/virtualenvs/3--EvudULI/lib/python3.6/site-packages/peewee.py", line 3224, in __exit__ return self._helper.__exit__(exc_type, exc_val, exc_tb) File "/home/andrew/.local/share/virtualenvs/3--EvudULI/lib/python3.6/site-packages/peewee.py", line 3295, in __exit__ self.rollback() File "/home/andrew/.local/share/virtualenvs/3--EvudULI/lib/python3.6/site-packages/peewee.py", line 3282, in rollback self.db.execute_sql('ROLLBACK TO SAVEPOINT %s;' % self.quoted_sid) File "/home/andrew/.local/share/virtualenvs/3--EvudULI/lib/python3.6/site-packages/peewee.py", line 2472, in execute_sql self.commit() File "/home/andrew/.local/share/virtualenvs/3--EvudULI/lib/python3.6/site-packages/peewee.py", line 2278, in __exit__ reraise(new_type, new_type(*exc_args), traceback) File "/home/andrew/.local/share/virtualenvs/3--EvudULI/lib/python3.6/site-packages/peewee.py", line 169, in reraise raise value.with_traceback(tb) File "/home/andrew/.local/share/virtualenvs/3--EvudULI/lib/python3.6/site-packages/peewee.py", line 2465, in execute_sql cursor.execute(sql, params or ()) File "/home/andrew/.local/share/virtualenvs/3--EvudULI/lib/python3.6/site-packages/pymysql/cursors.py", line 165, in execute result = self._query(query) File "/home/andrew/.local/share/virtualenvs/3--EvudULI/lib/python3.6/site-packages/pymysql/cursors.py", line 321, in _query conn.query(q) File "/home/andrew/.local/share/virtualenvs/3--EvudULI/lib/python3.6/site-packages/pymysql/connections.py", line 860, in query self._affected_rows = self._read_query_result(unbuffered=unbuffered) File "/home/andrew/.local/share/virtualenvs/3--EvudULI/lib/python3.6/site-packages/pymysql/connections.py", line 1061, in _read_query_result result.read() File "/home/andrew/.local/share/virtualenvs/3--EvudULI/lib/python3.6/site-packages/pymysql/connections.py", line 1349, in read first_packet = self.connection._read_packet() File "/home/andrew/.local/share/virtualenvs/3--EvudULI/lib/python3.6/site-packages/pymysql/connections.py", line 1018, in _read_packet packet.check_error() File "/home/andrew/.local/share/virtualenvs/3--EvudULI/lib/python3.6/site-packages/pymysql/connections.py", line 384, in check_error err.raise_mysql_exception(self._data) File "/home/andrew/.local/share/virtualenvs/3--EvudULI/lib/python3.6/site-packages/pymysql/err.py", line 107, in raise_mysql_exception raise errorclass(errno, errval) peewee.InternalError: (1305, 'SAVEPOINT s288f7ba54907478e977443cab3435824 does not exist') ``` I tried tracking down the culprit but haven't figured anything out so far.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1452/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1452/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1451
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1451/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1451/comments
https://api.github.com/repos/coleifer/peewee/issues/1451/events
https://github.com/coleifer/peewee/issues/1451
293,510,107
MDU6SXNzdWUyOTM1MTAxMDc=
1,451
Implementing database context in peewee 3.0
{ "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
[ "The [API documentation](http://docs.peewee-orm.com/en/latest/peewee/api.html) is **much** more thorough than the 2.x documentation, have you taken a look there?\r\n\r\nSimilarly the [changes documentation](http://docs.peewee-orm.com/en/latest/peewee/changes.html) describes that, in place of `execution_context()`, you can:\r\n\r\n* Simply use the database instance as a context manager, in which case the wrapped code is also wrapped in a transaction\r\n* Use `database.connection_context()`, which has similar semantics to `execution_context()`.\r\n\r\nDoes this solve your problem?", "Hi. Tanks for the hint regarding the changes page. I actually did not notice that.\r\n`database.connection_context()` looks promising. I'll re-open if it'll turn out to not work." ]
2018-02-01T12:20:16
2018-02-02T08:35:26
2018-02-02T08:35:26
CONTRIBUTOR
null
Unfortunately I have been to hasty migrating to peewee 3.0. I was using an [extension](https://github.com/HOMEINFO/peeweeplus/blob/27aef530f3a871593aa06b9b940057a033afa0ce/peeweeplus/database.py) of the MySQLDatabase class that handles connections well (if invoked with `closing=True`). This hack was/is supposed to compensate for peewee < 3.0 's bad behaviour regarding connection handling. Do you have any suggestions, how I may migrate this to the new API of peewee 3.0 (which unfortunately still has no useful docstrings documenting the respective classes, functions and parameters)? My goal is the following: I do not want peewee to raise `Error 2006` after a certain runtime as described [here](http://peewee.readthedocs.io/en/latest/peewee/database.html#error-2006-mysql-server-has-gone-away). Unfortunately, `MySQLDatabase.execution_context ` does no longer exist. Thanks for any hint.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1451/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1451/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1450
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1450/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1450/comments
https://api.github.com/repos/coleifer/peewee/issues/1450/events
https://github.com/coleifer/peewee/issues/1450
293,448,603
MDU6SXNzdWUyOTM0NDg2MDM=
1,450
Creating temporary databases for unit testing
{ "login": "cLupus", "id": 2326244, "node_id": "MDQ6VXNlcjIzMjYyNDQ=", "avatar_url": "https://avatars.githubusercontent.com/u/2326244?v=4", "gravatar_id": "", "url": "https://api.github.com/users/cLupus", "html_url": "https://github.com/cLupus", "followers_url": "https://api.github.com/users/cLupus/followers", "following_url": "https://api.github.com/users/cLupus/following{/other_user}", "gists_url": "https://api.github.com/users/cLupus/gists{/gist_id}", "starred_url": "https://api.github.com/users/cLupus/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/cLupus/subscriptions", "organizations_url": "https://api.github.com/users/cLupus/orgs", "repos_url": "https://api.github.com/users/cLupus/repos", "events_url": "https://api.github.com/users/cLupus/events{/privacy}", "received_events_url": "https://api.github.com/users/cLupus/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "So `database.bind(...)` is actually a context-manager. Hence why it is not working as you'd expect. In your `create_database` function you call database.bind(models), which instantiates a _BoundModelsContext context-manager, but since the context-manager is never entered, the binding does not take place.\r\n\r\nTo simplify your existing code, you can:\r\n\r\n```python\r\ndef create_database(database: Database, safe=True, nuke=False):\r\n if nuke:\r\n nuke_database(database)\r\n with database:\r\n for model in models:\r\n # Bind db. Alternatively you could use model.bind(database) but, without specifying\r\n # any arguments, that will traverse the model graph binding related models, which\r\n # would be redundant.\r\n model._meta.set_database(database)\r\n # Alt version: model.bind(database, bind_refs=False, bind_backrefs=False)\r\n database.create_tables(\r\n get_domain_models(),\r\n safe=safe\r\n )\r\n```\r\n\r\nFor individual test-cases, I use a decorator sometimes in the tests, `requires_models`, which looks like this:\r\n\r\n```python\r\ndef requires_models(*models):\r\n def decorator(method):\r\n @wraps(method)\r\n def inner(self):\r\n _db_mapping = {}\r\n for model in models:\r\n _db_mapping[model] = model._meta.database\r\n model._meta.set_database(self.database)\r\n self.database.drop_tables(models, safe=True)\r\n self.database.create_tables(models)\r\n\r\n try:\r\n method(self)\r\n finally:\r\n try:\r\n self.database.drop_tables(models)\r\n except:\r\n pass\r\n for model in models:\r\n model._meta.set_database(_db_mapping[model])\r\n return inner\r\n return decorator\r\n```", "Here's a simple version that should theoretically work:\r\n\r\n```python\r\n MODELS = (User, Account, Note)\r\n\r\n # Bind the given models to the db for the duration of wrapped block.\r\n def use_test_database(fn):\r\n @wraps(fn)\r\n def inner(self):\r\n with test_db.bind(MODELS):\r\n test_db.create_tables(MODELS)\r\n try:\r\n fn(self)\r\n finally:\r\n test_db.drop_tables(MODELS)\r\n return inner\r\n\r\n\r\n class TestSomething(TestCase):\r\n @use_test_database\r\n def test_something(self):\r\n # ... models are bound to test database ...\r\n pass\r\n```", "Here's a simple solution for a class decorator so you don't need to add it to every method.\r\n\r\nThis has the advantage of allowing the with_test_db class decorator to take a param (MODELS); this is set as an instance variable in the constructor. __ call __ then wraps the unittest class, replaces the testunit run() method with a new run method which has the new memory Sqlite code.\r\n\r\napp/model.py\r\n```\r\nclass BaseModel(peewee.Model):\r\n class Meta:\r\n database = db\r\n\r\nclass SomeTable(BaseModel):\r\n ...\r\n\r\nMODELS = (SomeTable,)\r\n```\r\n\r\ntestutils.py\r\n```\r\nclass with_test_db:\r\n def __init__(self, dbs: tuple):\r\n self.dbs = dbs\r\n\r\n def __call__(self, cls):\r\n def run(innerself, *args, **kwargs):\r\n test_db = playhouse.sqlite_ext.SqliteExtDatabase(\":memory:\")\r\n with test_db.bind_ctx(self.dbs):\r\n test_db.create_tables(self.dbs)\r\n try:\r\n cls.run(innerself, *args, **kwargs)\r\n finally:\r\n test_db.drop_tables(self.dbs)\r\n test_db.close()\r\n\r\n return type(cls.__name__, (cls,), {\"run\": run})\r\n\r\n\r\[email protected]_test_db(app.MODELS)\r\nclass MyAmazingTest(unittest.TestCase):\r\n def test_something(self):\r\n ...\r\n\r\n def test_something_else(self):\r\n ...\r\n```\r\n\r\nVoila. Only one decorator needed per class which all tests can use. \r\n\r\nThanks to https://www.dvlv.co.uk/a-super-helpful-decorator-for-peeweeflask-unit-testing.html for the inspiration." ]
2018-02-01T08:52:01
2020-08-04T16:19:37
2018-02-01T16:32:50
NONE
null
Hi, I am having trouble creating a database with tables that will be used in unit tests. In 2.10.2, I used `test_database` (ref #1440 ), however now this functionality have been removed. The desired functionality is to create / use a database, and create all the tables / (domain) models that is necessary. Currently, I have been using a decorator; ``` from functools import wraps, partial def use_database(func=None, database=None): if func is None: return partial(use_database, database=database) if database is None: database = get_database() @wraps(func) def use_database_decorator(*args, **kwargs): models = get_domain_models() with database: create_database(database, nuke=True) func(*args, **kwargs) database.drop_tables(models) return use_database_decorator def create_database(database: Database, safe=True, nuke=False): if nuke: nuke_database(database) with database: database.bind(models) database.create_tables( get_domain_models(), safe=safe ) def nuke_database(database: Database): """ Removes everything in the database, except the file itself """ models = get_domain_models()[::-1] database.drop_tables(models, safe=True) ``` Here, `get_domain_models()` returns a list of all the models / tables defined in the app / domain, except `BaseModel`, with _all_ models inherit. `get_database()` returns an instance of an (in-memory) APSWDatabase, with some pragma statements set. In some cases, there are no tables defined in the database, even though they have been explicitly created. An example of this is in the test bellow: ``` db = get_database() @use_database(database=db) def test_creation_of_database(): created_table_names = db.get_tables() given_table_names = [model._meta.name for model in get_domain_models()] assert set(created_table_names) == set(given_table_names) ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1450/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1450/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1449
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1449/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1449/comments
https://api.github.com/repos/coleifer/peewee/issues/1449/events
https://github.com/coleifer/peewee/issues/1449
293,210,624
MDU6SXNzdWUyOTMyMTA2MjQ=
1,449
drop_table missing cascade option in 3.0
{ "login": "asch99", "id": 5629047, "node_id": "MDQ6VXNlcjU2MjkwNDc=", "avatar_url": "https://avatars.githubusercontent.com/u/5629047?v=4", "gravatar_id": "", "url": "https://api.github.com/users/asch99", "html_url": "https://github.com/asch99", "followers_url": "https://api.github.com/users/asch99/followers", "following_url": "https://api.github.com/users/asch99/following{/other_user}", "gists_url": "https://api.github.com/users/asch99/gists{/gist_id}", "starred_url": "https://api.github.com/users/asch99/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/asch99/subscriptions", "organizations_url": "https://api.github.com/users/asch99/orgs", "repos_url": "https://api.github.com/users/asch99/repos", "events_url": "https://api.github.com/users/asch99/events{/privacy}", "received_events_url": "https://api.github.com/users/asch99/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Fixed" ]
2018-01-31T15:55:05
2018-01-31T18:30:53
2018-01-31T18:00:19
NONE
null
The cascade=True option is no longer supported for drop_table in 3.0, can you add it back?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1449/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1449/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1448
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1448/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1448/comments
https://api.github.com/repos/coleifer/peewee/issues/1448/events
https://github.com/coleifer/peewee/issues/1448
293,103,592
MDU6SXNzdWUyOTMxMDM1OTI=
1,448
Inherit database models
{ "login": "cLupus", "id": 2326244, "node_id": "MDQ6VXNlcjIzMjYyNDQ=", "avatar_url": "https://avatars.githubusercontent.com/u/2326244?v=4", "gravatar_id": "", "url": "https://api.github.com/users/cLupus", "html_url": "https://github.com/cLupus", "followers_url": "https://api.github.com/users/cLupus/followers", "following_url": "https://api.github.com/users/cLupus/following{/other_user}", "gists_url": "https://api.github.com/users/cLupus/gists{/gist_id}", "starred_url": "https://api.github.com/users/cLupus/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/cLupus/subscriptions", "organizations_url": "https://api.github.com/users/cLupus/orgs", "repos_url": "https://api.github.com/users/cLupus/repos", "events_url": "https://api.github.com/users/cLupus/events{/privacy}", "received_events_url": "https://api.github.com/users/cLupus/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Check out test-case I added in c80c9d4bc64327237b0a8c8de208c5f41e0bed40 -- I'm also developing using Python 3.6 and encounter no such error.\r\n\r\nAre you trying to inherit a `ForeignKeyField`?", "Looks like it -- I've added a test and a patch: a446a9f244d3b530b79b03ab97923d4081780c71\r\n\r\nFrom a semantic point-of-view, inheriting foreign-keys is a bit weird.", "In some of the cases, I want to inherit the foreign key, yes.\r\nIt would be nice not having to deal with it in properties, or other logic (i.e. look through the different `<tablename>_set` properties).\r\n\r\nI tried without the foreign key reference, and it seem to have worked.", "Also, thanks for quick patch, and response 😄 ", "I've added code to re-set the backref (`'<table>_set'`) so each inherited foreign-key instance will get its own backref on the related model.", "In 2.10.2, when I did this, the model the different inherited models referred to had a few extra fields, e.g.\r\n`basetable_set`, `tablea_set`, `tableb_set`, `tablec_set`, and `tabled_set`. Now however (3.0.7), there is only one; `basetable_set` (which refers to `tabled_set`).\r\n\r\nWhat do you suggest as a solution to access all the references that would have been created in 2.10.2, @coleifer ?", "I'm not sure I follow. In 8a6e080dd3b258e8fc547c6cdf47e8de75635d60 I added a change for clearing out the inherited FK backref so that it would be unique for each inherited model. See the test-cases and some assertions, specifically https://github.com/coleifer/peewee/blob/8a6e080dd3b258e8fc547c6cdf47e8de75635d60/tests/models.py#L1264-L1265\r\n\r\nTo put it another way:\r\n\r\n```python\r\n\r\nclass Category(Model):\r\n name = TextField()\r\n\r\nclass BaseContent(Model):\r\n category = ForeignKeyField(Category)\r\n\r\nclass Photo(BaseContent):\r\n image = TextField()\r\n\r\nclass Note(BaseContent):\r\n content = TextField()\r\n\r\n# Now, if I'm on Category, I can:\r\ncategory = Category.get(Category.name == 'whatever')\r\n\r\n# List notes associated w/the category:\r\nfor note in category.note_set:\r\n ...\r\n\r\n# List images associated w/the category:\r\nfor photo in category.photo_set:\r\n ...\r\n```\r\n\r\nAm I misunderstanding your comment?", "You are understanding my comment.\r\n\r\nIn my case, though, I only see the latter (e.i. note_set).\r\nAlso, the foreign key works as a primary key in my case (i.e. `ForeignKey(..., primary_key=True)`)", "Cool, I think this should address the issue with foreign-keys as primary-key: 8670ddb7835491cb75676cf7d70d3bd1c281aefe" ]
2018-01-31T10:21:36
2018-01-31T23:04:10
2018-01-31T11:45:00
NONE
null
Hi, In version 2.10.2, one could define a new model / table with fields and then create a new model that inherits from said model (though foreign keys was a hassle). ex. ``` class A(BaseModel): common = TextField() class B(A): specific = TextField() ``` However, in 3.0.6, this does not work, and gives an error message where the recursion limit has been reached. ``` test_domain_model.py:None (test_domain_model.py) test_domain_model.py:3: in <module> from src.models.domain import APSModel, ParameterNames ../../models/domain.py:654: in <module> class LinearTrend(Trend): ../../../venv/lib/python3.6/site-packages/peewee.py:4811: in __new__ parent_pk = deepcopy(base_meta.primary_key) ../../../venv/lib/python3.6/copy.py:180: in deepcopy y = _reconstruct(x, memo, *rv) ../../../venv/lib/python3.6/copy.py:281: in _reconstruct if hasattr(y, '__setstate__'): ../../../venv/lib/python3.6/site-packages/peewee.py:4134: in __getattr__ if attr in self.rel_model._meta.fields: ../../../venv/lib/python3.6/site-packages/peewee.py:4134: in __getattr__ if attr in self.rel_model._meta.fields: ../../../venv/lib/python3.6/site-packages/peewee.py:4134: in __getattr__ if attr in self.rel_model._meta.fields: E RecursionError: maximum recursion depth exceeded while calling a Python object !!! Recursion detected (same locals & position) ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1448/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1448/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1447
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1447/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1447/comments
https://api.github.com/repos/coleifer/peewee/issues/1447/events
https://github.com/coleifer/peewee/issues/1447
293,041,314
MDU6SXNzdWUyOTMwNDEzMTQ=
1,447
Add constrain name to ForeignKeyMetadata
{ "login": "aachurin", "id": 680329, "node_id": "MDQ6VXNlcjY4MDMyOQ==", "avatar_url": "https://avatars.githubusercontent.com/u/680329?v=4", "gravatar_id": "", "url": "https://api.github.com/users/aachurin", "html_url": "https://github.com/aachurin", "followers_url": "https://api.github.com/users/aachurin/followers", "following_url": "https://api.github.com/users/aachurin/following{/other_user}", "gists_url": "https://api.github.com/users/aachurin/gists{/gist_id}", "starred_url": "https://api.github.com/users/aachurin/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/aachurin/subscriptions", "organizations_url": "https://api.github.com/users/aachurin/orgs", "repos_url": "https://api.github.com/users/aachurin/repos", "events_url": "https://api.github.com/users/aachurin/events{/privacy}", "received_events_url": "https://api.github.com/users/aachurin/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Nope.", "Why not? IndexMeta has the name of index.\r\n " ]
2018-01-31T06:05:00
2018-01-31T17:19:10
2018-01-31T11:59:51
NONE
null
get_foreign_keys returns list of ForeignKeyMetadata. Can you add constraint name to ForeignKeyMetadata?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1447/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1447/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1446
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1446/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1446/comments
https://api.github.com/repos/coleifer/peewee/issues/1446/events
https://github.com/coleifer/peewee/issues/1446
292,998,099
MDU6SXNzdWUyOTI5OTgwOTk=
1,446
update with inner join
{ "login": "ra-esmith", "id": 24212262, "node_id": "MDQ6VXNlcjI0MjEyMjYy", "avatar_url": "https://avatars.githubusercontent.com/u/24212262?v=4", "gravatar_id": "", "url": "https://api.github.com/users/ra-esmith", "html_url": "https://github.com/ra-esmith", "followers_url": "https://api.github.com/users/ra-esmith/followers", "following_url": "https://api.github.com/users/ra-esmith/following{/other_user}", "gists_url": "https://api.github.com/users/ra-esmith/gists{/gist_id}", "starred_url": "https://api.github.com/users/ra-esmith/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/ra-esmith/subscriptions", "organizations_url": "https://api.github.com/users/ra-esmith/orgs", "repos_url": "https://api.github.com/users/ra-esmith/repos", "events_url": "https://api.github.com/users/ra-esmith/events{/privacy}", "received_events_url": "https://api.github.com/users/ra-esmith/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "#my thought is to try\r\n\r\n```python\r\ndef test():\r\n with my_app.db.database.atomic():\r\n Customer.update(x=CustomerRep.select(CustomerRep.x)\r\n .where(CustomerRep.acct == Customer.acct)\r\n .order_by(CustomerRep.id.desc())\r\n .limit(1)).execute()\r\n Customer.update(y=CustomerRep.select(CustomerRep.y)\r\n .where(CustomerRep.acct == Customer.acct)\r\n .order_by(CustomerRep.id.desc())\r\n .limit(1)).execute()\r\n```\r\n", "Did you happen to notice, when commenting or creating your issue that your code was not formatted? Please take the extra 10 seconds to do this when submitting issues.", "So, unfortunately, Peewee does not really support updates with joins. In fact, I don't know if any of the RDBMS's that Peewee supports allow that syntax.\r\n\r\n* https://www.postgresql.org/docs/current/static/sql-update.html\r\n* https://www.sqlite.org/lang_update.html\r\n\r\nCheck out this example for some ideas: http://docs.peewee-orm.com/en/latest/peewee/query_examples.html#update-a-row-based-on-the-contents-of-another-row" ]
2018-01-31T01:19:26
2018-01-31T03:15:17
2018-01-31T03:15:16
NONE
null
hello, what is the syntax for a peewee query such as the following? Is there a good way to figure this out on my own (like an sql to query syntax generator?). ```sql update customer set customer.x = customerrep.x, customer.y = customerrep.y from customer cust inner join customerrep custrep on cust.acct = custrep.acct ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1446/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1446/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1445
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1445/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1445/comments
https://api.github.com/repos/coleifer/peewee/issues/1445/events
https://github.com/coleifer/peewee/pull/1445
292,975,725
MDExOlB1bGxSZXF1ZXN0MTY2MTI2MTMx
1,445
Fix how set's are translated to SQL
{ "login": "aconz2", "id": 3137597, "node_id": "MDQ6VXNlcjMxMzc1OTc=", "avatar_url": "https://avatars.githubusercontent.com/u/3137597?v=4", "gravatar_id": "", "url": "https://api.github.com/users/aconz2", "html_url": "https://github.com/aconz2", "followers_url": "https://api.github.com/users/aconz2/followers", "following_url": "https://api.github.com/users/aconz2/following{/other_user}", "gists_url": "https://api.github.com/users/aconz2/gists{/gist_id}", "starred_url": "https://api.github.com/users/aconz2/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/aconz2/subscriptions", "organizations_url": "https://api.github.com/users/aconz2/orgs", "repos_url": "https://api.github.com/users/aconz2/repos", "events_url": "https://api.github.com/users/aconz2/events{/privacy}", "received_events_url": "https://api.github.com/users/aconz2/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Fixed with 7af636d8dd81573cf02ede0bbcb6f605c8ab6118 -- which includes test. Thanks." ]
2018-01-30T23:24:19
2018-01-31T02:51:42
2018-01-31T02:41:24
CONTRIBUTOR
null
The following code breaks from 2 to 3 ```python import peewee from peewee import * db = SqliteDatabase(':memory:') class MyModel(Model): class Meta: database = db class Foo(MyModel): name = CharField() print(peewee.__version__) print(Foo.select().where(Foo.name.in_({'foo'})).sql()) ``` And the output for each ``` 2.10.2 ('SELECT "t1"."id", "t1"."name" FROM "foo" AS t1 WHERE ("t1"."name" IN (?))', ['foo']) ``` ``` 3.0.5 ('SELECT "t1"."id", "t1"."name" FROM "foo" AS "t1" WHERE ("t1"."name" IN ?)', ["{'foo'}"]) ``` Given how the conversion used to include `set`s ([this](https://github.com/coleifer/peewee/blob/2.10.2/peewee.py#L1852) is the relavent line I think), this would be the "fix". If that change was intentional I understand that as well.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1445/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1445/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/1445", "html_url": "https://github.com/coleifer/peewee/pull/1445", "diff_url": "https://github.com/coleifer/peewee/pull/1445.diff", "patch_url": "https://github.com/coleifer/peewee/pull/1445.patch", "merged_at": null }
https://api.github.com/repos/coleifer/peewee/issues/1444
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1444/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1444/comments
https://api.github.com/repos/coleifer/peewee/issues/1444/events
https://github.com/coleifer/peewee/issues/1444
292,958,082
MDU6SXNzdWUyOTI5NTgwODI=
1,444
PasswordField & PickledField on 3?
{ "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
[ "Hey, those are no longer supported. PasswordField had some legitimate security concerns raised about it, and I don't want to give the false sense of security as to what it claims to do. PickleField is quite easy to implement in your own code or in a library.\r\n\r\n```python\r\nimport sqlite\r\nimport pickle\r\n\r\nclass PickledField(BlobField):\r\n def python_value(self, value):\r\n if isinstance(value, (bytearray, sqlite3.Binary)):\r\n value = bytes(value)\r\n return pickle.loads(value)\r\n\r\n def db_value(self, value):\r\n return sqlite3.Binary(pickle.dumps(value, 2))\r\n```", "**Thank you very much!.**\r\n\r\nField now lives here, in case someone still need it, or to ease migration to 3.x:\r\nhttps://github.com/juancarlospaco/peewee-extra-fields#pickledfield\r\n:smiley:\r\n", "Good stuff brotha, thanks", "So should we use https://github.com/juancarlospaco/peewee-extra-fields#simplepasswordfield instead?", "Just in case anyone was troubleshooting PickleField\r\nhttp://docs.peewee-orm.com/en/latest/peewee/playhouse.html#PickleField\r\n\r\n```\r\nfrom playhouse.fields import PickleField\r\n```" ]
2018-01-30T22:15:36
2020-10-19T22:50:12
2018-01-31T02:43:14
NONE
null
http://docs.peewee-orm.com/en/latest/peewee/changes.html#fields What are the alternatives for `PasswordField` and `PickledField` on 3.x ?. What are you using if you need `PasswordField` and `PickledField` on 3.x ?. The Documentation dont mention alternatives. :thinking:
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1444/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1444/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1443
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1443/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1443/comments
https://api.github.com/repos/coleifer/peewee/issues/1443/events
https://github.com/coleifer/peewee/issues/1443
292,924,274
MDU6SXNzdWUyOTI5MjQyNzQ=
1,443
ForeignKeyField on_update and on_delete
{ "login": "aachurin", "id": 680329, "node_id": "MDQ6VXNlcjY4MDMyOQ==", "avatar_url": "https://avatars.githubusercontent.com/u/680329?v=4", "gravatar_id": "", "url": "https://api.github.com/users/aachurin", "html_url": "https://github.com/aachurin", "followers_url": "https://api.github.com/users/aachurin/followers", "following_url": "https://api.github.com/users/aachurin/following{/other_user}", "gists_url": "https://api.github.com/users/aachurin/gists{/gist_id}", "starred_url": "https://api.github.com/users/aachurin/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/aachurin/subscriptions", "organizations_url": "https://api.github.com/users/aachurin/orgs", "repos_url": "https://api.github.com/users/aachurin/repos", "events_url": "https://api.github.com/users/aachurin/events{/privacy}", "received_events_url": "https://api.github.com/users/aachurin/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "This is now fixed, the clauses weren't being included in the constraint. Pushed a new release, 3.0.6. Thank you!" ]
2018-01-30T20:21:45
2018-01-30T21:37:23
2018-01-30T21:35:56
NONE
null
Is ForeignKeyField on_update and on_delete no longer supported?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1443/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1443/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1442
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1442/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1442/comments
https://api.github.com/repos/coleifer/peewee/issues/1442/events
https://github.com/coleifer/peewee/issues/1442
292,837,643
MDU6SXNzdWUyOTI4Mzc2NDM=
1,442
3.0.2 release breaks FlaskAdmin
{ "login": "brunson", "id": 51266, "node_id": "MDQ6VXNlcjUxMjY2", "avatar_url": "https://avatars.githubusercontent.com/u/51266?v=4", "gravatar_id": "", "url": "https://api.github.com/users/brunson", "html_url": "https://github.com/brunson", "followers_url": "https://api.github.com/users/brunson/followers", "following_url": "https://api.github.com/users/brunson/following{/other_user}", "gists_url": "https://api.github.com/users/brunson/gists{/gist_id}", "starred_url": "https://api.github.com/users/brunson/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/brunson/subscriptions", "organizations_url": "https://api.github.com/users/brunson/orgs", "repos_url": "https://api.github.com/users/brunson/repos", "events_url": "https://api.github.com/users/brunson/events{/privacy}", "received_events_url": "https://api.github.com/users/brunson/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I'm not the maintainer of Flask-Admin. You can see in the [changes](http://docs.peewee-orm.com/en/latest/peewee/changes.html#fields) that PrimaryKeyField has been renamed to AutoField.\r\n\r\nTo simplify updating, I suppose I can add a shim that logs a DeprecationWarning if you try to use PrimaryKeyField, however. This will give other maintainers some warning to upgrade their code. WDYT?", "Pushed 3.0.4, which adds a shim for `PrimaryKeyField`, which raises a DeprecationWarning if you attempt to use it. This should give folks time to update their codes.", "Wow, that's awesome. I created an issue for the flask_admin maintainer: https://github.com/mrjoes/flask-admin/issues/42\r\n\r\nThanks for the amazing turn around!", "Of course, thanks for reporting the issue. 3.0 is a major release and I want to be sure to make the transition as smooth as possible for folks upgrading. Cheers." ]
2018-01-30T16:00:46
2018-01-30T16:42:08
2018-01-30T16:16:37
NONE
null
When upgrading to peewee 3.0.2 from 2.10.2 the contrib.peewee module for flask_admin fails attempting to import PrimaryKeyField from peewee.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1442/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1442/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1441
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1441/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1441/comments
https://api.github.com/repos/coleifer/peewee/issues/1441/events
https://github.com/coleifer/peewee/issues/1441
292,831,679
MDU6SXNzdWUyOTI4MzE2Nzk=
1,441
Aggregating by month: "user-defined function raised exception"
{ "login": "piotrek-k", "id": 5506878, "node_id": "MDQ6VXNlcjU1MDY4Nzg=", "avatar_url": "https://avatars.githubusercontent.com/u/5506878?v=4", "gravatar_id": "", "url": "https://api.github.com/users/piotrek-k", "html_url": "https://github.com/piotrek-k", "followers_url": "https://api.github.com/users/piotrek-k/followers", "following_url": "https://api.github.com/users/piotrek-k/following{/other_user}", "gists_url": "https://api.github.com/users/piotrek-k/gists{/gist_id}", "starred_url": "https://api.github.com/users/piotrek-k/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/piotrek-k/subscriptions", "organizations_url": "https://api.github.com/users/piotrek-k/orgs", "repos_url": "https://api.github.com/users/piotrek-k/repos", "events_url": "https://api.github.com/users/piotrek-k/events{/privacy}", "received_events_url": "https://api.github.com/users/piotrek-k/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "What is the raw data stored in the Message.date column?", "Executing this code\r\n```\r\n query = (dc.Message.select(dc.Message.date).limit(5))\r\n \r\n for q in query:\r\n print(q.date)\r\n```\r\nGives me this response:\r\n\r\n> 2016-08-31 15:39:00+02:00\r\n> 2016-08-31 15:39:00+02:00\r\n> 2016-08-31 15:25:00+02:00\r\n> 2016-08-31 14:43:00+02:00\r\n> 2016-08-31 14:31:00+02:00 ", "The problem is that the datetime strings contain timezone information, which is not supported by these methods. If using SQLite, which does not contain a native datetime type, dates are stored in a text column in a format that ensures lexicographic ordering (so sorting and comparing datetimes works as you'd expect). You have the format correct (Y-m-d H:M:S) but the inclusion of the timezone will make ordering not work correctly (unless all values have the same timezone, which, if the case, means you can probably do without storing it anyways?). So to use the helper functions with SQLite, you'll want to store all datetimes as naive datetimes. If you use timezones, just convert to UTC before storing and convert back to local-time before using them in your application.", "@coleifer thanks, indeed it started to work after I removed timezone information.\r\n\r\nThere is still a little problem with `dc.Message.date.month` though. Ordering algorythm treats it as if it was string. So the order now looks like: \"1\", \"10\", \"11\", \"12\", \"2\" etc. Is there some quick workaround?", "You should be able to cast as an integer. [Sqlite Cast docs](https://sqlite.org/lang_expr.html#castexpr):\r\n\r\n```python\r\nMyModel.select().order_by(MyModel.timestamp.month.cast('INTEGER'))\r\n```" ]
2018-01-30T15:46:14
2018-01-30T17:59:14
2018-01-30T15:58:23
NONE
null
Hi, I'm trying to extract month from `date` column in my database. [Just as it's shown here.](http://docs.peewee-orm.com/en/latest/peewee/models.html#datetimefield-datefield-and-timefield) Here is my code: ``` query = (dc.Message.select(dc.Message.date.month.alias('month')).limit(5)) for q in query: print(q.month) ``` And Message model: ``` class Message(BaseModel): text = CharField(null = True) created_by = ForeignKeyField(User) posted_in = ForeignKeyField(Chat) date = DateTimeField() ``` When I try to execute my code, I get this message in debug console: > peewee.OperationalError: user-defined function raised exception Do you have any ideas how to fix that?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1441/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1441/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1440
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1440/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1440/comments
https://api.github.com/repos/coleifer/peewee/issues/1440/events
https://github.com/coleifer/peewee/issues/1440
292,751,141
MDU6SXNzdWUyOTI3NTExNDE=
1,440
Peewee 3.0.2, what happened to `playhouse.test_utils.test_database`?
{ "login": "cLupus", "id": 2326244, "node_id": "MDQ6VXNlcjIzMjYyNDQ=", "avatar_url": "https://avatars.githubusercontent.com/u/2326244?v=4", "gravatar_id": "", "url": "https://api.github.com/users/cLupus", "html_url": "https://github.com/cLupus", "followers_url": "https://api.github.com/users/cLupus/followers", "following_url": "https://api.github.com/users/cLupus/following{/other_user}", "gists_url": "https://api.github.com/users/cLupus/gists{/gist_id}", "starred_url": "https://api.github.com/users/cLupus/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/cLupus/subscriptions", "organizations_url": "https://api.github.com/users/cLupus/orgs", "repos_url": "https://api.github.com/users/cLupus/repos", "events_url": "https://api.github.com/users/cLupus/events{/privacy}", "received_events_url": "https://api.github.com/users/cLupus/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "The functionality has been removed. You can instead use:\r\n\r\n* http://docs.peewee-orm.com/en/latest/peewee/api.html#Model.bind\r\n* http://docs.peewee-orm.com/en/latest/peewee/api.html#Model.bind_ctx\r\n\r\nThese methods allow you to bind a model (and optionally its relations) to a database.\r\n\r\nThe bind() method will not create the tables in the same way test_database did, as it is more generally useful for binding a graph of models to a different database, which is presumed to exist already.", "Thanks 😄 " ]
2018-01-30T11:39:12
2018-02-01T07:14:35
2018-01-30T15:17:22
NONE
null
Hi, The method `test_database` seem to have disappeared, and I can't find any references to it in the new documentation (or in the changes made). Is there a new way of doing the same, or has the functionality ben removed for good?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1440/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1440/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1439
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1439/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1439/comments
https://api.github.com/repos/coleifer/peewee/issues/1439/events
https://github.com/coleifer/peewee/issues/1439
292,698,452
MDU6SXNzdWUyOTI2OTg0NTI=
1,439
Peewee 3.0.2, what happened to `Selectquery.naive`?
{ "login": "csytan", "id": 16357, "node_id": "MDQ6VXNlcjE2MzU3", "avatar_url": "https://avatars.githubusercontent.com/u/16357?v=4", "gravatar_id": "", "url": "https://api.github.com/users/csytan", "html_url": "https://github.com/csytan", "followers_url": "https://api.github.com/users/csytan/followers", "following_url": "https://api.github.com/users/csytan/following{/other_user}", "gists_url": "https://api.github.com/users/csytan/gists{/gist_id}", "starred_url": "https://api.github.com/users/csytan/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/csytan/subscriptions", "organizations_url": "https://api.github.com/users/csytan/orgs", "repos_url": "https://api.github.com/users/csytan/repos", "events_url": "https://api.github.com/users/csytan/events{/privacy}", "received_events_url": "https://api.github.com/users/csytan/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Ah, thanks! I'll correct the oversight.\r\n\r\nIn 3.x you can use `.objects()` instead." ]
2018-01-30T08:51:59
2018-01-30T15:14:23
2018-01-30T15:14:23
NONE
null
Here are the docs from 2.7.0, but I see no mention of it in the 3.0.2 change log. http://docs.peewee-orm.com/en/2.7.0/peewee/api.html#SelectQuery.naive Thanks!
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1439/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1439/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1438
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1438/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1438/comments
https://api.github.com/repos/coleifer/peewee/issues/1438/events
https://github.com/coleifer/peewee/issues/1438
292,654,474
MDU6SXNzdWUyOTI2NTQ0NzQ=
1,438
MySQL query working in 2.10.2 not working in 3.0.2
{ "login": "J-Light", "id": 2544660, "node_id": "MDQ6VXNlcjI1NDQ2NjA=", "avatar_url": "https://avatars.githubusercontent.com/u/2544660?v=4", "gravatar_id": "", "url": "https://api.github.com/users/J-Light", "html_url": "https://github.com/J-Light", "followers_url": "https://api.github.com/users/J-Light/followers", "following_url": "https://api.github.com/users/J-Light/following{/other_user}", "gists_url": "https://api.github.com/users/J-Light/gists{/gist_id}", "starred_url": "https://api.github.com/users/J-Light/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/J-Light/subscriptions", "organizations_url": "https://api.github.com/users/J-Light/orgs", "repos_url": "https://api.github.com/users/J-Light/repos", "events_url": "https://api.github.com/users/J-Light/events{/privacy}", "received_events_url": "https://api.github.com/users/J-Light/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Can you share the code for constructing the query? Specifically, what arguments are you passing to the `.select()` method?", "@coleifer in both cases the querry is \r\n\r\n`temp_prods.select().where(mymodel.AosProducts.name==prd_name).get()`\r\n\r\nwhere,\r\n`temp_prods = database_products.select().where(database_products.aos_product_category << sub_cat)`", "Ahh, thanks.\r\n\r\nIn that case, since you're not altering the columns being selected, you do not need the call to `select()` on `temp_prods`:\r\n\r\n```python\r\ntemp_prods = database_products.select().where(database_products.aos_product_category << sub_cat)\r\nthe_obj = temp_prods.where(mymodel.AosProducts.name == prd_name).get()\r\n```\r\n\r\nWhen you are calling `select()` a 2nd time, it is clearing-out the initial (default) selection, which is to select all fields. Although this is a regression, I'm not too inclined to patch it since the behavior is only triggered by an unnecessary 2nd call to `select()`.", "Well, I went ahead and fixed it :)" ]
2018-01-30T05:06:25
2018-01-31T12:29:50
2018-01-31T12:29:50
NONE
null
I am using a MySQL database and my application is producing errors when upgrading to 3.0.2. The documented changed for v3 does not indicate the source of the error. The following query is in 3.0.2 is ``` ('SELECT FROM `aos_products` AS `t1` WHERE ((`t1`.`aos_product_category_id` IN (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)) AND (`t1`.`id` = %s))', ['999f7d89-7d6a-13d0-4ba7-59fdb9e5b973', '9a088851-891a-257c-9ca2-59fdb9ab4e97', '9a771edd-a87b-08e5-a194-59fdb9c48633', '9a7cfe07-37b2-d6c7-3628-59fdb976cc9f', '9a827bb0-25ce-13e7-4c01-59fdb93a947b', '9a880187-460e-2982-1461-59fdb939ac0a', '9a92f875-1fde-5252-ffd1-59fdb9d0d497', '9a987012-454d-f8f0-818c-59fdb91f46ad', '9a9dfd80-4ed4-33bc-1662-59fdb9c9715b', '9aa3f3f4-0503-cb3e-5c74-59fdb9444991', '9aa9769d-a20f-5c39-16af-59fdb926c3e0', '9b481dcb-e8a3-0407-ab28-59fdb9bced65', '9b4da0c1-c8be-3061-75fc-59fdb9bbdb69', '9b532305-5654-0402-a612-59fdb95fdc75', '9b58b06f-add2-ec75-e601-59fdb9c6eeca', '9b5ece23-af3a-d3ab-1a36-59fdb9e30fa8', '9b645650-4077-e7b9-d702-59fdb99ea4a7', '9b69d753-bc39-1f0f-ba36-59fdb90a4aa1', '9b6f675a-2a76-f352-db75-59fdb9851747', '9b753dc2-e403-501f-618c-59fdb991e122', '9b7ae386-2714-9f52-020c-59fdb96c3ede', '9c124a19-2c9f-fc5b-3110-59fdb928d43f', '9c1817c2-b6e4-7796-3ef1-59fdb9ed3dc7', '9c1da5be-8bf9-fbe6-080f-59fdb9c1e7c1', '9c23273c-ec8e-b976-fea9-59fdb923768b', '9c28acbb-9208-8f6d-abea-59fdb9bd3178', '9c3ee8d2-6e4a-1e4b-aab3-59fdb9ef16bb', '855651d1-178e-39ba-3c7e-59fdba4a1972']) ``` This results in the following error: ``` *** peewee.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 'FROM `aos_products` AS `t1` WHERE ((`t1`.`aos_product_category_id` IN ('999f7d89' at line 1") ``` Downgrading to 2.10.2 the same query is; ``` ('SELECT `t1`.`id`, `t1`.`aos_product_category_id`, `t1`.`assigned_user_id`, `t1`.`category`, `t1`.`contact_id`, `t1`.`cost`, `t1`.`cost_usdollar`, `t1`.`created_by`, `t1`.`currency_id`, `t1`.`date_entered`, `t1`.`date_modified`, `t1`.`deleted`, `t1`.`description`, `t1`.`maincode`, `t1`.`modified_user_id`, `t1`.`name`, `t1`.`part_number`, `t1`.`price`, `t1`.`price_usdollar`, `t1`.`product_image`, `t1`.`type`, `t1`.`url` FROM `aos_products` AS t1 WHERE ((`t1`.`aos_product_category_id` IN (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)) AND (`t1`.`id` = %s))', ['999f7d89-7d6a-13d0-4ba7-59fdb9e5b973', '9a088851-891a-257c-9ca2-59fdb9ab4e97', '9a771edd-a87b-08e5-a194-59fdb9c48633', '9a7cfe07-37b2-d6c7-3628-59fdb976cc9f', '9a827bb0-25ce-13e7-4c01-59fdb93a947b', '9a880187-460e-2982-1461-59fdb939ac0a', '9a92f875-1fde-5252-ffd1-59fdb9d0d497', '9a987012-454d-f8f0-818c-59fdb91f46ad', '9a9dfd80-4ed4-33bc-1662-59fdb9c9715b', '9aa3f3f4-0503-cb3e-5c74-59fdb9444991', '9aa9769d-a20f-5c39-16af-59fdb926c3e0', '9b481dcb-e8a3-0407-ab28-59fdb9bced65', '9b4da0c1-c8be-3061-75fc-59fdb9bbdb69', '9b532305-5654-0402-a612-59fdb95fdc75', '9b58b06f-add2-ec75-e601-59fdb9c6eeca', '9b5ece23-af3a-d3ab-1a36-59fdb9e30fa8', '9b645650-4077-e7b9-d702-59fdb99ea4a7', '9b69d753-bc39-1f0f-ba36-59fdb90a4aa1', '9b6f675a-2a76-f352-db75-59fdb9851747', '9b753dc2-e403-501f-618c-59fdb991e122', '9b7ae386-2714-9f52-020c-59fdb96c3ede', '9c124a19-2c9f-fc5b-3110-59fdb928d43f', '9c1817c2-b6e4-7796-3ef1-59fdb9ed3dc7', '9c1da5be-8bf9-fbe6-080f-59fdb9c1e7c1', '9c23273c-ec8e-b976-fea9-59fdb923768b', '9c28acbb-9208-8f6d-abea-59fdb9bd3178', '9c3ee8d2-6e4a-1e4b-aab3-59fdb9ef16bb', '855651d1-178e-39ba-3c7e-59fdba4a1972']) ```
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1438/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1438/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1437
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1437/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1437/comments
https://api.github.com/repos/coleifer/peewee/issues/1437/events
https://github.com/coleifer/peewee/issues/1437
292,638,736
MDU6SXNzdWUyOTI2Mzg3MzY=
1,437
Field name case sensitivity bug
{ "login": "rene-dev", "id": 707259, "node_id": "MDQ6VXNlcjcwNzI1OQ==", "avatar_url": "https://avatars.githubusercontent.com/u/707259?v=4", "gravatar_id": "", "url": "https://api.github.com/users/rene-dev", "html_url": "https://github.com/rene-dev", "followers_url": "https://api.github.com/users/rene-dev/followers", "following_url": "https://api.github.com/users/rene-dev/following{/other_user}", "gists_url": "https://api.github.com/users/rene-dev/gists{/gist_id}", "starred_url": "https://api.github.com/users/rene-dev/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/rene-dev/subscriptions", "organizations_url": "https://api.github.com/users/rene-dev/orgs", "repos_url": "https://api.github.com/users/rene-dev/repos", "events_url": "https://api.github.com/users/rene-dev/events{/privacy}", "received_events_url": "https://api.github.com/users/rene-dev/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Which peewee version are you using? Sorry--I suppose it's clear that you're using 3.x.", "I've replicated this locally using Postgres. Has to do with some bug in the code assigning column values to instance attributes. Will update and push a fix as soon as I have more info.", "Thank you so much for taking the time to report this issue, as this was a serious bug!! What happened was the code for constructing model instances was not translating the underlying column name back to the appropriate field name.\r\n\r\nI've pushed 3.0.3 to remedy the issue.", "Thanks! I was using 3.0.2" ]
2018-01-30T03:12:20
2018-01-31T05:14:26
2018-01-30T15:45:35
NONE
null
I have a field name which is uppercase, and the model looks like this: `foo = IntegerField(column_name='Foo', null=True)` for some reason the field is always None in the query result. however, if I change the model to lowercase: `foo = IntegerField(column_name='foo', null=True)` it works as expected. I ran the sql output manually, and it contained numbers instead of null. the sql query reflects the case of column_name string, and both queries work. according to the mysql docs field names are never case sensitive: https://dev.mysql.com/doc/refman/5.6/en/identifier-case-sensitivity.html the model was created with pwiz, and column_name reflects the case of the database, which I think is correct. as both queries work, there must be some bug in the result handling in peewee. Im using PyMySQL and python3.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1437/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1437/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1436
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1436/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1436/comments
https://api.github.com/repos/coleifer/peewee/issues/1436/events
https://github.com/coleifer/peewee/pull/1436
292,535,111
MDExOlB1bGxSZXF1ZXN0MTY1Nzk4Nzc0
1,436
Add base class rename
{ "login": "aconz2", "id": 3137597, "node_id": "MDQ6VXNlcjMxMzc1OTc=", "avatar_url": "https://avatars.githubusercontent.com/u/3137597?v=4", "gravatar_id": "", "url": "https://api.github.com/users/aconz2", "html_url": "https://github.com/aconz2", "followers_url": "https://api.github.com/users/aconz2/followers", "following_url": "https://api.github.com/users/aconz2/following{/other_user}", "gists_url": "https://api.github.com/users/aconz2/gists{/gist_id}", "starred_url": "https://api.github.com/users/aconz2/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/aconz2/subscriptions", "organizations_url": "https://api.github.com/users/aconz2/orgs", "repos_url": "https://api.github.com/users/aconz2/repos", "events_url": "https://api.github.com/users/aconz2/events{/privacy}", "received_events_url": "https://api.github.com/users/aconz2/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Cheers. This wasn't exactly a public API, but I guess it doesn't hurt to include it?", "Yea I just ran into this while upgrading some code so figured I would try to give others a heads up. I have some scripts that do consistency checks that totally reach in where they're not supposed to.\r\n\r\nThank you for your work!" ]
2018-01-29T19:42:53
2018-01-29T20:07:40
2018-01-29T19:43:51
CONTRIBUTOR
null
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1436/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1436/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/1436", "html_url": "https://github.com/coleifer/peewee/pull/1436", "diff_url": "https://github.com/coleifer/peewee/pull/1436.diff", "patch_url": "https://github.com/coleifer/peewee/pull/1436.patch", "merged_at": "2018-01-29T19:43:51" }
https://api.github.com/repos/coleifer/peewee/issues/1435
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1435/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1435/comments
https://api.github.com/repos/coleifer/peewee/issues/1435/events
https://github.com/coleifer/peewee/issues/1435
291,398,007
MDU6SXNzdWUyOTEzOTgwMDc=
1,435
Peewee Not Propagating Empty Select (i.e., all columns) in certain scenarios
{ "login": "logannc", "id": 2867206, "node_id": "MDQ6VXNlcjI4NjcyMDY=", "avatar_url": "https://avatars.githubusercontent.com/u/2867206?v=4", "gravatar_id": "", "url": "https://api.github.com/users/logannc", "html_url": "https://github.com/logannc", "followers_url": "https://api.github.com/users/logannc/followers", "following_url": "https://api.github.com/users/logannc/following{/other_user}", "gists_url": "https://api.github.com/users/logannc/gists{/gist_id}", "starred_url": "https://api.github.com/users/logannc/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/logannc/subscriptions", "organizations_url": "https://api.github.com/users/logannc/orgs", "repos_url": "https://api.github.com/users/logannc/repos", "events_url": "https://api.github.com/users/logannc/events{/privacy}", "received_events_url": "https://api.github.com/users/logannc/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Peewee, for simplicity, will treat \"default\" calls to `select()` as selecting all columns declared on that model. However, when a \"default\" query is used for a subquery, Peewee will only select that table's primary key. To work around this, you can explicitly select the columns you desire.\r\n\r\nAlternatively, could you write this as:\r\n\r\n```python\r\nPA = Post.alias()\r\nsubq = PA.select(PA.user, fn.MAX(PA.timestamp).alias('max_ts')).group_by(PA.user).alias('latest')\r\npredicate = (Post.user == subq.c.user_id) & (Post.timestamp == subq.c.max_ts)\r\nquery = (Post\r\n .select(Post, User)\r\n .join(subq, on=predicate)\r\n .switch(Post)\r\n .join(User))\r\n\r\nfor result in query:\r\n print(result.user.username, result.content)\r\n```", "I ended up coding this example up and writing some tests around it, but the main issues with the queries you've written is that you have not been explicit about what columns / models you are SELECT-ing.\r\n\r\nSo `latest_posts`, since it is a \"default\" SELECT and is used as a sub-query (in the join), Peewee thinks you only need the \"id\". To remedy this, change the SELECT to:\r\n\r\n```python\r\nlatest_posts = (Post\r\n .select(Post) # Note I just added \"Post\", indicating we want all columns.\r\n .join(max_sub, on = (Post.user == max_sub.c.user_id) & (Post.created_at == max_sub.max_date))\r\n .alias('latest'))\r\n```\r\n\r\nThen, in the outermost query, we will want to select all the columns on the User table presumably, as well as the relevant fields from the Post query we joined on:\r\n\r\n```python\r\nlatest_posts_by_user = (User\r\n .select(User, latest_posts.c.content, latest_posts.c.created_at)\r\n .join(latest_posts, on = User.id == latest_posts.c.user_id))\r\n```\r\n\r\nThat being said, this revealed a limitation of the code that reconstructs the model graph when iterating over the cursor. Hence the patch in 930fbef.\r\n\r\nAlso note that the alternative query I proposed should work fine as well.", "> However, when a \"default\" query is used for a subquery, Peewee will only select that table's primary key. \r\n\r\nThis is what I was missing. IMO, this is an API bug as it leads to different behaviour/SQL generation based purely on the context of the query. \r\n\r\nIf the behaviour is not changed, it should be more prominently mentioned as a drawback and/or the examples in the documentation should not demonstrate `select` with no parameters. For example, on http://docs.peewee-orm.com/en/latest/peewee/api.html#Model.select\r\n\r\n> selection – A list of model classes, field instances, functions or expressions. If no argument is provided, all columns for the given model will be selected.\r\n\r\n> Examples of selecting all columns (default):\r\n\r\n`User.select().where(User.active == True).order_by(User.username)`\r\n\r\nThis, and all other examples, should be changed to use `User.select(User).where(...)...` so that the documentation demonstrates queries that are properly context independent, which I think is people's default intuition when reasoning about these python objects. \r\n\r\nIf you think the behaviour should be changed, great. I might consider a PR but I'm not too familiar with the internals. Otherwise, I might take a stab at a PR updating the docs to phase out the empty select pattern.\r\n\r\n", "> This is what I was missing. IMO, this is an API bug as it leads to different behaviour/SQL generation based purely on the context of the query.\r\n\r\nIt is this way by design, not by accident, since most-commonly if you are using a subquery you will just be interested in the primary key. Furthermore, how is peewee supposed to know which fields you wish to actually select from the subquery unless you specify them, in this example?", "> since most-commonly if you are using a subquery you will just be interested in the primary key\r\n\r\nI disagree with this or, at the very least, am not convinced of it - I don't think either of us has the data needed to make a claim one way or the other. I mean, the pattern I demonstrated above is a very common one, I think, when you have foreign keys (literal DB FKs or just joining on non-primary key fields).\r\n\r\nIt can't know which columns. Which is, IMO, why it should default to all columns which *does* include the primary key. Including only the primary key seems like a premature optimization that isn't worth the quirk of `select()` being context dependent.\r\n\r\nBesides, what is the downside to defaulting to all columns everywhere, including subqueries? All queries should continue to work identically if they default to 'all columns' as they provide a superset of information. Even in the case I posed above, because I don't select the information in the outer most select none of the extra columns get sent over the network, the columns are just made available in the `on` predicate. Depending on the DB, the columns in the subquery select may not even be accessed by the DB if they aren't selected from the outer query or used in the `on` predicate - at least, I hope this occurs, it seems like a simple enough optimization.", "> I don't think either of us has the data needed to make a claim one way or the other.\r\n\r\nWell, I *have* been maintaining this project for 7 1/2 years, and this has always been the behavior of `select()`. I don't recall anyone else finding it confusing. Not that you're wrong -- but just that this hasn't struck anyone as confusing to the point of raising it as an issue.\r\n\r\n> Besides, what is the downside to defaulting to all columns everywhere, including subqueries? \r\n\r\nPotentially inefficient or slow queries when only the ID column would suffice. Specifically being able to take advantage of primary-key or covering indexes, which is quite fast.\r\n\r\nTypically I see subquery ID lookups when doing UPDATEs or DELETEs on databases that do not support JOINs on those types of queries.\r\n\r\nIt makes sense to me to optimize for the 80% case, but for the other 20% to follow a reasonable convention -- that is, explicitly specifying the columns you wish to select.", "> Well, I have been maintaining this project for 7 1/2 years [...]\r\n\r\nFair enough. :) I only know my experience. Maybe most of your users have different usage patterns than me or structure their queries/databases differently. ¯\\\\\\_(ツ)_/¯\r\n\r\n> Potentially inefficient or slow queries when only the ID column would suffice. Specifically being able to \r\ntake advantage of primary-key or covering indexes, which is quite fast.\r\n\r\nI'm not sure what you mean by this. Merely selecting additional columns *shouldn't* slow a query down.\r\n\r\n> Typically I see subquery ID lookups when doing UPDATEs or DELETEs on databases that do not support JOINs on those types of queries.\r\n\r\nSo, like, `Post.update(user = User.select().filter(name='Logan')).where(created_at > yesterday)` or something like that?\r\n\r\nI guess I can see the utility in this case. Though, my (flawed) intuition about peewee had led me to write queries like `Post.update(user = User.select(User.id).filter(name='Logan')).where(created_at > yesterday)` because I *thought* that an empty select would default `select all_declared` and I knew that would be incorrect. :)\r\n\r\n> It makes sense to me to optimize for the 80% case, but for the other 20% to follow a reasonable convention -- that is, explicitly specifying the columns you wish to select.\r\n\r\nI absolutely agree with the sentiment, and I think I even agree with the defaulting to primary key in the update/delete case, but with `select()`, I think the 80% case is actually to select everything. But I'm not sure how technically feasible that is to split the update/delete case from the select case or if I'm going to be able to convince you :)", "> Merely selecting additional columns shouldn't slow a query down.\r\n\r\nhttps://www.sqlite.org/queryplanner.html#_covering_indices\r\n\r\nFor queries, let's say you want to delete tweets by users with inactive accounts and cannot do a JOIN.\r\n\r\n```python\r\ninactive = User.select().where(User.active == False)\r\nTweet.delete().where(Tweet.user.in_(inactive)).execute()\r\n```\r\n\r\nIn general, it's always best to explicitly select what you need. I hardly ever use a bare call to `select()` except when testing stuff out in the shell. So the example in your update query is just fine because it's explicit.", "> https://www.sqlite.org/queryplanner.html#_covering_indices\r\n\r\n+1! Was not aware of these. Even so, if the extra columns are not used from the outer select, a where clause, or an on-predicate, the DB should be able to use the covering index still.\r\n\r\nLike, I said, I agree that in the update/delete case, defaulting to just the primary key is more useful.\r\n\r\nMy problem is that `inactive` is now context dependent. It represents two different SQL queries based on where it is used. This makes it much more difficult to reason about. In the update/delete case, I think the productivity trade off is worth it because the alternative (select all) doesn't even make sense.\r\n\r\nAnyway, if you don't think it's worth changing, I think it *is* worth updating the documentation to not use the naked select style `select()` or to make it more clear that it doesn't actually default to all columns all the time." ]
2018-01-24T23:29:50
2018-01-25T21:22:00
2018-01-25T04:11:16
NONE
null
I have not yet figured out why this is happening and there is a workaround that isn't very onerous, but I still thought I'd post this here. Imagine you have a couple tables, `User` and `Post`. **Post** | id | user_id | created_at | content | | -- | ---------- | -------------- | ---------- | | int | int | timestamp | varchar | **User** | id | name | | -- | -------- | | int | varchar | Imagine you wish to query a list of all Users and their latest post. This might look like: ``` PA = Post.alias() max_sub = ( PA .select(PA.user, peewee.fn.max(PA.created_at).alias('max_date')) .group_by(PA.user) .alias('max_sub') ) latest_posts = ( Post .select() .join(max_sub, on = (Post.user == max_sub.c.user_id) & (Post.created_at == max_sub.max_date)) .alias('latest') ) latest_posts_by_user = ( User .select() .join(latest_posts, on = User.id == latest_posts.c.user_id) ) ``` However, `latest_posts_by_user` generates the following flawed SQL: ``` select u1.id, u1.name from user as u1 inner join ( select p1.id from post as p1 inner join ( select p2.user_id, max(p2.created_at) as max_date from post as p2 group by p2.user_id) as max_sub on ((p1.user_id = max_sub.user_id) and (p1.created_at = max_sub.max_date)) ) as latest on (u1.id = latest.user_id) ``` Notice that this will fail because the `latest_posts` subquery has suddenly changed from selecting all columns to only selecting `id` - the join will fail because `latest.user_id` does not exist. This only occurs when it is a subquery. If you print out the sql for `latest_posts` outside of this context, it gives you the correct looking subquery selecting all columns in the Post table. A workaround is to simply specify in `latest_posts` which columns you need. This is not all that bad, but does defeat the purpose of what should be the equivalent of `select *`.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1435/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1435/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1434
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1434/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1434/comments
https://api.github.com/repos/coleifer/peewee/issues/1434/events
https://github.com/coleifer/peewee/issues/1434
291,351,594
MDU6SXNzdWUyOTEzNTE1OTQ=
1,434
Issue with insert_many - IndexError: pop from empty list
{ "login": "kelso6969", "id": 35543864, "node_id": "MDQ6VXNlcjM1NTQzODY0", "avatar_url": "https://avatars.githubusercontent.com/u/35543864?v=4", "gravatar_id": "", "url": "https://api.github.com/users/kelso6969", "html_url": "https://github.com/kelso6969", "followers_url": "https://api.github.com/users/kelso6969/followers", "following_url": "https://api.github.com/users/kelso6969/following{/other_user}", "gists_url": "https://api.github.com/users/kelso6969/gists{/gist_id}", "starred_url": "https://api.github.com/users/kelso6969/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/kelso6969/subscriptions", "organizations_url": "https://api.github.com/users/kelso6969/orgs", "repos_url": "https://api.github.com/users/kelso6969/repos", "events_url": "https://api.github.com/users/kelso6969/events{/privacy}", "received_events_url": "https://api.github.com/users/kelso6969/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Note: I edited your comment to include formatting. Please take the extra 15 seconds to format code properly when submitting issues.\r\n\r\nRegarding the issue, I am unable to replicate it:\r\n\r\n```python\r\n\r\nfrom peewee import *\r\n\r\ndb = SqliteDatabase(':memory:')\r\n\r\nclass Mtas2(Model):\r\n ad = CharField()\r\n agcid = IntegerField()\r\n as_ = CharField(column_name='as')\r\n dn = CharField()\r\n fqdn = CharField()\r\n npa = CharField()\r\n nxx = CharField()\r\n ps = CharField()\r\n timestamp = DateTimeField()\r\n\r\n class Meta:\r\n database = db\r\n table_name = 'MTAs2'\r\n\r\ndata = [{'dn': '0123456789',\r\n 'ps': 'UNA',\r\n 'ad': 'AALN/1',\r\n 'timestamp': '2018-01-24 12:34:57',\r\n 'npa': '0',\r\n 'nxx': '0',\r\n 'as_': 'ACT',\r\n 'agcid': '5',\r\n 'fqdn': 'pbt8rd7vy.mo.testing.net'},\r\n {'dn': '0123456780', 'ps': 'UNA', 'ad': 'AALN/1', 'timestamp': '2018-01-24 12:34:57', 'npa': '0', 'nxx': '0', 'as_': 'ACT', 'agcid': '5', 'fqdn': 'tdfbu4j8k.mo.testing.net'},\r\n {'dn': '0123456781', 'ps': 'UNA', 'ad': 'AALN/1', 'timestamp': '2018-01-24 12:34:57', 'npa': '0', 'nxx': '0', 'as_': 'ACT', 'agcid': '5', 'fqdn': 'bwwtujjrp.mo.testing.net'}]\r\n\r\ndb.create_tables([Mtas2])\r\n\r\nwith db.atomic():\r\n Mtas2.insert_many(data).execute()\r\n\r\nprint(Mtas2.select().count())\r\n# prints 3\r\n```", "The issue has to do with how you're handling transactions, by the way, and doesn't seem related to `insert_many()`. Are you explicitly committing, rolling back, or otherwise doing stuff with transactions?\r\n\r\nIf I cause the `insert_many()` call to fail, by the way, the exception is raised correctly -- I do not get the \"pop() from empty list\" error.", "Thank you and apologies.\r\n\r\nI would do individual inserts, but on the 18 objects im looping through, this count can be 2k to 10k records being inserted, so I need to use a bulk insert method.\r\n\r\nIf I try the method to insert x rows at a time\r\n\r\n```\r\nwith database.atomic():\r\n for idx in range(0, len(subs), 100):\r\n Mtas2.insert_many(Subs[idx:idx+100]).execute()\r\n```\r\nI get the following error\r\n```\r\nTraceback (most recent call last):\r\n File \"test.py\", line 172, in <module>\r\n Mtas2.insert_many(Subs[idx:idx+100]).execute()\r\n File \"/usr/local/lib/python2.7/dist-packages/peewee.py\", line 3147, in __exit__\r\n return self._helper.__exit__(exc_type, exc_val, exc_tb)\r\n File \"/usr/local/lib/python2.7/dist-packages/peewee.py\", line 3180, in __exit__\r\n self.rollback(False)\r\n File \"/usr/local/lib/python2.7/dist-packages/peewee.py\", line 3167, in rollback\r\n self.db.rollback()\r\n File \"/usr/local/lib/python2.7/dist-packages/peewee.py\", line 2528, in rollback\r\n return self._state.conn.rollback()\r\nAttributeError: 'NoneType' object has no attribute 'rollback'\r\n```\r\n\r\nShould I see if the problem persists with peewee 2?", "\" Are you explicitly committing, rolling back, or otherwise doing stuff with transactions?\" I'm not sure I understand. I'm essentially parsing a large soap response into XML and iterating over the results building this list.\r\n\r\nI'm not doing anything else with that table or records, so I'm not sure. My other querys to update and insert single records are working as expected.", "Oddly, I tested your example above and it works using sqlite to memory. Im using mysql otherwise as I have a PHP front end. I guess my next question would be, how to diagnose this further? I can send you my whole script if needed if you think it would help.", "Can you send me a minimal example that I can use to try and reproduce this? That's very odd that it works fine with SQLite and breaks under MySQL. Peewee 3.0a (and 2.x) is tested using a combination of Python versions and database backends, including MySQL so if things were broken I would expect to see test failures: https://travis-ci.org/coleifer/peewee/builds/332047787\r\n\r\nIf you've got a **minimal** example I can run to replicate that'd be fantastic. As it is, it appears the insert is failing for some reason. Instead of finding and rolling-back the transaction, though, it's running into an error when doing the rollback...which doesn't make sense why it would only occur with MySQL.", "OK, I use the example of yours above, and the only thing I change is the db string (and comment out the table create since it's there) and the error returns.\r\n\r\ndb = MySQLDatabase('myDB', **{'passwd': 'MyPass', 'charset': 'utf8', 'user': 'MyUser', 'use_unicode': True})\r\n\r\n\r\n\r\n```\r\n\r\nfrom peewee import *\r\n\r\ndb = MySQLDatabase('myDB', **{'passwd': 'MyPass', 'charset': 'utf8', 'user': 'MyUser', 'use_unicode': True})\r\n\r\n\r\nclass Mtas2(Model):\r\n ad = CharField()\r\n agcid = IntegerField()\r\n as_ = CharField(column_name='as')\r\n dn = CharField()\r\n fqdn = CharField()\r\n npa = CharField()\r\n nxx = CharField()\r\n ps = CharField()\r\n timestamp = DateTimeField()\r\n\r\n class Meta:\r\n database = db\r\n table_name = 'MTAs2'\r\n\r\ndata = [{'dn': '0123456789',\r\n 'ps': 'UNA',\r\n 'ad': 'AALN/1',\r\n 'timestamp': '2018-01-24 12:34:57',\r\n 'npa': '0',\r\n 'nxx': '0',\r\n 'as_': 'ACT',\r\n 'agcid': '5',\r\n 'fqdn': 'pbt8rd7vy.mo.testing.net'},\r\n {'dn': '0123456780', 'ps': 'UNA', 'ad': 'AALN/1', 'timestamp': '2018-01-24 12:34:57', 'npa': '0', 'nxx': '0', 'as_': 'ACT', 'agcid': '5', 'fqdn': 'tdfbu4j8k.mo.testing.net'},\r\n {'dn': '0123456781', 'ps': 'UNA', 'ad': 'AALN/1', 'timestamp': '2018-01-24 12:34:57', 'npa': '0', 'nxx': '0', 'as_': 'ACT', 'agcid': '5', 'fqdn': 'bwwtujjrp.mo.testing.net'}]\r\n\r\n#db.create_tables([Mtas2])\r\n\r\nwith db.atomic():\r\n Mtas2.insert_many(data).execute()\r\n\r\nprint(Mtas2.select().count())\r\n# prints 3\r\n```\r\n\r\nerror\r\n```\r\npython testmy.py\r\nTraceback (most recent call last):\r\n File \"testmy.py\", line 36, in <module>\r\n Mtas2.insert_many(data).execute()\r\n File \"/usr/local/lib/python2.7/dist-packages/peewee.py\", line 3147, in __exit__\r\n return self._helper.__exit__(exc_type, exc_val, exc_tb)\r\n File \"/usr/local/lib/python2.7/dist-packages/peewee.py\", line 3188, in __exit__\r\n self.db.pop_transaction()\r\n File \"/usr/local/lib/python2.7/dist-packages/peewee.py\", line 2500, in pop_transaction\r\n return self._state.transactions.pop()\r\nIndexError: pop from empty list\r\n```\r\n\r\nIn my other script .update().execute() works great, so does an individual .create()", "```\r\nCREATE TABLE IF NOT EXISTS `MTAs2` (\r\n `agcid` int(3) NOT NULL,\r\n `ad` varchar(7) NOT NULL,\r\n `fqdn` varchar(50) NOT NULL,\r\n `as` varchar(5) NOT NULL,\r\n `ps` varchar(5) NOT NULL,\r\n `dn` varchar(10) NOT NULL,\r\n `npa` varchar(3) NOT NULL,\r\n `nxx` varchar(3) NOT NULL,\r\n `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP\r\n) ENGINE=InnoDB DEFAULT CHARSET=latin1;\r\n```\r\n\r\nIf you need a quick table creation script, save you a few minutes.", "I feel stupid.\r\n\r\n```\r\ndb.connect()\r\n```\r\n\r\nadded this and it works.\r\n\r\nThanks and sorry for wasting your time. It's odd that updates and other inserts would work without that.", "That is odd, it probably should have failed in a different way, though - so as to make clear that the connection needs to be set-up before the transaction is opened.\r\n\r\nI'll fix." ]
2018-01-24T20:38:37
2018-01-24T22:08:58
2018-01-24T22:08:58
NONE
null
I'm getting this error: ``` Traceback (most recent call last): File "test.py", line 166, in <module> Mtas2.insert_many(subs).execute() File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 3147, in __exit__ return self._helper.__exit__(exc_type, exc_val, exc_tb) File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 3188, in __exit__ self.db.pop_transaction() File "/usr/local/lib/python2.7/dist-packages/peewee.py", line 2500, in pop_transaction return self._state.transactions.pop() IndexError: pop from empty list ``` I'm passing a list of dicts like this: ``` [{'dn': '0123456789', 'ps': 'UNA', 'ad': 'AALN/1', 'timestamp': '2018-01-24 12:34:57', 'npa': '0', 'nxx': '0', 'as_': 'ACT', 'agcid': '5', 'fqdn': 'pbt8rd7vy.mo.testing.net'}, {'dn': '0123456780', 'ps': 'UNA', 'ad': 'AALN/1', 'timestamp': '2018-01-24 12:34:57', 'npa': '0', 'nxx': '0', 'as_': 'ACT', 'agcid': '5', 'fqdn': 'tdfbu4j8k.mo.testing.net'}, {'dn': '0123456781', 'ps': 'UNA', 'ad': 'AALN/1', 'timestamp': '2018-01-24 12:34:57', 'npa': '0', 'nxx': '0', 'as_': 'ACT', 'agcid': '5', 'fqdn': 'bwwtujjrp.mo.testing.net'}] ``` Executing my insert like this ``` with database.atomic(): Mtas2.insert_many(subs).execute() ``` Model if needed ``` class Mtas2(BaseModel): ad = CharField() agcid = IntegerField() as_ = CharField(column_name='as') dn = CharField() fqdn = CharField() npa = CharField() nxx = CharField() ps = CharField() timestamp = DateTimeField() class Meta: table_name = 'MTAs2' ``` Lastly, using peewee (3.0.0)
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1434/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1434/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1433
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1433/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1433/comments
https://api.github.com/repos/coleifer/peewee/issues/1433/events
https://github.com/coleifer/peewee/issues/1433
291,310,526
MDU6SXNzdWUyOTEzMTA1MjY=
1,433
Oracle
{ "login": "darena-mdsol", "id": 14183609, "node_id": "MDQ6VXNlcjE0MTgzNjA5", "avatar_url": "https://avatars.githubusercontent.com/u/14183609?v=4", "gravatar_id": "", "url": "https://api.github.com/users/darena-mdsol", "html_url": "https://github.com/darena-mdsol", "followers_url": "https://api.github.com/users/darena-mdsol/followers", "following_url": "https://api.github.com/users/darena-mdsol/following{/other_user}", "gists_url": "https://api.github.com/users/darena-mdsol/gists{/gist_id}", "starred_url": "https://api.github.com/users/darena-mdsol/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/darena-mdsol/subscriptions", "organizations_url": "https://api.github.com/users/darena-mdsol/orgs", "repos_url": "https://api.github.com/users/darena-mdsol/repos", "events_url": "https://api.github.com/users/darena-mdsol/events{/privacy}", "received_events_url": "https://api.github.com/users/darena-mdsol/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Yep, peewee works well with DB-API 2.0 drivers. See docs:\r\n\r\nhttp://docs.peewee-orm.com/en/latest/peewee/database.html#adding-a-new-database-driver" ]
2018-01-24T18:20:47
2018-01-24T19:40:27
2018-01-24T19:40:27
NONE
null
Is it possible for configure cx_Oracle for accessing for oracle DB?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1433/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1433/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1432
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1432/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1432/comments
https://api.github.com/repos/coleifer/peewee/issues/1432/events
https://github.com/coleifer/peewee/issues/1432
291,224,565
MDU6SXNzdWUyOTEyMjQ1NjU=
1,432
Feature request: Get by primary key shorthand.
{ "login": "conqp", "id": 3766192, "node_id": "MDQ6VXNlcjM3NjYxOTI=", "avatar_url": "https://avatars.githubusercontent.com/u/3766192?v=4", "gravatar_id": "", "url": "https://api.github.com/users/conqp", "html_url": "https://github.com/conqp", "followers_url": "https://api.github.com/users/conqp/followers", "following_url": "https://api.github.com/users/conqp/following{/other_user}", "gists_url": "https://api.github.com/users/conqp/gists{/gist_id}", "starred_url": "https://api.github.com/users/conqp/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/conqp/subscriptions", "organizations_url": "https://api.github.com/users/conqp/orgs", "repos_url": "https://api.github.com/users/conqp/repos", "events_url": "https://api.github.com/users/conqp/events{/privacy}", "received_events_url": "https://api.github.com/users/conqp/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "This is already implemented in 3.0a." ]
2018-01-24T14:17:23
2018-01-24T17:10:02
2018-01-24T17:10:02
CONTRIBUTOR
null
I often want to get instances of models by the respective primary key value. It would be nice to have a short-hand for: def by_pk(pk_value): return Model.get(Model._meta.primary_key == pk_value) Hence, I suggest adding `__getitem__` to `BaseModel`: def __getitem__(self, pk_value): return self.get(self._meta.primary_key == pk_value) So we can use: try: record_with_pk_12 = Model[12] except DoesNotExist: print('No record with primary key 12.')
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1432/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1432/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1431
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1431/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1431/comments
https://api.github.com/repos/coleifer/peewee/issues/1431/events
https://github.com/coleifer/peewee/issues/1431
290,935,233
MDU6SXNzdWUyOTA5MzUyMzM=
1,431
pwiz not generating foreign key fields for postgres in public schema
{ "login": "TheCleric", "id": 547567, "node_id": "MDQ6VXNlcjU0NzU2Nw==", "avatar_url": "https://avatars.githubusercontent.com/u/547567?v=4", "gravatar_id": "", "url": "https://api.github.com/users/TheCleric", "html_url": "https://github.com/TheCleric", "followers_url": "https://api.github.com/users/TheCleric/followers", "following_url": "https://api.github.com/users/TheCleric/following{/other_user}", "gists_url": "https://api.github.com/users/TheCleric/gists{/gist_id}", "starred_url": "https://api.github.com/users/TheCleric/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/TheCleric/subscriptions", "organizations_url": "https://api.github.com/users/TheCleric/orgs", "repos_url": "https://api.github.com/users/TheCleric/repos", "events_url": "https://api.github.com/users/TheCleric/events{/privacy}", "received_events_url": "https://api.github.com/users/TheCleric/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "The `UnknownField` is part of the boilerplate -- it is included so that it is clear where a field was found that was not of a recognized type.\r\n\r\nAs far as why the foreign key is not being picked, I'm not sure. Under-the-hood, peewee uses the following query to get information from postgres about foreign keys:\r\n\r\n```sql\r\n\r\nSELECT\r\n kcu.column_name, ccu.table_name, ccu.column_name\r\n FROM information_schema.table_constraints AS tc\r\n JOIN information_schema.key_column_usage AS kcu\r\n ON (tc.constraint_name = kcu.constraint_name AND\r\n tc.constraint_schema = kcu.constraint_schema)\r\n JOIN information_schema.constraint_column_usage AS ccu\r\n ON (ccu.constraint_name = tc.constraint_name AND\r\n ccu.constraint_schema = tc.constraint_schema)\r\n WHERE\r\n tc.constraint_type = 'FOREIGN KEY' AND\r\n tc.table_name = '<the table name>' AND\r\n tc.table_schema ='public'\r\n```\r\n\r\nWhat happens when you run that query? You might try tweaking the WHERE clause (removing restrictions) to see if one of those expressions is causing the constraint not to be listed?", "For the following query:\r\n\r\n```sql\r\nSELECT\r\n kcu.column_name, ccu.table_name, ccu.column_name\r\n FROM information_schema.table_constraints AS tc\r\n JOIN information_schema.key_column_usage AS kcu\r\n ON (tc.constraint_name = kcu.constraint_name AND\r\n tc.constraint_schema = kcu.constraint_schema)\r\n JOIN information_schema.constraint_column_usage AS ccu\r\n ON (ccu.constraint_name = tc.constraint_name AND\r\n ccu.constraint_schema = tc.constraint_schema)\r\n WHERE\r\n tc.constraint_type = 'FOREIGN KEY' AND\r\n tc.table_name = 'Session' AND\r\n tc.table_schema ='public'\r\n```\r\n\r\nI get the following result:\r\n```\r\n column_name | table_name | column_name \r\n-------------+------------+-------------\r\n user_id | User | id\r\n```", "After digging into your query deeper I've discovered this is my issue. The table was created by one user, but the peewee code is accessing the postgres database via another user, and this other user somehow can't \"see\" the foreign key (even though they have full permissions to the database). I have no idea how to fix this, but in the end this is not a peewee issue; it's a permissions issue. Feel free to close. Sorry for wasting your time. Thanks for pointing me in the right direction.", "For anyone who comes after me. Here's what's happening (from the PostgreSQL documentation https://www.postgresql.org/docs/current/static/infoschema-constraint-column-usage.html):\r\n\r\nMy user can't see the foreign key created by the other user because when viewing the `constraint_column_usage` table:\r\n\r\n> Only those columns are shown that are contained in a table owned by a currently enabled role. For a check constraint, this view identifies the columns that are used in the check expression.\r\n\r\nI was able to get similar (though not exact) results via the following query which is not excluded from viewing other owners foreign keys:\r\n\r\n```sql\r\nSELECT\r\n kcu.column_name, pg_get_constraintdef(pgc.oid)\r\n FROM information_schema.table_constraints AS tc\r\n JOIN information_schema.key_column_usage AS kcu\r\n ON (tc.constraint_name = kcu.constraint_name AND\r\n tc.constraint_schema = kcu.constraint_schema)\r\n JOIN \r\n \t pg_catalog.pg_constraint AS pgc\r\n ON (pgc.conname = tc.constraint_name)\r\n JOIN pg_catalog.pg_namespace pgn\r\n \tON (pgn.oid = pgc.connamespace AND\r\n \t\tpgn.nspname = tc.constraint_schema)\r\n WHERE\r\n tc.constraint_type = 'FOREIGN KEY' AND\r\n tc.table_name = 'Session' AND\r\n tc.table_schema ='public';\r\n```\r\n\r\nResults in:\r\n```\r\n column_name | pg_get_constraintdef \r\n-------------+---------------------------------------------\r\n user_id | FOREIGN KEY (user_id) REFERENCES \"User\"(id)\r\n```\r\n\r\nPerhaps someone with better regex skills than I could massage this into an exact match of the output of the other query and we'd have a user-proof `get_foreign_keys()` function.", "Sorry for the multiple postings. I've finally got something that has the same output as your existing query without the permissions issues:\r\n\r\n```sql\r\nSELECT \r\n pgatt2.attname AS column_name, pgc.relname AS table_name, pgatt1.attname AS column_name\r\nFROM\r\n (SELECT \r\n unnest(pgcon.conkey) AS parent_id, unnest(pgcon.confkey) AS child_id, pgcon.confrelid, pgcon.conrelid\r\n FROM pg_catalog.pg_class pgc\r\n JOIN pg_catalog.pg_namespace pgn\r\n \tON (pgc.relnamespace = pgn.oid)\r\n JOIN pg_catalog.pg_constraint pgcon\r\n \tON (pgcon.conrelid = pgc.oid)\r\n WHERE\r\n pgc.relname = 'Session' AND\r\n pgn.nspname = 'public' AND\r\n pgcon.contype = 'f'\r\n ) AS meta\r\nJOIN pg_catalog.pg_attribute pgatt1\r\n\tON (pgatt1.attrelid = meta.confrelid AND\r\n\t\tpgatt1.attnum = meta.child_id)\r\nJOIN pg_catalog.pg_class pgc\r\n\tON (pgc.oid = meta.confrelid)\r\nJOIN pg_catalog.pg_attribute pgatt2\r\n\tON (pgatt2.attrelid = meta.conrelid AND\r\n\t\tpgatt2.attnum = meta.parent_id)\r\n```\r\n\r\nModifying my local copy of peewee.py with this query gets me what I'm expecting:\r\n\r\n```python\r\nfrom peewee import *\r\n\r\ndatabase = PostgresqlDatabase('agnos', **{'user': 'api_user'})\r\n\r\nclass UnknownField(object):\r\n def __init__(self, *_, **__): pass\r\n\r\nclass BaseModel(Model):\r\n class Meta:\r\n database = database\r\n\r\nclass User(BaseModel):\r\n createdate = DateTimeField()\r\n createuser = TextField()\r\n email = TextField(unique=True)\r\n firstname = TextField()\r\n lastname = TextField()\r\n modifydate = DateTimeField(null=True)\r\n modifyuser = TextField(null=True)\r\n password = TextField()\r\n\r\n class Meta:\r\n db_table = 'User'\r\n indexes = (\r\n (('email', 'password'), True),\r\n )\r\n\r\nclass Session(BaseModel):\r\n issuedate = DateTimeField()\r\n token = TextField(unique=True)\r\n user = ForeignKeyField(db_column='user_id', rel_model=User, to_field='id')\r\n validuntildate = DateTimeField()\r\n\r\n class Meta:\r\n db_table = 'Session'\r\n```\r\n\r\nWould you be willing to accept a pull request if I submitted this as a change to `get_foreign_key()`?", "Innnnnteresting! Thank you for digging so deeply into this issue. I recall a long time ago running into similar permissions deals relating to sequences and was baffled by it.\r\n\r\nLet me look at and understand this query. Provided it works without regressions I'm fine with merging a change.", "I've taken a look at the query, compared to the previous implementation I'm kind of leery of introducing the change. Presumably get_primary_keys(), get_columns() etc are subject to the same limitations as get_foreign_keys(). Ultimately this is a permissions issue inside the database, and presumably the query peewee uses currently is doing the appropriate thing? Might actually pass on accepting this change.", "I think the issue is localized to the `information_schema.constraint_column_usage` table permissions, and therefore only affects `get_foreign_keys()` as the other functions do not attempt to select from that table. In my personal opinion I would say that the proper way to do this is to work around postgres limitation because who creates a FK shouldn't matter to who can see that it exists, and could lead to issues later for a developer who isn't paying attention.\r\n\r\nAt the same time I could see your position, and would have hesitance swapping out code that seems to have been working fine because some random developer found a weird edge case. I guess I can always patch it locally to cover my needs.", "Think I'm going to pass on this patch, but will re-open if that changes in the future.", "I'm running into similar issues. The fix proposed by @TheCleric works for foreign keys within the same schema, but fails for foreign keys pointing to other schemas. \r\n\r\nDoes the pwiz script work for foreign key references across schemas?", "Not to my knowledge, no." ]
2018-01-23T17:54:22
2018-07-25T13:08:07
2018-02-05T16:14:41
NONE
null
I'm attempting to use pwiz to generate models based on my existing database tables and am having an issue where the generated models do not represent a foreign key that exists within the database. I found #1021 but it seems like that users problems are related to the schema they were using. I am using the public schema. In the interest of providing info I will run through some of the debug steps that you instructed that user to provide. I ran the following code to get what peewee thinks my foreign keys are: ```python for table in db.get_tables(): print db.get_foreign_keys(table) ``` And I got the following output: ``` [] [] ``` I used psql to inspect my tables like so: ``` agnos=# \d+ "User" Table "public.User" Column | Type | Collation | Nullable | Default | Storage | Stats target | Description ------------+-----------------------------+-----------+----------+------------------------------------+----------+--------------+------------- id | integer | | not null | nextval('"User_id_seq"'::regclass) | plain | | email | text | | not null | | extended | | password | text | | not null | | extended | | firstname | text | | not null | | extended | | lastname | text | | not null | | extended | | createdate | timestamp without time zone | | not null | | plain | | createuser | text | | not null | | extended | | modifydate | timestamp without time zone | | | | plain | | modifyuser | text | | | | extended | | Indexes: "User_pkey" PRIMARY KEY, btree (id) "User_email_key" UNIQUE CONSTRAINT, btree (email) "user_email_password_idx" UNIQUE, btree (email, password) Referenced by: TABLE ""Session"" CONSTRAINT "Session_user_id_fkey" FOREIGN KEY (user_id) REFERENCES "User"(id) agnos=# \d+ "Session" Table "public.Session" Column | Type | Collation | Nullable | Default | Storage | Stats target | Description ----------------+-----------------------------+-----------+----------+---------------------------------------+----------+--------------+------------- id | integer | | not null | nextval('"Session_id_seq"'::regclass) | plain | | user_id | integer | | not null | | plain | | token | text | | not null | | extended | | issuedate | timestamp without time zone | | not null | | plain | | validuntildate | timestamp without time zone | | not null | | plain | | Indexes: "Session_pkey" PRIMARY KEY, btree (id) "Session_token_key" UNIQUE CONSTRAINT, btree (token) Foreign-key constraints: "Session_user_id_fkey" FOREIGN KEY (user_id) REFERENCES "User"(id) ``` For reference here is what I get when I run pwiz against this database: ```python from peewee import * database = PostgresqlDatabase('agnos', **{'user': 'api_user'}) class UnknownField(object): def __init__(self, *_, **__): pass class BaseModel(Model): class Meta: database = database class Session(BaseModel): issuedate = DateTimeField() token = TextField(unique=True) user = IntegerField(db_column='user_id') validuntildate = DateTimeField() class Meta: db_table = 'Session' class User(BaseModel): createdate = DateTimeField() createuser = TextField() email = TextField(unique=True) firstname = TextField() lastname = TextField() modifydate = DateTimeField(null=True) modifyuser = TextField(null=True) password = TextField() class Meta: db_table = 'User' indexes = ( (('email', 'password'), True), ) ``` As you can see the `user` field of the `Session` class is just being set to an `IntegerField` whereas I would expect it to be something similar to `ForeignKeyField(User)`. I'm also confused why it is creating the UnknownField at the top, but I can live with that. Please let me know any other information I can provide to help diagnose this issue.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1431/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1431/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1430
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1430/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1430/comments
https://api.github.com/repos/coleifer/peewee/issues/1430/events
https://github.com/coleifer/peewee/issues/1430
290,654,227
MDU6SXNzdWUyOTA2NTQyMjc=
1,430
Trouble compiling and running peewee with speedups
{ "login": "cLupus", "id": 2326244, "node_id": "MDQ6VXNlcjIzMjYyNDQ=", "avatar_url": "https://avatars.githubusercontent.com/u/2326244?v=4", "gravatar_id": "", "url": "https://api.github.com/users/cLupus", "html_url": "https://github.com/cLupus", "followers_url": "https://api.github.com/users/cLupus/followers", "following_url": "https://api.github.com/users/cLupus/following{/other_user}", "gists_url": "https://api.github.com/users/cLupus/gists{/gist_id}", "starred_url": "https://api.github.com/users/cLupus/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/cLupus/subscriptions", "organizations_url": "https://api.github.com/users/cLupus/orgs", "repos_url": "https://api.github.com/users/cLupus/repos", "events_url": "https://api.github.com/users/cLupus/events{/privacy}", "received_events_url": "https://api.github.com/users/cLupus/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Not sure... you might try Peewee 3.0a?", "Tests passed fine for me, for what it's worth.", "I've now tried the same with 3.0a (0914cee).\r\nThe test above now succeeds, however now there are two new failures:\r\n\r\n\r\n```\r\nUnable to import sqlite C extension tests, skipping.\r\nUnable to import postgres extension tests, skipping.\r\nUnable to import SQLCipher extension tests, skipping.\r\nUnable to import sqlite extension tests, skipping.\r\n...........................................................................................................................................................................................................................................................................FF...........................................................................................................................\r\n======================================================================\r\nFAIL: test_assert_query_count_ctx_mgr (tests.test_utils.TestQueryCounter)\r\n----------------------------------------------------------------------\r\nTraceback (most recent call last):\r\n File \"/***/build/peewee-3.0a/tests/test_utils.py\", line 89, in test_assert_query_count_ctx_mgr\r\n self.assertRaises(AssertionError, will_fail)\r\nAssertionError: AssertionError not raised by will_fail\r\n\r\n======================================================================\r\nFAIL: test_assert_query_count_decorator (tests.test_utils.TestQueryCounter)\r\n----------------------------------------------------------------------\r\nTraceback (most recent call last):\r\n File \"/***/build/peewee-3.0a/tests/test_utils.py\", line 77, in test_assert_query_count_decorator\r\n self.assertRaises(AssertionError, will_fail_under)\r\nAssertionError: AssertionError not raised by will_fail_under\r\n\r\n----------------------------------------------------------------------\r\nRan 392 tests in 6.292s\r\n\r\nFAILED (failures=2)\r\n```\r\n\r\nIn both cases the command\r\n```\r\n$PYTHON setup.py build_ext \\\r\n && $PYTHON setup.py build \\\r\n && $PYTHON setup.py install \\\r\n && $PYTHON runtests.py\r\n```\r\n\r\nwas run\r\n" ]
2018-01-22T23:26:04
2018-01-24T16:13:47
2018-01-23T17:15:31
NONE
null
Hi, After building peewee with python and the SQLite extension speed ups, I get the following error when running the tests. ``` FAIL: test_regexp (playhouse.tests.test_fields.TestFieldTypes) ---------------------------------------------------------------------- Traceback (most recent call last): File "/***/build/peewee-2.10.2/playhouse/tests/test_fields.py", line 377, in test_regexp assertValues('^ab', 'abcdefg', 'abcd') File "/***/build/peewee-2.10.2/playhouse/tests/test_fields.py", line 375, in assertValues self.assertEqual(values, list(expected)) AssertionError: Lists differ: [] != ['abcdefg', 'abcd'] Second list contains 2 additional elements. First extra element 0: 'abcdefg' - [] + ['abcdefg', 'abcd'] ---------------------------------------------------------------------- Ran 383 tests in 5.393s FAILED (failures=1) ``` Any tips?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1430/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1430/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1429
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1429/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1429/comments
https://api.github.com/repos/coleifer/peewee/issues/1429/events
https://github.com/coleifer/peewee/issues/1429
290,352,672
MDU6SXNzdWUyOTAzNTI2NzI=
1,429
multi query slow
{ "login": "m358807551", "id": 14256423, "node_id": "MDQ6VXNlcjE0MjU2NDIz", "avatar_url": "https://avatars.githubusercontent.com/u/14256423?v=4", "gravatar_id": "", "url": "https://api.github.com/users/m358807551", "html_url": "https://github.com/m358807551", "followers_url": "https://api.github.com/users/m358807551/followers", "following_url": "https://api.github.com/users/m358807551/following{/other_user}", "gists_url": "https://api.github.com/users/m358807551/gists{/gist_id}", "starred_url": "https://api.github.com/users/m358807551/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/m358807551/subscriptions", "organizations_url": "https://api.github.com/users/m358807551/orgs", "repos_url": "https://api.github.com/users/m358807551/repos", "events_url": "https://api.github.com/users/m358807551/events{/privacy}", "received_events_url": "https://api.github.com/users/m358807551/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "This is the most ludicrous and unrealistic ticket I've seen in a long time. There's no reason you should write your code in this way, in my opinion.\r\n\r\nIf you want to get `None` for the missing values, then you could do something like this:\r\n\r\n```python\r\nquery = ModelClass.select().order_by(ModelClass.id)\r\n\r\nlast_id = current_id = 0\r\nmissing_ids = []\r\nfor obj in query:\r\n current_id = obj.id\r\n if current_id != last_id + 1:\r\n missing_ids.extend(range(last_id, current_id))\r\n last_id = current_id\r\n```\r\n\r\nDoes that make sense?", "Thanks for reply.\r\nYour suggestion would work in most cases, but in my case, the table has millions of rows, and I do not think putting all of them in memory is a good idea.\r\nWhat I need is a function like `def get_models_by_ids(ids): ...`, and when the given id is not found in the table, get a `None` instead.\r\nAnd I finally found a not elegant way:\r\n```\r\ndef get_models_by_ids(given_ids):\r\n query = ModelClass.select().where(ModelClass.id << given_ids)\r\n id2model = {model.id: model for model in query}\r\n models = [id2model.get(id_) for id_ in given_ids]\r\n return models\r\n```\r\nIt is ugly but it really worked. Does peewee have a better way to do things like that? May be it's ludicrous, but I really need a function like that.", "Peewee can be made to use less RAM when iterating over large result-sets by chaining a call to `.iterator()` in your query:\r\n\r\n```python\r\nquery = ModelClass.select().order_by(ModelClass.id).iterator()\r\n\r\nlast_id = current_id = 0\r\nmissing_ids = []\r\nfor obj in query:\r\n current_id = obj.id\r\n if current_id != last_id + 1:\r\n missing_ids.extend(range(last_id, current_id))\r\n last_id = current_id\r\n```\r\n\r\nThe solution you've commented should work fine, too, of course.\r\n\r\nPeewee doesn't include anything like what you're asking for, no.", "Thanks for your explanation" ]
2018-01-22T05:10:57
2018-01-23T01:44:06
2018-01-22T05:30:08
NONE
null
I have thousands of ids for a table,and I want to query model one by one by use `xxx.select().filter(id==id).first()` in a for loop(not used `>>` operator because if the given id not exist in the table, I want to get None), but this way need thousands of db query and the huge total time() is unacceptable. I need the query result is in order and be None if the given id not found in the table, of course as fast as possible, anyone has some good ideas?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1429/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1429/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1428
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1428/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1428/comments
https://api.github.com/repos/coleifer/peewee/issues/1428/events
https://github.com/coleifer/peewee/issues/1428
290,171,657
MDU6SXNzdWUyOTAxNzE2NTc=
1,428
Default index for Fields
{ "login": "tomako", "id": 1412056, "node_id": "MDQ6VXNlcjE0MTIwNTY=", "avatar_url": "https://avatars.githubusercontent.com/u/1412056?v=4", "gravatar_id": "", "url": "https://api.github.com/users/tomako", "html_url": "https://github.com/tomako", "followers_url": "https://api.github.com/users/tomako/followers", "following_url": "https://api.github.com/users/tomako/following{/other_user}", "gists_url": "https://api.github.com/users/tomako/gists{/gist_id}", "starred_url": "https://api.github.com/users/tomako/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/tomako/subscriptions", "organizations_url": "https://api.github.com/users/tomako/orgs", "repos_url": "https://api.github.com/users/tomako/repos", "events_url": "https://api.github.com/users/tomako/events{/privacy}", "received_events_url": "https://api.github.com/users/tomako/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Fixed, thanks for bringing this to my attention (and sorry for the confusion it caused)." ]
2018-01-20T07:04:10
2018-01-21T04:34:42
2018-01-21T04:34:24
NONE
null
Most of the Fields have `index=False` by default. But there are few exceptions in postgres_ext package like ArrayField, BinaryJSONField, HStoreField, TSVectorField where this changed and they get `index=True` silently. I'm saying silently because I haven't seen in the doc and noticed that only later. Maybe our case is not a regular case because we don't need index for a BinaryJSONField field. But it was generated and was huge. Though it seems logical to add index to these fields but changing the default behavior (comparing to other Fields) can be confusing. Maybe a highlighted notice in the doc could help preventing such cases.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1428/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1428/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1427
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1427/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1427/comments
https://api.github.com/repos/coleifer/peewee/issues/1427/events
https://github.com/coleifer/peewee/issues/1427
289,999,614
MDU6SXNzdWUyODk5OTk2MTQ=
1,427
SQLite datetime field is str after save
{ "login": "lucasrc", "id": 441976, "node_id": "MDQ6VXNlcjQ0MTk3Ng==", "avatar_url": "https://avatars.githubusercontent.com/u/441976?v=4", "gravatar_id": "", "url": "https://api.github.com/users/lucasrc", "html_url": "https://github.com/lucasrc", "followers_url": "https://api.github.com/users/lucasrc/followers", "following_url": "https://api.github.com/users/lucasrc/following{/other_user}", "gists_url": "https://api.github.com/users/lucasrc/gists{/gist_id}", "starred_url": "https://api.github.com/users/lucasrc/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/lucasrc/subscriptions", "organizations_url": "https://api.github.com/users/lucasrc/orgs", "repos_url": "https://api.github.com/users/lucasrc/repos", "events_url": "https://api.github.com/users/lucasrc/events{/privacy}", "received_events_url": "https://api.github.com/users/lucasrc/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "I don't know what you're talking about:\r\n\r\n```python\r\nIn [1]: from peewee import *\r\n\r\nIn [2]: db = SqliteDatabase(':memory:')\r\n\r\nIn [3]: class Test(Model):\r\n ...: date = DateTimeField()\r\n ...: class Meta:\r\n ...: database = db\r\n ...: \r\n\r\nIn [4]: Test.create_table()\r\n\r\nIn [5]: t = Test(date=datetime.datetime.now())\r\n\r\nIn [6]: t.save()\r\nOut[6]: 1\r\n\r\nIn [7]: Test.get().date\r\nOut[7]: datetime.datetime(2018, 1, 19, 9, 5, 6, 364642)\r\n```", "Sorry I found the error: Its a timezone. In postgress works very well\r\n\r\nimport datetime\r\n\r\nfrom peewee import SqliteDatabase, Model, DateTimeField\r\n\r\nfrom pytz import timezone\r\n\r\neastern = timezone('US/Eastern')\r\ndb = SqliteDatabase(':memory:')\r\n\r\n\r\nclass Test(Model):\r\n\r\n class Meta:\r\n database = db\r\n\r\n date = DateTimeField()\r\n\r\n\r\nTest.create_table()\r\nTest(date=datetime.datetime.now(tz=eastern)).save()\r\n\r\ntest = Test.get()\r\nassert isinstance(test.date, datetime.datetime)\r\n\r\nTraceback (most recent call last):\r\n File \"test_peewee.py\", line 24, in <module>\r\n assert isinstance(test.date, datetime.datetime)\r\nAssertionError", "A-ha, thanks @lucasrc ... So SQLite does not have a native datetime column type (just text, blob, int, float and null). Because of this datetimes are stored in lexicographically-sortable strings (YYYY-mm-dd HH:MM:SS.ffffff by default). When Peewee pulls data out of the db, it attempts to convert the string into a datetime using a list of supported formats.\r\n\r\nWhen a timezone is included, the format becomes YYYY-mm-dd HH:MM:SS.ffffff-ZH:ZM -- which is not among the supported formats. Failing to convert to datetime, peewee just returns the string.\r\n\r\nTo support timezones with SQLite, you might (untested, beware):\r\n\r\n```python\r\nclass DateTimeTZField(DateTimeField):\r\n def python_value(self, value):\r\n if value is None: return\r\n datetime_str, zone = value.rsplit(' ', 1) # Expected YYYY-mm-dd HH:MM:SS.ffffff ZZZZ\r\n val = datetime.datetime.strptime(datetime_str, '%Y-%m-%d %H:%M:%S.%f')\r\n if zone.startswith('-'):\r\n mult = -1\r\n zone = zone[1:]\r\n else:\r\n mult = 1\r\n zh, zm = int(zone[:2]), int(zone[2:])\r\n offset = FixedOffset(mult * (zh * 60 + zm))\r\n return val.replace(tzinfo=offset)\r\n\r\n def db_value(self, value):\r\n return value.strftime('%Y-%m-%d %H:%M:%S.%f %z') if value else None\r\n```\r\n\r\nI think in 3.2 you can use %z with strptime, but since Peewee supports 2.7 I don't think that behavior can be relied upon.", "As I was thinking -- you know, using timezones will **break** lexicographic sorting. **You're best off converting everything to UTC and storing it as a naive datetime.**", "Thanks man for explanaition" ]
2018-01-19T14:49:57
2018-01-19T19:49:20
2018-01-19T15:05:38
NONE
null
class Customer(BaseModel): date_test = DateTimeField() Customer(date_test=now()).save() customer = Customer.get() customer.date_test # is a str now not datetime obj
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1427/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1427/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1426
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1426/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1426/comments
https://api.github.com/repos/coleifer/peewee/issues/1426/events
https://github.com/coleifer/peewee/issues/1426
289,855,827
MDU6SXNzdWUyODk4NTU4Mjc=
1,426
Cause a error when using join
{ "login": "cfk1996", "id": 24725783, "node_id": "MDQ6VXNlcjI0NzI1Nzgz", "avatar_url": "https://avatars.githubusercontent.com/u/24725783?v=4", "gravatar_id": "", "url": "https://api.github.com/users/cfk1996", "html_url": "https://github.com/cfk1996", "followers_url": "https://api.github.com/users/cfk1996/followers", "following_url": "https://api.github.com/users/cfk1996/following{/other_user}", "gists_url": "https://api.github.com/users/cfk1996/gists{/gist_id}", "starred_url": "https://api.github.com/users/cfk1996/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/cfk1996/subscriptions", "organizations_url": "https://api.github.com/users/cfk1996/orgs", "repos_url": "https://api.github.com/users/cfk1996/repos", "events_url": "https://api.github.com/users/cfk1996/events{/privacy}", "received_events_url": "https://api.github.com/users/cfk1996/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Why is `category_id` not a `ForeignKeyField`?\r\n\r\n```python\r\nclass CsArticle(MyBaseModel):\r\n ...\r\n category = ForeignKeyField(Category) # This will work instead of category_id field.\r\n```\r\n\r\nAfter that, your \".alias()\" needs to apply to the \"on\" expression...not the query as a whole:\r\n\r\n```python\r\n.join(\r\n Category,\r\n on=(CsArticle.category_id == Category.id).alias('cate')) # Note parentheses.\r\n```" ]
2018-01-19T03:58:28
2018-01-19T15:04:02
2018-01-19T15:04:02
NONE
null
## These are my models: ```python class MyBaseModel(Model): class Meta: database = db class Category(MyBaseModel): category_name = CharField(null=False, unique=True) class CsArticle(MyBaseModel): title = CharField(null=False, unique=True) md = TextField(null=False) html = TextField(null=False) date = DateField(null=False) category_id = IntegerField(null=False) number = IntegerField(null=False, default=0) ``` ## When I do this query: ```python datas = ( CsArticle .select(CsArticle, Category) .join( Category, on=(CsArticle.category_id == Category.id)).alias('cate') .order_by(CsArticle.date.desc())) response.append({'title': data.title, 'category': data.cate.category_name, 'date': data.date, 'id': data.id, 'number': data.number}) ``` ## It's caused such error: `File "/python-code/kunkun_blog/reader_request/article_list.py", line 44, in _get_cs_list 'category': data.cate.category_name, AttributeError: 'CsArticle' object has no attribute 'cate'`
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1426/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1426/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1425
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1425/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1425/comments
https://api.github.com/repos/coleifer/peewee/issues/1425/events
https://github.com/coleifer/peewee/issues/1425
289,580,554
MDU6SXNzdWUyODk1ODA1NTQ=
1,425
pwiz does not generate related_name argument
{ "login": "simopal6", "id": 4355487, "node_id": "MDQ6VXNlcjQzNTU0ODc=", "avatar_url": "https://avatars.githubusercontent.com/u/4355487?v=4", "gravatar_id": "", "url": "https://api.github.com/users/simopal6", "html_url": "https://github.com/simopal6", "followers_url": "https://api.github.com/users/simopal6/followers", "following_url": "https://api.github.com/users/simopal6/following{/other_user}", "gists_url": "https://api.github.com/users/simopal6/gists{/gist_id}", "starred_url": "https://api.github.com/users/simopal6/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/simopal6/subscriptions", "organizations_url": "https://api.github.com/users/simopal6/orgs", "repos_url": "https://api.github.com/users/simopal6/repos", "events_url": "https://api.github.com/users/simopal6/events{/privacy}", "received_events_url": "https://api.github.com/users/simopal6/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "The related_name (backref in 3.0) is a property that only exists in python/peewee. It's not an actual database thing, just a convenient way to reference the set of referenced objects. What would you expect to happen?", "Sorry, I wasn't very clear. I have two tables, `video` and `frame` (as in \"a video has many frames\"), with a foreign key constraint defined on `frame.videoid`.\r\n\r\nWhen I run `pwiz`, it creates the models and adds the `ForeignKeyField` to the generated `Frame` class. However, no `related_name` argument is passed to `ForeignKeyField`, so I'm unable to easily access the frames associated to a given video from a `Video` model instance.\r\n\r\nOf course I can easily modify the generated code and add the `related_name` argument myself, but I was wondering how come `pwiz` doesn't do it by itself.", "The `related_name` isn't explicitly defined because, if the user wants to use a non-default `related_name` pwiz has no way of anticipating what that might be.\r\n\r\nThe default related name/backref is \"modelname_set\", so in your case it would be `Frame.video_set` by default.\r\n\r\nIf you want something different then you'll of course need to edit the generated code.", "Ok, I see now. I didn't know that a default attribute on the \"other\" model would be created even without specifying `related_name` (I'm not sure this is documented). Thank you for your help!" ]
2018-01-18T10:37:42
2018-01-18T17:29:25
2018-01-18T17:13:36
NONE
null
As in the title, pwiz does not seem to use the `related_name` attribute on `ForeignKeyField`s. Is this expected? And is there a way to force it to do it?
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1425/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1425/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1424
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1424/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1424/comments
https://api.github.com/repos/coleifer/peewee/issues/1424/events
https://github.com/coleifer/peewee/issues/1424
289,023,051
MDU6SXNzdWUyODkwMjMwNTE=
1,424
Compute COUNT of a RawQuery
{ "login": "vadimkantorov", "id": 1041752, "node_id": "MDQ6VXNlcjEwNDE3NTI=", "avatar_url": "https://avatars.githubusercontent.com/u/1041752?v=4", "gravatar_id": "", "url": "https://api.github.com/users/vadimkantorov", "html_url": "https://github.com/vadimkantorov", "followers_url": "https://api.github.com/users/vadimkantorov/followers", "following_url": "https://api.github.com/users/vadimkantorov/following{/other_user}", "gists_url": "https://api.github.com/users/vadimkantorov/gists{/gist_id}", "starred_url": "https://api.github.com/users/vadimkantorov/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/vadimkantorov/subscriptions", "organizations_url": "https://api.github.com/users/vadimkantorov/orgs", "repos_url": "https://api.github.com/users/vadimkantorov/repos", "events_url": "https://api.github.com/users/vadimkantorov/events{/privacy}", "received_events_url": "https://api.github.com/users/vadimkantorov/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "What about:\r\n\r\n```python\r\nsql = \"my crazy query\"\r\ncount_sql = \"select count 1 from %s as _\" % sql\r\ncount, = db.execute_sql(count_sql).fetchone()\r\n```", "Closing due to no response." ]
2018-01-16T19:11:52
2018-01-18T17:13:57
2018-01-18T17:13:57
NONE
null
I have a complex raw query with joins, but I'm interested only in the number of rows in the result set. For now my workaround is: `len(list(MyModel.raw('SELECT obj.id FROM MyModel obj ...')))` but it's not very elegant and allocates objects uselessly. Attempts like `MyModel.raw('SELECT COUNT(*) FROM MyModel obj ....').scalar()` (always returns 1) or `MyModel.raw('SELECT obj.id FROM MyModel obj ....').count()`, or `len(MyModel.raw('SELECT obj.id FROM MyModel obj ...'))` have failed. Thanks!
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1424/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1424/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1423
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1423/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1423/comments
https://api.github.com/repos/coleifer/peewee/issues/1423/events
https://github.com/coleifer/peewee/issues/1423
288,921,406
MDU6SXNzdWUyODg5MjE0MDY=
1,423
[Proposal] Decoratorsfor fields conversion
{ "login": "gugadev", "id": 22750424, "node_id": "MDQ6VXNlcjIyNzUwNDI0", "avatar_url": "https://avatars.githubusercontent.com/u/22750424?v=4", "gravatar_id": "", "url": "https://api.github.com/users/gugadev", "html_url": "https://github.com/gugadev", "followers_url": "https://api.github.com/users/gugadev/followers", "following_url": "https://api.github.com/users/gugadev/following{/other_user}", "gists_url": "https://api.github.com/users/gugadev/gists{/gist_id}", "starred_url": "https://api.github.com/users/gugadev/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/gugadev/subscriptions", "organizations_url": "https://api.github.com/users/gugadev/orgs", "repos_url": "https://api.github.com/users/gugadev/repos", "events_url": "https://api.github.com/users/gugadev/events{/privacy}", "received_events_url": "https://api.github.com/users/gugadev/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "@gugadev -- That's invalid syntax.\r\n\r\nYour example `to_base64` decorator -- do you intend that to be implemented in Python or is that a function provided by your database? Is this feature intended to be bi-directional, i.e.:\r\n\r\n```python\r\nwith open('image-file.jpg', 'rb') as fh:\r\n raw_data = fh.read()\r\n\r\nuser = User()\r\nuser.photo = raw_data\r\nuser.save() # Is the photo data converted to base64 before sending it to the database?\r\n\r\nuser_from_db = User.get(User.id == 1)\r\ndata = user.photo # When accessing the property for reading, is the raw data returned, or base64?\r\n```\r\n\r\nI don't think your proposal is very well thought out.\r\n\r\nIf you're looking to apply a function to the data before writing/after reading, please check out this document:\r\n\r\nhttp://docs.peewee-orm.com/en/latest/peewee/models.html#creating-a-custom-field" ]
2018-01-16T14:14:42
2018-01-18T17:18:57
2018-01-18T17:18:57
NONE
null
First, congratz to the team for your excelent work. Should be nice have the option to convert automatically a field when the ORM fetchs data or call some property. For example, this model have a BLOB field: ```python class User(BaseModel): @to_base64 # this fn converts the binary to base64 on property call photo = BlobField() ``` When you get an user and call `.photo` property, the decorators is executed and you get the base64 representation. This could be useful when serialize a model to JSON, for example. Could this be feasible? Thanks for reading.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1423/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1423/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1422
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1422/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1422/comments
https://api.github.com/repos/coleifer/peewee/issues/1422/events
https://github.com/coleifer/peewee/issues/1422
288,220,838
MDU6SXNzdWUyODgyMjA4Mzg=
1,422
cast not supported
{ "login": "ra-esmith", "id": 24212262, "node_id": "MDQ6VXNlcjI0MjEyMjYy", "avatar_url": "https://avatars.githubusercontent.com/u/24212262?v=4", "gravatar_id": "", "url": "https://api.github.com/users/ra-esmith", "html_url": "https://github.com/ra-esmith", "followers_url": "https://api.github.com/users/ra-esmith/followers", "following_url": "https://api.github.com/users/ra-esmith/following{/other_user}", "gists_url": "https://api.github.com/users/ra-esmith/gists{/gist_id}", "starred_url": "https://api.github.com/users/ra-esmith/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/ra-esmith/subscriptions", "organizations_url": "https://api.github.com/users/ra-esmith/orgs", "repos_url": "https://api.github.com/users/ra-esmith/repos", "events_url": "https://api.github.com/users/ra-esmith/events{/privacy}", "received_events_url": "https://api.github.com/users/ra-esmith/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Cast is now just a method call:\r\n\r\n```python\r\n\r\nexpression = column.cast('text').contains(...)\r\n```" ]
2018-01-12T19:22:59
2018-01-12T20:01:25
2018-01-12T20:01:25
NONE
null
Hello, Peewee rocks! Thank you for a great ORM! I am porting unto 3.0 and ran into an error that cast was not supported. How might I do the following from playhouse.shortcuts import cast expr = (cast(column, 'text').contains(str((request_values[key_search])))) Thanks, Evan
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1422/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1422/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1421
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1421/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1421/comments
https://api.github.com/repos/coleifer/peewee/issues/1421/events
https://github.com/coleifer/peewee/pull/1421
288,143,901
MDExOlB1bGxSZXF1ZXN0MTYyNjQ5MTA4
1,421
Fix #1420 InsertQuery
{ "login": "Elfoniok", "id": 662433, "node_id": "MDQ6VXNlcjY2MjQzMw==", "avatar_url": "https://avatars.githubusercontent.com/u/662433?v=4", "gravatar_id": "", "url": "https://api.github.com/users/Elfoniok", "html_url": "https://github.com/Elfoniok", "followers_url": "https://api.github.com/users/Elfoniok/followers", "following_url": "https://api.github.com/users/Elfoniok/following{/other_user}", "gists_url": "https://api.github.com/users/Elfoniok/gists{/gist_id}", "starred_url": "https://api.github.com/users/Elfoniok/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/Elfoniok/subscriptions", "organizations_url": "https://api.github.com/users/Elfoniok/orgs", "repos_url": "https://api.github.com/users/Elfoniok/repos", "events_url": "https://api.github.com/users/Elfoniok/events{/privacy}", "received_events_url": "https://api.github.com/users/Elfoniok/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[]
2018-01-12T14:55:17
2018-01-21T04:35:02
2018-01-21T04:35:02
NONE
null
Signed-off-by: Lukasz Foniok <[email protected]> Resolves https://github.com/coleifer/peewee/issues/1420
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1421/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1421/timeline
null
null
false
{ "url": "https://api.github.com/repos/coleifer/peewee/pulls/1421", "html_url": "https://github.com/coleifer/peewee/pull/1421", "diff_url": "https://github.com/coleifer/peewee/pull/1421.diff", "patch_url": "https://github.com/coleifer/peewee/pull/1421.patch", "merged_at": null }
https://api.github.com/repos/coleifer/peewee/issues/1420
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1420/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1420/comments
https://api.github.com/repos/coleifer/peewee/issues/1420/events
https://github.com/coleifer/peewee/issues/1420
288,138,457
MDU6SXNzdWUyODgxMzg0NTc=
1,420
InsertQuery.execute quietly assumes synchronous cursor
{ "login": "Elfoniok", "id": 662433, "node_id": "MDQ6VXNlcjY2MjQzMw==", "avatar_url": "https://avatars.githubusercontent.com/u/662433?v=4", "gravatar_id": "", "url": "https://api.github.com/users/Elfoniok", "html_url": "https://github.com/Elfoniok", "followers_url": "https://api.github.com/users/Elfoniok/followers", "following_url": "https://api.github.com/users/Elfoniok/following{/other_user}", "gists_url": "https://api.github.com/users/Elfoniok/gists{/gist_id}", "starred_url": "https://api.github.com/users/Elfoniok/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/Elfoniok/subscriptions", "organizations_url": "https://api.github.com/users/Elfoniok/orgs", "repos_url": "https://api.github.com/users/Elfoniok/repos", "events_url": "https://api.github.com/users/Elfoniok/events{/privacy}", "received_events_url": "https://api.github.com/users/Elfoniok/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Have you tested with 3.0a? I just added a test-case to 3.0a which would indicate that this case is being handled properly:\r\n\r\n```diff\r\ndiff --git a/tests/sqliteq.py b/tests/sqliteq.py\r\nindex ebda3b7..cd7aecb 100644\r\n--- a/tests/sqliteq.py\r\n+++ b/tests/sqliteq.py\r\n@@ -69,6 +69,11 @@ class BaseTestQueueDatabase(object):\r\n self.assertRaises(OperationalError, curs.fetchone)\r\n self.database.stop()\r\n \r\n+ def test_integrity_error(self):\r\n+ self.database.start()\r\n+ u = User.create(name='u')\r\n+ self.assertRaises(IntegrityError, User.create, name='u')\r\n+\r\n def test_query_execution(self):\r\n qr = User.select().execute()\r\n self.assertEqual(self.database.queue_size(), 0)\r\n```", "No this is from 2.10.2, when 3.0 will be released?", "I tested this locally with Sqlite 2.10 and received the integrity error as expected:\r\n\r\n```python\r\nIn [1]: from playhouse.sqliteq import *\r\n\r\nIn [2]: from peewee import *\r\n\r\nIn [3]: db = SqliteQueueDatabase('/tmp/testing.db')\r\n\r\nIn [4]: class Sample(Model):\r\n ...: name = TextField(unique=True)\r\n ...: class Meta:\r\n ...: database = db\r\n ...: \r\n\r\nIn [5]: db.start()\r\nOut[5]: False\r\n\r\nIn [6]: Sample.create_table()\r\n\r\nIn [7]: u = Sample.create(name='s1')\r\n\r\nIn [8]: Sample.create(name='s1')\r\nIntegrityError Traceback (most recent call last)\r\n<ipython-input-8-1af0ec3b11a0> in <module>()\r\n----> 1 Sample.create(name='s1')\r\n....\r\n 60 raise ResultTimeout('results not ready, timed out.')\r\n 61 if self._exc is not None:\r\n---> 62 raise self._exc\r\n 63 self._ready = True\r\n 64 \r\n\r\nIntegrityError: UNIQUE constraint failed: sample.name\r\n```", "Yes i forgot to mention small thing, please add primary_key=True to Sample, and you see that it occur." ]
2018-01-12T14:37:19
2018-01-15T15:22:38
2018-01-15T14:52:39
NONE
null
When executing insert query, execute method assumes that synchronous code is executed. If async cursor was used insted, method will silently return passed row, even though exception should be thrown. Simple test, using SqliteQueueDatabase test this: ``` model.Payment.create(primarykey="xyz", value=5) with self.assertRaises(IntegrityError): model.Payment.create(primarykey="xyz", value=5) ``` This should throw ```IntegrityError: UNIQUE constraint failed``` but silently passed payment is returned.
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1420/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1420/timeline
null
completed
null
null
https://api.github.com/repos/coleifer/peewee/issues/1419
https://api.github.com/repos/coleifer/peewee
https://api.github.com/repos/coleifer/peewee/issues/1419/labels{/name}
https://api.github.com/repos/coleifer/peewee/issues/1419/comments
https://api.github.com/repos/coleifer/peewee/issues/1419/events
https://github.com/coleifer/peewee/issues/1419
287,202,614
MDU6SXNzdWUyODcyMDI2MTQ=
1,419
execution_context decorator throws error when used with Proxy (2.10.2)
{ "login": "tadasant", "id": 3900899, "node_id": "MDQ6VXNlcjM5MDA4OTk=", "avatar_url": "https://avatars.githubusercontent.com/u/3900899?v=4", "gravatar_id": "", "url": "https://api.github.com/users/tadasant", "html_url": "https://github.com/tadasant", "followers_url": "https://api.github.com/users/tadasant/followers", "following_url": "https://api.github.com/users/tadasant/following{/other_user}", "gists_url": "https://api.github.com/users/tadasant/gists{/gist_id}", "starred_url": "https://api.github.com/users/tadasant/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/tadasant/subscriptions", "organizations_url": "https://api.github.com/users/tadasant/orgs", "repos_url": "https://api.github.com/users/tadasant/repos", "events_url": "https://api.github.com/users/tadasant/events{/privacy}", "received_events_url": "https://api.github.com/users/tadasant/received_events", "type": "User", "site_admin": false }
[]
closed
false
null
[]
null
[ "Python is interpreted at runtime. When Python evaluates the class definition it sees `@database.execution_context()`. A decorator implies a function call and since the `database` is not bound at the time Python constructs the class, you get the error. Not an issue, just Python doing its thing." ]
2018-01-09T19:27:58
2018-01-09T22:52:18
2018-01-09T22:52:18
NONE
null
Haven't dived too deep into this since the workaround is easy, but observed... `models.py` ```python from peewee import Model, Proxy database = Proxy() class MyObject(Model): id = CharField(primary_key=True) class Meta: database = database ``` `Wrapper.py` ```python from src.models import database, MyObject class Wrapper(object): @database.execution_context() def get_or_create_object(self): my_object = MyObject.get_or_create(id='1') ``` throws: > File "src/Wrapper.py", line 4, in DatabaseClientWrapper @database.execution_context() File "venv/lib/python3.6/site-packages/peewee.py", line 439, in __getattr__ raise AttributeError('Cannot use uninitialized Proxy.') AttributeError: Cannot use uninitialized Proxy. Workaround is just: `Wrapper.py` ```python from src.models import database, MyObject class Wrapper(object): def get_or_create_object(self): with database.execution_context(): my_object = MyObject.get_or_create(id='1') ``` Maybe not worth fixing if it's just the conflicting nature of proxies vs. playing with decorators? Happy to take a shot at a PR if this is unintended
{ "url": "https://api.github.com/repos/coleifer/peewee/issues/1419/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 }
https://api.github.com/repos/coleifer/peewee/issues/1419/timeline
null
completed
null
null