diff --git a/flatland/envs/generators.py b/flatland/envs/generators.py
index bfcfdf71ed5a9c608e588f0dbd759921b7450c43..0b3f3eb02dc77efc03740f97888dbfc9cabfa4e7 100644
--- a/flatland/envs/generators.py
+++ b/flatland/envs/generators.py
@@ -923,7 +923,7 @@ def realistic_rail_generator(nr_start_goal=1, seed=0, add_max_dead_end=4, goals_
             agents_targets.pop(t)
             agents_target.append((tp[0], tp[1]))
 
-            if len(agents_position) == 0:
+            if len(agents_positions) == 0:
                 print("no more position left")
                 break