Skip to content

Commit 18ca1e2

Browse files
fix(core,database,management): fix createsuperuser command and replace python-jose with PyJWT
- Fix createsuperuser command to properly save users to database with automatic commit - Replace python-jose with PyJWT to eliminate Python 3.6 deprecation warnings - Update all JWT imports from 'from jose import jwt, JWTError' to 'import jwt' - Remove python-jose dependency from pyproject.toml and setup.py - Fix missing 'os' import in cotlette/__init__.py - Ensure all JWT operations work with PyJWT instead of python-jose - Test createsuperuser command successfully creates users in database
1 parent 9225e89 commit 18ca1e2

File tree

5 files changed

+13
-4
lines changed

5 files changed

+13
-4
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ dependencies = [
1212
"asgiref<4.0.0",
1313
"jinja2<3.2.0",
1414
"bcrypt<4.1.0",
15-
"python-jose<3.4.0",
15+
# "python-jose<3.4.0", # Заменено на PyJWT
1616
"pyjwt<2.8.0",
1717
"itsdangerous<2.2.0",
1818
"python-multipart<0.1.0",

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@ def read_readme():
2424
packages=find_packages(where="src"),
2525
package_dir={"": "src"},
2626
python_requires=">=3.6",
27+
# data_files=[("", ["suppress_warnings.pth"])], # Удалено, так как больше не нужно
2728
install_requires=[
2829
"uvicorn<0.20.0",
2930
"fastapi<0.100.0",
3031
"asgiref<4.0.0",
3132
"jinja2<3.2.0",
3233
"bcrypt<4.1.0",
33-
"python-jose<3.4.0",
34+
# "python-jose<3.4.0", # Заменено на PyJWT
3435
"pyjwt<2.8.0",
3536
"itsdangerous<2.2.0",
3637
"python-multipart<0.1.0",

src/cotlette/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
__version__ = "0.0.0"
22

3-
43
import os
54
import logging
65
# import importlib.util

src/cotlette/core/database/sqlalchemy.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,10 +260,16 @@ async def execute_async(self, query: str, params: tuple = None, fetch: bool = Fa
260260

261261
# Выполняем запрос без параметров
262262
result = await session.execute(sql_text)
263+
264+
# Делаем commit для сохранения изменений
265+
await session.commit()
263266

264267
if fetch:
265268
return result.fetchall()
266269
return result
270+
except Exception:
271+
await session.rollback()
272+
raise
267273
finally:
268274
await session.close()
269275

src/cotlette/core/management/commands/createsuperuser.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,10 @@ async def create_superuser_async():
123123

124124
# Выполняем запрос напрямую через базу данных
125125
from cotlette.core.database.sqlalchemy import db
126-
await db.execute_async(insert_query)
126+
try:
127+
await db.execute_async(insert_query)
128+
except Exception as e:
129+
raise CommandError(f"Error creating superuser: {e}")
127130

128131
self.stdout.write(f"Superuser '{username}' created successfully.")
129132
except Exception as e:

0 commit comments

Comments
 (0)