Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

type error in convert_tbl_column_to_sqla_col #31695

Open
3 tasks done
Mine-Echo opened this issue Jan 3, 2025 · 2 comments
Open
3 tasks done

type error in convert_tbl_column_to_sqla_col #31695

Mine-Echo opened this issue Jan 3, 2025 · 2 comments

Comments

@Mine-Echo
Copy link

Mine-Echo commented Jan 3, 2025

Bug description

function convert_tbl_column_to_sqla_col is at superset/models/helpers.py
https://github.com/apache/superset/blob/master/superset/models/helpers.py#L1403

    def convert_tbl_column_to_sqla_col(
        self,
        tbl_column: "TableColumn",
        label: Optional[str] = None,
        template_processor: Optional[BaseTemplateProcessor] = None,
    ) -> Column:
        label = label or tbl_column.column_name
        db_engine_spec = self.db_engine_spec
        column_spec = db_engine_spec.get_column_spec(self.type, db_extra=self.db_extra)
        type_ = column_spec.sqla_type if column_spec else None
        if expression := tbl_column.expression:
            if template_processor:
                expression = template_processor.process_template(expression)
            col = literal_column(expression, type_=type_)
        else:
            col = sa.column(tbl_column.column_name, type_=type_)
        col = self.make_sqla_column_compatible(col, label)
        return col

why here use self.type but not tbl.column? I think the latter is right.
column_spec = db_engine_spec.get_column_spec(self.type, db_extra=self.db_extra)
When debugging, I found self,type is "table", then column_spec will be None. I think self.type is not native type of the column, here we should pass tal_column. type, which is "IPADDR" in my case.
After I modify this, I successfully processed data types by literal_processor while using filters. For example, I process "127.0.0.1" to "ipaddr("127.0.0.1")" when filtering.
Is this really a bug in superset? Or did I just understand it wrong somewhere?

Screenshots/recordings

No response

Superset version

master / latest-dev

Python version

3.11

Node version

16

Browser

Chrome

Additional context

No response

Checklist

  • I have searched Superset docs and Slack and didn't find a solution to my problem.
  • I have searched the GitHub issue tracker and didn't find a similar bug report.
  • I have checked Superset's logs for errors and if I found a relevant Python stacktrace, I included it here as text in the "additional context" section.
Copy link

dosubot bot commented Jan 3, 2025

The issue you're encountering with the convert_tbl_column_to_sqla_col function, where self.type is used instead of tbl_column.type, does appear to be a bug. The use of self.type results in None for column_spec, which is not the intended behavior. Changing it to tbl_column.type resolves the issue by correctly using the type of the table column being converted [1].

There is a similar unsolved discussion on this topic, which you might find relevant: Why use self.type in function "convert_tbl_column_to_sqla_col" [2].

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other

@Mine-Echo
Copy link
Author

The discussion is opened by me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant