Re: [sqlalchemy] add new row into a many_to_one relationship database via ORM

2015-07-17 Thread Mike Bayer



On 7/17/15 5:02 AM, Chengjun JIN wrote:

Hi all,

I am trying to add new rows into an existing many to one database via 
sqlalchemy ORM.


What I am doing now(it seems working):
# The many to one relationship is:
stock = relationship('Stock', backref=backref('historicalprices', 
order_by=id))


# query an object
stock = session.query(Stock).filter_by(code='1').one()

# add row
stock.historicalprices.append([something])
session.add(stock)

The problem is that it is too slow to query one object. Is there a 
fast/standard way to do this?


I'm assuming you have a lot of Stock objects to query.   You can get a 
bunch of stock objects in batch like this:


stocks = dict(
session.query(Stock.code, Stock).all()
)


for something in somethings:
stock = stocks[something.desired_code]
something.stock = stock# assign on the many-to-one side so that 
you don't need to load 'historicalprices'


# add() shouldn't be needed
session.commit()


you can also batch this in subsets of Stock objects:


while somethings:
  batch = somethings[0:1000]
  somethings = somethings[1000:]
  stock_codes = set([something.desired_code for something in batch])
  stocks = dict(
   session.query(Stock.code, 
Stock).filter(Stock.code.in_(stock_codes)).all()

  )

  for something in batch:
   # ... same code as before









Thanks,
Chengjun






--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto:sqlalchemy@googlegroups.com.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


[sqlalchemy] add new row into a many_to_one relationship database via ORM

2015-07-17 Thread Chengjun JIN
Hi all,

I am trying to add new rows into an existing many to one database via 
sqlalchemy ORM.

What I am doing now(it seems working):
# The many to one relationship is:
stock = relationship('Stock', backref=backref('historicalprices', 
order_by=id))

# query an object
stock = session.query(Stock).filter_by(code='1').one()

# add row
stock.historicalprices.append([something])
session.add(stock)

The problem is that it is too slow to query one object. Is there a 
fast/standard way to do this?

Thanks,
Chengjun






-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] Columns not deferred when an object is merged into a session with load=False

2015-07-17 Thread Tom Flannaghan
Thanks a lot! This works well.

Tom

On Thu, 16 Jul 2015 at 21:23 Mike Bayer mike...@zzzcomputing.com wrote:



 On 7/16/15 2:28 PM, Tom Flannaghan wrote:

  Thanks for your reply. Our exact problem is that we are creating empty
 detached objects from the primary key alone, and then merging them in to a
 session, so we can't do this:

 On Thursday, 16 July 2015 18:44:26 UTC+1, Michael Bayer wrote:


 For now, I'd recommend either not using expire() or specifying specific
 attribute names to expire().


  I just included the expire() in the example as it was a more succinct
 way to reproduce the same bug.
  Our code looks more like this:

  detached_port = Port(name='test')
 make_transient_to_detached(detached_port)
 new_port = session.merge(detached_port, load=False)
 ...

  In my example, Port only has two columns so this won't demonstrate the
 bug as the only non-deferred column is filled in already, but more
 complicated objects that are merged in this way will not defer columns. Do
 you think there a work around in this case?

 try this recipe which should reset the expired state of the target
 attributes individually:


 from sqlalchemy.orm import attributes


 def merge_load_false(session, obj):
 obj = session.merge(obj, load=False)

 obj_state = attributes.instance_state(obj)
 obj_dict = obj_state.dict

 deferred_keys = [
 attr.key for attr in obj_state.mapper.column_attrs if
 attr.deferred]
 for k in deferred_keys:
 if k not in obj_dict:
 obj_state._reset(obj_dict, k)
 return obj

 a1 = merge_load_false(s, a1)






  Thanks,
 Tom
  --

 You received this message because you are subscribed to the Google Groups
 sqlalchemy group.

 To unsubscribe from this group and stop receiving emails from it, send an
 email to sqlalchemy+unsubscr...@googlegroups.com.


 To post to this group, send email to sqlalchemy@googlegroups.com.
 Visit this group at http://groups.google.com/group/sqlalchemy.
 For more options, visit https://groups.google.com/d/optout.

  --
 You received this message because you are subscribed to a topic in the
 Google Groups sqlalchemy group.
 To unsubscribe from this topic, visit
 https://groups.google.com/d/topic/sqlalchemy/gRV7mSHFJiE/unsubscribe.
 To unsubscribe from this group and all its topics, send an email to
 sqlalchemy+unsubscr...@googlegroups.com.
 To post to this group, send email to sqlalchemy@googlegroups.com.
 Visit this group at http://groups.google.com/group/sqlalchemy.
 For more options, visit https://groups.google.com/d/optout.


