Repository: oppia/oppia
File: core/controllers/blog_dashboard.py (Python)

Code before:
        'DELETE': {},
    }

    @acl_decorators.can_access_blog_dashboard
    def get(self, blog_post_id: str) -> None:
        """Populates the data on the blog dashboard editor page.

        Args:
            blog_post_id: str. The ID of the blog post.

        Raises:
            NotFoundException. The blog post with the given id
                or url doesn't exist.
        """
        blog_post = blog_services.get_blog_post_by_id(
            blog_post_id, strict=False
        )
        if blog_post is None:
            raise self.NotFoundException(
                'The blog post with the given id or url doesn\'t exist.'
            )

        author_details = blog_services.get_blog_author_details(
            blog_post.author_id
        )
        assert author_details is not None
        max_no_of_tags = platform_parameter_services.get_platform_parameter_value(
            platform_parameter_list.ParamName.MAX_NUMBER_OF_TAGS_ASSIGNED_TO_BLOG_POST.value
        )
        list_of_default_tags = constants.LIST_OF_DEFAULT_TAGS_FOR_BLOG_POST

        blog_post_dict = blog_post.to_dict()
        blog_post_dict_for_dashboard = {
            'id': blog_post_dict['id'],
            'title': blog_post_dict['title'],
            'displayed_author_name': author_details.displayed_author_name,
            'content': blog_post_dict['content'],
            'url_fragment': blog_post_dict['url_fragment'],
            'tags': blog_post_dict['tags'],
            'thumbnail_filename': blog_post_dict['thumbnail_filename'],
            'last_updated': blog_post_dict['last_updated'],
            'published_on': blog_post_dict['published_on'],
        }
        self.values.update(
            {
                'blog_post_dict': blog_post_dict_for_dashboard,
                'displayed_author_name': author_details.displayed_author_name,
                'max_no_of_tags': max_no_of_tags,
                'list_of_default_tags': list_of_default_tags,
            }
        )

Review comment (bug):
Ditto? Why are we only checking against None? Wouldn't `require_valid_displayed_author_name` be more helpful?

Also, I'd rather see a proper Exception with a helpful debug information that includes relevant debug details than a simple `assert` statement.

Think of it from a server maintainers perspective: if this were to happen in production, what information do I need to know to diagnose the problem? `author_details is not None failed` is useless, I want to know WHY it matters and HOW to find the root cause.

Code after:

        Raises:
            NotFoundException. The blog post with the given id
                or url doesn't exist.
        """
        blog_post = blog_services.get_blog_post_by_id(
            blog_post_id, strict=False
        )
        if blog_post is None:
            raise self.NotFoundException(
                'The blog post with the given id or url doesn\'t exist.'
            )

        author_details = blog_services.get_blog_author_details(
            blog_post.author_id
        )
        max_no_of_tags = platform_parameter_services.get_platform_parameter_value(
            platform_parameter_list.ParamName.MAX_NUMBER_OF_TAGS_ASSIGNED_TO_BLOG_POST.value
        )
        list_of_default_tags = constants.LIST_OF_DEFAULT_TAGS_FOR_BLOG_POST

        blog_post_dict = blog_post.to_dict()
        blog_post_dict_for_dashboard = {
            'id': blog_post_dict['id'],
            'title': blog_post_dict['title'],
            'displayed_author_name': author_details.displayed_author_name,
            'content': blog_post_dict['content'],
            'url_fragment': blog_post_dict['url_fragment'],
            'tags': blog_post_dict['tags'],
            'thumbnail_filename': blog_post_dict['thumbnail_filename'],
            'last_updated': blog_post_dict['last_updated'],
            'published_on': blog_post_dict['published_on'],
        }
        self.values.update(
            {
                'blog_post_dict': blog_post_dict_for_dashboard,
                'displayed_author_name': author_details.displayed_author_name,
                'max_no_of_tags': max_no_of_tags,
                'list_of_default_tags': list_of_default_tags,
            }
        )

        self.render_json(self.values)

    @acl_decorators.can_edit_blog_post
    def put(self, blog_post_id: str) -> None:
        """Updates properties of the given blog post.

        Args:
            blog_post_id: str. The ID of the blog post.
        """