-
Notifications
You must be signed in to change notification settings - Fork 199
fix: enhance error reporting by including HSN codes in error messages; remove unnecessary errors; #3553
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #3553 +/- ##
===========================================
+ Coverage 60.98% 68.75% +7.77%
===========================================
Files 134 182 +48
Lines 13788 17493 +3705
===========================================
+ Hits 8409 12028 +3619
- Misses 5379 5465 +86
🚀 New features to boost your workflow:
|
india_compliance/gst_india/doctype/gst_return_log/generate_gstr_1.py
Outdated
Show resolved
Hide resolved
…; remove unnecessary errors;
eec61c4
to
9fa9520
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
india_compliance/gst_india/utils/gstr_1/gstr_1_json_map.py (1)
1857-1866
: Critical: error extraction breaks for categories that store lists (e.g., B2CS, NIL, AT/TXP).
data.values()
may yield lists (e.g., B2CS groups invoices into lists by POS/Rate; NIL groups by type). Callingrow.get(...)
on a list raises AttributeError. This will crashconvert_to_internal_data_format(..., for_errors=True)
on such payloads.Apply this diff to handle both dict and list rows:
- errors = [] - for category, data in output.items(): - for row in data.values(): - if not row.get("error_code") and not row.get("error_message"): - continue - - row["category"] = category - errors.append(row) + errors = [] + for category, data in output.items(): + for rows in data.values(): + candidates = rows if isinstance(rows, list) else [rows] + for row in candidates: + # skip non-dict entries defensively + if not isinstance(row, dict): + continue + if not (row.get("error_code") or row.get("error_message")): + continue + row["category"] = category + errors.append(row)Consider adding a unit test for each list-based section (B2CS, NIL, AT/TXP) to ensure
for_errors=True
doesn’t throw and only returns rows witherror_code
orerror_message
.
🧹 Nitpick comments (3)
india_compliance/gst_india/utils/gstr_1/gstr_1_json_map.py (3)
1174-1175
: Remove stdout debug print (“converting hsn summ”).Printing in library code is noisy and hard to control in production. Use
frappe.logger().debug(...)
if needed, or drop it.Apply this diff:
- print("converting hsn summ")
1278-1284
: Harden error formatter: remove prints, handle None, and make HSN injection idempotent.
- Avoid printing raw
error_msg
anddata
(may contain PII: invoice no., item details).- Ensure the method doesn’t add the HSN twice if already present.
- Prefer the same suffix style used in GenerateGSTR1 (“... - HSN Code:
”) to stay consistent across code paths.
Apply this diff:
- def get_error_message(self, error_msg, data=None): - print(error_msg, data, "\n\n\n") - if data and (hsn_code := data.get(inv_f.HSN_CODE)): - return f"HSN Code: {hsn_code} - {error_msg}".strip() - - return error_msg + def get_error_message(self, error_msg, data=None): + # Normalize the base message + msg = (error_msg or "").strip() + if not data: + return msg + # Try both internal and gov keys to avoid ordering issues during formatting + hsn_code = data.get(inv_f.HSN_CODE) or data.get(gov_f.HSN_CODE) + if not hsn_code: + return msg + # Idempotency: if HSN already present, do nothing + if str(hsn_code) in msg: + return msg + # Match GenerateGSTR1 style (suffix) + return f"{msg} - HSN Code: {hsn_code}" if msg else f"HSN Code: {hsn_code}"
1843-1843
: Drop module-level print in converter.This will spam stdout whenever any conversion runs. Prefer
frappe.logger().debug(...)
gated by a debug flag, or remove.Apply this diff:
- print("Converting Gov data to internal format...\n\n")
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📥 Commits
Reviewing files that changed from the base of the PR and between 9fa95201c6016ce0f012c7de466eecf79812ad05 and 62cdb8ab01c8bec4ced978ee589508cdcb61181c.
📒 Files selected for processing (2)
india_compliance/gst_india/doctype/gst_return_log/generate_gstr_1.py
(4 hunks)
india_compliance/gst_india/utils/gstr_1/gstr_1_json_map.py
(5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- india_compliance/gst_india/doctype/gst_return_log/generate_gstr_1.py
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-04-22T13:15:18.792Z
Learnt from: Ninad1306
PR: resilient-tech/india-compliance#3222
File: india_compliance/gst_india/utils/gstr_1/gstr_1_json_map.py:1167-1171
Timestamp: 2025-04-22T13:15:18.792Z
Learning: In GSTR1 mappers like HSNSUM, serial number fields (num) don't need explicit entries in KEY_MAPPING when they're directly passed as GovDataField.INDEX.value to format_data(). Without a mapping entry, the format_data method preserves the original key (which is already correct) in the output.
Applied to files:
india_compliance/gst_india/utils/gstr_1/gstr_1_json_map.py
🧬 Code graph analysis (1)
india_compliance/gst_india/utils/gstr_1/gstr_1_json_map.py (2)
india_compliance/gst_india/report/hsn_wise_summary_of_outward_supplies/hsn_wise_summary_of_outward_supplies.py (1)
map_uom
(258-271)
india_compliance/gst_india/utils/itc_04/itc_04_json_map.py (1)
map_uom
(44-53)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
- GitHub Check: Codacy Static Code Analysis
- GitHub Check: Python Unit Tests
- GitHub Check: Mergify Merge Protections
- GitHub Check: Summary
self.value_formatters_for_internal = { | ||
gov_f.UOM: self.map_uom, | ||
gov_f.ERROR_MSG: self.get_error_message, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
Make ERROR_MSG formatter effective and prevent double HSN injection.
- As-is,
value_formatters_for_internal
adds a formatter forgov_f.ERROR_MSG
, but HSNSUM’sKEY_MAPPING
does not mapgov_f.ERROR_MSG
→inv_f.ERROR_MSG
(norgov_f.ERROR_CD
→inv_f.ERROR_CD
). Without the mapping, downstream logic that readsrow['error_message']
won’t see the formatted value, and yourfor_errors=True
filter may miss errors originating at the row level. - Also note: GenerateGSTR1 currently appends HSN to error messages for HSN rows. Combined with
get_error_message
here, that risks duplication (“HSN Code: 1102 - - HSN Code: 1102”).
Action:
- Add explicit mappings for
ERROR_MSG
andERROR_CD
in HSNSUM.KEY_MAPPING. - Pick one place to inject HSN into error messages (here in HSNSUM or in GenerateGSTR1), and make the other path idempotent or a no-op to avoid duplicates.
Add these entries in HSNSUM.KEY_MAPPING (outside the edited hunk):
# In class HSNSUM.KEY_MAPPING
gov_f.ERROR_CD: inv_f.ERROR_CD,
gov_f.ERROR_MSG: inv_f.ERROR_MSG,
Optionally, keep only one of the following:
- Keep HSNSUM.get_error_message and make GenerateGSTR1 skip extra suffix if already present, or
- Remove HSNSUM formatter for ERROR_MSG and keep GenerateGSTR1’s augmentation.
Run this to confirm consistent mappings across mappers and to locate the GenerateGSTR1 augmentation:
🏁 Script executed:
#!/bin/bash
rg -nP --type=py 'KEY_MAPPING\s*=\s*\{(?:.|\n)*?ERROR_(MSG|CD)(?:.|\n)*?\}' -C2
rg -nP --type=py 'HSN Code:\s*\{?hsn_code\}?|HSN Code:' -C2
Length of output: 1236
Ensure ERROR_MSG and ERROR_CD are mapped and remove duplicate HSN injection
The current implementation adds a formatter for gov_f.ERROR_MSG
but never maps it (or gov_f.ERROR_CD
) in HSNSUM.KEY_MAPPING, and both HSNSUM.get_error_message and GenerateGSTR1 append the “HSN Code” prefix—resulting in duplicated HSN text.
• HSNSUM.KEY_MAPPING (class in gstr_1_json_map.py
) has no entries for
gov_f.ERROR_CD → inv_f.ERROR_CD
gov_f.ERROR_MSG → inv_f.ERROR_MSG
• HSNSUM.get_error_message (lines ~1279–1281 in india_compliance/gst_india/utils/gstr_1/gstr_1_json_map.py
)
returns
f"HSN Code: {hsn_code} - {error_msg}"
• GenerateGSTR1 (lines ~583–587 in india_compliance/gst_india/doctype/gst_return_log/generate_gstr_1.py
) also does
f"{error_message} - HSN Code: {hsn_code}"
Action items:
- Add the missing mappings in HSNSUM.KEY_MAPPING:
class HSNSUM: KEY_MAPPING = { …, + gov_f.ERROR_CD: inv_f.ERROR_CD, + gov_f.ERROR_MSG: inv_f.ERROR_MSG, }
- Eliminate duplicate HSN injection by choosing one of:
– KeepHSNSUM.get_error_message
and guard in GenerateGSTR1 (e.g. skip suffix if already present), or
– Remove the HSN prefix fromHSNSUM.get_error_message
and rely solely on GenerateGSTR1’s augmentation.
Fixes: #3507
Summary by CodeRabbit