Opened 15 years ago
Closed 8 years ago
#13161 closed Cleanup/optimization (wontfix)
Avoid global registration of psycopg2 adapters/extensions
Reported by: | spoksss | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | psycopg2, unicode |
Cc: | Carl Meyer, Florian Apolloner | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | yes | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Hi,
I have some problem while I use Django connection based on psycopg2 in the same time while using some other database application.
Because Django changes default psycopg2 settings (psycopg2.extensions.register_type(psycopg2.extensions.UNICODE)),
I get "psycopg2.InterfaceError: can't decode into unicode string from SQLASCII", when I try use my external database application which works with SQLASCII after import django settings.
I think it isn't good way when Django changes default, global settings of psycopg2, because other application can have problems.
I have read documentation of psycopg2, and it is possible to set that psycopg2.extensions.UNICODE just for custom connection or cursor, so I think it is good idea to use that feature in Django.
http://initd.org/psycopg/docs/extensions.html#psycopg2.extensions.register_type
I have tested my changes with psycopg 2.0.8 and Django-1.2-beta-1 and everything work correctly.
Attachments (4)
Change History (22)
by , 15 years ago
comment:2 by , 15 years ago
Component: | Uncategorized → Database layer (models, ORM) |
---|---|
Has patch: | set |
Needs tests: | set |
Triage Stage: | Unreviewed → Accepted |
Strictly, this looks to be a duplicate of #5171, but I'll keep this open given that we have a patch that seems to address the implementation dead-end on that ticket.
This is going to need a test before it gets to trunk.
comment:3 by , 14 years ago
What could I do to test it?
This solution works correctly in my environment,
and it will be nice if I can help somehow and this patch will be add to trunk.
comment:4 by , 14 years ago
You write a test that does exactly the thing that causes the problem to occur -- that is, write a test that accesses psycopg directly as well as using Django's ORM, demonstrating that the way that Django's ORM sets the default value is problematic. The test should be integrated as part of Djanog's test suite -- the regressiontests.backend module would be an appropriate location; the test should fail using current trunk, and pass once your patch is applied.
comment:5 by , 14 years ago
Cc: | added |
---|
by , 14 years ago
Attachment: | project_with_test_ticket_13161.tar.gz added |
---|
Small project with test to raise psycopg2 error.
comment:6 by , 14 years ago
Hi,
I created some project just to show what is a problem, I attached it in this comment.
Set settings, syncdb and then try to run below test:
python manage.py test myapp.MyModelTestCase
comment:7 by , 14 years ago
Type: | → Bug |
---|
comment:8 by , 14 years ago
Severity: | → Normal |
---|
comment:9 by , 13 years ago
Easy pickings: | unset |
---|---|
UI/UX: | unset |
Hi,
what is status of this bug?
It is possible that the patch will be applied to trunk?
regards,
follow-up: 11 comment:10 by , 12 years ago
Version: | 1.2-beta → 1.4 |
---|
Now (version 1.4 of Django) there is only one supported backend (psycopg2) for postgresql, so it is possible, that this patch will be in trunk.
What else can be done to commit it to trunk?
comment:11 by , 12 years ago
Replying to anonymous:
What else can be done to commit it to trunk?
The patch is still marked as needing tests.
comment:12 by , 12 years ago
psycopg version "2.4.5 (dt dec pq3 ext)" fails to respect the per-connection settings, but respects the per-cursor setting just fine. Patch would be best served if setting command was moved to cursor creation (DatabaseWrapper._cursor()).
comment:13 by , 12 years ago
Needs tests: | unset |
---|
comment:14 by , 12 years ago
Needs tests: | set |
---|
comment:15 by , 12 years ago
Cc: | added |
---|
What about register_adapter in the most recent patch, isn't that "global" too? If yes we probable should fix all issues and not just the unicode issue.
comment:16 by , 12 years ago
I guess the SafeString adapters aren't much of an issue as they don't apply to anything else than the SafeString types. But yeah, global they are.
I'd like to confirm that creating a cursor isn't slowed down too much by the change.
comment:17 by , 9 years ago
Summary: | Ticked 2514 and 5171, solution for using Django with other psycopg2 applications. → Avoid global registration of psycopg2 adapters/extensions |
---|---|
Type: | Bug → Cleanup/optimization |
Version: | 1.4 → master |
comment:18 by , 8 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
The unicode type registration will be dropped with Python 2. There are some other extensions/types registered but I'm not sure they're causing any problems. Feel free to reopen if someone sees a reason to change things here.
Small usefull change.