constraint satisfaction problem missing one constraint

The main question would be answered with something like...

   def person_works_with_different():
        # over all the sessions, each person works with each other person no more than once.
        # 'works with' means in 'same session team'
        for p in all_people:
            buddy_constraint = []
            for s in all_sessions:
                for g in all_teams:
                    p_list = [pv[k] for k in filter(lambda i: i[P] == p and i[S] == s and i[G] == g, pv)]
                    for o in all_people:
                        if o != p:  # other is not person
                            o_list = [self.pv[k] for k in filter(lambda i: i[self.P] == o and i[self.S] == s and i[self.G] == g, self.pv)]
                            tmp = model.NewBoolVar('')
                            buddy_constraint.append(tmp)
                            model.Add(sum(o_list) == sum(p_list)).OnlyEnforceIf(tmp)
                            # tmp is set only if o and p are in the same session/team
            # The number of times a student gets to take part is the number of roles.
            # The size of the group controlled by the number of roles
            model.Add(sum(buddy_constraint) = all_roles * (all_roles - 1)) 

Added Edit

I had another look at your problem yesterday - (admittedly not long, as I have a lot of work on at the moment), and...

First of all, I see that your 'team' entity, is pretty much what I called an 'action' entity, and in retrospect I think 'team' (or 'group') was a better word for it.

If you are still finding the constraints hard, I suggest you break them out, and work on them individually - particularly the team/person/session constraints, followed by the role/task constraints.

/Added Edit

team: a gathering of 4 persons during a session
person (32): a participant of a team
session (6): time: eg, 8am -10am
role (4): what responsibility a person has in an action
task (6): type of action

A person does:
 0..1 action per session-group
 1 role per action
 1 task per action
 0..1 of each task
 1 of each role in an action
 4 persons in an action

A person meets each other person 0..1 times
An action requires exactly 4 people

I had a similar problem recently, and in the end turned to OR-tools. https://developers.google.com/optimization/cp/cp_solver

Particularly, have a look at the nurse scheduling problem: https://developers.google.com/optimization/scheduling/employee_scheduling#nurse_scheduling

Anyhow, the problem is not too complex, so maybe using a solver would be overkill for you.

Likewise, for this sort of problem it may be better to use a tuple-keyed dict to hold your variables, rather than nested lists:

{ Team, Session, Person: BoolVar }

The main reason is that you can then apply constraints via filters, which is much easier than having to do nested list manipulations, for instance, to apply a constraint across persons/teams, you can do (where person is index 2 and team is index 0):

for p in all_persons:
    for t in all_teams:
        stuff = [b_vars[k] for k in filter(lambda i: i[2] == p and i[0] == t, b_vars)]
        model.Add(sum(stuff) == 4)  # persons per team == 4