-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


[sqlalchemy] Issue with dynamically loaded modules and SQLAlchemy

2015-07-17 Thread Jeffrey McLarty
Hello,

I've got a very peculiar situation, where SQLA fails to create an engine, 
because it can't find the installed module, only when I do some relatively 
straightforward package discovery  import logic using imp.find_module and 
imp.load_module.

I'm wondering if SQLAlchemy does some magic which might be impacted if I've 
used find_module and load_module upstream, despite being in different name 
spaces(?)

I'm working with Python 2.7.6, SQLAlchemy 0.9.2, and Postgres 9.4, and 
psycopg2

Here's the traceback...

Traceback (most recent call last):
  File C:\WinPython-32bit-2.7.6.3-20140407\python-2.7.6\lib\pdb.py, line 
1314,
 in main
pdb._runscript(mainpyfile)
  File C:\WinPython-32bit-2.7.6.3-20140407\python-2.7.6\lib\pdb.py, line 
1233,
 in _runscript
self.run(statement)
  File C:\WinPython-32bit-2.7.6.3-20140407\python-2.7.6\lib\bdb.py, line 
400,
in run
exec cmd in globals, locals
  File string, line 1, in module
  File install.py, line 2, in module
from equitable.db.psyw import DBpicker, SQLAeng, SmartDB
  File 
C:\WinPython-32bit-2.7.6.3-20140407\python-2.7.6\lib\site-packages\trump
\orm.py, line 2287, in SetupTrump
engine = create_engine(engine_str)
  File 
C:\WinPython-32bit-2.7.6.3-20140407\python-2.7.6\lib\site-packages\sqlal
chemy\engine\__init__.py, line 344, in create_engine
return strategy.create(*args, **kwargs)
  File 
C:\WinPython-32bit-2.7.6.3-20140407\python-2.7.6\lib\site-packages\sqlal
chemy\engine\strategies.py, line 50, in create
dialect_cls = u.get_dialect()
  File 
C:\WinPython-32bit-2.7.6.3-20140407\python-2.7.6\lib\site-packages\sqlal
chemy\engine\url.py, line 116, in get_dialect
cls = registry.load(name)
  File 
C:\WinPython-32bit-2.7.6.3-20140407\python-2.7.6\lib\site-packages\sqlal
chemy\util\langhelpers.py, line 186, in load
(self.group, name))
NoSuchModuleError: Can't load plugin: 
sqlalchemy.dialects:postgresql.psycopg2


SQLAlchemy works as expected, (ie, it finds psycopg2) if I comment out line 
60 of https://github.com/Equitable/trump/blob/master/trump/orm.py (and 
replace the variable sources with an empty dictionary).  Line 60, is an 
import to sub-module which dynamically loads modules.

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] Issue with dynamically loaded modules and SQLAlchemy

2015-07-17 Thread Mike Bayer



On 7/17/15 1:39 PM, Mike Bayer wrote:



On 7/17/15 1:21 PM, Jeffrey McLarty wrote:

Hello,

