Open mgersh opened 9 years ago
Might be the same issue as #1655? On Jun 28, 2015 3:19 PM, "Miriam Gershenson" notifications@github.com wrote:
Today I ran into the opposite problem from the one described in #956 https://github.com/learning-unlimited/ESP-Website/issues/956: lookups being applied to different Records when I wanted them to be applied to the same Record. I generated a combination list, starting from 'Students who are enrolled in at least one class' and adding AND NOT 'Students who have clicked the Confirm button'. Empirically, what this gave me instead was 'Students who are enrolled in at least one class' AND NOT students who have ever confirmed their registration for any program.
This is the resulting Q object. (I checked building it myself without the weird (NOT (AND: )). Nothing changed.)
(AND: ('is_active', True), (NOT (AND: )), ('studentregistrationsectionparent_classparent_program', <Program: HSSP Summer 2015>), (OR: ('studentregistration__end_date', None), ('studentregistrationend_dategte', datetime.datetime(2015, 6, 28, 14, 15, 34, 580262)) ), ('groupsname', u'Student'), ('studentregistrationrelationshipname', 'Enrolled'), (NOT (AND: ('recordprogram', <Program: HSSP Summer 2015>), ('recordevent', 'reg_confirmed') ) ), (OR: ('studentregistrationstart_date', None), ('studentregistration__start_datelte', datetime.datetime(2015, 6, 28, 14, 15, 34, 580262)) ) )
And this is the resulting SQL:
SELECT DISTINCT [fields] FROM "auth_user" LEFT OUTER JOIN "program_studentregistration" ON ("auth_user"."id" = "program_studentregistration"."user_id") INNER JOIN "program_classsection" ON ("program_studentregistration"."section_id" = "program_classsection"."id") INNER JOIN "program_class" ON ("program_classsection"."parent_class_id" = "program_class"."id") LEFT OUTER JOIN "auth_user_groups" ON ("auth_user"."id" = "auth_user_groups"."user_id") LEFT OUTER JOIN "auth_group" ON ("auth_user_groups"."group_id" = "auth_group"."id") INNER JOIN "program_registrationtype" ON ("program_studentregistration"."relationship_id" = "program_registrationtype"."id") WHERE (NOT (("auth_user"."id" IN (SELECT U1."user_id" FROM "users_record" U1 WHERE (U1."program_id" = 121 AND U1."user_id" IS NOT NULL)) AND "auth_user"."id" IS NOT NULL) AND ("auth_user"."id" IN (SELECT U1."user_id" FROM "users_record" U1 WHERE (U1."event" = 'reg_confirmed' AND U1."user_id" IS NOT NULL)) AND "auth_user"."id" IS NOT NULL)) AND "auth_user"."is_active" = true AND ("program_studentregistration"."start_date" IS NULL OR "program_studentregistration"."start_date" <= '2015-06-28 15:43:01.488424') AND "program_class"."parent_program_id" = 121 AND "auth_group"."name" = 'Student' AND ("program_studentregistration"."end_date" IS NULL OR "program_studentregistration"."end_date" >= '2015-06-28 15:43:01.488424') AND "program_registrationtype"."name" = 'Enrolled')
— Reply to this email directly or view it on GitHub https://github.com/learning-unlimited/ESP-Website/issues/1718.
I looked at that and they seem like very different issues to me. That one generates a Q object that's just plain wrong, this one generates a Q object that looks reasonable but does the wrong thing due to Django behavior.
Interesting fact that I forgot to add: the combination list 'Students who are enrolled in at least one class' AND 'Students who have clicked the Confirm button' worked fine. Q object:
(AND: ('is_active', True), (OR: ('studentregistration__end_date', None), ('studentregistration__end_date__gte', datetime.datetime(2015, 6, 28, 15, 7, 3, 557440))), ('studentregistration__section__parent_class__parent_program', <Program: HSSP Summer 2015>), ('groups__name', u'Student'), ('studentregistration__relationship__name', 'Enrolled'), (NOT (AND: )), (OR: ('studentregistration__start_date', None), ('studentregistration__start_date__lte', datetime.datetime(2015, 6, 28, 15, 7, 3, 557440))), ('pk__in', [87805, 87987, 87075, 86602, 85849, 59395, 80229, 87335, 79668, 73394, 87267, 66281, 81279, 86802, 6\ 9196, 85777, 77789, 87953, 85807, 83518, '...(remaining elements truncated)...']))
Today I ran into the opposite problem from the one described in #956: lookups being applied to different Records when I wanted them to be applied to the same Record. I generated a combination list, starting from 'Students who are enrolled in at least one class' and adding AND NOT 'Students who have clicked the Confirm button'. Empirically, what this gave me instead was 'Students who are enrolled in at least one class' AND NOT students who have ever confirmed their registration for any program.
This is the resulting Q object. (I checked building it myself without the weird (NOT (AND: )). Nothing changed.)
(AND: ('is_active', True), (NOT (AND: )), ('studentregistration__section__parent_class__parent_program', <Program: HSSP Summer 2015>), (OR: ('studentregistration__end_date', None), ('studentregistration__end_date__gte', datetime.datetime(2015, 6, 28, 14, 15, 34, 580262)) ), ('groups__name', u'Student'), ('studentregistration__relationship__name', 'Enrolled'), (NOT (AND: ('record__program', <Program: HSSP Summer 2015>), ('record__event', 'reg_confirmed') ) ), (OR: ('studentregistration__start_date', None), ('studentregistration__start_date__lte', datetime.datetime(2015, 6, 28, 14, 15, 34, 580262)) ) )
And this is the resulting SQL:
SELECT DISTINCT [fields] FROM "auth_user" LEFT OUTER JOIN "program_studentregistration" ON ("auth_user"."id" = "program_studentregistration"."user_id") INNER JOIN "program_classsection" ON ("program_studentregistration"."section_id" = "program_classsection"."id") INNER JOIN "program_class" ON ("program_classsection"."parent_class_id" = "program_class"."id") LEFT OUTER JOIN "auth_user_groups" ON ("auth_user"."id" = "auth_user_groups"."user_id") LEFT OUTER JOIN "auth_group" ON ("auth_user_groups"."group_id" = "auth_group"."id") INNER JOIN "program_registrationtype" ON ("program_studentregistration"."relationship_id" = "program_registrationtype"."id") WHERE (NOT (("auth_user"."id" IN (SELECT U1."user_id" FROM "users_record" U1 WHERE (U1."program_id" = 121 AND U1."user_id" IS NOT NULL)) AND "auth_user"."id" IS NOT NULL) AND ("auth_user"."id" IN (SELECT U1."user_id" FROM "users_record" U1 WHERE (U1."event" = 'reg_confirmed' AND U1."user_id" IS NOT NULL)) AND "auth_user"."id" IS NOT NULL)) AND "auth_user"."is_active" = true AND ("program_studentregistration"."start_date" IS NULL OR "program_studentregistration"."start_date" <= '2015-06-28 15:43:01.488424') AND "program_class"."parent_program_id" = 121 AND "auth_group"."name" = 'Student' AND ("program_studentregistration"."end_date" IS NULL OR "program_studentregistration"."end_date" >= '2015-06-28 15:43:01.488424') AND "program_registrationtype"."name" = 'Enrolled')