oh, the pk "24769797950537768" is a postgres biginteger.


On 07/15/2015 04:46 PM, Richard Gerd Kuesters wrote:
thanks Mike!

here we go:

    (Pdb) session.query(MachineUnit).filter(MachineUnit.id_ ==
    24769797950537768).count()
    2015-07-15 16:43:53,114 INFO sqlalchemy.engine.base.Engine SELECT
    count(*) AS count_1
    FROM system_unit, (SELECT system_unit.fk_updated_by AS
    system_unit_fk_updated_by, system_unit.fk_created_by AS
    system_unit_fk_created_by, system_unit.dt_created_on AS
    system_unit_dt_created_on, system_unit.dt_updated_on AS
    system_unit_updated_on, system_unit.bi_rm_timestamp AS
    system_unit_bi_rm_timestamp, machine_unit.pk_fk_system_unit_id AS
    machine_unit_pk_fk_system_unit_id, system_unit.pk_system_unit_id
    AS system_unit_pk_system_unit_id, system_unit.fk_organization_id
    AS system_unit_fk_organization_id, system_unit.u_system_unit_name
    AS system_unit_u_system_unit_name, system_unit.in_ipv4 AS
    system_unit_in_ipv4, system_unit.p_system_unit_type AS
    system_unit_system_unit_type, system_unit.i_version AS
    system_unit_i_version, machine_unit.e_machine_type AS
    machine_unit_e_machine_type, machine_unit.e_printer_type AS
    machine_unit_e_printer_type
    FROM system_unit JOIN machine_unit ON
    system_unit.pk_system_unit_id = machine_unit.pk_fk_system_unit_id
    WHERE machine_unit.pk_fk_system_unit_id = %(system_unit_id_1)s AND
    system_unit.bi_rm_timestamp = %(rm_timestamp_1)s) AS anon_1
    WHERE system_unit.bi_rm_timestamp = %(rm_timestamp_2)s
    2015-07-15 16:43:53,114 INFO sqlalchemy.engine.base.Engine
    {'system_unit_id_1': 24769797950537768, 'rm_timestamp_1': 0,
    'rm_timestamp_2': 0}
    2L
    (Pdb) len(session.query(MachineUnit).filter(MachineUnit.id_ ==
    24769797950537768).all())
    2015-07-15 16:44:32,891 INFO sqlalchemy.engine.base.Engine SELECT
    system_unit.fk_updated_by AS system_unit_fk_updated_by,
    system_unit.fk_created_by AS system_unit_fk_created_by,
    system_unit.dt_created_on AS system_unit_dt_created_on,
    system_unit.dt_updated_on AS system_unit_updated_on,
    system_unit.bi_rm_timestamp AS system_unit_bi_rm_timestamp,
    machine_unit.pk_fk_system_unit_id AS
    machine_unit_pk_fk_system_unit_id, system_unit.pk_system_unit_id
    AS system_unit_pk_system_unit_id, system_unit.fk_organization_id
    AS system_unit_fk_organization_id, system_unit.u_system_unit_name
    AS system_unit_u_system_unit_name, system_unit.in_ipv4 AS
    system_unit_in_ipv4, system_unit.p_system_unit_type AS
    system_unit_system_unit_type, system_unit.i_version AS
    system_unit_i_version, machine_unit.e_machine_type AS
    machine_unit_e_machine_type, machine_unit.e_printer_type AS
    machine_unit_e_printer_type
    FROM system_unit JOIN machine_unit ON
    system_unit.pk_system_unit_id = machine_unit.pk_fk_system_unit_id
    WHERE machine_unit.pk_fk_system_unit_id = %(system_unit_id_1)s AND
    system_unit.bi_rm_timestamp = %(rm_timestamp_1)s
    2015-07-15 16:44:32,891 INFO sqlalchemy.engine.base.Engine
    {'system_unit_id_1': 24769797950537768, 'rm_timestamp_1': 0}
    1


# MachineUnit = Entity

it fits to the faq entry you mentioned earlier? :)


cheers,
richard.


On 07/15/2015 04:22 PM, Mike Bayer wrote:


On 7/15/15 3:13 PM, Richard Gerd Kuesters wrote:
does this happen even with a filter for a PK?

the problem is:

>>> session.query(Entity).filter(Entity.id_ == 24769797950537768).count() == 2 >>> len(session.query(Entity).filter(Entity.id_ == 24769797950537768).all()) == 1

i don't see where i have 2 pks with the same value ... in psql:

mydb=# select count(*) from entity where id_ = 24769797950537768;
 count
-------
     1
(1 row)

is this really right?
what does echo='debug' say ? both for the first query and the second. Also, that integer ID looks kind of like it itself could be hitting some overflow limit at some point. I assume no issue for a simple integer in the thousands ?








On 07/15/2015 04:02 PM, Mike Bayer wrote:


On 7/15/15 2:11 PM, Richard Gerd Kuesters wrote:
hello!

i'm encountering a weird behaviur with session.count() when using a custom mapper that implements a where condition to every session.

first, what is happening:

>>> len(session.query(Entity).all()) == 1
>>> session.query(Entity).count() == 2

your all() query is returning two rows that have the same primary key for Entity. The Query object de-duplicates redundant rows based on entity identity. Turn on echo='debug' and you should see this in the rows coming back.

we really need an FAQ entry for this one.



"Entity" is a base polymorphic entity, inherited by other classes.

my custom mapper:

class DeletedOption(MapperOption):
    propagate_to_loaders = True

    def process_query(self, query):
        mzo = query._mapper_zero()
        if hasattr(mzo, 'class_'):
            parent_cls = mzo.class_
            filter_crit = parent_cls.rm_timestamp == 0

        if query._criterion is None:
            query._criterion = filter_crit
        else:
            query._criterion = query._criterion & filter_crit


i remember getting this custom mapper option in a recipe ... i'm running sqla 1.0.6. if there's any information i can provide to enlighten this out, please let me know.

best regards,
richard.
--
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 <mailto: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 <mailto: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 <mailto:sqlalchemy+unsubscr...@googlegroups.com>. To post to this group, send email to sqlalchemy@googlegroups.com <mailto: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 <mailto:sqlalchemy+unsubscr...@googlegroups.com>. To post to this group, send email to sqlalchemy@googlegroups.com <mailto: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 <mailto:sqlalchemy+unsubscr...@googlegroups.com>. To post to this group, send email to sqlalchemy@googlegroups.com <mailto: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.

<<attachment: richard.vcf>>

Reply via email to