Skip to content

[REF-3160] [VarOps] It is way too easy to pass incorrect kwargs to rx.Var._replace #3531

Closed

Description

@masenf

Describe the bug
This _replace func accepts arbitrary kwargs, pulls out the ones it recognizes, and passes those off to BaseVar constructor. Meanwhile, any remainin unrecognized kwargs are just jettisoned without any errors.

This means if I pass _merge_var_data instead of merge_var_data, it silently does the wrong thing.

To Reproduce

rx.Var.create("foo")._replace(_this_should_fail=True)

Expected behavior
The line of code above should raise some TypeError or similar. Instead it returns a new Var with nothing changed.

REF-3160

Activity

  1. added
    bug
    on Jun 20, 2024
  2. changed the title [-][VarOps] It is way too easy to pass incorrect kwargs to `rx.Var._replace`[/-] [+][REF-3160] [VarOps] It is way too easy to pass incorrect kwargs to `rx.Var._replace`[/+] on Jun 20, 2024
  3. added this to the milestone on Jun 21, 2024
  4. Manas1820 commented on Jun 22, 2024

    @Manas1820
    Contributor

    Hey @masenf

    I noticed in vars.py that the _replace function typically takes class variables of BaseVars, Vars, or ComputedVar as kwargs. I propose a solution to create a custom decorator for verifying kwargs.

    In this decorator, we can either pass the class and it will automatically consider the class variables, or we can pass a set of expected kwargs, if the values passes is outside the set it will throw and TypeError. This decorator might be useful at multiple places too .

    Let me know your thoughts on this !

  5. modified the milestones: , , on Jul 3, 2024
  6. added
    bug
    and removed
    bug
    on Sep 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions