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

fix: type error bug in convert_tbl_column_to_sqla_col #31780

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Mine-Echo
Copy link

@Mine-Echo Mine-Echo commented Jan 10, 2025

SUMMARY

    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

I am developpydolphindb to adapt superset to DolphinDB
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.

class UUID(sqltypes.BINARY):
    __visit_name__ = "UUID"

    def literal_processor(self, dialect):
        def process(value):
            if value is not None:
                value = f'uuid("{value}")'
            return value

        return process

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.
The right SQL script after I modify self.type to tbl_column.type:
image
The issue: #31695

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

TESTING INSTRUCTIONS

Now can only test by adding breakpoint at this line and print self.type and tbl_column,type.
Our pydolphindb has not been released yet and is expected to be released at the end of the month

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

Description by Korbit AI

What change is being made?

Fix a type error bug in the convert_tbl_column_to_sqla_col function by correctly using tbl_column.type instead of self.type when fetching the column specification.

Why are these changes being made?

The previous implementation incorrectly passed self.type to the get_column_spec method, which likely resulted in an incorrect or failed type conversion. Changing it to use tbl_column.type ensures that the column's actual type is used, aligning with the intended logic and fixing the type error.

Is this description stale? Ask me to generate a new description by commenting /korbit-generate-pr-description

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Congrats on making your first PR and thank you for contributing to Superset! 🎉 ❤️

We hope to see you in our Slack community too! Not signed up? Use our Slack App to self-register.

Copy link

@korbit-ai korbit-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review by Korbit AI

Korbit automatically attempts to detect when you fix issues in new commits.
Category Issue Fix Detected
Functionality Missing type null check ▹ view
Files scanned
File Path Reviewed
superset/models/helpers.py

Explore our documentation to understand the languages and file types we support and the files we ignore.

Need a new review? Comment /korbit-review on this PR and I'll review your latest changes.

Korbit Guide: Usage and Customization

Interacting with Korbit

  • You can manually ask Korbit to review your PR using the /korbit-review command in a comment at the root of your PR.
  • You can ask Korbit to generate a new PR description using the /korbit-generate-pr-description command in any comment on your PR.
  • Too many Korbit comments? I can resolve all my comment threads if you use the /korbit-resolve command in any comment on your PR.
  • Chat with Korbit on issues we post by tagging @korbit-ai in your reply.
  • Help train Korbit to improve your reviews by giving a 👍 or 👎 on the comments Korbit posts.

Customizing Korbit

  • Check out our docs on how you can make Korbit work best for you and your team.
  • Customize Korbit for your organization through the Korbit Console.

Current Korbit Configuration

General Settings
Setting Value
Review Schedule Automatic excluding drafts
Max Issue Count 10
Automatic PR Descriptions
Issue Categories
Category Enabled
Naming
Database Operations
Documentation
Logging
Error Handling
Systems and Environment
Objects and Data Structures
Readability and Maintainability
Asynchronous Processing
Design Patterns
Third-Party Libraries
Performance
Security
Functionality

Feedback and Support

Note

Korbit Pro is free for open source projects 🎉

Looking to add Korbit to your team? Get started with a free 2 week trial here

@@ -1419,7 +1419,7 @@ def convert_tbl_column_to_sqla_col(
) -> 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)
column_spec = db_engine_spec.get_column_spec(tbl_column.type, db_extra=self.db_extra)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing type null check category Functionality

Tell me more
What is the issue?

Missing null check for tbl_column.type before calling get_column_spec

Why this matters

If tbl_column.type is None, get_column_spec() may raise an error since some database engines cannot handle None type inputs.

Suggested change ∙ Feature Preview

Add null check before getting column spec:

column_spec = None
if tbl_column.type is not None:
    column_spec = db_engine_spec.get_column_spec(tbl_column.type, db_extra=self.db_extra)
Chat with Korbit by mentioning @korbit-ai, and give a 👍 or 👎 to help Korbit improve your reviews.

@michael-s-molina michael-s-molina changed the title fix type error bug in convert_tbl_column_to_sqla_col fix: type error bug in convert_tbl_column_to_sqla_col Jan 10, 2025
Copy link

codecov bot commented Jan 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 65.52%. Comparing base (76d897e) to head (f8af758).
Report is 1301 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #31780      +/-   ##
==========================================
+ Coverage   60.48%   65.52%   +5.03%     
==========================================
  Files        1931      538    -1393     
  Lines       76236    39011   -37225     
  Branches     8568        0    -8568     
==========================================
- Hits        46114    25562   -20552     
+ Misses      28017    13449   -14568     
+ Partials     2105        0    -2105     
Flag Coverage Δ
hive 48.84% <0.00%> (-0.32%) ⬇️
javascript ?
presto 53.37% <100.00%> (-0.44%) ⬇️
python 65.52% <100.00%> (+2.03%) ⬆️
unit 61.04% <100.00%> (+3.42%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

Successfully merging this pull request may close these issues.

1 participant