Skip to content

Commit 11ea7d3

Browse files
committed
Resolve conflict
Signed-off-by: wiseaidev <[email protected]>
2 parents fe1dd1b + a00a68b commit 11ea7d3

18 files changed

+593
-769
lines changed

.github/workflows/ci.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
- name: Checkout
2626
uses: actions/checkout@v3
2727
- name: Setup Python 3.9
28-
uses: actions/setup-python@v4.0.0
28+
uses: actions/setup-python@v4.2.0
2929
with:
3030
python-version: 3.9
3131
#----------------------------------------------
@@ -97,7 +97,7 @@ jobs:
9797
- name: Checkout
9898
uses: actions/checkout@v3
9999
- name: Setup Python ${{ matrix.pyver }}
100-
uses: actions/setup-python@v4.0.0
100+
uses: actions/setup-python@v4.2.0
101101
with:
102102
python-version: ${{ matrix.pyver }}
103103
#----------------------------------------------
@@ -158,7 +158,7 @@ jobs:
158158
- name: Checkout
159159
uses: actions/checkout@v3
160160
- name: Setup Python 3.9
161-
uses: actions/setup-python@v4.0.0
161+
uses: actions/setup-python@v4.2.0
162162
with:
163163
python-version: 3.9
164164
- name: Install Poetry

.github/workflows/codeql.yml

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: "CodeQL"
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
# The branches below must be a subset of the branches above
8+
branches: [ "main" ]
9+
schedule:
10+
- cron: '40 4 * * 4'
11+
12+
jobs:
13+
analyze:
14+
name: Analyze
15+
runs-on: ubuntu-latest
16+
permissions:
17+
actions: read
18+
contents: read
19+
security-events: write
20+
21+
strategy:
22+
fail-fast: false
23+
matrix:
24+
language: [ 'python' ]
25+
26+
steps:
27+
- name: Checkout repository
28+
uses: actions/checkout@v3
29+
30+
# Initializes the CodeQL tools for scanning.
31+
- name: Initialize CodeQL
32+
uses: github/codeql-action/init@v2
33+
with:
34+
languages: ${{ matrix.language }}
35+
36+
- name: Perform CodeQL Analysis
37+
uses: github/codeql-action/analyze@v2

.github/workflows/spellcheck.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
- name: Checkout
99
uses: actions/checkout@v3
1010
- name: Check Spelling
11-
uses: rojopolis/spellcheck-github-actions@0.23.0
11+
uses: rojopolis/spellcheck-github-actions@0.26.0
1212
with:
1313
config_path: .github/spellcheck-settings.yml
1414
task_name: Markdown

aredis_om/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from .async_redis import redis # isort:skip
12
from .checks import has_redis_json, has_redisearch
23
from .connections import get_redis_connection
34
from .model.migrations.migrator import MigrationError, Migrator

aredis_om/async_redis.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from redis import asyncio as redis

aredis_om/connections.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import os
22

3-
import aioredis
3+
from . import redis
44

55

66
URL = os.environ.get("REDIS_OM_URL", None)
77

88

9-
def get_redis_connection(**kwargs) -> aioredis.Redis:
9+
def get_redis_connection(**kwargs) -> redis.Redis:
1010
# If someone passed in a 'url' parameter, or specified a REDIS_OM_URL
1111
# environment variable, we'll create the Redis client from the URL.
1212
url = kwargs.pop("url", URL)
1313
if url:
14-
return aioredis.Redis.from_url(url, **kwargs)
14+
return redis.Redis.from_url(url, **kwargs)
1515

1616
# Decode from UTF-8 by default
1717
if "decode_responses" not in kwargs:
1818
kwargs["decode_responses"] = True
19-
return aioredis.Redis(**kwargs)
19+
return redis.Redis(**kwargs)

aredis_om/model/migrations/migrator.py

+20-19
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from enum import Enum
55
from typing import List, Optional
66

7-
from aioredis import Redis, ResponseError
7+
from ... import redis
88

99

