Code nodes raise AttributeError ('section') in CSV export and text_search
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 62/100
Hướng nghiên cứu
Bắt đầu với application/utils/spreadsheet.py:120 trong ExportSheet.write_standard_entry và application/database/db.py:2812 trong Node_collection.text_search; cả hai đường dẫn đều đọc các trường section từ các node Code. Dùng script trong issue để tái hiện lỗi, sau đó kiểm tra phần kiểm tra hiện có của find_cres_of_node về cách xử lý các trường không tồn tại. Hoàn thành khi cả xuất CSV và text_search đều trả về HTTP 200 cho một node Code, như mô tả trong các bài kiểm thử hồi quy được đề xuất trong issue.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Issue
What is the issue?
Code nodes have no section, sectionID or subsection fields (Standard and Tool do), but two code paths read them from any non-CRE node. If the database contains a Code node, both of the following raise an unhandled AttributeError. The test client propagates the exception, and a deployed Flask app would return HTTP 500 for it.
- CSV export:
ExportSheet.write_standard_entry,application/utils/spreadsheet.py:120 - Fuzzy
text_search:Node_collection.text_search,application/database/db.py:2812
Found on main at 6bc7a30e. Environment: Python 3.11.9, Windows, repo test configuration (create_app(mode="test")).
Field check on main:
>>> {c.__name__: [f for f in ('section', 'sectionID', 'subsection') if f in c.__dataclass_fields__] for c in (Standard, Tool, Code)}
{'Standard': ['section', 'sectionID', 'subsection'], 'Tool': ['section', 'sectionID', 'subsection'], 'Code': []}
This is separate from #1176 (OSCAL format) and #862 (text_search with no text parameter). Neither covers Code nodes.
Expected Behaviour
Both requests succeed (HTTP 200). The Code node is exported or returned like any other node.
Actual Behaviour
Both raise AttributeError: 'Code' object has no attribute 'section'.
CSV export, GET /rest/v1/code/SecCodeSnippet?format=csv (abridged):
application/web/web_main.py:297, in find_node_by_name
docs = sheet_utils.ExportSheet().prepare_spreadsheet(
application/utils/spreadsheet.py:289, in prepare_spreadsheet
entry = self.write_standard_entry(doc)
application/utils/spreadsheet.py:120, in write_standard_entry
if node.section:
AttributeError: 'Code' object has no attribute 'section'
GET /rest/v1/text_search?text=Snippet (abridged):
application/web/web_main.py:635, in text_search
documents = database.text_search(text)
application/database/db.py:2812, in text_search
node_key = f"{node.name}:{node.version}:{node.section}:{node.sectionID}:{node.subsection}:"
AttributeError: 'Code' object has no attribute 'section'
Steps to reproduce
From the repo root, on main (6bc7a30e), with the dev requirements installed, save this as repro_code_node.py:
import sys
import traceback
from application import create_app, sqla
from application.database import db
from application.defs import cre_defs as defs
app = create_app(mode="test")
with app.app_context():
sqla.create_all()
collection = db.Node_collection().with_graph()
collection.add_node(defs.Code(name="SecCodeSnippet", description="sample"))
client = app.test_client()
for label, url in [
("CSV export", "/rest/v1/code/SecCodeSnippet?format=csv"),
("text_search", "/rest/v1/text_search?text=Snippet"),
]:
print("=== " + label + ": GET " + url)
try:
resp = client.get(url, base_url="https://localhost")
print("HTTP", resp.status_code)
except Exception:
traceback.print_exc(file=sys.stdout)
Run it:
# bash
PYTHONPATH=. python repro_code_node.py 2>/dev/null
# PowerShell
$env:PYTHONPATH = "."; python repro_code_node.py 2>$null
(2>/dev/null and 2>$null only hide the JSON log lines.) Both sections end in the AttributeError shown above.
With the change proposed below applied, the same script prints HTTP 200 for both requests.
Notes
Codenodes are part of normal data. They are handled on import incre_main.py, and/rest/v1/code/<name>already has JSON and Markdown tests inweb_main_test.py. CSV is not covered.find_cres_of_nodeindb.pyalready tolerates the missing attributes ("section" not in vars(node)).
Proposed fix
Read the attributes with getattr(node, "section", "") (same for sectionID and subsection) at both sites. I have this ready with three regression tests (one in spreadsheet_test.py, two in web_main_test.py) that fail on main and pass with the change. I'll open a PR once a maintainer acknowledges the issue.
- Ngôn ngữ chính
- Python
- Star
- 216
- Fork
- 173
- Merge trung bình
- 1 ngày 21 giờ
- Pull request đã merge (30 ngày)
- 21
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Có Dockerfile hoặc tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của OWASP/OpenCRE
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
OWASP/OpenCRE#1228 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Incorrect inverse relationship type in CRE internal-link exportCó thể làm lại được @saicharan-r02 đã nhận 9 ngày trước và không có pull request nào đang mở. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
OWASP/OpenCRE#1215 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Map Analysis continues polling after a background job failsCó thể đã có người làm @abhi2005-bit đã nhận 11 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
OWASP/OpenCRE#1211 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của OWASP/OpenCRE
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
NL-BioImaging/biomero#136 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Grayscale PNGs with partial transparency can turn gray pixels whiteCó thể đã có người làm @ktz03 đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
Add deterministic regex redaction for IDs, IBANs, and account numbers in summaries & keywordsĐang mởenhancement good first issue help wanted
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
floorianmb/tidywise#5 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
eclipse-score/tools#82 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
Maintainer thường phản hồi trong vòng 1 ngày