Skip to content
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

fix: add default value for is_posted_at_null #674

Merged
merged 2 commits into from
Nov 20, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/fyle/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ def create_expense_objects(expenses: List[Dict], workspace_id, skip_update: bool
'file_ids': expense['file_ids'],
'spent_at': expense['spent_at'],
'posted_at': expense['posted_at'],
'is_posted_at_null': expense['is_posted_at_null'],
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

🛠️ Refactor suggestion

Dictionary access should use .get() method for safer handling

Looking at the codebase, direct dictionary access is used for all fields in the expense dictionary, while .get() is used in other parts of the code. Since is_posted_at_null is derived from posted_at, we should use the safer .get() method with a default value derived from the posted_at field.

  • apps/fyle/models.py: Replace direct dictionary access with .get() method
'is_posted_at_null': expense.get('is_posted_at_null', expense['posted_at'] is None),
🔗 Analysis chain

Consider adding validation for is_posted_at_null field

The code assumes that is_posted_at_null will always be present in the expense dictionary. Consider adding validation or a default value to handle cases where this field might be missing from the input data.

-                'is_posted_at_null': expense['is_posted_at_null'],
+                'is_posted_at_null': expense.get('is_posted_at_null', expense['posted_at'] is None),
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if there are any existing error handlers for missing dictionary keys
rg -A 5 "KeyError.*is_posted_at_null" 

Length of output: 39


Script:

#!/bin/bash
# Let's check the context around the usage of is_posted_at_null in models.py
rg -B 5 -A 5 "is_posted_at_null" apps/fyle/models.py

# Also check if there are any existing .get() usages for safe dictionary access
rg "expense\.get\(" apps/fyle/models.py

Length of output: 1683


Script:

#!/bin/bash
# Let's check how posted_at is handled in the codebase
rg -B 3 -A 3 "posted_at.*=.*expense\[" apps/fyle/models.py

# Check if there are any other places where dictionary access is done with .get()
rg "\.get\(" apps/fyle/models.py

# Check for any error handling patterns in the create_expense_objects method
ast-grep --pattern 'def create_expense_objects($$$) {
  $$$
  try {
    $$$
  } catch {
    $$$
  }
  $$$
}'

Length of output: 378

'fund_source': SOURCE_ACCOUNT_MAP[expense['source_account_type']],
'verified_at': expense['verified_at'],
'custom_properties': expense['custom_properties'],
Expand Down
Loading