On Fri, Oct 8, 2021, at 7:09 AM, niuji...@gmail.com wrote:
> In order to make sure that the mapped class is fully ready, I chose the 
> latest point, namely `class_instrument`.
> However, it seems that at that moment the `__mapper__` attribute is not 
> available.
> When I tried 
>   return cls.__mapper__.get_property_by_column(column_obj).key
> 
> I got:
>  AttributeError: type object 'GeoAreaVariantName' has no attribute 
> '__mapper__'
> 
> Is this a bug or a feature?

it's a normal behavior, that event is called before mapping has been 
established.

but also, the "__mapper__" attribute is a convenience feature that should not 
be relied upon at this stage.  the correct way to get the mapper for a class is 
to use the sqlalchemy.inspect() function, i.e.  mapper = inspect(class).




> On Wednesday, October 6, 2021 at 5:36:22 AM UTC-7 Mike Bayer wrote:
>> __
>> events that occur around this time include
>> 
>> this one claims it's before:
>> 
>> https://docs.sqlalchemy.org/en/14/orm/events.html#sqlalchemy.orm.MapperEvents.instrument_class
>> 
>> this one says after:
>> 
>> https://docs.sqlalchemy.org/en/14/orm/events.html#sqlalchemy.orm.InstrumentationEvents.class_instrument
>> 
>> this one is definitely after and is usually fine for anything that needs to 
>> happen for mapped classes before they are reconciled against other classes:
>> 
>> https://docs.sqlalchemy.org/en/14/orm/events.html#sqlalchemy.orm.MapperEvents.before_mapper_configured
>> 
>> 
>> On Wed, Oct 6, 2021, at 4:48 AM, niuji...@gmail.com wrote:
>>> I want to do some after processing on each class that is just put into the 
>>> class_registry. Is there a event hook for this? 
>>> 
>>> 
>>> -- 
>>> 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+...@googlegroups.com.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/sqlalchemy/6ec43831-d59e-4343-99cf-dce3773a1216n%40googlegroups.com
>>>  
>>> <https://groups.google.com/d/msgid/sqlalchemy/6ec43831-d59e-4343-99cf-dce3773a1216n%40googlegroups.com?utm_medium=email&utm_source=footer>.
>> 
> 
> 
> -- 
> 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 view this discussion on the web visit 
> https://groups.google.com/d/msgid/sqlalchemy/066675cb-164a-4f61-9764-15ac402b6a3bn%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/sqlalchemy/066675cb-164a-4f61-9764-15ac402b6a3bn%40googlegroups.com?utm_medium=email&utm_source=footer>.

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/adb50a08-814c-42bc-8498-4c041108ce75%40www.fastmail.com.

Reply via email to