-
Notifications
You must be signed in to change notification settings - Fork 0
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: expense migration #176
Conversation
WalkthroughThis pull request introduces a migration and model update in the Changes
Possibly related PRs
Suggested labels
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
|
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: 2
🧹 Outside diff range and nitpick comments (3)
apps/fyle/migrations/0004_expense_is_posted_at_null.py (1)
13-17
: Consider adding an index for query performance.The migration looks good structurally. Since this field might be used in filtering queries (e.g., finding expenses with null posted_at), consider adding a database index if this field will be frequently queried.
If you expect frequent queries on this field, you can modify the field definition to include an index:
-field=models.BooleanField(default=False, help_text='Flag check if posted at is null or not'), +field=models.BooleanField(default=False, help_text='Flag check if posted at is null or not', db_index=True),apps/fyle/models.py (2)
148-148
: Consider adding model-level validation foris_posted_at_null
The new field should be kept in sync with the
posted_at
field's null status. Consider adding a model-level validation to ensure consistency.class Expense(BaseForeignWorkspaceModel): + def clean(self): + super().clean() + if self.is_posted_at_null != (self.posted_at is None): + raise ValidationError({ + 'is_posted_at_null': 'Field value must match posted_at null status' + })
148-148
: Update method documentationThe
create_expense_objects
method's docstring should be updated to include the newis_posted_at_null
field in the expected input format.@staticmethod def create_expense_objects(expenses: List[Dict], workspace_id: int, skip_update: bool = False): """ Bulk create expense objects + + Args: + expenses: List of dictionaries containing expense data + Required fields: [...existing fields...] + is_posted_at_null: Boolean indicating if posted_at is null + workspace_id: Integer workspace identifier + skip_update: Boolean to skip certain field updates """
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
apps/fyle/migrations/0004_expense_is_posted_at_null.py
(1 hunks)apps/fyle/models.py
(1 hunks)
🔇 Additional comments (1)
apps/fyle/models.py (1)
148-148
: Verify migration and field usage
Let's verify the migration file and any queries using this field.
✅ Verification successful
Migration and field usage verified successfully
The verification shows:
- Migration file
0004_expense_is_posted_at_null.py
exists and properly adds the boolean field with default value - Field is only used in models.py for definition and serialization
- No existing queries depend on this field, suggesting it's a new addition
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Check if migration file exists and contains the field
echo "Checking migration file..."
fd --type f "0004_expense_is_posted_at_null.py" apps/fyle/migrations/
# Check for any queries using this field
echo "Checking field usage in queries..."
rg "is_posted_at_null" --type py
Length of output: 610
Script:
#!/bin/bash
# Let's check the content of the migration file
echo "Checking migration file content..."
cat apps/fyle/migrations/0004_expense_is_posted_at_null.py
# Let's also check for any tests using this field
echo "Checking test files..."
rg "is_posted_at_null" --type py --glob "*test*.py"
Length of output: 704
operations = [ | ||
migrations.AddField( | ||
model_name='expense', | ||
name='is_posted_at_null', | ||
field=models.BooleanField(default=False, help_text='Flag check if posted at is null or not'), | ||
), | ||
] |
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.
Add data migration for existing records.
The migration adds the field with a default False value, but existing records should have this field populated based on their actual posted_at
values. Consider adding a data migration to set the correct values.
Would you like me to help create a data migration that:
- Queries all existing expenses
- Sets
is_posted_at_null=True
for records whereposted_at IS NULL
- Sets
is_posted_at_null=False
for records whereposted_at IS NOT NULL
@@ -145,6 +145,7 @@ def create_expense_objects(expenses: List[Dict], workspace_id: int, skip_update: | |||
'report_id': expense['report_id'], | |||
'spent_at': expense['spent_at'], | |||
'posted_at': expense['posted_at'], | |||
'is_posted_at_null': expense['is_posted_at_null'], |
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.
🛠️ Refactor suggestion
Add input validation for is_posted_at_null
The method assumes is_posted_at_null
will be present in the input dictionary. Consider adding validation or a default value to handle missing or invalid data.
defaults = {
- 'is_posted_at_null': expense['is_posted_at_null'],
+ 'is_posted_at_null': bool(expense.get('is_posted_at_null', False)),
'fund_source': SOURCE_ACCOUNT_MAP[expense['source_account_type']],
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
'is_posted_at_null': expense['is_posted_at_null'], | |
'is_posted_at_null': bool(expense.get('is_posted_at_null', False)), |
|
|
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: 0
🧹 Outside diff range and nitpick comments (2)
tests/test_fyle/test_tasks.py (2)
46-46
: Remove debug print statement.Debug print statements should not be committed to the codebase. Please remove this line as it adds noise to the test output.
- print(payload['data'])
Line range hint
12-71
: Add test coverage foris_posted_at_null
field.The test should verify the behavior of the newly added
is_posted_at_null
field in the Expense model. Consider adding assertions to check:
- The field is correctly set when expenses are created/updated
- The field's impact on expense updates through webhooks
Example additions:
# After expense creation assert expense_created.is_posted_at_null == True # or expected value # After update expense = Expense.objects.get(expense_id='txhJLOSKs1iN', org_id=org_id) assert expense.is_posted_at_null == True # or expected value
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (4)
apps/fyle/models.py
(2 hunks)requirements.txt
(1 hunks)tests/test_fyle/fixtures.py
(3 hunks)tests/test_fyle/test_tasks.py
(2 hunks)
✅ Files skipped from review due to trivial changes (1)
- requirements.txt
🚧 Files skipped from review as they are similar to previous changes (2)
- apps/fyle/models.py
- tests/test_fyle/fixtures.py
🔇 Additional comments (2)
tests/test_fyle/test_tasks.py (2)
3-9
: LGTM! Import organization looks good.
The imports are now well-organized, following a logical grouping pattern from external to internal dependencies.
Line range hint 12-71
: Verify test fixtures include the new field.
Let's verify that the test fixtures are properly updated with the new is_posted_at_null
field.
✅ Verification successful
Test fixtures are properly updated with the new field
The test fixtures in tests/test_fyle/fixtures.py
include the is_posted_at_null
field in both the raw_expense
and default_raw_expense
fixtures with appropriate values:
raw_expense
:'is_posted_at_null': True
default_raw_expense
:'is_posted_at_null': True
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Check if test fixtures include the new is_posted_at_null field
# Search for is_posted_at_null in fixture files
rg "is_posted_at_null" tests/test_fyle/fixtures.py
# Show the raw_expense and default_raw_expense fixtures
rg -A 10 "raw_expense = \{|default_raw_expense = \{" tests/test_fyle/fixtures.py
Length of output: 243
Script:
#!/bin/bash
# Let's get more context around the fixtures by showing the entire fixtures.py file
cat tests/test_fyle/fixtures.py
Length of output: 22841
|
apps/fyle/models.py
Outdated
@@ -104,6 +104,7 @@ def create_expense_objects(expenses: List[Dict], workspace_id: int, skip_update: | |||
|
|||
# Create an empty list to store expense objects | |||
expense_objects = [] | |||
print(expenses) |
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.
print pls remove
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.
removed sir
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.
fixed
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #176 +/- ##
==========================================
+ Coverage 96.38% 96.44% +0.06%
==========================================
Files 90 90
Lines 4981 5041 +60
==========================================
+ Hits 4801 4862 +61
+ Misses 180 179 -1 ☔ View full report in Codecov by Sentry. 🚨 Try these New Features:
|
|
Description
fix: expense migration
Clickup
https://app.clickup.com/
Summary by CodeRabbit
New Features
is_posted_at_null
, to track the posting status of expenses.Bug Fixes
Chores
fyle-integrations-platform-connector
to the latest version.