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

TypeError: incompatible types, LP_c_short instance instead of LP_c_short instance [PYFB26] #29

Closed
firebird-automations opened this issue Jan 29, 2013 · 7 comments

Comments

@firebird-automations
Copy link

Submitted by: nepomnyashiy evgeniy (nepomnyashiy evgeniy)

Sometimes I receive strange exception

File "c:\tools\reestr\env\Lib\site-packages\fdb\http://fbcore.py", line 3040, in execute
PreparedStatement(operation, self, True))
File "c:\tools\reestr\env\Lib\site-packages\fdb\http://fbcore.py", line 1701, in __init__
self.__coerce_XSQLDA(self.out_sqlda)
File "c:\tools\reestr\env\Lib\site-packages\fdb\http://fbcore.py", line 2009, in __coerce_XSQLDA
sqlvar.sqlind = ctypes.pointer(ISC_SHORT(0))
TypeError: incompatible types, LP_c_short instance instead of LP_c_short instance

After I receive it first time, every query to database ends with it. Creating new connection or something else dont help - I need to restart apache.

On my development machine (without apache and mod_wsgi) I never receive such exception.

@firebird-automations
Copy link
Author

Modified by: @pcisar

status: Open [ 1 ] => Closed [ 6 ]

resolution: Cannot Reproduce [ 5 ]

@firebird-automations
Copy link
Author

Commented by: nepomnyashiy evgeniy (nepomnyashiy evgeniy)

On my environment I often received this error (before I rollback to kinterbasdb). May be I can help you? Write some logs or something else?

@firebird-automations
Copy link
Author

Commented by: @pcisar

This is clearly Python/ctypes problem, not FDB problem. The FDB code that occasionally reports this bug is unconditionally called whenever SQL command with data is processed, which means that it should always fail if it would be wrong code. Also, nobody else reports such problem although it should be quite common (code path executed frequently), neither could be reproduced. The error message itself is reported by ctypes (standard Python library module) and illogical (LP_c_short instance instead of LP_c_short instance - i.e. expected type although correctly passed was not recognized). So it's clearly problem in your environment or ctypes itself.

I'd suggest to upgrade Python to most recent 2.7 version, preferably from ActiveState (http://www.activestate.com/activepython), and see what happens.

@firebird-automations
Copy link
Author

Commented by: nepomnyashiy evgeniy (nepomnyashiy evgeniy)

I use many connection to same db from many threads. With kinterbasdb I set special constant in his init method, but fdb has not this method.
May be problem in such use of fdb?

I already has last python 2.7 version from http://python.org. I will try to use version from activestate

@firebird-automations
Copy link
Author

Commented by: @pcisar

Generally speaking, access from multiple threads shouldn't be a problem, at least if each thread uses it's own Connection object.

KDB was written mostly in C that required special handling of multiple threads due to C/Python interface, while FDB is pure Python. And concurrency at FB API level is handled by FB client library. If you're using FB 2.5, there shouldn't be any problem, see http://www.firebirdsql.org/rlsnotesh/rlsnotes25.html#rnfb25-engine-thrdsafe.

@firebird-automations
Copy link
Author

Commented by: Sam Watkins (sswam)

We have the same bug today on Ubuntu 14.04.2 LTS 64-bit, using fdb 1.4.9 (built from source), Python 2.7.6, and apache2 mod python with mpm prefork. Again, it only happens when running our app in apache, not in the test web server.

An somewhat similar issue with ctypes is reported here, where ctypes reports "incompatible types, X instance instead of X instance":
http://ctypes-users.narkive.com/Dl51mA0r/weird-incompatible-types-error

This error can occur if two different POINTER() types have somehow been created with the same name. But looking through the fdb code, I can't see how it would have happened. You don't create POINTER() types using strings as in the other case.

I am using "subprocess" to fork and run some other programs. I had thought the error might be related to this, but after testing it seems not. Will let you know if we find a solution.

@firebird-automations
Copy link
Author

Commented by: Sam Watkins (sswam)

I hacked around this problem by patching FDB with three ugly casts like this:
2359: sqlvar.sqlind = ctypes.cast(ctypes.pointer(ISC_SHORT(0)), type(sqlvar.sqlind))
2812: sqlvar.sqlind = ctypes.cast(ctypes.pointer(ISC_SHORT(-1)), type(sqlvar.sqlind))
2819: sqlvar.sqlind = ctypes.cast(ctypes.pointer(ISC_SHORT(0)), type(sqlvar.sqlind))

This hack is very far from ideal but it seems to be preventing the exception.

It would be better to fix whatever bug is actually causing us to create two different POINTER(ISC_SHORT) types!
Whether it is in ctypes or fdb, or whatever. Perhaps it's something to do with threading?
I am yet to try this with the latest Python 2.7.10, perhaps they have fixed it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants