I think I got it solved, I had to use another DAL parameter: table_hash
If you look into databases folder, you will see that every .table file
begins with a hash.
That hash was initialy generated by web2py when the tables were created,
the first time the models were run.
I think that web2py generates that hash using the connection string
parameters, such as the db username used for the connection.
Anyway, here is what I did in APP2 to be able to connect to the APP1's
database, using a different db username:
# gets the table_hash from the first .table file present in the databases
folder
table_hash = None
databases_folder = CONFIG.path_web2py, 'applications', 'app1', 'databases')
for tablefile in os.listdir(databases_folder):
if tablefile.endswith('.table'):
table_hash = archivo.split('_')[0]
break
# connects to the DB using auto_import and table_hash
db_app1 = DAL('postgres://%s:%s@%s/%s' % ('otheruser', 'mypassword',
'localhost', 'george'),
migrate=False,
folder=databases_folder,
auto_import=True,
table_hash=table_hash)
I couldn't find much in the documentation about table_hash:
http://www.web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#DAL-signature
Maybe some clarification about table_hash needs to be added in the section
"Using DAL without define tables":
http://www.web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#Using-DAL-without-define-tables
Anyway, I hope this helps if anywan runs into the same.
Best regards,
Lisandro.
El viernes, 19 de mayo de 2017, 12:49:33 (UTC-3), Lisandro escribió:
>
> I have this scenario:
>
> One postgreSQL database called "george", owned by one user also called
> "george".
>
> APP1:
> It is the main app that uses the database.
> This app executed the migrations the first time, then it uses lazy tables.
>
>
> APP2:
> In some ocations, it connects to the "george" database using user
> "george", but it uses the auto_import parameter like this:
>
> DAL('postgres://george:mypassword@localhost/george',
> migrate=False,
> folder=databases_path,
> auto_import=True)
>
> *databases_path* is a variable that points to the folder inside APP1 that
> has the .table files created by web2py.
>
> *Up to here, all works great. *APP2 can connect to george database and do
> selects, inserts, etc.
>
> Now I'm trying to connect with te postgres user, that is, the default user
> of postgres, the root user.
> I just replaced the user/password in the code above, but when I try to
> access any table, I receive this error from DAL:
>
> AttributeError: 'DAL' object has no attribute 'contenido'
>
>
> I think that auto_import is failing somehow because of the different user
> connecting to the database.
> Is this the expected behaviour?
>
> I appreciate any comments.
> Thanks in advance!
>
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.