I've got a very peculiar situation, where SQLA fails to create an 
engine, because it can't find the installed module, only when I do 
some relatively straightforward package discovery  import logic 
using imp.find_module and imp.load_module.


feel free to share that logic.  Otherwise, no clue.


oh sorry, I see you did. this is a little more code than I can 
follow, but you want to make sure you don't prohibit the __import__ line 
below from working.






I'm wondering if SQLAlchemy does some magic


only if you consider this to be magic:

module = __import__('sqlalchemy.dialects.%s' % (dialect, )).dialects




which might be impacted if I've used find_module and load_module 
upstream, despite being in different name spaces(?)


I'm working with Python 2.7.6, SQLAlchemy 0.9.2, and Postgres 9.4, 
and psycopg2


Here's the traceback...

|
Traceback(most recent call last):
FileC:\WinPython-32bit-2.7.6.3-20140407\python-2.7.6\lib\pdb.py,line 1314,
inmain
pdb._runscript(mainpyfile)
FileC:\WinPython-32bit-2.7.6.3-20140407\python-2.7.6\lib\pdb.py,line 1233,
in_runscript
self.run(statement)
FileC:\WinPython-32bit-2.7.6.3-20140407\python-2.7.6\lib\bdb.py,line 400,
inrun
execcmd inglobals,locals
Filestring,line 1,inmodule
Fileinstall.py,line 2,inmodule
fromequitable.db.psyw importDBpicker,SQLAeng,SmartDB
FileC:\WinPython-32bit-2.7.6.3-20140407\python-2.7.6\lib\site-packages\trump
\orm.py,line 2287,inSetupTrump
engine =create_engine(engine_str)
FileC:\WinPython-32bit-2.7.6.3-20140407\python-2.7.6\lib\site-packages\sqlal
chemy\engine\__init__.py,line 344,increate_engine
returnstrategy.create(*args,**kwargs)
FileC:\WinPython-32bit-2.7.6.3-20140407\python-2.7.6\lib\site-packages\sqlal
chemy\engine\strategies.py,line 50,increate
dialect_cls =u.get_dialect()
FileC:\WinPython-32bit-2.7.6.3-20140407\python-2.7.6\lib\site-packages\sqlal
chemy\engine\url.py,line 116,inget_dialect
cls =registry.load(name)
FileC:\WinPython-32bit-2.7.6.3-20140407\python-2.7.6\lib\site-packages\sqlal
chemy\util\langhelpers.py,line 186,inload
(self.group,name))
NoSuchModuleError:Can't load plugin: 
sqlalchemy.dialects:postgresql.psycopg2

|


SQLAlchemy works as expected, (ie, it finds psycopg2) if I comment 
out line 60 of 
https://github.com/Equitable/trump/blob/master/trump/orm.py (and 
replace the variable sources with an empty dictionary).  Line 60, 
is an import to sub-module which dynamically loads modules.

--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, 
send an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto:sqlalchemy@googlegroups.com.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto:sqlalchemy@googlegroups.com.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] Issue with dynamically loaded modules and SQLAlchemy

2015-07-17 Thread Mike Bayer



On 7/17/15 1:21 PM, Jeffrey McLarty wrote:

Hello,

I've got a very peculiar situation, where SQLA fails to create an 
engine, because it can't find the installed module, only when I do 
some relatively straightforward package discovery  import logic using 
imp.find_module and imp.load_module.


feel free to share that logic.  Otherwise, no clue.


I'm wondering if SQLAlchemy does some magic


only if you consider this to be magic:

module = __import__('sqlalchemy.dialects.%s' % (dialect, )).dialects




which might be impacted if I've used find_module and load_module 
upstream, despite being in different name spaces(?)


I'm working with Python 2.7.6, SQLAlchemy 0.9.2, and Postgres 9.4, and 
psycopg2


Here's the traceback...

|
Traceback(most recent call last):
FileC:\WinPython-32bit-2.7.6.3-20140407\python-2.7.6\lib\pdb.py,line 
1314,