1010
log = logging.getLogger(__name__)
@@ -39,18 +39,19 @@ def schema_hash_key(index_name):
3939
return f"{index_name}:hash"
4040

4141

42-
async def create_index(redis: Redis, index_name, schema, current_hash):
43-
db_number = redis.connection_pool.connection_kwargs.get("db")
42+
async def create_index(conn: redis.Redis, index_name, schema, current_hash):
43+
db_number = conn.connection_pool.connection_kwargs.get("db")
4444
if db_number and db_number > 0:
4545
raise MigrationError(
4646
"Creating search indexes is only supported in database 0. "
4747
f"You attempted to create an index in database {db_number}"
4848
)
4949
try:
50-
await redis.execute_command(f"ft.info {index_name}")
51-
except ResponseError:
52-
await redis.execute_command(f"ft.create {index_name} {schema}")
53-
await redis.set(schema_hash_key(index_name), current_hash)
50+
await conn.execute_command(f"ft.info {index_name}")
51+
except redis.ResponseError:
52+
await conn.execute_command(f"ft.create {index_name} {schema}")
53+
# TODO: remove "type: ignore" when type stubs will be fixed
54+
await conn.set(schema_hash_key(index_name), current_hash) # type: ignore
5455
else:
5556
log.info("Index already exists, skipping. Index hash: %s", index_name)
5657

@@ -67,7 +68,7 @@ class IndexMigration:
6768
schema: str
6869
hash: str
6970
action: MigrationAction
70-
redis: Redis
71+
conn: redis.Redis
7172
previous_hash: Optional[str] = None
7273

7374
async def run(self):
@@ -78,14 +79,14 @@ async def run(self):
7879

7980
async def create(self):
8081
try:
81-
await create_index(self.redis, self.index_name, self.schema, self.hash)
82-
except ResponseError:
82+
await create_index(self.conn, self.index_name, self.schema, self.hash)
83+
except redis.ResponseError:
8384
log.info("Index already exists: %s", self.index_name)
8485

8586
async def drop(self):
8687
try:
87-
await self.redis.execute_command(f"FT.DROPINDEX {self.index_name}")
88-
except ResponseError:
88+
await self.conn.execute_command(f"FT.DROPINDEX {self.index_name}")
89+
except redis.ResponseError:
8990
log.info("Index does not exist: %s", self.index_name)
9091

9192

@@ -105,7 +106,7 @@ async def detect_migrations(self):
105106

106107
for name, cls in model_registry.items():
107108
hash_key = schema_hash_key(cls.Meta.index_name)
108-
redis = cls.db()
109+
conn = cls.db()
109110
try:
110111
schema = cls.redisearch_schema()
111112
except NotImplementedError:
@@ -114,21 +115,21 @@ async def detect_migrations(self):
114115
current_hash = hashlib.sha1(schema.encode("utf-8")).hexdigest() # nosec
115116

116117
try:
117-
await redis.execute_command("ft.info", cls.Meta.index_name)
118-
except ResponseError:
118+
await conn.execute_command("ft.info", cls.Meta.index_name)
119+
except redis.ResponseError:
119120
self.migrations.append(
120121
IndexMigration(
121122
name,
122123
cls.Meta.index_name,
123124
schema,
124125
current_hash,
125126
MigrationAction.CREATE,
126-
redis,
127+
conn,
127128
)
128129
)
129130
continue
130131

131-
stored_hash = await redis.get(hash_key)
132+
stored_hash = await conn.get(hash_key)
132133
schema_out_of_date = current_hash != stored_hash
133134

134135
if schema_out_of_date:
@@ -140,7 +141,7 @@ async def detect_migrations(self):
140141
schema,
141142
current_hash,
142143
MigrationAction.DROP,
143-
redis,
144+
conn,
144145
stored_hash,
145146
)
146147
)
@@ -151,7 +152,7 @@ async def detect_migrations(self):
151152
schema,
152153
current_hash,
153154
MigrationAction.CREATE,
154-
redis,
155+
conn,
155156
stored_hash,
156157
)
157158
)

0 commit comments

Comments
 (0)