On Fri, Oct 8, 2021, at 4:13 PM, niuji...@gmail.com wrote:
> Thanks for this very important information!
> 
> If I do want to utilize the mapper functions at this stage, what can I do? 
> currently I have this error showing up:
> 
> AttributeError: 'Mapper' object has no attribute '_columntoproperty'

you would need to show me a stack trace on that.  however, depending on which 
event you are using to get at the mapper, it may not be initialized yet (can 
confirm that class_instrument() event is too early if access to the internals 
of the mapper is required).      as stated previously, the best event to use 
when a class is first mapped but before the full span of mappings have been 
considered is the before_mapper_configured() event (can confirm 
_columntoproperty is available at that stage).



> On Friday, October 8, 2021 at 6:58:02 AM UTC-7 Mike Bayer wrote:
>> 
>> 
>> 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+...@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/fb457c38-74a2-4ce6-bb1c-35157347fd9fn%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/sqlalchemy/fb457c38-74a2-4ce6-bb1c-35157347fd9fn%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/b0ccce9f-f733-438b-b75f-91e109e2a3d6%40www.fastmail.com.

Reply via email to