inmain
pdb._runscript(mainpyfile)
FileC:\WinPython-32bit-2.7.6.3-20140407\python-2.7.6\lib\pdb.py,line 
1233,

in_runscript
self.run(statement)
FileC:\WinPython-32bit-2.7.6.3-20140407\python-2.7.6\lib\bdb.py,line 
400,

inrun
execcmd inglobals,locals
Filestring,line 1,inmodule
Fileinstall.py,line 2,inmodule
fromequitable.db.psyw importDBpicker,SQLAeng,SmartDB
FileC:\WinPython-32bit-2.7.6.3-20140407\python-2.7.6\lib\site-packages\trump
\orm.py,line 2287,inSetupTrump
engine =create_engine(engine_str)
FileC:\WinPython-32bit-2.7.6.3-20140407\python-2.7.6\lib\site-packages\sqlal
chemy\engine\__init__.py,line 344,increate_engine
returnstrategy.create(*args,**kwargs)
FileC:\WinPython-32bit-2.7.6.3-20140407\python-2.7.6\lib\site-packages\sqlal
chemy\engine\strategies.py,line 50,increate
dialect_cls =u.get_dialect()
FileC:\WinPython-32bit-2.7.6.3-20140407\python-2.7.6\lib\site-packages\sqlal
chemy\engine\url.py,line 116,inget_dialect
cls =registry.load(name)
FileC:\WinPython-32bit-2.7.6.3-20140407\python-2.7.6\lib\site-packages\sqlal
chemy\util\langhelpers.py,line 186,inload
(self.group,name))
NoSuchModuleError:Can't load plugin: 
sqlalchemy.dialects:postgresql.psycopg2

|


SQLAlchemy works as expected, (ie, it finds psycopg2) if I comment out 
line 60 of https://github.com/Equitable/trump/blob/master/trump/orm.py 
(and replace the variable sources with an empty dictionary).  Line 
60, is an import to sub-module which dynamically loads modules.

--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto:sqlalchemy@googlegroups.com.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] marking an object read-only / recursive expunge?

2015-07-17 Thread Jonathan Vanasco


On Friday, July 17, 2015 at 2:46:42 PM UTC-4, Michael Bayer wrote:

  
 well then yeah you need to do your own thing :)


i foolishly thought this was something others may have experienced ;)
 

 i'd use inspect(obj) to get the mapper.but also you might want to use 
 cascade_iterator: 
 http://docs.sqlalchemy.org/en/rel_1_0/orm/mapping_api.html?highlight=cascade_iterator#sqlalchemy.orm.mapper.Mapper.cascade_iterator

 
i'll look into the cascade_iterator.  I keep forgetting that inspect is not 
just for debugging.
 

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] marking an object read-only / recursive expunge?

2015-07-17 Thread Mike Bayer



On 7/17/15 2:32 PM, Jonathan Vanasco wrote:

editing the cascade isn't an option.


well then yeah you need to do your own thing :)

i'd use inspect(obj) to get the mapper.but also you might want to 
use cascade_iterator: 
http://docs.sqlalchemy.org/en/rel_1_0/orm/mapping_api.html?highlight=cascade_iterator#sqlalchemy.orm.mapper.Mapper.cascade_iterator


for now this seems to work, though it's ugly.

def recursive_expunge(obj, dbSession):
def _recursive_expunge(_obj):
if hasattr(_obj, '__mapper__'):
for rel in obj.__mapper__.relationships:
try:
dbSession.expunge(rel)
except sqlalchemy.orm.exc.UnmappedInstanceError:
pass
_recursive_expunge(obj)
recursive_expunge(postingObject, self.request.dbSession.writer)

--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto:sqlalchemy@googlegroups.com.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


[sqlalchemy] marking an object read-only / recursive expunge?

