Skip to content

Commit 0d2db45

Browse files
Add debug prints and test instructions for owner context issues
Co-authored-by: yourton.ma <yourton.ma@gmail.com>
1 parent 1561164 commit 0d2db45

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

FINAL_DEBUG_TEST.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# 最终调试测试
2+
3+
## 🎯 现在请运行
4+
5+
```bash
6+
cd ~/workspaces/OpenMetadata
7+
8+
# 清除缓存
9+
find ingestion/src -name "*.pyc" -delete
10+
11+
# 运行测试,只看调试输出
12+
metadata ingest -c ingestion/tests/unit/metadata/ingestion/owner_config_tests/test-03-multiple-users.yaml 2>&1 | grep "🔍" | head -20
13+
```
14+
15+
## 📊 分析输出
16+
17+
### 场景 1: 存储时就是列表,但获取时变成字符串
18+
19+
```
20+
🔍 [STORE_DB] database=finance_db, owner_names=['alice', 'bob'], storing=['alice', 'bob'], type=<class 'list'>
21+
🔍 [GET_SCHEMA] schema=accounting, parent_owner from context=alice, type=<class 'str'>
22+
```
23+
24+
**说明**:Context 在多线程环境下复制时出现问题,列表被转换成了字符串。
25+
26+
**解决方法**:需要检查 TopologyContextManager 的实现,或者改变存储策略。
27+
28+
---
29+
30+
### 场景 2: 存储时就变成了字符串
31+
32+
```
33+
🔍 [STORE_DB] database=finance_db, owner_names=['alice', 'bob'], storing=alice, type=<class 'str'>
34+
🔍 [GET_SCHEMA] schema=accounting, parent_owner from context=alice, type=<class 'str'>
35+
```
36+
37+
**说明**:存储逻辑有问题,`len(database_owner_names) == 1` 的判断不正确。
38+
39+
**解决方法**:检查 `database_owner_names` 的长度判断。
40+
41+
---
42+
43+
### 场景 3: 正常(应该看到的)
44+
45+
```
46+
🔍 [STORE_DB] database=finance_db, owner_names=['alice', 'bob'], storing=['alice', 'bob'], type=<class 'list'>
47+
🔍 [GET_SCHEMA] schema=accounting, parent_owner from context=['alice', 'bob'], type=<class 'list'>
48+
```
49+
50+
**说明**:存储和获取都正常,问题在别处。
51+
52+
---
53+
54+
## 🔧 根据场景采取行动
55+
56+
请把调试输出告诉我,我会根据具体情况给出解决方案!

ingestion/src/metadata/ingestion/source/database/common_db_source.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,11 @@ def yield_database(
225225
database_owner_names = [owner.name for owner in database_owner_ref.root]
226226
# If only one owner, store as string; otherwise store as list
227227
database_owner = database_owner_names[0] if len(database_owner_names) == 1 else database_owner_names
228+
229+
# 🔍 DEBUG: Verify what we're storing
230+
import sys
231+
print(f"🔍 [STORE_DB] database={database_name}, owner_names={database_owner_names}, storing={database_owner}, type={type(database_owner)}", file=sys.stderr)
232+
228233
self.context.get().upsert("database_owner", database_owner)
229234
else:
230235
# Clear context to avoid residual owner from previous database

ingestion/src/metadata/ingestion/source/database/database_service.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,10 @@ def get_schema_owner_ref(self, schema_name: str) -> Optional[EntityReferenceList
635635
try:
636636
# Read database_owner directly from context
637637
parent_owner = getattr(self.context.get(), "database_owner", None)
638+
639+
# 🔍 DEBUG: Check what we got from context
640+
import sys
641+
print(f"🔍 [GET_SCHEMA] schema={schema_name}, parent_owner from context={parent_owner}, type={type(parent_owner)}", file=sys.stderr)
638642

639643
schema_fqn = f"{self.context.get().database}.{schema_name}"
640644

0 commit comments

Comments
 (0)