Re: [sqlalchemy] Redefine class on runtime

2019-03-04 Thread Tolstov Sergey
Thanks for answer,  can i get only part of classes mappers? Somethink about 
Myclass.mapper.clear()?

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
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 https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: Error while running “superset db upgrade” after changing metadata DB to vertica

2019-03-04 Thread Mike Bayer
Hi there -

I'm not familiar with "Superset", nor does Alembic have built in
support for the "Vertica" database.It looks like the Vertica
SQLAlchemy drive doesn't have Alembic support implemented which at the
very least would be a small stub DefaultImpl subclass..   You would
need to consult with the developers of the Vertica SQLAlchemy driver
to get help with your application.


On Mon, Mar 4, 2019 at 4:42 PM rishi reddy  wrote:
>
> I am trying to change the metadata DB to Vertica from sqlite and I am facing 
> an issue while running "superset db upgrade" as part of bringing up Superset 
> application
>
> Steps to reproduce:
>
> 1) Installed Superset using pip (pip install superset)
>
> 2) Created "superset_config.py" with below content:
>
> #-
> # Superset specific config
> #-
> ROW_LIMIT = 5000
>
> SUPERSET_WEBSERVER_PORT = 8088
> #-
>
> #-
> # Flask App Builder configuration
> #-
> # Your App secret key
> SECRET_KEY = '\2\1thisismyscretkey\1\2\e\y\y\h'
>
> # The SQLAlchemy connection string to your database backend
> # This connection defines the path to the database that stores your
> # superset metadata (slices, connections, tables, dashboards, ...).
> # Note that the connection information to connect to the datasources
> # you want to explore are managed directly in the web UI
> #SQLALCHEMY_DATABASE_URI = 'sqlite:path/to/superset.db'
> SQLALCHEMY_DATABASE_URI = 
> 'vertica+vertica_python://dbadmin:password@x.x.x.x/vertica9'
> # Flask-WTF flag for CSRF
> WTF_CSRF_ENABLED = True
> # Add endpoints that need to be exempt from CSRF protection
> WTF_CSRF_EXEMPT_LIST = []
> # A CSRF token that expires in 1 year
> WTF_CSRF_TIME_LIMIT = 60 * 60 * 24 * 365
>
> # Set this API key to enable Mapbox visualizations
> MAPBOX_API_KEY = ''
>
> 3) Added superset_config.py path to PYTHONPATH
>
> export 
> PYTHONPATH=/usr/local/lib/python3.6/site-packages/superset/:/usr/local/bin/python3
>
> 4) Installed SqlAlchemy Vertica drivers. pip install sqlalchemy-vertica-python
>
> 5) Ran "fabmanager create-admin --app superset" which successfully created 
> admin user in vertica
>
> 6) While running "superset db upgrade", I am seeing below error:
>
> [root@user ~]# superset db upgrade
> Loaded your LOCAL configuration at 
> [/usr/local/lib/python3.6/site-packages/superset/superset_config.py]
> Traceback (most recent call last):
>   File "/usr/local/bin/superset", line 15, in 
> cli()
>   File "/usr/local/lib/python3.6/site-packages/click/core.py", line 722, in 
> __call__
> return self.main(*args, **kwargs)
>   File "/usr/local/lib/python3.6/site-packages/flask/cli.py", line 557, in 
> main
> return super(FlaskGroup, self).main(*args, **kwargs)
>   File "/usr/local/lib/python3.6/site-packages/click/core.py", line 697, in 
> main
> rv = self.invoke(ctx)
>   File "/usr/local/lib/python3.6/site-packages/click/core.py", line 1066, in 
> invoke
> return _process_result(sub_ctx.command.invoke(sub_ctx))
>   File "/usr/local/lib/python3.6/site-packages/click/core.py", line 1066, in 
> invoke
> return _process_result(sub_ctx.command.invoke(sub_ctx))
>   File "/usr/local/lib/python3.6/site-packages/click/core.py", line 895, in 
> invoke
> return ctx.invoke(self.callback, **ctx.params)
>   File "/usr/local/lib/python3.6/site-packages/click/core.py", line 535, in 
> invoke
> return callback(*args, **kwargs)
>   File "/usr/local/lib/python3.6/site-packages/click/decorators.py", line 17, 
> in new_func
> return f(get_current_context(), *args, **kwargs)
>   File "/usr/local/lib/python3.6/site-packages/flask/cli.py", line 412, in 
> decorator
> return __ctx.invoke(f, *args, **kwargs)
>   File "/usr/local/lib/python3.6/site-packages/click/core.py", line 535, in 
> invoke
> return callback(*args, **kwargs)
>   File "/usr/local/lib/python3.6/site-packages/flask_migrate/cli.py", line 
> 134, in upgrade
> _upgrade(directory, revision, sql, tag, x_arg)
>   File "/usr/local/lib/python3.6/site-packages/flask_migrate/__init__.py", 
> line 95, in wrapped
> f(*args, **kwargs)
>   File "/usr/local/lib/python3.6/site-packages/flask_migrate/__init__.py", 
> line 280, in upgrade
> command.upgrade(config, revision, sql=sql, tag=tag)
>   File "/usr/local/lib/python3.6/site-packages/alembic/command.py", line 276, 
> in upgrade
> script.run_env()
>   File "/usr/local/lib/python3.6/site-packages/alembic/script/base.py", line 
> 475, in run_env
> util.load_python_file(self.dir, "env.py")
>   File "/usr/local/lib/python3.6/site-packages/alembic/util/pyfiles.py", line 
> 90, in load_python_file
> module = load_module_py(module_id, path)
>   File "/usr/local/lib/python3.6/site-packages/alembic/util/compat.py", line 