2015-07-17 Thread Jonathan Vanasco
I'm updating our visual preview tool for edits, and ran into an issue.  

In order to best mimic the production view, I can't simply clone the 
objects any longer (they have way too many attributes and relationships) 
and must apply edits onto the real object.  

I'd like to ensure that changes can't persist, so the easiest way to mark 
the object read only was to expunge it from the session.  Perfect.

The problem I've run into, is that `expunge()` only applies to the actual 
object -- it doesn't apply to any of the loaded (lazy/eager/etc) 
relationships.  

Has anyone figured out way to do a recursive expunge?  I don't want to 
alter the cascades on the relationship, I just have one (or more) 
context(s) where I need to disassociate an object and any loaded children 
from the session.

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] marking an object read-only / recursive expunge?

2015-07-17 Thread Mike Bayer



On 7/17/15 2:18 PM, Jonathan Vanasco wrote:

I'm updating our visual preview tool for edits, and ran into an issue.

In order to best mimic the production view, I can't simply clone the 
objects any longer (they have way too many attributes and 
relationships) and must apply edits onto the real object.


I'd like to ensure that changes can't persist, so the easiest way to 
mark the object read only was to expunge it from the session.  Perfect.


The problem I've run into, is that `expunge()` only applies to the 
actual object -- it doesn't apply to any of the loaded 
(lazy/eager/etc) relationships.


Has anyone figured out way to do a recursive expunge?  I don't want to 
alter the cascades on the relationship, I just have one (or more) 
context(s) where I need to disassociate an object and any loaded 
children from the session.


there's an expunge cascade you can set on relationship:

http://docs.sqlalchemy.org/en/rel_1_0/orm/cascades.html#expunge






--
You received this message because you are subscribed to the Google 
Groups sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to sqlalchemy+unsubscr...@googlegroups.com 
mailto:sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com 
mailto:sqlalchemy@googlegroups.com.

Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] marking an object read-only / recursive expunge?

2015-07-17 Thread Jonathan Vanasco
editing the cascade isn't an option.  

for now this seems to work, though it's ugly.

def recursive_expunge(obj, dbSession):
def _recursive_expunge(_obj):
if hasattr(_obj, '__mapper__'):
for rel in obj.__mapper__.relationships:
try:
dbSession.expunge(rel)
except sqlalchemy.orm.exc.UnmappedInstanceError:
pass
_recursive_expunge(obj)
recursive_expunge(postingObject, self.request.dbSession.writer)

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] Issue with dynamically loaded modules and SQLAlchemy

2015-07-17 Thread Jeffrey McLarty
Thanks for the pointers; that was all I needed. Plunking around SQLA's
PluginLoader and dialect.__init__.py with pdb...allowed me to figure out
the problem.

__import__ doesn't reload packages if they are already loaded, but the
check to determine already loaded,  obviously can't include a comparison
with folder location, since __import__ is given only a name.  I had an
extension, **isolated** from both my package and site-packages, named
psycopg2, loaded via an explicit folder+name call using
load_module()...but after I loaded it, SQLA couldn't find the original
psycopg2 package.

I just renamed my project's extension, to something other than an exact
match for psycopg2; all worked.

Thanks SO much, for your help Mike, and making SQLA one the most awesome
libraries ever.

*Jeffrey McLarty*

