Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade from python 3.7 to 3.11 #21

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Use official python base image, small and debian edition
FROM amd64/python:3.7.3-slim
# Use official python base image, small edition
FROM docker.io/amd64/python:3.11-slim

ARG purpose=dev

Expand Down
8 changes: 4 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@ services:
- "redis"

redis:
image: redis:alpine
image: docker.io/library/redis:alpine

# wikireplica simulator
mywiki:
image: mariadb:10.4-focal
image: docker.io/library/mariadb:10.11
volumes:
- ./docker-replica/replica.sql:/docker-entrypoint-initdb.d/replica.sql
environment:
MYSQL_USER: repl
MYSQL_PASSWORD: repl
MYSQL_DATABASE: repl
MYSQL_DATABASE: mywiki_p
MYSQL_RANDOM_ROOT_PASSWORD: 1

db:
image: mariadb:10.1.48-bionic
image: docker.io/library/mariadb:10.11
volumes:
- ./schema.sql:/docker-entrypoint-initdb.d/schema.sql
environment:
Expand Down
5 changes: 0 additions & 5 deletions docker-replica/replica.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,8 @@
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

CREATE DATABASE /*!32312 IF NOT EXISTS*/ `mywiki_p` /*!40100 DEFAULT CHARACTER SET utf8mb4 */;

USE `mywiki_p`;

DROP DATABASE IF EXISTS repl;
GRANT SELECT ON mywiki_p.* TO 'repl'@'%';

DROP TABLE IF EXISTS `actor`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
Expand Down
61 changes: 28 additions & 33 deletions quarry/web/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def star_query() -> Union[Tuple[str, int], str]:


@api_blueprint.route("/api/query/meta", methods=["POST"])
def api_set_meta() -> Tuple[Union[str, Response], int]:
def api_set_meta() -> tuple[str, int] | Response:
if get_user() is None:
return "Authentication required", 401

