pre_get_posts Tax Query not working for custom author page

I am using the theme TwentyTwelve and modified the standard post query in the file author.php with the following code:

function wpd_author_query( $query ) {
//CODE to set $current_user_name here
//This gets the author from the URL
$author = get_user_by('slug',get_query_var('author_name'));
$current_user_name = $author->user_nicename;

    if ( $query->is_author() && $query->is_main_query()) {
            // your code to set $current_user_name here
            $query->set( 'meta_key', '_writer_relation_added_date_'.$current_user_name );
            $query->set( 'orderby', 'meta_value_num' );
            $query->set( 'post_status', $post_status );

            $tax_query = array(  
                array(
                    'taxonomy' => 'writer',
                    'field' => 'name',
                    'terms' => $current_user_name
                )
            );
            $query->set( 'tax_query', $tax_query );
    }               
}
add_action( 'pre_get_posts', 'wpd_author_query' );

However, the tax_query is not working for the author page. It is still not retrieving the posts in the writer taxonomy.

I did try applying that code for other pages such as is_home() is_archive() and it does work.

So, there must be a conflict in with wordpress and the author template page that is not allowing me to use the tax_query for retrieving posts in the writer taxonomy.

Solutions Collecting From Web of "pre_get_posts Tax Query not working for custom author page"

Don’t run a new query in the template, modify the main query before it’s run via the pre_get_posts action in the theme’s functions.php file.

function wpd_author_query( $query ) {
    if ( $query->is_author()
        && $query->is_main_query() ) {
            // your code to set $current_user_name here
            $query->set( 'meta_key', '_writer_relation_added_date_' . $current_user_name );
            $query->set( 'orderby', 'meta_value_num' );
            $tax_query = array(  
                array(
                    'taxonomy' => 'writer',
                    'field' => 'name',
                    'terms' => $current_user_name
                )
            )
            $query->set( 'tax_query', $tax_query );

            // EDIT
            // unset the requested author
            unset( $query->query_vars['author_name'] );
    }
}
add_action( 'pre_get_posts', 'wpd_author_query' );

You can then run the vanilla loop in the default author template, and save an extra query in the process.