Skip to content

$ sign in fn method causing issues #14273

Closed

Description

@jamesicon

Issue Creation Checklist

Bug Description

I have a function that looks like this

  User.findByUsername = async (username) => {
    let user = await User.findOne({
      where: {
        username: sequelize.where(
          sequelize.fn('LOWER', sequelize.col('username')),
          '=',
          sequelize.fn('LOWER', username)
        ),
      },
    });
    return user;
  };

if the username includes a $ symbol the lookup always fails. I dug around in the source code and found if I changed Line 1611 in the query-generator.js file from:

return this.escape(typeof arg === "string" ? arg.replace("$", "$$$") : arg);

to:

return this.escape(typeof arg === "string" ? arg.replace("$", "$$") : arg);

everything works properly. I'm not familiar with this codebase so unsure of why "$$$" was originally put but it is breaking things for me.

SSCCE

Here is the link to the SSCCE for this issue: LINK-HERE

What do you expect to happen?

The query of username="money$" should have returned Foo where there username was "money$"

What is actually happening?

the output as null

Additional context

Add any other context and details here.

Environment

  • Sequelize version: 6.17.0
  • Node.js version: v14.17.0
  • If TypeScript related: TypeScript version:
  • Database & Version: PostgreSQL 13
  • Connector library & Version: pg

Would you be willing to resolve this issue by submitting a Pull Request?

  • Yes, I have the time and I know how to start.
  • Yes, I have the time but I don't know how to start, I would need guidance.
  • [x ] No, I don't have the time, although I believe I could do it if I had the time...
  • No, I don't have the time and I wouldn't even know how to start.

Activity

  1. ephys commented on Mar 25, 2022

    @ephys
    Member

    Likely related to #13817

  2. github-actions commented on Apr 9, 2022

    @github-actions
    Contributor

    This issue has been automatically marked as stale because it has been open for 14 days without activity. It will be closed if no further activity occurs within the next 14 days. If this is still an issue, just leave a comment or remove the "stale" label. 🙂

  3. ephys commented on Apr 24, 2022

    @ephys
    Member

    This is being fixed but we're tracking it in that linked issue

  4. ephys commented on Apr 25, 2022

    @ephys
    Member

    I've now removed the piece of code you linked to in PR #14447. It was a bad band-aid for a deeper problem, which I am fixing.

    I'll re-open because it's not strictly the same issue as #13817

  5. reopened this on Apr 25, 2022
  6. added
    type: bug
    and removed on Apr 25, 2022
  7. jamesicon commented on Apr 25, 2022

    @jamesicon
    Author

    Awesome thank you @ephys

  8. ephys commented on Apr 26, 2022

    @ephys
    Member

    The fix is ready, but the bad news is that this change is a breaking change, so I can only release this in Sequelize 7

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

    type: bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions