Comments (8)
Hi,
I think this is expected behaviour. A string is interpreted as an url, so the ?
delimits the query from the path.
from sqlalchemy.
it looks like a bug . they are creating the URL programattically. The name of the database is a?b=c
. that should round trip.
That said, nobody would ever have a database name like that. so what's the XY problem here? (e.g. what do you actually need to do ?)
from sqlalchemy.
@CaselIT Hi, I might have been confusing:
I understand that if I pass sqlite:///a?b=c
then, b=c are parsed as query and it is expected
What in my view is not expected is the fact, that first_url_as_string contains this ? directly (instead of some kind of escaping, e.g urlencoded, etc), so that it would roundtrip well
from sqlalchemy.
this is the patch, this is for 2.1 only as URL adjustments are extremely high risk
diff --git a/lib/sqlalchemy/engine/url.py b/lib/sqlalchemy/engine/url.py
index 1eeb73a23..7565252c7 100644
--- a/lib/sqlalchemy/engine/url.py
+++ b/lib/sqlalchemy/engine/url.py
@@ -641,7 +641,7 @@ class URL(NamedTuple):
if self.port is not None:
s += ":" + str(self.port)
if self.database is not None:
- s += "/" + self.database
+ s += "/" + quote_plus(self.database)
if self.query:
keys = list(self.query)
keys.sort()
@@ -888,11 +888,10 @@ def _parse_url(name: str) -> URL:
query = None
components["query"] = query
- if components["username"] is not None:
- components["username"] = unquote(components["username"])
+ for comp in "username", "password", "database":
+ if components[comp] is not None:
+ components[comp] = unquote(components[comp])
- if components["password"] is not None:
- components["password"] = unquote(components["password"])
ipv4host = components.pop("ipv4host")
ipv6host = components.pop("ipv6host")
from sqlalchemy.
I tried to understand whether I needed to escape my path when building an URL as a string (we don't have any strange character in the path to database but I wanted to fix it just in case). I've found that I can use URL class.
But while I was playing with it, I've noticed that behaviour is not what I expected
So, this behaviour doesn't bother me, I've already solved my problem, just decided to report what for me looks like a bug
from sqlalchemy.
I fear that the patch above will break existing use cases, since I'm not sure what all the various db driver would do in this case.
tried to create a db named "my?db=1" in pg and all kind of tools are failing to connect. Like I can't manage to connect using psql... Psycopg2 works though
from sqlalchemy.
this is less sensitive than "password". this breaks if someone had a database named "a%3Fb%3Dc" with URL escape symbols in it, that's basically it.
from sqlalchemy.
sure, probably not a big dial, but needs a breaking change node
from sqlalchemy.
Related Issues (20)
- NoForeignKeysError inconsistent error? HOT 5
- Enums are not created in new type alias syntax HOT 12
- IndexError in Query with string literal + repeated ORM attribute HOT 4
- Parameter substitution fails when statement has a postgres style cast HOT 5
- reflecting oracle synonym of synonym over dblink HOT 4
- Changing decimal separator to comma using locale.setlocale causes crash on MSSQL columns of decimal type HOT 3
- Generated syntax error when using funcs in server_default in MySQL
- NoForeignKeysError and AmbiguousForeignKeysError after upgrade to 2.x HOT 5
- selectin_polymorphic does not work for multiple level joined inheritance HOT 2
- ColumnCollection.get(col, default) types as Optional even with default HOT 2
- bulk_save_objects() w/ return defaults writes incorrect identity key HOT 4
- `sqlalchemy.utils.langhelpers.TypingOnly` too rigidly prevents special dunders from appearing HOT 5
- func.count argument typing issue HOT 1
- Bundle labels are wrong for new style select only (query works ?!) HOT 9
- Use of `raise NotImplementedError` instead of `NotImplemented` HOT 1
- Design a Repository pattern with sqlalchemy HOT 1
- Add `name` to `with_polymorphic ` HOT 2
- _JoinedListener can sneak into a metadata collection if Enum adapts itself, which can happen now, prohibiting serialization HOT 2
- TypeAlias cannot be found in type_annotation_map HOT 2
- Typing: of_type method not properly generic. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sqlalchemy.