**SIGH** Please ignore last message... I had forgotten to actually
update the database schema itself. :(  Pardon me while I go shoot
myself...

- Ken


On Tue, Jul 1, 2014 at 4:19 PM, Ken Lareau <klar...@tagged.com> wrote:

> On Thu, Jun 26, 2014 at 7:47 PM, Ken Lareau <klar...@tagged.com> wrote:
>
>> On Jun 26, 2014 7:40 PM, "Mike Bayer" <mike...@zzzcomputing.com> wrote:
>> >
>> > right, so a few emails ago I said:
>> >
>> > >  you need to put .label('environment') on that column before it finds
>> its way into subq.  I dont have the mappings here to review.
>> >
>> > here's that:
>> >
>> >
>> >     @environment.expression
>> >     def environment(cls):
>> >         return select(
>> >                 [Environment.environment]
>> >             ).where(
>> >                 Environment.id == cls.environment_id
>> >             ).correlate(cls).label('environment')
>> >
>> Aha... thanks.  Now I'm afraid to ask if you looked at the "after" file,
>> and if so, considered it insane. :)
>>
>> - Ken
>>
>> >
>> >
>> >
>> >
>> >
>> > On 6/26/14, 9:50 PM, Ken Lareau wrote:
>> >>
>> >> Done, new file attached (this gives the same error message as the one
>> I showed initially, at least on my system).
>> >>
>> >> - Ken
>> >> --
>> >> 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 http://groups.google.com/group/sqlalchemy.
>> >> For more options, visit https://groups.google.com/d/optout.
>> >
>> >
>> > --
>> > 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 http://groups.google.com/group/sqlalchemy.
>> > For more options, visit https://groups.google.com/d/optout.
>>
> Okay, trying the updated code worked with queries, but apparently not
> with an insert.  Here's the basic code involved:
>
> class AppDeployment(Base):
>     __tablename__ = 'app_deployments'
>
>     id = Column(u'AppDeploymentID', INTEGER(), primary_key=True)
>     deployment_id = Column(
>         u'DeploymentID',
>         INTEGER(),
>         ForeignKey('deployments.DeploymentID', ondelete='cascade'),
>         nullable=False
>     )
>     app_id = Column(
>         u'AppID',
>         SMALLINT(display_width=6),
>         ForeignKey('app_definitions.AppID', ondelete='cascade'),
>         nullable=False
>     )
>     user = Column(String(length=32), nullable=False)
>     status = Column(
>         Enum(
>             'complete',
>             'incomplete',
>             'inprogress',
>             'invalidated',
>             'validated',
>         ),
>         nullable=False
>     )
>     environment_id = Column(
>         u'environment_id',
>         INTEGER(),
>         ForeignKey('environments.environmentID', ondelete='cascade'),
>         nullable=False
>     )
>     realized = Column(
>         TIMESTAMP(),
>         nullable=False,
>         server_default=func.current_timestamp()
>
>     )
>     environment_obj = relationship('Environment')
>
>     @hybrid_property
>     def environment(self):
>         return self.environment_obj.environment
>
>     @environment.expression
>     def environment(cls):
>         return select([Environment.environment]).\
>                 where(Environment.id ==
> cls.environment_id).correlate(cls).\
>                 label('environment')
>
> and
>
> def _calculate_environment_id(environment):
>     return (Session.query(Environment.id)
>                    .filter_by(environment=environment)
>                    .one())[0]
>
> def add_app_deployment(dep_id, app_id, user, status, environment):
>     """Add a tier deployment for a given deployment ID"""
>
>     environment_id = _calculate_environment_id(environment)
>
>     app_dep = AppDeployment(
>         deployment_id=dep_id,
>         app_id=app_id,
>         user=user,
>         status=status,
>         environment_id=environment_id,
>         realized=func.current_timestamp()
>     )
>
>     # Commit to DB immediately
>     Session.add(app_dep)
>     Session.commit()
>
>     return app_dep
>
> An actual call to add_app_deployment() results in this exception:
>
> File "util.pyx", line 91, in oursql._do_warnings_query
> (oursqlx/oursql.c:3969)
> sqlalchemy.exc.DBAPIError: (CollatedWarningsError) (None, 'query caused
> warnings', [(<class 'oursql.Warning'>, (u"Field 'environment' doesn't have
> a default value", 1364L))]) u'INSERT INTO app_deployments (`DeploymentID`,
> `AppID`, user, status, environment_id, realized) VALUES (?, ?, ?, ?, ?,
> CURRENT_TIMESTAMP)' (4162L, 405L, 'klareau', 'inprogress', 1L)
>
> I'm guessing something's still not quite right with the 'environment'
> hybrid property
> in the class? :-/
>
>
> --
> - Ken Lareau
>
>


-- 
- Ken Lareau

-- 
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 http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to