Skip to content

Commit 6325fa4

Browse files
committed
Fix typing errors in tracking extension
1 parent da34655 commit 6325fa4

File tree

4 files changed

+35
-31
lines changed

4 files changed

+35
-31
lines changed

ckan/lib/cli.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import click
99
import paste.script # type: ignore
10-
import routes # type: ignore
10+
import routes
1111
from paste.registry import Registry # type: ignore
1212

1313
from urllib.parse import urlparse

ckan/lib/dictization/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from __future__ import annotations
33

44
import datetime
5-
from typing import Any, Callable, Iterable, Literal
5+
from typing import Any, Callable, Iterable, Literal, cast
66

77
import sqlalchemy
88
from sqlalchemy import Table
@@ -127,7 +127,7 @@ def table_dict_save(
127127
'''
128128
session = context["session"]
129129

130-
table = class_mapper(ModelClass).persist_selectable
130+
table = cast(Table, class_mapper(ModelClass).persist_selectable)
131131

132132
obj = None
133133

ckanext/tracking/cli/tracking.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def update_all(start_date: Optional[str] = None):
5353
# No date given. See when we last have data for and get data
5454
# from 2 days before then in case new data is available.
5555
# If no date here then use 2011-01-01 as the start date
56-
stmt = select(ts).order_by(desc(ts.tracking_date))
56+
stmt = select(ts).order_by(ts.tracking_date.desc())
5757
result = session.scalars(stmt).first()
5858
if result:
5959
date = result.tracking_date
@@ -204,7 +204,7 @@ def update_tracking_summary_with_package_id(package_url: str):
204204
)
205205

206206
session.query(ts).filter(
207-
ts.package_id.is_(None), # type: ignore
207+
ts.package_id.is_(None),
208208
ts.tracking_type == "page",
209209
).update(
210210
{ts.package_id: func.coalesce(subquery, "~~not~found~~")},
@@ -229,7 +229,7 @@ def update_tracking_summary_with_package_id(package_url: str):
229229
.filter(
230230
ta.url == ts.url,
231231
ta.tracking_date <= ts.tracking_date,
232-
ta.tracking_date >= ts.tracking_date - 14, # type: ignore
232+
ta.tracking_date >= ts.tracking_date - 14,
233233
)
234234
.scalar_subquery()
235235
)
@@ -250,7 +250,7 @@ def update_tracking_summary_with_package_id(package_url: str):
250250
session.query(ts).filter(
251251
ts.running_total == 0,
252252
ts.tracking_type == "page",
253-
ts.package_id.isnot(None), # type: ignore
253+
ts.package_id.isnot(None),
254254
ts.package_id != "~~not~found~~",
255255
).update(
256256
{

ckanext/tracking/model.py

+28-24
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
import datetime
1919

20-
from sqlalchemy import types, Column, text, Index
20+
from sqlalchemy import types, Column, text, Index, Table
2121

2222
import ckan.model.meta as meta
2323
import ckan.model.domain_object as domain_object
@@ -27,17 +27,21 @@
2727
__all__ = ['TrackingSummary', 'TrackingRaw']
2828

2929

30-
class TrackingRaw(domain_object.DomainObject, BaseModel): # type: ignore
30+
class TrackingRaw(domain_object.DomainObject, BaseModel):
3131

32-
__tablename__ = 'tracking_raw'
33-
34-
user_key = Column("user_key", types.Unicode(100), nullable=False,
35-
primary_key=True)
36-
url = Column("url", types.UnicodeText, nullable=False, primary_key=True)
37-
tracking_type = Column("tracking_type", types.Unicode(10),
38-
nullable=False)
39-
access_timestamp = Column("access_timestamp", types.DateTime,
40-
primary_key=True, default=datetime.datetime.now)
32+
__table__ = Table(
33+
"tracking_raw",
34+
BaseModel.metadata,
35+
Column("user_key", types.Unicode(100), nullable=False, primary_key=True),
36+
Column("url", types.UnicodeText, nullable=False, primary_key=True),
37+
Column("tracking_type", types.Unicode(10), nullable=False),
38+
Column(
39+
"access_timestamp",
40+
types.DateTime,
41+
primary_key=True,
42+
default=datetime.datetime.now
43+
),
44+
)
4145

4246
def __init__(self, user_key: str,
4347
url: str,
@@ -66,19 +70,19 @@ def create(cls, **kw: _types.Any) -> TrackingRaw:
6670
Index('tracking_raw_access_timestamp', 'access_timestamp')
6771

6872

69-
class TrackingSummary(domain_object.DomainObject, BaseModel): # type: ignore
70-
71-
__tablename__ = 'tracking_summary'
73+
class TrackingSummary(domain_object.DomainObject, BaseModel):
7274

73-
url = Column("url", types.UnicodeText, nullable=False, primary_key=True)
74-
package_id = Column("package_id", types.UnicodeText)
75-
tracking_type = Column("tracking_type", types.Unicode(10), nullable=False)
76-
count = Column("count", types.Integer, nullable=False) # type: ignore
77-
running_total = Column("running_total", types.Integer, nullable=False,
78-
server_default='0')
79-
recent_views = Column("recent_views", types.Integer, nullable=False,
80-
server_default='0')
81-
tracking_date = Column("tracking_date", types.Date)
75+
__table__ = Table(
76+
"tracking_summary",
77+
BaseModel.metadata,
78+
Column("url", types.UnicodeText, nullable=False, primary_key=True),
79+
Column("package_id", types.UnicodeText),
80+
Column("tracking_type", types.Unicode(10), nullable=False),
81+
Column("count", types.Integer, nullable=False),
82+
Column("running_total", types.Integer, nullable=False, server_default="0"),
83+
Column("recent_views", types.Integer, nullable=False, server_default="0"),
84+
Column("tracking_date", types.Date)
85+
)
8286

8387
def __init__(self,
8488
url: str,
@@ -141,5 +145,5 @@ def get_for_resource(cls, url: str) -> dict[str, int]:
141145

142146

143147
Index('tracking_summary_url', TrackingSummary.url)
144-
Index('tracking_summary_package_id', TrackingSummary.package_id) # type: ignore
148+
Index('tracking_summary_package_id', TrackingSummary.package_id)
145149
Index('tracking_summary_date', 'tracking_date')

0 commit comments

Comments
 (0)