A story of a field named object... and is it a big deal

20 views
Skip to first unread message

Ken MacKenzie

unread,
Aug 9, 2017, 2:12:25 PM8/9/17
to sqlalchemy
So I have been using SQL alchemy to convert some unidata data stores into ms sql data.

One of the GL components in our system is called object, well object code.

Most refer to it as object so when I defined my model for the table including it I named it object.

It all works fine, but object is technically is something else in python.  I guess in theory within the lexical scope of that class I am redefining what object means.

Is this a big deal?  I am viewing it as a big deal and I want to get it changed, which requires some coordination because what was an experiment turned into an in use prototype (ain't that always the way).

I just wanted to get some more experienced feedback in case any of the data consumers start asking why I am wanting to change something that works to rename this field.

Ken

Mike Bayer

unread,
Aug 9, 2017, 6:33:34 PM8/9/17
to sqlal...@googlegroups.com
the column can be named object in the database, that's just a string name.

Python side, you can name a field "object", Python doesn't complain:

>>> class Foo(object):
... def __init__(self, object):
... self.object = object
...
>>> f1 = Foo(object='hi')
>>> print f1.object
hi

if you wanted to be perfect you'd name it "object_" or something else
totally but it isn't essential.



>
> Ken
>
> --
> 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 post to this group, send email to sqlal...@googlegroups.com.
> Visit this group at https://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.

Ken MacKenzie

unread,
Aug 9, 2017, 6:57:33 PM8/9/17
to sqlal...@googlegroups.com
yeah but I have it in the model as 

class gltable(Base):
...
    object = column(string(6))


> To post to this group, send email to sqlal...@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 a topic in the Google Groups "sqlalchemy" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sqlalchemy/cnigdkAb2fY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sqlalchemy+unsubscribe@googlegroups.com.

Mike Bayer

unread,
Aug 9, 2017, 7:18:03 PM8/9/17
to sqlal...@googlegroups.com
On Wed, Aug 9, 2017 at 6:57 PM, Ken MacKenzie <k...@mack-z.com> wrote:
> yeah but I have it in the model as
>
> class gltable(Base):
> ...
> object = column(string(6))


it will work fine, up to you if you want to worry about it, you can
always make it:

object_ = column("object", string(6))
>> > email to sqlalchemy+...@googlegroups.com.
>> > To post to this group, send email to sqlal...@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 a topic in the
>> Google Groups "sqlalchemy" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/sqlalchemy/cnigdkAb2fY/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to
>> sqlalchemy+...@googlegroups.com.
>> To post to this group, send email to sqlal...@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+...@googlegroups.com.

Jonathan Vanasco

unread,
Aug 9, 2017, 7:25:47 PM8/9/17
to sqlalchemy


On Wednesday, August 9, 2017 at 7:18:03 PM UTC-4, Mike Bayer wrote:
 
it will work fine

expanding on Mike's response... you're just defining `object` within the scope of the class definition.

    # `object` is the built-in
    class Foo(object):
        object = column()
        # `object` is the column, unless you bust into a method, then it's the built-in
        def __init__(self):
            # `self.object` is the column
            # `object` is the built-in
    # `object` is the built-in

Ken MacKenzie

unread,
Aug 11, 2017, 9:20:02 AM8/11/17
to sqlal...@googlegroups.com
Thank you everyone for the responses.

I think it is not as big a deal as I might have been expecting,.  The purist in me does not like redefining object.  But from an api perspective there is not cleaner and purpose built name for the field in question.

Ken
Reply all
Reply to author
Forward
0 new messages