Skip to content

Feat: Added persistance to the cl#13

Merged
xenonnn4w merged 1 commit intocyclohexane-2:mainfrom
darshan2006-op:add-feature-8
Dec 12, 2025
Merged

Feat: Added persistance to the cl#13
xenonnn4w merged 1 commit intocyclohexane-2:mainfrom
darshan2006-op:add-feature-8

Conversation

@darshan2006-op
Copy link
Contributor

@darshan2006-op darshan2006-op commented Nov 23, 2025

Data persistence has been implemented with all the requirements.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR implements data persistence for the student management CLI application, allowing assignments and grades to be saved and loaded from a JSON file.

Key Changes:

  • Added custom JSON encoder/decoder classes to handle datetime serialization
  • Implemented save/load functionality in StudentManager with error handling for missing or corrupted files
  • Integrated persistence into the main application flow to automatically load on startup and save on exit

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 10 comments.

File Description
utils.py Added DateTimeEncoder/DateTimeDecoder classes for datetime serialization and enhanced error handling in load_from_json
student_manager.py Added persistence methods (dump_manager, load_manager) and serialization helpers (__ser_object, __deser_object)
main.py Integrated data loading on startup and saving on exit with error handling for corrupted files
.gitignore Added blank line (formatting change)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 4 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +63 to +70
return {
"status": 1
}
except json.JSONDecodeError as e:
os.remove(filename)
return {
"status": 2
}
Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

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

The return value structure is inconsistent. When successful, the function returns the actual data dictionary, but on error it returns a status dictionary with a "status" key. This makes it difficult for callers to distinguish between actual data that might contain a "status" key and error conditions. Consider using a more explicit pattern like returning a tuple (data, status) or raising exceptions for error cases.

Copilot uses AI. Check for mistakes.
utils.py Outdated
Comment on lines 21 to 29
"""Handles special case of date deserialization"""
for key, value in obj.items():
if isinstance(value, str):
try:
obj[key] = datetime.fromisoformat(value)
except ValueError:
pass # Not a datetime string
return obj

Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

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

The object_hook method iterates over dictionary items and attempts to modify the dictionary during iteration, which can work but only handles top-level datetime strings. Nested dictionaries or lists containing datetime strings won't be properly converted. Additionally, this approach will attempt to parse every string value as a datetime, which could be inefficient for large objects with many string fields.

Suggested change
"""Handles special case of date deserialization"""
for key, value in obj.items():
if isinstance(value, str):
try:
obj[key] = datetime.fromisoformat(value)
except ValueError:
pass # Not a datetime string
return obj
"""Handles special case of date deserialization, including nested structures"""
return self._decode_dates(obj)
def _decode_dates(self, value):
if isinstance(value, dict):
return {k: self._decode_dates(v) for k, v in value.items()}
elif isinstance(value, list):
return [self._decode_dates(item) for item in value]
elif isinstance(value, str):
try:
return datetime.fromisoformat(value)
except ValueError:
return value
else:
return value

Copilot uses AI. Check for mistakes.
if "status" in data:
status = data.get("status")
return cls(), status
return cls.__deser_object(data), 0
Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

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

Missing cls parameter in the call to __deser_object. Should be cls._StudentManager__deser_object(data) due to name mangling, or better yet, change the method to use single underscore as noted in another comment.

Copilot uses AI. Check for mistakes.
def dump_manager(self):
"""Dumps data into json file for persistence"""
data = self.__ser_object()
save_to_json(data, self.persistence_FILE_NAME)
Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

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

Typo in method name: persistence_FILE_NAME should be PERSISTENCE_FILE_NAME to match the constant defined at line 10.

Suggested change
save_to_json(data, self.persistence_FILE_NAME)
save_to_json(data, self.PERSISTENCE_FILE_NAME)

Copilot uses AI. Check for mistakes.

def __ser_object(self):
"""
Protected method to aggrigate data
Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

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

Typo in comment: aggrigate should be aggregate.

Suggested change
Protected method to aggrigate data
Protected method to aggregate data

Copilot uses AI. Check for mistakes.
@xenonnn4w
Copy link
Contributor

fix these, rest lgtm!

@xenonnn4w
Copy link
Contributor

Also do squash your commits into one with a better commit message, Thanks!

@xenonnn4w
Copy link
Contributor

Resolve the conflict with the main, i.e. rebase it to upstream. Also mark the conversation resolved if you are done with that.

@xenonnn4w xenonnn4w requested a review from Copilot December 11, 2025 13:53
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 4 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

utils.py:1

  • Corrected spelling of 'aggrigate' to 'aggregate'.
"""

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@darshan2006-op darshan2006-op force-pushed the add-feature-8 branch 2 times, most recently from bb3a203 to 81eecfa Compare December 11, 2025 17:09
@xenonnn4w
Copy link
Contributor

Lgtm thanks!

@xenonnn4w xenonnn4w merged commit d2c399f into cyclohexane-2:main Dec 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants