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

Support special characters for similarity queries #1182

Closed
wants to merge 1 commit into from

Conversation

loicgasser
Copy link
Contributor

This PR is for: geoadmin/mf-geoadmin3#2009

At some point the where unicode will be converted to byte str and will fail because for some reason we have non-ASCII unicode strings.

The famous UnicodeError ...

Here we

  1. Build a query to postrges can understand (Escaping the \ and telling postrgres to escape it with E)
  2. We convert to byte str and replace unmapped characters with ? that we finally replace with %

It's a workaround but it works fine.
If anybody has a better solution/understanding of what's going on please feel free.

Current Link in prod

Deployed Branch in test

@cedricmoullet
Copy link
Contributor

@procrastinatio please review

@procrastinatio
Copy link
Contributor

Hmm, do not understand why you have to convert to ascii, the column type in the model should be sqlalchemy.types.Unicode

match.group(2).replace('\'', '\\\''),
match.group(3)
))
where = where.encode('ascii', 'replace')
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you need to convert to ascii ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because sqlAlchemy uses ascii to build plain SQL requests (this is where it fails).
replace argument replaces all the non-ascii characters with ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Not really up to date here, but e.g. ü is a non-ascii character, but doesn't cause any problems?

@procrastinatio
Copy link
Contributor

The error is unrelated to encoding errors, it is simply a matter of properly escape special characters in the partial SQL request. Normally, it is best to leave SQLAlchemy do the job.

@procrastinatio
Copy link
Contributor

OK.

@loicgasser
Copy link
Contributor Author

I know why prod and dev are behaving diffrently. pyramid_debugtoolbar is bugged see Pylons/pyramid_debugtoolbar#60

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

Successfully merging this pull request may close these issues.

None yet

4 participants