From 55c0c6e6041a85ebca7f8efa144bf187e447298a Mon Sep 17 00:00:00 2001 From: Jake Radcliff Date: Fri, 7 Nov 2025 22:22:23 -0700 Subject: [PATCH] Fix AttributeError: 'NoneType' object has no attribute 'value' in download_runner When post_sort_method is NULL in database records, download_runner.py line 372 crashes with AttributeError when accessing sort_method.value. This occurs during user/subreddit downloads with legacy records or incomplete migrations. Stack trace: download_runner.py:372 in get_raw_submissions AttributeError: 'NoneType' object has no attribute 'value' Add null check with fallback to PostSortMethod.NEW (schema default) before accessing sort_method.value. Updates the record in-place on first access to prevent subsequent errors. No migration required - NULL values are handled at runtime and auto-corrected. Resolves crash when downloading from users/subreddits with NULL sort method. --- DownloaderForReddit/core/download_runner.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/DownloaderForReddit/core/download_runner.py b/DownloaderForReddit/core/download_runner.py index 5fc08b7..ae9074e 100644 --- a/DownloaderForReddit/core/download_runner.py +++ b/DownloaderForReddit/core/download_runner.py @@ -368,7 +368,16 @@ def get_raw_submissions(self, praw_object, reddit_object): and limit the submission generator. :return: A submission generator for the supplied praw object. """ + from ..database.model_enums import PostSortMethod sort_method = reddit_object.post_sort_method + # Handle None case by falling back to default + if sort_method is None: + self.logger.warning( + f'post_sort_method is None for {reddit_object.object_type} {reddit_object.name}, ' + f'using default PostSortMethod.NEW' + ) + sort_method = PostSortMethod.NEW + reddit_object.post_sort_method = PostSortMethod.NEW if sort_method.value <= 4: submission_method = self.get_raw_submission_method(praw_object, sort_method.name.lower()) return submission_method(limit=reddit_object.post_limit)