On Fri, Jul 17, 2015 at 1:41 PM, Mike Bayer mike...@zzzcomputing.com
wrote:



 On 7/17/15 1:39 PM, Mike Bayer wrote:



 On 7/17/15 1:21 PM, Jeffrey McLarty wrote:

 Hello,

  I've got a very peculiar situation, where SQLA fails to create an
 engine, because it can't find the installed module, only when I do some
 relatively straightforward package discovery  import logic using
 imp.find_module and imp.load_module.


 feel free to share that logic.  Otherwise, no clue.


 oh sorry, I see you did. this is a little more code than I can follow,
 but you want to make sure you don't prohibit the __import__ line below from
 working.





  I'm wondering if SQLAlchemy does some magic


 only if you consider this to be magic:

 module = __import__('sqlalchemy.dialects.%s' % (dialect, )).dialects




  which might be impacted if I've used find_module and load_module
 upstream, despite being in different name spaces(?)

  I'm working with Python 2.7.6, SQLAlchemy 0.9.2, and Postgres 9.4, and
 psycopg2

  Here's the traceback...

   Traceback (most recent call last):
   File C:\WinPython-32bit-2.7.6.3-20140407\python-2.7.6\lib\pdb.py,
 line 1314,
  in main
 pdb._runscript(mainpyfile)
   File C:\WinPython-32bit-2.7.6.3-20140407\python-2.7.6\lib\pdb.py,
 line 1233,
  in _runscript
 self.run(statement)
   File C:\WinPython-32bit-2.7.6.3-20140407\python-2.7.6\lib\bdb.py,
 line 400,
 in run
 exec cmd in globals, locals
   File string, line 1, in module
   File install.py, line 2, in module
 from equitable.db.psyw import DBpicker, SQLAeng, SmartDB
   File
 C:\WinPython-32bit-2.7.6.3-20140407\python-2.7.6\lib\site-packages\trump
 \orm.py, line 2287, in SetupTrump
 engine = create_engine(engine_str)
   File
 C:\WinPython-32bit-2.7.6.3-20140407\python-2.7.6\lib\site-packages\sqlal
 chemy\engine\__init__.py, line 344, in create_engine
 return strategy.create(*args, **kwargs)
   File
 C:\WinPython-32bit-2.7.6.3-20140407\python-2.7.6\lib\site-packages\sqlal
 chemy\engine\strategies.py, line 50, in create
 dialect_cls = u.get_dialect()
   File
 C:\WinPython-32bit-2.7.6.3-20140407\python-2.7.6\lib\site-packages\sqlal
 chemy\engine\url.py, line 116, in get_dialect
 cls = registry.load(name)
   File
 C:\WinPython-32bit-2.7.6.3-20140407\python-2.7.6\lib\site-packages\sqlal
 chemy\util\langhelpers.py, line 186, in load
 (self.group, name))
 NoSuchModuleError: Can't load plugin:
 sqlalchemy.dialects:postgresql.psycopg2


  SQLAlchemy works as expected, (ie, it finds psycopg2) if I comment out
 line 60 of https://github.com/Equitable/trump/blob/master/trump/orm.py
 (and replace the variable sources with an empty dictionary).  Line 60, is
 an import to sub-module which dynamically loads modules.
  --
 You received this message because you are subscribed to the Google Groups
 sqlalchemy group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to sqlalchemy+unsubscr...@googlegroups.com.
 To post to this group, send email to sqlalchemy@googlegroups.com.
 Visit this group at http://groups.google.com/group/sqlalchemy.
 For more options, visit https://groups.google.com/d/optout.


 --
 You received this message because you are subscribed to the Google Groups
 sqlalchemy group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to sqlalchemy+unsubscr...@googlegroups.com.
 To post to this group, send email to sqlalchemy@googlegroups.com.
 Visit this group at http://groups.google.com/group/sqlalchemy.
 For more options, visit https://groups.google.com/d/optout.


  --
 You received this message because you are subscribed to a topic in the
 Google Groups sqlalchemy group.
 To unsubscribe from this topic, visit
 https://groups.google.com/d/topic/sqlalchemy/AbPSrqH0kb4/unsubscribe.
 To unsubscribe from this group and all its topics, send an email to
 sqlalchemy+unsubscr...@googlegroups.com.
 To post to this group, send email to sqlalchemy@googlegroups.com.
 Visit this group at http://groups.google.com/group/sqlalchemy.
 For more options, visit https://groups.google.com/d/optout.


-- 
You received this message because you are subscribed to the Google Groups