Re: [sqlalchemy] Re: Organizing a project

2019-03-04 Thread Rich Shepard

On Mon, 4 Mar 2019, Jonathan Vanasco wrote:


We "define" the model in a separate package - all the classes and
relationships are in there. There are database support items as well, and
some of the advanced/business logic that manipulate the ORM objects. By
advanced-database-specific logic, an example might be: resetting a
password is a function that checks the existing password against current &
past ones, updates the current credentials table, and migrates a consumed
credential into a table of invalid previously used options - it's a
multi-step database update.


Jonathan,

Thanks for clarifying.

For this and the next application I need to build the model (in model.py) is
the SQLAlchemy translation of the postgres tables; with this application
there are 9 tables/classes. No other application will use these.


The webapps typically have a "model" namespace, but that just invokes the
'shared' model package and contains any application/implementation
specific model logic. Everything is written so it can be easily migrated
into the shared model package so all of the coordinated apps/utilities can
leverage it.


I have a module called commonDlgs.py which contains re-useable classes, such
as password login, quitter (asks 'Are you sure?'), and generic message box.


This is just a personal preference my I have gravitated towards with my
team over the past few years.


You're really helped me resolve my questions. Now I know that I can put
classes in whatever modules and subdirectories I want as long as import them
where they are used, and it really doesn't matter what the structure is so
long as it is easy for others to follow. The current application is for my
business needs; the next one will be given away and hosted on github.

Regards,

Rich

--
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper


http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
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 https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] Re: Organizing a project

2019-03-04 Thread Jonathan Vanasco
We "define" the model in a separate package - all the classes and 
relationships are in there. There are database support items as well, and 
some of the advanced/business logic that manipulate the ORM objects.  By 
advanced-database-specific logic, an example might be: resetting a password 
is a function that checks the existing password against current & past 
ones, updates the current credentials table, and migrates a consumed 
credential into a table of invalid previously used options - it's a 
multi-step database update.   

The webapps typically have a "model" namespace, but that just invokes the 
'shared' model package and contains any application/implementation specific 
model logic.  Everything is written so it can be easily migrated into the 
shared model package so all of the coordinated apps/utilities can leverage 
it.

This is just a personal preference my I have gravitated towards with my 
team over the past few years.  We've just never built a MVC app where the 
model only serves a single app after a few months.  There are always new 
tools/services/etc needed and this approach keeps everything centralized... 
especially many of the test suites.  One "project" was originally a Pyramid 
app that has grown to also be a Celery Utility, Twisted Daemon with 9 
services, and about 50 python tools. They all use a central SqlAlchemy 
model.

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
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 https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] Redefine class on runtime

