Skip to content

Commit 60fee23

Browse files
Fix: Correct owner inheritance logic for multiple owners
Co-authored-by: yourton.ma <yourton.ma@gmail.com>
1 parent 414b4c9 commit 60fee23

File tree

3 files changed

+466
-3
lines changed

3 files changed

+466
-3
lines changed

FINAL_INSTRUCTIONS.md

Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
# 最终执行指令
2+
3+
## ✅ 代码修改确认
4+
5+
您的代码修改已经**完全正确**
6+
7+
验证:
8+
```bash
9+
cd ~/workspaces/OpenMetadata
10+
11+
# 检查修改(应该看到2行)
12+
grep -n "parent_owner: Optional\[Union\[str, List\[str\]\]\]" ingestion/src/metadata/utils/owner_utils.py
13+
```
14+
15+
**期望输出**
16+
```
17+
56: parent_owner: Optional[Union[str, List[str]]] = None,
18+
234: parent_owner: Optional[Union[str, List[str]]] = None,
19+
```
20+
21+
如果看到这两行,说明修改完全正确!✅
22+
23+
## 🚀 立即运行测试
24+
25+
### 方法 1: 使用更新后的验证脚本(推荐)
26+
27+
```bash
28+
cd ~/workspaces/OpenMetadata
29+
30+
# 从 /workspace 复制更新后的脚本
31+
cp /workspace/RUN_AND_VERIFY.sh ./RUN_AND_VERIFY.sh
32+
33+
# 运行
34+
bash RUN_AND_VERIFY.sh
35+
```
36+
37+
### 方法 2: 手动运行测试
38+
39+
```bash
40+
cd ~/workspaces/OpenMetadata
41+
42+
# 清除缓存
43+
find ingestion/src -name "*.pyc" -delete
44+
find ingestion/src -name "__pycache__" -exec rm -rf {} + 2>/dev/null
45+
46+
# 运行测试
47+
metadata ingest -c ingestion/tests/unit/metadata/ingestion/owner_config_tests/test-03-multiple-users.yaml 2>&1 | tee /tmp/test-03.log
48+
49+
# 检查继承日志
50+
grep -i "inherited owner" /tmp/test-03.log
51+
```
52+
53+
**期望看到**(关键!):
54+
```
55+
DEBUG ... Using inherited owner for 'accounting': ['alice', 'bob']
56+
57+
DEBUG ... Using inherited owner for 'accounting': alice, bob
58+
```
59+
60+
如果看到列表或两个名字,说明继承正常!
61+
62+
### 方法 3: 直接验证 API
63+
64+
等 ingestion 完成后:
65+
66+
```bash
67+
# 设置 JWT token(如果未设置)
68+
export JWT_TOKEN="your_token_here"
69+
70+
# 检查 accounting schema 的 owners
71+
curl -s -X GET "http://localhost:8585/api/v1/databaseSchemas/name/postgres-test-03-multiple-users.finance_db.accounting" \
72+
-H "Authorization: Bearer $JWT_TOKEN" | jq '.owners | length'
73+
```
74+
75+
**期望输出**: `2`(而不是 `1`
76+
77+
## 🔍 如果仍然只有1个owner
78+
79+
### 步骤1: 检查日志中的详细信息
80+
81+
```bash
82+
# 查看所有 owner 相关的日志
83+
grep -i "owner\|parent" /tmp/test-03.log | grep -v "password"
84+
85+
# 特别关注 accounting schema 的日志
86+
grep -C 5 "accounting" /tmp/test-03.log | grep -i owner
87+
```
88+
89+
### 步骤2: 添加临时调试输出
90+
91+
编辑 `ingestion/src/metadata/ingestion/source/database/common_db_source.py`,在第228行后添加:
92+
93+
```python
94+
self.context.get().upsert("database_owner", database_owner)
95+
96+
# 🔍 临时调试
97+
import sys
98+
print(f"🔍 DEBUG [database]: database_owner_names = {database_owner_names}", file=sys.stderr)
99+
print(f"🔍 DEBUG [database]: database_owner (context) = {database_owner}", file=sys.stderr)
100+
print(f"🔍 DEBUG [database]: type = {type(database_owner)}", file=sys.stderr)
101+
```
102+
103+
编辑 `ingestion/src/metadata/utils/owner_utils.py`,在第117行后添加:
104+
105+
```python
106+
if self.enable_inheritance and parent_owner:
107+
# 🔍 临时调试
108+
import sys
109+
print(f"🔍 DEBUG [resolve]: parent_owner = {parent_owner}", file=sys.stderr)
110+
print(f"🔍 DEBUG [resolve]: type = {type(parent_owner)}", file=sys.stderr)
111+
112+
owner_ref = self._get_owner_refs(parent_owner)
113+
114+
# 🔍 临时调试
115+
if owner_ref and owner_ref.root:
116+
print(f"🔍 DEBUG [resolve]: returned {len(owner_ref.root)} owners: {[o.name for o in owner_ref.root]}", file=sys.stderr)
117+
```
118+
119+
然后运行:
120+
121+
```bash
122+
metadata ingest -c test-03-multiple-users.yaml 2>&1 | grep "🔍 DEBUG"
123+
```
124+
125+
**期望看到**
126+
```
127+
🔍 DEBUG [database]: database_owner_names = ['alice', 'bob']
128+
🔍 DEBUG [database]: database_owner (context) = ['alice', 'bob']
129+
🔍 DEBUG [database]: type = <class 'list'>
130+
🔍 DEBUG [resolve]: parent_owner = ['alice', 'bob']
131+
🔍 DEBUG [resolve]: type = <class 'list'>
132+
🔍 DEBUG [resolve]: returned 2 owners: ['alice', 'bob']
133+
```
134+
135+
如果看到的不是这样,请告诉我具体输出是什么。
136+
137+
### 步骤3: 检查 OpenMetadata 服务端
138+
139+
可能性:OpenMetadata 服务端有限制或bug,即使我们发送了2个owners,服务端也只保存了1个。
140+
141+
验证方法:
142+
143+
```bash
144+
# 检查 database 的 owners(这个应该肯定是2个,因为是直接配置的)
145+
curl -s "http://localhost:8585/api/v1/databases/name/postgres-test-03-multiple-users.finance_db" \
146+
-H "Authorization: Bearer $JWT_TOKEN" | jq '.owners'
147+
```
148+
149+
如果 **database** 只有1个owner,说明问题在服务端或网络层。
150+
151+
如果 **database** 有2个owner,但 **schema** 只有1个,说明继承逻辑有问题。
152+
153+
## 📊 预期的完整流程
154+
155+
### 正确的数据流:
156+
157+
1. **配置解析**:
158+
```yaml
159+
database:
160+
"finance_db": ["alice", "bob"] # 数组
161+
```
162+
163+
2. **Database 层级**:
164+
```python
165+
# resolve_owner 返回
166+
EntityReferenceList(root=[
167+
EntityReference(name="alice", type="user"),
168+
EntityReference(name="bob", type="user")
169+
])
170+
171+
# 存储到 context
172+
database_owner = ["alice", "bob"] # 列表
173+
```
174+
175+
3. **Schema 层级(继承)**:
176+
```python
177+
# 从 context 获取
178+
parent_owner = ["alice", "bob"] # 列表
179+
180+
# 调用 resolve_owner
181+
owner_ref = self._get_owner_refs(["alice", "bob"])
182+
183+
# 返回
184+
EntityReferenceList(root=[
185+
EntityReference(name="alice", type="user"),
186+
EntityReference(name="bob", type="user")
187+
])
188+
```
189+
190+
4. **API 存储**:
191+
```json
192+
{
193+
"owners": [
194+
{"name": "alice", "type": "user"},
195+
{"name": "bob", "type": "user"}
196+
]
197+
}
198+
```
199+
200+
## 🆘 需要更多帮助
201+
202+
如果上述步骤都正常,但还是只有1个owner,请提供:
203+
204+
1. **调试日志**:
205+
```bash
206+
grep "🔍 DEBUG" /tmp/test-03.log
207+
```
208+
209+
2. **继承日志**:
210+
```bash
211+
grep "inherited owner" /tmp/test-03.log
212+
```
213+
214+
3. **API 返回**:
215+
```bash
216+
curl ... | jq '.owners'
217+
```
218+
219+
我会根据这些信息进一步诊断!

RUN_AND_VERIFY.sh

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,14 @@ else
4343
exit 1
4444
fi
4545

46-
if grep -q "parent_owner: Optional\[Union\[str, List\[str\]\]\]" ingestion/src/metadata/utils/owner_utils.py; then
47-
echo -e "${GREEN}✅ owner_utils.py 类型声明正确${NC}"
46+
# 检查 parent_owner 类型声明(应该有2处)
47+
PARENT_OWNER_COUNT=$(grep -c "parent_owner: Optional\[Union\[str, List\[str\]\]\]" ingestion/src/metadata/utils/owner_utils.py || true)
48+
if [ "$PARENT_OWNER_COUNT" -ge 2 ]; then
49+
echo -e "${GREEN}✅ owner_utils.py 类型声明正确(找到 $PARENT_OWNER_COUNT 处)${NC}"
4850
else
49-
echo -e "${RED}❌ owner_utils.py 类型声明不正确${NC}"
51+
echo -e "${RED}❌ owner_utils.py 类型声明不正确(只找到 $PARENT_OWNER_COUNT 处,应该至少2处)${NC}"
52+
echo "实际内容:"
53+
grep -n "parent_owner: Optional" ingestion/src/metadata/utils/owner_utils.py || true
5054
exit 1
5155
fi
5256

0 commit comments

Comments
 (0)