Expand All @@ -81,14 +81,13 @@ def api_set_meta() -> Tuple[Union[str, Response], int]:
query.description = request.form["description"]
g.conn.session.add(query)
g.conn.session.commit()
return (
Response(json.dumps({"id": query.id}), mimetype="application/json"),
200,
return Response(
json.dumps({"id": query.id}), mimetype="application/json", status=200
)


@api_blueprint.route("/api/query/run", methods=["POST"])
def api_run_query() -> Tuple[Union[str, Response], int]:
def api_run_query() -> tuple[str, int] | Response:
if get_user() is None:
return "Authentication required", 401
text = request.form["text"]
Expand Down Expand Up @@ -141,17 +140,15 @@ def api_run_query() -> Tuple[Union[str, Response], int]:
g.conn.session.add(query_rev)
g.conn.session.add(query_run)
g.conn.session.commit()
return (
Response(
json.dumps({"qrun_id": query_run.id}),
mimetype="application/json",
),
200,
return Response(
json.dumps({"qrun_id": query_run.id}),
mimetype="application/json",
status=200,
)


@api_blueprint.route("/api/query/stop", methods=["POST"])
def api_stop_query() -> Tuple[Union[str, Response], int]:
def api_stop_query() -> tuple[str, int] | Response:
if get_user() is None:
return "Authentication required", 401

Expand All @@ -164,17 +161,17 @@ def api_stop_query() -> Tuple[Union[str, Response], int]:
query_run = (
g.conn.session.query(QueryRun).filter(QueryRun.id == qrun_id).one()
)
result_dictionary = ast.literal_eval(query_run.extra_info)
if "connection_id" in result_dictionary:
g.replica.connection = db_of_process
cur = g.replica.connection.cursor()
try:
cur.execute("KILL %s;", (result_dictionary["connection_id"]))
output = "job stopped"
except OperationalError:
output = "job not running"
else:
output = "job not running"
output = "job not running"
if query_run.extra_info:
result_dictionary = ast.literal_eval(query_run.extra_info)
if "connection_id" in result_dictionary:
g.replica.connection = db_of_process
cur = g.replica.connection.cursor()
try:
cur.execute("KILL %s;", (result_dictionary["connection_id"]))
output = "job stopped"
except OperationalError:
output = "job not running"

# Stopping the job usually gets a stopped status. However some jobs stopped
# before the stop button was pressed, and didn't update the DB to reflect
Expand All @@ -185,14 +182,13 @@ def api_stop_query() -> Tuple[Union[str, Response], int]:
query_run.status = QueryRun.STATUS_STOPPED
g.conn.session.add(query_run)
g.conn.session.commit()
return (
Response(json.dumps({"stopped": output}), mimetype="application/json"),
200,
return Response(
json.dumps({"stopped": output}), mimetype="application/json", status=200
)


@api_blueprint.route("/api/preferences/get/<key>")
def pref_get(key) -> Response:
def pref_get(key) -> tuple[str, int] | Response:
if get_user() is None:
return "Authentication required", 401

Expand All @@ -209,16 +205,15 @@ def pref_get(key) -> Response:


@api_blueprint.route("/api/preferences/set/<key>/<value>")
def pref_set(key, value) -> Union[Tuple[str, int], Tuple[Response, int]]:
def pref_set(key, value) -> tuple[str, int] | Response:
if get_user() is None:
return "Authentication required", 401

get_preferences()[key] = None if value == "null" else value
return (
Response(
json.dumps({"key": key, "success": ""}), mimetype="application/json"
),
201,
return Response(
json.dumps({"key": key, "success": ""}),
mimetype="application/json",
status=201,
)


Expand Down
2 changes: 1 addition & 1 deletion quarry/web/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def collect(self):
labels=["status"],
)

for (status_id, query_count) in queries_per_status:
for status_id, query_count in queries_per_status:
metric_family.add_metric(
[QueryRun.STATUS_MESSAGES[status_id]], query_count
)
Expand Down
3 changes: 2 additions & 1 deletion quarry/web/models/queryrun.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import datetime
import json
from sqlalchemy import (
Column,
Expand Down Expand Up @@ -37,7 +38,7 @@ class QueryRun(Base):
id = Column(Integer, primary_key=True)
query_rev_id = Column(Integer, ForeignKey("query_revision.id"))
status = Column(Integer)
timestamp = Column(DateTime)
timestamp = Column(DateTime, default=datetime.datetime.utcnow)
task_id = Column(String)
extra_info = Column(UnicodeText)

Expand Down
2 changes: 1 addition & 1 deletion quarry/web/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import types

from flask import Response, escape
from werkzeug.contrib.iterio import IterI
from .utils.iterio import IterI
import xlsxwriter


Expand Down
8 changes: 5 additions & 3 deletions quarry/web/redissession.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def get_redis_expiration_time(self, app, session):
return timedelta(days=1)

def open_session(self, app, request):
sid = request.cookies.get(app.session_cookie_name)
sid = request.cookies.get(app.config["SESSION_COOKIE_NAME"])
if not sid:
sid = self.generate_sid()
return self.session_class(sid=sid, new=True)
Expand All @@ -51,7 +51,9 @@ def save_session(self, app, session, response):
if not session:
self.redis.delete(self.prefix + session.sid)
if session.modified:
response.delete_cookie(app.session_cookie_name, domain=domain)
response.delete_cookie(
app.config["SESSION_COOKIE_NAME"], domain=domain
)
return
redis_exp = self.get_redis_expiration_time(app, session)
cookie_exp = self.get_expiration_time(app, session)
Expand All @@ -62,7 +64,7 @@ def save_session(self, app, session, response):
time=int(redis_exp.total_seconds()),
)
response.set_cookie(
app.session_cookie_name,
app.config["SESSION_COOKIE_NAME"],
session.sid,
expires=cookie_exp,
httponly=True,
Expand Down
7 changes: 4 additions & 3 deletions quarry/web/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
from decimal import Decimal
from typing import List

INITIAL_SQL = """
CREATE TABLE resultsets (id, headers, rowcount)
"""
INITIAL_SQL = "CREATE TABLE resultsets (id, headers, rowcount)"


def get_unique_columns(raw_columns: List[str]) -> List[str]:
Expand Down Expand Up @@ -57,12 +55,15 @@ def start_resultset(self, columns, rowcount):
unique_columns = get_unique_columns(columns)
sanitized_columns = [self._quote_identifier(c) for c in unique_columns]

# Create table that will store the resultset
table_name = self._get_current_resultset_table()
sql = "CREATE TABLE %s (__id__ INTEGER PRIMARY KEY, %s)" % (
table_name,
", ".join(sanitized_columns),
)
self.db.execute(sql)

# Add the new one to the resultset index table
self.db.execute(
"INSERT INTO resultsets (id, headers, rowcount) VALUES (?, ?, ?)",
(self.resultset_id, json.dumps(unique_columns), rowcount),
Expand Down
Loading