2019-03-04 Thread Mike Bayer
On Mon, Mar 4, 2019 at 12:40 AM Tolstov Sergey  wrote:
>
> Hi, for unit tests i need to create class with Base.metadata.create_all, and 
> delete table defintion (for tests)
>
> On second definition i have a error (already defined)
>
> With use Base.metadata.clear i get warning
>
> SAWarning: Reassigning polymorphic association for identity 'testparentclass' 
> from  to  0x7f910d83f860; TestParentClass>: Check for duplicate use of 
> 'testparentclass' as value for polymorphic_identity.
>
> Can i clear cached inherit?

metadata.create_all / drop_all  aren't related to the state of your
mappers, these two methods can be called freely with no need to call
metadata.clear().  You likely should not be using metadata.clear().

If OTOH you are actually changing the structure of declarative classes
per test such that something is being removed from a mapping, you
would need to use clear_mappers() and redefine all classes and
mappings from scratch, using a new Base.You can't remove elements
from mappings, such as here where you'd want to remove a polymorphic
subclass and replace it with a new one.

If you are using classical mappings or hybrid delcarative mappings
with __table__, there might be some more options here but it's usually
best to keep class hierarchies that are local to tests fully within
the setup/teardown of those tests.









>
> --
> SQLAlchemy -
> The Python SQL Toolkit and Object Relational Mapper
>
> http://www.sqlalchemy.org/
>
> To post example code, please provide an MCVE: Minimal, Complete, and 
> Verifiable Example. See http://stackoverflow.com/help/mcve for a full 
> description.
> ---
> 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 https://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
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 https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] MySQL Connector

2019-03-04 Thread Mike Bayer
On Sun, Mar 3, 2019 at 8:40 PM Warwick Prince  wrote:
>
> Hi Community
>
> We’ve been using sqlalchemy with great success for many years.  We’ve been 
> using the mysqlconnector to connect to my MySQL databases with no issues to 
> speak of.
>
> My issue is that I recently upgraded to the latest version of the connector 
> from Oracle which has changed from Python to C.  I’m now regularly receiving 
> the following error where this has never happened in the past;   MySQL 5.6 
> BTW.
>
> DatabaseError: (mysql.connector.errors.HashError) Hashed authentication data 
> is invalid
>
> Obviously, I would assume that this is not a sqlalchemy issue, however 
> there’s nothing really being spoken about this anywhere else and I wondered 
> if anyone had had the problem and fixed it - or eventually rolled back to the 
> very old version of mysqlconnector?

Unfortunately recent versions of MySQL connector, specifically when
the C code was added, work very poorly, such that I had to remove
mysql connector from testing.   I documented a partial list of
blocking issues I encountered here:
https://docs.sqlalchemy.org/en/latest/dialects/mysql.html#current-issues


>
> Alternatively, @Mike - could you recommend in your opinion the ‘best’ 
> connector to use for MySQL based on reliability and performance.

The best drivers for MySQL are mysqlclient and pymysql, both
maintained by the same person.  Both drivers work very well and are
well supported.   mysqlclient is a fork of the original C based
python-mysql driver which is no longer maintained.


>
> Cheers
> Warwick
>
> Warwick Prince
> Managing Director
> mobile: +61 411 026 992
> skype: warwickprince
> phone: +61 7 3102 3730
> fax:  +61 7 3319 6734
> web: www.mushroomsys.com
>
> --
> SQLAlchemy -
> The Python SQL Toolkit and Object Relational Mapper
>
> http://www.sqlalchemy.org/
>
> To post example code, please provide an MCVE: Minimal, Complete, and 
> Verifiable Example. See http://stackoverflow.com/help/mcve for a full 
> description.
> ---
> 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 https://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
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 https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] Re: Organizing a project

2019-03-04 Thread Rich Shepard

On Sun, 3 Mar 2019, Jonathan Vanasco wrote:


I generally write the SqlAlchemy models as a separate package, then import
that into my MVC/etc patterned app.



In terms of the SqlAlchemy logic, some of that I keep in the models
package, others are in the core app.

...

So my general advice is to approach things with two packages, one for [M]
and the other for [VC]


Jonathan,

I see three different approaches in the above: 1) a separate SA package; 2)
some SA in the model, some in the application class; and 3) a model module
and a combined view/controller module. Please help me distinguish among
them.

Regards,

Rich

--
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper


http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
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 https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.