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: Keep module state when editing students #64

Merged
merged 2 commits into from
Apr 4, 2024

Conversation

taufiq
Copy link

@taufiq taufiq commented Apr 3, 2024

This addresses a bug (#61) pointed out by @blaukc where if we edit a student using the edit command and don't intend to change their modules, their module state gets completely wiped.

When we parse the EditCommand we create an EditStudentDescriptor instance which by default is initialized as a List with 0 entries.

So when executing the command we use the getModules function to decide if we want to keep the old module state or replace it with new module state. The bug was that the logic for the for getModules always returns a non-null Optional value (because it checks if modules is null which never happens bcos always initialised with empty list), thereby always taking the empty list of modules from the EditStudentDescriptor instance and not the old Student instance, thus wiping out the modules state.

This commit initializes modules as null so that getModules works as intended.

This addresses a bug pointed out by @blaukc where if we edit a student using the `edit` command and don't intend to change their modules, their module state gets completely wiped.

When we parse the `EditCommand` we create an `EditStudentDescriptor` instance which by default is initialized as a List with 0 entries.

So when executing the command we use the `Optional` `getModules` function to decide if we want to keep the old module state or replace it with new module state that we provided in the command. The bug was that the logic for the for `getModules` always returns a non-null `Optional` value (because it checks if `modules` is null which never happens bcos always initialised with empty list), thereby always taking the empty list of modules from the `EditStudentDescriptor` instance and not the old `Student` instance, thus wiping out the modules state.

This commit initializes `modules` as `null` so that `getModules` works as intended.
@taufiq taufiq requested a review from a team April 3, 2024 09:50
Copy link

codecov bot commented Apr 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 59.73%. Comparing base (0e07720) to head (dfa5198).

Additional details and impacted files
@@             Coverage Diff              @@
##             master      #64      +/-   ##
============================================
+ Coverage     59.64%   59.73%   +0.08%     
  Complexity      434      434              
============================================
  Files            91       91              
  Lines          1819     1818       -1     
  Branches        178      179       +1     
============================================
+ Hits           1085     1086       +1     
  Misses          696      696              
+ Partials         38       36       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

@blaukc blaukc left a comment

Choose a reason for hiding this comment

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

Feels a bit hacky but it works LGTM good simple fix

@taufiq taufiq merged commit c90eaa0 into master Apr 4, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants