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/2719 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2719/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2719/comments | https://api.github.com/repos/coleifer/peewee/issues/2719/events | https://github.com/coleifer/peewee/issues/2719 | 1,692,808,474 | I_kwDOAA7yGM5k5jUa | 2,719 | PeeWee ForeignKeyField error. IntegrityError: (1215, 'Cannot add foreign key constraint') | {
"login": "Ezyhoo",
"id": 43151697,
"node_id": "MDQ6VXNlcjQzMTUxNjk3",
"avatar_url": "https://avatars.githubusercontent.com/u/43151697?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/Ezyhoo",
"html_url": "https://github.com/Ezyhoo",
"followers_url": "https://api.github.com/users/Ezyhoo/followers",
"following_url": "https://api.github.com/users/Ezyhoo/following{/other_user}",
"gists_url": "https://api.github.com/users/Ezyhoo/gists{/gist_id}",
"starred_url": "https://api.github.com/users/Ezyhoo/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/Ezyhoo/subscriptions",
"organizations_url": "https://api.github.com/users/Ezyhoo/orgs",
"repos_url": "https://api.github.com/users/Ezyhoo/repos",
"events_url": "https://api.github.com/users/Ezyhoo/events{/privacy}",
"received_events_url": "https://api.github.com/users/Ezyhoo/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"It is probably not recommended to put the UNIQUE in the field definitions since these are already primary keys:\r\n\r\n```python\r\nclass UnsignedBigAutoField(pw.BigAutoField):\r\n field_type = 'BIGINT UNSIGNED AUTO_INCREMENT'\r\n\r\nclass UnsignedAutoField(pw.AutoField):\r\n field_type = 'INT UNSIGNED AUTO_INCREMENT'\r\n```\r\n\r\nThe issue is that Peewee sees your subclass of `BigAutoField` and infers that it should use BIGINT instead of BIGINT UNSIGNED. The fix is to override the `field_type` on the foreign-key, e.g.:\r\n\r\n```python\r\n\r\nclass UnsignedForeignKey(pw.ForeignKeyField):\r\n field_type = 'BIGINT UNSIGNED'\r\n\r\nclass Ticket(MySQLModel):\r\n id = UnsignedBigAutoField(primary_key=True)\r\n user = UnsignedForeignKeyField(User, backref=\"tickets\", field=\"id\", on_delete=\"RESTRICT\", on_update=\"CASCADE\")\r\n date_created = pw.DateTimeField(default=datetime.datetime.now)\r\n```"
] | 2023-05-02T17:26:01 | 2023-05-02T19:42:51 | 2023-05-02T19:42:05 | NONE | null | I have code like below:
```
import datetime
import peewee as pw
import os
my_db = pw.MySQLDatabase(database=os.getenv("DB_NAME"), host=os.getenv("DB_HOST"), port=os.getenv("DB_PORT"),
user=os.getenv("DB_USER"), passwd=os.getenv("DB_PASSWORD")
class MySQLModel(pw.Model):
"""A base model class that will use MySQL"""
class Meta:
database = my_db
class UnsignedBigAutoField(pw.BigAutoField):
field_type = 'BIGINT UNSIGNED UNIQUE AUTO_INCREMENT'
class UnsignedAutoField(pw.AutoField):
field_type = 'INT UNSIGNED UNIQUE AUTO_INCREMENT'
class User(MySQLModel):
id = UnsignedBigAutoField(primary_key=True)
alias = pw.CharField(max_length=16, unique=True, null=False)
date_created = pw.DateTimeField(default=datetime.datetime.now)
class Ticket(MySQLModel):
id = UnsignedBigAutoField(primary_key=True)
user = pw.ForeignKeyField(User, backref="tickets", field="id", on_delete="RESTRICT", on_update="CASCADE")
date_created = pw.DateTimeField(default=datetime.datetime.now)
my_db.create_tables([User, Ticket])
```
The last line of the code when creating ForeignKey produces error:
> peewee.IntegrityError: (1215, 'Cannot add foreign key constraint')
I checked the datatype(Bitint), and unique/non-null flag are all setup correctly for User table.
Couldn't figure out what went wrong here. I created the ForeignKey in MySqlWorkBench manually in Ticket table without a problem.
Any help would be appreciated. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2719/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2719/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2718 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2718/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2718/comments | https://api.github.com/repos/coleifer/peewee/issues/2718/events | https://github.com/coleifer/peewee/issues/2718 | 1,692,807,469 | I_kwDOAA7yGM5k5jEt | 2,718 | Fastapi db connection doc | {
"login": "AndyJiangIsTaken",
"id": 87741207,
"node_id": "MDQ6VXNlcjg3NzQxMjA3",
"avatar_url": "https://avatars.githubusercontent.com/u/87741207?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/AndyJiangIsTaken",
"html_url": "https://github.com/AndyJiangIsTaken",
"followers_url": "https://api.github.com/users/AndyJiangIsTaken/followers",
"following_url": "https://api.github.com/users/AndyJiangIsTaken/following{/other_user}",
"gists_url": "https://api.github.com/users/AndyJiangIsTaken/gists{/gist_id}",
"starred_url": "https://api.github.com/users/AndyJiangIsTaken/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/AndyJiangIsTaken/subscriptions",
"organizations_url": "https://api.github.com/users/AndyJiangIsTaken/orgs",
"repos_url": "https://api.github.com/users/AndyJiangIsTaken/repos",
"events_url": "https://api.github.com/users/AndyJiangIsTaken/events{/privacy}",
"received_events_url": "https://api.github.com/users/AndyJiangIsTaken/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"The FastAPI docs have a thorough section, I probably need to just link it since your comment is correct and my docs may be misleading.\r\n\r\nhttps://fastapi.tiangolo.com/advanced/sql-databases-peewee/#make-peewee-async-compatible-peeweeconnectionstate",
"Updated doc here: http://docs.peewee-orm.com/en/latest/peewee/database.html#fastapi"
] | 2023-05-02T17:25:10 | 2023-05-02T17:48:16 | 2023-05-02T17:34:10 | NONE | null | Hi,
Here's the peewee doc I'm referring to:
https://docs.peewee-orm.com/en/latest/peewee/database.html#fastapi
According to the FastAPI doc,
the startup & shutdown events are for when the application, not request here:
https://fastapi.tiangolo.com/advanced/events/#startup-event
Let me know I'm missing something, new here. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2718/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2718/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2717 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2717/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2717/comments | https://api.github.com/repos/coleifer/peewee/issues/2717/events | https://github.com/coleifer/peewee/issues/2717 | 1,690,728,970 | I_kwDOAA7yGM5kxnoK | 2,717 | Calling save fails when PK is provided but record does not exist yet. | {
"login": "keiranjprice101",
"id": 44777678,
"node_id": "MDQ6VXNlcjQ0Nzc3Njc4",
"avatar_url": "https://avatars.githubusercontent.com/u/44777678?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/keiranjprice101",
"html_url": "https://github.com/keiranjprice101",
"followers_url": "https://api.github.com/users/keiranjprice101/followers",
"following_url": "https://api.github.com/users/keiranjprice101/following{/other_user}",
"gists_url": "https://api.github.com/users/keiranjprice101/gists{/gist_id}",
"starred_url": "https://api.github.com/users/keiranjprice101/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/keiranjprice101/subscriptions",
"organizations_url": "https://api.github.com/users/keiranjprice101/orgs",
"repos_url": "https://api.github.com/users/keiranjprice101/repos",
"events_url": "https://api.github.com/users/keiranjprice101/events{/privacy}",
"received_events_url": "https://api.github.com/users/keiranjprice101/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"The docs do make mention of this, there is in fact a section on this: http://docs.peewee-orm.com/en/latest/peewee/models.html#manually-specifying-primary-keys\r\n\r\nAt the most basic, though, this is all you need to add if you are doing this one-off:\r\n\r\n```\r\ncustomer.id = 4\r\ncustomer.email = \"example@example.com\"\r\ncustomer.save(force_insert=True)\r\n```"
] | 2023-05-01T12:02:11 | 2023-05-01T13:07:19 | 2023-05-01T13:07:18 | NONE | null | In this example:
```python
class CustomerPeewee(BaseModel):
email = CharField()
class Meta:
db_table = "customer"
customer = CustomerPeewee()
customer.id = 4
customer.email = "example@example.com"
customer.save()
```
No record is created and 0 is returned. If this is intended it feels counter intuitive as the docs seem to make no mention of this behaviour not being possible
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2717/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2717/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2716 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2716/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2716/comments | https://api.github.com/repos/coleifer/peewee/issues/2716/events | https://github.com/coleifer/peewee/issues/2716 | 1,687,136,706 | I_kwDOAA7yGM5kj6nC | 2,716 | Automatic Migrations Capability | {
"login": "anuran-roy",
"id": 76481787,
"node_id": "MDQ6VXNlcjc2NDgxNzg3",
"avatar_url": "https://avatars.githubusercontent.com/u/76481787?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/anuran-roy",
"html_url": "https://github.com/anuran-roy",
"followers_url": "https://api.github.com/users/anuran-roy/followers",
"following_url": "https://api.github.com/users/anuran-roy/following{/other_user}",
"gists_url": "https://api.github.com/users/anuran-roy/gists{/gist_id}",
"starred_url": "https://api.github.com/users/anuran-roy/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/anuran-roy/subscriptions",
"organizations_url": "https://api.github.com/users/anuran-roy/orgs",
"repos_url": "https://api.github.com/users/anuran-roy/repos",
"events_url": "https://api.github.com/users/anuran-roy/events{/privacy}",
"received_events_url": "https://api.github.com/users/anuran-roy/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
">since I couldn't find any automated tool for migrations\r\n\r\nYou may not have looked very hard, there are several I'm aware of:\r\n\r\n* https://github.com/klen/peewee_migrate\r\n* https://github.com/aachurin/peewee_migrations\r\n* https://github.com/timster/peewee-moves\r\n\r\nI can't vouch for the fitness or suitability of any of the above, but they all seem to offer automatic migrations in some form.\r\n\r\n>why automated migrations haven't been added\r\n\r\nBecause I don't believe they actually save much time, and that writing an explicit migration using the migrator module is preferable. Not everyone agrees with me, hence the above list. I have no plans on integrating such functionality into peewee, however.",
"I actually found only aachurin/peewee_migrations and it seems to be inactive, so I raised the issue. Thanks for the clarification! "
] | 2023-04-27T15:58:44 | 2023-04-27T16:35:29 | 2023-04-27T16:13:05 | NONE | null | Hey there!
Anuran this side! I'm a long time fan of peewee, been using it for a quite a few projects - thanks for this awesome tool, really saves a lot of time for someone who uses Django as well! 🚀
Actually I was on the process of creating a custom script for automated migrations, since I couldn't find any automated tool for migrations, so I decided to create one. I was going through the codebase of peewee - it's pretty neat.
I wonder why an automated migrations haven't been added yet, especially given that `playhouse.migrate` does exist.
Can I go forward and develop an `AutoMigrator` object, that depends on the objects provided by `playhouse.migrate`? | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2716/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2716/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2715 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2715/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2715/comments | https://api.github.com/repos/coleifer/peewee/issues/2715/events | https://github.com/coleifer/peewee/issues/2715 | 1,685,261,994 | I_kwDOAA7yGM5kcw6q | 2,715 | Postgres error : Driver not installed, using peewee,docker and fastapi | {
"login": "Master-Y0da",
"id": 10148942,
"node_id": "MDQ6VXNlcjEwMTQ4OTQy",
"avatar_url": "https://avatars.githubusercontent.com/u/10148942?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/Master-Y0da",
"html_url": "https://github.com/Master-Y0da",
"followers_url": "https://api.github.com/users/Master-Y0da/followers",
"following_url": "https://api.github.com/users/Master-Y0da/following{/other_user}",
"gists_url": "https://api.github.com/users/Master-Y0da/gists{/gist_id}",
"starred_url": "https://api.github.com/users/Master-Y0da/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/Master-Y0da/subscriptions",
"organizations_url": "https://api.github.com/users/Master-Y0da/orgs",
"repos_url": "https://api.github.com/users/Master-Y0da/repos",
"events_url": "https://api.github.com/users/Master-Y0da/events{/privacy}",
"received_events_url": "https://api.github.com/users/Master-Y0da/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Apparently you didn't install `psycopg2`, or for some reason Peewee is unable to import it. In your `main.py` try adding a line `import psycopg2 ; print(psycopg2)` - it should be easy to tell.",
"I intalled pyscogp2 not psycopg2 , really bad one hahaha thank you!!",
"You might've installed some malware or a miner, be careful, people typosquat pypi stuff."
] | 2023-04-26T15:33:40 | 2023-04-26T16:44:22 | 2023-04-26T15:51:31 | NONE | null | I have installed peewee 3.16.2 ,pyscopg2 66.0.2 and fastapi 0.95.1.
I follow the steps in peewee docs about integrate fastapi apps, but showing up this error **peewee.ImproperlyConfigured: Postgres driver not installed!**
This is my config file in fastapi:
def init_db():
db = PostgresqlDatabase(
'atlas_repos',
user='atlas',
password='password',
host='localhost',
port=5432)
return db
this function is called from a main.py in fastapi where I have a db.connect() function
Any help would be much apreciated.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2715/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2715/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2714 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2714/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2714/comments | https://api.github.com/repos/coleifer/peewee/issues/2714/events | https://github.com/coleifer/peewee/issues/2714 | 1,681,779,813 | I_kwDOAA7yGM5kPexl | 2,714 | `peewee` for WebAssembly (JupyterLite + XEUS-Python + emscripten-forge) | {
"login": "michaelweinold",
"id": 23102087,
"node_id": "MDQ6VXNlcjIzMTAyMDg3",
"avatar_url": "https://avatars.githubusercontent.com/u/23102087?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/michaelweinold",
"html_url": "https://github.com/michaelweinold",
"followers_url": "https://api.github.com/users/michaelweinold/followers",
"following_url": "https://api.github.com/users/michaelweinold/following{/other_user}",
"gists_url": "https://api.github.com/users/michaelweinold/gists{/gist_id}",
"starred_url": "https://api.github.com/users/michaelweinold/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/michaelweinold/subscriptions",
"organizations_url": "https://api.github.com/users/michaelweinold/orgs",
"repos_url": "https://api.github.com/users/michaelweinold/repos",
"events_url": "https://api.github.com/users/michaelweinold/events{/privacy}",
"received_events_url": "https://api.github.com/users/michaelweinold/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"1. peewee does not necessarily require c extensions\r\n2. psycopg2cffi is only needed if you want to use postgres and is primarily aimed at pypy users who don't have c extensions, so I'm completely at a loss why this particular bit seemed so important to you.\r\n3. the error is not coming from peewee but seems related to however you're abstracting the file-system for use by sqlite. The error is coming from sqlite and seems to indicate some problem with the file."
] | 2023-04-24T18:06:14 | 2023-04-24T18:14:13 | 2023-04-24T18:14:12 | NONE | null | ## Overview
To bring the [Brightway life-cycle assessment python package](https://documentation.brightway.dev/) to the browser, [we](https://github.com/brightway-lca) recently added `peewee` to the WebAssembly [`emscripten-forge`](https://github.com/emscripten-forge/recipes) package repository. This was necessary since `peewee` comes with C extensions (more specifically, it is using [`psycopg2cffi`](https://github.com/coleifer/peewee/blob/c825a0fb11b1dae1f88d93c67f2fbcb4a34d4ad4/peewee.py#L43)).
`emscripten-forge` is an alternative to the monolythic [Pyodide](https://pyodide.org/en/stable/index.html) Python WebAssembly distribution that is best described [in this article by the core development team.](https://blog.jupyter.org/mamba-meets-jupyterlite-88ef49ac4dc8)
## Error
Unfortunately, I get an error when running it in a [JupyterLite](https://jupyterlite.readthedocs.io/en/latest/) XEUX-Python hub. While this is likely out-of-scope for the developers of `peewee`, I would be very grateful for any hints on the potential root cause. It might be realated to [the filesystem of JupyterLite](https://jupyterlite.readthedocs.io/en/latest/search.html?q=filesystem).
```
from peewee import *
# Define a database object
db = SqliteDatabase('my_database.db')
# Define a model class
class Person(Model):
name = CharField()
age = IntegerField()
class Meta:
database = db
# Create the table in the database
db.connect()
db.create_tables([Person])
person1 = Person(name='Alice', age=25)
person1.save()
```
returnes:
```
DatabaseError: database disk image is malformed
```
<details>
<summary>Full Error Message</summary>
```
---------------------------------------------------------------------------
DatabaseError Traceback (most recent call last)
/tmp/xeus-python-kernel/envs/xeus-python-kernel/lib/python3.10/site-packages/peewee.py in execute_sql(self, sql, params, commit)
3235 cursor = self.cursor()
-> 3236 cursor.execute(sql, params or ())
3237 return cursor
DatabaseError: database disk image is malformed
During handling of the above exception, another exception occurred:
DatabaseError Traceback (most recent call last)
/tmp/xpython_42/2390659374.py in <cell line: 2>()
1 person1 = Person(name='Alice', age=25)
----> 2 person1.save()
/tmp/xeus-python-kernel/envs/xeus-python-kernel/lib/python3.10/site-packages/peewee.py in save(self, force_insert, only)
6745 rows = self.update(**field_dict).where(self._pk_expr()).execute()
6746 elif pk_field is not None:
-> 6747 pk = self.insert(**field_dict).execute()
6748 if pk is not None and (self._meta.auto_increment or
6749 pk_value is None):
/tmp/xeus-python-kernel/envs/xeus-python-kernel/lib/python3.10/site-packages/peewee.py in inner(self, database, *args, **kwargs)
1960 raise InterfaceError('Query must be bound to a database in order '
1961 'to call "%s".' % method.__name__)
-> 1962 return method(self, database, *args, **kwargs)
1963 return inner
1964
/tmp/xeus-python-kernel/envs/xeus-python-kernel/lib/python3.10/site-packages/peewee.py in execute(self, database)
2031 @database_required
2032 def execute(self, database):
-> 2033 return self._execute(database)
2034
2035 def _execute(self, database):
/tmp/xeus-python-kernel/envs/xeus-python-kernel/lib/python3.10/site-packages/peewee.py in _execute(self, database)
2836 self._returning = (self.table._primary_key,)
2837 try:
-> 2838 return super(Insert, self)._execute(database)
2839 except self.DefaultValuesException:
2840 pass
/tmp/xeus-python-kernel/envs/xeus-python-kernel/lib/python3.10/site-packages/peewee.py in _execute(self, database)
2549 cursor = self.execute_returning(database)
2550 else:
-> 2551 cursor = database.execute(self)
2552 return self.handle_result(database, cursor)
2553
/tmp/xeus-python-kernel/envs/xeus-python-kernel/lib/python3.10/site-packages/peewee.py in execute(self, query, commit, **context_options)
3242 ctx = self.get_sql_context(**context_options)
3243 sql, params = ctx.sql(query).query()
-> 3244 return self.execute_sql(sql, params)
3245
3246 def get_context_options(self):
/tmp/xeus-python-kernel/envs/xeus-python-kernel/lib/python3.10/site-packages/peewee.py in execute_sql(self, sql, params, commit)
3232 __deprecated__('"commit" has been deprecated and is a no-op.')
3233 logger.debug((sql, params))
-> 3234 with __exception_wrapper__:
3235 cursor = self.cursor()
3236 cursor.execute(sql, params or ())
/tmp/xeus-python-kernel/envs/xeus-python-kernel/lib/python3.10/site-packages/peewee.py in __exit__(self, exc_type, exc_value, traceback)
3008 new_type = self.exceptions[exc_type.__name__]
3009 exc_args = exc_value.args
-> 3010 reraise(new_type, new_type(exc_value, *exc_args), traceback)
3011
3012
/tmp/xeus-python-kernel/envs/xeus-python-kernel/lib/python3.10/site-packages/peewee.py in reraise(tp, value, tb)
190 def reraise(tp, value, tb=None):
191 if value.__traceback__ is not tb:
--> 192 raise value.with_traceback(tb)
193 raise value
194
/tmp/xeus-python-kernel/envs/xeus-python-kernel/lib/python3.10/site-packages/peewee.py in execute_sql(self, sql, params, commit)
3234 with __exception_wrapper__:
3235 cursor = self.cursor()
-> 3236 cursor.execute(sql, params or ())
3237 return cursor
3238
DatabaseError: database disk image is malformed
```
</details>
## Reproduce Error
Access the JupyterLite Hub and open `peewee_test.ipynb` at https://michaelweinold.github.io/hub/
## Related
- https://github.com/emscripten-forge/recipes/issues/295
- https://github.com/emscripten-forge/recipes/pull/322 | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2714/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2714/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2713 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2713/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2713/comments | https://api.github.com/repos/coleifer/peewee/issues/2713/events | https://github.com/coleifer/peewee/issues/2713 | 1,680,911,617 | I_kwDOAA7yGM5kMK0B | 2,713 | How to "NOT" create index on a "unique" field | {
"login": "eddysnjack",
"id": 38407276,
"node_id": "MDQ6VXNlcjM4NDA3Mjc2",
"avatar_url": "https://avatars.githubusercontent.com/u/38407276?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/eddysnjack",
"html_url": "https://github.com/eddysnjack",
"followers_url": "https://api.github.com/users/eddysnjack/followers",
"following_url": "https://api.github.com/users/eddysnjack/following{/other_user}",
"gists_url": "https://api.github.com/users/eddysnjack/gists{/gist_id}",
"starred_url": "https://api.github.com/users/eddysnjack/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/eddysnjack/subscriptions",
"organizations_url": "https://api.github.com/users/eddysnjack/orgs",
"repos_url": "https://api.github.com/users/eddysnjack/repos",
"events_url": "https://api.github.com/users/eddysnjack/events{/privacy}",
"received_events_url": "https://api.github.com/users/eddysnjack/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"What database engine are you using?",
"> What database engine are you using?\r\n\r\nhow can i check that?",
"You presumably declared it yourself... SqliteDatabase, MySQLDatabase, PostgresqlDatabase...",
"At any rate it seems to be working fine for me:\r\n\r\n```python\r\ndb = SqliteDatabase(':memory:')\r\n\r\nclass User(db.Model):\r\n username = TextField(null=True, unique=True)\r\n\r\nUser.create_table()\r\n\r\nUser.create(username=None)\r\nUser.create(username=None)\r\nUser.create(username='u1')\r\ntry:\r\n User.create(username='u1')\r\nexcept IntegrityError:\r\n pass\r\nelse:\r\n assert False, 'expected integrity error not raised'\r\n\r\nfor u in User:\r\n print(u.username)\r\n```\r\n\r\nCorrectly prints out:\r\n\r\n```\r\nNone\r\nNone\r\nu1\r\n```",
"> You presumably declared it yourself... SqliteDatabase, MySQLDatabase, PostgresqlDatabase...\r\n\r\noh i see SqliteDatabase in this case. i misinterpreted \"engine\", sorry :)"
] | 2023-04-24T10:09:35 | 2023-04-24T13:47:48 | 2023-04-24T12:42:17 | NONE | null | i have o model looking like this.
```
class User(BaseModel):
id = BigIntegerField(unique=True)
first_name = TextField()
last_name = CharField(null=True)
username = CharField(unique=True, null=True, index=False)
phone = CharField(null=True)
deleted = BooleanField(null=True)
is_bot = BooleanField(null=True)
bio = CharField(null=True)
photo = TextField(null=True)
roles = BigIntegerField()
```
After tables are created when i check db file with sqlstudio i saw "username" index on user table. I dont want this, it is unique but should be null as well. I'm getting "UNIQUE constraint failed: user.username" error when I try to update or create a user without a username second time. I believe that index is the cause.
<img width="870" alt="Screen Shot 2023-04-24 at 13 03 17" src="https://user-images.githubusercontent.com/38407276/233966648-e8504dc1-a15d-4fc8-974e-ad0f4ae42bba.png">
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2713/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2713/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2712 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2712/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2712/comments | https://api.github.com/repos/coleifer/peewee/issues/2712/events | https://github.com/coleifer/peewee/issues/2712 | 1,680,522,237 | I_kwDOAA7yGM5kKrv9 | 2,712 | insert_many method missing field values. | {
"login": "frelion",
"id": 71957494,
"node_id": "MDQ6VXNlcjcxOTU3NDk0",
"avatar_url": "https://avatars.githubusercontent.com/u/71957494?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/frelion",
"html_url": "https://github.com/frelion",
"followers_url": "https://api.github.com/users/frelion/followers",
"following_url": "https://api.github.com/users/frelion/following{/other_user}",
"gists_url": "https://api.github.com/users/frelion/gists{/gist_id}",
"starred_url": "https://api.github.com/users/frelion/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/frelion/subscriptions",
"organizations_url": "https://api.github.com/users/frelion/orgs",
"repos_url": "https://api.github.com/users/frelion/repos",
"events_url": "https://api.github.com/users/frelion/events{/privacy}",
"received_events_url": "https://api.github.com/users/frelion/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"http://docs.peewee-orm.com/en/latest/peewee/api.html?highlight=insert_many#Model.insert_many",
"Looks to be working fine:\r\n\r\n```python\r\nclass Reg(db.Model):\r\n val = TextField(null=True)\r\n\r\nReg.create_table()\r\nReg.insert_many([{}, {'val': 'asdf'}], fields=[Reg.val]).execute()\r\nprint(list(Reg.select().tuples()))\r\n# [(1, None), (2, 'asdf')]\r\n```"
] | 2023-04-24T06:07:36 | 2023-04-24T12:37:00 | 2023-04-24T07:07:49 | NONE | null | peewee==3.16.0
Python 3.10.6
For the following code:
```
class TestModel(Model):
class Meta:
database = mysql_db
test_field = CharField(null=True)
TestModel.create_table()
insert_data = [
{}, {
'test_field': "hello"
}
]
TestModel.insert_many(insert_data).execute()
```
Result:
```
id test_field
1 NULL
2 NULL
```
The test_field field of the second record was not inserted.
The following is the modified code:
```
class TestModel(Model):
class Meta:
database = mysql_db
test_field = CharField(null=True)
TestModel.create_table()
insert_data = [{
'test_field': None
},{
'test_field': "hello"
}
]
TestModel.insert_many(insert_data).execute()
```
It worked
```
id test_field
1 NULL
2 hello
```
Is it by design?
This goes against my instincts.
Thank you for working on such an easy-to-use ORM framework
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2712/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2712/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2711 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2711/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2711/comments | https://api.github.com/repos/coleifer/peewee/issues/2711/events | https://github.com/coleifer/peewee/pull/2711 | 1,676,462,240 | PR_kwDOAA7yGM5OwRRM | 2,711 | Feature/filter none on where | {
"login": "ponponon",
"id": 38725104,
"node_id": "MDQ6VXNlcjM4NzI1MTA0",
"avatar_url": "https://avatars.githubusercontent.com/u/38725104?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/ponponon",
"html_url": "https://github.com/ponponon",
"followers_url": "https://api.github.com/users/ponponon/followers",
"following_url": "https://api.github.com/users/ponponon/following{/other_user}",
"gists_url": "https://api.github.com/users/ponponon/gists{/gist_id}",
"starred_url": "https://api.github.com/users/ponponon/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/ponponon/subscriptions",
"organizations_url": "https://api.github.com/users/ponponon/orgs",
"repos_url": "https://api.github.com/users/ponponon/repos",
"events_url": "https://api.github.com/users/ponponon/events{/privacy}",
"received_events_url": "https://api.github.com/users/ponponon/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I don't think silently ignoring arguments is a good plan, the issue is the caller passing `None` in the first place."
] | 2023-04-20T10:35:57 | 2023-04-20T12:33:25 | 2023-04-20T12:33:25 | NONE | null | ```python
q = SeriesTable.select().where(
None, None
)
```
If where is called for the first time and where has more than one None parameter, an error will occur:
```shell
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "/Users/ponponon/Desktop/code/me/gs_review_api/dev/peewee_in.py", line 32, in <module>
q = SeriesTable.select().where(
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ponponon/.local/share/virtualenvs/gs_review_api-0lO5qGKr/lib/python3.11/site-packages/peewee.py", line 755, in inner
method(clone, *args, **kwargs)
File "/Users/ponponon/.local/share/virtualenvs/gs_review_api-0lO5qGKr/lib/python3.11/site-packages/peewee.py", line 2156, in where
self._where = reduce(operator.and_, expressions)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: unsupported operand type(s) for &: 'NoneType' and 'NoneType'
```
So we filter the parameters of where and ignore those with the value None to avoid errors
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2711/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2711/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/2711",
"html_url": "https://github.com/coleifer/peewee/pull/2711",
"diff_url": "https://github.com/coleifer/peewee/pull/2711.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/2711.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/2710 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2710/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2710/comments | https://api.github.com/repos/coleifer/peewee/issues/2710/events | https://github.com/coleifer/peewee/pull/2710 | 1,676,397,519 | PR_kwDOAA7yGM5OwDKO | 2,710 | feature: When `.in_(None)` is executed, the null condition should be … | {
"login": "ponponon",
"id": 38725104,
"node_id": "MDQ6VXNlcjM4NzI1MTA0",
"avatar_url": "https://avatars.githubusercontent.com/u/38725104?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/ponponon",
"html_url": "https://github.com/ponponon",
"followers_url": "https://api.github.com/users/ponponon/followers",
"following_url": "https://api.github.com/users/ponponon/following{/other_user}",
"gists_url": "https://api.github.com/users/ponponon/gists{/gist_id}",
"starred_url": "https://api.github.com/users/ponponon/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/ponponon/subscriptions",
"organizations_url": "https://api.github.com/users/ponponon/orgs",
"repos_url": "https://api.github.com/users/ponponon/repos",
"events_url": "https://api.github.com/users/ponponon/events{/privacy}",
"received_events_url": "https://api.github.com/users/ponponon/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"No, I think `.in_(None)` is incorrect since `None` is not an iterable - going to pass on this."
] | 2023-04-20T09:55:00 | 2023-04-20T12:32:35 | 2023-04-20T12:32:35 | NONE | null | When `.in_(None)` is executed, the null condition should be ignored as `0 = 1` | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2710/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2710/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/2710",
"html_url": "https://github.com/coleifer/peewee/pull/2710",
"diff_url": "https://github.com/coleifer/peewee/pull/2710.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/2710.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/2709 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2709/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2709/comments | https://api.github.com/repos/coleifer/peewee/issues/2709/events | https://github.com/coleifer/peewee/issues/2709 | 1,674,699,657 | I_kwDOAA7yGM5j0eOJ | 2,709 | db.atomic decorator is not a thread-safe | {
"login": "delatars",
"id": 22956479,
"node_id": "MDQ6VXNlcjIyOTU2NDc5",
"avatar_url": "https://avatars.githubusercontent.com/u/22956479?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/delatars",
"html_url": "https://github.com/delatars",
"followers_url": "https://api.github.com/users/delatars/followers",
"following_url": "https://api.github.com/users/delatars/following{/other_user}",
"gists_url": "https://api.github.com/users/delatars/gists{/gist_id}",
"starred_url": "https://api.github.com/users/delatars/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/delatars/subscriptions",
"organizations_url": "https://api.github.com/users/delatars/orgs",
"repos_url": "https://api.github.com/users/delatars/repos",
"events_url": "https://api.github.com/users/delatars/events{/privacy}",
"received_events_url": "https://api.github.com/users/delatars/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Yes you're quite right, thanks for finding this. The issue is down to the fact that a single instance is being created and reused/overwritten. I will figure out a fix. For now the workaround will need to be to use the context manager.",
"This should now be fixed.",
"3.16.2 release contains this fix, thanks for the report this really needed to be fixed!"
] | 2023-04-19T11:19:19 | 2023-04-21T20:18:44 | 2023-04-19T13:11:14 | NONE | null | Hello!
peewee: 3.15.4
python: 3.10.8
Using db.atomic as decorator is not a thread-safe.
The following example is showing that behaviour.
```python
import logging
import random
import uuid
from concurrent.futures import ThreadPoolExecutor
from time import sleep
import peewee
from playhouse.pool import PooledPostgresqlExtDatabase
db = PooledPostgresqlExtDatabase(
database='test',
user='postgres',
password='postgres',
host='localhost',
)
logging.basicConfig(
level=logging.DEBUG,
format='[%(asctime)s] %(levelname)s [%(thread)s] %(message)s',
datefmt='%Y-%m-%d %H:%M:%S',
)
class User(peewee.Model):
class Meta:
database = db
table_name = 'users'
name = peewee.TextField()
@db.atomic()
def get_first():
sleep(random.randint(1, 3))
return User.select().first()
def main(n):
print(f'task {n}: start')
with db.atomic():
User.insert(name=uuid.uuid4().hex).execute()
get_first()
with ThreadPoolExecutor(max_workers=5) as worker:
worker.map(main, range(5))
```
app logs
```
[2023-04-19 13:59:56] DEBUG [6174699520] No connection available in pool.
[2023-04-19 13:59:56] DEBUG [6174699520] Created new connection 4365525936.
[2023-04-19 13:59:56] DEBUG [6174699520] ('INSERT INTO "users" ("name") VALUES (%s) RETURNING "users"."id"', ['erika16'])
[2023-04-19 13:59:56] DEBUG [6191525888] No connection available in pool.
[2023-04-19 13:59:56] DEBUG [6191525888] Created new connection 4365526608.
[2023-04-19 13:59:56] DEBUG [6191525888] ('INSERT INTO "users" ("name") VALUES (%s) RETURNING "users"."id"', ['qfritz'])
[2023-04-19 13:59:56] DEBUG [6208352256] No connection available in pool.
[2023-04-19 13:59:56] DEBUG [6174699520] ('SAVEPOINT "s36f6b1b9c9964d338b76086917abfa2c";', None)
[2023-04-19 13:59:56] DEBUG [6191525888] ('SAVEPOINT "sf48e71a842874f81989e4b29ebb93c5b";', None)
[2023-04-19 13:59:56] DEBUG [6208352256] Created new connection 4365526944.
[2023-04-19 13:59:56] DEBUG [6208352256] ('INSERT INTO "users" ("name") VALUES (%s) RETURNING "users"."id"', ['paulanderson'])
[2023-04-19 13:59:56] DEBUG [6225178624] No connection available in pool.
[2023-04-19 13:59:56] DEBUG [6225178624] Created new connection 4365527280.
[2023-04-19 13:59:56] DEBUG [6225178624] ('INSERT INTO "users" ("name") VALUES (%s) RETURNING "users"."id"', ['patricia09'])
[2023-04-19 13:59:56] DEBUG [6242004992] No connection available in pool.
[2023-04-19 13:59:56] DEBUG [6225178624] ('SAVEPOINT "s4ce9c8529df342a9ac71c47196be2567";', None)
[2023-04-19 13:59:56] DEBUG [6242004992] Created new connection 4365527616.
[2023-04-19 13:59:56] DEBUG [6242004992] ('INSERT INTO "users" ("name") VALUES (%s) RETURNING "users"."id"', ['christina08'])
[2023-04-19 13:59:57] DEBUG [6208352256] ('SAVEPOINT "s33981849fd6345f69f7365c8279e4472";', None)
[2023-04-19 13:59:57] DEBUG [6242004992] ('SAVEPOINT "s97756b77a9264a9cbf194afde4f9e546";', None)
[2023-04-19 13:59:57] DEBUG [6174699520] ('SELECT "t1"."id", "t1"."name" FROM "users" AS "t1" LIMIT %s', [1])
[2023-04-19 13:59:57] DEBUG [6174699520] ('RELEASE SAVEPOINT "s97756b77a9264a9cbf194afde4f9e546";', None)
[2023-04-19 13:59:57] DEBUG [6174699520] ('ROLLBACK TO SAVEPOINT "s97756b77a9264a9cbf194afde4f9e546";', None)
[2023-04-19 13:59:57] DEBUG [6191525888] ('SELECT "t1"."id", "t1"."name" FROM "users" AS "t1" LIMIT %s', [1])
[2023-04-19 13:59:57] DEBUG [6191525888] ('RELEASE SAVEPOINT "s97756b77a9264a9cbf194afde4f9e546";', None)
[2023-04-19 13:59:57] DEBUG [6191525888] ('ROLLBACK TO SAVEPOINT "s97756b77a9264a9cbf194afde4f9e546";', None)
[2023-04-19 13:59:58] DEBUG [6208352256] ('SELECT "t1"."id", "t1"."name" FROM "users" AS "t1" LIMIT %s', [1])
[2023-04-19 13:59:58] DEBUG [6208352256] ('RELEASE SAVEPOINT "s97756b77a9264a9cbf194afde4f9e546";', None)
[2023-04-19 13:59:58] DEBUG [6208352256] ('ROLLBACK TO SAVEPOINT "s97756b77a9264a9cbf194afde4f9e546";', None)
[2023-04-19 13:59:58] DEBUG [6242004992] ('SELECT "t1"."id", "t1"."name" FROM "users" AS "t1" LIMIT %s', [1])
[2023-04-19 13:59:58] DEBUG [6242004992] ('RELEASE SAVEPOINT "s97756b77a9264a9cbf194afde4f9e546";', None)
[2023-04-19 13:59:59] DEBUG [6225178624] ('SELECT "t1"."id", "t1"."name" FROM "users" AS "t1" LIMIT %s', [1])
[2023-04-19 13:59:59] DEBUG [6225178624] ('RELEASE SAVEPOINT "s97756b77a9264a9cbf194afde4f9e546";', None)
[2023-04-19 13:59:59] DEBUG [6225178624] ('ROLLBACK TO SAVEPOINT "s97756b77a9264a9cbf194afde4f9e546";', None)
```
In the logs above, we're see, that threads are trying to release savepoint with an id it did not create.
postgres logs:
```
2023-04-19 10:59:56.522 UTC [61057] LOG: statement: BEGIN
2023-04-19 10:59:56.543 UTC [61057] LOG: duration: 23.928 ms
2023-04-19 10:59:56.549 UTC [61057] LOG: statement: INSERT INTO "users" ("name") VALUES ('erika16') RETURNING "users"."id"
2023-04-19 10:59:56.615 UTC [61057] LOG: duration: 68.462 ms
2023-04-19 10:59:56.626 UTC [61059] LOG: statement: BEGIN
2023-04-19 10:59:56.630 UTC [61059] LOG: duration: 6.580 ms
2023-04-19 10:59:56.636 UTC [61059] LOG: statement: INSERT INTO "users" ("name") VALUES ('qfritz') RETURNING "users"."id"
2023-04-19 10:59:56.637 UTC [61057] LOG: statement: SAVEPOINT "s36f6b1b9c9964d338b76086917abfa2c";
2023-04-19 10:59:56.637 UTC [61057] LOG: duration: 0.593 ms
2023-04-19 10:59:56.678 UTC [61059] LOG: duration: 42.479 ms
2023-04-19 10:59:56.689 UTC [61059] LOG: statement: SAVEPOINT "sf48e71a842874f81989e4b29ebb93c5b";
2023-04-19 10:59:56.691 UTC [61059] LOG: duration: 1.423 ms
2023-04-19 10:59:56.728 UTC [61061] LOG: statement: BEGIN
2023-04-19 10:59:56.732 UTC [61061] LOG: duration: 8.113 ms
2023-04-19 10:59:56.735 UTC [61061] LOG: statement: INSERT INTO "users" ("name") VALUES ('paulanderson') RETURNING "users"."id"
2023-04-19 10:59:56.819 UTC [61063] LOG: statement: BEGIN
2023-04-19 10:59:56.824 UTC [61063] LOG: duration: 6.820 ms
2023-04-19 10:59:56.828 UTC [61063] LOG: statement: INSERT INTO "users" ("name") VALUES ('patricia09') RETURNING "users"."id"
2023-04-19 10:59:56.922 UTC [61063] LOG: duration: 94.511 ms
2023-04-19 10:59:56.928 UTC [61063] LOG: statement: SAVEPOINT "s4ce9c8529df342a9ac71c47196be2567";
2023-04-19 10:59:56.929 UTC [61063] LOG: duration: 0.893 ms
2023-04-19 10:59:56.981 UTC [61065] LOG: statement: BEGIN
2023-04-19 10:59:56.984 UTC [61065] LOG: duration: 5.307 ms
2023-04-19 10:59:56.987 UTC [61065] LOG: statement: INSERT INTO "users" ("name") VALUES ('christina08') RETURNING "users"."id"
2023-04-19 10:59:57.009 UTC [61061] LOG: duration: 274.434 ms
2023-04-19 10:59:57.015 UTC [61061] LOG: statement: SAVEPOINT "s33981849fd6345f69f7365c8279e4472";
2023-04-19 10:59:57.015 UTC [61061] LOG: duration: 0.838 ms
2023-04-19 10:59:57.219 UTC [61065] LOG: duration: 232.845 ms
2023-04-19 10:59:57.222 UTC [61065] LOG: statement: SAVEPOINT "s97756b77a9264a9cbf194afde4f9e546";
2023-04-19 10:59:57.222 UTC [61065] LOG: duration: 0.481 ms
2023-04-19 10:59:57.644 UTC [61057] LOG: statement: SELECT "t1"."id", "t1"."name" FROM "users" AS "t1" LIMIT 1
2023-04-19 10:59:57.657 UTC [61057] LOG: duration: 13.231 ms
2023-04-19 10:59:57.661 UTC [61057] LOG: statement: RELEASE SAVEPOINT "s97756b77a9264a9cbf194afde4f9e546";
2023-04-19 10:59:57.662 UTC [61057] ERROR: savepoint "s97756b77a9264a9cbf194afde4f9e546" does not exist
2023-04-19 10:59:57.662 UTC [61057] STATEMENT: RELEASE SAVEPOINT "s97756b77a9264a9cbf194afde4f9e546";
2023-04-19 10:59:57.672 UTC [61057] LOG: statement: ROLLBACK TO SAVEPOINT "s97756b77a9264a9cbf194afde4f9e546";
2023-04-19 10:59:57.673 UTC [61057] ERROR: savepoint "s97756b77a9264a9cbf194afde4f9e546" does not exist
2023-04-19 10:59:57.673 UTC [61057] STATEMENT: ROLLBACK TO SAVEPOINT "s97756b77a9264a9cbf194afde4f9e546";
2023-04-19 10:59:57.677 UTC [61057] LOG: statement: ROLLBACK
2023-04-19 10:59:57.684 UTC [61057] LOG: duration: 6.259 ms
2023-04-19 10:59:57.695 UTC [61059] LOG: statement: SELECT "t1"."id", "t1"."name" FROM "users" AS "t1" LIMIT 1
2023-04-19 10:59:57.721 UTC [61059] LOG: duration: 26.199 ms
2023-04-19 10:59:57.724 UTC [61059] LOG: statement: RELEASE SAVEPOINT "s97756b77a9264a9cbf194afde4f9e546";
2023-04-19 10:59:57.726 UTC [61059] ERROR: savepoint "s97756b77a9264a9cbf194afde4f9e546" does not exist
2023-04-19 10:59:57.726 UTC [61059] STATEMENT: RELEASE SAVEPOINT "s97756b77a9264a9cbf194afde4f9e546";
2023-04-19 10:59:57.733 UTC [61059] LOG: statement: ROLLBACK TO SAVEPOINT "s97756b77a9264a9cbf194afde4f9e546";
2023-04-19 10:59:57.734 UTC [61059] ERROR: savepoint "s97756b77a9264a9cbf194afde4f9e546" does not exist
2023-04-19 10:59:57.734 UTC [61059] STATEMENT: ROLLBACK TO SAVEPOINT "s97756b77a9264a9cbf194afde4f9e546";
2023-04-19 10:59:57.741 UTC [61059] LOG: statement: ROLLBACK
2023-04-19 10:59:57.778 UTC [61059] LOG: duration: 37.320 ms
2023-04-19 10:59:58.023 UTC [61061] LOG: statement: SELECT "t1"."id", "t1"."name" FROM "users" AS "t1" LIMIT 1
2023-04-19 10:59:58.041 UTC [61061] LOG: duration: 18.985 ms
2023-04-19 10:59:58.045 UTC [61061] LOG: statement: RELEASE SAVEPOINT "s97756b77a9264a9cbf194afde4f9e546";
2023-04-19 10:59:58.046 UTC [61061] ERROR: savepoint "s97756b77a9264a9cbf194afde4f9e546" does not exist
2023-04-19 10:59:58.046 UTC [61061] STATEMENT: RELEASE SAVEPOINT "s97756b77a9264a9cbf194afde4f9e546";
2023-04-19 10:59:58.050 UTC [61061] LOG: statement: ROLLBACK TO SAVEPOINT "s97756b77a9264a9cbf194afde4f9e546";
2023-04-19 10:59:58.051 UTC [61061] ERROR: savepoint "s97756b77a9264a9cbf194afde4f9e546" does not exist
2023-04-19 10:59:58.051 UTC [61061] STATEMENT: ROLLBACK TO SAVEPOINT "s97756b77a9264a9cbf194afde4f9e546";
2023-04-19 10:59:58.054 UTC [61061] LOG: statement: ROLLBACK
2023-04-19 10:59:58.071 UTC [61061] LOG: duration: 17.898 ms
2023-04-19 10:59:58.228 UTC [61065] LOG: statement: SELECT "t1"."id", "t1"."name" FROM "users" AS "t1" LIMIT 1
2023-04-19 10:59:58.247 UTC [61065] LOG: duration: 20.065 ms
2023-04-19 10:59:58.249 UTC [61065] LOG: statement: RELEASE SAVEPOINT "s97756b77a9264a9cbf194afde4f9e546";
2023-04-19 10:59:58.250 UTC [61065] LOG: duration: 1.504 ms
2023-04-19 10:59:58.251 UTC [61065] LOG: statement: COMMIT
2023-04-19 10:59:58.254 UTC [61065] LOG: duration: 2.655 ms
2023-04-19 10:59:59.937 UTC [61063] LOG: statement: SELECT "t1"."id", "t1"."name" FROM "users" AS "t1" LIMIT 1
2023-04-19 10:59:59.957 UTC [61063] LOG: duration: 20.771 ms
2023-04-19 10:59:59.960 UTC [61063] LOG: statement: RELEASE SAVEPOINT "s97756b77a9264a9cbf194afde4f9e546";
2023-04-19 10:59:59.961 UTC [61063] ERROR: savepoint "s97756b77a9264a9cbf194afde4f9e546" does not exist
2023-04-19 10:59:59.961 UTC [61063] STATEMENT: RELEASE SAVEPOINT "s97756b77a9264a9cbf194afde4f9e546";
2023-04-19 10:59:59.964 UTC [61063] LOG: statement: ROLLBACK TO SAVEPOINT "s97756b77a9264a9cbf194afde4f9e546";
2023-04-19 10:59:59.964 UTC [61063] ERROR: savepoint "s97756b77a9264a9cbf194afde4f9e546" does not exist
2023-04-19 10:59:59.964 UTC [61063] STATEMENT: ROLLBACK TO SAVEPOINT "s97756b77a9264a9cbf194afde4f9e546";
2023-04-19 10:59:59.966 UTC [61063] LOG: statement: ROLLBACK
2023-04-19 10:59:59.968 UTC [61063] LOG: duration: 1.987 ms
``` | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2709/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2709/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2708 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2708/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2708/comments | https://api.github.com/repos/coleifer/peewee/issues/2708/events | https://github.com/coleifer/peewee/pull/2708 | 1,667,423,731 | PR_kwDOAA7yGM5OSM0H | 2,708 | update pwiz add fields attr | {
"login": "GuoGuo54",
"id": 38908865,
"node_id": "MDQ6VXNlcjM4OTA4ODY1",
"avatar_url": "https://avatars.githubusercontent.com/u/38908865?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/GuoGuo54",
"html_url": "https://github.com/GuoGuo54",
"followers_url": "https://api.github.com/users/GuoGuo54/followers",
"following_url": "https://api.github.com/users/GuoGuo54/following{/other_user}",
"gists_url": "https://api.github.com/users/GuoGuo54/gists{/gist_id}",
"starred_url": "https://api.github.com/users/GuoGuo54/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/GuoGuo54/subscriptions",
"organizations_url": "https://api.github.com/users/GuoGuo54/orgs",
"repos_url": "https://api.github.com/users/GuoGuo54/repos",
"events_url": "https://api.github.com/users/GuoGuo54/events{/privacy}",
"received_events_url": "https://api.github.com/users/GuoGuo54/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Going to pass. `column_comment` isn't supported by postgres, btw."
] | 2023-04-14T02:47:10 | 2023-04-14T14:09:35 | 2023-04-14T14:09:34 | NONE | null | Issues #2707 : https://github.com/coleifer/peewee/issues | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2708/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2708/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/2708",
"html_url": "https://github.com/coleifer/peewee/pull/2708",
"diff_url": "https://github.com/coleifer/peewee/pull/2708.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/2708.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/2707 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2707/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2707/comments | https://api.github.com/repos/coleifer/peewee/issues/2707/events | https://github.com/coleifer/peewee/issues/2707 | 1,667,373,094 | I_kwDOAA7yGM5jYhgm | 2,707 | pwiz generates detailed field attributes | {
"login": "GuoGuo54",
"id": 38908865,
"node_id": "MDQ6VXNlcjM4OTA4ODY1",
"avatar_url": "https://avatars.githubusercontent.com/u/38908865?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/GuoGuo54",
"html_url": "https://github.com/GuoGuo54",
"followers_url": "https://api.github.com/users/GuoGuo54/followers",
"following_url": "https://api.github.com/users/GuoGuo54/following{/other_user}",
"gists_url": "https://api.github.com/users/GuoGuo54/gists{/gist_id}",
"starred_url": "https://api.github.com/users/GuoGuo54/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/GuoGuo54/subscriptions",
"organizations_url": "https://api.github.com/users/GuoGuo54/orgs",
"repos_url": "https://api.github.com/users/GuoGuo54/repos",
"events_url": "https://api.github.com/users/GuoGuo54/events{/privacy}",
"received_events_url": "https://api.github.com/users/GuoGuo54/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Going to pass. Column comments is mysql-specific, and the varchar max length is negligible in my view, since adding it to the introspected field doesn't change any behavior (and it usually isn't enforced anywhere)."
] | 2023-04-14T01:32:46 | 2023-04-14T14:11:37 | 2023-04-14T14:11:37 | NONE | null | The peewee model generated by pwiz based on the database table is too simple, like:
class NameModel(Model):
name = CharField(null=True)
status = IntegerField(default=11, index=True)
class Meta:
table_name = 'name_model'
But generally we need more detailed field attributes,like (max_length, verbose):
class NameModel(Model):
name = CharField(max_length=128, null=True, verbose_name='name')
status = IntegerField(default=11, index=True, verbose_name='status')
class Meta:
table_name = 'name_model'
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2707/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2707/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2706 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2706/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2706/comments | https://api.github.com/repos/coleifer/peewee/issues/2706/events | https://github.com/coleifer/peewee/issues/2706 | 1,666,749,628 | I_kwDOAA7yGM5jWJS8 | 2,706 | How to avoid fetch-then-create pattern, when fk id already known? | {
"login": "anentropic",
"id": 147840,
"node_id": "MDQ6VXNlcjE0Nzg0MA==",
"avatar_url": "https://avatars.githubusercontent.com/u/147840?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/anentropic",
"html_url": "https://github.com/anentropic",
"followers_url": "https://api.github.com/users/anentropic/followers",
"following_url": "https://api.github.com/users/anentropic/following{/other_user}",
"gists_url": "https://api.github.com/users/anentropic/gists{/gist_id}",
"starred_url": "https://api.github.com/users/anentropic/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/anentropic/subscriptions",
"organizations_url": "https://api.github.com/users/anentropic/orgs",
"repos_url": "https://api.github.com/users/anentropic/repos",
"events_url": "https://api.github.com/users/anentropic/events{/privacy}",
"received_events_url": "https://api.github.com/users/anentropic/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"You can just do this:\r\n\r\n```\r\ngame = GameSession.create(user=user_id, subject=subject)\r\n```"
] | 2023-04-13T16:33:13 | 2023-04-13T16:37:19 | 2023-04-13T16:37:18 | NONE | null | New to Peewee... I'm sure this is easy but could not find an example in the docs
In a case like this:
```python
def start_game(user_id, subject: str) -> GameSession:
user = User.get(User.id == user_id)
game = GameSession.create(user=user, subject=subject)
return game
```
How do I avoid first fetching the `User`, and instead create `GameSession` directly using the `user_id` already known for the foreign key field
Is there something like Django's `user__id` relation-spanning syntax, or implicit `_id` suffixed fields for foreign keys? | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2706/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2706/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2705 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2705/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2705/comments | https://api.github.com/repos/coleifer/peewee/issues/2705/events | https://github.com/coleifer/peewee/issues/2705 | 1,663,812,893 | I_kwDOAA7yGM5jK8Ud | 2,705 | Bitwise shift operators as functions? | {
"login": "andycasey",
"id": 504436,
"node_id": "MDQ6VXNlcjUwNDQzNg==",
"avatar_url": "https://avatars.githubusercontent.com/u/504436?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/andycasey",
"html_url": "https://github.com/andycasey",
"followers_url": "https://api.github.com/users/andycasey/followers",
"following_url": "https://api.github.com/users/andycasey/following{/other_user}",
"gists_url": "https://api.github.com/users/andycasey/gists{/gist_id}",
"starred_url": "https://api.github.com/users/andycasey/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/andycasey/subscriptions",
"organizations_url": "https://api.github.com/users/andycasey/orgs",
"repos_url": "https://api.github.com/users/andycasey/repos",
"events_url": "https://api.github.com/users/andycasey/events{/privacy}",
"received_events_url": "https://api.github.com/users/andycasey/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"You can look at how the `bin_and()`, `bin_or()`, and `__xor__()` methods on field/columns are implemented. There are no bitwish shifts at present, but it should be easy to add them for your case. You can do this as a standalone function, e.g.\r\n\r\n```python\r\ndef lshift(lhs, rhs):\r\n return Expression(lhs, '<<', rhs)\r\n\r\n# Usage.\r\nfn.div(cf, 8).cast('integer') ^ lshift(1, fn.mod(cf, 8).cast('integer'))\r\n```\r\n\r\nMinimal example:\r\n\r\n```python\r\nclass Reg(db.Model):\r\n value = IntegerField()\r\n\r\ndb.create_tables([Reg])\r\n\r\ndef lshift(lhs, rhs):\r\n return Expression(lhs, '<<', rhs)\r\n\r\nfor i in range(10):\r\n Reg.create(value=i)\r\n\r\nquery = Reg.select(Reg.value, lshift(Reg.value, 2).alias('shifted'))\r\nfor row in query:\r\n print(row.value, row.shifted)\r\n\r\n# 0 0\r\n# 1 4\r\n# 2 8\r\n# 3 12\r\n# 4 16\r\n# ...\r\n```"
] | 2023-04-12T05:22:22 | 2023-04-12T13:04:38 | 2023-04-12T13:04:37 | NONE | null | Hi,
I know the Python operators `<<` and `>>` are overloaded in `peewee`. I'm wondering if there is some function (in `peewee.fn`) to use the [bitwise shift left/right operators in Postgresql](https://www.postgresql.org/docs/current/functions-bitstring.html). I've searched a lot but can't find anything myself.
My use case is that I am doing a bitwise OR operation on a byte from a bytearray like this:
```python
class Source(BaseModel):
carton_flags = BigBitField()
# search by a carton flag `cf`
...
where=(
fn.get_byte(self.carton_flags, fn.div(cf, 8).cast("integer")) ^ (1 << fn.mod(cf, 8).cast("integer"))
)
```
And I'm running into Python errors (`TypeError: unsupported operand type(s) for <<: 'int' and 'Cast'`), which forced me to use some ugly-ass `SQL()` unless I could find the bitwise left/right functions. Right now my workaround solution is to use
```python
where=(fn.get_bit(self.carton_flags, cf) != 0)
```
but I'm wondering if there the bitwise left/right shift functions have been interfaced somewhere.
Thanks
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2705/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2705/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2704 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2704/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2704/comments | https://api.github.com/repos/coleifer/peewee/issues/2704/events | https://github.com/coleifer/peewee/issues/2704 | 1,661,731,988 | I_kwDOAA7yGM5jDASU | 2,704 | get_or_none() fails with postgres | {
"login": "TxMat",
"id": 46858765,
"node_id": "MDQ6VXNlcjQ2ODU4NzY1",
"avatar_url": "https://avatars.githubusercontent.com/u/46858765?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/TxMat",
"html_url": "https://github.com/TxMat",
"followers_url": "https://api.github.com/users/TxMat/followers",
"following_url": "https://api.github.com/users/TxMat/following{/other_user}",
"gists_url": "https://api.github.com/users/TxMat/gists{/gist_id}",
"starred_url": "https://api.github.com/users/TxMat/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/TxMat/subscriptions",
"organizations_url": "https://api.github.com/users/TxMat/orgs",
"repos_url": "https://api.github.com/users/TxMat/repos",
"events_url": "https://api.github.com/users/TxMat/events{/privacy}",
"received_events_url": "https://api.github.com/users/TxMat/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"`get_or_none()` takes an expression. See docs: https://docs.peewee-orm.com/en/latest/peewee/api.html#Model.get_or_none\r\n\r\n```python\r\nShippingInfo.get_or_none(\r\n ShippingInfo.id == order.shipping_info)\r\n```\r\n\r\nA cursory look would have solved this for you.",
"It indeed makes sense but for some reason the erroneous syntax Is totally valid when using an SQLite database witch threw me off a little bit."
] | 2023-04-11T04:01:29 | 2023-04-11T17:48:12 | 2023-04-11T11:55:38 | NONE | null | ```py
# Get shipping info from order.shipping_info_id
shipping_info = {}
if order.shipping_info:
shipping_info = model_to_dict(ShippingInfo.get_or_none(order.shipping_info))
# no need to send id to client
del shipping_info["id"]
```
Get_or_none with postgres raises `psycopg2.errors.DatatypeMismatch: argument of WHERE must be type boolean, not type integer` as the query built uses `WHERE 1`
here is the full sql query :
```
SELECT "t1"."id", "t1"."country", "t1"."address", "t1"."postal_code", "t1"."city", "t1"."province" FROM "shippinginfo" AS "t1" WHERE 1 LIMIT 1 OFFSET 0'
```
I'm now using select and get as a temporary fix
```py
# Get shipping info from order.shipping_info_id
shipping_info = {}
if order.shipping_info:
shipping_info = model_to_dict(ShippingInfo.select().where(ShippingInfo.id == order.shipping_info.id).get())
# no need to send id to client
del shipping_info["id"
```
Full stack trace :
---
```
functional_test.py:133 (TestPutShippingInfoOrder.test_put_order_valid_shipping_info)
self = <peewee.PostgresqlDatabase object at 0x7f3d953e5a10>
sql = 'SELECT "t1"."id", "t1"."country", "t1"."address", "t1"."postal_code", "t1"."city", "t1"."province" FROM "shippinginfo" AS "t1" WHERE %s LIMIT %s OFFSET %s'
params = [1, 1, 0], commit = None
def execute_sql(self, sql, params=None, commit=None):
if commit is not None:
__deprecated__('"commit" has been deprecated and is a no-op.')
logger.debug((sql, params))
with __exception_wrapper__:
cursor = self.cursor()
> cursor.execute(sql, params or ())
E psycopg2.errors.DatatypeMismatch: argument of WHERE must be type boolean, not type integer
E LINE 1: ..."t1"."province" FROM "shippinginfo" AS "t1" WHERE 1 LIMIT 1 ...
E ^
../../venv/lib/python3.11/site-packages/peewee.py:3236: DatatypeMismatch
During handling of the above exception, another exception occurred:
self = <Tests.functional_test.TestPutShippingInfoOrder object at 0x7f3d942c7310>
client = <FlaskClient <Flask 'api.inf349'>>
def test_put_order_valid_shipping_info(self, client):
create_order(client)
> response = client.put('/order/1', json={
"order": {
"email": "elon.musk@spacex.com",
"shipping_information": {
"country": "Senegal",
"address": "Rue des potiers",
"postal_code": "G7H 0S5",
"city": "Chicoutimi",
"province": "QC"
}
}
})
functional_test.py:136:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../venv/lib/python3.11/site-packages/werkzeug/test.py:1151: in put
return self.open(*args, **kw)
../../venv/lib/python3.11/site-packages/flask/testing.py:223: in open
response = super().open(
../../venv/lib/python3.11/site-packages/werkzeug/test.py:1095: in open
response = self.run_wsgi_app(request.environ, buffered=buffered)
../../venv/lib/python3.11/site-packages/werkzeug/test.py:962: in run_wsgi_app
rv = run_wsgi_app(self.application, environ, buffered=buffered)
../../venv/lib/python3.11/site-packages/werkzeug/test.py:1243: in run_wsgi_app
app_rv = app(environ, start_response)
../../venv/lib/python3.11/site-packages/flask/app.py:2551: in __call__
return self.wsgi_app(environ, start_response)
../../venv/lib/python3.11/site-packages/flask/app.py:2531: in wsgi_app
response = self.handle_exception(e)
../../venv/lib/python3.11/site-packages/flask/app.py:2528: in wsgi_app
response = self.full_dispatch_request()
../../venv/lib/python3.11/site-packages/flask/app.py:1825: in full_dispatch_request
rv = self.handle_user_exception(e)
../../venv/lib/python3.11/site-packages/flask/app.py:1823: in full_dispatch_request
rv = self.dispatch_request()
../../venv/lib/python3.11/site-packages/flask/app.py:1799: in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
../inf349.py:293: in order_id_handler
return put_order()
../inf349.py:282: in put_order
return update_shipping_order(payload["order"])
../inf349.py:217: in update_shipping_order
return get_order()
../inf349.py:162: in get_order
shipping_info = model_to_dict(ShippingInfo.get_or_none(order.shipping_info))
../../venv/lib/python3.11/site-packages/peewee.py:6634: in get_or_none
return cls.get(*query, **filters)
../../venv/lib/python3.11/site-packages/peewee.py:6629: in get
return sq.get()
../../venv/lib/python3.11/site-packages/peewee.py:7077: in get
return clone.execute(database)[0]
../../venv/lib/python3.11/site-packages/peewee.py:1962: in inner
return method(self, database, *args, **kwargs)
../../venv/lib/python3.11/site-packages/peewee.py:2033: in execute
return self._execute(database)
../../venv/lib/python3.11/site-packages/peewee.py:2206: in _execute
cursor = database.execute(self)
../../venv/lib/python3.11/site-packages/peewee.py:3244: in execute
return self.execute_sql(sql, params)
../../venv/lib/python3.11/site-packages/peewee.py:3234: in execute_sql
with __exception_wrapper__:
../../venv/lib/python3.11/site-packages/peewee.py:3010: in __exit__
reraise(new_type, new_type(exc_value, *exc_args), traceback)
../../venv/lib/python3.11/site-packages/peewee.py:192: in reraise
raise value.with_traceback(tb)
``` | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2704/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2704/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2703 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2703/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2703/comments | https://api.github.com/repos/coleifer/peewee/issues/2703/events | https://github.com/coleifer/peewee/issues/2703 | 1,661,723,222 | I_kwDOAA7yGM5jC-JW | 2,703 | Failed constraints raises IntegrityError but exceeding max_length raises DataEror with postgres | {
"login": "TxMat",
"id": 46858765,
"node_id": "MDQ6VXNlcjQ2ODU4NzY1",
"avatar_url": "https://avatars.githubusercontent.com/u/46858765?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/TxMat",
"html_url": "https://github.com/TxMat",
"followers_url": "https://api.github.com/users/TxMat/followers",
"following_url": "https://api.github.com/users/TxMat/following{/other_user}",
"gists_url": "https://api.github.com/users/TxMat/gists{/gist_id}",
"starred_url": "https://api.github.com/users/TxMat/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/TxMat/subscriptions",
"organizations_url": "https://api.github.com/users/TxMat/orgs",
"repos_url": "https://api.github.com/users/TxMat/repos",
"events_url": "https://api.github.com/users/TxMat/events{/privacy}",
"received_events_url": "https://api.github.com/users/TxMat/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"These errors are raised by postgres and passed on through psycopg2, which determines what error type to raise. Typically one would perform validation beforehand to eliminate something as simple as an over-length violation."
] | 2023-04-11T03:48:34 | 2023-04-11T11:57:35 | 2023-04-11T11:57:35 | NONE | null | ```py
# shipping info model
class ShippingInfo(BaseModel):
id = peewee.AutoField(primary_key=True, unique=True)
country = peewee.CharField(null=False)
address = peewee.CharField(null=False)
postal_code = peewee.CharField(null=False, max_length=7, constraints=[peewee.Check('length(postal_code) = 7')])
city = peewee.CharField(null=False)
province = peewee.CharField(null=False)
```
I don't know if it's intended but it makes catching for errors a bit trickier
```py
try:
shipping_info_instance = ShippingInfo.create(**shipping_info)
order.shipping_info = shipping_info_instance
except peewee.IntegrityError, peewee.DataError:
return errors.error_handler("orders", "invalid-fields", "Les informations d'achat ne sont pas correctes"), 422
``` | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2703/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2703/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2702 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2702/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2702/comments | https://api.github.com/repos/coleifer/peewee/issues/2702/events | https://github.com/coleifer/peewee/issues/2702 | 1,661,715,757 | I_kwDOAA7yGM5jC8Ut | 2,702 | LIKE statement with postgres returns IndexError | {
"login": "TxMat",
"id": 46858765,
"node_id": "MDQ6VXNlcjQ2ODU4NzY1",
"avatar_url": "https://avatars.githubusercontent.com/u/46858765?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/TxMat",
"html_url": "https://github.com/TxMat",
"followers_url": "https://api.github.com/users/TxMat/followers",
"following_url": "https://api.github.com/users/TxMat/following{/other_user}",
"gists_url": "https://api.github.com/users/TxMat/gists{/gist_id}",
"starred_url": "https://api.github.com/users/TxMat/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/TxMat/subscriptions",
"organizations_url": "https://api.github.com/users/TxMat/orgs",
"repos_url": "https://api.github.com/users/TxMat/repos",
"events_url": "https://api.github.com/users/TxMat/events{/privacy}",
"received_events_url": "https://api.github.com/users/TxMat/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"The \"%\" need to be escaped:\r\n\r\n```\r\nemail = peewee.CharField(null=True, constraints=[peewee.Check(\"email LIKE '%%@%%'\")])\r\n```"
] | 2023-04-11T03:37:04 | 2023-04-11T12:38:33 | 2023-04-11T12:38:14 | NONE | null | The like statement inside the email field is causing peewee to return an index error when constructing the database
```py
class Order(BaseModel):
id = peewee.AutoField(primary_key=True, unique=True)
shipping_info = peewee.ForeignKeyField(ShippingInfo, backref='shipping_info', null=True)
product = peewee.ForeignKeyField(Product, backref='product')
email = peewee.CharField(null=True, constraints=[peewee.Check("email LIKE '%@%'")])
paid = peewee.BooleanField(null=False, default=False)
credit_card = peewee.ForeignKeyField(CreditCard, backref='credit_card', null=True)
transaction = peewee.ForeignKeyField(Transaction, backref='transaction', null=True)
```
```
@pytest.fixture
def client():
app.config['TESTING'] = True
client = app.test_client()
# init db
db.connect()
> db.create_tables([Product, ShippingInfo, Transaction, CreditCard, Order, OrderProduct])
conftest.py:16:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../venv/lib/python3.11/site-packages/peewee.py:3425: in create_tables
model.create_table(**options)
../../venv/lib/python3.11/site-packages/peewee.py:6865: in create_table
cls._schema.create_all(safe, **options)
../../venv/lib/python3.11/site-packages/peewee.py:5967: in create_all
self.create_table(safe, **table_options)
../../venv/lib/python3.11/site-packages/peewee.py:5818: in create_table
self.database.execute(self._create_table(safe=safe, **options))
../../venv/lib/python3.11/site-packages/peewee.py:3244: in execute
return self.execute_sql(sql, params)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <peewee.PostgresqlDatabase object at 0x7fe651b025d0>
sql = 'CREATE TABLE IF NOT EXISTS "order" ("id" SERIAL NOT NULL PRIMARY KEY, "shipping_info_id" INTEGER, "product_id" INTEGE...KEY ("credit_card_id") REFERENCES "creditcard" ("id"), FOREIGN KEY ("transaction_id") REFERENCES "transaction" ("id"))'
params = [], commit = None
def execute_sql(self, sql, params=None, commit=None):
if commit is not None:
__deprecated__('"commit" has been deprecated and is a no-op.')
logger.debug((sql, params))
with __exception_wrapper__:
cursor = self.cursor()
> cursor.execute(sql, params or ())
E IndexError: tuple index out of range
../../venv/lib/python3.11/site-packages/peewee.py:3236: IndexError
```
it seems that some other fields causes the indexError error but i can't precisely identify them
also i noticed the error because i'm migrating from sqlite to postgres | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2702/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2702/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2701 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2701/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2701/comments | https://api.github.com/repos/coleifer/peewee/issues/2701/events | https://github.com/coleifer/peewee/issues/2701 | 1,657,252,090 | I_kwDOAA7yGM5ix6j6 | 2,701 | setup.py being deprecated | {
"login": "crdoconnor",
"id": 6067509,
"node_id": "MDQ6VXNlcjYwNjc1MDk=",
"avatar_url": "https://avatars.githubusercontent.com/u/6067509?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/crdoconnor",
"html_url": "https://github.com/crdoconnor",
"followers_url": "https://api.github.com/users/crdoconnor/followers",
"following_url": "https://api.github.com/users/crdoconnor/following{/other_user}",
"gists_url": "https://api.github.com/users/crdoconnor/gists{/gist_id}",
"starred_url": "https://api.github.com/users/crdoconnor/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/crdoconnor/subscriptions",
"organizations_url": "https://api.github.com/users/crdoconnor/orgs",
"repos_url": "https://api.github.com/users/crdoconnor/repos",
"events_url": "https://api.github.com/users/crdoconnor/events{/privacy}",
"received_events_url": "https://api.github.com/users/crdoconnor/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"What version of peewee are you using? I think this should be fixed since we have a magic pyproject toml file now.",
"3.16.0, installed with python 3.11.2:\r\n\r\n```\r\nroot@6b1a08642656:/src# /venv/bin/pip install peewee==3.16.0 \r\nCollecting peewee==3.16.0\r\n Using cached peewee-3.16.0.tar.gz (866 kB)\r\n Preparing metadata (setup.py) ... done\r\nInstalling collected packages: peewee\r\n DEPRECATION: peewee is being installed using the legacy 'setup.py install' method, because it does not have a 'pyproject.toml' and the 'wheel' package is not installed. pip 23.1 will enforce this behaviour change. A possible replacement is to enable the '--use-pep517' option. Discussion can be found at https://github.com/pypa/pip/issues/8559\r\n```\r\n\r\nI think your pyproject needs to have all of the details included.",
"Oh I might have forgotten to add it to the manifest so it didn't get bundled! If you are able to look inside that cached peewee-3.16.0.tar.gz can you see if pyproject.toml is present?",
"That might be it. Yes, it's missing.",
"Thanks I'll get that added to the manifest. It's fine to ignore the warning in the meantime."
] | 2023-04-06T11:34:12 | 2023-04-06T12:10:17 | 2023-04-06T12:10:17 | NONE | null | This message is being displayed when pip installing peewee on python version 3.11.2:
```
DEPRECATION: peewee is being installed using the legacy 'setup.py install' method,
because it does not have a 'pyproject.toml' and the 'wheel' package is not installed.
pip 23.1 will enforce this behaviour change. A possible replacement is to enable
the '--use-pep517' option. Discussion can be found at https://github.com/pypa/pip/issues/8559
``` | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2701/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2701/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2700 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2700/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2700/comments | https://api.github.com/repos/coleifer/peewee/issues/2700/events | https://github.com/coleifer/peewee/issues/2700 | 1,656,510,705 | I_kwDOAA7yGM5ivFjx | 2,700 | Create aware datetime objects for TimestampField | {
"login": "IBuckton",
"id": 48970269,
"node_id": "MDQ6VXNlcjQ4OTcwMjY5",
"avatar_url": "https://avatars.githubusercontent.com/u/48970269?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/IBuckton",
"html_url": "https://github.com/IBuckton",
"followers_url": "https://api.github.com/users/IBuckton/followers",
"following_url": "https://api.github.com/users/IBuckton/following{/other_user}",
"gists_url": "https://api.github.com/users/IBuckton/gists{/gist_id}",
"starred_url": "https://api.github.com/users/IBuckton/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/IBuckton/subscriptions",
"organizations_url": "https://api.github.com/users/IBuckton/orgs",
"repos_url": "https://api.github.com/users/IBuckton/repos",
"events_url": "https://api.github.com/users/IBuckton/events{/privacy}",
"received_events_url": "https://api.github.com/users/IBuckton/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"You can't compare naive and tz-aware datetimes, so this is a non-starter unfortunately. The idea is that your naive datetime *is* already in UTC so the tzinfo is meaningless and provides flexibility -- that is *also* why `utc=False` by default. We can't be switching the return value between naive and tz-aware based on the value of the `utc` parameter.\r\n\r\nMy suggestion would be to subclass `TimestampField` and override the `python_value()` if you wish, e.g.\r\n\r\n```python\r\nclass UTCTimestampField(TimestampField):\r\n def __init__(self, **kwargs):\r\n kwargs['utc'] = True\r\n super(UTCTimestampField, self).__init__(**kwargs)\r\n def python_value(self, value):\r\n value = super(UTCTimestampField, self).python_value(value)\r\n if value is not None:\r\n return value.replace(tzinfo=datetime.timezone.utc)\r\n```"
] | 2023-04-06T00:55:51 | 2023-04-06T04:02:53 | 2023-04-06T04:02:52 | NONE | null | **Description**
With `TimestampField(utc=True)` it returns a naive datetime object. This is not recommended as they are treated by many datetime methods as local times.
**Expected behaviour**
Return an aware datetime object to avoid confusion, per the recommendation in [datetime docs](https://docs.python.org/3.11/library/datetime.html#datetime.datetime.utcfromtimestamp)
**Suggested change**
```python
if self.utc:
- value = datetime.datetime.utcfromtimestamp(value)
+ value = datetime.datetime.fromtimestamp(value, datetime.timezone.utc)
``` | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2700/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2700/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2699 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2699/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2699/comments | https://api.github.com/repos/coleifer/peewee/issues/2699/events | https://github.com/coleifer/peewee/issues/2699 | 1,652,084,899 | I_kwDOAA7yGM5ieNCj | 2,699 | test_multiple_writers failing with database is locked on ppc64le arch | {
"login": "vkrizan",
"id": 7695766,
"node_id": "MDQ6VXNlcjc2OTU3NjY=",
"avatar_url": "https://avatars.githubusercontent.com/u/7695766?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/vkrizan",
"html_url": "https://github.com/vkrizan",
"followers_url": "https://api.github.com/users/vkrizan/followers",
"following_url": "https://api.github.com/users/vkrizan/following{/other_user}",
"gists_url": "https://api.github.com/users/vkrizan/gists{/gist_id}",
"starred_url": "https://api.github.com/users/vkrizan/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/vkrizan/subscriptions",
"organizations_url": "https://api.github.com/users/vkrizan/orgs",
"repos_url": "https://api.github.com/users/vkrizan/repos",
"events_url": "https://api.github.com/users/vkrizan/events{/privacy}",
"received_events_url": "https://api.github.com/users/vkrizan/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Thanks for the report. That timing for the tests (500+ seconds) is unreal, for comparison they run in less than 4 seconds on my workstation:\r\n\r\n```\r\nRan 1154 tests in 3.359s\r\n```\r\n\r\nSo I wonder if you are hitting the sqlite busy timeout on that particular test-case. Is there a particular test that is slowing things down? Even on a small, lightly provisioned VM I'd expect them to run much more quickly than your timing.",
"You can also try this patch or one like it to see if eliminates the failure:\r\n\r\n```diff\r\ndiff --git a/tests/db_tests.py b/tests/db_tests.py\r\nindex 593abe40..f38d14e0 100644\r\n--- a/tests/db_tests.py\r\n+++ b/tests/db_tests.py\r\n@@ -23,6 +23,7 @@ from .base import TestModel\r\n from .base import db\r\n from .base import db_loader\r\n from .base import get_in_memory_db\r\n+from .base import new_connection\r\n from .base import requires_models\r\n from .base import requires_postgresql\r\n from .base_models import Category\r\n@@ -348,6 +349,8 @@ class TestDatabase(DatabaseTestCase):\r\n \r\n \r\n class TestThreadSafety(ModelTestCase):\r\n+ if IS_SQLITE:\r\n+ database = new_connection(timeout=30)\r\n nthreads = 4\r\n nrows = 10\r\n requires = [User]\r\n```",
"Here is the full build: https://koji.fedoraproject.org/koji/taskinfo?taskID=99476458\r\n\r\nInterestingly other archs are running slow as well:\r\n* x86_64 -- Ran 1147 tests in 16.497s\r\n* aarch64 (ARM64) -- Ran 1147 tests in 11.318s\r\n* s390x (IBM System/390) -- Ran 1147 tests in 22.812s\r\n\r\nThis runs on build system ([Koji](https://fedoraproject.org/wiki/Koji)). I think build nodes should have enough resources to complete a build.\r\n\r\nI can try to apply the suggested fix and do a scratch build. However, the test run seems a bit off based on your comment.",
"Build of 3.15.4 was slow as well https://koji.fedoraproject.org/koji/buildinfo?buildID=2128823 (16s on x86_64).",
"Test runs on the order of 10's of seconds is definitely no problem and nothing to worry about, even 100-200s is likely just indicative of a slow machine and/or disk and no real problem.\r\n\r\nOn my workstation I used the above patch with the timeout set to `0.001` and was able to replicate this type of failure -- so my guess is that the ppc64le arch is just performing terribly on our testcases (for whatever reason). By default we give Sqlite 5s to acquire that lock in the multiple writers tests which is ordinarily orders of magnitude more than necessary (for comparison setting it to `0.01` was still plenty of time and did not replicate the issue).\r\n\r\nDo you all maintain any patches for peewee? If so you can try adding the above patch I shared or just marking the test as allowed failure.",
"Currently there are no patches applied, but we can create any that would be necessary. I'll try that...\r\nHaving patches in the upstream (this repository) would be the best option.\r\n\r\nHere is the packaging repository https://src.fedoraproject.org/rpms/python-peewee/tree/rawhide (build is defined within an [RPM spec](https://rpm-packaging-guide.github.io/)) \r\nHere's where test run is defined https://src.fedoraproject.org/rpms/python-peewee/blob/rawhide/f/python-peewee.spec#_90",
"@vkrizan - try the above commit, https://github.com/coleifer/peewee/commit/027eccff176bf458972900d6a329e05d5b969eb4 and let's see if that addresses the issue.",
"@coleifer I'll try to apply it as a patch and see (tomorrow). Unfortunately the [build spec follows git version tags](https://src.fedoraproject.org/rpms/python-peewee/blob/rawhide/f/python-peewee.spec#_16) for me to test it quickly (without applying a patch).",
"If this were a legit issue I'd be more concerned, but this seems to be a confluence of some kind of build environment issues manifesting as a test-only failure, so take heart: all is well.",
"I've tried the patch and this time 3 tests have failed and it got deadlocked :slightly_frowning_face: .\r\n* 2x tests.pool.TestPooledDatabaseIntegration.test_pool_with_models\r\n* tests.pool.TestPooledDatabaseIntegration.test_pooled_database_integration\r\n\r\n```\r\npeewee.OperationalError: database is locked\r\n----------------------------------------------------------------------\r\nRan 1147 tests in 484.713s\r\nFAILED (errors=3, skipped=112)\r\nUnable to import SQLCipher extension tests, skipping.\r\n```\r\nThat was the last log message. It never exited, I had to cancel the build job today.\r\n\r\nThe version of sqlite is: `sqlite-libs-3.40.1-2.fc38.ppc64le`.\r\n(It succeeded on Fedora in development F39. That one has `sqlite-libs-3.41.2-1.fc39.ppc64le`.)\r\n\r\nhttps://koji.fedoraproject.org/koji/taskinfo?taskID=99517867",
"On second try it went through -- build succeeded. The behavior seems a bit non-deterministic. ",
"Id suggest looking into why the performance on ppc64le is so abysmal. I think you mentioned most other architectures finished in 10-15s, so 400-500+ seems unreasonably slow.",
"3.16.1 released."
] | 2023-04-03T13:34:00 | 2023-04-18T17:11:16 | 2023-04-03T14:41:20 | NONE | null | Hello,
The `tests.db_tests.TestThreadSafety.test_multiple_writers` test is failing on ppc64le architecture with:
```
peewee.OperationalError: database is locked
```
```
+ createdb peewee_test
+ psql -c 'CREATE EXTENSION hstore' peewee_test
CREATE EXTENSION
+ /usr/bin/python3 runtests.py
...................................................................................s................ssssssssssssssssssssssssssssssssss...................s..........................sss............................................s.......ss............................s.................s........ssss..................................................................................s..........................................................................ssssss...........................ss..............................................s...................................................................................................................................................s.ss.................ssss............................................ss...............................s..................s...........ss...............................s....ss......s..............s..............................................................ss...............................................................Exception in thread Thread-47 (create_users):
Traceback (most recent call last):
File "/builddir/build/BUILD/peewee-3.16.0/peewee.py", line 3236, in execute_sql
Exception in thread Thread-46 (create_users):
Traceback (most recent call last):
File "/builddir/build/BUILD/peewee-3.16.0/peewee.py", line 3236, in execute_sql
cursor.execute(sql, params or ())
cursor.execute(sql, params or ())
sqlite3.OperationalError: database is locked
During handling of the above exception, another exception occurred:
sqlite3.OperationalError: database is locked
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib64/python3.11/threading.py", line 1038, in _bootstrap_inner
Traceback (most recent call last):
File "/usr/lib64/python3.11/threading.py", line 1038, in _bootstrap_inner
self.run()
File "/usr/lib64/python3.11/threading.py", line 975, in run
self._target(*self._args, **self._kwargs)
File "/builddir/build/BUILD/peewee-3.16.0/tests/db_tests.py", line 358, in create_users
self.run()
File "/usr/lib64/python3.11/threading.py", line 975, in run
User.create(username='u%d' % i)
File "/builddir/build/BUILD/peewee-3.16.0/peewee.py", line 6537, in create
self._target(*self._args, **self._kwargs)
File "/builddir/build/BUILD/peewee-3.16.0/tests/db_tests.py", line 358, in create_users
User.create(username='u%d' % i)
File "/builddir/build/BUILD/peewee-3.16.0/peewee.py", line 6537, in create
inst.save(force_insert=True)
File "/builddir/build/BUILD/peewee-3.16.0/peewee.py", line 6747, in save
inst.save(force_insert=True)
File "/builddir/build/BUILD/peewee-3.16.0/peewee.py", line 6747, in save
pk = self.insert(**field_dict).execute()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/builddir/build/BUILD/peewee-3.16.0/peewee.py", line 1962, in inner
return method(self, database, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/builddir/build/BUILD/peewee-3.16.0/peewee.py", line 2033, in execute
return self._execute(database)
^^^^^^^^^^^^^^^^^^^^^^^
File "/builddir/build/BUILD/peewee-3.16.0/peewee.py", line 2838, in _execute
return super(Insert, self)._execute(database)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/builddir/build/BUILD/peewee-3.16.0/peewee.py", line 2551, in _execute
pk = self.insert(**field_dict).execute()
cursor = database.execute(self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/builddir/build/BUILD/peewee-3.16.0/peewee.py", line 1962, in inner
^^^^^^^^^^^^^^^^^^^^^^
File "/builddir/build/BUILD/peewee-3.16.0/peewee.py", line 3244, in execute
return method(self, database, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/builddir/build/BUILD/peewee-3.16.0/peewee.py", line 2033, in execute
return self._execute(database)
return self.execute_sql(sql, params)
^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/builddir/build/BUILD/peewee-3.16.0/peewee.py", line 3234, in execute_sql
File "/builddir/build/BUILD/peewee-3.16.0/peewee.py", line 2838, in _execute
with __exception_wrapper__:
File "/builddir/build/BUILD/peewee-3.16.0/peewee.py", line 3010, in __exit__
reraise(new_type, new_type(exc_value, *exc_args), traceback)
File "/builddir/build/BUILD/peewee-3.16.0/peewee.py", line 192, in reraise
return super(Insert, self)._execute(database)
raise value.with_traceback(tb)
File "/builddir/build/BUILD/peewee-3.16.0/peewee.py", line 3236, in execute_sql
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/builddir/build/BUILD/peewee-3.16.0/peewee.py", line 2551, in _execute
cursor.execute(sql, params or ())
peewee.OperationalError: database is locked
cursor = database.execute(self)
^^^^^^^^^^^^^^^^^^^^^^
File "/builddir/build/BUILD/peewee-3.16.0/peewee.py", line 3244, in execute
return self.execute_sql(sql, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/builddir/build/BUILD/peewee-3.16.0/peewee.py", line 3234, in execute_sql
with __exception_wrapper__:
File "/builddir/build/BUILD/peewee-3.16.0/peewee.py", line 3010, in __exit__
reraise(new_type, new_type(exc_value, *exc_args), traceback)
File "/builddir/build/BUILD/peewee-3.16.0/peewee.py", line 192, in reraise
raise value.with_traceback(tb)
File "/builddir/build/BUILD/peewee-3.16.0/peewee.py", line 3236, in execute_sql
cursor.execute(sql, params or ())
peewee.OperationalError: database is locked
Fssssssss..............................sssssss........sss.......ssssssssssssss.....s........................s..................................
======================================================================
FAIL: test_multiple_writers (tests.db_tests.TestThreadSafety.test_multiple_writers)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/builddir/build/BUILD/peewee-3.16.0/tests/db_tests.py", line 367, in test_multiple_writers
self.assertEqual(User.select().count(), self.nrows * self.nthreads)
AssertionError: 20 != 40
```
Full log: https://kojipkgs.fedoraproject.org//work/tasks/6601/99476601/build.log
Failing build: https://koji.fedoraproject.org/koji/taskinfo?taskID=99476601
Thank you.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2699/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2699/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2698 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2698/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2698/comments | https://api.github.com/repos/coleifer/peewee/issues/2698/events | https://github.com/coleifer/peewee/pull/2698 | 1,641,066,536 | PR_kwDOAA7yGM5M6wfI | 2,698 | Ae configurable default | {
"login": "paetling",
"id": 3281726,
"node_id": "MDQ6VXNlcjMyODE3MjY=",
"avatar_url": "https://avatars.githubusercontent.com/u/3281726?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/paetling",
"html_url": "https://github.com/paetling",
"followers_url": "https://api.github.com/users/paetling/followers",
"following_url": "https://api.github.com/users/paetling/following{/other_user}",
"gists_url": "https://api.github.com/users/paetling/gists{/gist_id}",
"starred_url": "https://api.github.com/users/paetling/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/paetling/subscriptions",
"organizations_url": "https://api.github.com/users/paetling/orgs",
"repos_url": "https://api.github.com/users/paetling/repos",
"events_url": "https://api.github.com/users/paetling/events{/privacy}",
"received_events_url": "https://api.github.com/users/paetling/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Is there a reason you are not just using:\r\n\r\n```python\r\nclass Base(Model):\r\n id = BinaryUUIDField(primary_key=True, ...)\r\n\r\nclass MyModel(Base):\r\n # MyModel.id will be a binary uuid field\r\n```\r\n\r\nThis change seems redundant."
] | 2023-03-26T20:10:10 | 2023-03-27T12:48:35 | 2023-03-27T12:48:30 | NONE | null | ## Context
Make it so that we can configure the type of the id that is created | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2698/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2698/timeline | null | null | true | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/2698",
"html_url": "https://github.com/coleifer/peewee/pull/2698",
"diff_url": "https://github.com/coleifer/peewee/pull/2698.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/2698.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/2697 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2697/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2697/comments | https://api.github.com/repos/coleifer/peewee/issues/2697/events | https://github.com/coleifer/peewee/issues/2697 | 1,634,492,330 | I_kwDOAA7yGM5hbF-q | 2,697 | peewee-value-returns-to-its-default-after-few-seconds-bug | {
"login": "instasck",
"id": 43851500,
"node_id": "MDQ6VXNlcjQzODUxNTAw",
"avatar_url": "https://avatars.githubusercontent.com/u/43851500?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/instasck",
"html_url": "https://github.com/instasck",
"followers_url": "https://api.github.com/users/instasck/followers",
"following_url": "https://api.github.com/users/instasck/following{/other_user}",
"gists_url": "https://api.github.com/users/instasck/gists{/gist_id}",
"starred_url": "https://api.github.com/users/instasck/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/instasck/subscriptions",
"organizations_url": "https://api.github.com/users/instasck/orgs",
"repos_url": "https://api.github.com/users/instasck/repos",
"events_url": "https://api.github.com/users/instasck/events{/privacy}",
"received_events_url": "https://api.github.com/users/instasck/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"OK ISSUES IS\r\nThat a pointer to the database is not refreshing automatically, it pointing to local data in memory so holding old data.",
"Don't spam the issues -- please try to have a bit of patience.",
"Well it took me 2 hours before I found the issue.\r\nit is not clear about refreshing data from the doc..."
] | 2023-03-21T18:26:54 | 2023-03-21T19:09:42 | 2023-03-21T19:06:38 | NONE | null | https://stackoverflow.com/questions/75804965/peewee-value-returns-to-its-default-after-few-seconds-bug
Can you explain this ? | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2697/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2697/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2696 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2696/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2696/comments | https://api.github.com/repos/coleifer/peewee/issues/2696/events | https://github.com/coleifer/peewee/issues/2696 | 1,634,154,999 | I_kwDOAA7yGM5hZzn3 | 2,696 | Point type | {
"login": "diegocatalao",
"id": 81654879,
"node_id": "MDQ6VXNlcjgxNjU0ODc5",
"avatar_url": "https://avatars.githubusercontent.com/u/81654879?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/diegocatalao",
"html_url": "https://github.com/diegocatalao",
"followers_url": "https://api.github.com/users/diegocatalao/followers",
"following_url": "https://api.github.com/users/diegocatalao/following{/other_user}",
"gists_url": "https://api.github.com/users/diegocatalao/gists{/gist_id}",
"starred_url": "https://api.github.com/users/diegocatalao/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/diegocatalao/subscriptions",
"organizations_url": "https://api.github.com/users/diegocatalao/orgs",
"repos_url": "https://api.github.com/users/diegocatalao/repos",
"events_url": "https://api.github.com/users/diegocatalao/events{/privacy}",
"received_events_url": "https://api.github.com/users/diegocatalao/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"No plans on integrating this into Peewee at the present."
] | 2023-03-21T15:22:36 | 2023-03-21T15:25:31 | 2023-03-21T15:25:30 | NONE | null | Good afternoon people.
Most databases implement the Point type. I've implemented a custom type but I don't know if that's on your roadmap.
I would like to implement it natively in PeeWee. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2696/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2696/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2695 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2695/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2695/comments | https://api.github.com/repos/coleifer/peewee/issues/2695/events | https://github.com/coleifer/peewee/issues/2695 | 1,630,086,918 | I_kwDOAA7yGM5hKScG | 2,695 | FOR UPDATE not supported by CockroachDatabase | {
"login": "arel",
"id": 153497,
"node_id": "MDQ6VXNlcjE1MzQ5Nw==",
"avatar_url": "https://avatars.githubusercontent.com/u/153497?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/arel",
"html_url": "https://github.com/arel",
"followers_url": "https://api.github.com/users/arel/followers",
"following_url": "https://api.github.com/users/arel/following{/other_user}",
"gists_url": "https://api.github.com/users/arel/gists{/gist_id}",
"starred_url": "https://api.github.com/users/arel/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/arel/subscriptions",
"organizations_url": "https://api.github.com/users/arel/orgs",
"repos_url": "https://api.github.com/users/arel/repos",
"events_url": "https://api.github.com/users/arel/events{/privacy}",
"received_events_url": "https://api.github.com/users/arel/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Thank you for letting me know, I'll get this fixed.\r\n\r\nIn the meantime you can set the flag manually when you do your database initialization.\r\n\r\n```\r\ndb = ...\r\ndb.for_update = True\r\n```",
"Thanks!",
"When I enabled the flag the crdb tests are locking up and failing, so something must be special about their implementation. If you're able to look into it that'd be great but if not I'll get around to it. (runtests.py -e cockroachdb)",
"I'm just marking the locked tests to skip for CockroachDB. I have no clue why it isn't working like Postgres or MySQL. This should be resolved now by:\r\n\r\n0031ca565651bc3fd4a12ba347c4cb76c99a643f and 7357d9303a07826bab539a508f05b534f6fcbcc1"
] | 2023-03-18T02:06:31 | 2023-03-18T21:13:38 | 2023-03-18T21:13:37 | NONE | null | I believe this is a bug. I am getting the following error when I try to use `for_update()` in Cockroach DB:
```
File "/workspace/nuhom-api/.venv/lib/python3.10/site-packages/peewee.py", line 2509, in __sql__
raise ValueError('FOR UPDATE specified but not supported '
graphql.error.graphql_error.GraphQLError: FOR UPDATE specified but not supported by database.
```
It looks like `CockroachDatabase` believes `FOR UPDATE` is not supported (which may have been the case in an earlier version): https://github.com/coleifer/peewee/blob/b5cee5e99bcc0b20010646cb52c60f8e37dd620a/playhouse/cockroachdb.py#L65
But, in the CockroachDB docs, it states that `FOR UPDATE` is now supported: https://www.cockroachlabs.com/docs/stable/select-for-update.html
And, even though CockroachDB does not support [locking strengths](https://www.cockroachlabs.com/docs/v22.2/select-for-update#locking-strengths) (`FOR SHARE` or `FOR KEY SHARE`), the syntax is also supported to be compatible with Postgres.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2695/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2695/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2694 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2694/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2694/comments | https://api.github.com/repos/coleifer/peewee/issues/2694/events | https://github.com/coleifer/peewee/issues/2694 | 1,629,501,735 | I_kwDOAA7yGM5hIDkn | 2,694 | `CharField.max_length` has no effect on a Sqlite database | {
"login": "calvinweb",
"id": 38599774,
"node_id": "MDQ6VXNlcjM4NTk5Nzc0",
"avatar_url": "https://avatars.githubusercontent.com/u/38599774?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/calvinweb",
"html_url": "https://github.com/calvinweb",
"followers_url": "https://api.github.com/users/calvinweb/followers",
"following_url": "https://api.github.com/users/calvinweb/following{/other_user}",
"gists_url": "https://api.github.com/users/calvinweb/gists{/gist_id}",
"starred_url": "https://api.github.com/users/calvinweb/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/calvinweb/subscriptions",
"organizations_url": "https://api.github.com/users/calvinweb/orgs",
"repos_url": "https://api.github.com/users/calvinweb/repos",
"events_url": "https://api.github.com/users/calvinweb/events{/privacy}",
"received_events_url": "https://api.github.com/users/calvinweb/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"That is correct, and is down to the way SQLite implements text affinity columns.\r\n\r\nIf you want to enforce a max length you can add a check constraint or implement a subclass of charfield that overrides the `db_value()` method to trim the string.",
"> That is correct, and is down to the way SQLite implements text affinity columns.\r\n> \r\n> If you want to enforce a max length you can add a check constraint or implement a subclass of charfield that overrides the `db_value()` method to trim the string.\r\n\r\nbut i think this should be done by peewee itself because databases should have same behavour"
] | 2023-03-17T15:23:13 | 2023-03-18T01:57:47 | 2023-03-17T16:16:44 | NONE | null | null | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2694/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2694/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2693 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2693/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2693/comments | https://api.github.com/repos/coleifer/peewee/issues/2693/events | https://github.com/coleifer/peewee/issues/2693 | 1,628,079,936 | I_kwDOAA7yGM5hCodA | 2,693 | peewee.ProgrammingError: Error binding parameter 1: type 'builtin_function_or_method' is not supported | {
"login": "RanjithSivam",
"id": 57189095,
"node_id": "MDQ6VXNlcjU3MTg5MDk1",
"avatar_url": "https://avatars.githubusercontent.com/u/57189095?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/RanjithSivam",
"html_url": "https://github.com/RanjithSivam",
"followers_url": "https://api.github.com/users/RanjithSivam/followers",
"following_url": "https://api.github.com/users/RanjithSivam/following{/other_user}",
"gists_url": "https://api.github.com/users/RanjithSivam/gists{/gist_id}",
"starred_url": "https://api.github.com/users/RanjithSivam/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/RanjithSivam/subscriptions",
"organizations_url": "https://api.github.com/users/RanjithSivam/orgs",
"repos_url": "https://api.github.com/users/RanjithSivam/repos",
"events_url": "https://api.github.com/users/RanjithSivam/events{/privacy}",
"received_events_url": "https://api.github.com/users/RanjithSivam/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Do not post questions like this on here. Post your questions on stack overflow. The error is extremely basic, and the error message tells you what is going on. You cannot pass a function as a query parameter.\r\n\r\n```python\r\n# Actually call .now(), don't pass the function itself:\r\n.update(last_login=datetime.datetime.now())\r\n```"
] | 2023-03-16T18:45:53 | 2023-03-16T18:55:45 | 2023-03-16T18:55:44 | NONE | null | I am trying to update. I get this error.
My Code:
![image](https://user-images.githubusercontent.com/57189095/225722329-ac69c23c-d0d4-44bc-8571-aba021a24f28.png)
Here is the error:
Traceback (most recent call last):
File "C:\Users\ranjith-15557\AppData\Local\Programs\Python\Python311\Lib\site-packages\peewee.py", line 3236, in execute_sql
cursor.execute(sql, params or ())
sqlite3.ProgrammingError: Error binding parameter 1: type 'builtin_function_or_method' is not supported
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\ranjith-15557\AppData\Local\Programs\Python\Python311\Lib\site-packages\eel\__init__.py", line 318, in _process_message
return_val = _exposed_functions[message['name']](*message['args'])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\personal\Shoonya\start.py", line 39, in loginDefault
dbHelper.updateLastLogin()
File "E:\personal\Shoonya\lib\db.py", line 63, in updateLastLogin
Credential.update(last_login=datetime.datetime.now).where(Credential.is_default == True).execute()
File "C:\Users\ranjith-15557\AppData\Local\Programs\Python\Python311\Lib\site-packages\peewee.py", line 1962, in inner
return method(self, database, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ranjith-15557\AppData\Local\Programs\Python\Python311\Lib\site-packages\peewee.py", line 2033, in execute
return self._execute(database)
^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ranjith-15557\AppData\Local\Programs\Python\Python311\Lib\site-packages\peewee.py", line 2551, in _execute
cursor = database.execute(self)
^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ranjith-15557\AppData\Local\Programs\Python\Python311\Lib\site-packages\peewee.py", line 3244, in execute
return self.execute_sql(sql, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ranjith-15557\AppData\Local\Programs\Python\Python311\Lib\site-packages\peewee.py", line 3234, in execute_sql
with __exception_wrapper__:
File "C:\Users\ranjith-15557\AppData\Local\Programs\Python\Python311\Lib\site-packages\peewee.py", line 3010, in __exit__
reraise(new_type, new_type(exc_value, *exc_args), traceback)
File "C:\Users\ranjith-15557\AppData\Local\Programs\Python\Python311\Lib\site-packages\peewee.py", line 192, in reraise
raise value.with_traceback(tb)
File "C:\Users\ranjith-15557\AppData\Local\Programs\Python\Python311\Lib\site-packages\peewee.py", line 3236, in execute_sql
cursor.execute(sql, params or ())
peewee.ProgrammingError: Error binding parameter 1: type 'builtin_function_or_method' is not supported
Traceback (most recent call last):
File "C:\Users\ranjith-15557\AppData\Local\Programs\Python\Python311\Lib\site-packages\gevent\_ffi\loop.py", line 270, in python_check_callback
def python_check_callback(self, watcher_ptr): # pylint:disable=unused-argument
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ranjith-15557\AppData\Local\Programs\Python\Python311\Lib\site-packages\peewee.py", line 2033, in execute
return self._execute(database)
^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ranjith-15557\AppData\Local\Programs\Python\Python311\Lib\site-packages\peewee.py", line 2551, in _execute cursor = database.execute(self)
^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ranjith-15557\AppData\Local\Programs\Python\Python311\Lib\site-packages\peewee.py", line 3244, in execute
return self.execute_sql(sql, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ranjith-15557\AppData\Local\Programs\Python\Python311\Lib\site-packages\peewee.py", line 3234, in execute_sql
with __exception_wrapper__:
File "C:\Users\ranjith-15557\AppData\Local\Programs\Python\Python311\Lib\site-packages\peewee.py", line 3010, in __exit__
reraise(new_type, new_type(exc_value, *exc_args), traceback)
File "C:\Users\ranjith-15557\AppData\Local\Programs\Python\Python311\Lib\site-packages\peewee.py", line 192, in reraise
raise value.with_traceback(tb)
File "C:\Users\ranjith-15557\AppData\Local\Programs\Python\Python311\Lib\site-packages\peewee.py", line 3236, in execute_sql
cursor.execute(sql, params)
peewee.ProgrammingError: Error binding parameter 1: type 'builtin_function_or_method' is not supported
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2693/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2693/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2692 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2692/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2692/comments | https://api.github.com/repos/coleifer/peewee/issues/2692/events | https://github.com/coleifer/peewee/issues/2692 | 1,623,585,150 | I_kwDOAA7yGM5gxfF- | 2,692 | Creating indexes on UUID primary key failes | {
"login": "martijnED",
"id": 104991209,
"node_id": "U_kgDOBkIJ6Q",
"avatar_url": "https://avatars.githubusercontent.com/u/104991209?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/martijnED",
"html_url": "https://github.com/martijnED",
"followers_url": "https://api.github.com/users/martijnED/followers",
"following_url": "https://api.github.com/users/martijnED/following{/other_user}",
"gists_url": "https://api.github.com/users/martijnED/gists{/gist_id}",
"starred_url": "https://api.github.com/users/martijnED/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/martijnED/subscriptions",
"organizations_url": "https://api.github.com/users/martijnED/orgs",
"repos_url": "https://api.github.com/users/martijnED/repos",
"events_url": "https://api.github.com/users/martijnED/events{/privacy}",
"received_events_url": "https://api.github.com/users/martijnED/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"The docs are pretty clear:\r\n\r\n```python\r\n# Adding an index:\r\n\r\n# Specify the table, column names, and whether the index should be\r\n# UNIQUE or not.\r\nmigrate(\r\n # Create an index on the `pub_date` column.\r\n migrator.add_index('story', ('pub_date',), False),\r\n\r\n # Create a multi-column index on the `pub_date` and `status` fields.\r\n migrator.add_index('story', ('pub_date', 'status'), False),\r\n\r\n # Create a unique index on the category and title fields.\r\n migrator.add_index('story', ('category_id', 'title'), True),\r\n)\r\n```\r\n\r\nPlease at least look at the docs before opening an issue in the future.",
"On closer inspection it looks like this isn't even for peewee, but for a third-party package. Please refer to the 3rd party package maintainer's documentation or take it up with them.",
"If I do so, I get a different error:\r\n\r\n## Code\r\n``` python\r\nimport uuid\r\nfrom peewee import UUIDField,\r\n\r\n\r\nclass CommandControl(Model):\r\n id = UUIDField(primary_key=True, default=uuid.uuid4)\r\n\r\ndef migrate(migrator, database, fake=False, **kwargs):\r\n \"\"\"Write your migrations here.\"\"\"\r\n migrator.create_table(CommandControl)\r\n migrator.add_index('command_control', ('id',), False)\r\n\r\n```\r\n\r\n## The error than\r\n``` bash\r\nTypeError: not all arguments converted during string formatting\r\n```\r\nbit unclear what this means and how to solve that part",
"You aren't showing what `migrator` is but from your earlier comment I inferred it is some 3rd party library `peewee_migrate`? Please refer there.",
"You completely right! Will ask the question there!"
] | 2023-03-14T14:19:57 | 2023-03-14T14:41:00 | 2023-03-14T14:25:14 | NONE | null | During creating of tables and creating indexes on that table it failes to create indexes on UUID key.
## The code
``` python
import uuid
from playhouse.postgres_ext import UUIDField
class CommandControl(Model):
id = UUIDField(primary_key=True, default=uuid.uuid4)
def migrate(migrator, database, fake=False, **kwargs):
"""Write your migrations here."""
migrator.create_table(CommandControl)
migrator.add_index(CommandControl.id)
```
## The error
``` bash
File "/app/__pypackages__/3.10/lib/peewee_migrate/migrator.py", line 117, in wrapper
model._meta.schema = migrator.schema
AttributeError: 'UUIDField' object has no attribute '_meta'
``` | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2692/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2692/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2691 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2691/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2691/comments | https://api.github.com/repos/coleifer/peewee/issues/2691/events | https://github.com/coleifer/peewee/issues/2691 | 1,619,326,207 | I_kwDOAA7yGM5ghPT_ | 2,691 | reflection.generate_models BinaryJSONField column always has index, even when underlying database schema has no index | {
"login": "rberman",
"id": 6520506,
"node_id": "MDQ6VXNlcjY1MjA1MDY=",
"avatar_url": "https://avatars.githubusercontent.com/u/6520506?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/rberman",
"html_url": "https://github.com/rberman",
"followers_url": "https://api.github.com/users/rberman/followers",
"following_url": "https://api.github.com/users/rberman/following{/other_user}",
"gists_url": "https://api.github.com/users/rberman/gists{/gist_id}",
"starred_url": "https://api.github.com/users/rberman/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/rberman/subscriptions",
"organizations_url": "https://api.github.com/users/rberman/orgs",
"repos_url": "https://api.github.com/users/rberman/repos",
"events_url": "https://api.github.com/users/rberman/events{/privacy}",
"received_events_url": "https://api.github.com/users/rberman/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2023-03-10T17:16:36 | 2023-03-10T19:03:17 | 2023-03-10T19:03:17 | NONE | null | I have a table defined as follows:
```python
from playhouse.postgres_ext import BinaryJSONField
class MyTable(flask_db.Model):
some_data = BinaryJSONField(index=False)
```
For this table, we don’t need an index since we only ever write to this table.
When I try to use generate_models on this table, the generated BinaryJSONField has `index=True`, as demonstrated below:
```python
from playhouse.reflection import generate_models
from models import MyTable
generated_model = generate_models(flask_db.database, table_names=["mytable"])["mytable"]
generated_column = generated_model._meta.columns["some_data"]
reference_column = MyTable._meta.columns["some_data"]
# Raises an error:
assert generated_column.index == reference_column.index
```
I believe this is happening because `BinaryJSONField` inherits from `IndexedFieldMixin` and, therefore, defaults the `index` parameter to `True`. The reflection code checks for indexes and adds `index=True` to column definitions when necessary to create the corresponding indexes, but does not add `index=False` when they are not required ([see here](https://github.com/coleifer/peewee/blob/3fc96dbe33500d3e5099ea11ef7af080900127ba/playhouse/reflection.py#L762-L767)). That normally works, but not for column types that include `IndexedFieldMixin`.
The preferred behavior would be for the `index=False` value to taken into account when creating the table. Would you please take a look? Thank you! | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2691/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2691/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2690 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2690/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2690/comments | https://api.github.com/repos/coleifer/peewee/issues/2690/events | https://github.com/coleifer/peewee/issues/2690 | 1,618,951,492 | I_kwDOAA7yGM5gfz1E | 2,690 | Prefetch with many ForeignKeyField to same model | {
"login": "dim49v",
"id": 15666913,
"node_id": "MDQ6VXNlcjE1NjY2OTEz",
"avatar_url": "https://avatars.githubusercontent.com/u/15666913?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/dim49v",
"html_url": "https://github.com/dim49v",
"followers_url": "https://api.github.com/users/dim49v/followers",
"following_url": "https://api.github.com/users/dim49v/following{/other_user}",
"gists_url": "https://api.github.com/users/dim49v/gists{/gist_id}",
"starred_url": "https://api.github.com/users/dim49v/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/dim49v/subscriptions",
"organizations_url": "https://api.github.com/users/dim49v/orgs",
"repos_url": "https://api.github.com/users/dim49v/repos",
"events_url": "https://api.github.com/users/dim49v/events{/privacy}",
"received_events_url": "https://api.github.com/users/dim49v/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Seems to be working OK for me:\r\n\r\n```python\r\nclass State(db.Model):\r\n name = TextField()\r\n def __str__(self):\r\n return self.name\r\n\r\nclass Transition(db.Model):\r\n source_state = ForeignKeyField(State, backref='sources')\r\n target_state = ForeignKeyField(State, backref='targets')\r\n def __str__(self):\r\n return '%s->%s' % (self.source_state, self.target_state)\r\n\r\ndb.create_tables([State, Transition])\r\n\r\ns1 = State.create(name='s1')\r\ns2a = State.create(name='s2-a')\r\ns2b = State.create(name='s2-b')\r\ns3 = State.create(name='s3')\r\nTransition.create(source_state=s1, target_state=s2a)\r\nTransition.create(source_state=s1, target_state=s2b)\r\nTransition.create(source_state=s2a, target_state=s3)\r\nTransition.create(source_state=s2b, target_state=s3)\r\n\r\nquery = State.select().where(State.name != 's3')\r\ntransitions = Transition.select()\r\np = prefetch(query, transitions, prefetch_type=PREFETCH_TYPE.JOIN)\r\nfor row in p:\r\n print(row.name, row.sources, row.targets)\r\n```\r\n\r\nOutput as expected:\r\n\r\n```\r\ns1 [<Transition: s1->s2-a>, <Transition: s1->s2-b>] []\r\ns2-a [<Transition: s2-a->s3>] [<Transition: s1->s2-a>]\r\ns2-b [<Transition: s2-b->s3>] [<Transition: s1->s2-b>]\r\n```",
"The above code also gives an error:\r\n```\r\npsycopg2.errors.AmbiguousColumn: column reference \"id\" is ambiguous\r\nLINE 1: ...AS \"t2\" WHERE (\"t2\".\"name\" != 's3')) AS \"t3\" ON ((\"t3\".\"id\" ...\r\n ^\r\n```\r\nQuery:\r\n```\r\n('SELECT DISTINCT \"t1\".\"id\", \"t1\".\"source_state_id\", \"t1\".\"target_state_id\" FROM \"transition\" AS \"t1\"\r\n INNER JOIN (SELECT \"t2\".\"id\", \"t2\".\"id\" FROM \"state\" AS \"t2\" WHERE (\"t2\".\"name\" != %s)) AS \"t3\"\r\n ON ((\"t3\".\"id\" = \"t1\".\"source_state_id\") OR (\"t3\".\"id\" = \"t1\".\"target_state_id\"))', ['s3'])\r\n```\r\nСhecked on the latest version 3.16.0. \r\nDatabase - PostgreSQL 10.23",
"Oh no, I tested with SQLite so I assumed it was ok. Reopening and will look into it, thanks for letting me know.",
"This is now fixed, thanks again."
] | 2023-03-10T13:06:12 | 2023-03-12T14:15:30 | 2023-03-12T14:08:10 | NONE | null | Hello!
I'm have 2 models:
```
class State(Entity):
uuid = UUIDField(column_name='uuid', primary_key=True)
class Transition(Entity):
uuid = UUIDField(column_name='uuid', primary_key=True)
source_state = ForeignKeyField(State, column_name='source_state_id', backref='_db_source_transitions')
target_state = ForeignKeyField(State, column_name='target_state_id', backref='_db_target_transitions')
```
I'm trying load `State` entity and all his `Transition`:
```
states = State.select().where(...)
transitions = Transition.select()
states = prefetch(states, transitions, prefetch_type=PREFETCH_TYPE.JOIN)
```
I get the following query:
```
SELECT ... FROM "transition" AS "t1"
INNER JOIN (SELECT "t2"."uuid", "t2"."uuid" FROM "state" AS "t2" WHERE (...)) AS "t3"
ON (("t3"."uuid" = "t1"."source_state_id") OR ("t3"."uuid" = "t1"."target_state_id"))
```
and error in ON statement:
```
column reference "uuid" is ambiguous
```
Is there a way to specify the single foreign key used or is it a bug? | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2690/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2690/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2689 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2689/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2689/comments | https://api.github.com/repos/coleifer/peewee/issues/2689/events | https://github.com/coleifer/peewee/issues/2689 | 1,617,001,747 | I_kwDOAA7yGM5gYX0T | 2,689 | Is it possible to serialise peewee.Expression? | {
"login": "vdytyniak-exos",
"id": 94358054,
"node_id": "U_kgDOBZ_KJg",
"avatar_url": "https://avatars.githubusercontent.com/u/94358054?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/vdytyniak-exos",
"html_url": "https://github.com/vdytyniak-exos",
"followers_url": "https://api.github.com/users/vdytyniak-exos/followers",
"following_url": "https://api.github.com/users/vdytyniak-exos/following{/other_user}",
"gists_url": "https://api.github.com/users/vdytyniak-exos/gists{/gist_id}",
"starred_url": "https://api.github.com/users/vdytyniak-exos/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/vdytyniak-exos/subscriptions",
"organizations_url": "https://api.github.com/users/vdytyniak-exos/orgs",
"repos_url": "https://api.github.com/users/vdytyniak-exos/repos",
"events_url": "https://api.github.com/users/vdytyniak-exos/events{/privacy}",
"received_events_url": "https://api.github.com/users/vdytyniak-exos/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"No, not really or not officially. You can see how the [dynamic filters work in flask-peewee](http://docs.peewee-orm.com/projects/flask-peewee/en/latest/admin.html#filters): https://github.com/coleifer/flask-peewee/blob/master/flask_peewee/filters.py\r\n\r\nProbably the easiest thing to do though is to use the django-style query apis, eg `field__eq=value`. These can be passed to `model.filter()` like Django.\r\n\r\nLastly, we have irc on libera #peewee, or you can ask general questions on stack overflow. I regularly check SO and try to provide help there just fyi.",
"@coleifer Thanks for you answer. I am trying to implement my own json decoder, looks like it is that hard to represent pewee.Expression tree in json. "
] | 2023-03-09T11:19:40 | 2023-03-09T14:04:47 | 2023-03-09T12:43:27 | NONE | null | it is not an issue, but I didn't find other communication channel to get some ideas in how to serialise peewee.Expression to pass it to the API and later use there as filter in the query. Thanks | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2689/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2689/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2688 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2688/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2688/comments | https://api.github.com/repos/coleifer/peewee/issues/2688/events | https://github.com/coleifer/peewee/pull/2688 | 1,611,011,168 | PR_kwDOAA7yGM5LWNxs | 2,688 | mysql add column comment | {
"login": "smzhao",
"id": 2282742,
"node_id": "MDQ6VXNlcjIyODI3NDI=",
"avatar_url": "https://avatars.githubusercontent.com/u/2282742?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/smzhao",
"html_url": "https://github.com/smzhao",
"followers_url": "https://api.github.com/users/smzhao/followers",
"following_url": "https://api.github.com/users/smzhao/following{/other_user}",
"gists_url": "https://api.github.com/users/smzhao/gists{/gist_id}",
"starred_url": "https://api.github.com/users/smzhao/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/smzhao/subscriptions",
"organizations_url": "https://api.github.com/users/smzhao/orgs",
"repos_url": "https://api.github.com/users/smzhao/repos",
"events_url": "https://api.github.com/users/smzhao/events{/privacy}",
"received_events_url": "https://api.github.com/users/smzhao/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Going to pass."
] | 2023-03-06T09:33:38 | 2023-03-06T12:16:44 | 2023-03-06T12:16:44 | NONE | null | mysql add column comment with verbose_name or help_text | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2688/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2688/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/2688",
"html_url": "https://github.com/coleifer/peewee/pull/2688",
"diff_url": "https://github.com/coleifer/peewee/pull/2688.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/2688.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/2687 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2687/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2687/comments | https://api.github.com/repos/coleifer/peewee/issues/2687/events | https://github.com/coleifer/peewee/issues/2687 | 1,610,105,140 | I_kwDOAA7yGM5f-EE0 | 2,687 | `playhouse.signals.Signal.disconnect` disconnects more than key, sender pair. | {
"login": "real-yfprojects",
"id": 62463991,
"node_id": "MDQ6VXNlcjYyNDYzOTkx",
"avatar_url": "https://avatars.githubusercontent.com/u/62463991?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/real-yfprojects",
"html_url": "https://github.com/real-yfprojects",
"followers_url": "https://api.github.com/users/real-yfprojects/followers",
"following_url": "https://api.github.com/users/real-yfprojects/following{/other_user}",
"gists_url": "https://api.github.com/users/real-yfprojects/gists{/gist_id}",
"starred_url": "https://api.github.com/users/real-yfprojects/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/real-yfprojects/subscriptions",
"organizations_url": "https://api.github.com/users/real-yfprojects/orgs",
"repos_url": "https://api.github.com/users/real-yfprojects/repos",
"events_url": "https://api.github.com/users/real-yfprojects/events{/privacy}",
"received_events_url": "https://api.github.com/users/real-yfprojects/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Oh yes it should be instead:\r\n\r\n```\r\nif not (n,s)==key\r\n```",
"Nice! Thanks for fixing. Do you have a rough estimate for the next release date?",
"Let me think on it."
] | 2023-03-05T08:30:29 | 2023-03-05T14:57:19 | 2023-03-05T14:49:03 | NONE | null | When connecting two receiver to the same sender and disconnecting one of them. Both are disconnected. This bug is also illustrated by the code itself:
https://github.com/coleifer/peewee/blob/f88fa44a29601ca2de9fe492fda11b1fb28fb412/playhouse/signals.py#L25-L38
The `_receivers` set stores pairs of receiver and model. When disconnecting a single pair is removed if present. However `_receiver_list` looses all entries for which `n != name and s != sender` is false. Quick transformation:
$$ \lnot( n \ne name \land s \ne sender ) \Leftrightarrow $$
$$ \lnot( n \ne name ) \lor \lnot( s \ne sender ) \Leftrightarrow $$
$$ n = name \lor s = sender $$
Notice that all receivers are removed that have a matching name or receiver. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2687/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2687/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2686 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2686/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2686/comments | https://api.github.com/repos/coleifer/peewee/issues/2686/events | https://github.com/coleifer/peewee/issues/2686 | 1,610,098,096 | I_kwDOAA7yGM5f-CWw | 2,686 | Undocumented parameter `sender` for `playhouse.signals.Signal.disconnect`. | {
"login": "real-yfprojects",
"id": 62463991,
"node_id": "MDQ6VXNlcjYyNDYzOTkx",
"avatar_url": "https://avatars.githubusercontent.com/u/62463991?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/real-yfprojects",
"html_url": "https://github.com/real-yfprojects",
"followers_url": "https://api.github.com/users/real-yfprojects/followers",
"following_url": "https://api.github.com/users/real-yfprojects/following{/other_user}",
"gists_url": "https://api.github.com/users/real-yfprojects/gists{/gist_id}",
"starred_url": "https://api.github.com/users/real-yfprojects/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/real-yfprojects/subscriptions",
"organizations_url": "https://api.github.com/users/real-yfprojects/orgs",
"repos_url": "https://api.github.com/users/real-yfprojects/repos",
"events_url": "https://api.github.com/users/real-yfprojects/events{/privacy}",
"received_events_url": "https://api.github.com/users/real-yfprojects/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"You just don't want to update/improve the documentation of your library or why are you closing it without a comment. Others will find that pretty unwelcoming.",
"7246a7f2b8c5adbae33180af3c817601560dc33a"
] | 2023-03-05T08:03:44 | 2023-03-05T16:53:34 | 2023-03-05T12:25:53 | NONE | null | https://github.com/coleifer/peewee/blob/f88fa44a29601ca2de9fe492fda11b1fb28fb412/playhouse/signals.py#L25
There is a `sender` parameter. However there is no such parameter here:
https://github.com/coleifer/peewee/blob/f88fa44a29601ca2de9fe492fda11b1fb28fb412/docs/peewee/playhouse.rst?plain=1#L2740 | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2686/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2686/timeline | null | not_planned | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2685 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2685/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2685/comments | https://api.github.com/repos/coleifer/peewee/issues/2685/events | https://github.com/coleifer/peewee/issues/2685 | 1,609,389,010 | I_kwDOAA7yGM5f7VPS | 2,685 | Cast Bigint to timestamp | {
"login": "antoinebrtd",
"id": 34452191,
"node_id": "MDQ6VXNlcjM0NDUyMTkx",
"avatar_url": "https://avatars.githubusercontent.com/u/34452191?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/antoinebrtd",
"html_url": "https://github.com/antoinebrtd",
"followers_url": "https://api.github.com/users/antoinebrtd/followers",
"following_url": "https://api.github.com/users/antoinebrtd/following{/other_user}",
"gists_url": "https://api.github.com/users/antoinebrtd/gists{/gist_id}",
"starred_url": "https://api.github.com/users/antoinebrtd/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/antoinebrtd/subscriptions",
"organizations_url": "https://api.github.com/users/antoinebrtd/orgs",
"repos_url": "https://api.github.com/users/antoinebrtd/repos",
"events_url": "https://api.github.com/users/antoinebrtd/events{/privacy}",
"received_events_url": "https://api.github.com/users/antoinebrtd/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Is there a very compelling reason why you are using `TimestampField` at all, instead of `DateTimeField`? It's really intended mostly for Sqlite users, which does not provide a dedicated date/time type.\r\n\r\nAt any rate, you need to use the postgres `to_timestamp` function here if you insist on doing it this way:\r\n\r\n```sql\r\nselect extract(week from to_timestamp(1677887000));\r\n```\r\n\r\nSo probably something like (untested):\r\n\r\n```python\r\n.group_by(fn.date_part('week', fn.to_timestamp(Game.ts_played)))\r\n```"
] | 2023-03-03T23:16:36 | 2023-03-03T23:56:30 | 2023-03-03T23:56:29 | NONE | null | Hello,
I am trying to partition some data using `fn.date_part` on a `TimestampField`.
Here is my simplified model:
```
class Game(Model):
id = PrimaryKeyField()
ts_played = TimestampField(utc=True, default=None, null=True)
score = IntegerField(null=True)
```
My full query:
```
results = Game \
.select(
fn.date_part("week", Game.ts_played).alias("week"),
fn.SUM(Game.score).alias("total_score")
) \
.where(
Game.ts_played.is_null(False),
Game.score.is_null(False),
Game.ts_played >= 123456789,
Game.ts_played <= 987654321
) \
.group_by(fn.date_part("week", Game.ts_played)) \
.order_by(fn.date_part("week", Game.ts_played))
```
I get the following error:
```
peewee.ProgrammingError: function date_part(unknown, bigint) does not exist
```
which does not surprise me because TimestampField is not really a timestamp but rather a Bigint.
I then try to cast the underlying bigint to timestamp, replacing `Game.ts_played` everywhere in the query above with:
```
Game.ts_played.cast("timestamp")
```
I get the error
```
peewee.ProgrammingError: cannot cast type bigint to timestamp without time zone
```
It works fine without casting when I change `ts_played` to be a `DateTimeField`. Is there a convenient way to partition a `TimestampField` in weeks? | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2685/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2685/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2684 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2684/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2684/comments | https://api.github.com/repos/coleifer/peewee/issues/2684/events | https://github.com/coleifer/peewee/issues/2684 | 1,601,653,522 | I_kwDOAA7yGM5fd0sS | 2,684 | Build failures with Cython 3.0.0b1 | {
"login": "mgorny",
"id": 110765,
"node_id": "MDQ6VXNlcjExMDc2NQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/110765?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/mgorny",
"html_url": "https://github.com/mgorny",
"followers_url": "https://api.github.com/users/mgorny/followers",
"following_url": "https://api.github.com/users/mgorny/following{/other_user}",
"gists_url": "https://api.github.com/users/mgorny/gists{/gist_id}",
"starred_url": "https://api.github.com/users/mgorny/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/mgorny/subscriptions",
"organizations_url": "https://api.github.com/users/mgorny/orgs",
"repos_url": "https://api.github.com/users/mgorny/repos",
"events_url": "https://api.github.com/users/mgorny/events{/privacy}",
"received_events_url": "https://api.github.com/users/mgorny/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Thank you, I think I got 'em in the above commit.",
"Thanks, seems to build now. Note that there's still this warning though:\r\n\r\n```\r\n[1/2] Cythonizing playhouse/_sqlite_ext.pyx\r\n/tmp/peewee/venv/lib/python3.11/site-packages/Cython/Compiler/Main.py:370: FutureWarning: Cython directive 'language_level' not set, using '3str' for now (Py3). This has changed from earlier releases! File: /tmp/peewee/playhouse/_sqlite_ext.pyx\r\n tree = Parsing.p_module(s, pxd, full_module_name)\r\n[2/2] Cythonizing playhouse/_sqlite_udf.pyx\r\n/tmp/peewee/venv/lib/python3.11/site-packages/Cython/Compiler/Main.py:370: FutureWarning: Cython directive 'language_level' not set, using '3str' for now (Py3). This has changed from earlier releases! File: /tmp/peewee/playhouse/_sqlite_udf.pyx\r\n tree = Parsing.p_module(s, pxd, full_module_name)\r\n```",
"Yeah I'm going to have to spend some time understanding the ramifications of setting the lang level directive. It should probably just be 3 but like I said, not sure the ramifications of that yet and tests are passing so I'll plan on keeping an eye on it."
] | 2023-02-27T17:48:43 | 2023-02-27T18:05:46 | 2023-02-27T17:57:56 | NONE | null | Cython 3.0.0 has released its first beta, meaning that 3.0.0 final will be out sooner than later. Right now peewee fails to build with it:
```
$ python setup.py build
Compiling playhouse/_sqlite_udf.pyx because it changed.
Compiling playhouse/_sqlite_ext.pyx because it changed.
[1/2] Cythonizing playhouse/_sqlite_ext.pyx
/tmp/peewee/venv/lib/python3.11/site-packages/Cython/Compiler/Main.py:370: FutureWarning: Cython directive 'language_level' not set, using '3str' for now (Py3). This has changed from earlier releases! File: /tmp/peewee/playhouse/_sqlite_ext.pyx
tree = Parsing.p_module(s, pxd, full_module_name)
Error compiling Cython file:
------------------------------------------------------------
...
pIdxInfo.estimatedCost = <double>1
pIdxInfo.estimatedRows = 10
else:
# Penalize score based on number of missing params.
pIdxInfo.estimatedCost = <double>10000000000000 * <double>(nParams - nArg)
pIdxInfo.estimatedRows = 10 ** (nParams - nArg)
^
------------------------------------------------------------
playhouse/_sqlite_ext.pyx:608:40: Cannot assign type 'double' to 'sqlite3_int64'
Error compiling Cython file:
------------------------------------------------------------
...
self._commit_hook = fn
if fn is None:
sqlite3_commit_hook(self.conn.db, NULL, NULL)
else:
sqlite3_commit_hook(self.conn.db, _commit_callback, <void *>fn)
^
------------------------------------------------------------
playhouse/_sqlite_ext.pyx:1463:46: Cannot assign type 'int (void *) except? -1 nogil' to 'int (*)(void *) noexcept nogil'
Error compiling Cython file:
------------------------------------------------------------
...
self._rollback_hook = fn
if fn is None:
sqlite3_rollback_hook(self.conn.db, NULL, NULL)
else:
sqlite3_rollback_hook(self.conn.db, _rollback_callback, <void *>fn)
^
------------------------------------------------------------
playhouse/_sqlite_ext.pyx:1473:48: Cannot assign type 'void (void *) except * nogil' to 'void (*)(void *) noexcept nogil'
Error compiling Cython file:
------------------------------------------------------------
...
self._update_hook = fn
if fn is None:
sqlite3_update_hook(self.conn.db, NULL, NULL)
else:
sqlite3_update_hook(self.conn.db, _update_callback, <void *>fn)
^
------------------------------------------------------------
playhouse/_sqlite_ext.pyx:1483:46: Cannot assign type 'void (void *, int, const char *, const char *, sqlite3_int64) except * nogil' to 'void (*)(void *, int, char *, char *, sqlite3_int64) noexcept nogil'
Error compiling Cython file:
------------------------------------------------------------
...
"""
if not self.conn.initialized or not self.conn.db:
return False
cdef sqlite3_int64 n = timeout * 1000
sqlite3_busy_handler(self.conn.db, _aggressive_busy_handler, <void *>n)
^
------------------------------------------------------------
playhouse/_sqlite_ext.pyx:1494:43: Cannot assign type 'int (void *, int) except? -1 nogil' to 'int (*)(void *, int) noexcept nogil'
Traceback (most recent call last):
File "/tmp/peewee/setup.py", line 185, in <module>
_do_setup(extension_support, sqlite_extension_support)
File "/tmp/peewee/setup.py", line 180, in _do_setup
ext_modules=cythonize(ext_modules))
^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/peewee/venv/lib/python3.11/site-packages/Cython/Build/Dependencies.py", line 1134, in cythonize
cythonize_one(*args)
File "/tmp/peewee/venv/lib/python3.11/site-packages/Cython/Build/Dependencies.py", line 1301, in cythonize_one
raise CompileError(None, pyx_file)
Cython.Compiler.Errors.CompileError: playhouse/_sqlite_ext.pyx
```
To reproduce:
```
pip install Cython==3.0.0b1
python setup.py build
``` | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2684/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2684/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2683 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2683/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2683/comments | https://api.github.com/repos/coleifer/peewee/issues/2683/events | https://github.com/coleifer/peewee/issues/2683 | 1,599,887,876 | I_kwDOAA7yGM5fXFoE | 2,683 | Can't query with unicode character | {
"login": "groggyegg",
"id": 66879210,
"node_id": "MDQ6VXNlcjY2ODc5MjEw",
"avatar_url": "https://avatars.githubusercontent.com/u/66879210?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/groggyegg",
"html_url": "https://github.com/groggyegg",
"followers_url": "https://api.github.com/users/groggyegg/followers",
"following_url": "https://api.github.com/users/groggyegg/following{/other_user}",
"gists_url": "https://api.github.com/users/groggyegg/gists{/gist_id}",
"starred_url": "https://api.github.com/users/groggyegg/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/groggyegg/subscriptions",
"organizations_url": "https://api.github.com/users/groggyegg/orgs",
"repos_url": "https://api.github.com/users/groggyegg/repos",
"events_url": "https://api.github.com/users/groggyegg/events{/privacy}",
"received_events_url": "https://api.github.com/users/groggyegg/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"This probably has to do with the collation you're using. Is this MySQL?",
"No, I’m using SQLite",
"Wait so your data is *literally* the Unicode escapes? If so have you tried double escaping the forward quote?",
"> Wait so your data is _literally_ the Unicode escapes? If so have you tried double escaping the forward quote?\r\n\r\nThat seems to fix the problem. I'm suprised that I didn't realized that :astonished:\r\nThanks!"
] | 2023-02-26T00:49:33 | 2023-02-26T12:53:07 | 2023-02-26T12:53:07 | NONE | null | I have a column containing this type of data `{"zh": "\u65e5\u97e9\u5267"}` and when I query it with this code `Video.select().where(Video.director.contains('\u65e5\u97e9\u5267'))` , I'm not getting any result. It only works when I query non-unicode text e.g. `Video.select().where(Video.director.contains('"zh"'))`.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2683/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2683/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2682 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2682/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2682/comments | https://api.github.com/repos/coleifer/peewee/issues/2682/events | https://github.com/coleifer/peewee/issues/2682 | 1,599,859,949 | I_kwDOAA7yGM5fW-zt | 2,682 | peewee.InterfaceError: Error, database must be initialized before opening a connection. | {
"login": "NPZYMR",
"id": 101792221,
"node_id": "U_kgDOBhE53Q",
"avatar_url": "https://avatars.githubusercontent.com/u/101792221?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/NPZYMR",
"html_url": "https://github.com/NPZYMR",
"followers_url": "https://api.github.com/users/NPZYMR/followers",
"following_url": "https://api.github.com/users/NPZYMR/following{/other_user}",
"gists_url": "https://api.github.com/users/NPZYMR/gists{/gist_id}",
"starred_url": "https://api.github.com/users/NPZYMR/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/NPZYMR/subscriptions",
"organizations_url": "https://api.github.com/users/NPZYMR/orgs",
"repos_url": "https://api.github.com/users/NPZYMR/repos",
"events_url": "https://api.github.com/users/NPZYMR/events{/privacy}",
"received_events_url": "https://api.github.com/users/NPZYMR/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"If you had taken a moment to debug this, you would have found that `db_name = os.environ.get('DB_NAME')` is somehow getting set to `None`. This is the issue.",
"In debug, I'm getting my DB name in \"db_name = os.environ.get('DB_NAME')\" but\ndon't know how to rectify this now. please don't mind this I'm new to\nprogramming might sound silly.\n\nOn Sun, Feb 26, 2023 at 4:13 AM Charles Leifer ***@***.***>\nwrote:\n\n> If you had taken a moment to debug this, you would have found that db_name\n> = os.environ.get('DB_NAME') is somehow getting set to None. This is the\n> issue.\n>\n> —\n> Reply to this email directly, view it on GitHub\n> <https://github.com/coleifer/peewee/issues/2682#issuecomment-1445220548>,\n> or unsubscribe\n> <https://github.com/notifications/unsubscribe-auth/AYITTXNG2NCYUIK3EDA2Y3TWZKDHNANCNFSM6AAAAAAVIC6EQA>\n> .\n> You are receiving this because you authored the thread.Message ID:\n> ***@***.***>\n>\n\n-- \n============================================================================\nIMPORTANT NOTICE: The information in this e-mail and any attached files is \nCONFIDENTIAL and may be legally privileged or prohibited from disclosure \nand unauthorised use. The views of the author may not necessarily reflect \nthose of Zymr, Inc. It is intended solely for the addressee, or the \nemployee or agent responsible for delivering such materials to the \naddressee. If you have received this message in error please return it to \nthe sender then delete the email and destroy any copies of it. If you are \nnot the intended recipient, any form of reproduction, dissemination, \ncopying, disclosure, modification, distribution and/or publication, or any \naction taken or omitted to be taken in reliance upon this message or its \nattachments is prohibited and may be unlawful. At present the integrity of \ne-mail across the Internet cannot be guaranteed and messages sent via this \nmedium are potentially at risk. All liability is excluded to the extent \npermitted by law for any claims arising as a result of the use of this \nmedium to transmit information by or to Zymr, Inc.\n",
"You would want to double-check what you're specifying wherever you have your `PostgresqlDatabase(...)` constructor, e.g.:\r\n\r\n```\r\nassert db_name, 'db_name is empty!'\r\npg_db = PostgresqlExtDatabase(db_name, user=db_user, password=db_password,host=db_host, port=db_port)\r\n```",
"Thank you for your help, I'll check it out.\n\nOn Sun, Feb 26, 2023 at 4:27 AM Charles Leifer ***@***.***>\nwrote:\n\n> You would want to double-check what you're specifying wherever you have\n> your PostgresqlDatabase(...) constructor, e.g.:\n>\n> assert db_name, 'db_name is empty!'\n> pg_db = PostgresqlExtDatabase(db_name, user=db_user, password=db_password,host=db_host, port=db_port)\n>\n> —\n> Reply to this email directly, view it on GitHub\n> <https://github.com/coleifer/peewee/issues/2682#issuecomment-1445222329>,\n> or unsubscribe\n> <https://github.com/notifications/unsubscribe-auth/AYITTXMRJVQ5CQBNMEH2RDDWZKE3XANCNFSM6AAAAAAVIC6EQA>\n> .\n> You are receiving this because you authored the thread.Message ID:\n> ***@***.***>\n>\n\n-- \n============================================================================\nIMPORTANT NOTICE: The information in this e-mail and any attached files is \nCONFIDENTIAL and may be legally privileged or prohibited from disclosure \nand unauthorised use. The views of the author may not necessarily reflect \nthose of Zymr, Inc. It is intended solely for the addressee, or the \nemployee or agent responsible for delivering such materials to the \naddressee. If you have received this message in error please return it to \nthe sender then delete the email and destroy any copies of it. If you are \nnot the intended recipient, any form of reproduction, dissemination, \ncopying, disclosure, modification, distribution and/or publication, or any \naction taken or omitted to be taken in reliance upon this message or its \nattachments is prohibited and may be unlawful. At present the integrity of \ne-mail across the Internet cannot be guaranteed and messages sent via this \nmedium are potentially at risk. All liability is excluded to the extent \npermitted by law for any claims arising as a result of the use of this \nmedium to transmit information by or to Zymr, Inc.\n",
"After migration do I need to remove migrate(.... ) function from my model\nfile?\n\nHow will I add new model field in my existing model class(python code)?\n\n-- \n============================================================================\nIMPORTANT NOTICE: The information in this e-mail and any attached files is \nCONFIDENTIAL and may be legally privileged or prohibited from disclosure \nand unauthorised use. The views of the author may not necessarily reflect \nthose of Zymr, Inc. It is intended solely for the addressee, or the \nemployee or agent responsible for delivering such materials to the \naddressee. If you have received this message in error please return it to \nthe sender then delete the email and destroy any copies of it. If you are \nnot the intended recipient, any form of reproduction, dissemination, \ncopying, disclosure, modification, distribution and/or publication, or any \naction taken or omitted to be taken in reliance upon this message or its \nattachments is prohibited and may be unlawful. At present the integrity of \ne-mail across the Internet cannot be guaranteed and messages sent via this \nmedium are potentially at risk. All liability is excluded to the extent \npermitted by law for any claims arising as a result of the use of this \nmedium to transmit information by or to Zymr, Inc.\n",
"```class User(Model):\n pass\n\nf = TextField()\nUser._meta.add_field('username', f)\nprint(User._meta.fields)# {'id': <peewee.AutoField at\n0x7f552815bc50>,# 'username': <peewee.TextField at 0x7f552b1d7e10>}\n```\n\n\nI've read one reply of yours in which you are referring to this. Is\nthat referring to what I want.\n\n\nOn Mon, Feb 27, 2023 at 1:07 AM Naveen Pandia ***@***.***>\nwrote:\n\n> After migration do I need to remove migrate(.... ) function from my model\n> file?\n>\n> How will I add new model field in my existing model class(python code)?\n>\n\n-- \n============================================================================\nIMPORTANT NOTICE: The information in this e-mail and any attached files is \nCONFIDENTIAL and may be legally privileged or prohibited from disclosure \nand unauthorised use. The views of the author may not necessarily reflect \nthose of Zymr, Inc. It is intended solely for the addressee, or the \nemployee or agent responsible for delivering such materials to the \naddressee. If you have received this message in error please return it to \nthe sender then delete the email and destroy any copies of it. If you are \nnot the intended recipient, any form of reproduction, dissemination, \ncopying, disclosure, modification, distribution and/or publication, or any \naction taken or omitted to be taken in reliance upon this message or its \nattachments is prohibited and may be unlawful. At present the integrity of \ne-mail across the Internet cannot be guaranteed and messages sent via this \nmedium are potentially at risk. All liability is excluded to the extent \npermitted by law for any claims arising as a result of the use of this \nmedium to transmit information by or to Zymr, Inc.\n"
] | 2023-02-25T22:25:31 | 2023-02-26T19:46:52 | 2023-02-25T22:42:51 | NONE | null | import os
from playhouse.postgres_ext import CharField, DateTimeField, IntegerField, BooleanField
from .base import Base
import datetime
from peewee import PostgresqlDatabase
from playhouse.migrate import *
db_name = os.environ.get('DB_NAME')
db_host = os.environ.get('DB_HOST')
db_port = os.environ.get('DB_PORT')
db_password = os.environ.get('DB_PASSWORD')
db_user= os.environ.get('DB_USER')
# Initialize database.
pg_db = PostgresqlExtDatabase(db_name, user=db_user, password=db_password,host=db_host, port=db_port)
migrator = PostgresqlMigrator(pg_db)
class EmpDetails(Base):
id = CharField(25, null=False)
email = CharField(255, unique=True)
name = CharField(255)
location = CharField(255)
created_at = DateTimeField(default=datetime.datetime.now)
updated_at = DateTimeField(default=datetime.datetime.now)
is_active = BooleanField(default=True)
role = CharField(25)
class Meta:
table_name = 'emp_details'
test_field = CharField(default='')
migrate(
migrator.add_column('emp_details', 'test', test_field),
)
I'm trying to make my DB instance for migration but getting an error :
```
File "/home/naveen.p@ah.zymrinc.com/Desktop/zfr/server/s-venv/lib/python3.8/site-packages/peewee.py", line 3026, in connect
raise InterfaceError('Error, database must be initialized '
peewee.InterfaceError: Error, database must be initialized before opening a connection.
``` | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2682/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2682/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2681 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2681/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2681/comments | https://api.github.com/repos/coleifer/peewee/issues/2681/events | https://github.com/coleifer/peewee/issues/2681 | 1,599,322,496 | I_kwDOAA7yGM5fU7mA | 2,681 | Does migrate() run every time I run server(Ex. flask server) | {
"login": "NPZYMR",
"id": 101792221,
"node_id": "U_kgDOBhE53Q",
"avatar_url": "https://avatars.githubusercontent.com/u/101792221?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/NPZYMR",
"html_url": "https://github.com/NPZYMR",
"followers_url": "https://api.github.com/users/NPZYMR/followers",
"following_url": "https://api.github.com/users/NPZYMR/following{/other_user}",
"gists_url": "https://api.github.com/users/NPZYMR/gists{/gist_id}",
"starred_url": "https://api.github.com/users/NPZYMR/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/NPZYMR/subscriptions",
"organizations_url": "https://api.github.com/users/NPZYMR/orgs",
"repos_url": "https://api.github.com/users/NPZYMR/repos",
"events_url": "https://api.github.com/users/NPZYMR/events{/privacy}",
"received_events_url": "https://api.github.com/users/NPZYMR/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Let's say you want to add a column to a model in an application. The typical process would be to:\r\n\r\n1. Stop the application.\r\n2. Update the schema of the database by running a migration once.\r\n3. Restart the application with the new field present in the code.\r\n\r\nYou can always add a \"check\" in your `create_...()` function to see if the column exists, and if not, do the migration. This would only be necessary if you have lots of instances of your application running around which will be updated at some unknown time, e.g., this is a library or something.",
"> Let's say you want to add a column to a model in an application. The typical process would be to:\r\n> \r\n> 1. Stop the application.\r\n> 2. Update the schema of the database by running a migration once.\r\n> 3. Restart the application with the new field present in the code.\r\n> \r\n> You can always add a \"check\" in your `create_...()` function to see if the column exists, and if not, do the migration. This would only be necessary if you have lots of instances of your application running around which will be updated at some unknown time, e.g., this is a library or something.\r\n\r\n\r\nI want to make sure that the Production env runs smoothly as whatever migrations I've written will be applied once, stopping production env won't be a good option very time.\r\n\r\nwhat you mentioned about the check I didn't get that properly.\r\n\r\nI'm calling create _table like this:\r\n\r\n```\r\ndef create_tables():\r\n \r\n EmpDetails.create_table(fail_silently=True)\r\n\r\nI'm going to add multiple models here\r\n```\r\n\r\nand calling this create_tables() at server start.\r\n\r\n\r\nSecondly, where to add that new column field (Question 1)?",
"I think you are imagining you buy some security by doing it this way but you really do not. Schema changes are one-time operations. It's probably best to put them in standalone scripts and run them when you deploy application changes."
] | 2023-02-24T21:54:40 | 2023-02-25T12:46:39 | 2023-02-24T22:51:06 | NONE | null | Suppose I've added create_table(fail_silently=True) when the flask server starts.
In this model class below, I want to add the column "test" in my DB corresponding field "test_field".
Question:
1. Do I need to add "test_field" in my model **EmpDetails** or outside the **class** or both(like I did in the code snippet) for migrations?
2. As I've created create_function() to run at the server(flask server) start, will it migrate() every time at the start of the server(_I need to make sure whether data added in the new column will not vanish if migrate runs every time_).
or if the schema changes are done in the database will it not rerun the migration?
Code snippet for my model class:
```
class EmpDetails(Base):
id = CharField(25, null=False)
email = CharField(255, unique=True)
name = CharField(255)
location = CharField(255)
created_at = DateTimeField(default=datetime.datetime.now)
updated_at = DateTimeField(default=datetime.datetime.now)
is_active = BooleanField(default=True)
role = CharField(25)
test_field = CharField(default='') -------> here
class Meta:
table_name = 'emp_details'
test_field = CharField(default='') ---------> here
migrate(
migrator.add_column(EmpDetails._meta.emp_details, 'test', test_field),
)
``` | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2681/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2681/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2680 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2680/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2680/comments | https://api.github.com/repos/coleifer/peewee/issues/2680/events | https://github.com/coleifer/peewee/issues/2680 | 1,593,303,175 | I_kwDOAA7yGM5e9-CH | 2,680 | How to use with pgbouncer? | {
"login": "backpropogation",
"id": 34347364,
"node_id": "MDQ6VXNlcjM0MzQ3MzY0",
"avatar_url": "https://avatars.githubusercontent.com/u/34347364?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/backpropogation",
"html_url": "https://github.com/backpropogation",
"followers_url": "https://api.github.com/users/backpropogation/followers",
"following_url": "https://api.github.com/users/backpropogation/following{/other_user}",
"gists_url": "https://api.github.com/users/backpropogation/gists{/gist_id}",
"starred_url": "https://api.github.com/users/backpropogation/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/backpropogation/subscriptions",
"organizations_url": "https://api.github.com/users/backpropogation/orgs",
"repos_url": "https://api.github.com/users/backpropogation/repos",
"events_url": "https://api.github.com/users/backpropogation/events{/privacy}",
"received_events_url": "https://api.github.com/users/backpropogation/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"They are somewhat orthogonal, and also dependent upon what kind of pooling you use in pgbouncer (session, txn or statement). Peewee's pooled variants will maintain open connections to postgres so doubling-up and using `PooledPostgresqlDatabase` + pgbouncer is probably unnecessary. It also kinda depends on what latency you anticipate with opening the connection (whether to pg itself or to your pgbouncer). There \"right\" answer is: it depends.\r\n\r\nIf you use pgbouncer, though, a good starting place is just to use `PostgresqlDatabase` and point it at pgbouncer.\r\n\r\nIf you want to let peewee handle a connection pool, use the Pooled- variants."
] | 2023-02-21T11:23:00 | 2023-02-21T13:35:54 | 2023-02-21T13:35:54 | NONE | null | Could someone, please, make clear, how to use peewee with pgbouncer?
Am I supposed to use `PooledPostgresqlExtDatabase` or it's overkill and just `PostgresqlExtDatabase` will be fine? Connection string will point to pgbouncer. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2680/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2680/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2679 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2679/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2679/comments | https://api.github.com/repos/coleifer/peewee/issues/2679/events | https://github.com/coleifer/peewee/pull/2679 | 1,592,259,335 | PR_kwDOAA7yGM5KXb30 | 2,679 | Fix typo in docs | {
"login": "puntonim",
"id": 6423485,
"node_id": "MDQ6VXNlcjY0MjM0ODU=",
"avatar_url": "https://avatars.githubusercontent.com/u/6423485?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/puntonim",
"html_url": "https://github.com/puntonim",
"followers_url": "https://api.github.com/users/puntonim/followers",
"following_url": "https://api.github.com/users/puntonim/following{/other_user}",
"gists_url": "https://api.github.com/users/puntonim/gists{/gist_id}",
"starred_url": "https://api.github.com/users/puntonim/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/puntonim/subscriptions",
"organizations_url": "https://api.github.com/users/puntonim/orgs",
"repos_url": "https://api.github.com/users/puntonim/repos",
"events_url": "https://api.github.com/users/puntonim/events{/privacy}",
"received_events_url": "https://api.github.com/users/puntonim/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2023-02-20T17:54:34 | 2023-02-20T21:01:12 | 2023-02-20T21:01:12 | NONE | null | null | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2679/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2679/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/2679",
"html_url": "https://github.com/coleifer/peewee/pull/2679",
"diff_url": "https://github.com/coleifer/peewee/pull/2679.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/2679.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/2678 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2678/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2678/comments | https://api.github.com/repos/coleifer/peewee/issues/2678/events | https://github.com/coleifer/peewee/issues/2678 | 1,587,353,006 | I_kwDOAA7yGM5enRWu | 2,678 | Playhouse Migrator does not honour model schema | {
"login": "berzi",
"id": 32619123,
"node_id": "MDQ6VXNlcjMyNjE5MTIz",
"avatar_url": "https://avatars.githubusercontent.com/u/32619123?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/berzi",
"html_url": "https://github.com/berzi",
"followers_url": "https://api.github.com/users/berzi/followers",
"following_url": "https://api.github.com/users/berzi/following{/other_user}",
"gists_url": "https://api.github.com/users/berzi/gists{/gist_id}",
"starred_url": "https://api.github.com/users/berzi/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/berzi/subscriptions",
"organizations_url": "https://api.github.com/users/berzi/orgs",
"repos_url": "https://api.github.com/users/berzi/repos",
"events_url": "https://api.github.com/users/berzi/events{/privacy}",
"received_events_url": "https://api.github.com/users/berzi/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I monkeypatched this on my end like so:\r\n```python\r\ndef __sql__(self, ctx):\r\n return ctx.literal(\".\".join(self._path))\r\nEntity.__sql__ = __sql__\r\n```\r\nand then I pass `schema.table` as table name to each migrator action, but that gets rid of quoting entirely (and I can't even manually add them in my table path manually because, for reasons unclear to me, Entity does `.replace('\"', '\"\"')`, causing zero-length identifiers in the query), so this is not a general solution that I could submit as a pull request. I don't have the time to delve deeper into Peewee's code to know what the most effective fix would be, much less write tests for these cases.\r\n\r\nBut I suspect it isn't actually a hard fix for someone who knows the codebase well, so I hope for a quick reaction to this issue.",
"Have you tried the suggestion from the docs?\r\n\r\n>Postgres users may need to set the search-path when using a non-standard schema. This can be done as follows:\r\n\r\n```\r\nnew_field = TextField(default='', null=False)\r\nmigrator = PostgresqlMigrator(db)\r\nmigrate(\r\n migrator.set_search_path('my_schema_name'),\r\n migrator.add_column('table', 'field_name', new_field))\r\n```\r\n\r\nhttp://docs.peewee-orm.com/en/latest/peewee/playhouse.html#PostgresqlMigrator.set_search_path",
"Doing this on the migrator seems rather hard to find for the user. I\nunderstand why it makes sense that it's there from Peewee's perspective,\nbut is there no way for Peewee to get it automatically from the model?\n\nAfter all, different models might be on different schemas and that would\nmean having to either make multiple migrators or change the migrator's path\nmid-way, which hinders and complicates more generic systems that install\nmigrations seemingly unnecessarily.\n\nIt's also, honestly, a hard to discover edge case.\n\nOn Thu, 16 Feb 2023, 17:35 Charles Leifer ***@***.***> wrote:\n\n> Have you tried the suggestion from the docs?\n>\n> Postgres users may need to set the search-path when using a non-standard\n> schema. This can be done as follows:\n>\n> new_field = TextField(default='', null=False)\n> migrator = PostgresqlMigrator(db)\n> migrate(migrator.set_search_path('my_schema_name'),\n> migrator.add_column('table', 'field_name', new_field))\n>\n> —\n> Reply to this email directly, view it on GitHub\n> <https://github.com/coleifer/peewee/issues/2678#issuecomment-1433372035>,\n> or unsubscribe\n> <https://github.com/notifications/unsubscribe-auth/AHY3U437IIXFWCJX2CQW6FLWXZJM5ANCNFSM6AAAAAAU55VVAQ>\n> .\n> You are receiving this because you authored the thread.Message ID:\n> ***@***.***>\n>\n",
"Moreover, it just doesn't work: I get the same error if I use `migrator.set_search_path('my_schema_name')`: Peewee quotes the whole thing and not the schema and table separately.\r\n\r\nI also found out that for any ForeignKeyField, the related model's table is looked up without schema.",
"That doesn't make sense because it should be setting the schema on the connection so you don't specify it anywhere. Note that the migrator does not operate on a model, it takes a table name. Can you explain how it's putting the schema and table in quotes?",
"I'm not really sure, the logic inside Peewee is rather convoluted and I don't know it well enough. To be clear: when testing your suggestion I disabled my monkeypatching entirely, so I'm not meddling with Peewee's code at all when it fails.\r\n\r\n\r\nRegarding this:\r\n\r\n> I also found out that for any ForeignKeyField, the related model's table is looked up without schema.\r\n\r\nI'm pretty sure this happens in `SchemaMigrator.add_inline_fk_sql()`, where:\r\n\r\n```python\r\ndef add_inline_fk_sql(self, ctx, field):\r\n ctx = (ctx\r\n .literal(' REFERENCES ')\r\n .sql(Entity(field.rel_model._meta.table_name)) # <== schema is not taken into account here\r\n .literal(' ')\r\n .sql(EnclosedNodeList((Entity(field.rel_field.column_name),))))\r\n if field.on_delete is not None:\r\n ctx = ctx.literal(' ON DELETE %s' % field.on_delete)\r\n if field.on_update is not None:\r\n ctx = ctx.literal(' ON UPDATE %s' % field.on_update)\r\n return ctx\r\n```",
"I think something is wrong, because it works fine for me. Example script:\r\n\r\n```python\r\n\r\nclass User(db.Model):\r\n key = CharField()\r\n class Meta:\r\n schema = 'custom'\r\n table_name = 'users'\r\n\r\nclass Tweet(db.Model):\r\n content = TextField()\r\n class Meta:\r\n schema = 'custom'\r\n\r\ndb.create_tables([User, Tweet])\r\n\r\nprint(db.get_columns('tweet', 'custom'))\r\n\r\n# Uh-oh, forgot to add the \"user_id\" foreign-key from Tweet -> User.\r\nuser = ForeignKeyField(User, field=User.id, null=True)\r\n\r\nmigrator = PostgresqlMigrator(db)\r\nmigrate(\r\n migrator.set_search_path('custom'),\r\n migrator.add_column(Tweet._meta.table_name, 'user_id', user),\r\n)\r\n\r\nprint(db.get_columns('tweet', 'custom'))\r\nprint(db.get_foreign_keys('tweet', 'custom'))\r\n```\r\n\r\nThe output is correct:\r\n\r\n```\r\n# Before migrate\r\n[\r\n ColumnMetadata(name='id', data_type='integer', ...), \r\n ColumnMetadata(name='content', data_type='text', ...)\r\n]\r\n\r\n# After migrate\r\n[\r\n ColumnMetadata(name='id', data_type='integer'...),\r\n ColumnMetadata(name='content', data_type='text', ...),\r\n ColumnMetadata(name='user_id', data_type='integer', ...)\r\n]\r\n\r\n# Our foreign-key shows up fine:\r\n[ForeignKeyMetadata(column='user_id', dest_table='users', dest_column='id', table='tweet')]\r\n```"
] | 2023-02-16T09:41:36 | 2023-02-17T19:19:43 | 2023-02-16T16:37:17 | NONE | null | Sorry for not including a full code example: I'm using playhouse.migrate in a utility and it would be more than overkill to include all of it, not to mention it's closed-source company code I'm not allowed to share. But I believe there's enough information to tackle the issue.
In all the scenarios below, I call `migrate(*actions)` where `actions = [migrator.add_column(table_name, "fieldname", TextField(default=""))]` or similar. `table_name` is always `MyPeeweeModel._meta.table_name` and the model always has `Meta.schema` set to a constant value. Note that I'm using Postgresql (both for the database and the migrator, obviously).
Note: if I want to create the table for my model it seems my only options are either raw SQL or `database.create_tables()`. Setting aside the fact that I don't want to use the latter because it creates fields for the *current* state of the model, which isn't what I want, if I do use it, it **does** create the table in the correct schema.
Further note: there seems to be no way to create the schema itself, so I resorted to doing this manually. I can't remember if `.create_tables()` attemps doing it at all but as I said, I need to bypass that and create the table manually to prevent inconsistencies between the table's initial state and any migrations.
**Scenario 1:** I attempt:
```python
migrate(
# table_name is simply MyPeeweeModel._meta.table_name
migrator.add_column(table_name, "fieldname", TextField(default="")),
)
```
*Result:* "peewee.ProgrammingError: relation "mytable" does not exist". The table *does* exist in the database at that point, so I must surmise that the schema is not prepended to the path to the table; in other words Peewee looks for the table without honouring the schema.
**Scenario 2:** I attempt:
```python
migrate(
# table_name is a string like schema.table where the schema comes from MyPeeweeModel._meta.schema
migrator.add_column(table_name, "fieldname", TextField(default="")),
)
```
*Result:* "peewee.ProgrammingError: relation "myschema.mytable" does not exist". Again, the table actually exists in the right schema. The relation which isn't found is incorrectly quoted, because it enquotes myschema.mytable entirely instead of the schema and the table separately.
**Scenario 3:** I attempt:
```python
migrate(
# table_name is a pre-quoted string like "schema"."table"
migrator.add_column(table_name, "fieldname", TextField(default="")),
)
```
*Result:* "peewee.ProgrammingError: relation ""myschema"."mytable"" does not exist". Same as above: the whole thing is quoted regardless of the fact that the identifiers are already quoted.
**Scenario 4:** As I traced back the quoting Peewee does to the `Entity` class and I noticed its init:
```python
def __init__(self, *path):
self._path = [part.replace('"', '""') for part in path if part]
```
takes an iterable, I tried giving it a tuple like `(schema, table)` but that didn't work, and if I try to place a breakpoint in the init, my debugger crashes every time while trying to collect data (presumably on `self`'s attributes), even if I monkeypatch the whole function (!). As such, I'm quite stuck and am also unable to open a pull request to fix the issue myself, since debugging it seems nigh on impossible.
I'm honestly surprised this hasn't come up before: has nobody ever tested or tried to use the migration helpers with a non-default schema? | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2678/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2678/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2677 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2677/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2677/comments | https://api.github.com/repos/coleifer/peewee/issues/2677/events | https://github.com/coleifer/peewee/pull/2677 | 1,577,460,129 | PR_kwDOAA7yGM5JmIK6 | 2,677 | query.first() mutates the query | {
"login": "klen",
"id": 90699,
"node_id": "MDQ6VXNlcjkwNjk5",
"avatar_url": "https://avatars.githubusercontent.com/u/90699?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/klen",
"html_url": "https://github.com/klen",
"followers_url": "https://api.github.com/users/klen/followers",
"following_url": "https://api.github.com/users/klen/following{/other_user}",
"gists_url": "https://api.github.com/users/klen/gists{/gist_id}",
"starred_url": "https://api.github.com/users/klen/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/klen/subscriptions",
"organizations_url": "https://api.github.com/users/klen/orgs",
"repos_url": "https://api.github.com/users/klen/repos",
"events_url": "https://api.github.com/users/klen/events{/privacy}",
"received_events_url": "https://api.github.com/users/klen/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"The `first()` method is a bit of a special-case. It applies a limit of 1 to avoid making the server generate the full result-set, as it is assumed that after calling `first()` the query itself will not be iterated. Similarly, the mutation is done in-place so that multiple calls to `first()` do not result in additional queries.\r\n\r\nI will add some documentation explaining this."
] | 2023-02-09T08:32:19 | 2023-02-09T13:40:24 | 2023-02-09T13:40:24 | CONTRIBUTOR | null | The `query.first()` method mutates the query and it may lead to unexpected behaviour
```python
query = SomeModel.select()
first_item = query.first()
for item in query:
# This cycle only runs once, because after first() the query is mutated and now it has limit 1
```
The PR fixes the behaviour. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2677/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2677/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/2677",
"html_url": "https://github.com/coleifer/peewee/pull/2677",
"diff_url": "https://github.com/coleifer/peewee/pull/2677.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/2677.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/2676 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2676/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2676/comments | https://api.github.com/repos/coleifer/peewee/issues/2676/events | https://github.com/coleifer/peewee/pull/2676 | 1,577,125,031 | PR_kwDOAA7yGM5JlA0X | 2,676 | merge latest dev | {
"login": "guardrails-test",
"id": 63639880,
"node_id": "MDQ6VXNlcjYzNjM5ODgw",
"avatar_url": "https://avatars.githubusercontent.com/u/63639880?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/guardrails-test",
"html_url": "https://github.com/guardrails-test",
"followers_url": "https://api.github.com/users/guardrails-test/followers",
"following_url": "https://api.github.com/users/guardrails-test/following{/other_user}",
"gists_url": "https://api.github.com/users/guardrails-test/gists{/gist_id}",
"starred_url": "https://api.github.com/users/guardrails-test/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/guardrails-test/subscriptions",
"organizations_url": "https://api.github.com/users/guardrails-test/orgs",
"repos_url": "https://api.github.com/users/guardrails-test/repos",
"events_url": "https://api.github.com/users/guardrails-test/events{/privacy}",
"received_events_url": "https://api.github.com/users/guardrails-test/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Delete this please."
] | 2023-02-09T02:30:01 | 2023-02-09T13:48:24 | 2023-02-09T02:31:43 | NONE | null | void | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2676/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2676/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/2676",
"html_url": "https://github.com/coleifer/peewee/pull/2676",
"diff_url": "https://github.com/coleifer/peewee/pull/2676.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/2676.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/2675 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2675/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2675/comments | https://api.github.com/repos/coleifer/peewee/issues/2675/events | https://github.com/coleifer/peewee/issues/2675 | 1,575,789,960 | I_kwDOAA7yGM5d7KWI | 2,675 | excuse, how could i use a variable as table's field | {
"login": "EasyArch-lyy",
"id": 46855467,
"node_id": "MDQ6VXNlcjQ2ODU1NDY3",
"avatar_url": "https://avatars.githubusercontent.com/u/46855467?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/EasyArch-lyy",
"html_url": "https://github.com/EasyArch-lyy",
"followers_url": "https://api.github.com/users/EasyArch-lyy/followers",
"following_url": "https://api.github.com/users/EasyArch-lyy/following{/other_user}",
"gists_url": "https://api.github.com/users/EasyArch-lyy/gists{/gist_id}",
"starred_url": "https://api.github.com/users/EasyArch-lyy/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/EasyArch-lyy/subscriptions",
"organizations_url": "https://api.github.com/users/EasyArch-lyy/orgs",
"repos_url": "https://api.github.com/users/EasyArch-lyy/repos",
"events_url": "https://api.github.com/users/EasyArch-lyy/events{/privacy}",
"received_events_url": "https://api.github.com/users/EasyArch-lyy/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Post stuff like this on stackoverflow in the future. You use `getattr(test, field) == 'cc'`."
] | 2023-02-08T09:36:58 | 2023-02-08T13:43:03 | 2023-02-08T13:43:03 | NONE | null | eg:
create table test
(
id int auto_increment primary key,
name varchar(255) null,
);
field = 'name'
query_list = list(test.select().where(test.field=='cc').dicts())
AttributeError: type object 'test' has no attribute 'field'
want to know the api | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2675/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2675/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2674 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2674/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2674/comments | https://api.github.com/repos/coleifer/peewee/issues/2674/events | https://github.com/coleifer/peewee/issues/2674 | 1,574,923,381 | I_kwDOAA7yGM5d32x1 | 2,674 | Example of custom operators for custom fields? | {
"login": "eddyg",
"id": 3235109,
"node_id": "MDQ6VXNlcjMyMzUxMDk=",
"avatar_url": "https://avatars.githubusercontent.com/u/3235109?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/eddyg",
"html_url": "https://github.com/eddyg",
"followers_url": "https://api.github.com/users/eddyg/followers",
"following_url": "https://api.github.com/users/eddyg/following{/other_user}",
"gists_url": "https://api.github.com/users/eddyg/gists{/gist_id}",
"starred_url": "https://api.github.com/users/eddyg/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/eddyg/subscriptions",
"organizations_url": "https://api.github.com/users/eddyg/orgs",
"repos_url": "https://api.github.com/users/eddyg/repos",
"events_url": "https://api.github.com/users/eddyg/events{/privacy}",
"received_events_url": "https://api.github.com/users/eddyg/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"You can find an example of a field with a custom `__add__` implementation in `peewee._StringField` which overrides the add operation to perform a string concatenation. The implementation looks like this:\r\n\r\n```python\r\nclass _StringField(Field):\r\n def adapt(self, value):\r\n if isinstance(value, text_type):\r\n return value\r\n elif isinstance(value, bytes_type):\r\n return value.decode('utf-8')\r\n return text_type(value)\r\n\r\n def __add__(self, other): return StringExpression(self, OP.CONCAT, other)\r\n def __radd__(self, other): return StringExpression(other, OP.CONCAT, self)\r\n\r\nclass CharField(_StringField):\r\n # ...\r\n```\r\n\r\nAnd `StringExpression` is a subclass of `Expression` that similary overrides `__add__` so that additions can be chained or combined.\r\n\r\nFor your case I can't really make sense of what you're trying to do so it's hard to advise. Binary operations need to take two operands and output some kind of a self-contained expression in Peewee. For your case, if it is more complex than this, you probably are at the wrong API level and need to go higher-up.",
"I did see that example, but I was looking for something more complex; one that showed how to properly access the _current_ value of the field in the row, and return an updated value that was based on the current value.\r\n\r\nOf course I could do this by issuing a `select()` to get the current values, updating the dictionary, and then running an `update()`, but I was hoping to be able to take advantage of PeeWee's custom fields and do it in a nice, clean \"upsert\" by overloading `+` to sum the dictionaries.\r\n\r\nHowever, it seems like overriding operators with arbitrary functionality is not possible like I had initially envisioned; any operation you want to perform must exist in SQL, which is the key part I was missing.\r\n\r\nAs always, thanks for your time!",
"You shouldn't need to do a select. Depends on what db you use but I think your first step is to write a sql expression using the available json functions to perform the merge and add. Once you have the sql you can wrap it up however you want, whether via an operator overload or just a helper method.",
"I was fiddling around with how you might do this using Sqlite, here's a small example:\r\n\r\n```sql\r\nCREATE TABLE IF NOT EXISTS \"reg\" (\r\n \"id\" INTEGER NOT NULL PRIMARY KEY, \r\n \"key\" TEXT NOT NULL, \"data\" JSON NOT NULL);\r\n\r\nINSERT INTO \"reg\" (\"key\", \"data\") VALUES ('k1', json('{\"a\": 1, \"b\": 2, \"c\": 3}'));\r\nINSERT INTO \"reg\" (\"key\", \"data\") VALUES ('k2', json('{\"a\": 10, \"b\": 20}'));\r\n\r\nselect coalesce(j.key, k.key), coalesce(j.value, 0) + coalesce(k.value, 0)\r\nfrom (\r\n select json_each.key, json_each.value from reg, json_each(reg.data)\r\n where reg.key = 'k1') as j\r\nfull outer join (\r\n select key, value from json_each('{\"a\": 1, \"c\": 3, \"e\": 5}')) as k\r\non (j.key = k.key);\r\n```\r\n\r\nOutput:\r\n\r\n```\r\na 2\r\nb 2\r\nc 6\r\ne 5\r\n```",
"Wow, thanks for taking the time to think about this more. 🎉 I'm new to Peewee, so _very_ much appreciate your time and insight!\r\n\r\nI definitely would not have thought of using `coaelsce()` for this. Your example query returns the summed result — is there any way to _update_ the `k1` row with the newly-summed value? (My thinking being that single-operation database events are better than multiple sequential operations that could potentially lead to race conditions.)\r\n\r\nThanks again! 👍 ",
">is there any way to update the k1 row with the newly-summed value?\r\n\r\nProbably but that is left as an exercise to the reader.",
"Fair enough, just didn't want to spin my wheels unnecessarily. Thanks again.",
"You know, I'm not sure if you're using sqlite, but if so you might try using a user-defined function:\r\n\r\n```python\r\nimport json\r\nfrom peewee import *\r\nfrom playhouse.sqlite_ext import *\r\n\r\ndb = SqliteExtDatabase(':memory:')\r\nclass Reg(db.Model):\r\n key = TextField(unique=True)\r\n data = JSONField()\r\ndb.create_tables([Reg])\r\n\r\nReg.create(key='k1', data={'a': 1, 'b': 2, 'c': 3})\r\n\r\n@db.func()\r\ndef merge_sum(j1, j2):\r\n d1 = json.loads(j1) if j1 else {}\r\n d2 = json.loads(j2) if j2 else {}\r\n for k, v in d2.items():\r\n d1.setdefault(k, 0)\r\n d1[k] += v\r\n return json.dumps(d1)\r\n\r\nq = (Reg\r\n .insert(key='k1', data={'a': 1, 'c': 3, 'e': 5})\r\n .on_conflict(\r\n conflict_target=[Reg.key],\r\n update={Reg.data: fn.merge_sum(Reg.data, EXCLUDED.data)})\r\n .execute())\r\n\r\nprint(Reg.get().data)\r\n```",
"I am indeed using SQLite!\r\n\r\nThanks for the suggestion... I had _not_ thought of using a user-defined function — but that is pretty much the functionality _(no pun intended)_ I was trying to achieve by overloading the `+` operator.\r\n\r\nReally appreciate you taking the time to follow-up on this (closed) issue with this solution. You rock! 🎉"
] | 2023-02-07T19:43:24 | 2023-02-13T19:31:20 | 2023-02-07T21:54:22 | NONE | null | I've tried to find an instance of a custom field that needed to override the behavior of something like the `+` operator but haven't found one.
As an example scenario, let's say I had a custom field named `CounterDictField` (that subclassed `JSONField` for storage).
I want to override the `__add__` method in the `CounterDictField` class with code that behaves like this:
```python
# override '+' operator to numerically add together dictionary values with the same key
def __add__(lhs, rhs):
return {key: lhs.get(key, 0) + rhs.get(key, 0) for key in set(lhs).union(rhs)}
```
so `+` _numerically sums_ the entries of the two dictionaries:
```python
stats = {"a": 1, "b": 2, "c": 3}
new_stats = {"b": -1, "d": 1}
stats = __add__(stats, new_stats)
# stats={'c': 3, 'd': 1, 'a': 1, 'b': 1}
# 'stats' now contains the result of numerically summing the values with matching keys in 'new_stats'
```
This is so that I can make an "upsert" call (where the `stats` column is the above `CounterDictField` field type):
```python
MyTable.insert(user_id=user_id, username=username, stats=stats).
on_conflict(
conflict_target=[MyTable.user_id],
preserve=[MyTable.username],
update={MyTable.stats: MyTable.stats + stats}
).execute()
```
and have the `stats` field _add to_ existing stats in the dict for records that already exist.
Is something like this possible?
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2674/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2674/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2673 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2673/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2673/comments | https://api.github.com/repos/coleifer/peewee/issues/2673/events | https://github.com/coleifer/peewee/issues/2673 | 1,573,925,868 | I_kwDOAA7yGM5d0DPs | 2,673 | MySQL introspector returns columns in non-deterministic order | {
"login": "linhr",
"id": 5601366,
"node_id": "MDQ6VXNlcjU2MDEzNjY=",
"avatar_url": "https://avatars.githubusercontent.com/u/5601366?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/linhr",
"html_url": "https://github.com/linhr",
"followers_url": "https://api.github.com/users/linhr/followers",
"following_url": "https://api.github.com/users/linhr/following{/other_user}",
"gists_url": "https://api.github.com/users/linhr/gists{/gist_id}",
"starred_url": "https://api.github.com/users/linhr/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/linhr/subscriptions",
"organizations_url": "https://api.github.com/users/linhr/orgs",
"repos_url": "https://api.github.com/users/linhr/repos",
"events_url": "https://api.github.com/users/linhr/events{/privacy}",
"received_events_url": "https://api.github.com/users/linhr/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2023-02-07T08:52:16 | 2023-02-07T13:44:13 | 2023-02-07T13:44:13 | NONE | null | When I use the introspector to generate model classes for MySQL tables, the order of columns seems non-deterministic. It turns out that `MySQLDatabase.get_columns()` does not fetch columns ordered by their ordinal position. (Sometimes the columns are simply returned alphabetically, from what I observed.) Could we add `ORDER BY ordinal_position` when selecting from the `information_schema.columns` table in MySQL?
Here is the code for MySQL, and there is no `ORDER BY` clause:
https://github.com/coleifer/peewee/blob/e4f5df28e1b3716de1c006652371744da3743018/peewee.py#L4193-L4197
We can see that for PostgreSQL, columns are returned in a deterministic order:
https://github.com/coleifer/peewee/blob/e4f5df28e1b3716de1c006652371744da3743018/peewee.py#L3983-L3988 | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2673/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2673/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2672 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2672/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2672/comments | https://api.github.com/repos/coleifer/peewee/issues/2672/events | https://github.com/coleifer/peewee/issues/2672 | 1,561,906,409 | I_kwDOAA7yGM5dGMzp | 2,672 | migrator may conflict with AutoIncrementField in sqlite | {
"login": "js515990",
"id": 108316845,
"node_id": "U_kgDOBnTIrQ",
"avatar_url": "https://avatars.githubusercontent.com/u/108316845?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/js515990",
"html_url": "https://github.com/js515990",
"followers_url": "https://api.github.com/users/js515990/followers",
"following_url": "https://api.github.com/users/js515990/following{/other_user}",
"gists_url": "https://api.github.com/users/js515990/gists{/gist_id}",
"starred_url": "https://api.github.com/users/js515990/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/js515990/subscriptions",
"organizations_url": "https://api.github.com/users/js515990/orgs",
"repos_url": "https://api.github.com/users/js515990/repos",
"events_url": "https://api.github.com/users/js515990/events{/privacy}",
"received_events_url": "https://api.github.com/users/js515990/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"The problem is that Sqlite does not support a way to modify constraints. So in order to do this, we have to create a new table without the changed constraint, copy data into it, drop the old table, then rename the new table -> old table. In this process, your autoincrement sequence gets lost."
] | 2023-01-30T07:38:45 | 2023-01-30T13:48:35 | 2023-01-30T13:48:35 | NONE | null | I have created a sqlite table 'user' using peewee:
The table generally looks like this:
> id name
> 1 name1
> 2 name2
> 3 name3
> 4 name4 (deleted)
For column id, i'm using `AutoIncrementField` from `playhouse.sqlite_ext` to prevent the deleted id from being reused
Since the name4 line has been deleted, the id of next created user should be 5
Then i used a migrator to remove the not-null constraint on field name
`migrator = SqliteMigrator(database)`
`migrator.drop_not_null('user', 'name')`
But after this i created a user and the id field was 4, the deleted id was still reused
Without `migrator.drop_not_null('user', 'name')`, the id column works as expected
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2672/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2672/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2671 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2671/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2671/comments | https://api.github.com/repos/coleifer/peewee/issues/2671/events | https://github.com/coleifer/peewee/issues/2671 | 1,557,037,210 | I_kwDOAA7yGM5czoCa | 2,671 | Value not saved when an alias (column_name) used | {
"login": "ehcpdeveloper",
"id": 1267949,
"node_id": "MDQ6VXNlcjEyNjc5NDk=",
"avatar_url": "https://avatars.githubusercontent.com/u/1267949?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/ehcpdeveloper",
"html_url": "https://github.com/ehcpdeveloper",
"followers_url": "https://api.github.com/users/ehcpdeveloper/followers",
"following_url": "https://api.github.com/users/ehcpdeveloper/following{/other_user}",
"gists_url": "https://api.github.com/users/ehcpdeveloper/gists{/gist_id}",
"starred_url": "https://api.github.com/users/ehcpdeveloper/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/ehcpdeveloper/subscriptions",
"organizations_url": "https://api.github.com/users/ehcpdeveloper/orgs",
"repos_url": "https://api.github.com/users/ehcpdeveloper/repos",
"events_url": "https://api.github.com/users/ehcpdeveloper/events{/privacy}",
"received_events_url": "https://api.github.com/users/ehcpdeveloper/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Adding a second field like that is most definitely \"undefined behavior\" and not advisable. If you want something like this (for some reason), it should be done in Python as perhaps a property. Your example doesn't make clear what the intended goal you were going for, but let's say you wanted something like a normalized accessor to some email field:\r\n\r\n```python\r\nclass User(Model):\r\n email = TextField()\r\n\r\n @property\r\n def normalized_email(self):\r\n return self.email.lower()\r\n```\r\n\r\nAlso check out hybrid properties, which provide a similar abstraction that can work at the SQL level as well. Docs: http://docs.peewee-orm.com/en/latest/peewee/playhouse.html#hybrid\r\n\r\nAbove example:\r\n\r\n```python\r\nclass User(Model):\r\n email = TextField()\r\n\r\n @hybrid_property\r\n def normalized_email(self):\r\n return self.email.lower()\r\n\r\n @normalized_email.expression\r\n def normalized_email(cls):\r\n return fn.LOWER(cls.email)\r\n\r\n# Allows things like:\r\nquery = User.select().where(User.normalized_email == 'foo@example.com')\r\n# Corresponding to, e.g.:\r\n# select * from user where lower(email) = 'foo@example.com'\r\n```",
"Intended goal was to use two different field names for same database field.\r\nIf this has some kind of \"undefined behaviour\", then, this should be either forbidden (like with error), or maybe at least warned somehow. \r\nIt does select() etc, but saving does not work and the cause is hard to determine/notice.\r\n\r\n\"undefined behaviour\"s should be avoided as much as possible. \r\nAnyway, thanks for this nice ORM library/utility.",
">Intended goal was to use two different field names for same database field.\r\n\r\nTo what end? I guess what I'm saying is it sounds like you have a kludge and are unable or unwilling to let go of it.",
"I'm just trying to provide you feedback, so that you can improve your product/software. Nothing else.\r\nIf I have done wrong by providing you some feedback and reporting an \"unexpected behaviour\", then, sorry !!"
] | 2023-01-25T17:37:28 | 2023-01-26T07:25:02 | 2023-01-25T17:54:50 | NONE | null | ```
>>> class Test(BaseModel):
... test1 = DecimalField(constraints=[SQL("DEFAULT 0.00")], null=True)
... class Meta:
... table_name = 'test'
...
>>>
>>>
>>> Test.create_table()
>>> Test.insert(test1=12).execute()
1
>>> a=Test[1]
>>> a.test1=20;
>>> a.save()
1
>>> a=Test[1]
>>> a.test1
Decimal('20.00000')
```
Up to now, normal, correct.
Lets define an alias (2nd field) for test1 field:
```
class Test(BaseModel):
test1 = DecimalField(constraints=[SQL("DEFAULT 0.00")], null=True)
test2 = DecimalField(constraints=[SQL("DEFAULT 0.00")], null=True, column_name='test1')
class Meta:
table_name = 'test'
>>> a=Test[1]
>>> a.test1=30
>>> a.save()
0
>>>
```
So, that entity unchanged.
I am not sure if this is an intended behaviour, but, it is obviously misleading.
I encountered this during dealing with a bug and this was the issue. it was not saving the value.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2671/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2671/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2670 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2670/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2670/comments | https://api.github.com/repos/coleifer/peewee/issues/2670/events | https://github.com/coleifer/peewee/issues/2670 | 1,552,809,681 | I_kwDOAA7yGM5cjf7R | 2,670 | [Feature Request] Event hooks for peewee | {
"login": "Zheaoli",
"id": 7054676,
"node_id": "MDQ6VXNlcjcwNTQ2NzY=",
"avatar_url": "https://avatars.githubusercontent.com/u/7054676?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/Zheaoli",
"html_url": "https://github.com/Zheaoli",
"followers_url": "https://api.github.com/users/Zheaoli/followers",
"following_url": "https://api.github.com/users/Zheaoli/following{/other_user}",
"gists_url": "https://api.github.com/users/Zheaoli/gists{/gist_id}",
"starred_url": "https://api.github.com/users/Zheaoli/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/Zheaoli/subscriptions",
"organizations_url": "https://api.github.com/users/Zheaoli/orgs",
"repos_url": "https://api.github.com/users/Zheaoli/repos",
"events_url": "https://api.github.com/users/Zheaoli/events{/privacy}",
"received_events_url": "https://api.github.com/users/Zheaoli/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"peewee already have signal support see more in https://docs.peewee-orm.com/en/latest/peewee/playhouse.html#signals\n\nDoes this feature meets your needs?\n ",
"@Zheaoli - I'm going to pass, as the generally-supported approach for Peewee users has been to override the `Database.execute_sql()` method in these types of cases (where you want before or after a query execution), for example. You can extend this to other core methods like `commit()`, etc."
] | 2023-01-23T10:00:47 | 2023-01-23T14:16:43 | 2023-01-23T14:16:42 | NONE | null | For now, I'm looking for event hooks in peewee, but I think we don't support event hooks for peewee yet(I have already read the docs, please feel free to correct me if I'm wrong)
I think it's an excellent choice to support event hooks like Django ORM or sqlalchemy like below.
```python
from peewee import event
event.listen(client, "before_cursor_execute", callback_func)
```
The code above means that the callback function will be executed before the final SQL start to be executed.
It's a good feature for a lot of people. For example, we can inject the trace ID in SQL by using SQL comment using https://google.github.io/sqlcommenter/python/sqlalchemy/
FYI https://docs.sqlalchemy.org/en/14/core/events.html | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2670/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2670/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2669 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2669/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2669/comments | https://api.github.com/repos/coleifer/peewee/issues/2669/events | https://github.com/coleifer/peewee/issues/2669 | 1,551,887,516 | I_kwDOAA7yGM5cf-yc | 2,669 | How to use instance-relative SQLite databases with FlaskDB | {
"login": "eddyg",
"id": 3235109,
"node_id": "MDQ6VXNlcjMyMzUxMDk=",
"avatar_url": "https://avatars.githubusercontent.com/u/3235109?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/eddyg",
"html_url": "https://github.com/eddyg",
"followers_url": "https://api.github.com/users/eddyg/followers",
"following_url": "https://api.github.com/users/eddyg/following{/other_user}",
"gists_url": "https://api.github.com/users/eddyg/gists{/gist_id}",
"starred_url": "https://api.github.com/users/eddyg/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/eddyg/subscriptions",
"organizations_url": "https://api.github.com/users/eddyg/orgs",
"repos_url": "https://api.github.com/users/eddyg/repos",
"events_url": "https://api.github.com/users/eddyg/events{/privacy}",
"received_events_url": "https://api.github.com/users/eddyg/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"What is the value of app.instance_path at the time you're trying to use it? The error seems to me to indicate it's a badly formed filename.",
"If I add this line to code above (before the call to `db.create_tables`):\r\n\r\n```python\r\n print(f\"{os.getcwd()=}\\n{app.instance_path=}\\n{app.config['DATABASE']=}\")\r\n```\r\n\r\nI get:\r\n\r\n```text\r\nos.getcwd()='/Users/eddyg/git/test'\r\napp.instance_path='/Users/eddyg/git/test/instance'\r\napp.config['DATABASE']='sqlite:///Users/eddyg/git/test/instance/db.sqlite'\r\n```\r\n",
"Does that full directory path exist? You might add a `os.makedirs(app.instance_path)`",
"That call (to ensure the instance_path directory exists) is in the sample code I posted; it definitely exists (or gets created).",
"Ugh sorry bro I should have double checked the docs. I believe you need three slashes before the path rather than two, http://docs.peewee-orm.com/en/latest/peewee/playhouse.html#db-url\r\n\r\n```\r\n\"sqlite:///\" + ...\r\n```",
"Ugh, that was indeed the problem.\r\n\r\nAs you can see from the output above, I already had 3 slashes (the [normal amount](https://en.wikipedia.org/wiki/File_URI_scheme#Unix) for path-based URIs), with **4** slashes (`sqlite:///` + `/path/to/db`) it works to get the database file into the `instance_path` directory.\r\n\r\nAny idea why it requires the extra slash?",
"Just how the stdlib urlparse works.",
"Hmm... I still don't get it.\r\n\r\nWith 3 slashes:\r\n\r\n```python\r\nfrom urllib.parse import urlparse\r\nresults = urlparse(\"sqlite:///path/to/file.sqlite\")\r\nprint(f\"{results.scheme=}\\n{results.hostname=}\\n{results.path=}\")\r\n```\r\n\r\n```\r\nresults.scheme='sqlite'\r\nresults.hostname=None\r\nresults.path='/path/to/file.sqlite'\r\n```\r\n\r\nWith 4 slashes:\r\n```python\r\nresults = urlparse(\"sqlite:////path/to/file.sqlite\")\r\nprint(f\"{results.scheme=}\\n{results.hostname=}\\n{results.path=}\")\r\n```\r\n\r\n```\r\nresults.scheme='sqlite'\r\nresults.hostname=None\r\nresults.path='//path/to/file.sqlite'\r\n```\r\n\r\nThose are the results I expected, and why it seems 3 slashes should be enough. 🤷 \r\n\r\nThanks for your time and the solution! 🎉 "
] | 2023-01-21T19:10:44 | 2023-01-21T20:20:40 | 2023-01-21T19:44:03 | NONE | null | I have this code in `test/__init__.py`:
```python
import os
import contextlib
from flask import Flask
from peewee import CharField, PrimaryKeyField
from playhouse.flask_utils import FlaskDB
db_wrapper = FlaskDB()
class User(db_wrapper.Model):
user_id = PrimaryKeyField()
user_name = CharField(max_length=128, unique=True)
def create_app() -> Flask:
app = Flask(__name__, instance_relative_config=True)
app.config.from_mapping(
DATABASE="sqlite://" + os.path.join(app.instance_path, "db.sqlite"),
# DATABASE="sqlite:///db.sqlite",
)
# create instance path if it doesn't already exist
with contextlib.suppress(OSError):
os.makedirs(app.instance_path)
db_wrapper.init_app(app)
if db := db_wrapper.database:
db.create_tables([User], safe=True)
return app
```
and when I run:
```shell
flask --app test --debug run
```
It errors with:
```text
peewee.OperationalError: unable to open database file
```
*__but__* if I uncomment the `DATABASE` line shown above so it _doesn't_ use `app.instance_path`, it works fine (but then the database isn't in the `instance` directory).
The `app.instance_path` does exist (or gets created by the code if it's missing).
FWIW, if I replace the call to `db.create_tables` with `db.connect()` _(for example)_ I get the same error.
Is there something I'm missing with getting the SQLite database into the `instance_path` directory?
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2669/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2669/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2668 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2668/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2668/comments | https://api.github.com/repos/coleifer/peewee/issues/2668/events | https://github.com/coleifer/peewee/issues/2668 | 1,533,214,216 | I_kwDOAA7yGM5bYv4I | 2,668 | The record is not saving in only one Table | {
"login": "d1n0z",
"id": 79446044,
"node_id": "MDQ6VXNlcjc5NDQ2MDQ0",
"avatar_url": "https://avatars.githubusercontent.com/u/79446044?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/d1n0z",
"html_url": "https://github.com/d1n0z",
"followers_url": "https://api.github.com/users/d1n0z/followers",
"following_url": "https://api.github.com/users/d1n0z/following{/other_user}",
"gists_url": "https://api.github.com/users/d1n0z/gists{/gist_id}",
"starred_url": "https://api.github.com/users/d1n0z/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/d1n0z/subscriptions",
"organizations_url": "https://api.github.com/users/d1n0z/orgs",
"repos_url": "https://api.github.com/users/d1n0z/repos",
"events_url": "https://api.github.com/users/d1n0z/events{/privacy}",
"received_events_url": "https://api.github.com/users/d1n0z/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
">```c.users = c.users.replace(f\"{self.event.text.lower()[15:]}/\", \"\")\r\nc.save()```\r\n\r\nThis is so far off-base I don't really know where to start. But try something like this:\r\n\r\n```\r\nUser.update(user_clan='').where(user_clan=x).execute()\r\n```\r\n\r\nWhere x is the old clan name...if I understand this right.",
"I suggest reading a beginner level sql tutorial, then go through some of the peewee docs like the quick start.",
"> > \r\n> \r\n> c.save()```\r\n> \r\n> This is so far off-base I don't really know where to start. But try something like this:\r\n> \r\n> ```\r\n> User.update(user_clan='').where(user_clan=x).execute()\r\n> ```\r\n> \r\n> Where x is the old clan name...if I understand this right.\r\n\r\nYes, i already did like this, but record is not stored in database even though print() says otherwise",
"I think you have some sort of basic confusion about how peewee works so I suggest spending time really going through the docs and examples. For questions like this stack overflow is the place to ask.",
"> I think you have some sort of basic confusion about how peewee works so I suggest spending time really going through the docs and examples. For questions like this stack overflow is the place to ask.\r\n\r\n\r\nI already read the docs, did everything right (as in the examples, but for myself), but as I understand it doesn’t work like that, because, as I said above, it simply not saving to the database. Am I right?",
"Now I don't understand anything. `User.insert(...).where(...).execute()` immediately wrote to the database, and `User.update(...).where(...).execute()` refuses to work no matter how I wrote this. So can you give me at least hint?",
"@coleifer can You tell something pls?",
"Insert...where is not even valid sql (although peewee will prevent including the where clause). Again I suggest some sql tutorials.",
".where(...) was a typo, sorry, in code it was just User.insert(...).execute(). I think I know how sql works, I was learning sql in the past btw"
] | 2023-01-14T10:55:57 | 2023-01-14T15:02:01 | 2023-01-14T12:51:00 | NONE | null | Only the "c" part is saved, although I do exactly the same thing, the "u" part changes, but it is not saved in the database. When I put .save (force_insert) it gives an error:
`UNIQUE constraint failed: Users.id`
Code(3 files):
```
# main.py
# self.event.text.lower()[15:] - user id
# self.db - current user database
c = utils.getClanById(self.db.userId)
c.users = c.users.replace(f"{self.event.text.lower()[15:]}/", "")
c.save()
u = utils.getUserById(int(self.event.text.lower()[15:]))
u.user_clan = ""
u.save()
# utils.py
import time
from models import *
def getUserById(user_id):
try:
return User().get(User.userId == user_id)
except:
User(
userId=user_id,
name="",
lastTimeUsedBonus=time.time() - 86400,
money=0,
GB=0,
crowns=0,
place=1000,
user_clan="",
clan_invites=""
).save()
return User().get(vk_id=user_id)
def getClanById(user_id, buy=False):
user_id = int(user_id)
try:
return Clan().get(Clan.owner_id == user_id)
except:
if buy:
Clan(
owner_id=user_id,
name="",
idd=0,
users="",
base=1,
rating=0,
coffers=0,
wins=0,
loses=0
).save()
return Clan().get(Clan.owner_id == user_id)
# models.py
from peewee import *
dbu = SqliteDatabase('users and clans.db')
class User(Model):
class Meta:
database = dbu
db_table = 'Users'
userId = IntegerField()
name = TextField()
lastTimeUsedBonus = TimeField()
money = IntegerField()
GB = IntegerField()
crowns = IntegerField()
user_clan = TextField()
clan_invites = TextField()
class Clan(Model):
class Meta:
database = dbu
db_table = 'Clans'
owner_id = IntegerField()
name = TextField()
idd = IntegerField()
users = TextField()
base = IntegerField()
rating = IntegerField()
coffers = IntegerField()
wins = IntegerField()
loses = IntegerField()
if __name__ == '__main__':
dbu.create_tables([Clan, User])
``` | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2668/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2668/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2667 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2667/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2667/comments | https://api.github.com/repos/coleifer/peewee/issues/2667/events | https://github.com/coleifer/peewee/issues/2667 | 1,533,156,449 | I_kwDOAA7yGM5bYhxh | 2,667 | OSS License compatibility question | {
"login": "Ashley123456789",
"id": 56197499,
"node_id": "MDQ6VXNlcjU2MTk3NDk5",
"avatar_url": "https://avatars.githubusercontent.com/u/56197499?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/Ashley123456789",
"html_url": "https://github.com/Ashley123456789",
"followers_url": "https://api.github.com/users/Ashley123456789/followers",
"following_url": "https://api.github.com/users/Ashley123456789/following{/other_user}",
"gists_url": "https://api.github.com/users/Ashley123456789/gists{/gist_id}",
"starred_url": "https://api.github.com/users/Ashley123456789/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/Ashley123456789/subscriptions",
"organizations_url": "https://api.github.com/users/Ashley123456789/orgs",
"repos_url": "https://api.github.com/users/Ashley123456789/repos",
"events_url": "https://api.github.com/users/Ashley123456789/events{/privacy}",
"received_events_url": "https://api.github.com/users/Ashley123456789/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2023-01-14T06:21:09 | 2023-01-14T12:45:25 | 2023-01-14T12:45:25 | NONE | null | There’s some possible confusion on the license of your repository when you combine other open-source code.
The module `tests/libs/mock.py` claims its license as **the BSD License**. However, the license of your whole project is shown as **the MIT license** in LICENSE, i.e., **less strict** than the BSD License on license terms, which has impacted the whole license compatibility in your repository and may bring legal and financial risks.
You can select another proper license for your repository, or write a custom license with license exceptions if some license terms couldn’t be summed up consistently
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2667/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2667/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2666 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2666/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2666/comments | https://api.github.com/repos/coleifer/peewee/issues/2666/events | https://github.com/coleifer/peewee/issues/2666 | 1,530,933,173 | I_kwDOAA7yGM5bQC-1 | 2,666 | Closing SQLite3 db blocks | {
"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 | [
"Your code works just fine for me, though I would note that you do **not** need to call `Database.db.commit()`. Peewee operates in autocommit mode unless you are explicitly using either an `atomic()` or `transaction()` block. This *may* be related to your issue or not, I'm not sure.\r\n\r\nExample output when I run your code:\r\n\r\n```\r\n0\r\nClosing\r\nDone\r\n```\r\n\r\n(Note that it prints 0 because you are storing the result of the `.save()` call into `token` -- probably you meant to do something like this):\r\n\r\n```python\r\ntoken = Token(token_type=2, token_value=\"test\", expires_at=\"2021-01-01 00:00:00\")\r\ntoken.save()\r\n# Or:\r\n# token = Token.create(token_type=2, token_value='test', expires_at='2021-01-01 00:00:00')\r\nprint(token)\r\n```\r\n\r\nNonetheless, I don't know how this could be related to the lock. You might try to interrupt the program when its blocked and generate a traceback, but I'm not sure whether that will yield any clues.",
"I tried without commit as well. It always hangs, but just within the kodi context. I am not sure whether this is an issue related to kodi or peewee.\r\n\r\nI cannot really get a traceback since the entire interpreter hangs at that point.",
"Ah, so it's running within Kodi? I'm not sure how the lock would affect that, either, to be honest. The lock is only held briefly when opening and closing the db to prevent race conditions. My guess is that Sqlite itself is preventing you from closing the connection, but I'm not sure.\r\n\r\nI'd suggest trying something like the following:\r\n\r\n```python\r\nfrom peewee import Model, SqliteDatabase, CharField, DateTimeField, IntegerField, SQL\r\nfrom pathlib import Path\r\n\r\ndb_path = Path.cwd()\r\ndb = SqliteDatabase(db_path.joinpath(\"database.db\"))\r\n\r\nclass BaseModel(Model):\r\n class Meta:\r\n database = db\r\n\r\nclass Token(BaseModel):\r\n # TokenType is an enum\r\n token_type = IntegerField(\r\n primary_key=True, constraints=[SQL(\"ON CONFLICT REPLACE\")]\r\n )\r\n token_value = CharField(null=False)\r\n expires_at = DateTimeField(null=False)\r\n\r\n# When you need to use the database, use context managers.\r\nwith db:\r\n db.create_tables([Token])\r\n\r\n# Create a record.\r\nwith db:\r\n token = Token.create(token_type=2, token_value=\"test\", expires_at=\"2021-01-01 00:00:00\")\r\n print(token)\r\n```",
"Unfortunately it hangs this way as well. And yes, Kodi exposes a python API so one can write add-ons for the media center. It can do anything what a normal python installation can, but it runs embedded.\r\n\r\nAnd I was suspecting logs like I wrote originally, but ditched that idea. Since I tested with the following snippet:\r\n\r\n```py\r\nwith threading.RLock():\r\n f = open(\"test.txt\")\r\n f.write(\"test\")\r\n f.close()\r\nprint(\"Done\")\r\n```\r\n\r\nAnd it worked. I also tested if I can open, write to and close an sqlite3 database using the sqlite3 lib, worked fine too. It's only peewee that causes a block.",
"If you instantiate your database with `thread_safe=False` does that fix it?\r\n\r\n```\r\ndb = SqliteDatabase(db_path.joinpath(\"database.db\"),\r\n thread_safe=False)\r\n```",
"Also, just for reference, Peewee should work fine with Sqlite and threads, e.g. this runs 10 threads, inserting 10 records each. The output is 100 and the program ends cleanly:\r\n\r\n```python\r\nimport threading\r\nfrom peewee import *\r\n\r\ndb = SqliteDatabase('/tmp/foo.db')\r\n\r\nclass Reg(db.Model):\r\n key = TextField(primary_key=True, constraints=[SQL('on conflict replace')])\r\n\r\ndb.create_tables([Reg])\r\n\r\ndef work_in_thread(i):\r\n for j in range(i * 10, (i * 10) + 10):\r\n Reg.create(key='k%02d' % j)\r\n\r\nthreads = [threading.Thread(target=work_in_thread, args=(i,))\r\n for i in range(10)]\r\nfor t in threads: t.start()\r\nfor t in threads: t.join()\r\n\r\nprint(Reg.select().count())\r\ndb.close()\r\n```",
"> If you instantiate your database with `thread_safe=False` does that fix it?\r\n\r\nI tried that too, unfortunately without any luck. Same blocking is there on close. But literally only on closing. And it seems to keep the file open forever too.",
">Same blocking is there on close. But literally only on closing. And it seems to keep the file open forever too.\r\n\r\nSetting `thread_safe=False` removes all locking (the `threading.RLock` is replaced by a dummy implementation that no-ops). So I think that hypothesis can be safely thrown out.\r\n\r\nMy best guess is that you have unfinalized statements and are using an oldish version of the `libsqlite3` driver that does not use `sqlite3_close_v2`. See: https://www.sqlite.org/c3ref/close.html and https://github.com/python/cpython/blob/3.8/Modules/_sqlite/util.h -- however, the standard lib sqlite3 *should* be finalizing all statements when you close the connection, so I may be wrong about what's happening.\r\n\r\nIs the database hosted on a networked filesystem, possibly?\r\n\r\nOtherwise I'm about out of ideas.",
"It's on a local NVMe storage, local fs too. sqlite3 can close databases even after writing to them just fine. Is there any way to enable verbose logging?\r\n\r\nOr any way to force the use of sqlite3? If I understood you correctly libsqlite3 and sqlite3 are two different things.",
"Peewee uses `sqlite3` (the python wrapper/driver), which is specific to your version of Python installed. `libsqlite3` is the sqlite3 library installed on your system, that the python driver is wrapping.\r\n\r\nYou can insert a breakpoint into your code that calls `.close()` and step into it to see where it's getting blocked. You can add print statements / logging to peewee, etc."
] | 2023-01-12T15:36:23 | 2023-01-13T16:45:37 | 2023-01-12T16:07:17 | NONE | null | hi,
I am writing a Kodi addon where I wanted to use peewee as my CRM. My Kodi build uses python3.8 internally. I packaged the latest peewee version available and it works fine. I can create databases write to them read from them etc.
But if I try to call close() on the database, it blocks forever and the code never exits.
The same code runs fine with my PC's python interpreter.
The code: https://pastebin.com/zCNreHF0
I tried to debug this. First I tried to create a simple file and close it. That worked just fine. Then I used sqlite3 to create a database, insert a record and close the database. Worked also fine. Then I was suspecting threading.RLock() as the causer, but that also works just fine.
Any idea what could be wrong? Can I force the lib to use sqlite3? | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2666/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2666/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2665 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2665/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2665/comments | https://api.github.com/repos/coleifer/peewee/issues/2665/events | https://github.com/coleifer/peewee/issues/2665 | 1,518,819,649 | I_kwDOAA7yGM5ah1lB | 2,665 | Unable to import module 'app': No module named 'playhouse' | {
"login": "bitfede",
"id": 15684622,
"node_id": "MDQ6VXNlcjE1Njg0NjIy",
"avatar_url": "https://avatars.githubusercontent.com/u/15684622?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/bitfede",
"html_url": "https://github.com/bitfede",
"followers_url": "https://api.github.com/users/bitfede/followers",
"following_url": "https://api.github.com/users/bitfede/following{/other_user}",
"gists_url": "https://api.github.com/users/bitfede/gists{/gist_id}",
"starred_url": "https://api.github.com/users/bitfede/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/bitfede/subscriptions",
"organizations_url": "https://api.github.com/users/bitfede/orgs",
"repos_url": "https://api.github.com/users/bitfede/repos",
"events_url": "https://api.github.com/users/bitfede/events{/privacy}",
"received_events_url": "https://api.github.com/users/bitfede/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Peewee, the package, includes `playhouse` so I'd assume you would just need to ensure that `peewee` is installed in your environment and then `playhouse` should work. I am not familiar with chalice, and questions such as this are better suited to StackOverflow.",
"@bitfede Note that you can [deploy AWS Chalice into AWS Lambda using an S3 bucket as an intermediary for your requirements.](https://docs.aws.amazon.com/lambda/latest/dg/gettingstarted-package.html#gettingstarted-package-zip) Your requirements, presumably including peewee would be zipped and uploaded to S3 then loaded into Lambda on creation. Another [example with Terraform](https://developer.hashicorp.com/terraform/tutorials/aws/lambda-api-gateway).",
"@coleifer Thank you for getting back to me very fast, I posted the question on StackOverflow.\r\n\r\n@Insighttful really appreciate your response. Can you elaborate a bit more on why uploading the zip to S3 then load it into Lambda might make peewee's playhouse work compared to running `chalice deploy`? Thank you so much.",
"@bitfede have you confirmed that **_peewee was actually installed_** as a requirement in the Lambda environment with the standard deploy? Chalice deployments with requirements over 10mb can use S3 as an intermediary to load requirements into Lambda. "
] | 2023-01-04T11:36:10 | 2023-01-06T14:44:52 | 2023-01-04T13:46:18 | NONE | null | Hello,
I am working on an [AWS Chalice](https://aws.github.io/chalice/quickstart.html#deploying) project, and I chose peewee as the ORM for the postgresql DB we have.
When I run things locally with `chalice local` I can run my api with no problem, I'm able to CRUD normally.
When I deploy my microservice using `chalice deploy` and I go test it out I encounter an error 500. When looking into the logs I see this message multiple times:
```
Traceback (most recent call last):
2023-01-03 22:39:57.665000 d87bac [ERROR] Runtime.ImportModuleError: Unable to import module 'app': No module named 'playhouse'
```
I cannot do `poetry add playhouse`, because I get the following error: `Could not find a matching version of package playhouse`. What can you suggest me to do to fix this?
Thank you so much | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2665/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2665/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2664 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2664/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2664/comments | https://api.github.com/repos/coleifer/peewee/issues/2664/events | https://github.com/coleifer/peewee/issues/2664 | 1,513,647,552 | I_kwDOAA7yGM5aOG3A | 2,664 | Error when aurora cluster instance failover | {
"login": "oxeye-schmil",
"id": 86559997,
"node_id": "MDQ6VXNlcjg2NTU5OTk3",
"avatar_url": "https://avatars.githubusercontent.com/u/86559997?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/oxeye-schmil",
"html_url": "https://github.com/oxeye-schmil",
"followers_url": "https://api.github.com/users/oxeye-schmil/followers",
"following_url": "https://api.github.com/users/oxeye-schmil/following{/other_user}",
"gists_url": "https://api.github.com/users/oxeye-schmil/gists{/gist_id}",
"starred_url": "https://api.github.com/users/oxeye-schmil/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/oxeye-schmil/subscriptions",
"organizations_url": "https://api.github.com/users/oxeye-schmil/orgs",
"repos_url": "https://api.github.com/users/oxeye-schmil/repos",
"events_url": "https://api.github.com/users/oxeye-schmil/events{/privacy}",
"received_events_url": "https://api.github.com/users/oxeye-schmil/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"`is_closed()` refers to internal state of Peewee, not the underlying psycopg2/libpq connection. Psycopg2 does not really expose a good way to check the state, see this comment for some background explanation: https://github.com/coleifer/peewee/issues/2654#issuecomment-1325199936 - also note that handling failover by silently reconnecting may not be a good idea, as any uncommitted changes prior to the reconnect could be lost.\r\n\r\nMy suggestion is to decide where, in your application, it makes the most sense to handle these kinds of events - and code defensively (catching the `InterfaceError` possibly, although I would have expected one slightly different error **before** the `InterfaceError` occurs -- typically an OperationalError)."
] | 2022-12-29T11:31:08 | 2022-12-29T14:18:51 | 2022-12-29T14:18:51 | NONE | null | Hi,
I'm using PostgresqlDatabase to manage my Aurora DB.
I've encountered the following error after the the AZ on which the writer instance went down and caused a failover.
```
Traceback (most recent call last):
File "/Users/schmil/work/oxeye-cloud/data_pipeline/sink_instance_creator/sink_instance_persistant_storage.py", line 72, in _handle
query.execute()
File "/usr/local/lib/python3.9/site-packages/peewee.py", line 1911, in inner
return method(self, database, *args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/peewee.py", line 1982, in execute
return self._execute(database)
File "/usr/local/lib/python3.9/site-packages/peewee.py", line 2761, in _execute
return super(Insert, self)._execute(database)
File "/usr/local/lib/python3.9/site-packages/peewee.py", line 2477, in _execute
cursor = self.execute_returning(database)
File "/usr/local/lib/python3.9/site-packages/peewee.py", line 2484, in execute_returning
cursor = database.execute(self)
File "/usr/local/lib/python3.9/site-packages/peewee.py", line 3173, in execute
return self.execute_sql(sql, params, commit=commit)
File "/usr/local/lib/python3.9/site-packages/peewee.py", line 3167, in execute_sql
self.commit()
File "/usr/local/lib/python3.9/site-packages/peewee.py", line 2933, in __exit__
reraise(new_type, new_type(exc_value, *exc_args), traceback)
File "/usr/local/lib/python3.9/site-packages/peewee.py", line 191, in reraise
raise value.with_traceback(tb)
File "/usr/local/lib/python3.9/site-packages/peewee.py", line 3158, in execute_sql
cursor = self.cursor(commit)
File "/usr/local/lib/python3.9/site-packages/peewee.py", line 3145, in cursor
return self._state.conn.cursor()
peewee.InterfaceError: connection already closed
```
I managed to reproduce it and when checked the connection before executing the query using `is_closed()` it returned false but still got the error
I'm using a single connection without connection pool because I have only a single thread
How can configure peewee to handle failovers? | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2664/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2664/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2663 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2663/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2663/comments | https://api.github.com/repos/coleifer/peewee/issues/2663/events | https://github.com/coleifer/peewee/issues/2663 | 1,511,683,801 | I_kwDOAA7yGM5aGnbZ | 2,663 | Suggestion: .is_ and .is_not query lookups | {
"login": "frosthamster",
"id": 17183342,
"node_id": "MDQ6VXNlcjE3MTgzMzQy",
"avatar_url": "https://avatars.githubusercontent.com/u/17183342?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/frosthamster",
"html_url": "https://github.com/frosthamster",
"followers_url": "https://api.github.com/users/frosthamster/followers",
"following_url": "https://api.github.com/users/frosthamster/following{/other_user}",
"gists_url": "https://api.github.com/users/frosthamster/gists{/gist_id}",
"starred_url": "https://api.github.com/users/frosthamster/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/frosthamster/subscriptions",
"organizations_url": "https://api.github.com/users/frosthamster/orgs",
"repos_url": "https://api.github.com/users/frosthamster/repos",
"events_url": "https://api.github.com/users/frosthamster/events{/privacy}",
"received_events_url": "https://api.github.com/users/frosthamster/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"We use `.is_null()`: http://docs.peewee-orm.com/en/latest/peewee/api.html#ColumnBase",
"But we can use it only for generating `is null` and `it not null`, not for `is not true`"
] | 2022-12-27T10:50:26 | 2022-12-28T07:33:40 | 2022-12-27T13:40:07 | NONE | null | It'd be great to have an option to write `is` and `is not` lookups via functions `Model.field.is_(value)` and not `Model.field >> value` which is unreadable, similar to `Model.field.in_(value)`. It's useful for writing queries against nullable boolean fields, like `Model.is_finished.is_not(True)`
I can submit a pr if you want that change too. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2663/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2663/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2662 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2662/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2662/comments | https://api.github.com/repos/coleifer/peewee/issues/2662/events | https://github.com/coleifer/peewee/issues/2662 | 1,511,046,894 | I_kwDOAA7yGM5aEL7u | 2,662 | Suggestion: SQLiteDatabase option to disable automatic DB creation | {
"login": "MrBillium",
"id": 14281367,
"node_id": "MDQ6VXNlcjE0MjgxMzY3",
"avatar_url": "https://avatars.githubusercontent.com/u/14281367?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/MrBillium",
"html_url": "https://github.com/MrBillium",
"followers_url": "https://api.github.com/users/MrBillium/followers",
"following_url": "https://api.github.com/users/MrBillium/following{/other_user}",
"gists_url": "https://api.github.com/users/MrBillium/gists{/gist_id}",
"starred_url": "https://api.github.com/users/MrBillium/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/MrBillium/subscriptions",
"organizations_url": "https://api.github.com/users/MrBillium/orgs",
"repos_url": "https://api.github.com/users/MrBillium/repos",
"events_url": "https://api.github.com/users/MrBillium/events{/privacy}",
"received_events_url": "https://api.github.com/users/MrBillium/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Going to pass"
] | 2022-12-26T15:45:26 | 2022-12-26T16:05:49 | 2022-12-26T16:05:39 | NONE | null | There does not appear to be a way to disable DB creation if not found.
e.g db = SqliteDatabase('mydb.db', pragmas={'foreign_keys': 1}, **create_db=False**)
Why this could be helpful:
I just went down a rabbit hole moving running code to an Apache server where I forgot to set **home=/var/www/myapp** in my apache .conf file.
The result was everything ran fine without errors but the DB in the same dir as the rest of the code was not found so an empty copy was created by Peewee in /home/<user>
This led to troubleshooting why a fully functional db was not returning any data.
In most cases of deployment or migration the database should not NEED be 'created' and preventing it from happening iwould immediately show up as an error as it should.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2662/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2662/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2661 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2661/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2661/comments | https://api.github.com/repos/coleifer/peewee/issues/2661/events | https://github.com/coleifer/peewee/issues/2661 | 1,502,355,166 | I_kwDOAA7yGM5ZjB7e | 2,661 | bulk_create() doesn't work with server-side default values | {
"login": "gondolio",
"id": 4338344,
"node_id": "MDQ6VXNlcjQzMzgzNDQ=",
"avatar_url": "https://avatars.githubusercontent.com/u/4338344?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/gondolio",
"html_url": "https://github.com/gondolio",
"followers_url": "https://api.github.com/users/gondolio/followers",
"following_url": "https://api.github.com/users/gondolio/following{/other_user}",
"gists_url": "https://api.github.com/users/gondolio/gists{/gist_id}",
"starred_url": "https://api.github.com/users/gondolio/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/gondolio/subscriptions",
"organizations_url": "https://api.github.com/users/gondolio/orgs",
"repos_url": "https://api.github.com/users/gondolio/repos",
"events_url": "https://api.github.com/users/gondolio/events{/privacy}",
"received_events_url": "https://api.github.com/users/gondolio/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Yes, this is because `bulk_create()` is explicit about inserting all fields. If you want finer-grained control, for (e.g.) fields w/server-side defaults, you should just use `insert_many()` and be explicit.",
"Got it - so first convert the objects to dicts (via `object.__data__`) and then feed it into `insert_many()`. Thx!"
] | 2022-12-19T05:58:06 | 2022-12-20T08:39:11 | 2022-12-19T19:31:49 | NONE | null | It appears that bulk_create does not work with server-side default values specified in [constraint](https://docs.peewee-orm.com/en/latest/peewee/models.html?highlight=table%20generation#:~:text=can%20use%20the-,constraints,-parameter%20to%20specify).
For example, with this model:
```
class MyModel(Modell):
datetime = DateTimeField(constraints=[SQL("DEFAULT CURRENT_TIMESTAMP")])
class Meta:
database = my_postgresql_db
```
The following works:
`MyModel().save()`
whereas this fails:
```
MyModel.bulk_create([MyModel()])
# IntegrityError: null value in column "datetime" violates not-null constraint DETAIL: Failing row contains (2, null).
```
Any suggestions on how to bulk create using server-side defaults? | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2661/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2661/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2660 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2660/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2660/comments | https://api.github.com/repos/coleifer/peewee/issues/2660/events | https://github.com/coleifer/peewee/issues/2660 | 1,500,328,870 | I_kwDOAA7yGM5ZbTOm | 2,660 | playhouse/_sqlite_udf.pyx: compilation error | {
"login": "wedobetter",
"id": 31860030,
"node_id": "MDQ6VXNlcjMxODYwMDMw",
"avatar_url": "https://avatars.githubusercontent.com/u/31860030?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/wedobetter",
"html_url": "https://github.com/wedobetter",
"followers_url": "https://api.github.com/users/wedobetter/followers",
"following_url": "https://api.github.com/users/wedobetter/following{/other_user}",
"gists_url": "https://api.github.com/users/wedobetter/gists{/gist_id}",
"starred_url": "https://api.github.com/users/wedobetter/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/wedobetter/subscriptions",
"organizations_url": "https://api.github.com/users/wedobetter/orgs",
"repos_url": "https://api.github.com/users/wedobetter/repos",
"events_url": "https://api.github.com/users/wedobetter/events{/privacy}",
"received_events_url": "https://api.github.com/users/wedobetter/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2022-12-16T14:32:30 | 2022-12-16T18:31:37 | 2022-12-16T18:31:37 | NONE | null | Peewee Version: 3.15.4
Python: 3.11.0
Cython: 3.0.0a11
Platform: MacOS M1 - arm64
How to reproduce: pip install peewee
```
Error compiling Cython file:
------------------------------------------------------------
...
if self.ct == 0:
return None
elif self.ct < 3:
return self.items[0]
else:
return self.selectKth(self.ct / 2)
^
------------------------------------------------------------
playhouse/_sqlite_udf.pyx:137:42: Cannot assign type 'double' to 'int'
``` | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2660/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2660/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2659 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2659/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2659/comments | https://api.github.com/repos/coleifer/peewee/issues/2659/events | https://github.com/coleifer/peewee/issues/2659 | 1,488,771,281 | I_kwDOAA7yGM5YvNjR | 2,659 | Type support | {
"login": "gp-slick-coder",
"id": 1906169,
"node_id": "MDQ6VXNlcjE5MDYxNjk=",
"avatar_url": "https://avatars.githubusercontent.com/u/1906169?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/gp-slick-coder",
"html_url": "https://github.com/gp-slick-coder",
"followers_url": "https://api.github.com/users/gp-slick-coder/followers",
"following_url": "https://api.github.com/users/gp-slick-coder/following{/other_user}",
"gists_url": "https://api.github.com/users/gp-slick-coder/gists{/gist_id}",
"starred_url": "https://api.github.com/users/gp-slick-coder/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/gp-slick-coder/subscriptions",
"organizations_url": "https://api.github.com/users/gp-slick-coder/orgs",
"repos_url": "https://api.github.com/users/gp-slick-coder/repos",
"events_url": "https://api.github.com/users/gp-slick-coder/events{/privacy}",
"received_events_url": "https://api.github.com/users/gp-slick-coder/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Hey, why was this closed? Is there already a solution for this?",
"I already did some research ;-) unfortunately, the creator of this nice ORM doesn't like type hints. Coming from Typescript, python does miss a nice modern ORM solution :-( ",
"You can create your own hints (I think they're called \"stubs\"?), but this particular question has been asked and answered several times since type hints were introduced."
] | 2022-12-10T18:12:21 | 2022-12-12T11:32:34 | 2022-12-10T18:26:52 | NONE | null | Type support in VSCode would be nice.
![image](https://user-images.githubusercontent.com/1906169/206869371-b9555cef-e9d1-4d66-a27f-5fc61968aae8.png)
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2659/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2659/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2658 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2658/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2658/comments | https://api.github.com/repos/coleifer/peewee/issues/2658/events | https://github.com/coleifer/peewee/issues/2658 | 1,473,350,239 | I_kwDOAA7yGM5X0Ypf | 2,658 | Gotcha for folks using update | {
"login": "brewerja",
"id": 410845,
"node_id": "MDQ6VXNlcjQxMDg0NQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/410845?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/brewerja",
"html_url": "https://github.com/brewerja",
"followers_url": "https://api.github.com/users/brewerja/followers",
"following_url": "https://api.github.com/users/brewerja/following{/other_user}",
"gists_url": "https://api.github.com/users/brewerja/gists{/gist_id}",
"starred_url": "https://api.github.com/users/brewerja/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/brewerja/subscriptions",
"organizations_url": "https://api.github.com/users/brewerja/orgs",
"repos_url": "https://api.github.com/users/brewerja/repos",
"events_url": "https://api.github.com/users/brewerja/events{/privacy}",
"received_events_url": "https://api.github.com/users/brewerja/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
">Would an update_instance method help?\r\n\r\nThe docs and examples are already quite clear. You update an instance by setting the attributes and using `save()`, as this is an active-record style ORM.",
"I think it would be worth a warning note in the docs, letting folks know that Python will happily allow them to update every row in a table from an instance. It's a simple mistake that can have big consequences.\r\n\r\nI really appreciated all the [n+1 problem docs](https://github.com/coleifer/peewee/blob/master/docs/peewee/relationships.rst#avoiding-the-n1-problem)."
] | 2022-12-02T19:36:38 | 2022-12-02T21:22:24 | 2022-12-02T20:33:02 | NONE | null | Speaking from recent experience, I made a mistake when attempting to update a single field on a model.
```python
flag = Flag.get_by_id(flag_id)
flag.update(active=False).execute()
```
Given that I was operating on an instance of the model, I assumed I'd be updating that field only on a single row. However, given that in Python you can call a classmethod on an instance variable, it updates ALL the flags in the database! I'm glad I wasn't using the delete classmethod by accident.
```python
class Test:
@classmethod
def hello(cls):
print("CLASS HELLO")
if __name__ == '__main__':
t = Test()
t.hello()
Test.hello()
```
I wish I had a good suggestion for how to help others not make this mistake (other than learning Python better 😢 ). I see you do have `flag.delete_instance()` in addition to `Flag.delete()`. Would an `update_instance` method help?
Unfortunately, I see no way to detect, from a classmethod call, whether it was the class or an instance that invoked it.
[update]
I would favor what you suggested back in 2015:
>Classmethods operate on the table. Instance methods operate on the rows. Class represents table, instance represents row. It is just an inconvenient fact of python's `classmethod` decorator that you can call classmethods from an instance. I could write a special decorator that prevented this, e.g. `classonlymethod` but I don't think it's worth the time and more Pythonic anyways.
_Originally posted by @coleifer in https://github.com/coleifer/peewee/issues/586#issuecomment-95960454_ | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2658/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2658/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2657 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2657/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2657/comments | https://api.github.com/repos/coleifer/peewee/issues/2657/events | https://github.com/coleifer/peewee/issues/2657 | 1,472,272,003 | I_kwDOAA7yGM5XwRaD | 2,657 | [feature] Query tagging capability | {
"login": "recipe",
"id": 1947600,
"node_id": "MDQ6VXNlcjE5NDc2MDA=",
"avatar_url": "https://avatars.githubusercontent.com/u/1947600?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/recipe",
"html_url": "https://github.com/recipe",
"followers_url": "https://api.github.com/users/recipe/followers",
"following_url": "https://api.github.com/users/recipe/following{/other_user}",
"gists_url": "https://api.github.com/users/recipe/gists{/gist_id}",
"starred_url": "https://api.github.com/users/recipe/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/recipe/subscriptions",
"organizations_url": "https://api.github.com/users/recipe/orgs",
"repos_url": "https://api.github.com/users/recipe/repos",
"events_url": "https://api.github.com/users/recipe/events{/privacy}",
"received_events_url": "https://api.github.com/users/recipe/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Since this is so google-specific, I'm not too inclined to add it at the present."
] | 2022-12-02T03:55:25 | 2022-12-02T16:54:01 | 2022-12-02T16:54:01 | NONE | null | Hi @coleifer,
What do you think in general about providing a capability to add [tags for queries](https://cloud.google.com/sql/docs/postgres/using-query-insights#using-sqlcommenter:~:text=When%20you%20examine%20results%20in%20SQL%20database%20logs%2C%20they%20appear%20as%20follows)? Tagging SQL queries simplifies application troubleshooting and can be helpful for people who are using the Google Cloud SQL. Their Query Insights feature is able to parse tags and provide [application centric view](https://www.youtube.com/watch?v=qN7x3ngwz1o) to SRE.
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2657/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2657/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2656 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2656/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2656/comments | https://api.github.com/repos/coleifer/peewee/issues/2656/events | https://github.com/coleifer/peewee/issues/2656 | 1,469,201,531 | I_kwDOAA7yGM5Xkjx7 | 2,656 | can't select self-children items | {
"login": "1fisher",
"id": 91577407,
"node_id": "U_kgDOBXVcPw",
"avatar_url": "https://avatars.githubusercontent.com/u/91577407?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/1fisher",
"html_url": "https://github.com/1fisher",
"followers_url": "https://api.github.com/users/1fisher/followers",
"following_url": "https://api.github.com/users/1fisher/following{/other_user}",
"gists_url": "https://api.github.com/users/1fisher/gists{/gist_id}",
"starred_url": "https://api.github.com/users/1fisher/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/1fisher/subscriptions",
"organizations_url": "https://api.github.com/users/1fisher/orgs",
"repos_url": "https://api.github.com/users/1fisher/repos",
"events_url": "https://api.github.com/users/1fisher/events{/privacy}",
"received_events_url": "https://api.github.com/users/1fisher/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"`item.children` is exposed as a select query, which is iterable. Do this:\r\n\r\n```python\r\na = A.get(...)\r\nfor child in a.children:\r\n print(child)\r\n```\r\n\r\nAlso post questions like this on stack overflow. Self-referential fk docs are here for your reference: http://docs.peewee-orm.com/en/latest/peewee/models.html#self-referential-foreign-keys"
] | 2022-11-30T07:55:55 | 2022-11-30T14:17:50 | 2022-11-30T14:17:50 | NONE | null | ``` Python
class A(BaseModel):
parent = ForieginField('self', null=True, backref='children')
for item in A.select():
print(item.children)
``` | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2656/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2656/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2655 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2655/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2655/comments | https://api.github.com/repos/coleifer/peewee/issues/2655/events | https://github.com/coleifer/peewee/issues/2655 | 1,468,443,855 | I_kwDOAA7yGM5XhqzP | 2,655 | PostgresqlDatabase multithreading performance problem | {
"login": "mohamin1995",
"id": 45896467,
"node_id": "MDQ6VXNlcjQ1ODk2NDY3",
"avatar_url": "https://avatars.githubusercontent.com/u/45896467?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/mohamin1995",
"html_url": "https://github.com/mohamin1995",
"followers_url": "https://api.github.com/users/mohamin1995/followers",
"following_url": "https://api.github.com/users/mohamin1995/following{/other_user}",
"gists_url": "https://api.github.com/users/mohamin1995/gists{/gist_id}",
"starred_url": "https://api.github.com/users/mohamin1995/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/mohamin1995/subscriptions",
"organizations_url": "https://api.github.com/users/mohamin1995/orgs",
"repos_url": "https://api.github.com/users/mohamin1995/repos",
"events_url": "https://api.github.com/users/mohamin1995/events{/privacy}",
"received_events_url": "https://api.github.com/users/mohamin1995/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"@coleifer ",
">but the performance is worse than sequential running. anyone have any ideas?\r\n\r\nPython uses a global interpreter lock so only 1 thread is ever executing python code. If your code is CPU-bound then, due to context-switching, you will waste time overall.\r\n\r\nYou can try using multiple processes to circumvent this issue.",
"Although my job is IO-bound(multi-threading is not a bad choice), I implemented the multi process version too but the problem still persist with peewee then I implemented the function using psycopg2 adapter and the performance became 4 times faster(with multi threading).\r\n@coleifer ",
"Was it also 4x faster single-threaded with psycopg2?",
"No, single-threaded version of psycopg2 almost takes time equal to single-threaded peewee.",
"I made a little script that inserts 100K rows and queries it single-threaded, using 4 threads and 4 processes. The single-thread and 4-thread run about the same, but the multiprocess version runs in about half the time.\r\n\r\nThe psycopg2-only version is faster, but this is somewhat expected since it carries none of the python-side overhead. It is also marginally faster (10%) when run multi-threaded.\r\n\r\nI profiled the code and it looks to me like the bulk of the time in peewee is spent generating sql and serializing result rows to model instances, which is to be expected."
] | 2022-11-29T17:27:28 | 2022-12-02T19:33:42 | 2022-11-29T17:44:11 | NONE | null | Hello,
I have a postgresql db connection:
```
database = PostgresqlDatabase(config_server['database_name'],
**{'host': config_server['host'], 'port': config_server['port'],
'user': config_server['user'],
'password': config_server['password']
})
```
and each thread(4 thread) runs the below function with different date_time parameter, we must run the below function 100 times:
```
def get_estimations_v1(date_time, db) -> pd.DataFrame:
Estimation._meta.set_table_name('est_' + date_time.strftime("%Y%m%d"))
try:
db.connect(reuse_if_open=True)
query = Estimation.select().where(
Estimation.date_time.between(date_time - timedelta(minutes=1), date_time))
estimations = pd.DataFrame(list(query.dicts()))
return estimations
except Exception as ce:
logger.error('load of estimations failed for {}, {}', date_time, str(ce))
return
finally:
db.close()
return
```
but the performance is worse than sequential running. anyone have any ideas?
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2655/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2655/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2654 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2654/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2654/comments | https://api.github.com/repos/coleifer/peewee/issues/2654/events | https://github.com/coleifer/peewee/issues/2654 | 1,461,470,014 | I_kwDOAA7yGM5XHEM- | 2,654 | PostgresqlDatabase:is_connection_usable returns True, although the database is shut down | {
"login": "parallaxe",
"id": 1765580,
"node_id": "MDQ6VXNlcjE3NjU1ODA=",
"avatar_url": "https://avatars.githubusercontent.com/u/1765580?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/parallaxe",
"html_url": "https://github.com/parallaxe",
"followers_url": "https://api.github.com/users/parallaxe/followers",
"following_url": "https://api.github.com/users/parallaxe/following{/other_user}",
"gists_url": "https://api.github.com/users/parallaxe/gists{/gist_id}",
"starred_url": "https://api.github.com/users/parallaxe/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/parallaxe/subscriptions",
"organizations_url": "https://api.github.com/users/parallaxe/orgs",
"repos_url": "https://api.github.com/users/parallaxe/repos",
"events_url": "https://api.github.com/users/parallaxe/events{/privacy}",
"received_events_url": "https://api.github.com/users/parallaxe/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"There could potentially be a lot of overhead in checking liveness so Peewee uses two things:\r\n\r\n1. Internal flag indicating whether we successfully connected.\r\n2. Whether psycopg2's underlying connection transaction state is not in error.\r\n\r\nIf you are just using plain old psycopg2 and try this experiment you'll see that there's not much info available for \"detecting\" this:\r\n\r\n```python\r\nimport psycopg2\r\nimport psycopg2.extensions\r\n\r\nconn = psycopg2.connect(dbname='peewee_test')\r\nprint('connected!')\r\nprint('closed?', conn.closed)\r\nprint('status?', conn.status)\r\nprint('poll?', conn.poll())\r\ncurs = conn.cursor()\r\ncurs.execute('select 1')\r\ncurs.fetchall()\r\nconn.commit()\r\n\r\ninput('Shut down database now, then press Enter.')\r\n\r\nprint('closed?', conn.closed)\r\nprint('status?', conn.status)\r\nprint('poll?', conn.poll())\r\ncurs = conn.cursor()\r\ncurs.execute('select 1') # We will first detect the problem here.\r\ncurs.fetchall()\r\nconn.commit()\r\n```\r\n\r\nOutputs:\r\n\r\n```\r\nconnected!\r\nclosed? 0\r\nstatus? 1\r\npoll? 0\r\nShut down database now, then press Enter.\r\n <---- NOTE: I shut down the database server. The psycopg2 connection still reports\r\n that it is not closed and its status is READY.\r\nclosed? 0\r\nstatus? 1\r\npoll? 0\r\nTraceback (most recent call last):\r\n File \"x.py\", line 20, in <module>\r\n curs.execute('select 1')\r\npsycopg2.errors.AdminShutdown: terminating connection due to unexpected postmaster exit\r\nserver closed the connection unexpectedly\r\n This probably means the server terminated abnormally\r\n before or while processing the request.\r\n```\r\n\r\nYou can ask the psycopg2 folks what the best way would be to detect this before executing queries, but typically you probably want to be monitoring your database server and handling keeping the db running separately from your python app. Similarly, within your Python app, what exactly would you do if the database was not running, anyways? It's not like you can just reconnect because there's presumably nothing to reconnect to if its shut down.\r\n\r\nYou can always subclass and override `is_connection_usable` to attempt to execute something like `SELECT 1` and handle an exception there, but I've opted against that for the reasons mentioned above."
] | 2022-11-23T10:24:40 | 2022-11-23T15:00:55 | 2022-11-23T14:54:54 | NONE | null | I'm using peewee 3.15.4 with psycopg2-binary to connect to a postgres-database. To test how the system behaves in case that the database is not available, I shut the database down.
In the code I call `is_connection_usable` to check if the database is available. It returns `True`, although the database is no longer available. The termination of the connection is logged, so it is recognised by any of the modules involved, but it does not propagate up to the `PostgresqlDatabase`-instance. Any ideas what is going on here?
```
ERROR:root:terminating connection due to administrator command
server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
ERROR:root:terminating connection due to administrator command
server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
ERROR:root:connection already closed
ERROR:root:connection already closed
Database status True
``` | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2654/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2654/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2653 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2653/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2653/comments | https://api.github.com/repos/coleifer/peewee/issues/2653/events | https://github.com/coleifer/peewee/issues/2653 | 1,460,850,759 | I_kwDOAA7yGM5XEtBH | 2,653 | When the connection is maintained, the query suddenly takes a lot of time one day | {
"login": "liuhuanxg",
"id": 45617105,
"node_id": "MDQ6VXNlcjQ1NjE3MTA1",
"avatar_url": "https://avatars.githubusercontent.com/u/45617105?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/liuhuanxg",
"html_url": "https://github.com/liuhuanxg",
"followers_url": "https://api.github.com/users/liuhuanxg/followers",
"following_url": "https://api.github.com/users/liuhuanxg/following{/other_user}",
"gists_url": "https://api.github.com/users/liuhuanxg/gists{/gist_id}",
"starred_url": "https://api.github.com/users/liuhuanxg/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/liuhuanxg/subscriptions",
"organizations_url": "https://api.github.com/users/liuhuanxg/orgs",
"repos_url": "https://api.github.com/users/liuhuanxg/repos",
"events_url": "https://api.github.com/users/liuhuanxg/events{/privacy}",
"received_events_url": "https://api.github.com/users/liuhuanxg/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"That's quite odd, but I can't really speculate as to what might be going on. When you say \"the service\" are you referring to the database server, or the python application? What does the query look like that went from 3 seconds -> 90 seconds? I'm almost positive that something in the Peewee code wouldn't be affecting this. The behavior should be effectively \"stateless\" -- you execute the query and do whatever with the results -- if it was a Peewee issue I'd think it would either be always slow or always fast.\r\n\r\nSo my guess is either it's the db server, pypy, or perhaps something else that may be going on inside your application.",
"Going to close for now unless there is compelling evidence this is in fact a peewee issue, but please feel free to comment w/more details and I'll give it some thought."
] | 2022-11-23T02:30:17 | 2022-11-23T14:41:38 | 2022-11-23T14:41:37 | NONE | null | I use pypy2.7, When I connect to MySQL, Because of the large amount of data, the paging query used took about 3 seconds to complete all queries at the beginning, but after about seven days, it took 80-90 seconds. When the service was restarted, it was restored. I don't know why, does anyone know? | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2653/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2653/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2652 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2652/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2652/comments | https://api.github.com/repos/coleifer/peewee/issues/2652/events | https://github.com/coleifer/peewee/issues/2652 | 1,458,397,909 | I_kwDOAA7yGM5W7WLV | 2,652 | Does peewee support PostgreSQL `CREATE INDEX CONCURRENTLY`? | {
"login": "ilyakamens",
"id": 3293811,
"node_id": "MDQ6VXNlcjMyOTM4MTE=",
"avatar_url": "https://avatars.githubusercontent.com/u/3293811?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/ilyakamens",
"html_url": "https://github.com/ilyakamens",
"followers_url": "https://api.github.com/users/ilyakamens/followers",
"following_url": "https://api.github.com/users/ilyakamens/following{/other_user}",
"gists_url": "https://api.github.com/users/ilyakamens/gists{/gist_id}",
"starred_url": "https://api.github.com/users/ilyakamens/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/ilyakamens/subscriptions",
"organizations_url": "https://api.github.com/users/ilyakamens/orgs",
"repos_url": "https://api.github.com/users/ilyakamens/repos",
"events_url": "https://api.github.com/users/ilyakamens/events{/privacy}",
"received_events_url": "https://api.github.com/users/ilyakamens/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"We don't have that right now, but the use-case is probably a one-off migration (if you need to do it concurrently, without locking things). In those situations its probably better to just write and run the SQL directly, e.g.\r\n\r\n```python\r\ndb.execute_sql('create index concurrently ...')\r\n```",
"Yes, that's what I'm currently doing. Would you accept a PR to add `concurrently=True` to `add_index()`?",
"Hi, @coleifer. Following up with something related:\r\n\r\nAs you probably know, concurrent indexes [can't be run inside of a transaction](https://www.postgresql.org/docs/current/sql-createindex.html#SQL-CREATEINDEX-CONCURRENTLY):\r\n\r\n>Another difference is that a regular CREATE INDEX command can be performed within a transaction block, but CREATE INDEX CONCURRENTLY cannot.\r\n\r\nWhen I try to create the index:\r\n\r\n```python\r\ndb.database.execute_sql(\"CREATE INDEX CONCURRENTLY foo_bar ON foo (bar);\")\r\n```\r\n\r\nI receive the following error as expected:\r\n\r\n```sh\r\nTraceback (most recent call last):\r\n File \"/usr/local/lib/python3.7/site-packages/peewee.py\", line 3144, in execute_sql\r\n cursor.execute(sql, params or ())\r\npsycopg2.errors.ActiveSqlTransaction: CREATE INDEX CONCURRENTLY cannot run inside a transaction block\r\n\r\n\r\nDuring handling of the above exception, another exception occurred:\r\n\r\nTraceback (most recent call last):\r\n File \"./manage.py\", line 611, in <module>\r\n manager.run()\r\n ...\r\n File \"/usr/local/lib/python3.7/site-packages/peewee.py\", line 3144, in execute_sql\r\n cursor.execute(sql, params or ())\r\npeewee.InternalError: CREATE INDEX CONCURRENTLY cannot run inside a transaction block\r\n```\r\n\r\nI receive the same error with the following:\r\n\r\n```python\r\nwith db.database.manual_commit():\r\n db.database.execute_sql(\"CREATE INDEX CONCURRENTLY foo_bar ON foo (bar);\")\r\n```\r\n\r\nOnly the following works (found [here](https://www.psycopg.org/docs/connection.html#connection.autocommit)):\r\n\r\n```python\r\ndb.database._state.conn.set_session(autocommit=True)\r\ndb.database.execute_sql(\"CREATE INDEX CONCURRENTLY foo_bar ON foo (bar);\")\r\n```\r\n\r\nIs there some other peewee API I'm missing so I don't have to reach so far down the stack? Version details:\r\n\r\n>peewee==3.14.4\r\n>psycopg2==2.8.2\r\n\r\nThe `db` object above is created via:\r\n\r\n```python\r\nfrom playhouse.flask_utils import FlaskDB\r\n\r\ndb = FlaskDB(app)\r\n```\r\n\r\nThank you.",
"Oh interesting, no you're not doing anything wrong! This looks to me more like a DB-API 2.0 / psycopg2 side-effect. I've never seen this before, actually - and like you, would have assumed that the changes would be run in autocommit mode by default. Unfortunately, the DB-API 2.0 specifies some sort of strange behavior, so explicitly setting the underlying connection to `autocommit` for the purposes of this script isn't too bad.\r\n\r\nHere's a slightly better version you can use:\r\n\r\n```python\r\npwdb = db.database\r\npwdb.connection().set_session(autocommit=True)\r\npwdb.execute_sql(\"CREATE INDEX CONCURRENTLY foo_bar ON foo (bar);\")\r\n```",
"Awesome. Thank you, and happy 🦃."
] | 2022-11-21T18:30:58 | 2022-11-22T15:50:28 | 2022-11-21T19:22:01 | CONTRIBUTOR | null | I didn't see any mention of [this](https://www.postgresql.org/docs/current/sql-createindex.html#:~:text=Normally%20PostgreSQL%20locks%20the%20table,the%20index%20build%20is%20finished.) in code, docs, or past issues (apologies if I didn't search thoroughly enough). My guess is it doesn't, but figured I'd ask just in case. If that's so, would you be open to a PR? | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2652/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2652/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2651 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2651/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2651/comments | https://api.github.com/repos/coleifer/peewee/issues/2651/events | https://github.com/coleifer/peewee/issues/2651 | 1,457,962,502 | I_kwDOAA7yGM5W5r4G | 2,651 | Allow usage of __init_subclass__ in Models | {
"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 | [
"Darn it. This is already fixed in `3.15.4`. I was using `3.14.8` on that particular machine.\r\nSorry for the noise.",
"No problem at all, I only just released that fix, with thanks to @smac89 for the patch."
] | 2022-11-21T13:35:12 | 2022-11-21T13:55:31 | 2022-11-21T13:39:58 | CONTRIBUTOR | null | Currently, one cannot use `__init_subclass__()` on `Model`s.
This is useful, if one wants to create an abstract model to be implemented with different parameters.
Unfortunately `ModelBase` currently hands off all kwargs to the parent type `type` resulting in `TypeError`s:
```python
from peewee import Model
class MyTemplate(Model):
def __init_subclass__(cls, *args, some_param: str, **kwargs):
super().__init_subclass__(*args, **kwargs)
if some_param is not None:
cls.SOME_PARAM = some_param
class MyImplementation(MyTemplate, some_param='hello world'):
pass
```
Resulting in:
```shell
$ python3 test.py
Traceback (most recent call last):
File "/root/test.py", line 13, in <module>
class MyImplementation(MyTemplate, some_param='hello world'):
TypeError: __new__() got an unexpected keyword argument 'some_param'
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2651/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2651/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2650 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2650/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2650/comments | https://api.github.com/repos/coleifer/peewee/issues/2650/events | https://github.com/coleifer/peewee/issues/2650 | 1,457,710,908 | I_kwDOAA7yGM5W4uc8 | 2,650 | affairs exist concurrency Error | {
"login": "DreamBizideal",
"id": 82210587,
"node_id": "MDQ6VXNlcjgyMjEwNTg3",
"avatar_url": "https://avatars.githubusercontent.com/u/82210587?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/DreamBizideal",
"html_url": "https://github.com/DreamBizideal",
"followers_url": "https://api.github.com/users/DreamBizideal/followers",
"following_url": "https://api.github.com/users/DreamBizideal/following{/other_user}",
"gists_url": "https://api.github.com/users/DreamBizideal/gists{/gist_id}",
"starred_url": "https://api.github.com/users/DreamBizideal/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/DreamBizideal/subscriptions",
"organizations_url": "https://api.github.com/users/DreamBizideal/orgs",
"repos_url": "https://api.github.com/users/DreamBizideal/repos",
"events_url": "https://api.github.com/users/DreamBizideal/events{/privacy}",
"received_events_url": "https://api.github.com/users/DreamBizideal/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"You need to re-fetch it or use update... returning (if your database supports it)."
] | 2022-11-21T10:40:40 | 2022-11-21T12:50:45 | 2022-11-21T11:52:04 | NONE | null | ![QQ截图20221121183253](https://user-images.githubusercontent.com/82210587/203028544-30f73d9f-3684-485f-90e5-eefee34f40a3.png)
`if __name__ == '__main__':
t1 = threading.Thread(target=sell2)
t2 = threading.Thread(target=sell2)
t1.start()
t2.start()
t1.join()
t2.join()`
sorry i don't speak english
我开启了两个线程 一个线程在被修改完成后 另一个线程查不到实时数据 只能查到修改之前的数据(操作都在with db.atomic() as txn:)
并且我没有rollback()
不使用 db.atomic()就正常查询到 但是我需要事务
添加了事务即使数据库修改过数据 在db.atomic()里进行查询也不会查到当前的数据 只会查到之前的
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2650/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2650/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2649 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2649/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2649/comments | https://api.github.com/repos/coleifer/peewee/issues/2649/events | https://github.com/coleifer/peewee/issues/2649 | 1,451,340,015 | I_kwDOAA7yGM5WgbDv | 2,649 | Build a database (SQLite) with peewee WITHOUT setting in the python code the "name" of the table fields | {
"login": "rollobesson",
"id": 118347770,
"node_id": "U_kgDOBw3X-g",
"avatar_url": "https://avatars.githubusercontent.com/u/118347770?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/rollobesson",
"html_url": "https://github.com/rollobesson",
"followers_url": "https://api.github.com/users/rollobesson/followers",
"following_url": "https://api.github.com/users/rollobesson/following{/other_user}",
"gists_url": "https://api.github.com/users/rollobesson/gists{/gist_id}",
"starred_url": "https://api.github.com/users/rollobesson/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/rollobesson/subscriptions",
"organizations_url": "https://api.github.com/users/rollobesson/orgs",
"repos_url": "https://api.github.com/users/rollobesson/repos",
"events_url": "https://api.github.com/users/rollobesson/events{/privacy}",
"received_events_url": "https://api.github.com/users/rollobesson/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"The easiest way to do this is using the `type()` builtin:\r\n\r\n```python\r\nclass BaseModel(Model):\r\n class Meta:\r\n database = ...\r\n\r\nfields = {\r\n 'dynamic1': CharField(),\r\n 'dynamic2': IntegerField(),\r\n ...\r\n}\r\n\r\n# Create a new class. Signature is (name, bases, attrs).\r\nMyTable = type('MyTable', (BaseModel,), fields)\r\n```\r\n\r\nThis produces:\r\n\r\n```python\r\n>>> MyTable._meta.fields\r\n{'id': <AutoField: MyTable.id>,\r\n 'dynamic1': <CharField: MyTable.dynamic1>,\r\n 'dynamic2': <IntegerField: MyTable.dynamic2>}\r\n\r\n>>> MyTable._meta.table_name]\r\n'mytable'\r\n```"
] | 2022-11-16T10:41:53 | 2022-11-16T14:06:40 | 2022-11-16T14:06:14 | NONE | null | Hi everyboby
Hope my english will be understable
I need to read a folder fulled of Excel file and to feed a sqlite data base: Yes EASY
In fact I want to make a tool :
I feed a txt file with the name of the folder, the cells (eg: A1, B6, ...) and the names of the datas (eg: firstname, lastname, ...)
I lunch a Peewee program which reads the txt file and the folder and build the database
The difficulty is on the Class(Model):
class mytable(Model):
dynamic_data[0]=CharField() "# here "first_name" is in dynamic_data[0]
class Meta:
database = db
CharField() refuses to make an objet with a dynamic name coming from my txt file
Who has an solution ?
Thank you ! | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2649/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2649/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2648 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2648/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2648/comments | https://api.github.com/repos/coleifer/peewee/issues/2648/events | https://github.com/coleifer/peewee/pull/2648 | 1,446,286,891 | PR_kwDOAA7yGM5Cvxas | 2,648 | Remove redundant wheel dep from pyproject.toml | {
"login": "mgorny",
"id": 110765,
"node_id": "MDQ6VXNlcjExMDc2NQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/110765?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/mgorny",
"html_url": "https://github.com/mgorny",
"followers_url": "https://api.github.com/users/mgorny/followers",
"following_url": "https://api.github.com/users/mgorny/following{/other_user}",
"gists_url": "https://api.github.com/users/mgorny/gists{/gist_id}",
"starred_url": "https://api.github.com/users/mgorny/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/mgorny/subscriptions",
"organizations_url": "https://api.github.com/users/mgorny/orgs",
"repos_url": "https://api.github.com/users/mgorny/repos",
"events_url": "https://api.github.com/users/mgorny/events{/privacy}",
"received_events_url": "https://api.github.com/users/mgorny/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I'm just following what is listed here: https://pip.pypa.io/en/stable/reference/build-system/pyproject-toml/#fallback-behaviour\r\n\r\nAnd as recently as this week by another one of the pypa team: https://github.com/pypa/pip/issues/8559#issuecomment-1310317396",
"> I'm just following what is listed here: https://pip.pypa.io/en/stable/reference/build-system/pyproject-toml/#fallback-behaviour\r\n\r\nWell, I don't think it's needed for the \"fallback\" code path either but even if it were, you are not supposed to use that backend. It's just \"what happens when there's no pyproject.toml\".\r\n\r\n> And as recently as this week by another one of the pypa team: [pypa/pip#8559 (comment)](https://github.com/pypa/pip/issues/8559#issuecomment-1310317396)\r\n\r\nUnfortunately, it will probably take years before people realize they're copying a mistake from the past. That's why I'm always linking to the official documentation.",
">Unfortunately, it will probably take years before people realize they're copying a mistake from the past. That's why I'm always linking to the official documentation.\r\n\r\nI agree, and would add my own opinion that pypa is an absolute joke.\r\n\r\nI'm going to leave it in. Call it cargo-culting, call it senseless, but I just don't care to spend the effort to try and learn all the intricacies of these various new tools/their interactions/and what combination of what versions does what (wheel, pyproject, pip, setuptools). They'll probably change everything again in a year or two.",
"Well, the whole point is that they are considering actually stopping to use `wheel` (though it was a while back, back when wheel received zero maintenance) in favor of a built-in wheel generator in setuptools."
] | 2022-11-12T06:22:32 | 2022-11-14T14:26:58 | 2022-11-14T13:30:49 | NONE | null | Remove the redundant `wheel` dependency, as it is added by the backend automatically. Listing it explicitly in the documentation was a historical mistake and has been fixed since, see: https://github.com/pypa/setuptools/commit/f7d30a9529378cf69054b5176249e5457aaf640a | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2648/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2648/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/2648",
"html_url": "https://github.com/coleifer/peewee/pull/2648",
"diff_url": "https://github.com/coleifer/peewee/pull/2648.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/2648.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/2647 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2647/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2647/comments | https://api.github.com/repos/coleifer/peewee/issues/2647/events | https://github.com/coleifer/peewee/issues/2647 | 1,443,869,429 | I_kwDOAA7yGM5WD7L1 | 2,647 | make the build system pep518 compatible | {
"login": "sileht",
"id": 200878,
"node_id": "MDQ6VXNlcjIwMDg3OA==",
"avatar_url": "https://avatars.githubusercontent.com/u/200878?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/sileht",
"html_url": "https://github.com/sileht",
"followers_url": "https://api.github.com/users/sileht/followers",
"following_url": "https://api.github.com/users/sileht/following{/other_user}",
"gists_url": "https://api.github.com/users/sileht/gists{/gist_id}",
"starred_url": "https://api.github.com/users/sileht/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/sileht/subscriptions",
"organizations_url": "https://api.github.com/users/sileht/orgs",
"repos_url": "https://api.github.com/users/sileht/repos",
"events_url": "https://api.github.com/users/sileht/events{/privacy}",
"received_events_url": "https://api.github.com/users/sileht/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"For fucks sake, pypa is so obnoxious! I don't know how to make our setup process compatible with this toml nonsense because we offer several installation modes:\r\n\r\n1. When cython is available we will cythonize the extension files\r\n2. When sqlite headers are available we will compile the extensions\r\n3. If sqlite headers are not available we do an installation without the optional extensions.\r\n\r\nI think part of the issue is that you don't have the `wheel` package installed, and thus `pip` cannot run `setup.py bdist_wheel`. For some insane reason the pip folks have not found it in their interests to make `wheel` part of either the standard library or the dependencies of `pip` itself, but in the future will effectively treat it as a dependency for projects that don't or can't use \"toml\".\r\n\r\nAt any rate, I'm going to hold off on any knee-jerk changes to this library and suggest for now that you install `wheel` first. Going forward, I may need to look into just pushing wheels to pypi, but I don't want to do that because a) concerns about conditionally compiling the extensions, b) cross-platform support for C extensions, and c) breaking everyone's existing installation workflow.",
"Actually, I'm going to try adding the absolute minimal `pyproject.toml` and see where that gets us."
] | 2022-11-10T13:01:36 | 2022-11-10T13:52:52 | 2022-11-10T13:50:10 | NONE | null | Installation of this package is going to break soon.
```
$ pip install peewee
Collecting peewee
Using cached peewee-3.15.3.tar.gz (858 kB)
Preparing metadata (setup.py) ... done
Installing collected packages: peewee
DEPRECATION: peewee is being installed using the legacy 'setup.py install' method, because it does not have a 'pyproject.toml' and the 'wheel' package is not installed. pip 23.1 will enforce this behaviour change. A possible replacement is to enable the '--use-pep517' option. Discussion can be found at https://github.com/pypa/pip/issues/8559
Running setup.py install for peewee ... done
Successfully installed peewee-3.15.3
```
does the project has planned to upgrade the build system ? | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2647/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2647/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2646 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2646/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2646/comments | https://api.github.com/repos/coleifer/peewee/issues/2646/events | https://github.com/coleifer/peewee/issues/2646 | 1,443,775,831 | I_kwDOAA7yGM5WDkVX | 2,646 | NameError: name 'Counter' is not defined in example | {
"login": "stefaneidelloth",
"id": 12675339,
"node_id": "MDQ6VXNlcjEyNjc1MzM5",
"avatar_url": "https://avatars.githubusercontent.com/u/12675339?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/stefaneidelloth",
"html_url": "https://github.com/stefaneidelloth",
"followers_url": "https://api.github.com/users/stefaneidelloth/followers",
"following_url": "https://api.github.com/users/stefaneidelloth/following{/other_user}",
"gists_url": "https://api.github.com/users/stefaneidelloth/gists{/gist_id}",
"starred_url": "https://api.github.com/users/stefaneidelloth/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/stefaneidelloth/subscriptions",
"organizations_url": "https://api.github.com/users/stefaneidelloth/orgs",
"repos_url": "https://api.github.com/users/stefaneidelloth/repos",
"events_url": "https://api.github.com/users/stefaneidelloth/events{/privacy}",
"received_events_url": "https://api.github.com/users/stefaneidelloth/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Yeah the readme is just showing that to illustrate a point. It's hopefully obvious what the intent is.",
"No, its not. I thought Counter is a missing Class that is also mapped to the database or there is a missing import."
] | 2022-11-10T11:56:24 | 2022-11-10T12:08:51 | 2022-11-10T12:02:34 | NONE | null | ---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In [7], line 35
28 users = (User
29 .select(User, tweet_ct.alias('ct'))
30 .join(Tweet, JOIN.LEFT_OUTER)
31 .group_by(User)
32 .order_by(tweet_ct.desc()))
34 # Do an atomic update
---> 35 Counter.update(count=Counter.count + 1).where(Counter.url == request.url)
NameError: name 'Counter' is not defined | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2646/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2646/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2645 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2645/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2645/comments | https://api.github.com/repos/coleifer/peewee/issues/2645/events | https://github.com/coleifer/peewee/issues/2645 | 1,443,527,569 | I_kwDOAA7yGM5WCnuR | 2,645 | Bug: ``insert_many`` with tuple insert first character of string | {
"login": "Sherlock-Homlmes",
"id": 19506491,
"node_id": "MDQ6VXNlcjE5NTA2NDkx",
"avatar_url": "https://avatars.githubusercontent.com/u/19506491?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/Sherlock-Homlmes",
"html_url": "https://github.com/Sherlock-Homlmes",
"followers_url": "https://api.github.com/users/Sherlock-Homlmes/followers",
"following_url": "https://api.github.com/users/Sherlock-Homlmes/following{/other_user}",
"gists_url": "https://api.github.com/users/Sherlock-Homlmes/gists{/gist_id}",
"starred_url": "https://api.github.com/users/Sherlock-Homlmes/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/Sherlock-Homlmes/subscriptions",
"organizations_url": "https://api.github.com/users/Sherlock-Homlmes/orgs",
"repos_url": "https://api.github.com/users/Sherlock-Homlmes/repos",
"events_url": "https://api.github.com/users/Sherlock-Homlmes/events{/privacy}",
"received_events_url": "https://api.github.com/users/Sherlock-Homlmes/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"The thing is `('val1-1')` is not a tuple, it's just a string.\r\n\r\n```\r\n>>> v = ('val1-1')\r\n>>> type(v)\r\n<class 'str'>\r\n```\r\n\r\nFor tuple It shoud be `('val1-1',)`.",
"This is not a big but you have a mistake in your syntax. @rudyryk has the correct solution.\r\n\r\nAlso do you really think something THIS foundational would be broken? Next time triple check your own code before creating issues."
] | 2022-11-10T09:13:48 | 2022-11-10T11:56:33 | 2022-11-10T11:56:33 | NONE | null | **Model:**
```
class Tags(PeeweeModel):
id = IntegerField()
name = TextField()
class Meta:
db_table = 'tags'
```
**Insert function:**
```
def create_sample_tags():
list_tags=[
('val1-1'),
('val2-1'),
('val3-1')
]
Tags.insert_many(list_tags, fields=[Tags.name]).execute()
```
**Result:**
![image](https://user-images.githubusercontent.com/19506491/201047088-764636b3-9569-43e7-835c-1ec80384b231.png)
It failed to insert the value with tuple.
When I insert_many with dictionary, it still works.
Peewee: 3.15.3
Database: Postgres 15
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2645/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/2645/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2644 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2644/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2644/comments | https://api.github.com/repos/coleifer/peewee/issues/2644/events | https://github.com/coleifer/peewee/issues/2644 | 1,435,402,355 | I_kwDOAA7yGM5VjoBz | 2,644 | What's the proper way of serializing a dynamically extended model for use in another process? | {
"login": "Jessime",
"id": 8493770,
"node_id": "MDQ6VXNlcjg0OTM3NzA=",
"avatar_url": "https://avatars.githubusercontent.com/u/8493770?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/Jessime",
"html_url": "https://github.com/Jessime",
"followers_url": "https://api.github.com/users/Jessime/followers",
"following_url": "https://api.github.com/users/Jessime/following{/other_user}",
"gists_url": "https://api.github.com/users/Jessime/gists{/gist_id}",
"starred_url": "https://api.github.com/users/Jessime/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/Jessime/subscriptions",
"organizations_url": "https://api.github.com/users/Jessime/orgs",
"repos_url": "https://api.github.com/users/Jessime/repos",
"events_url": "https://api.github.com/users/Jessime/events{/privacy}",
"received_events_url": "https://api.github.com/users/Jessime/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"So you're wanting to store a pickle of the model class itself? My own interpretation without knowing any of the context is that you've got an accretion of hacks and are looking for more hacks to add on top, without considering that maybe the whole approach is flawed. When pickle looks up the class in the 2nd process, it doesn't serialize the model class and all its attributes -- it's just storing basically the path to the class (`__main__.BasicModel`). So you would have to apply your changes there, too.\r\n\r\nThat said if you want to treat your model classes themselves as just more data, I'd suggest an intermediate format like `{\"BasicModel\": [[\"field1\", \"int\"], [\"field2\", \"text\"]]}` and create them dynamically.",
"Hi! Thanks for the quick response.\r\n\r\n> you've got an accretion of hacks and are looking for more hacks to add on top\r\n\r\nThankfully, I'm just starting out on this project. So, no hacks yet, just some early code smells. Hopefully you don't mind if I give this question one more attempt. I suspect that 1) a little more context might make things clearer 2) I have a gut feeling there's an interesting point here.\r\n\r\nFirst, a little more context. I'm building a CLI to deal with fairly messy bioinformatics user data, which is coming in as multiple flat text files. Each file contains a handful of required columns and likely multiple optional/custom fields as well. The whole spec for a `.vcf` file is a whopping 29 pages long, if you're morbidly curious. https://samtools.github.io/hts-specs/VCFv4.2.pdf\r\n\r\nBecause all of the files (despite having different columns) all contain information about genomic variants, there's a lot of value to be gained from loading these files into a database. But it's impossible to know a priori what the columns are going to be. \r\n\r\nSo as I mentioned previously, step 1 is to build the db. That's not too bad. We've got the `add_field` API, so no hacks needed there. \r\n\r\nNow, how do I help users visualize/query/analyze/etc. their new db in future processes, given that I don't know their db schema? Pickling the class created during the load was one idea, dumping a custom intermediate format is another, but I'm by no means tied to either of them. A third option I thought of in writing up this response is that maybe [pwiz](http://docs.peewee-orm.com/en/latest/peewee/playhouse.html#pwiz-a-model-generator) is a reasonable approach?\r\n\r\nFinally, I have a philosophical question. Given that `add_field` exists, dynamic generation of models seems a supported, non-hack pattern. However, since there's no standard way of saving the generated/modified model, does that imply that the modified model is only valid for the lifetime of the originating process? Is there a specific reason why one should avoid using a modified data model in a downstream process?\r\n\r\nI'm by no means a db expert, so genuinely curious to hear thoughts!",
">Now, how do I help users visualize/query/analyze/etc. their new db in future processes, given that I don't know their db schema?\r\n\r\nYou'll have to use introspection at some point or other -- take a look at `dataset`, it might be just what you need: http://docs.peewee-orm.com/en/latest/peewee/playhouse.html#dataset -- it can handle messy data and makes heavy use of the introspection stuff that pwiz also uses.\r\n\r\n>does that imply that the modified model is only valid for the lifetime of the originating process?\r\n\r\nYou're conflating a pickled class with the actual class itself. The class itself is a perfectly valid python construct, however you created it. The issue is that pickle does not serialize all the attributes of the class. It serializes the import path. That's it.\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 Reg(db.Model):\r\n ...: key = TextField()\r\n ...: \r\n\r\nIn [4]: import pickle\r\n\r\nIn [5]: pickle.dumps(Reg)\r\nOut[5]: b'\\x80\\x03c__main__\\nReg\\nq\\x00.'\r\n```\r\n\r\nSee how \"key\" appears nowhere in there? Neither does \"id\" (which is also a field on the model).\r\n\r\nThe models are perfectly valid wherever they're created, however they're created. You just need to find a serialization transport or other method of reading and writing data that does not rely on a broken/flawed assumption.",
"Ah, I should have used a more descriptive word than just \"valid\". I meant valid not so much in the technical sense as in a \"this is a normal pattern we support in peewee\" sense. In other words, maybe there could/should be a canonical serialization method, perhaps wrapped in `Model.serialize()`?\r\n\r\n Regardless of whether that's a reasonable suggestion:\r\n 1. I played around with `pwiz` and it get's me where I need to go\r\n 2. I've actually used `dataset` a ton and love its simplicity and ease-of-use\r\n 3. Thanks for all the time and effort you've put into this library!",
"The database schema is always the ultimate source of truth, regardless of the model class -- that's why introspection / `playhouse.reflection` is probably the best bet."
] | 2022-11-04T00:32:18 | 2022-11-04T23:29:55 | 2022-11-04T13:08:14 | NONE | null | I can hack my way out of this situation, but it seems a common enough pattern that there might be a conical way of doing it that I'm not able to Google.
I want to be able to:
1. Dynamically add fields to some basic model, then save a bunch of data to a db.
2. In a second python process, I want to be able to query the data in the db I just created, using the dynamically extended class
However, if I try serializing the class with `pickle`, the dynamically added fields are missing from the model. Here's some toy code to demonstrate:
```python
import peewee
import pickle
DB = peewee.SqliteDatabase("test1.db")
class BasicModel(peewee.Model):
class Meta:
database = DB
header = peewee.CharField()
user_defined_field_name = "my_field"
BasicModel._meta.add_field(user_defined_field_name, peewee.CharField())
row1 = BasicModel(header="header", my_field="data")
row1.save()
# This part runs, but doesn't work as intended
pickle.dump(BasicModel, open("BasicModel.pkl", "wb"))
```
So great, I have a db that has the data I want in it. Now, in a second process, I'd like to be able to query that data:
```python
import pickle
BasicModel = pickle.load(open("BasicModel.pkl", "rb"))
example = BasicModel.select().limit(1)[0]
print(example.my_field)
```
Unfortunately, this results in:
```python
AttributeError: 'VariantRecord' object has no attribute 'my_field'
```
A couple of sanity checks:
1. In the first process, I'm able to do `print(dir(BasicModel))` and see `my_field`
2. In the second process, I'm able to do `print(example.header)`
It seems pretty clear that `pickle` isn't serializing anything from `add_field`, but I'm not sure what to do about it. I don't think it would be that hard to pickle enough information to re-execute the `add_field` code at runtime of the second process, but it's still a hassle I'd rather avoid if possible.
Any suggestions? Thanks! | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2644/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2644/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2643 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2643/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2643/comments | https://api.github.com/repos/coleifer/peewee/issues/2643/events | https://github.com/coleifer/peewee/issues/2643 | 1,435,051,834 | I_kwDOAA7yGM5ViSc6 | 2,643 | Peewee Not Honouring Alias When Alias Name Matches Column Name | {
"login": "NinjaMeTimbers",
"id": 1312289,
"node_id": "MDQ6VXNlcjEzMTIyODk=",
"avatar_url": "https://avatars.githubusercontent.com/u/1312289?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/NinjaMeTimbers",
"html_url": "https://github.com/NinjaMeTimbers",
"followers_url": "https://api.github.com/users/NinjaMeTimbers/followers",
"following_url": "https://api.github.com/users/NinjaMeTimbers/following{/other_user}",
"gists_url": "https://api.github.com/users/NinjaMeTimbers/gists{/gist_id}",
"starred_url": "https://api.github.com/users/NinjaMeTimbers/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/NinjaMeTimbers/subscriptions",
"organizations_url": "https://api.github.com/users/NinjaMeTimbers/orgs",
"repos_url": "https://api.github.com/users/NinjaMeTimbers/repos",
"events_url": "https://api.github.com/users/NinjaMeTimbers/events{/privacy}",
"received_events_url": "https://api.github.com/users/NinjaMeTimbers/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"This is known behavior, as Peewee falls back to using heuristics (column name in this case) to try to determine which \"converter\" to apply to the value coming back from the database cursor. It is treating each string, 'Y' and 'N' as truth-y boolean values.\r\n\r\nTo eliminate this behavior, just add `.coerce(False)` to your `Case`:\r\n\r\n```python\r\nprint(list(A.select(Case(None, [(A.a, \"Y\")], \"N\").coerce(False).alias(\"a\")).dicts()))\r\n```",
"Awesome, thanks!"
] | 2022-11-03T17:49:16 | 2022-11-03T18:24:54 | 2022-11-03T18:14:55 | NONE | null | When doing a query with peewee (version 3.14.0), when making an alias for a column that matches the actual column name, the values in the output do not match what was given in the query. It seems to be casting the data to match the data type of the original column. The following code highlights this issue:
```
from peewee import *
db = SqliteDatabase(":memory:")
db.connect()
class A(Model):
a = BooleanField()
class Meta:
database = db
db.create_tables([A])
A.insert(dict(a=True)).execute()
A.insert(dict(a=False)).execute()
print(list(A.select(Case(None, [(A.a, "Y")], "N").alias("a")).dicts()))
print(list(A.select(Case(None, [(A.a, "Y")], "N").alias("b")).dicts()))
```
The output is
```
[{'a': True}, {'a': True}]
[{'b': 'Y'}, {'b': 'N'}]
```
I would expect the output of both cases be the same and to match the output with alias "b". | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2643/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2643/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2642 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2642/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2642/comments | https://api.github.com/repos/coleifer/peewee/issues/2642/events | https://github.com/coleifer/peewee/issues/2642 | 1,430,059,326 | I_kwDOAA7yGM5VPPk- | 2,642 | Bug: insert_many execute in PostgreSQL returns cursor instead of int row count | {
"login": "bravegag",
"id": 4385408,
"node_id": "MDQ6VXNlcjQzODU0MDg=",
"avatar_url": "https://avatars.githubusercontent.com/u/4385408?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/bravegag",
"html_url": "https://github.com/bravegag",
"followers_url": "https://api.github.com/users/bravegag/followers",
"following_url": "https://api.github.com/users/bravegag/following{/other_user}",
"gists_url": "https://api.github.com/users/bravegag/gists{/gist_id}",
"starred_url": "https://api.github.com/users/bravegag/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/bravegag/subscriptions",
"organizations_url": "https://api.github.com/users/bravegag/orgs",
"repos_url": "https://api.github.com/users/bravegag/repos",
"events_url": "https://api.github.com/users/bravegag/events{/privacy}",
"received_events_url": "https://api.github.com/users/bravegag/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"And if you scrolled further, you'll see: ![screenshot](https://user-images.githubusercontent.com/119974/199052251-48224a6c-cb9c-492e-9102-91894e6deebb.png)\r\n\r\n>The default return value is the number of rows modified. However, when using Postgres, Peewee will return a cursor by default that yields the primary-keys of the inserted rows. To disable this functionality with Postgres, use an empty call to returning().\r\n\r\nThe above will return you the actual psycopg2 cursor.\r\n\r\nTo get the rowcount instead: https://docs.peewee-orm.com/en/latest/peewee/api.html?highlight=insert_many#Insert.as_rowcount",
"Ok, thanks! will this same API work with any vendor or is it PostgreSQL specific?\r\n",
"It should work across libraries. Here's a test case if you want to look at some examples:\r\n\r\nhttps://github.com/coleifer/peewee/blob/master/tests/models.py#L419"
] | 2022-10-31T15:40:33 | 2022-11-01T12:08:35 | 2022-10-31T15:59:30 | NONE | null | Bug: insert_many execute in PostgreSQL returns cursor instead of int row count. In SQLite it returns the int number of rows inserted while in PostgreSQL it returns a cursor.
[In the documentation it states that `insert_many(...).execute()` returns the number of inserted rows.](https://docs.peewee-orm.com/en/latest/peewee/api.html?highlight=insert_many#Model.insert_many) | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2642/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2642/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2641 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2641/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2641/comments | https://api.github.com/repos/coleifer/peewee/issues/2641/events | https://github.com/coleifer/peewee/issues/2641 | 1,429,964,464 | I_kwDOAA7yGM5VO4aw | 2,641 | API for removing all models Or getting all models | {
"login": "dyadav7",
"id": 8121360,
"node_id": "MDQ6VXNlcjgxMjEzNjA=",
"avatar_url": "https://avatars.githubusercontent.com/u/8121360?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/dyadav7",
"html_url": "https://github.com/dyadav7",
"followers_url": "https://api.github.com/users/dyadav7/followers",
"following_url": "https://api.github.com/users/dyadav7/following{/other_user}",
"gists_url": "https://api.github.com/users/dyadav7/gists{/gist_id}",
"starred_url": "https://api.github.com/users/dyadav7/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/dyadav7/subscriptions",
"organizations_url": "https://api.github.com/users/dyadav7/orgs",
"repos_url": "https://api.github.com/users/dyadav7/repos",
"events_url": "https://api.github.com/users/dyadav7/events{/privacy}",
"received_events_url": "https://api.github.com/users/dyadav7/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"http://docs.peewee-orm.com/en/latest/peewee/api.html#SubclassAwareMetadata\r\n\r\n```python\r\nfrom peewee import SubclassAwareMetadata\r\n\r\ndb = SqliteDatabase(':memory:')\r\n\r\nclass Base(Model):\r\n class Meta:\r\n database = db\r\n model_metadata_class = SubclassAwareMetadata \r\n\r\nclass P1(Base): pass\r\nclass P2(Base): pass\r\nclass C1_1(P1): pass\r\nclass C1_2(P2): pass\r\n\r\nBase._meta.map_models(print)\r\n\r\n# Or for you case:\r\naccum = []\r\nBase._meta.map_models(accum.append)\r\nprint(accum)\r\n# [<Model: Base>, <Model: P1>, <Model: P2>, <Model: C1_1>, <Model: C1_2>] \r\n```",
"I have removed some Model names form the file. I want to remove all tables names from the db (Includes tables for the Model definition that exist previously).\r\n\r\nThere is an API to get all table names ( db.get_tables() ).\r\nIt return lower case names for Models (e.g. \"versiondb\" for VersionDB Model).\r\nThere should be a way to delete the table names returned by `get_tables()`.\r\n\r\ndb.remove_tables() API should be there :\r\n``` \r\n all_tables = db.get_tables() \r\n db.remove__tables(all_tables)\r\n```",
"@dyadav7 - yes but that does not take into consideration any relationships/dependencies so you'll have to `DROP...CASCADE` all of those presumably. You can just write a loop or your own helper function if you literally want to delete every single table unconditionally:\r\n\r\n```python\r\nfor table_name in db.get_tables():\r\n db.execute_sql('drop table if exists \"%s\" cascade' % table_name)\r\n```\r\n\r\nOr drop and re-create your database itself."
] | 2022-10-31T14:42:51 | 2022-11-01T12:39:00 | 2022-10-31T14:52:26 | NONE | null | I want to remove all the models (i.e. remove all tables) without listing all the Model names.
Is there a way to do it ?
OR
I can get all model names using some API and call "drop_tables(models)" also.
Is there an API to get the list of models ?
e.g.
```
db.remove all models()
OR
db.remove all tables()
OR
models = db.get_models()
db.drop_tables(models)
``` | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2641/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2641/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2640 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2640/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2640/comments | https://api.github.com/repos/coleifer/peewee/issues/2640/events | https://github.com/coleifer/peewee/issues/2640 | 1,425,622,126 | I_kwDOAA7yGM5U-URu | 2,640 | Setting just <fieldtype>(default=None) does not work - but should | {
"login": "MrBillium",
"id": 14281367,
"node_id": "MDQ6VXNlcjE0MjgxMzY3",
"avatar_url": "https://avatars.githubusercontent.com/u/14281367?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/MrBillium",
"html_url": "https://github.com/MrBillium",
"followers_url": "https://api.github.com/users/MrBillium/followers",
"following_url": "https://api.github.com/users/MrBillium/following{/other_user}",
"gists_url": "https://api.github.com/users/MrBillium/gists{/gist_id}",
"starred_url": "https://api.github.com/users/MrBillium/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/MrBillium/subscriptions",
"organizations_url": "https://api.github.com/users/MrBillium/orgs",
"repos_url": "https://api.github.com/users/MrBillium/repos",
"events_url": "https://api.github.com/users/MrBillium/events{/privacy}",
"received_events_url": "https://api.github.com/users/MrBillium/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Disagree, fields are not-null by default, and there is no \"sentinel\" value for `default` -- in other words, the default is (by default) None.\r\n\r\nAll you really need to specify is:\r\n\r\n`last_logged_on = DateTimeField(null=True)`\r\n\r\n"
] | 2022-10-27T13:16:36 | 2022-10-27T16:37:49 | 2022-10-27T16:37:33 | NONE | null | New user here and just ran into this one which surprised me.
Setting a Field default to None does not work by itself when creating a Model row because there is an implicit null=False.
```
class User(BaseModel):
name = TextField()
# last_logged_on = DateTimeField(default=None) # This will not work when created using default ( i.e. it was omitted)!
last_logged_on = DateTimeField(null=True, default=None) # this will work
```
I was taught that Explicit should ALWAYS override Implicit so I would expect my Field argument (command) to set a field to None to cause Peewee to do everything necessary to make that happen without another argument.
Requiring both is counterintuitive. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2640/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2640/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2639 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2639/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2639/comments | https://api.github.com/repos/coleifer/peewee/issues/2639/events | https://github.com/coleifer/peewee/issues/2639 | 1,422,124,248 | I_kwDOAA7yGM5Uw-TY | 2,639 | enhancement for doing get/update/create at the same time | {
"login": "James4Ever0",
"id": 103997068,
"node_id": "U_kgDOBjLejA",
"avatar_url": "https://avatars.githubusercontent.com/u/103997068?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/James4Ever0",
"html_url": "https://github.com/James4Ever0",
"followers_url": "https://api.github.com/users/James4Ever0/followers",
"following_url": "https://api.github.com/users/James4Ever0/following{/other_user}",
"gists_url": "https://api.github.com/users/James4Ever0/gists{/gist_id}",
"starred_url": "https://api.github.com/users/James4Ever0/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/James4Ever0/subscriptions",
"organizations_url": "https://api.github.com/users/James4Ever0/orgs",
"repos_url": "https://api.github.com/users/James4Ever0/repos",
"events_url": "https://api.github.com/users/James4Ever0/events{/privacy}",
"received_events_url": "https://api.github.com/users/James4Ever0/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Pass",
"[similar commit](https://github.com/coleifer/peewee/commit/073364ad89a8de48f4a25bbf6106bf42050d34fa)"
] | 2022-10-25T09:06:45 | 2022-11-10T11:22:25 | 2022-10-25T12:52:13 | NONE | null | here's the following code. it's been tested on some schema with one single unique key.
```python
# peewee.py:7119
@classmethod
def get_and_update_or_create(cls, _unique_keys:list=[],**kwargs):
try:
obj, flag = cls.get_or_create(
**kwargs
) # will it update this thing? let's see.
except:
flag = False
if not flag:
fieldNames = [
name for name, x in cls.__dict__.items() if type(x) == FieldAccessor
]
uniqueKeyNames = _unique_keys
for name in fieldNames:
field = cls.__dict__[name].field
if field.unique:
uniqueKeyNames.append(name)
if field.primary_key:
primaryKeyName = name
# use or/and? better use and.
uniq_or_primary_key_names_shared_with_kwargs_keys = [
name
for name in set([primaryKeyName] + uniqueKeyNames)
if name in kwargs.keys()
]
# print(dir(cls))
# print(uniqueKeyNames)
# print(uniq_or_primary_key_names_shared_with_kwargs_keys)
# breakpoint()
operand = None
for name in uniq_or_primary_key_names_shared_with_kwargs_keys:
val = cls.__dict__[name].field == kwargs[name]
if operand is None:
operand = val
else:
operand = operand & val
cls.update(**{key:value for key, value in kwargs.items() if key not in uniq_or_primary_key_names_shared_with_kwargs_keys}).where(
operand
).execute() # damn it.
# breakpoint() # what is the update result?
obj= cls.get_or_none(**kwargs) # none?
return obj, flag
``` | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2639/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2639/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2638 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2638/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2638/comments | https://api.github.com/repos/coleifer/peewee/issues/2638/events | https://github.com/coleifer/peewee/issues/2638 | 1,420,385,314 | I_kwDOAA7yGM5UqVwi | 2,638 | Noob question about accesing meta data | {
"login": "ionesculiviucristian",
"id": 7398490,
"node_id": "MDQ6VXNlcjczOTg0OTA=",
"avatar_url": "https://avatars.githubusercontent.com/u/7398490?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/ionesculiviucristian",
"html_url": "https://github.com/ionesculiviucristian",
"followers_url": "https://api.github.com/users/ionesculiviucristian/followers",
"following_url": "https://api.github.com/users/ionesculiviucristian/following{/other_user}",
"gists_url": "https://api.github.com/users/ionesculiviucristian/gists{/gist_id}",
"starred_url": "https://api.github.com/users/ionesculiviucristian/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/ionesculiviucristian/subscriptions",
"organizations_url": "https://api.github.com/users/ionesculiviucristian/orgs",
"repos_url": "https://api.github.com/users/ionesculiviucristian/repos",
"events_url": "https://api.github.com/users/ionesculiviucristian/events{/privacy}",
"received_events_url": "https://api.github.com/users/ionesculiviucristian/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"> you can modify the source code just like me\r\n\r\nThanks for the response but I have no idea what you are referring to. What source code is that? Worst case I'm gonna add the same ```table_name``` on the parent class which is definitely not the way to do it.",
"The table name is accessible via:\r\n\r\n```\r\nModelClass._meta.table_name\r\n```\r\n\r\nThe full list of available meta options is here: http://docs.peewee-orm.com/en/latest/peewee/models.html#model-options-and-table-metadata\r\n\r\nThe `._meta` is a holdover from Django and is kinda a namespace for metadata of the model class itself. It can be considered part of the public interface.\r\n\r\nNote: I've removed a couple comments that were unhelpful or missed the point."
] | 2022-10-24T07:57:08 | 2022-10-24T13:25:25 | 2022-10-24T13:23:52 | NONE | null | Hi. I have the following class:
```py
class Migration(BaseModel):
name = CharField(null=True, unique=True)
class Meta:
table_name = "migrations"
```
How can I access the table name without using it like this:
```py
Migration._meta.table.__name__
```
Need something more "public" kinda way. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2638/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2638/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2637 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2637/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2637/comments | https://api.github.com/repos/coleifer/peewee/issues/2637/events | https://github.com/coleifer/peewee/issues/2637 | 1,419,758,189 | I_kwDOAA7yGM5Un8pt | 2,637 | enhancement to simplify the BaseModel boilerplate code | {
"login": "James4Ever0",
"id": 103997068,
"node_id": "U_kgDOBjLejA",
"avatar_url": "https://avatars.githubusercontent.com/u/103997068?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/James4Ever0",
"html_url": "https://github.com/James4Ever0",
"followers_url": "https://api.github.com/users/James4Ever0/followers",
"following_url": "https://api.github.com/users/James4Ever0/following{/other_user}",
"gists_url": "https://api.github.com/users/James4Ever0/gists{/gist_id}",
"starred_url": "https://api.github.com/users/James4Ever0/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/James4Ever0/subscriptions",
"organizations_url": "https://api.github.com/users/James4Ever0/orgs",
"repos_url": "https://api.github.com/users/James4Ever0/repos",
"events_url": "https://api.github.com/users/James4Ever0/events{/privacy}",
"received_events_url": "https://api.github.com/users/James4Ever0/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"ps: i've seen this pattern from [sqla-wrapper](https://sqla-wrapper.scaletti.dev/sqlalchemy-wrapper/). this library might be helpful as well.",
"another enhancement:\r\n\r\n```python\r\n# /usr/local/lib/python3.9/dist-packages/peewee.py:3420\r\n\r\n# def create_tables(self, models, bind=True,**options):\r\n# for model in sort_models(models):\r\n# if bind:\r\n# model.bind(self)\r\n# model.create_table(**options)\r\nclass User2(Model):\r\n username = CharField(unique=True)\r\n\r\ndb.create_tables([User2])\r\n\r\n```",
"I'm going to pass on the `create_tables()` but have merged the `Model` property helper."
] | 2022-10-23T11:10:13 | 2022-10-24T13:36:34 | 2022-10-24T13:36:34 | NONE | null | i wrote some code for simplification:
```python
from peewee import *
# some patch on /usr/local/lib/python3.9/dist-packages/peewee.py:3142
# @property
# def Model(self): # this is interesting. does it work as expected?
# class BaseModel(Model):
# class Meta:
# database = self
# return BaseModel
db = SqliteDatabase('my_database.db')
class User(db.Model):
username = CharField(unique=True)
``` | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2637/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2637/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2636 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2636/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2636/comments | https://api.github.com/repos/coleifer/peewee/issues/2636/events | https://github.com/coleifer/peewee/issues/2636 | 1,418,844,633 | I_kwDOAA7yGM5UkdnZ | 2,636 | datetime compare not working correctly with single digit | {
"login": "marcelkb",
"id": 60894942,
"node_id": "MDQ6VXNlcjYwODk0OTQy",
"avatar_url": "https://avatars.githubusercontent.com/u/60894942?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/marcelkb",
"html_url": "https://github.com/marcelkb",
"followers_url": "https://api.github.com/users/marcelkb/followers",
"following_url": "https://api.github.com/users/marcelkb/following{/other_user}",
"gists_url": "https://api.github.com/users/marcelkb/gists{/gist_id}",
"starred_url": "https://api.github.com/users/marcelkb/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/marcelkb/subscriptions",
"organizations_url": "https://api.github.com/users/marcelkb/orgs",
"repos_url": "https://api.github.com/users/marcelkb/repos",
"events_url": "https://api.github.com/users/marcelkb/events{/privacy}",
"received_events_url": "https://api.github.com/users/marcelkb/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"seems to be a problem of missing data ;)",
"I hope it turns up! Sometimes when I lose something, I throw something similar away and watch where it goes."
] | 2022-10-21T20:47:07 | 2022-10-21T21:04:08 | 2022-10-21T20:52:38 | NONE | null | MariaDBConnectorDatabase:
DateTimeField:
PriceArchive.select().where(PriceArchive.time <= datetime.datetime(2022, 10, 10, 00, 00)).order_by(
PriceArchive.time.desc()).limit(1).get() works correctly
with datetime.datetime(2022, 10, 1, 00, 00) it gives first entry in Database, in my case something from August.
Concrete every day above 9 works, only single digits dates not
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2636/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2636/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2635 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2635/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2635/comments | https://api.github.com/repos/coleifer/peewee/issues/2635/events | https://github.com/coleifer/peewee/issues/2635 | 1,417,379,884 | I_kwDOAA7yGM5Ue4As | 2,635 | Alter column query has wrong syntax | {
"login": "martinzarza",
"id": 54747048,
"node_id": "MDQ6VXNlcjU0NzQ3MDQ4",
"avatar_url": "https://avatars.githubusercontent.com/u/54747048?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/martinzarza",
"html_url": "https://github.com/martinzarza",
"followers_url": "https://api.github.com/users/martinzarza/followers",
"following_url": "https://api.github.com/users/martinzarza/following{/other_user}",
"gists_url": "https://api.github.com/users/martinzarza/gists{/gist_id}",
"starred_url": "https://api.github.com/users/martinzarza/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/martinzarza/subscriptions",
"organizations_url": "https://api.github.com/users/martinzarza/orgs",
"repos_url": "https://api.github.com/users/martinzarza/repos",
"events_url": "https://api.github.com/users/martinzarza/events{/privacy}",
"received_events_url": "https://api.github.com/users/martinzarza/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"`change_fields` is not part of the peewee migration API. Not sure what library you're using but I suggest taking the issue up there.",
"For what it's worth, the playhouse migrate seems working well (it is not necessary or desirable to include the `primary_key=True` when converting field type - this is preserved):\r\n\r\n```python\r\nfrom playhouse.migrate import *\r\nmigrator = SchemaMigrator.from_database(db)\r\n\r\nmigrate(\r\n migrator.alter_column_type('users', 'user_id', BigIntegerField())\r\n)\r\nprint(db.get_columns('users'))\r\n```\r\n\r\nPrints:\r\n\r\n```\r\n[ColumnMetadata(\r\n name='user_id', \r\n data_type='bigint', \r\n null=False, \r\n primary_key=True, \r\n table='users', \r\n default=\"nextval('users_user_id_seq'::regclass)\"),\r\n ...\r\n]\r\n```\r\n\r\nSQL emitted:\r\n\r\n```sql\r\nALTER TABLE \"users\" ALTER COLUMN \"user_id\" TYPE BIGINT\r\n```"
] | 2022-10-20T22:15:25 | 2022-10-21T21:02:22 | 2022-10-20T23:32:16 | NONE | null | Hi everyone, I was running an update migration to alter a column type in PostgreSQL, but the query execution fails due to a syntax error.
Here is the migration file:
```python
def migrate(migrator, database, fake=False, **kwargs):
"""Write your migrations here."""
migrator.change_fields('users', user_id=pw.BigIntegerField(primary_key=True))
def rollback(migrator, database, fake=False, **kwargs):
"""Write your rollback migrations here."""
migrator.change_fields('users', user_id=pw.IntegerField(primary_key=True))
```
And this is the error message showing the query:
```
Creating migration "migration"
Migration has been created as "002_migration"
Starting migrations
Migrate "002_migration"
change_column ('users', 'user_id', <BigIntegerField: Users.user_id>)
Migration failed: 002_migration
Traceback (most recent call last):
File "/Users/martin-zarza/Documents/My Projects/sendit-telegram-bot/venv/lib/python3.9/site-packages/peewee.py", line 3221, in execute_sql
cursor.execute(sql, params or ())
psycopg2.errors.SyntaxError: syntax error at or near "BIGINT"
LINE 1: ALTER TABLE "users" ALTER COLUMN "user_id" BIGINT TYPE PRIMA...
^
```
I believe there has to be a *SET* before the *BIGINT...* | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2635/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2635/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2634 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2634/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2634/comments | https://api.github.com/repos/coleifer/peewee/issues/2634/events | https://github.com/coleifer/peewee/pull/2634 | 1,414,810,440 | PR_kwDOAA7yGM5BGaGi | 2,634 | udpate fastapi example | {
"login": "verigle",
"id": 32769358,
"node_id": "MDQ6VXNlcjMyNzY5MzU4",
"avatar_url": "https://avatars.githubusercontent.com/u/32769358?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/verigle",
"html_url": "https://github.com/verigle",
"followers_url": "https://api.github.com/users/verigle/followers",
"following_url": "https://api.github.com/users/verigle/following{/other_user}",
"gists_url": "https://api.github.com/users/verigle/gists{/gist_id}",
"starred_url": "https://api.github.com/users/verigle/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/verigle/subscriptions",
"organizations_url": "https://api.github.com/users/verigle/orgs",
"repos_url": "https://api.github.com/users/verigle/repos",
"events_url": "https://api.github.com/users/verigle/events{/privacy}",
"received_events_url": "https://api.github.com/users/verigle/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [] | 2022-10-19T11:38:28 | 2022-10-19T12:25:21 | 2022-10-19T12:25:21 | NONE | null | to fix wrong fastapi example
detail please reference : #2633 | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2634/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2634/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/2634",
"html_url": "https://github.com/coleifer/peewee/pull/2634",
"diff_url": "https://github.com/coleifer/peewee/pull/2634.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/2634.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/2633 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2633/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2633/comments | https://api.github.com/repos/coleifer/peewee/issues/2633/events | https://github.com/coleifer/peewee/issues/2633 | 1,414,778,786 | I_kwDOAA7yGM5UU8-i | 2,633 | fastapi example is wrong for db connect and close | {
"login": "verigle",
"id": 32769358,
"node_id": "MDQ6VXNlcjMyNzY5MzU4",
"avatar_url": "https://avatars.githubusercontent.com/u/32769358?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/verigle",
"html_url": "https://github.com/verigle",
"followers_url": "https://api.github.com/users/verigle/followers",
"following_url": "https://api.github.com/users/verigle/following{/other_user}",
"gists_url": "https://api.github.com/users/verigle/gists{/gist_id}",
"starred_url": "https://api.github.com/users/verigle/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/verigle/subscriptions",
"organizations_url": "https://api.github.com/users/verigle/orgs",
"repos_url": "https://api.github.com/users/verigle/repos",
"events_url": "https://api.github.com/users/verigle/events{/privacy}",
"received_events_url": "https://api.github.com/users/verigle/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
">So those code can not set db connect before request processing and set db close for request processing over.\r\n\r\nPeewee is connection-per-thread. FastAPI does not have such a concept -- rather it has an async context that may be interrupted at any time to switch to another request *within the same thread*. Therefore it's probably better to connect at startup. It's because of subtleties like this, along with the cargo-cult around asyncio, that I advise you to tread carefully."
] | 2022-10-19T11:15:10 | 2022-10-19T12:24:48 | 2022-10-19T12:24:47 | NONE | null | there has wrong example for db connect and close
http://docs.peewee-orm.com/en/latest/peewee/database.html#fastapi
```python
from fastapi import FastAPI
from peewee import *
db = SqliteDatabase('my_app.db')
app = FastAPI()
# This hook ensures that a connection is opened to handle any queries
# generated by the request.
@app.on_event("startup")
def startup():
db.connect()
# This hook ensures that the connection is closed when we've finished
# processing the request.
@app.on_event("shutdown")
def shutdown():
if not db.is_closed():
db.close()
```
however `@app.on_event("startup")` is for application not for request, and `@app.on_event("shutdown")` also for application stop not for request. So those code can not set db connect before request processing and set db close for request processing over.
please reference fastapi document confirm this problem : https://fastapi.tiangolo.com/advanced/events/
peewee document can be reference [this ]( https://fastapi.tiangolo.com/advanced/sql-databases-peewee/#main-fastapi-app
)and then update fastapi example :
```python
from fastapi import FastAPI
from peewee import *
import time
from typing import List
from fastapi import Depends, FastAPI, HTTPException
app = FastAPI()
sleep_time = 10
db = SqliteDatabase('my_app.db')
app = FastAPI()
def get_db():
try:
db.connect()
yield
finally:
if not db.is_closed():
db.close()
@app.post("/users/", dependencies=[Depends(get_db)])
def create_user(user):
pass
``` | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2633/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2633/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2632 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2632/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2632/comments | https://api.github.com/repos/coleifer/peewee/issues/2632/events | https://github.com/coleifer/peewee/pull/2632 | 1,413,066,120 | PR_kwDOAA7yGM5BAh0m | 2,632 | Support IN and INNER JOIN subqueries on prefetch | {
"login": "nomme",
"id": 216670,
"node_id": "MDQ6VXNlcjIxNjY3MA==",
"avatar_url": "https://avatars.githubusercontent.com/u/216670?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/nomme",
"html_url": "https://github.com/nomme",
"followers_url": "https://api.github.com/users/nomme/followers",
"following_url": "https://api.github.com/users/nomme/following{/other_user}",
"gists_url": "https://api.github.com/users/nomme/gists{/gist_id}",
"starred_url": "https://api.github.com/users/nomme/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/nomme/subscriptions",
"organizations_url": "https://api.github.com/users/nomme/orgs",
"repos_url": "https://api.github.com/users/nomme/repos",
"events_url": "https://api.github.com/users/nomme/events{/privacy}",
"received_events_url": "https://api.github.com/users/nomme/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Nice patch, thank you. I've rebased your commits into a single commit af3f34f10555a22003726dca90fb2d577617656a and amended it to respect the line-length limit, but otherwise your changes are all merged."
] | 2022-10-18T11:39:59 | 2022-10-19T12:45:03 | 2022-10-19T12:45:02 | CONTRIBUTOR | null | This PR intends to solve #2631
It adds a parameter to `prefetch` that allows the user to choose the type of subquery performed. Using `INNER JOIN` is desirable when combining `LIMIT` with MySQL as the current implementation is not compatible.
Usage example
```python
from peewee import PREFETCH_TYPE
people = Person.select().order_by(Person.name)
query = people.prefetch(Note, NoteItem, prefetch_type=PREFETCH_TYPE.JOIN)
```
The current behavior should remain the same as `prefetch_type` default to using the current implementation. I suggest whitespace changes are ignored when diffing `prefetch_tests.py`.
It goes without saying, but any feedback is welcome. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2632/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2632/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/2632",
"html_url": "https://github.com/coleifer/peewee/pull/2632",
"diff_url": "https://github.com/coleifer/peewee/pull/2632.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/2632.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/2631 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2631/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2631/comments | https://api.github.com/repos/coleifer/peewee/issues/2631/events | https://github.com/coleifer/peewee/issues/2631 | 1,413,056,572 | I_kwDOAA7yGM5UOYg8 | 2,631 | Support LIMIT with prefetch and MySQL | {
"login": "nomme",
"id": 216670,
"node_id": "MDQ6VXNlcjIxNjY3MA==",
"avatar_url": "https://avatars.githubusercontent.com/u/216670?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/nomme",
"html_url": "https://github.com/nomme",
"followers_url": "https://api.github.com/users/nomme/followers",
"following_url": "https://api.github.com/users/nomme/following{/other_user}",
"gists_url": "https://api.github.com/users/nomme/gists{/gist_id}",
"starred_url": "https://api.github.com/users/nomme/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/nomme/subscriptions",
"organizations_url": "https://api.github.com/users/nomme/orgs",
"repos_url": "https://api.github.com/users/nomme/repos",
"events_url": "https://api.github.com/users/nomme/events{/privacy}",
"received_events_url": "https://api.github.com/users/nomme/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Merged your PR here: af3f34f10555a22003726dca90fb2d577617656a",
"Awesome, thank you!"
] | 2022-10-18T11:33:15 | 2022-10-19T14:01:40 | 2022-10-19T12:46:13 | CONTRIBUTOR | null | Hi
The premise is simple. It would be pretty sweet if peewee's `prefetch` supports `LIMIT` when using MySQL. I want to add support for it by introducing a switch on `prefetch` that subqueries using `INNER JOIN` instead of `IN`.
Background:
In a project using peewee and MySQL we often encounter the following limitation when using `prefetch`.
```
This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'
```
This can be seen reported multiple times across the internet, which you also address all those times. [There are ways around it](https://github.com/coleifer/peewee/pull/381#issuecomment-47823210) but native support would feel much better, and would also require one less query and avoid giant `IN` lists with large limit values.
I'll submit a PR in a moment to show what I have in mind. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2631/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2631/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2630 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2630/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2630/comments | https://api.github.com/repos/coleifer/peewee/issues/2630/events | https://github.com/coleifer/peewee/issues/2630 | 1,412,990,339 | I_kwDOAA7yGM5UOIWD | 2,630 | Unable to install peewee on py 3.10 on windows - ERROR: No .egg-info directory found in C:\Users\*User*\AppData\Local\Temp\pip-pip-egg-info-fhrb40k6 | {
"login": "jurezic",
"id": 71229581,
"node_id": "MDQ6VXNlcjcxMjI5NTgx",
"avatar_url": "https://avatars.githubusercontent.com/u/71229581?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/jurezic",
"html_url": "https://github.com/jurezic",
"followers_url": "https://api.github.com/users/jurezic/followers",
"following_url": "https://api.github.com/users/jurezic/following{/other_user}",
"gists_url": "https://api.github.com/users/jurezic/gists{/gist_id}",
"starred_url": "https://api.github.com/users/jurezic/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/jurezic/subscriptions",
"organizations_url": "https://api.github.com/users/jurezic/orgs",
"repos_url": "https://api.github.com/users/jurezic/repos",
"events_url": "https://api.github.com/users/jurezic/events{/privacy}",
"received_events_url": "https://api.github.com/users/jurezic/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Can you try doing:\r\n\r\n```\r\ngit clone https://github.com/coleifer/peewee\r\ncd peewee\r\npython setup.py egg_info\r\n```\r\n\r\nAnd share the output?",
"Sorry, forgot to mention, I have also downloaded peewee-3.15.3.tar.gz and tried\r\n- py -3.10 -m pip install helpers/peewee-3.15.3.tar.gz\r\n- poetry add helpers/peewee-3.15.3.tar.gz\r\n\r\nAnd again receive -\r\nERROR: No .egg-info directory found in C:\\Users\\*user*\\AppData\\Local\\Temp\\pip-pip-egg-info-8qd21w02\r\n",
"Can you please try the commands in my comment, and paste the output here?",
"This is the output of commands from your comment - \r\n\r\n```\r\n'cl.exe' is not recognized as an internal or external command,\r\noperable program or batch file.\r\nunable to compile sqlite3 C extensions - missing headers?\r\nC:\\Users\\**\\Documents\\Projects\\**\\**\\helpers\\peewee\\setup.py:110: UserWarning: Could not find libsqlite3, SQLite extensions will not be built.\r\n warnings.warn('Could not find libsqlite3, SQLite extensions will not '\r\nrunning egg_info\r\ncreating peewee.egg-info\r\nwriting peewee.egg-info\\PKG-INFO\r\nwriting dependency_links to peewee.egg-info\\dependency_links.txt\r\nwriting top-level names to peewee.egg-info\\top_level.txt\r\nwriting manifest file 'peewee.egg-info\\SOURCES.txt'\r\nreading manifest file 'peewee.egg-info\\SOURCES.txt'\r\nreading manifest template 'MANIFEST.in'\r\nwarning: no files found matching 'tests.py'\r\nwarning: no files found matching 'playhouse\\*.c'\r\nwarning: no files found matching 'playhouse\\pskel'\r\nwarning: no files found matching 'playhouse\\tests\\README'\r\nadding license file 'LICENSE'\r\nwriting manifest file 'peewee.egg-info\\SOURCES.txt'\r\n```",
"Looks like you don't have a C compiler installed (it is not a hard requirement for peewee, but we check), although I'm unsure why `pip` is complaining because the egg-info is successfully written. Anyways, I suggest either:\r\n\r\n1. install a c compiler\r\n2. in the `peewee` directory created earlier, just run `python setup.py install` and skip `pip` altogether."
] | 2022-10-18T10:42:35 | 2022-10-18T12:49:34 | 2022-10-18T12:49:10 | NONE | null | Always getting the same error, except everytime I get another tag in the end of the trace.
Setup-
Python 3.10.
setuptools-65.5.0
pip-22.3
poetry-
1.1.13.
What I have tried:
Update python/pip/setuptools
Install over poetry - same error
Does anyone have an idea how to proceed? | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2630/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2630/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2629 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2629/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2629/comments | https://api.github.com/repos/coleifer/peewee/issues/2629/events | https://github.com/coleifer/peewee/issues/2629 | 1,410,578,986 | I_kwDOAA7yGM5UE7oq | 2,629 | How to query nodes without children with closure table extension | {
"login": "trifle",
"id": 450916,
"node_id": "MDQ6VXNlcjQ1MDkxNg==",
"avatar_url": "https://avatars.githubusercontent.com/u/450916?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/trifle",
"html_url": "https://github.com/trifle",
"followers_url": "https://api.github.com/users/trifle/followers",
"following_url": "https://api.github.com/users/trifle/following{/other_user}",
"gists_url": "https://api.github.com/users/trifle/gists{/gist_id}",
"starred_url": "https://api.github.com/users/trifle/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/trifle/subscriptions",
"organizations_url": "https://api.github.com/users/trifle/orgs",
"repos_url": "https://api.github.com/users/trifle/repos",
"events_url": "https://api.github.com/users/trifle/events{/privacy}",
"received_events_url": "https://api.github.com/users/trifle/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"~~You don't even need the closure for this, you can find all categories with zero children:~~\r\n\r\nSorry, I see you already have a formulation for this:\r\n\r\n```python\r\nCA = Category.alias()\r\n(CA\r\n .select()\r\n .join(\r\n Category,\r\n on=(CA.id == Category.parent_id),\r\n join_type=JOIN.LEFT_OUTER)\r\n .where(Category.id >> None))\r\n```\r\n\r\nAnother:\r\n\r\n```python\r\nCA = Category.alias()\r\nq = (Category\r\n .select()\r\n .join(CA, JOIN.LEFT_OUTER, on=(CA.parent == Category.id))\r\n .group_by(Category)\r\n .having(fn.COUNT(CA.id) == 0))\r\n```\r\n\r\nOr use a subquery:\r\n\r\n```python\r\nCA = Category.alias()\r\nq = (Category\r\n .select()\r\n .where(~fn.EXISTS(\r\n CA.select().where(CA.parent == Category.id))))\r\n```\r\n\r\nTo use the closure extension is not necessary here. But if you want to, you can modify the above types of queries to query the closure table to ensure there are no descendants:\r\n\r\n```python\r\nq = (Category\r\n .select()\r\n .join(CategoryClosure, JOIN.LEFT_OUTER, on=(\r\n (CategoryClosure.root == Category.id) &\r\n (CategoryClosure.depth > 0)))\r\n .where(CategoryClosure.id.is_null()))\r\n```\r\n\r\nOr use a subquery:\r\n\r\n```python\r\nsubq = (CategoryClosure\r\n .select(SQL('1'))\r\n .where((CategoryClosure.root == Category.id) &\r\n (CategoryClosure.depth > 0)))\r\nq = (Category\r\n .select()\r\n .where(~fn.EXISTS(subq)))\r\n```",
"Apologies for not reading your comment more closely originally, I've edited my answer to include closure-table specific implementations of the query.",
"Thanks Charles, I didn't know about the `root` field!\r\nThat was exactly what I was looking for. And the alternative versions of the self-join query are also a useful refresher.\r\n\r\nJust to add, it's almost surreal how much work you put into answering questions and issues here. Thanks for caring!"
] | 2022-10-16T18:36:20 | 2022-10-17T16:32:19 | 2022-10-17T13:13:20 | NONE | null | Hi, thanks for making peewee!
This issue is a somewhat exotic question, so feel free to close if it doesn't fit in here.
I'm trying to model a DAG in peewee where children are created to contain the result of some processing of parents.
Let's take the example of video files: The root may be a raw video file, whose encoded versions are children, and each of those may have a thumbnail attached as lvl 2 children (grandchildren of the raw footage).
To find missing entries, I need to query for some nodes of arbitrary position (i.e.: raw footage at level 0, or encoded files at level 1 etc.) that have not yet had any children attached.
The documentation and [blog post](https://charlesleifer.com/blog/querying-tree-structures-in-sqlite-using-python-and-the-transitive-closure-extension/) nicely describe how to set up a closure table with the playhouse and sqlite extension.
One thing that isn't clear to me at all is how to query for nodes **without children**.
I'll use the example models for categories given in the docs:
```python
class Category(Model):
name = CharField()
parent = ForeignKeyField('self', null=True, backref='children')
```
With a normal self-join, I'd use an `outer join` like this:
```sql
select * FROM category AS cat
LEFT OUTER JOIN category ON (cat.id = category.parent_id)
WHERE category.id IS NULL;
```
Which translates to peewee as:
```python
cat = Category.alias()
(cat
.select()
.join(
Category,
on=(cat.id == Category.parent_id),
join_type=JOIN.LEFT_OUTER)
.where(Category.id >> None)
)
```
It would be nice to be able to use the tree-specific queries afforded by the closure table to do the same.
What I imagine the closure table syntax to look like is roughly:
```python
(Category
.select()
.join(
CategoryClosure,
on=(Category.id == CategoryClosure.id),
join_type=JOIN.LEFT_OUTER)
.where(Category.id >> None)
)
```
But that doesn't yield any results (and using .where(CategoryClosure.id >> None) yields all records).
Please excuse if I'm on the entirely wrong track here, as I'm not usually writing SQL. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2629/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2629/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2628 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2628/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2628/comments | https://api.github.com/repos/coleifer/peewee/issues/2628/events | https://github.com/coleifer/peewee/issues/2628 | 1,405,670,351 | I_kwDOAA7yGM5TyNPP | 2,628 | With db.atomic decorator, ReconnectMixin does not automatically reconnect | {
"login": "breezechen",
"id": 2368879,
"node_id": "MDQ6VXNlcjIzNjg4Nzk=",
"avatar_url": "https://avatars.githubusercontent.com/u/2368879?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/breezechen",
"html_url": "https://github.com/breezechen",
"followers_url": "https://api.github.com/users/breezechen/followers",
"following_url": "https://api.github.com/users/breezechen/following{/other_user}",
"gists_url": "https://api.github.com/users/breezechen/gists{/gist_id}",
"starred_url": "https://api.github.com/users/breezechen/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/breezechen/subscriptions",
"organizations_url": "https://api.github.com/users/breezechen/orgs",
"repos_url": "https://api.github.com/users/breezechen/repos",
"events_url": "https://api.github.com/users/breezechen/events{/privacy}",
"received_events_url": "https://api.github.com/users/breezechen/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"The behavior of peewee could certainly be better here, but what is the correct thing to do if a connection dies midway through a transaction? Important changes would be lost with no indication given to the caller. I've added a patch that will instead raise the exception without reconnecting if Peewee is in a transaction, that way the caller can handle the situation appropriately.",
"Got it, thanks."
] | 2022-10-12T06:53:19 | 2022-10-13T03:19:38 | 2022-10-12T13:33:01 | NONE | null | Steps to reproduce the issue:
1. change mysql `wait_timeout` and `interactive_timeout` to 5.
```
version: '3.1'
services:
db:
image: mysql
restart: always
environment:
- LANG=C.UTF-8
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=testapp
volumes:
- /etc/localtime:/etc/localtime:ro
ports:
- 3307:3306
command:
- "--default-authentication-plugin=mysql_native_password"
- "--character-set-server=utf8mb4"
- "--collation-server=utf8mb4_general_ci"
- "--explicit_defaults_for_timestamp=true"
- "--lower_case_table_names=1"
- "--wait_timeout=5"
- "--interactive_timeout=5"
```
2. run the code
```
from time import sleep
from peewee import Model, TextField
from playhouse.pool import PooledMySQLDatabase
from playhouse.shortcuts import ReconnectMixin
class ReconnectMySQLDatabase(ReconnectMixin, PooledMySQLDatabase):
pass
db = ReconnectMySQLDatabase(
database="testapp",
host="127.0.0.1",
port=3307,
user="root",
password="root",
max_connections=2,
)
class Test(Model):
test = TextField()
class Meta:
database = db
@db.atomic()
def issue_func():
Test.create(test="test1")
Test.create(test="test2")
def main():
db.connect()
db.create_tables([Test])
while True:
sleep(5)
issue_func()
if __name__ == "__main__":
main()
```
3. wait 5 seconds, it will crash...
```
Traceback (most recent call last):
File "/home/breeze/projects/github/peewee-issue/venv/lib/python3.9/site-packages/peewee.py", line 3221, in execute_sql
cursor.execute(sql, params or ())
File "/home/breeze/projects/github/peewee-issue/venv/lib/python3.9/site-packages/pymysql/cursors.py", line 148, in execute
result = self._query(query)
File "/home/breeze/projects/github/peewee-issue/venv/lib/python3.9/site-packages/pymysql/cursors.py", line 310, in _query
conn.query(q)
File "/home/breeze/projects/github/peewee-issue/venv/lib/python3.9/site-packages/pymysql/connections.py", line 548, in query
self._affected_rows = self._read_query_result(unbuffered=unbuffered)
File "/home/breeze/projects/github/peewee-issue/venv/lib/python3.9/site-packages/pymysql/connections.py", line 775, in _read_query_result
result.read()
File "/home/breeze/projects/github/peewee-issue/venv/lib/python3.9/site-packages/pymysql/connections.py", line 1156, in read
first_packet = self.connection._read_packet()
File "/home/breeze/projects/github/peewee-issue/venv/lib/python3.9/site-packages/pymysql/connections.py", line 701, in _read_packet
raise err.OperationalError(
pymysql.err.OperationalError: (2013, 'Lost connection to MySQL server during query')
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/breeze/projects/github/peewee-issue/venv/lib/python3.9/site-packages/playhouse/shortcuts.py", line 250, in execute_sql
return super(ReconnectMixin, self).execute_sql(sql, params, commit)
File "/home/breeze/projects/github/peewee-issue/venv/lib/python3.9/site-packages/peewee.py", line 3228, in execute_sql
self.commit()
File "/home/breeze/projects/github/peewee-issue/venv/lib/python3.9/site-packages/peewee.py", line 2994, in __exit__
reraise(new_type, new_type(exc_value, *exc_args), traceback)
File "/home/breeze/projects/github/peewee-issue/venv/lib/python3.9/site-packages/peewee.py", line 191, in reraise
raise value.with_traceback(tb)
File "/home/breeze/projects/github/peewee-issue/venv/lib/python3.9/site-packages/peewee.py", line 3221, in execute_sql
cursor.execute(sql, params or ())
File "/home/breeze/projects/github/peewee-issue/venv/lib/python3.9/site-packages/pymysql/cursors.py", line 148, in execute
result = self._query(query)
File "/home/breeze/projects/github/peewee-issue/venv/lib/python3.9/site-packages/pymysql/cursors.py", line 310, in _query
conn.query(q)
File "/home/breeze/projects/github/peewee-issue/venv/lib/python3.9/site-packages/pymysql/connections.py", line 548, in query
self._affected_rows = self._read_query_result(unbuffered=unbuffered)
File "/home/breeze/projects/github/peewee-issue/venv/lib/python3.9/site-packages/pymysql/connections.py", line 775, in _read_query_result
result.read()
File "/home/breeze/projects/github/peewee-issue/venv/lib/python3.9/site-packages/pymysql/connections.py", line 1156, in read
first_packet = self.connection._read_packet()
File "/home/breeze/projects/github/peewee-issue/venv/lib/python3.9/site-packages/pymysql/connections.py", line 701, in _read_packet
raise err.OperationalError(
peewee.OperationalError: (2013, 'Lost connection to MySQL server during query')
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/breeze/projects/github/peewee-issue/venv/lib/python3.9/site-packages/peewee.py", line 412, in inner
return fn(*args, **kwargs)
File "/home/breeze/projects/github/peewee-issue/issue.py", line 31, in issue_func
Test.create(test="test1")
File "/home/breeze/projects/github/peewee-issue/venv/lib/python3.9/site-packages/peewee.py", line 6508, in create
inst.save(force_insert=True)
File "/home/breeze/projects/github/peewee-issue/venv/lib/python3.9/site-packages/peewee.py", line 6718, in save
pk = self.insert(**field_dict).execute()
File "/home/breeze/projects/github/peewee-issue/venv/lib/python3.9/site-packages/peewee.py", line 1946, in inner
return method(self, database, *args, **kwargs)
File "/home/breeze/projects/github/peewee-issue/venv/lib/python3.9/site-packages/peewee.py", line 2017, in execute
return self._execute(database)
File "/home/breeze/projects/github/peewee-issue/venv/lib/python3.9/site-packages/peewee.py", line 2822, in _execute
return super(Insert, self)._execute(database)
File "/home/breeze/projects/github/peewee-issue/venv/lib/python3.9/site-packages/peewee.py", line 2535, in _execute
cursor = database.execute(self)
File "/home/breeze/projects/github/peewee-issue/venv/lib/python3.9/site-packages/peewee.py", line 3234, in execute
return self.execute_sql(sql, params, commit=commit)
File "/home/breeze/projects/github/peewee-issue/venv/lib/python3.9/site-packages/playhouse/shortcuts.py", line 264, in execute_sql
self.close()
File "/home/breeze/projects/github/peewee-issue/venv/lib/python3.9/site-packages/peewee.py", line 3175, in close
raise OperationalError('Attempting to close database while '
peewee.OperationalError: Attempting to close database while transaction is open.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/breeze/projects/github/peewee-issue/venv/lib/python3.9/site-packages/peewee.py", line 3378, in rollback
return self._state.conn.rollback()
File "/home/breeze/projects/github/peewee-issue/venv/lib/python3.9/site-packages/pymysql/connections.py", line 479, in rollback
self._execute_command(COMMAND.COM_QUERY, "ROLLBACK")
File "/home/breeze/projects/github/peewee-issue/venv/lib/python3.9/site-packages/pymysql/connections.py", line 793, in _execute_command
raise err.InterfaceError(0, "")
pymysql.err.InterfaceError: (0, '')
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/breeze/projects/github/peewee-issue/issue.py", line 44, in <module>
main()
File "/home/breeze/projects/github/peewee-issue/issue.py", line 40, in main
issue_func()
File "/home/breeze/projects/github/peewee-issue/venv/lib/python3.9/site-packages/peewee.py", line 412, in inner
return fn(*args, **kwargs)
File "/home/breeze/projects/github/peewee-issue/venv/lib/python3.9/site-packages/peewee.py", line 4313, in __exit__
return self._helper.__exit__(exc_type, exc_val, exc_tb)
File "/home/breeze/projects/github/peewee-issue/venv/lib/python3.9/site-packages/peewee.py", line 4344, in __exit__
self.rollback(False)
File "/home/breeze/projects/github/peewee-issue/venv/lib/python3.9/site-packages/peewee.py", line 4331, in rollback
self.db.rollback()
File "/home/breeze/projects/github/peewee-issue/venv/lib/python3.9/site-packages/peewee.py", line 3378, in rollback
return self._state.conn.rollback()
File "/home/breeze/projects/github/peewee-issue/venv/lib/python3.9/site-packages/peewee.py", line 2994, in __exit__
reraise(new_type, new_type(exc_value, *exc_args), traceback)
File "/home/breeze/projects/github/peewee-issue/venv/lib/python3.9/site-packages/peewee.py", line 191, in reraise
raise value.with_traceback(tb)
File "/home/breeze/projects/github/peewee-issue/venv/lib/python3.9/site-packages/peewee.py", line 3378, in rollback
return self._state.conn.rollback()
File "/home/breeze/projects/github/peewee-issue/venv/lib/python3.9/site-packages/pymysql/connections.py", line 479, in rollback
self._execute_command(COMMAND.COM_QUERY, "ROLLBACK")
File "/home/breeze/projects/github/peewee-issue/venv/lib/python3.9/site-packages/pymysql/connections.py", line 793, in _execute_command
raise err.InterfaceError(0, "")
peewee.InterfaceError: (0, '')
```
| {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2628/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2628/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2627 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2627/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2627/comments | https://api.github.com/repos/coleifer/peewee/issues/2627/events | https://github.com/coleifer/peewee/pull/2627 | 1,403,737,387 | PR_kwDOAA7yGM5AhiB9 | 2,627 | Forward class creation keyword arguments | {
"login": "smac89",
"id": 8305511,
"node_id": "MDQ6VXNlcjgzMDU1MTE=",
"avatar_url": "https://avatars.githubusercontent.com/u/8305511?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/smac89",
"html_url": "https://github.com/smac89",
"followers_url": "https://api.github.com/users/smac89/followers",
"following_url": "https://api.github.com/users/smac89/following{/other_user}",
"gists_url": "https://api.github.com/users/smac89/gists{/gist_id}",
"starred_url": "https://api.github.com/users/smac89/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/smac89/subscriptions",
"organizations_url": "https://api.github.com/users/smac89/orgs",
"repos_url": "https://api.github.com/users/smac89/repos",
"events_url": "https://api.github.com/users/smac89/events{/privacy}",
"received_events_url": "https://api.github.com/users/smac89/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Sure, I've merged an equivalent patch w/just the 79 char line limit.",
"That was easy. Thanks!\r\n\r\nWhen do you think a new release will be available?",
"There's hardly any fixes, I think it may need a bit of time."
] | 2022-10-10T21:37:44 | 2022-10-11T00:52:02 | 2022-10-10T22:46:50 | NONE | null | https://docs.python.org/3/library/functions.html#type
I wanted to be able to create a template model which other models inherit from and modify, by passing keyword arguments in the class definition. However, the current implementation of `ModelBase` does not pass along those arguments which results in errors like
```
TypeError: ModelBase.__new__() got an unexpected keyword argument 'custom_arg'
```
---
Example code:
Base class
```py
class Foo(pw.Model):
foo_type: pw.CharField
@classmethod
def __init_subclass__(
cls, foo_type_default: str
) -> None:
cls.foo_type = pw.CharField(
choices=(
("bar", "Bar"),
("foobar", "Foobar"),
),
default=foo_type_default,
)
```
Subclass1
```py
class Bar(Foo, foo_type_default="bar"):
pass
```
Subclass2
```py
class FooBar(Foo, foo_type_default="foobar"):
pass
```
With the current implementation, the above doesn't work. This PR fixes that. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2627/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2627/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/2627",
"html_url": "https://github.com/coleifer/peewee/pull/2627",
"diff_url": "https://github.com/coleifer/peewee/pull/2627.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/2627.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/2626 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2626/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2626/comments | https://api.github.com/repos/coleifer/peewee/issues/2626/events | https://github.com/coleifer/peewee/issues/2626 | 1,399,287,530 | I_kwDOAA7yGM5TZ27q | 2,626 | Any way to change table naming logic? | {
"login": "Glucksistemi",
"id": 5073004,
"node_id": "MDQ6VXNlcjUwNzMwMDQ=",
"avatar_url": "https://avatars.githubusercontent.com/u/5073004?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/Glucksistemi",
"html_url": "https://github.com/Glucksistemi",
"followers_url": "https://api.github.com/users/Glucksistemi/followers",
"following_url": "https://api.github.com/users/Glucksistemi/following{/other_user}",
"gists_url": "https://api.github.com/users/Glucksistemi/gists{/gist_id}",
"starred_url": "https://api.github.com/users/Glucksistemi/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/Glucksistemi/subscriptions",
"organizations_url": "https://api.github.com/users/Glucksistemi/orgs",
"repos_url": "https://api.github.com/users/Glucksistemi/repos",
"events_url": "https://api.github.com/users/Glucksistemi/events{/privacy}",
"received_events_url": "https://api.github.com/users/Glucksistemi/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Yes, specify `legacy_table_names = False` in your base model Meta:\r\n\r\n```python\r\nfrom peewee import *\r\n\r\ndef table_name(cls):\r\n return cls.__name__\r\n\r\nclass Base(Model):\r\n class Meta:\r\n legacy_table_names = False\r\n\r\nclass RealModelWithLongName(Base):\r\n pass\r\n\r\nprint(RealModelWithLongName._meta.table_name)\r\n```\r\n\r\nPrints \"real_model_with_long_name\".\r\n\r\npeewee also supports a `Meta.table_function` option to provide your own implementation. For your example:\r\n\r\n```python\r\nfrom peewee import *\r\n\r\ndef table_name(cls):\r\n return cls.__name__\r\n\r\nclass Base(Model):\r\n class Meta:\r\n table_function = table_name\r\n\r\nclass RealModelWithLongName(Base):\r\n pass\r\n\r\nprint(RealModelWithLongName._meta.table_name)\r\n```\r\n\r\nPrints \"RealModelWithLongName\". Documented here: http://docs.peewee-orm.com/en/latest/peewee/models.html#table-names"
] | 2022-10-06T10:15:57 | 2022-10-06T12:48:30 | 2022-10-06T12:46:13 | NONE | null | By default, if I call my Model class using python conventional CamelCase with multiple words in its name (like `class ManyWordsNamedTable(peewee.Model)`) Peewee will just lowercase it, so I'll get table "manywordsnamedtable" created in my DB which is hardly readable. I know there's an option to use Meta.table_name parameter, but it applies individually so I should define names for every table by my hands. Is there any option to name all the tables in snake_case just changing base model Meta class and then inherit every table from this BaseModel?
I want it to be something like this:
```python
import peewee
class BaseModel(peewee.Model):
class Meta:
database = peewee.PostgresqlDatabase(...)
table_nameing_type = peewee.SNAKE_CASE_NAMING
class RealModelWithLongName(BaseModel)
some_field = peewee.IntegerField()
RealModelWithLongName.create_table()
```
And it would create table named real_model_with_long_name | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2626/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2626/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2625 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2625/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2625/comments | https://api.github.com/repos/coleifer/peewee/issues/2625/events | https://github.com/coleifer/peewee/issues/2625 | 1,393,493,599 | I_kwDOAA7yGM5TDwZf | 2,625 | Postgresql: Updating an existing field with adding/incrementing some value didn't work as expected | {
"login": "Sonotoki-da",
"id": 34913890,
"node_id": "MDQ6VXNlcjM0OTEzODkw",
"avatar_url": "https://avatars.githubusercontent.com/u/34913890?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/Sonotoki-da",
"html_url": "https://github.com/Sonotoki-da",
"followers_url": "https://api.github.com/users/Sonotoki-da/followers",
"following_url": "https://api.github.com/users/Sonotoki-da/following{/other_user}",
"gists_url": "https://api.github.com/users/Sonotoki-da/gists{/gist_id}",
"starred_url": "https://api.github.com/users/Sonotoki-da/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/Sonotoki-da/subscriptions",
"organizations_url": "https://api.github.com/users/Sonotoki-da/orgs",
"repos_url": "https://api.github.com/users/Sonotoki-da/repos",
"events_url": "https://api.github.com/users/Sonotoki-da/events{/privacy}",
"received_events_url": "https://api.github.com/users/Sonotoki-da/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I found that I'm concatenating a string with a None type object...\r\n```python\r\n# Work.authors = None\r\n# author = 'string'\r\nWork.update(authors=Work.authors + author)\r\n```\r\nMaybe this is the problem I'm encountering? It's strange that I'm not getting any errors though",
"All is working as far as I can tell:\r\n\r\n```python\r\ndb = PostgresqlDatabase('peewee_test')\r\n\r\nclass Reg(Model):\r\n data = TextField()\r\n class Meta:\r\n database = db\r\n\r\ndb.drop_tables([Reg])\r\ndb.create_tables([Reg])\r\n\r\nr = Reg.create(data='start')\r\nuq = (Reg\r\n .update(data=Reg.data + '-end')\r\n .where(Reg.id == r.id)\r\n .execute())\r\n\r\nr_db = Reg.get(Reg.id == r.id)\r\nprint(r_db.data)\r\n```\r\n\r\nPrints:\r\n\r\n```\r\nstart-end\r\n```",
"Oh, sorry for troubling\r\nMaybe something went wrong, and it seems I haven't tested my code thoroughly yet\r\nThank you for your confirmation on this case, I really love this library!"
] | 2022-10-01T17:58:26 | 2022-10-03T17:13:00 | 2022-10-03T13:05:32 | NONE | null | My table is:
```python
class Work(BaseModel):
id = AutoField()
user_id = BigIntegerField()
name = TextField(unique=True)
filename = CharField(null=True, unique=True)
authors = TextField(null=True)
content = TextField(null=True)
start_date = DateField()
end_date = DateField(null=True)
```
I'm trying to add (that is, +=) some string to an existing data record:
```python
def add_author(user_id: int, name: str, author: str):
# author = 'Illyustrator:An illustrator%'
# the delimiter is '%'
return Work.update(authors=Work.authors + author).where(
(Work.user_id == user_id) & (Work.name == name)
).execute()
```
The debug logs are:
```
2022-10-01 22:41:17,493 - DEBUG - peewee - ('SELECT "t1"."authors" FROM "work" AS "t1" WHERE (("t1"."user_id" = %s) AND ("t1"."name" = %s))', [5581756786, 'Title name here'])
2022-10-01 22:41:17,495 - DEBUG - peewee - ('UPDATE "work" SET "authors" = ("work"."authors" || %s) WHERE (("work"."user_id" = %s) AND ("work"."name" = %s))', ['Illyustrator:An illustrator%', 5581756786, 'Title name here'])
```
a Postgresql query in the psql cli after that query:
```
ebookmaker=> select * from work;
id | user_id | name | filename | authors | content | start_date | end_date
----+------------+-----------------+----------+---------+---------+------------+----------
4 | 5581756786 | Title name here | | | | 2022-10-01 |
(1 row)
```
But the query doesn't adding the string value to the authors field...
Versions of python and pewee are:
```
Python 3.10.6 (main, Aug 3 2022, 17:39:45) [GCC 12.1.1 20220730] on linux
peewee: 3.15.2
```
By the way, this feature was working in sqlite database | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2625/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2625/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2624 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2624/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2624/comments | https://api.github.com/repos/coleifer/peewee/issues/2624/events | https://github.com/coleifer/peewee/issues/2624 | 1,384,201,801 | I_kwDOAA7yGM5SgT5J | 2,624 | `_id` field required for some transactions | {
"login": "rmskinsa2",
"id": 86251795,
"node_id": "MDQ6VXNlcjg2MjUxNzk1",
"avatar_url": "https://avatars.githubusercontent.com/u/86251795?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/rmskinsa2",
"html_url": "https://github.com/rmskinsa2",
"followers_url": "https://api.github.com/users/rmskinsa2/followers",
"following_url": "https://api.github.com/users/rmskinsa2/following{/other_user}",
"gists_url": "https://api.github.com/users/rmskinsa2/gists{/gist_id}",
"starred_url": "https://api.github.com/users/rmskinsa2/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/rmskinsa2/subscriptions",
"organizations_url": "https://api.github.com/users/rmskinsa2/orgs",
"repos_url": "https://api.github.com/users/rmskinsa2/repos",
"events_url": "https://api.github.com/users/rmskinsa2/events{/privacy}",
"received_events_url": "https://api.github.com/users/rmskinsa2/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Is this just occurring while you're doing things in a schema change? Can you post a minimal reproduction of the problem, as I'm having a hard time making sense of the issue as-is.",
"The actual problem occurs after doing a schema migration. In several places where our code is executing and an instance of Bob tries to access a ManyToMany field, which points to a model with a ForeignKey field we get this error. So like if we did:\r\n```\r\ncar = Car.create(name='Jeep')\r\nsue = Sue.create(car=car.id)\r\nbob = Bob.create()\r\nbob.sues.add(sue)\r\nbob.save()\r\n\r\ncars = [s.car.name for s in bob.sues] <-- error occurs here when calling bob.sues\r\n```",
"I still am not clear what your schema is or exactly what **minimal** steps to follow to reproduce.",
"Going to close for now as I think this is probably some error in the various steps you may have followed, but if you can put together a minimal set of steps I can follow to reproduce I will happily reinvestigate.",
"I don't understand what else you need to reproduce? I recreated the minimum necessary data model here, pasted the migration that was done, as well as provided the minimum code needed to throw the error. Also please give me a chance to respond instead of closing over the weekend. I'll summarize everything here again in the hopes that this issue gets a serious look:\r\n\r\nStart with this data model:\r\n```\r\nclass Bob(db.Model):\r\n sues = ManyToManyField(Sue, backref='bobs')\r\n\r\nclass Sue(db.Model):\r\n age = IntegerField(null=True)\r\n```\r\n\r\nCall this code:\r\n```\r\nsue = Sue.create(age=45)\r\nbob = Bob.create()\r\nbob.sues.add(sue)\r\nbob.save()\r\n\r\nages = [s.age for s in bob.sues] # <-- Iterating over bob.sues works just fine\r\n```\r\n\r\nNow add a Car data model, update the Sue model to point to it via ForeignKeyField, and run a migration using Playhouse:\r\n```\r\nclass Bob(db.Model): # <-- NO change here\r\n sues = ManyToManyField(Sue, backref='bobs')\r\n\r\nclass Car(db.Model): # <-- Create this\r\n make = CharField(null=True)\r\n\r\nclass Sue(db.Model): # <-- add the car field to this\r\n age = IntegerField(null=True)\r\n car = ForeignKeyField(Car, null=True, backref='sues')\r\n```\r\nMigration (this is a very simplified version that doesn't contain all our usual error catching / rollback / logging code. I've stripped it down to the column add):\r\n```\r\n # created reference to db and imported what's needed above ...\r\n migrator = get_migrator(db)\r\n with db.atomic() as transaction:\r\n # Add new Sue.car column\r\n migrate(\r\n migrator.add_column('sue', 'car', Sue.car)\r\n )\r\n```\r\n\r\nNow try this code:\r\n```\r\ncar = Car.create(name='Jeep')\r\nsue = Sue.create(car=car.id)\r\nbob = Bob.create()\r\nbob.sues.add(sue)\r\nbob.save()\r\n\r\ncars = [s.car.name for s in bob.sues] # <-- error occurs here when calling bob.sues\r\n```\r\n\r\nGet this error: `\"Unknown column 't1.car_id' in 'field list'\"`\r\n\r\nNow do this migration:\r\n```\r\n # created reference to db and imported what's needed above ...\r\n migrator = get_migrator(db)\r\n with db.atomic() as transaction:\r\n # Add Sue.car_id column\r\n migrate(\r\n migrator.add_column('sue', 'car_id', IntegerField(null=True))\r\n )\r\n\r\n\r\n sql = \"\"\"\r\n UPDATE\r\n db_name.sue\r\n SET\r\n car_id = car;\r\n \"\"\"\r\n db.execute_sql(sql)\r\n```\r\n\r\nNow run this code again:\r\n```\r\ncar = Car.create(name='Jeep')\r\nsue = Sue.create(car=car.id)\r\nbob = Bob.create()\r\nbob.sues.add(sue)\r\nbob.save()\r\n\r\ncars = [s.car.name for s in bob.sues]\r\n```\r\n\r\nIt now works without throwing any errors.\r\n\r\nDoes querying object B through another object A's ManyToMany field assume any ForeignKey fields on object B have an `_id` appended to their name? Does Playhouse know this when it is adding a ForeignKey column to a table? Does the documentation talk about this somewhere that I missed?",
"Oh I see the issue, thank you for the example. Your migration that adds the foreign-key needs to use the column name and not the field name. The column name in this case is `car_id`:\r\n\r\n```python\r\n migrator = get_migrator(db)\r\n with db.atomic() as transaction:\r\n # Add new Sue.car column\r\n migrate(\r\n migrator.add_column('sue', 'car_id', Sue.car)\r\n )\r\n```",
"http://docs.peewee-orm.com/en/latest/peewee/playhouse.html#SchemaMigrator.add_column",
"I guess my issue is that I don't see docs saying that we need to append `_id` onto the end of a foreign key column name. I was under the impression we could name a foreign key whatever we wanted to. The source code seems to expect this `_id` to be appended when making queries, but nowhere do I see where there are naming requirements for foreign key columns.",
"I agree that the docs could be improved. Hopefully the latest addition clarifies things: http://docs.peewee-orm.com/en/latest/peewee/playhouse.html#supported-operations",
"That does clarify things, thank you."
] | 2022-09-23T19:09:27 | 2022-09-27T16:38:54 | 2022-09-23T21:37:25 | NONE | null | This has happened twice now and I'm trying to figure out if we're implementing things correctly.
So I have a model with several ManyToMany fields like so:
```
class Bob(db.Model):
...
joes = ManyToManyField(Joe, backref='bobs')
sues = ManyToManyField(Sue, backref='bobs')
pams = ManyToManyField(Pam, backref='bobs')
...
class Joe(db.Model):
a = IntegerField(null=True)
class Sue(db.Model):
...
house = ForeignKey(House, null=True, backref='sues')
class Pam(db.Model):
...
car = ForeignKey(Car, null=True, backref='pams')
```
Note that the ForeignKey fields were added via Playhouse migration some time after Sue and Pam tables were first created. Using `add_column`.
```
migrator.add_column(
'pam',
'car',
Pam.car
),
```
When I instantiate an instance of Bob and call something like `self.sues` or `bob1.pams`, I get an error lilke:
```
"Unknown column 't1.house_id' in 'field list'"
```
or
```
"Unknown column 't1.car_id' in 'field list'"
```
To fix this, I create a column called `sue.house_id` and copy the data from `sue.house` into it. And with Pam I create a column called `pam.car_id` and copy data from `pam.car` into it.
It seems that the query of `bob.sues` or `bob.pams` tries to return the foreign key field, but expects an `_id` to be appended to that column name in the db. Playhouse does not create this `_id` column when we add the ForeignKey via migration. I read the following in the docs:
```
Sometimes you only need the associated primary key value from the foreign key column. In this case, Peewee follows the convention established by Django, of allowing you to access the raw foreign key value by appending "_id" to the foreign key field’s name
```
But it doesn't indicate that some queries _require_ or at least _default to_ an `_id` column for the ForeignKey, or that Playhouse doesn't add that column when we use the `add_column` feature. Are we implementing incorrectly or is this a bug? | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2624/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2624/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2623 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2623/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2623/comments | https://api.github.com/repos/coleifer/peewee/issues/2623/events | https://github.com/coleifer/peewee/issues/2623 | 1,383,788,163 | I_kwDOAA7yGM5Seu6D | 2,623 | Is it possible to make non-peewee models play nicely with Peewee? | {
"login": "ilyakamens",
"id": 3293811,
"node_id": "MDQ6VXNlcjMyOTM4MTE=",
"avatar_url": "https://avatars.githubusercontent.com/u/3293811?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/ilyakamens",
"html_url": "https://github.com/ilyakamens",
"followers_url": "https://api.github.com/users/ilyakamens/followers",
"following_url": "https://api.github.com/users/ilyakamens/following{/other_user}",
"gists_url": "https://api.github.com/users/ilyakamens/gists{/gist_id}",
"starred_url": "https://api.github.com/users/ilyakamens/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/ilyakamens/subscriptions",
"organizations_url": "https://api.github.com/users/ilyakamens/orgs",
"repos_url": "https://api.github.com/users/ilyakamens/repos",
"events_url": "https://api.github.com/users/ilyakamens/events{/privacy}",
"received_events_url": "https://api.github.com/users/ilyakamens/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"I would not advise doing this, even if it works in the simple case. It will be too confusing, I think, especially if you have more than one person working on this codebase or intend to support it for a while (imagine trying to explain all this to a new hire).\r\n\r\nBetter, in my opinion, to just explicitly reference the IDs or add convenience methods. Also in your example, I don't think it is correct to `ForeignKey(User)` since `User` is not a real table.",
">Also in your example, I don't think it is correct to ForeignKey(User) since User is not a real table.\r\n\r\nI don't think it'll change your response, but that was a typo, which I've since fixed.\r\n\r\n> It will be too confusing, I think, especially if you have more than one person working on this codebase or intend to support it for a while (imagine trying to explain all this to a new hire).\r\n\r\nThis is subjective / beyond the scope of the discussion, but we optimize our codebases for folks who have been working in them for some time (which is the majority / common case). Thanks again for your consideration."
] | 2022-09-23T13:11:29 | 2022-09-23T14:27:29 | 2022-09-23T13:44:09 | CONTRIBUTOR | null | Good morning (?), @coleifer.
I'm wondering if it's possible to make non-peewee models play nicely with Peewee. Consider the following, which is contrived, but also a real pattern we use at my company:
```python
class DBUser(Model):
pass
class DBAccount(Model):
user = ForeignKeyField(DBUser)
class BankUser:
"""A user in our banking partner's system (not our DB)."""
class User:
"""A higher level user representing a user that lives both in our DB and in our banking partner's system."""
def __init__(dbuser, bankuser):
self._db = dbuser
self._bank = bankuser
```
Is it possible, or are there officially endorsed ways, to duck-type a non-Peewee model (e.g.,`User`) so that it will play nicely with queries like the following:
```python
DBAccount.select().where(DBAccount.user == user)
```
In this particular case, adding the following methods does the trick:
```python
# We already have this method defined for other purposes.
@property
def id(self):
return self._db.id
def __int__(self):
return self.id
```
That's obviously brittle, though, and doesn't work when the primary key isn't the ID. I'm looking for something that doesn't rely on Peewee's internals, and wouldn't be subject to breaking from a non-major version change. I briefly looked at `Metadata`, but figured I'd ask before going further down the rabbit hole. No problem if there's nothing official or unofficial for this. Thank you. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2623/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2623/timeline | null | completed | null | null |
https://api.github.com/repos/coleifer/peewee/issues/2622 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2622/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2622/comments | https://api.github.com/repos/coleifer/peewee/issues/2622/events | https://github.com/coleifer/peewee/pull/2622 | 1,382,324,942 | PR_kwDOAA7yGM4_bFS1 | 2,622 | [CC Reduction] | {
"login": "isaevmik",
"id": 45544322,
"node_id": "MDQ6VXNlcjQ1NTQ0MzIy",
"avatar_url": "https://avatars.githubusercontent.com/u/45544322?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/isaevmik",
"html_url": "https://github.com/isaevmik",
"followers_url": "https://api.github.com/users/isaevmik/followers",
"following_url": "https://api.github.com/users/isaevmik/following{/other_user}",
"gists_url": "https://api.github.com/users/isaevmik/gists{/gist_id}",
"starred_url": "https://api.github.com/users/isaevmik/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/isaevmik/subscriptions",
"organizations_url": "https://api.github.com/users/isaevmik/orgs",
"repos_url": "https://api.github.com/users/isaevmik/repos",
"events_url": "https://api.github.com/users/isaevmik/events{/privacy}",
"received_events_url": "https://api.github.com/users/isaevmik/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Pass for now "
] | 2022-09-22T11:55:41 | 2022-09-22T12:02:18 | 2022-09-22T12:02:18 | NONE | null | Reduction of CC (cyclomatic complixty) of model_to_dict function by putting some some function pieces. | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2622/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2622/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/2622",
"html_url": "https://github.com/coleifer/peewee/pull/2622",
"diff_url": "https://github.com/coleifer/peewee/pull/2622.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/2622.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/2621 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2621/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2621/comments | https://api.github.com/repos/coleifer/peewee/issues/2621/events | https://github.com/coleifer/peewee/pull/2621 | 1,382,050,645 | PR_kwDOAA7yGM4_aLqd | 2,621 | Fix typo | {
"login": "pylipp",
"id": 10617122,
"node_id": "MDQ6VXNlcjEwNjE3MTIy",
"avatar_url": "https://avatars.githubusercontent.com/u/10617122?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/pylipp",
"html_url": "https://github.com/pylipp",
"followers_url": "https://api.github.com/users/pylipp/followers",
"following_url": "https://api.github.com/users/pylipp/following{/other_user}",
"gists_url": "https://api.github.com/users/pylipp/gists{/gist_id}",
"starred_url": "https://api.github.com/users/pylipp/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/pylipp/subscriptions",
"organizations_url": "https://api.github.com/users/pylipp/orgs",
"repos_url": "https://api.github.com/users/pylipp/repos",
"events_url": "https://api.github.com/users/pylipp/events{/privacy}",
"received_events_url": "https://api.github.com/users/pylipp/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"Ill clean this up later. Thx"
] | 2022-09-22T08:31:11 | 2022-09-22T11:34:19 | 2022-09-22T11:34:18 | NONE | null | null | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2621/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2621/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/2621",
"html_url": "https://github.com/coleifer/peewee/pull/2621",
"diff_url": "https://github.com/coleifer/peewee/pull/2621.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/2621.patch",
"merged_at": null
} |
https://api.github.com/repos/coleifer/peewee/issues/2620 | https://api.github.com/repos/coleifer/peewee | https://api.github.com/repos/coleifer/peewee/issues/2620/labels{/name} | https://api.github.com/repos/coleifer/peewee/issues/2620/comments | https://api.github.com/repos/coleifer/peewee/issues/2620/events | https://github.com/coleifer/peewee/pull/2620 | 1,381,601,607 | PR_kwDOAA7yGM4_YutS | 2,620 | Skip test_murmur_hash on big endian architectures | {
"login": "carlwgeorge",
"id": 12187228,
"node_id": "MDQ6VXNlcjEyMTg3MjI4",
"avatar_url": "https://avatars.githubusercontent.com/u/12187228?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/carlwgeorge",
"html_url": "https://github.com/carlwgeorge",
"followers_url": "https://api.github.com/users/carlwgeorge/followers",
"following_url": "https://api.github.com/users/carlwgeorge/following{/other_user}",
"gists_url": "https://api.github.com/users/carlwgeorge/gists{/gist_id}",
"starred_url": "https://api.github.com/users/carlwgeorge/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/carlwgeorge/subscriptions",
"organizations_url": "https://api.github.com/users/carlwgeorge/orgs",
"repos_url": "https://api.github.com/users/carlwgeorge/repos",
"events_url": "https://api.github.com/users/carlwgeorge/events{/privacy}",
"received_events_url": "https://api.github.com/users/carlwgeorge/received_events",
"type": "User",
"site_admin": false
} | [] | closed | false | null | [] | null | [
"My man, thank you. I got my hands full with the kids this evening so I wasn't going to get this until tomorrow. Looks good!"
] | 2022-09-21T22:44:27 | 2022-09-21T23:19:29 | 2022-09-21T22:59:02 | CONTRIBUTOR | null | Resolves #2619 | {
"url": "https://api.github.com/repos/coleifer/peewee/issues/2620/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} | https://api.github.com/repos/coleifer/peewee/issues/2620/timeline | null | null | false | {
"url": "https://api.github.com/repos/coleifer/peewee/pulls/2620",
"html_url": "https://github.com/coleifer/peewee/pull/2620",
"diff_url": "https://github.com/coleifer/peewee/pull/2620.diff",
"patch_url": "https://github.com/coleifer/peewee/pull/2620.patch",
"merged_at": "2022-09-21T22:59:02"
} |