Skip to content

view_information should raise instead of warn #330

@coldnebo

Description

@coldnebo

In SchemaStatements#view_information line 337:

view_info[:VIEW_DEFINITION] = begin
    select_values("EXEC sp_helptext #{quote_table_name(table_name)}", 'SCHEMA').join
  rescue
    warn "No view definition found, possible permissions problem.\nPlease run GRANT VIEW DEFINITION TO your_user;"
    nil
  end

The condition indicated by the warn is serious enough to require a raise instead.

For example, one of our read-only models uses a view. Since there is no migration, it is critical that permission to run sp_helptext is granted, but since this assignment returns nil, we get a meaningless error somewhere later in Model.find():

ReportDetails view exception: undefined method `match' for nil:NilClass 

This error comes from deep in the rails stack without providing a clear indication of what happened. For the curious it's caused by the function views_real_column_name in line 351 in schema_statements.rb which is invoked during find():

match_data = view_definition.match(/([\w-]*)\s+as\s+#{column_name}/im)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions